openaire-library/utils/result-preview/result-preview.component.ts

183 lines
6.4 KiB
TypeScript
Raw Normal View History

import {Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core";
import {ResultPreview} from "./result-preview";
import {EnvProperties} from "../properties/env-properties";
import {RouterHelper} from "../routerHelper.class";
import {AlertModal} from "../modal/alert";
import {properties} from "../../../../environments/environment";
[Trunk | Library]: 1. error-interceptor.service.ts: Add "properties.orcidAPIURL" in UNAUTHORIZED_WHITELIST. 2. resultLanding.component.html: If result has identifiers and user is logged in, call <orcid-work>. 3. resultLanding.module.ts: Import OrcidModule. 4. searchResult.component.ts: If user is logged in, call "orcidService.getPutCodes()" and set orcidPutCodes of previewResults. 5. searchResults.module.ts: Add "OrcidService" in providers. 6. searchResearchResults.service.ts: In method "parseResults()", call "this.parsingFunctions.parseIdentifiers(resData['pid'])" to set identifiers. 7. customOptions.class.ts: Change method return type: "public static registryOptions(): any" --> public static registryOptions(): {}". (caused problem in return type of services (e.g. HttpEvent<string> instead of string). 8. searchResult.ts: Add field "identifiers: Map<string, string[]>". 9. env-properties.ts: Add field "orcidAPIURL". 10. result-preview.component.html: a. If result has identifiers and user is logged in, call <orcid-work>. b. In bottom line with impact factors and orcid, add class "result-preview-bottom" (set color to #747474 (like muted text) when not on hover). 11. result-preview.component.ts: Add field "loggedIn" and check on init if user is logged in (via Session). 12. result-preview.module.ts: Import OrcidModule. 13. result-preview.ts: Add field "orcidPutCodes" | In method "searchResultConvert()", set resultPreview.identifiers with all identifiers (not only dois). git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60231 d315682c-612b-4755-9ff5-7f18f6832af3
2021-01-13 19:30:25 +01:00
import {Session} from "../../login/utils/helper.class";
import {Identifier} from "../string-utils.class";
import {OpenaireEntities} from "../properties/searchFields";
@Component({
selector: 'result-preview',
templateUrl: 'result-preview.component.html'
})
export class ResultPreviewComponent implements OnInit, OnChanges {
@Input() result: ResultPreview;
@Input() properties: EnvProperties;
public openaireEntities = OpenaireEntities;
@Input() showSubjects: boolean = true;
@Input() showOrganizations: boolean = true;
@Input() modal: AlertModal = null;
@Input() promoteWebsiteURL: boolean = false;
@Input() hasLink: boolean = true;
2022-03-15 12:13:28 +01:00
@Input() isCard: boolean = false;
public routerHelper: RouterHelper = new RouterHelper();
public urlParam: string;
public url: string;
@Input() externalUrl: string;
public type: string;
public beforeTitle: string[] = [];
public dataProviderUrl = properties.searchLinkToDataProvider.split('?')[0];
@Input() showOrcid: boolean = true;
@Input() showEnermaps: boolean = false;
[Trunk | Library]: 1. error-interceptor.service.ts: Add "properties.orcidAPIURL" in UNAUTHORIZED_WHITELIST. 2. resultLanding.component.html: If result has identifiers and user is logged in, call <orcid-work>. 3. resultLanding.module.ts: Import OrcidModule. 4. searchResult.component.ts: If user is logged in, call "orcidService.getPutCodes()" and set orcidPutCodes of previewResults. 5. searchResults.module.ts: Add "OrcidService" in providers. 6. searchResearchResults.service.ts: In method "parseResults()", call "this.parsingFunctions.parseIdentifiers(resData['pid'])" to set identifiers. 7. customOptions.class.ts: Change method return type: "public static registryOptions(): any" --> public static registryOptions(): {}". (caused problem in return type of services (e.g. HttpEvent<string> instead of string). 8. searchResult.ts: Add field "identifiers: Map<string, string[]>". 9. env-properties.ts: Add field "orcidAPIURL". 10. result-preview.component.html: a. If result has identifiers and user is logged in, call <orcid-work>. b. In bottom line with impact factors and orcid, add class "result-preview-bottom" (set color to #747474 (like muted text) when not on hover). 11. result-preview.component.ts: Add field "loggedIn" and check on init if user is logged in (via Session). 12. result-preview.module.ts: Import OrcidModule. 13. result-preview.ts: Add field "orcidPutCodes" | In method "searchResultConvert()", set resultPreview.identifiers with all identifiers (not only dois). git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@60231 d315682c-612b-4755-9ff5-7f18f6832af3
2021-01-13 19:30:25 +01:00
ngOnInit(): void {
if(this.hasLink) {
if (this.result.resultType === "publication") {
this.urlParam = "articleId";
this.url = properties.searchLinkToPublication.split('?')[0];
} else if (this.result.resultType === "dataset") {
this.urlParam = "datasetId";
this.url = properties.searchLinkToDataset.split('?')[0];
} else if (this.result.resultType === "software") {
this.urlParam = "softwareId";
this.url = properties.searchLinkToSoftwareLanding.split('?')[0];
} else if (this.result.resultType === "other") {
this.urlParam = "orpId";
this.url = properties.searchLinkToOrp.split('?')[0];
} else if (this.result.resultType == "project") {
if(this.result.id) {
this.urlParam = "projectId";
}else if(this.result.code && this.result.funderShortname){
this.result.id = this.result.code;
this.urlParam = "grantId";
}
this.url = properties.searchLinkToProject.split('?')[0];
} else if (this.result.resultType == "organization") {
this.urlParam = "organizationId";
this.url = properties.searchLinkToOrganization.split('?')[0];
} else if (this.result.resultType == "dataprovider") {
this.urlParam = "datasourceId";
this.url = properties.searchLinkToDataProvider.split('?')[0];
2022-05-13 14:57:31 +02:00
} else if (this.result.resultType == "service") {
this.urlParam = "serviceId";
this.url = properties.searchLinkToService.split('?')[0];
} else {
this.urlParam = "id";
this.url = properties.searchLinkToResult.split('?')[0];
}
this.checkPID();
}
this.initBeforeTitle();
if(this.result.languages) {
this.result.languages = this.removeUnknown(this.result.languages);
}
if(this.result.countries) {
this.result.countries = this.removeUnknown(this.result.countries);
}
}
ngOnChanges(changes: SimpleChanges) {
if(changes.result && this.hasLink) {
this.checkPID();
}
}
checkPID() {
// if result has a pid use it as parameter instead of openaireId
let pid:Identifier =this.getPID();
if(pid){
this.urlParam = "pid";
this.result.id = pid.id;
}
}
getPID() {
return Identifier.getResultPIDFromIdentifiers(this.result.identifiers);
}
public initBeforeTitle() {
if(this.result.resultType && this.result.resultType !== 'dataprovider') {
this.type = this.getTypeName(this.result.resultType);
}
if(this.result.types) {
this.removeUnknown(this.removeDuplicates(this.result.types)).forEach(type => {
this.beforeTitle.push(type);
});
}
if(this.result.year) {
this.beforeTitle.push(this.result.year.toString());
}
if(this.result.startYear && this.result.endYear) {
this.beforeTitle.push(this.result.startYear.toString() + ' - ' + this.result.endYear.toString());
}
if(this.result.provenanceAction) {
this.beforeTitle.push(this.result.provenanceAction);
}
if(this.result.relationName) {
this.beforeTitle.push(this.result.relationName);
}
// if(this.result.percentage) {
// this.beforeTitle.push((this.result.relation ? this.result.relation+": " : "") + this.result.percentage.toString() + "%");
// }
}
public getTypeName(type: string): string {
if (type === "dataset") {
return this.openaireEntities.DATASET;
} else if (type === "other") {
return this.openaireEntities.OTHER_SINGULAR;
} else if (type === "dataprovider") {
return this.openaireEntities.DATASOURCE;
2022-05-13 14:57:31 +02:00
} else if (type === "service") {
return this.openaireEntities.SERVICE;
} else if (type === "publication") {
return this.openaireEntities.PUBLICATION;
} else if (type === "software") {
return this.openaireEntities.SOFTWARE_SINGULAR;
} else if (type === "result") {
return this.openaireEntities.RESULT;
} else {
return type;
}
}
public removeUnknown(array: string[]): string[] {
return array.filter(value => value.toLowerCase() !== 'unknown');
}
public removeDuplicates(array: string[]): string[] {
return array.filter(value => value.toLowerCase() !== this.result.resultType);
}
public accessClass(accessMode: string): string {
if(accessMode.toLowerCase().indexOf('open') !== -1) {
2022-03-15 12:13:28 +01:00
return 'success';
} else if(accessMode.toLowerCase() === 'not available') {
2022-03-15 12:13:28 +01:00
return 'disabled'; // unknown
} else {
2022-03-15 12:13:28 +01:00
return 'disabled'; // closed
}
}
public onClick() {
if(this.modal) {
this.modal.cancel();
}
}
createParam(){
if(this.urlParam == "grantId" ){
return this.routerHelper.createQueryParams([this.urlParam,"funder"],[this.result.id,this.result.funderShortname])
}
return this.routerHelper.createQueryParam(this.urlParam,this.result.id)
}
public get isResultType() {
return this.result.resultType == "publication" || this.result.resultType == "dataset" ||
this.result.resultType == "software" || this.result.resultType == "other" || this.result.resultType == "result";
}
}