openaire-library/orcid/my-orcid-links/searchMyOrcidResults.compon...

128 lines
4.4 KiB
TypeScript
Raw Normal View History

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";
import {OpenaireEntities} from "../../utils/properties/searchFields";
@Component({
selector: 'my-orcid-result',
templateUrl:'searchMyOrcidResults.component.html'
})
export class searcMyOrcidResultsComponent {
@Input() results: SearchResult[];
@Input() status: number;
@Input() type: string;
@Input() properties:EnvProperties;
public openaireEntities = OpenaireEntities;
@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 (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);
}
[Trunk | Library]: 1. resultLanding.component.html & result-preview.component.html: Show orcid buttons in all environments (production too) | in <orcid-work> added "resultTitle" property. 2. myOrcidLinks.component.ts: Added "getPersonalDetails()" method and link to advanced research outcomes page, filtered by user's name (if personal details from ORCID fails, use name from AAI - getUserInfo). 3. searchMyOrcidResults.module.ts: Removed PagingModule and added NoLoadPaging. 4. searchMyOrcidResults.component.ts: Added method "totalPages()" to calculate pages in paging. 5. searchMyOrcidResults.component.html: a. Added <no-load-paging> (instead of custom paging with <paging-no-load>). b. In <orcid-work> added "resultTitle" property. c. Fix widths of grid inside card for result preview and orcid buttons. 6. orcid-work.component.ts: a. Added "resultTitle" @Input property, to show it in notifications, instead of pids. b. Updated messages for errors and for multiple put-codes. c. Use "danger" notifications instead of "warning" when an error occurs. d. For search and my orcid links pages, in orcid buttons, use <icon> for icons | For landing page, updated icons in orcid buttons. e. Added message "The action will affect your real ORCID iD." in tooltips, when environment == 'beta'. f. Removed property "procedurePaused" and its usage replaced by "currentAction". g. [Bug fix] For search pages, added "uk-align-right", in order orcid button not to take width for the whole line. h. [Bug fix] In method "getOrcidWorks()" check "Session.isLoggedIn()" was missing. 7. orcid.component.ts: If personal details from ORCID fails, use name from AAI - getUserInfo. 8. orcid.module.ts: Added IconsModule and registered icons: add, remove, preview, refresh in IconsService. 9. searchResult.component.ts: Call "orcidService.getPutCodes()" in all environments (production too). git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60619 d315682c-612b-4755-9ff5-7f18f6832af3
2021-03-11 02:40:53 +01:00
public totalPages(totalResults: number): number {
let totalPages:any = totalResults/this.resultsPerPage;
if(!(Number.isInteger(totalPages))) {
totalPages = (parseInt(totalPages, this.resultsPerPage) + 1);
}
return totalPages;
}
}