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

244 lines
8.3 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";
import {Identifier, StringUtils} from "../string-utils.class";
import {OpenaireEntities} from "../properties/searchFields";
import {HelperFunctions} from "../HelperFunctions.class";
import {NumberUtils} from '../../utils/number-utils.class';
@Component({
selector: 'result-preview',
templateUrl: 'result-preview.component.html',
styleUrls: ['result-preview.component.less']
})
export class ResultPreviewComponent implements OnInit, OnChanges {
[Library | develop & Eosc Explore | develop]: Added font-family "Inter" to align with Marketplace | Updated how back button "Go to search" is build - combine referrer and the new url parameter "pv", which is expected to have the previous url path and params. 1. /assets: Added /media/fonts/inter folder with the "Inter" font-family. 2. eosc-custom.less: Override the default font family to use 'Inter', sans-serif. 3. routerHelper.class.ts: Added method "addQueryParam()" to add a query parameter in already existing or not object with parameters. 4. search-tab.component.ts & searchResult.component & projects-in-modal.component.ts & result/deletedByInference/deletedByInference.component.ts & organization/deletedByInference/deletedByInference.component.ts: Added @Input() prevPath: string = ""; and pass it to the appropriate children components. 5. result-preview.component & fundedBy.component.ts & availableOn.component.ts & relatedDatasourcesTab.component.ts: Added @Input() prevPath: string = ""; and method "addEoscPrevInParams()" and call it when building queryParams of internal links. 6. metrics.component.ts: Added @Input() prevPath: string = ""; and use it when building internal urls. 7. resultLanding.component.ts & project.component.ts & organization.component.ts & dataProvider.component.ts: a. Added fields public referrer: string; and public prevPath: string; b. Read "pv" url property and get referrer. c. Added methods "addEoscPrevInParams()" and "eoscBackLink()". 8. resultLanding.component.html & project.component.html & organization.component.html & dataProvider.component.html: a. Update "Go to Search" back link. b. Call "addEoscPrevInParams()" method when building queryParams of internal links. c. Pass "prevPath" to the appropriate children components.
2023-04-20 19:06:53 +02:00
@Input() prevPath: string = "";
@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;
/**
* @deprecated
* */
@Input() isCard: boolean = false;
@Input() isMobile: boolean = false;
public routerHelper: RouterHelper = new RouterHelper();
public urlParam: string;
public url: string;
@Input() externalUrl: string;
@Input() showOrcid: boolean = true;
@Input() showEnermaps: boolean = false;
@Input() provenanceActionVocabulary = null;
@Input() relationsVocabulary = null;
@Input() showInline: boolean = false; // do not open modal for "view more" when this is true
@Input() isDeletedByInferenceModal: boolean = false; // do not show action bar in results when in "Other versions" modal section
/* Metadata */
public type: string;
public types: string[];
public provenanceAction: string;
public relationName: string;
public linking: boolean = false;
public share: boolean = false;
public cite: boolean = false;
public orcid: boolean = false;
public deposit: boolean = false;
public embed: boolean = false;
ngOnInit(): void {
if (this.hasLink) {
if (this.result.resultType === "publication") {
this.urlParam = "articleId";
this.url = properties.searchLinkToPublication.split('?')[0];
this.resultActions();
} else if (this.result.resultType === "dataset") {
this.urlParam = "datasetId";
this.url = properties.searchLinkToDataset.split('?')[0];
this.resultActions();
} else if (this.result.resultType === "software") {
this.urlParam = "softwareId";
this.url = properties.searchLinkToSoftwareLanding.split('?')[0];
this.resultActions();
} else if (this.result.resultType === "other") {
this.urlParam = "orpId";
this.url = properties.searchLinkToOrp.split('?')[0];
this.resultActions();
} 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];
this.projectActions();
} else if (this.result.resultType == "organization") {
this.urlParam = "organizationId";
this.url = properties.searchLinkToOrganization.split('?')[0];
this.organizationActions();
} else if (this.result.resultType == "dataprovider") {
if (this.result.compatibilityUNKNOWN && properties.adminToolsPortalType == "eosc") {
this.urlParam = "serviceId";
this.url = properties.searchLinkToService.split('?')[0];
} else {
this.urlParam = "datasourceId";
this.url = properties.searchLinkToDataProvider.split('?')[0];
}
this.contentProviderActions();
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.initMetadata();
if (this.result.languages) {
this.result.languages = this.removeUnknown(this.result.languages);
}
if (this.result.countries) {
this.result.countries = this.removeUnknown(this.result.countries);
}
}
resultActions() {
this.linking = true;
this.share = true;
this.cite = true;
this.orcid = (this.properties.adminToolsPortalType == 'explore' || this.properties.adminToolsPortalType == 'community' || this.properties.adminToolsPortalType == 'aggregator') &&
this.showOrcid && this.result.identifiers && this.result.identifiers.size > 0;
}
projectActions() {
this.linking = true;
this.share = true;
this.deposit = true;
this.embed = true;
}
organizationActions() {
this.share = true;
}
contentProviderActions() {
this.share = true;
}
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() {
[Library | new-theme]: Allow also ?pid url parameter in datasource landing | Fixes in newSearchPage for service filters. 1. dataProvider.component.ts: [Bug fix] Allow also ?pid url parameter, query accordingly and set canonicalUrl to use it in seoService and scema2jsonld. 2. dataProvider.component.html: Set canonicalUrl into URL of <schema2jsonld> | Use <landing-header> instead of <showTitle>. 3. dataProvider.service.ts: Set url for querying a datasource by pid (if ?pid in landing url param) and parse also the whole record, the objIdentifier and the relcanId. 4. landing-header.component.ts: Added @Input() isSticky: boolean = false; to set less margins when sticky. 5. resultLanding.component.html: Use <landing-header> instead of <showTitle>. 6. resultLanding.component.ts: Use renamed Identifier.getResultPIDFromIdentifiers --> Identifier.getPIDFromIdentifiers. 7. metrics.service.ts: Removed console.log. 8. searchDataproviders.service.ts: Added parsing for relcanId. 9. dataProviderInfo.ts: Added relcanId, objIdentifier, record. 10. result-preview.component.ts: Use renamed Identifier.getResultPIDFromIdentifiers --> Identifier.getPIDFromIdentifiers. 11. string-utils.class.ts: Renamed Identifier.getResultPIDFromIdentifiers --> Identifier.getPIDFromIdentifiers. 12. [SITEMAPS] extractUrlsFromSearch.ts: Use renamed Identifier.getResultPIDFromIdentifiers --> Identifier.getPIDFromIdentifiers. 13. newSearchPage.component.ts: [Bug fix] a. entityType for datasources is "dataprovider". b. Added service filter options only when entityType == "service".
2022-05-30 09:39:10 +02:00
return Identifier.getPIDFromIdentifiers(this.result.identifiers);
}
public initMetadata() {
if (this.result.resultType && this.result.resultType !== 'dataprovider') {
this.type = this.getTypeName(this.result.resultType);
}
if (this.result.types) {
this.types = this.removeUnknown(this.removeDuplicates(this.result.types));
}
if (this.result.provenanceAction) {
this.provenanceAction = HelperFunctions.getVocabularyLabel(this.result.provenanceAction, this.provenanceActionVocabulary, false);
}
if (this.result.relationName) {
this.relationName = HelperFunctions.getVocabularyLabel(this.result.relationName, this.relationsVocabulary);
}
// if(this.result.percentage) {
// this.beforeTitle.push((this.result.relation ? this.result.relation+": " : "") + this.result.percentage.toString() + "%");
// }
}
get hasActions() {
return this.linking || this.share || this.cite || this.orcid;
}
public getTypeName(type: string): string {
return StringUtils.getEntityName(type, false);
}
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";
}
public formatNumber(num: number | string) {
let formatted = NumberUtils.roundNumber(+num);
return formatted.number + formatted.size;
}
public getAccessLabel(accessRight) : string {
if(accessRight) {
return (accessRight + (accessRight.toLowerCase().endsWith(" access") ? "" : " access"));
}
return "Not available access";
}
[Library | develop & Eosc Explore | develop]: Added font-family "Inter" to align with Marketplace | Updated how back button "Go to search" is build - combine referrer and the new url parameter "pv", which is expected to have the previous url path and params. 1. /assets: Added /media/fonts/inter folder with the "Inter" font-family. 2. eosc-custom.less: Override the default font family to use 'Inter', sans-serif. 3. routerHelper.class.ts: Added method "addQueryParam()" to add a query parameter in already existing or not object with parameters. 4. search-tab.component.ts & searchResult.component & projects-in-modal.component.ts & result/deletedByInference/deletedByInference.component.ts & organization/deletedByInference/deletedByInference.component.ts: Added @Input() prevPath: string = ""; and pass it to the appropriate children components. 5. result-preview.component & fundedBy.component.ts & availableOn.component.ts & relatedDatasourcesTab.component.ts: Added @Input() prevPath: string = ""; and method "addEoscPrevInParams()" and call it when building queryParams of internal links. 6. metrics.component.ts: Added @Input() prevPath: string = ""; and use it when building internal urls. 7. resultLanding.component.ts & project.component.ts & organization.component.ts & dataProvider.component.ts: a. Added fields public referrer: string; and public prevPath: string; b. Read "pv" url property and get referrer. c. Added methods "addEoscPrevInParams()" and "eoscBackLink()". 8. resultLanding.component.html & project.component.html & organization.component.html & dataProvider.component.html: a. Update "Go to Search" back link. b. Call "addEoscPrevInParams()" method when building queryParams of internal links. c. Pass "prevPath" to the appropriate children components.
2023-04-20 19:06:53 +02:00
public addEoscPrevInParams(obj) {
if(properties.adminToolsPortalType == "eosc" && this.prevPath) {
let splitted: string[] = this.prevPath.split("?");
obj = this.routerHelper.addQueryParam("return_path", splitted[0], obj);
if(splitted.length > 0) {
obj = this.routerHelper.addQueryParam("search_params", splitted[1], obj);
}
[Library | develop & Eosc Explore | develop]: Added font-family "Inter" to align with Marketplace | Updated how back button "Go to search" is build - combine referrer and the new url parameter "pv", which is expected to have the previous url path and params. 1. /assets: Added /media/fonts/inter folder with the "Inter" font-family. 2. eosc-custom.less: Override the default font family to use 'Inter', sans-serif. 3. routerHelper.class.ts: Added method "addQueryParam()" to add a query parameter in already existing or not object with parameters. 4. search-tab.component.ts & searchResult.component & projects-in-modal.component.ts & result/deletedByInference/deletedByInference.component.ts & organization/deletedByInference/deletedByInference.component.ts: Added @Input() prevPath: string = ""; and pass it to the appropriate children components. 5. result-preview.component & fundedBy.component.ts & availableOn.component.ts & relatedDatasourcesTab.component.ts: Added @Input() prevPath: string = ""; and method "addEoscPrevInParams()" and call it when building queryParams of internal links. 6. metrics.component.ts: Added @Input() prevPath: string = ""; and use it when building internal urls. 7. resultLanding.component.ts & project.component.ts & organization.component.ts & dataProvider.component.ts: a. Added fields public referrer: string; and public prevPath: string; b. Read "pv" url property and get referrer. c. Added methods "addEoscPrevInParams()" and "eoscBackLink()". 8. resultLanding.component.html & project.component.html & organization.component.html & dataProvider.component.html: a. Update "Go to Search" back link. b. Call "addEoscPrevInParams()" method when building queryParams of internal links. c. Pass "prevPath" to the appropriate children components.
2023-04-20 19:06:53 +02:00
}
return obj;
}
}