Manager your ORCID links',
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
this.showLoading = false;
}
},
error => {
this.handleError(error);
console.error("Error posting landing info", error);
}
));
}
goToOrcidLinksPage() {
this._router.navigate([this.properties.myOrcidLinksPage]);
}
private updateWorkPreparation() {
if (!Session.isLoggedIn()) {
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");
} 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 => {
if (response) {
this.updateDates[0] = response['last-modified-date'].value;
// message: 'You have successfully updated work with pids: ' + this.pids + ' in your ORCID record!',
UIkit.notification({
message: 'You have successfully updated work "' + this.resultTitle + '" in your ORCID record!'
// +
// '
Manager your ORCID links'
,
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
}
this.showLoading = false;
},
error => {
this.handleError(error);
console.error("Error updating landing info", error);
}
));
}
public confirmedPropagation() {
this.propagationModal.cancel();
this.deleteWorks(true);
//}
// if(this.currentAction == "update") {
// this.saveWork();
// }
}
public getOrcidWorks() {
if (!Session.isLoggedIn()) {
this._router.navigate(['/user-info'], {
queryParams: {
"errorCode": LoginErrorCodes.NOT_VALID,
"redirectUrl": this._router.url
}
});
} else {
this.showLoading = true;
this.subscriptions.push(this.orcidService.getOrcidWorks(this.putCodes).subscribe(
(response) => {
let error: boolean = true;
if (response && response['bulk']) {
response = response['bulk'].filter(res => {
return (!res.error && res.work);
});
if (response && response.length > 0) {
error = false;
this.orcidWorks = response;
this.openWorkModal();
}
}
if (error) {
UIkit.notification({
message: 'There was an error getting this work. Please make sure you have not deleted it from your ORCID iD.',
status: 'warning',
timeout: 6000,
pos: 'bottom-right'
});
}
this.showLoading = false;
},
error => {
this.handleError(error);
console.error("Error getting work", error);
}
));
}
}
public deleteWorks(confirmed: boolean = false) {
if (!Session.isLoggedIn()) {
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");
} else if (this.putCodes.length > 1 && !confirmed) {
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(this.properties.logServiceUrl) {
this.subscriptions.push(this._logService.logRemoveOrcidLink(this.properties, deletedPutCode).subscribe(res => { }));
}
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);
console.error("Error deleting landing info: null");
} else {
if (this.currentAction == "update") {
this.saveWork();
} else {
// this.closeGrantModal();
// this.message = "You have successfully deleted work with pids: " + this.pids + " from your ORCID record!";
this.message = "You have successfully deleted work \"" + this.resultTitle + "\" from your ORCID record!";
// this.openMessageModal("Work deleted successfully");
// message: 'You have successfully deleted work with pids: ' + this.pids + ' from your ORCID record!',
UIkit.notification({
message: 'You have successfully deleted work "' + this.resultTitle + '" from your ORCID record!'
// +
// '
Manager your ORCID links'
,
status: 'success',
timeout: 6000,
pos: 'bottom-right'
});
this.showLoading = false;
}
}
},
error => {
this.handleError(error);
console.error("Error deleting work", error);
}
));
}
}
}
openGrantModal(title: string) {
if(this.isMobile) {
this.grantFsModal.okButton = false;
this.grantFsModal.title = title;
this.grantFsModal.open();
} else {
this.grantModal.cancelButton = true;
this.grantModal.okButton = true;
this.grantModal.okButtonText = "Grant OpenAIRE";
this.grantModal.okButtonLeft = false;
this.grantModal.alertTitle = title;
this.grantModal.open();
}
}
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) {
if(this.isMobile) {
this.propagationFsModal.okButton = false;
this.propagationFsModal.title = title;
this.propagationFsModal.open();
} else {
this.propagationModal.cancelButton = true;
this.propagationModal.okButton = true;
this.propagationModal.okButtonText = "Continue";
this.propagationModal.okButtonLeft = false;
this.propagationModal.alertTitle = title;
this.propagationModal.open();
}
}
closePropagationModal() {
this.propagationModal.cancel();
}
handleError(error) {
if (error && error.status == "401") {
this.openGrantModal("Add, delete or edit work in your ORCID record");
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");
this.requestGrant = true;
this.requestGrantMessage = "Please login again to ORCID."
// this.openGrantModal();
} else {
this.message = "";
if (error && error.status == "409") {
this.message = "There is already a work in your ORCID record with the same information of the work you are trying to add now.
";
}
if (this.currentAction == "get") {
// this.message += "There was an error getting work with pids: " + this.pids + " from your ORCID record. Please try again later.";
this.message += "There was an error getting work \"" + this.resultTitle + "\" from your ORCID record. Please try again later.";
} else if (this.currentAction == "add") {
// this.message += "There was an error adding work with pids: "+this.pids+" to your ORCID record. Please try again later.";
this.message += "There was an error adding work with pids: \"" + this.pids + "\" to your ORCID record. Please try again later.";
} else if (this.currentAction == "update") {
// this.message += "There was an error updating work with pids: "+this.pids+" to your ORCID record. Please try again later.";
this.message += "There was an error updating work \"" + this.resultTitle + "\" to your ORCID record. Please try again later.";
} else if (this.currentAction == "delete") {
// this.message += "There was an error deleting work with pids: "+this.pids+" from your ORCID record. Please try again later.";
this.message += "There was an error deleting work \"" + this.resultTitle + "\" from your ORCID record. Please try again later.";
} else {
this.message += "There was an error. Please try again later."
}
UIkit.notification({
message: this.message,
status: 'danger',
timeout: 6000,
pos: 'bottom-right'
});
// this.openMessageModal("An error occured");
}
this.showLoading = false;
}
get tooltipAdd() {
return "Add this work to your ORCID record" + ((properties.environment == "beta") ? ". The action will affect your real ORCID iD." : "");
}
get tooltipDelete() {
return "Delete this work from your ORCID record" + ((properties.environment == "beta") ? ". The action will affect your real ORCID iD." : "");
}
get tooltipNoPid() {
return "Only resources with a PID (persistent identifier) like DOI, handle, PMID can be added or deleted from your ORCID record";
}
get tooltipNoLoggedInUser() {
return "Add or delete a work from your ORCID record. Please log in first."
}
hoverEvent($event, action: string = "add") {
if (action == "add") {
this.hoverAdd = $event.type == "mouseover";
this.hoverDelete = false;
} else if (action == "delete") {
this.hoverDelete = $event.type == "mouseover";
this.hoverAdd = false;
}
}
}