diff --git a/orcid/my-orcid-links/myOrcidLinks.component.ts b/orcid/my-orcid-links/myOrcidLinks.component.ts new file mode 100644 index 00000000..d079e791 --- /dev/null +++ b/orcid/my-orcid-links/myOrcidLinks.component.ts @@ -0,0 +1,538 @@ +import {Component, Input, ViewChild} from '@angular/core'; +import {ActivatedRoute, Router} from '@angular/router'; +import {Location} from '@angular/common'; +import {ErrorCodes} from "../../utils/properties/errorCodes"; +import {ErrorMessagesComponent} from "../../utils/errorMessages.component"; +import {SearchUtilsClass} from "../../searchPages/searchUtils/searchUtils.class"; +import {RouterHelper} from "../../utils/routerHelper.class"; +import {EnvProperties} from "../../utils/properties/env-properties"; +import {properties} from "../../../../environments/environment"; +import {OrcidService} from "../orcid.service"; +import {Identifier, StringUtils} from "../../utils/string-utils.class"; +import {SearchResearchResultsService} from "../../services/searchResearchResults.service"; +import {Session} from "../../login/utils/helper.class"; +import {LoginErrorCodes} from "../../login/utils/guardHelper.class"; +import {SearchResult} from "../../utils/entities/searchResult"; +import {ResultPreview} from "../../utils/result-preview/result-preview"; +import {HttpClient} from "@angular/common/http"; + +declare var UIkit: any; + +@Component({ + selector: 'my-orcid-links', + template: ` + + + + + + + + +
+
+ + +
+
+
+ This is a private page, only for users that have connected their ORCID iD with OpenAIRE. + Please grant OpenAIRE to access and update your ORCID works. +
+ +
+ +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+
+
+ + + + +
+
+
+
+ ` +}) +export class MyOrcidLinksComponent { + public resultType: string = "result"; + + private errorCodes: ErrorCodes; + private errorMessages: ErrorMessagesComponent; + @Input() piwikSiteId = null; + public results =[]; + public currentResults = []; + public totalResults:number = 0 ; + public baseUrl:string; + public searchUtils:SearchUtilsClass = new SearchUtilsClass(); + public subscriptions: any[] = []; + public _location:Location; + + public disableForms: boolean = false; + public loadPaging: boolean = true; + public oldTotalResults: number = 0; + pagingLimit = 0; + + properties:EnvProperties; + + @Input() public communityId: string = null; + + depositLearnHowPage: string = null; + public routerHelper:RouterHelper = new RouterHelper(); + // breadcrumbs:Breadcrumb[] = []; + parameters = {}; + keyword = ""; + + identifiers: string[] = []; + works: any[] = []; + + orcidQuery: string = ""; + typeQuery: string = ""; + + public showLoading: boolean = true; + + currentPage: number = 1; + totalOrcidResults: number; + resultsPerPage: number = 5; + + public requestGrant: boolean = false; + public window: any; + private tokenUrl: string; + private clientId: string = "APP-A5M3KTX6NCN67L91"; + + public showErrorMessage: boolean = false; + + constructor (private route: ActivatedRoute, private router: Router, + private _orcidService: OrcidService, + private _searchResearchResultsService: SearchResearchResultsService + // ,private http: HttpClient/*ATHENA CODE*/ + ) { + this.errorCodes = new ErrorCodes(); + this.errorMessages = new ErrorMessagesComponent(); + this.searchUtils.status = this.errorCodes.LOADING; + this.searchUtils.page =1; + + 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"; + } + } + + public ngOnInit() { + this.properties = properties; + this.depositLearnHowPage = this.properties.depositLearnHowPage; + this.baseUrl = this.properties.depositSearchPage; + this.pagingLimit = this.properties.pagingLimit; + // this.breadcrumbs.push({name: 'home', route: '/'}, { + // name: "Deposit", + // route: this.depositLearnHowPage + // }, {name: "Browse repositories", route: null}); + + // this.subscriptions.push(this.route.queryParams.subscribe( + // params => { + // this.searchUtils.page = params['page'] ? params['page']-1 : 1; + // this.searchUtils.size = params['size'] ? params['size'] : 5; + + // let page = (params['page'] === undefined) ? 1 : +params['page']; + // this.searchUtils.page = (page <= 0) ? 1 : page; + // let size = (params['size'] === undefined) ? 5 : +params['size']; + // this.searchUtils.size = (size <= 0) ? 1 : size; + // + // if (params["type"]) { + // let types = params["type"]; + // types = Array.isArray(types) ? types.join(',').split(","):types.split(","); + // types.map( function (t) { + // return StringUtils.unquote(StringUtils.URIDecode(t)); + // } ); + // + // if(types.indexOf("publications")!=-1 && types.indexOf("datasets")!=-1 && types.indexOf("software")!=-1 && types.indexOf("other")!=-1 ){ + // this.typeQuery += "&type=results"; + // }else{ + // for (let type of types) { + // this.typeQuery += "&type=" + StringUtils.unquote(StringUtils.URIDecode(type)); + // } + // } + // }else{ + // this.typeQuery += "&type=results"; + // } + + this.typeQuery = "&type=results"; + // this.getLocalWorks(this.currentPage, this.resultsPerPage); + // })); + this.typeQuery = "&type=results"; + this.getLocalWorks(); + } + + public ngOnDestroy() { + for(let sub of this.subscriptions){ + sub.unsubscribe(); + } + } + + openGrantWindow() { + this.window = window.open(this.tokenUrl, '_blank', + 'location=yes,height=700,width=540,left=500,top=100,scrollbars=yes,status=yes'); + + 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 connecting your ORCID iD with OpenAIRE!', + status: 'success', + timeout: 6000, + pos: 'bottom-right' + }); + self.getLocalWorks(); + }; + } + + getLocalWorks() { + this.showErrorMessage = false; + + this.showLoading = true; + this.subscriptions.push(this._orcidService.getLocalWorks().subscribe( + (response: any[]) => { + + this.works = response;//['results']; + this.totalOrcidResults = this.works.length;//response['total']; + + this.prepareOrcidQuery(); + }, + error => { + this.handleError(error, "Could not get locally stored user's ORCID works"); + this.showLoading = false; + } + )); + } + + public prepareOrcidQuery() { + + if(this.results.length >= this.currentPage) { + this.currentResults = this.results[this.currentPage-1]; + return; + } + + this.showLoading = true; + + this.orcidQuery = ""; + + let from: number = (this.currentPage-1)*this.resultsPerPage; + if(from >= this.works.length) { + this.searchUtils.status = this.errorCodes.OUT_OF_BOUND; + } + let to: number = this.currentPage*this.resultsPerPage; + + if(to > this.works.length) { + to = this.works.length; + } + + let works = this.works.slice(from, to); + + for(let work of works) { + for(let pid of work['pids']) { + let identifier: Identifier = Identifier.getIdentifierFromString(pid); + this.orcidQuery += (this.orcidQuery ? " or " : "") + ('(pidclassid exact "'+identifier.class+'" and pid="'+StringUtils.URIEncode(identifier.id)+'")'); + //this.orcidQuery = '(pidclassid exact "doi" and pid="10.1007/978-3-030-55814-7_16")'; + // console.debug(this.orcidQuery); + } + } + this.showLoading = false; + this._getResults(works); + } + + public _getResults(works: any) { + this.searchUtils.status = this.errorCodes.LOADING; + this.disableForms = true; + this.currentResults = []; + this.searchUtils.totalResults = 0; + + // let params: string = this.orcidQuery + this.typeQuery; + //this.subs.push(this._searchResearchResultsService.advancedSearchResults(this.resultType, parameters, page, size, sortBy, this.properties, (refine) ? this.searchPage.getRefineFieldsQuery() : null, this.searchPage.getFields(), refineFieldsFilterQuery) + this.subscriptions.push(this._searchResearchResultsService.searchForMyOrcidLinks(this.resultType, this.orcidQuery, this.typeQuery, 1, 50) + //this.subs.push(this._searchResearchResultsService.advancedSearchResults(this.resultType, parameters, page, size, sortBy, this.properties, null, this.searchPage.getFields(), refineFieldsFilterQuery) + .subscribe( + data => { + let totalResults = data[0]; + let results = data[1]; + + this.resultsReturned(results, totalResults, works); + }, + err => { + // this.handleError("Error getting " + this.getEntityName(this.resultType, true, true), err); + console.error("Error getting " + this.getEntityName(this.resultType, true, true)); + this.showLoading = false; + this.searchUtils.status = this.errorMessages.getErrorCode(err.status); + this.disableForms = false; + } + ) + ); + } + + public resultsReturned(results: any, totalResults, works: any[]) { + this.searchUtils.totalResults = totalResults; + + let resultsFound: Map = new Map(); + + for(let work of works) { + results.forEach(result => { + let identifierValues: string[] = [].concat(...Array.from(result.identifiers.values())); + if(work['pids'].some(pid => identifierValues.includes(pid))) { + + let index: number = resultsFound.get(identifierValues); + if(!index) { + this.currentResults.push(this.getResultPreview(result)); + index = this.currentResults.length - 1; + + this.currentResults[index].orcidPutCodes = []; + this.currentResults[index].orcidCreationDates = []; + this.currentResults[index].orcidUpdateDates = []; + } + + if (work['putCode']) { + this.currentResults[index].orcidPutCodes.push(work['putCode']); + } + if (work['creationDate']) { + this.currentResults[index].orcidCreationDates.push(work['creationDate']); + } + if (work['updateDate']) { + this.currentResults[index].orcidUpdateDates.push(work['updateDate']); + } + } + }) + } + + // /////////////////////// ATHENA CODE /////////////////////// + // // console.log(data[1]); + // let dois = encodeURIComponent(results.map((result) => result.DOIs).join(",")); + // console.log(dois); + // console.log(this.properties.impactFactorsAPIURL); + // if(dois.length > 0 && (this.properties.impactFactorsAPIURL && this.properties.impactFactorsAPIURL.length > 0) ) { + // let url = this.properties.impactFactorsAPIURL + dois; + // this.http.get((this.properties.useCache?(this.properties.cacheUrl+(encodeURIComponent(url))):url)).subscribe((data_received:any[]) => { + // let impact =[]; + // data_received.forEach(function (result) { + // if(result.doi && result.doi.length > 0 && result.pop_class!=null && result.inf_class!=null) + // impact[result.doi]=result; + // }); + // this.currentResults.forEach(function (result) { + // if(result.identifiers) { + // result.identifiers.get("doi").forEach(function (doi) { + // if (impact[doi]) { + // result.DOI = doi; + // } + // + // }) + // } + // }); + // for (let i = 0; i < this.currentResults.length; i++) { + // if (this.currentResults[i].DOI) { + // this.currentResults[i].pop_inf = new Array(); + // this.currentResults[i].pop_inf.push(impact[this.currentResults[i].DOI].pop_class, impact[this.currentResults[i].DOI].inf_class); + // if(this.currentResults[i].pop_inf[0]=="A"){ + // // this.previewResults[i].pop_inf.push("High"); + // this.currentResults[i].pop_inf.push("Exceptional"); + // }else if(this.currentResults[i].pop_inf[0]=="B"){ + // // this.previewResults[i].pop_inf.push("Average"); + // this.currentResults[i].pop_inf.push("Substantial"); + // }else{ + // // this.previewResults[i].pop_inf.push("low"); + // this.currentResults[i].pop_inf.push("Average"); + // } + // if(this.currentResults[i].pop_inf[1]=="A"){ + // // this.previewResults[i].pop_inf.push("Strong"); + // this.currentResults[i].pop_inf.push("Exceptional"); + // }else if(this.currentResults[i].pop_inf[1]=="B"){ + // // this.previewResults[i].pop_inf.push("Average"); + // this.currentResults[i].pop_inf.push("Substantial"); + // }else{ + // // this.previewResults[i].pop_inf.push("Weak"); + // this.currentResults[i].pop_inf.push("Average"); + // } + // } + // } + // + // }, error1 => { + // console.error("Failed to get Impact factors for elixir-gr") + // }); + // // console.log(researchResults[1]); + // + // } + // /////////////////////// ATHENA CODE /////////////////////// + + + this.results[this.currentPage-1] = this.currentResults; + + this.searchUtils.status = this.errorCodes.DONE; + if (this.searchUtils.totalResults == 0) { + this.searchUtils.status = this.errorCodes.NONE; + } + + this.disableForms = false; + } + + public resultsReturned2(results: any, totalResults, works: any[]) { + this.searchUtils.totalResults = totalResults; + + for(let result of results) { + let identifierValues: string[] = [].concat(...Array.from(result.identifiers.values())); + + this.currentResults.push(this.getResultPreview(result)); + + let filteredWorks = works.filter(work => { + return work['pids'].some(pid => identifierValues.includes(pid)); + }) + + this.currentResults[this.currentResults.length - 1].orcidPutCodes = []; + this.currentResults[this.currentResults.length - 1].orcidCreationDates = []; + this.currentResults[this.currentResults.length - 1].orcidUpdateDates = []; + + filteredWorks.forEach(work => { + if(work['putCode']) { + this.currentResults[this.currentResults.length - 1].orcidPutCodes.push(work['putCode']); + } + if(work['creationDate']) { + this.currentResults[this.currentResults.length - 1].orcidCreationDates.push(work['creationDate']); + } + if(work['updateDate']) { + this.currentResults[this.currentResults.length - 1].orcidUpdateDates.push(work['updateDate']); + } + + // this.currentResults[this.currentResults.length - 1].orcidPutCodes.push(work['putCode']); + // this.currentResults[this.currentResults.length - 1].orcidCreationDates.push(work['creationDate']); + // this.currentResults[this.currentResults.length - 1].orcidUpdateDates.push(work['creationDate']); + }); + } + + this.results[this.currentPage-1] = this.currentResults; + // if(!refine) { + // this.searchPage.buildPageURLParameters(this.filters, this.rangeFilters, false); + // } + + this.searchUtils.status = this.errorCodes.DONE; + if (this.searchUtils.totalResults == 0) { + this.searchUtils.status = this.errorCodes.NONE; + } + + this.disableForms = false; + } + + public getResultPreview(result: SearchResult): ResultPreview { + return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.resultType); + } + + // private handleError(message: string, error) { + // if(error && error.status == "401") { + // 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.requestGrant = true; + // this.requestGrantMessage = "Please login again to ORCID." + // } + // console.error("My ORCID links Page: "+message, error); + // } + + public getEntityName(entityType: string, plural: boolean, full: boolean): string { + if (entityType == "publication") { + return "publication" + (plural ? "s" : ""); + } else if (entityType == "dataset") { + return (full ? "research data" : ("dataset" + (plural ? "s" : ""))); + } else if (entityType == "software") { + return "software"; + } else if (entityType == "other") { + return (full ? ("other research product" + (plural ? "s" : "")) : "other"); + } else if (entityType == "result") { + return (full ? ("research outcome" + (plural ? "s" : "")) : "result"); + } + } + + public pageChanged($event) { + this.currentPage = $event.value; + this.prepareOrcidQuery(); + // this.getLocalWorks(this.currentPage, this.resultsPerPage); + } + + handleError(error, errorMsg: string) { + if(error && (error.status == "401" || error.status == "403")) { + this.requestGrant = true; + } else { + this.showErrorMessage = true; + + // UIkit.notification({ + // message: errorMsg, + // status: 'warning', + // timeout: 6000, + // pos: 'bottom-right' + // }); + } + this.showLoading = false; + } +} diff --git a/orcid/my-orcid-links/myOrcidLinks.module.ts b/orcid/my-orcid-links/myOrcidLinks.module.ts new file mode 100644 index 00000000..498f280d --- /dev/null +++ b/orcid/my-orcid-links/myOrcidLinks.module.ts @@ -0,0 +1,29 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {FormsModule} from '@angular/forms'; +import {RouterModule} from '@angular/router'; + +import {ResultPreviewModule} from "../../utils/result-preview/result-preview.module"; +import {ErrorMessagesModule} from "../../utils/errorMessages.module"; +import {MyOrcidLinksComponent} from "./myOrcidLinks.component"; +import {SearchResearchResultsServiceModule} from "../../services/searchResearchResultsService.module"; +import {SearchMyOrcidResultsModule} from "./searchMyOrcidResults.module"; +import {AlertModalModule} from "../../utils/modal/alertModal.module"; + +@NgModule({ + imports: [ + CommonModule, FormsModule, + RouterModule, ErrorMessagesModule, + ResultPreviewModule, SearchResearchResultsServiceModule, SearchMyOrcidResultsModule, + AlertModalModule + ], + declarations: [ + MyOrcidLinksComponent + ], + providers:[ + ], + exports: [ + MyOrcidLinksComponent + ] +}) +export class MyOrcidLinksModule { } diff --git a/orcid/my-orcid-links/searchMyOrcidResults.component.html b/orcid/my-orcid-links/searchMyOrcidResults.component.html new file mode 100644 index 00000000..bfa41580 --- /dev/null +++ b/orcid/my-orcid-links/searchMyOrcidResults.component.html @@ -0,0 +1,41 @@ + + + + + + + + + +
+
+ +
+ +
    + + +
  • +
    +
    +
    + + +
    + +
    +
    + + +
    +
    +
    +
    +
  • +
+
\ No newline at end of file diff --git a/orcid/my-orcid-links/searchMyOrcidResults.component.ts b/orcid/my-orcid-links/searchMyOrcidResults.component.ts new file mode 100644 index 00000000..7f7dffa2 --- /dev/null +++ b/orcid/my-orcid-links/searchMyOrcidResults.component.ts @@ -0,0 +1,117 @@ +import {Component, EventEmitter, Input, Output, SimpleChanges} from '@angular/core'; +import {ActivatedRoute} from "@angular/router"; +import {Subscriber} from "rxjs"; +import {SearchResult} from "../../utils/entities/searchResult"; +import {EnvProperties} from "../../utils/properties/env-properties"; +import {RouterHelper} from "../../utils/routerHelper.class"; +import {ErrorCodes} from "../../utils/properties/errorCodes"; +import {ResultPreview} from "../../utils/result-preview/result-preview"; +import {properties} from "../../../../environments/environment"; +import {Session} from "../../login/utils/helper.class"; +import {OrcidService} from "../orcid.service"; + +@Component({ + selector: 'my-orcid-result', + templateUrl:'searchMyOrcidResults.component.html' +}) + +export class searcMyOrcidResultsComponent { + @Input() results: SearchResult[]; + @Input() status: number; + @Input() type: string; + @Input() properties:EnvProperties; + + @Input() previewResults:ResultPreview[]; + + public urlParam: string; + public linkToAdvancedSearchPage: string; + public errorCodes:ErrorCodes = new ErrorCodes(); + public routerHelper:RouterHelper = new RouterHelper(); + public errorMessage: string = "No results found"; + @Output() pageChange = new EventEmitter(); + @Input() currentPage: number = 0; + @Input() totalResults: number; + @Input() resultsPerPage: number = 5; + + sub; + constructor (private route: ActivatedRoute, private orcidService: OrcidService) {} + ngOnDestroy() { + if (this.sub instanceof Subscriber) { + this.sub.unsubscribe(); + } + } + ngOnInit() { + if(this.type == "publication") { + this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedPublications; + this.urlParam = "articleId"; + } else if(this.type == "dataset") { + this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedDatasets; + this.urlParam = "datasetId"; + } else if(this.type == "software") { + this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedSoftware; + this.urlParam = "softwareId"; + } else if(this.type == "other") { + this.linkToAdvancedSearchPage = this.properties.searchLinkToAdvancedOrps; + this.urlParam = "orpId"; + } + + this.properties = properties; + + } + + // ngOnChanges(changes: SimpleChanges): void { + // if (changes.results) { + // this.initialize(); + // } + // } + + public quote(params: string):string { + return '"'+params+'"'; + } + public getResultPreview(result: SearchResult): ResultPreview { + return ResultPreview.searchResultConvert(result, (result.entityType)?result.entityType:this.type); + } + + initialize() { + this.previewResults = []; + for (let result of this.results) { + this.previewResults.push(this.getResultPreview(result)); + } + + if (this.properties.environment == 'development' && Session.isLoggedIn() && this.results && this.results.length > 0) { + this.orcidService.getLocalWorksByPids(this.previewResults.map( + previewResult => { + if (previewResult.identifiers) { + let pidsArray: string[] = []; + for (let key of Array.from(previewResult.identifiers.keys())) { + pidsArray = pidsArray.concat(previewResult.identifiers.get(key)); + } + return pidsArray;//.join(); + } + })).subscribe( + works => { + for (let i = 0; i < this.previewResults.length; i++) { + if (this.previewResults[i].identifiers) { + this.previewResults[i].orcidPutCodes = []; + this.previewResults[i].orcidUpdateDates = []; + + works[i].forEach(work => { + this.previewResults[i].orcidPutCodes.push(work['putCode']); + this.previewResults[i].orcidUpdateDates.push(work['creationDate']); + }); + // this.previewResults[i].orcidPutCodes = works[i].map(work => work['putCode']); + // this.previewResults[i].orcidUpdateDates = works[i] + // console.debug(i, this.previewResults[i].orcidPutCodes); + } + } + }, error => { + + } + ); + } + } + + public pageChanged($event) { + this.pageChange.emit($event); + } +} diff --git a/orcid/my-orcid-links/searchMyOrcidResults.module.ts b/orcid/my-orcid-links/searchMyOrcidResults.module.ts new file mode 100644 index 00000000..94dec3cc --- /dev/null +++ b/orcid/my-orcid-links/searchMyOrcidResults.module.ts @@ -0,0 +1,27 @@ +import {NgModule} from '@angular/core'; +import {CommonModule} from '@angular/common'; +import {FormsModule} from '@angular/forms'; +import {RouterModule} from '@angular/router'; + +import {ResultPreviewModule} from "../../utils/result-preview/result-preview.module"; +import {ErrorMessagesModule} from "../../utils/errorMessages.module"; +import {searcMyOrcidResultsComponent} from "./searchMyOrcidResults.component"; +import {OrcidModule} from "../orcid.module"; +import {PagingModule} from "../../utils/paging.module"; + +@NgModule({ + imports: [ + CommonModule, FormsModule, + RouterModule, ErrorMessagesModule, + ResultPreviewModule, OrcidModule, PagingModule + ], + declarations: [ + searcMyOrcidResultsComponent + ], + providers:[ + ], + exports: [ + searcMyOrcidResultsComponent + ] +}) +export class SearchMyOrcidResultsModule { }