openaire-library/orcid/orcid-work.component.ts

842 lines
37 KiB
TypeScript
Raw Normal View History

import {Component, Input, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from "@angular/router";
import {Subscriber, Subscription} from "rxjs";
import {OrcidService} from "./orcid.service";
import {ResultLandingInfo} from "../utils/entities/resultLandingInfo";
import {ResultLandingService} from "../landingPages/result/resultLanding.service";
import {properties} from "../../../environments/environment";
import {Session} from "../login/utils/helper.class";
import {LoginErrorCodes} from "../login/utils/guardHelper.class";
import {ExternalIDV3_0, WorkV3_0} from "./orcidWork";
declare var UIkit: any;
@Component({
styles: [
'.add-orcid-button { background-color: #a6ce39; color: #fff; border: 1px solid #a6ce39; } ' +
'.add-orcid-button:hover { background-color: #b6d65c; border-color: #b6d65c; } ' +
'.delete-orcid-button { background-color: #fff; color: #ff3d33; border: 1px solid #ff3d33 }' +
'.delete-orcid-button:hover { color: #ff0d00; border-color: #ff0d00; } ' +
' a:not(:hover) .orcid-color { color: #a6ce39; }' +
'.loading-action-button { width: 36px; height: 36px; }' +
'.orcid-button { background-color: #fff; border: 1px solid #a6ce39; } ' +
'.orcid-button:hover { background-color: #e0f0d5; } '
],
selector: 'orcid-work',
template: `
<ng-container *ngIf="pageType == 'search'">
<span *ngIf="!putCodes || putCodes.length == 0"
[attr.uk-tooltip]="(!isLoggedIn)
? 'Only logged in users can add or delete a work from their ORCID record '
: 'Add this work to your ORCID record'">
<a (click)="saveWorkPreparation();"
[class]="'uk-flex uk-flex-middle uk-flex-right uk-margin-right '+ ((showLoading || !isLoggedIn) ? 'uk-disabled ' : '') + (!isLoggedIn ? 'half-opacity' : '')">
<!-- [class]="'uk-margin-right uk-flex uk-flex-middle '+ (showLoading ? 'uk-disabled' : '')">-->
<svg *ngIf="!showLoading" width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"
data-svg="plus">
<rect x="7" y="1" width="1" height="13" fill="#A6CE39"></rect>
<rect x="1" y="7" width="13" height="1" fill="#A6CE39"></rect>
</svg>
<span *ngIf="showLoading" class="uk-icon icon-button"><loading [top_margin]="false"></loading></span>
<span class="uk-margin-small-left">Add to
<span class="orcid-color">
<img src="assets/common-assets/common/ORCIDiD_icon16x16.png" alt="">{{" "}}
ORCID
</span>
</span>
<!-- <span class="uk-margin-small-left">Add to <span class="orcid-color">ORCID</span></span>-->
</a>
</span>
<span *ngIf="putCodes && putCodes.length > 0"
[attr.uk-tooltip]="(!isLoggedIn)
? 'Only logged in users can add or delete a work from their ORCID record '
: 'Delete this work from your ORCID record'">
<a (click)="deleteWorks();"
[class]="'uk-flex uk-flex-middle uk-flex-right uk-margin-right '+ (showLoading ? 'uk-disabled' : '')">
<!-- <img src="assets/common-assets/common/ORCIDiD_icon16x16.png" alt="">{{" "}}-->
<!-- <svg *ngIf="!showLoading" width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"-->
<!-- data-svg="minus">-->
<!-- <rect height="1" width="13" y="7" x="1" fill="#FF3D33"></rect>-->
<!-- </svg>-->
<span *ngIf="!showLoading" class="uk-icon uk-preserve">
<svg width="14" height="14" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" data-svg="trash">
<polyline fill="none" stroke="#666" points="6.5 3 6.5 1.5 13.5 1.5 13.5 3"></polyline>
<polyline fill="none" stroke="#666" points="4.5 4 4.5 18.5 15.5 18.5 15.5 4"></polyline>
<rect x="8" y="7" width="1" height="9" color="#666"></rect>
<rect x="11" y="7" width="1" height="9" color="#666"></rect>
<rect x="2" y="3" width="16" height="1" color="#666"></rect>
</svg>
</span>
<span *ngIf="showLoading" class="uk-icon icon-button"><loading [top_margin]="false"></loading></span>
<span class="uk-margin-small-left">Delete from
<span class="orcid-color">
<img src="assets/common-assets/common/ORCIDiD_icon16x16.png" alt="">{{" "}}
ORCID
</span>
</span>
</a>
</span>
</ng-container>
<ng-container *ngIf="pageType == 'landing'">
<span *ngIf="!putCodes || putCodes.length == 0"
[attr.uk-tooltip]="(!pids || !isLoggedIn)
? (!pids?'Only resources with a PID (persistent identifier) like DOI, handle, PMID can be added or deleted from your ORCID record'
: 'Only logged in users can add or delete a work from their ORCID record ')
: 'Add this work to your ORCID record'"
[class]="(!pids || !isLoggedIn) ? 'half-opacity' : ''">
<a (click)="saveWorkPreparation();"
[class]="'uk-link-text uk-text-bold uk-text-uppercase '+ (showLoading ? 'uk-disabled' : '') + (!isLoggedIn || !pids ? 'uk-disabled uk-text-muted' : '')">
<span *ngIf="!showLoading" class="uk-icon-button add-orcid-button uk-icon">
<svg width="15" height="15" viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg" data-svg="plus">
<rect x="7.5" y="1" width="1" height="15" fill="#A6CE39"></rect>
<rect x="1" y="7.5" width="15" height="1" fill="#A6CE39"></rect>
</svg>
</span>
<span *ngIf="showLoading" class="uk-icon icon-button loading-action-button"><loading
[top_margin]="false"></loading></span>
<span class="uk-margin-small-left">Add to
<span class="orcid-color">
<img src="assets/common-assets/common/ORCIDiD_icon16x16.png" alt="">{{" "}}
ORCID
</span>
</span>
<!-- <span class="uk-margin-small-left">Add to <span class="orcid-color">ORCID</span></span>-->
</a>
</span>
<span *ngIf="putCodes && putCodes.length > 0"
[attr.uk-tooltip]="(!pids || !isLoggedIn)
? (!pids?'Only resources with a PID (persistent identifier) like DOI, handle, PMID can be added or deleted from your ORCID record'
: 'Only logged in users can add or delete a work from their ORCID record ')
: 'Delete this work from your ORCID record'"
[class]="(!pids || !isLoggedIn) ? 'half-opacity' : ''">
<a (click)="deleteWorks();"
[class]="'uk-link-text uk-text-bold uk-text-uppercase '+ (showLoading ? 'uk-disabled' : '') + (!isLoggedIn || !pids ? 'uk-disabled uk-text-muted' : '')">
<!-- <span *ngIf="!showLoading" class="uk-icon-button delete-orcid-button uk-icon">-->
<!-- <svg width="15" height="15" viewBox="0 0 15 15" xmlns="http://www.w3.org/2000/svg" data-svg="minus">-->
<!-- <rect height="1" width="15" y="7.5" x="1" fill="#FF3D33"></rect>-->
<!-- </svg>-->
<!-- </span>-->
<span *ngIf="!showLoading" class="uk-icon-button delete-orcid-button uk-icon uk-preserve">
<svg width="15" height="15" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" data-svg="trash">
<polyline fill="none" stroke="#FF3D33" points="6.5 3 6.5 1.5 13.5 1.5 13.5 3"></polyline>
<polyline fill="none" stroke="#FF3D33" points="4.5 4 4.5 18.5 15.5 18.5 15.5 4"></polyline>
<rect x="8" y="7" width="1" height="9" color="#FF3D33"></rect>
<rect x="11" y="7" width="1" height="9" color="#FF3D33"></rect>
<rect x="2" y="3" width="16" height="1" color="#FF3D33"></rect>
</svg>
</span>
<span *ngIf="showLoading" class="uk-icon icon-button loading-action-button"><loading
[top_margin]="false"></loading></span>
<span class="uk-margin-small-left">Delete from
<span class="orcid-color">
<img src="assets/common-assets/common/ORCIDiD_icon16x16.png" alt="">{{" "}}
ORCID
</span>
</span>
<!-- <span class="uk-margin-small-left">Delete from <span class="orcid-color">ORCID</span></span>-->
</a>
</span>
</ng-container>
<modal-alert #grantModal [classTitle]="'landing-modal-header uk-padding-small'"
[classBody]="'landing-modal uk-padding-removeremove'">
<div class="uk-text-center uk-padding-small">
<div>{{requestGrantMessage}}</div>
<div class="uk-margin-medium-top uk-align-right">
<button (click)="closeGrantModal()" type="submit"
class="uk-button uk-padding-small uk-padding-remove-vertical uk-button-default">
<span>Cancel</span>
</button>
<button (click)="openGrantWindow()" type="submit"
class="uk-button uk-padding-small uk-padding-remove-vertical uk-margin-left uk-button-primary">
<span>Grant OpenAIRE</span>
</button>
<!-- <button (click)="openGrantWindow()" type="submit"-->
<!-- class="uk-button uk-padding-small uk-padding-remove-vertical uk-margin-left orcid-button">-->
<!-- <img src="assets/common-assets/common/ORCIDiD_icon16x16.png" alt="">{{" "}}-->
<!-- <span>Create or Connect your ORCID iD</span>-->
<!-- </button>-->
</div>
</div>
</modal-alert>
<ng-container *ngIf="pageType == 'my_search'">
<div class="uk-margin-bottom uk-text-center">
<img src="assets/common-assets/common/ORCIDiD_icon16x16.png" alt="">{{" "}}
ORCID ACTIONS
</div>
<span *ngIf="!putCodes || putCodes.length == 0"
uk-tooltip="Add this work to your ORCID record">
<a (click)="currentAction='add'; saveWorkPreparation();"
[class]="'uk-button action uk-flex uk-flex-middle '+ (showLoading ? 'uk-disabled' : '')">
<svg *ngIf="!showLoading || currentAction!='add'" width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"
data-svg="plus">
<rect x="7" y="1" width="1" height="13" fill="#A6CE39"></rect>
<rect x="1" y="7" width="13" height="1" fill="#A6CE39"></rect>
</svg>
<span *ngIf="showLoading && currentAction=='add'" class="uk-icon icon-button"><loading [top_margin]="false"></loading></span>
<span class="uk-margin-small-left">Add to ORCID</span>
<!-- <span class="uk-margin-small-left">Add to <span class="orcid-color">ORCID</span></span>-->
</a>
</span>
<span *ngIf="putCodes && putCodes.length > 0"
uk-tooltip="Delete this work from your ORCID record">
<a (click)="currentAction='delete'; deleteWorks();"
[class]="'uk-button action uk-flex uk-flex-middle '+ (showLoading ? 'uk-disabled' : '')">
<!-- <img src="assets/common-assets/common/ORCIDiD_icon16x16.png" alt="">{{" "}}-->
<!-- <svg *ngIf="!showLoading || currentAction!='delete'" width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"-->
<!-- data-svg="minus">-->
<!-- <rect height="1" width="13" y="7" x="1" fill="#FF3D33"></rect>-->
<!-- </svg>-->
<span *ngIf="!showLoading || currentAction!='delete'" class="uk-icon uk-preserve">
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" data-svg="trash">
<polyline fill="none" stroke="#FF3D33" points="6.5 3 6.5 1.5 13.5 1.5 13.5 3"></polyline>
<polyline fill="none" stroke="#FF3D33" points="4.5 4 4.5 18.5 15.5 18.5 15.5 4"></polyline>
<rect x="8" y="7" width="1" height="9" color="#FF3D33"></rect>
<rect x="11" y="7" width="1" height="9" color="#FF3D33"></rect>
<rect x="2" y="3" width="16" height="1" color="#FF3D33"></rect>
</svg>
</span>
<span *ngIf="showLoading && currentAction=='delete'" class="uk-icon icon-button"><loading [top_margin]="false"></loading></span>
<span class="uk-margin-small-left">Delete from ORCID</span>
<!-- <span class="uk-margin-small-left">Delete from <span class="orcid-color">ORCID</span></span>-->
</a>
</span>
<span [attr.uk-tooltip]="(!putCodes || putCodes.length == 0)
? 'This work is currently deleted.'
: 'Show this work from your ORCID record'">
<a (click)="currentAction='get'; getOrcidWorks()"
[class]="'uk-button action uk-margin-top uk-flex uk-flex-middle '+ ((showLoading || !putCodes || putCodes.length == 0) ? 'uk-disabled' : '')">
<!-- <svg *ngIf="!showLoading" width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"-->
<!-- data-svg="plus">-->
<!-- <rect x="7" y="1" width="1" height="13" fill="#A6CE39"></rect>-->
<!-- <rect x="1" y="7" width="13" height="1" fill="#A6CE39"></rect>-->
<!-- </svg>-->
<!-- uk-icon="server"-->
<span *ngIf="!showLoading || currentAction!='get'">
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24">
<path d="M0 0h24v24H0z" fill="none"></path>
<path d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z" fill="#666"></path>
</svg>
</span>
<span *ngIf="showLoading && currentAction=='get'" class="uk-icon icon-button"><loading [top_margin]="false"></loading></span>
<span class="uk-margin-small-left">Show ORCID work</span>
<!-- <span class="uk-margin-small-left">Show <span class="orcid-color">ORCID</span> work</span>-->
</a>
</span>
<span [attr.uk-tooltip]="(!putCodes || putCodes.length == 0)
? 'This work is currently deleted.'
: 'Update this work to your ORCID record'">
<a (click)="currentAction='update'; updateWorkPreparation()"
[class]="'uk-button action uk-margin-top uk-flex uk-flex-middle '+ ((showLoading || !putCodes || putCodes.length == 0) ? 'uk-disabled' : '')">
<!-- <svg *ngIf="!showLoading" width="14" height="14" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg"-->
<!-- data-svg="plus">-->
<!-- <rect x="7" y="1" width="1" height="13" fill="#A6CE39"></rect>-->
<!-- <rect x="1" y="7" width="13" height="1" fill="#A6CE39"></rect>-->
<!-- </svg>-->
<span *ngIf="!showLoading || currentAction!='update'" uk-icon="refresh"></span>
<span *ngIf="showLoading && currentAction=='update'" class="uk-icon icon-button"><loading [top_margin]="false"></loading></span>
<span class="uk-margin-small-left">Update ORCID work</span>
<!-- <span class="uk-margin-small-left">Update <span class="orcid-color">ORCID</span> work</span>-->
</a>
</span>
</ng-container>
<modal-alert #workModal [classTitle]="'landing-modal-header uk-padding-small'"
[classBody]="'landing-modal uk-padding-remove'">
<div *ngIf="orcidWorks" class="uk-padding-small">
<div *ngFor="let work of orcidWorks['bulk']">
<ng-container *ngTemplateOutlet="orcidWorkPreview; context:{work: work['work']}"></ng-container>
</div>
</div>
</modal-alert>
<ng-template #orcidWorkPreview1 let-work="work">
{{work | json}}}
</ng-template>
<ng-template #orcidWorkPreview let-work="work">
<div class="uk-card uk-card-default uk-padding uk-card-hover">
<div>{{work.title?.title?.value}}</div>
<div>{{work.title?.subtitle?.value}}</div>
<div class="uk-text-uppercase">{{work['journal-title']?.value}}</div>
<div *ngIf="work['publication-date'] || work['type']" class="uk-text-small uk-margin-small-bottom">
<span *ngIf="work['publication-date']">
<span *ngIf="work['publication-date']['year'] && work['publication-date']['year'].value">
{{work['publication-date']?.year?.value}}
</span>
<span *ngIf="work['publication-date']['year'] && work['publication-date']['year'].value
&& (
(work['publication-date']['month'] && work['publication-date']['month'].value) || (work['publication-date']['day'] && work['publication-date']['day'].value))">
-
</span>
<span *ngIf="work['publication-date']['month'] && work['publication-date']['month'].value">
{{work['publication-date']?.month?.value}}
</span>
<span *ngIf="work['publication-date']['month'] && work['publication-date']['month'].value
&& (work['publication-date']['day'] && work['publication-date']['day'].value) ">
-
</span>
<span *ngIf="work['publication-date']['day'] && work['publication-date']['day'].value">
{{work['publication-date']?.day?.value}}
</span>
<span *ngIf="work['type']"> | </span>
</span>
<span>{{work['type']}}</span>
</div>
<!-- Description -->
<div *ngIf="work['short-description']" class="uk-margin-small-bottom multi-line-ellipsis lines-3">
<p class="uk-text-muted uk-text-small">
{{work['short-description']}}
</p>
</div>
<div *ngIf="work['external-ids'] && work['external-ids']['external-id']" class="uk-margin-small-bottom">
<showIdentifiers [identifiers]="parseIdentifiers(work['external-ids']['external-id'])"></showIdentifiers>
</div>
<div *ngIf="work['contributors'] && work['contributors']['contributor']">
<div *ngFor="let contributor of work['contributors']['contributor']">
<span *ngIf="contributor['credit-name'] && contributor['credit-name'].value">
{{contributor['credit-name']?.value}}
</span>
<span *ngIf="(contributor['credit-name'] && contributor['credit-name'].value) && (
(contributor['contributor-attributes'] && contributor['contributor-attributes']['contributor-role'])
||
(contributor['contributor-attributes'] && contributor['contributor-attributes']['contributor-sequence'])
||
(contributor['contributor-orcid'] && contributor['contributor-orcid']['path'])
)">
(
</span>
<span *ngIf="contributor['contributor-attributes'] && contributor['contributor-attributes']['contributor-role']">
{{contributor['contributor-attributes']['contributor-role']}}
</span>
<span *ngIf="(contributor['contributor-attributes'] && contributor['contributor-attributes']['contributor-role'])
&& (contributor['contributor-attributes']['contributor-sequence'] || (contributor['contributor-orcid'] && contributor['contributor-orcid']['path']))">
,
</span>
<span *ngIf="contributor['contributor-attributes'] && contributor['contributor-attributes']['contributor-sequence']">
{{contributor['contributor-attributes']['contributor-sequence']}}
</span>
<span *ngIf="contributor['contributor-attributes'] && contributor['contributor-attributes']['contributor-sequence']
&& contributor['contributor-orcid'] && contributor['contributor-orcid']['path']">
,
</span>
<span *ngIf="contributor['contributor-orcid'] && contributor['contributor-orcid']['path']">
{{contributor['contributor-orcid']?.path}}
</span>
<span *ngIf="(contributor['credit-name'] && contributor['credit-name'].value) && (
(contributor['contributor-attributes'] && contributor['contributor-attributes']['contributor-role'])
||
(contributor['contributor-attributes'] && contributor['contributor-attributes']['contributor-sequence'])
||
(contributor['contributor-orcid'] && contributor['contributor-orcid']['path'])
)">
)
</span>
</div>
</div>
</div>
</ng-template>
<modal-alert #propagationModal [classTitle]="'landing-modal-header uk-padding-small'"
[classBody]="'landing-modal uk-padding-remove'">
<div class="uk-text-center uk-padding-small">
<div>
It seems than this result in OpenAIRE is the deduplication of multiple harvested results.
You have already added {{this.putCodes?.length}} works in your ORCID record related to this result.
<div *ngIf="currentAction == 'delete'">
If you continue with delete action, all these works will be deleted.
</div>
<div *ngIf="currentAction == 'update'">
If you continue with update action, all these works will be deleted and a new merged work will be added instead.
</div>
</div>
<div class="uk-margin-medium-top uk-align-right">
<button (click)="closePropagationModal()" type="submit"
class="uk-button uk-padding-small uk-padding-remove-vertical uk-button-default">
<span>Cancel</span>
</button>
<button (click)="confirmedPropagation()" type="submit"
class="uk-button uk-padding-small uk-padding-remove-vertical uk-margin-left uk-button-primary">
<span>Continue</span>
</button>
</div>
</div>
</modal-alert>
`
})
export class OrcidWorkComponent {
@Input() resultId: string = "";
@Input() resultLandingInfo: ResultLandingInfo;
@Input() pids: string = "";
@Input() identifiers: Map<string, string[]>;
@Input() type: string;
@Input() putCodes: string[] = [];
@Input() creationDates: string[] = [];
@Input() updateDates: string[] = [];
@Input() givenPutCode: boolean = false;
@Input() pageType: string = "search";
public subscriptions: Subscription[] = [];
@ViewChild('workModal') workModal;
@ViewChild('saveWorkModal') saveWorkModal;
@ViewChild('grantModal') grantModal;
@ViewChild('messageModal') messageModal;
@ViewChild('propagationModal') propagationModal;
private procedurePaused: string = "save";
public requestGrant: boolean = false;
public requestGrantMessage: string = "Please grant OpenAIRE to access and update your ORCID works.";
private clientId: string = "APP-A5M3KTX6NCN67L91";
private tokenUrl: string;
public message: string = "";
public showLoading: boolean = false;
public works: any[] = [];
public orcidWorks: any[] = [];
public window: any;
public isLoggedIn: boolean = Session.isLoggedIn();
public currentAction: string = "";
constructor(private route: ActivatedRoute,
private _router: Router,
private orcidService: OrcidService,
private resultLandingService: ResultLandingService) {
if(typeof document !== 'undefined') {
this.tokenUrl = "https://sandbox.orcid.org/oauth/authorize?"
+ "client_id="+this.clientId
// + "&response_type=code&scope=/activities/update"
// + "&response_type=code&scope=/authenticate /activities/update /person/update /read-limited"
+ "&response_type=code&scope=/activities/update /read-limited"
+ "&redirect_uri="+location.origin+"/orcid?source=openaire";
}
}
ngOnInit() {
if(!this.givenPutCode) {
this.getPutCode();
}
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
// console.debug("subscription closing...");
subscription.unsubscribe();
}
});
}
public parseIdentifiers(identifiers: ExternalIDV3_0[]): Map<string, string[]> {
let identifiersMap: Map<string, string[]> = new Map<string, string[]>();
for(let identifier of identifiers) {
if(!identifiersMap.has(identifier['external-id-type'])) {
identifiersMap.set(identifier['external-id-type'], new Array<string>());
}
identifiersMap.get(identifier['external-id-type']).push(identifier['external-id-value']);
}
return identifiersMap;
}
openGrantWindow() {
if(!Session.isLoggedIn()){
//this.userValidMessage = "User session has expired. Please login again.";
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
// this.tokenUrl = location.origin+"/orcid";
this.window = window.open(this.tokenUrl, '_blank',
'location=yes,height=700,width=540,left=500,top=100,scrollbars=yes,status=yes');
// this.requestGrant = false;
this.closeGrantModal();
// var timer = setInterval(function() {
// if(this.window.closed) {
// clearInterval(timer);
// }
// }, 1000);
let self = this;
window.onmessage = function (ev) {
if (ev.isTrusted && ev.origin !== location.origin && ev.data !== 'success')
return;
self.requestGrant = false;
UIkit.notification({
message: 'Thank you for <strong>connecting your ORCID iD</strong> with OpenAIRE!',
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
if (self.procedurePaused == "save") {
self.saveWorkPreparation();
} else if (self.procedurePaused == "delete") {
self.deleteWorks();
} else if(self.procedurePaused == "update") {
self.updateWorkPreparation();
}
};
// window.addEventListener("message", (eventt) => {
// // if(event.origin !== location.origin+"/orcid")
// // return;
// }, false);
// this.window.onbeforeunload = function () {
// UIkit.notification({
// message: '<strong>Thank you for connecting your ORCID iD with OpenAIRE!<strong>',
// status: 'success',
// timeout: 6000,
// pos: 'bottom-right'
// });
// }
}
}
private getPutCode() {
this.subscriptions.push(this.orcidService.getPutCode(this.pids).subscribe(
putCodes => {
this.putCodes = putCodes;
}, error => {
}
))
}
private getResultLandingInfo(action: string) {
this.subscriptions.push(this.resultLandingService.getResultLandingInfo(this.resultId, null, this.type, null, properties).subscribe(
resultLandingInfo => {
this.resultLandingInfo = resultLandingInfo;
if (this.resultLandingInfo && this.resultLandingInfo.identifiers) {
let pidsArray: string[] = [];
for (let key of Array.from(this.resultLandingInfo.identifiers.keys())) {
pidsArray = pidsArray.concat(this.resultLandingInfo.identifiers.get(key));
}
this.pids = pidsArray.join();
}
if(action == "save") {
this.saveWork();
} else if (action == "update") {
this.updateWork();
}
},
error => {
this.handleError(error,
"There was an error adding work with pids: "+this.pids+" to your ORCID record. Please try again later.",
"save");
console.error("Error getting landing info: ", error);
}
))
}
private saveWorkPreparation() {
if(!Session.isLoggedIn()){
//this.userValidMessage = "User session has expired. Please login again.";
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
if (this.requestGrant) {
this.openGrantModal("Add, delete or edit work in your ORCID record", "save");
} else {
this.showLoading = true;
if (this.resultLandingInfo) {
this.saveWork();
} else {
this.getResultLandingInfo("save");
}
}
}
}
private saveWork() {
this.subscriptions.push(this.orcidService.saveWork(this.resultLandingInfo, this.pids).subscribe(
response => {
// for testing only
// this.openGrantModal("Add work in your ORCID record");
// this.requestGrant = true;
// this.requestGrantMessage = "Please grant OpenAIRE to access and update your ORCID record and works.";
if(response == null) {
this.handleError(null,
"There was an error adding work with pids: "+this.pids+" to your ORCID record. Please try again later.",
"save");
console.error("Error posting landing info: null");
} else {
//this.work = this.orcidService.parse(this.resultLandingInfo);
//this.work['put-code'] = response;
// this.works.push(response);
this.putCodes.push(""+response['put-code']);
this.creationDates.push(response['created-date']['value']);
this.updateDates.push(response['last-modified-date']['value']);
// this.closeGrantModal();
this.message = "You have successfully added work with pids: "+this.pids+" in your ORCID record!";
// this.openMessageModal("Work added successfully");
UIkit.notification({
message: 'You have <strong>successfully added</strong> work with pids: <strong>'+this.pids+'</strong> in your ORCID record!',
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
this.showLoading = false;
}
},
error => {
this.handleError(error,
"There was an error adding work with pids: "+this.pids+" to your ORCID record. Please try again later.",
"save");
console.error("Error posting landing info", error);
}
));
}
private updateWorkPreparation() {
if(!Session.isLoggedIn()){
//this.userValidMessage = "User session has expired. Please login again.";
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
if (this.requestGrant) {
this.openGrantModal("Add, delete or edit work in your ORCID record", "save");
} else if(this.putCodes.length > 1) {
this.openPropagationModal("Update ORCID work");
} else {
this.showLoading = true;
if (this.resultLandingInfo) {
this.updateWork();
} else {
this.getResultLandingInfo("update");
}
}
}
}
private updateWork() {
this.subscriptions.push(this.orcidService.updateWork(this.resultLandingInfo, this.pids, this.putCodes[0]).subscribe(
response => {
//this.work = this.orcidService.parse(this.resultLandingInfo);
//this.work['put-code'] = response;
// this.work = response;
this.updateDates[0] = response['last-modified-date'].value;
UIkit.notification({
message: 'You have <strong>successfully updated</strong> work with pids: <strong>'+this.pids+'</strong> in your ORCID record!',
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
this.showLoading = false;
},
error => {
this.handleError(error,
"There was an error updating work with pids: "+this.pids+" to your ORCID record. Please try again later.",
"update");
console.error("Error updating landing info", error);
}
));
}
public confirmedPropagation() {
for(let putCode of this.putCodes)
{
this.deleteWorks();
}
if(this.currentAction == "update") {
this.saveWork();
}
}
private getOrcidWorks() {
this.showLoading = true;
this.subscriptions.push(this.orcidService.getOrcidWorks(this.putCodes).subscribe(
(response: WorkV3_0[]) => {
this.orcidWorks = response;
this.openWorkModal();
this.showLoading = false;
},
error => {
this.handleError(error,
"There was an error getting work with pids: "+this.pids+" from your ORCID record. Please try again later.",
"");
console.error("Error getting work", error);
}
));
}
private deleteWorks() {
if(!Session.isLoggedIn()){
//this.userValidMessage = "User session has expired. Please login again.";
this._router.navigate(['/user-info'], { queryParams: { "errorCode": LoginErrorCodes.NOT_VALID, "redirectUrl": this._router.url} });
} else {
// let put_code;// = this.testingPutCode;
// if(this.work && this.work['put-code']) {
// put_code = this.work['put-code'];
// }
if (this.requestGrant) {
this.openGrantModal("Add, delete or edit work in your ORCID record", "delete");
} else if(this.putCodes.length > 1) {
this.openPropagationModal("Delete ORCID work");
} else {
this.showLoading = true;
if (!this.resultLandingInfo && this.identifiers) {
let pidsArray: string[] = [];
for (let key of Array.from(this.identifiers.keys())) {
pidsArray = pidsArray.concat(this.identifiers.get(key));
}
this.pids = pidsArray.join();
}
this.subscriptions.push(this.orcidService.deleteWorks(this.putCodes).subscribe(
deletedPutCodes => {
let deletedAll: boolean = true;
if (deletedPutCodes) {
for (let i = 0; i < deletedPutCodes.length; i++) {
let deletedPutCode = deletedPutCodes[i];
if (deletedPutCode == null) {
deletedAll = false;
} else {
this.putCodes.splice(i, 1);
this.creationDates.splice(i, 1);
this.updateDates.splice(i, 1);
// this.works.splice(i, 1);
}
}
} else {
deletedAll = false;
}
if (!deletedAll) {
this.handleError(null,
"There was an error deleting work with pids: "+this.pids+" from your ORCID record. Please try again later.",
"delete");
console.error("Error deleting landing info: null");
} else {
// this.closeGrantModal();
this.message = "You have successfully deleted work with pids: "+this.pids+" from your ORCID record!";
// this.openMessageModal("Work deleted successfully");
UIkit.notification({
message: 'You have <strong>successfully deleted</strong> work with pids: <strong>'+this.pids+'</strong> from your ORCID record!',
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
this.showLoading = false;
}
},
error => {
this.handleError(error,
"There was an error deleting work with pids: "+this.pids+" to your ORCID record. Please try again later.",
"delete");
console.error("Error deleting work", error);
}
));
}
}
}
openGrantModal(title: string, procedurePaused: string) {
this.grantModal.cancelButton = false;
this.grantModal.okButton = false;
this.grantModal.alertTitle = title;
this.grantModal.open();
this.procedurePaused = procedurePaused;
}
closeGrantModal() {
this.grantModal.cancel();
}
openWorkModal() {
this.workModal.cancelButton = false;
this.workModal.okButton = false;
this.workModal.alertTitle = "Work in your ORCID record";
this.workModal.open();
}
closeWorkModal() {
this.workModal.cancel();
}
openMessageModal(title: string) {
this.messageModal.cancelButton = false;
this.messageModal.okButton = false;
this.messageModal.alertTitle = title;
this.messageModal.open();
}
closeMessageModal() {
this.messageModal.cancel();
}
openPropagationModal(title: string) {
this.propagationModal.cancelButton = false;
this.propagationModal.okButton = false;
this.propagationModal.alertTitle = title;
this.propagationModal.open();
}
closePropagationModal() {
this.propagationModal.cancel();
}
handleError(error, errorMsg: string, procedurePaused: string) {
if(error && error.status == "401") {
this.openGrantModal("Add, delete or edit work in your ORCID record", procedurePaused);
this.requestGrant = true;
this.requestGrantMessage = "Please grant OpenAIRE to access and update your ORCID record and works. ";
// + "If you have already granted OpenAIRE, you just need to login again to ORCID!";
} else if(error && error.status == "403") {
this.openGrantModal("Add, delete or edit work in your ORCID record", procedurePaused);
this.requestGrant = true;
this.requestGrantMessage = "Please login again to ORCID."
// this.openGrantModal();
} else {
this.message = errorMsg;
UIkit.notification({
message: this.message,
status: 'warning',
timeout: 6000,
pos: 'bottom-right'
});
// this.openMessageModal("An error occured");
}
this.showLoading = false;
}
}