[Library | new-theme]: Do not show provenance value if no provenance vocabulary or if no label for this provenance value.

1. fundedBy.component.ts: Added local field "provenancesCalculated" to check for each provenance label only once and do not show provenance if no vocabulary or if not label for this value.
2. result-preview.component.ts: Do not show provenance if no vocabulary or if no label for this value.
3. HelperFunctions.class.ts: In method "getVocabularyLabel()" added parameter "returnIfNotFound: boolean = true" to return null if no vocabulary or if no label for this value, when it is false.
This commit is contained in:
Konstantina Galouni 2022-09-09 00:35:11 +03:00
parent fa919431d3
commit 656a3634e2
3 changed files with 21 additions and 7 deletions

View File

@ -58,10 +58,10 @@ import {HelperFunctions} from '../../utils/HelperFunctions.class';
<span class="uk-text-meta">Funding stream: </span>{{item.funding}}
</li>
</ul>
<div *ngIf="item.provenanceAction || item.validated" class="uk-text-meta">
<div *ngIf="getVocabularyLabel(item, provenanceActionVocabulary, i) || item.validated" class="uk-text-meta">
<span *ngIf="item.validated">Validated by funder</span>
<span *ngIf="item.provenanceAction && item.validated"> | </span>
<span *ngIf="item.provenanceAction">{{getVocabularyLabel(item.provenanceAction, provenanceActionVocabulary)}}</span>
<span *ngIf="item.provenanceAction">{{item.provenanceAction}}</span>
</div>
</div>
</div>
@ -80,6 +80,7 @@ export class FundedByComponent {
public url = properties.searchLinkToProject.split('?')[0];
public title: string = "Funded by";
@Input() provenanceActionVocabulary = null;
public provenancesCalculated: boolean[] = [];
public viewAllClick() {
if(this.fundedByProjects.length <= this.threshold*2) {
@ -96,7 +97,11 @@ export class FundedByComponent {
this.viewAllClicked.emit("");
}
public getVocabularyLabel(value: any, vocabulary: any) {
return HelperFunctions.getVocabularyLabel(value, vocabulary);
public getVocabularyLabel(item: any, vocabulary: any, index: number) {
if(!this.provenancesCalculated[index]) {
this.provenancesCalculated[index] = true;
item.provenanceAction = HelperFunctions.getVocabularyLabel(item.provenanceAction, vocabulary, false);
}
return item.provenanceAction;
}
}

View File

@ -72,11 +72,17 @@ export class HelperFunctions {
return Object.keys(value).map(key => value[key]);
}
public static getVocabularyLabel(value: any, vocabulary: any) {
public static getVocabularyLabel(value: any, vocabulary: any, returnIfNotFound: boolean = true) {
if(value == undefined || value == null) {
return null;
}
if(vocabulary && value in vocabulary) {
return vocabulary[value];
}
return value;
if(returnIfNotFound) {
return value;
}
return null;
}
public static sortSDGs(sgd1: string, sdg2: string): number {

View File

@ -123,7 +123,10 @@ export class ResultPreviewComponent implements OnInit, OnChanges {
this.beforeTitle.push(this.result.startYear.toString() + ' - ' + this.result.endYear.toString());
}
if(this.result.provenanceAction) {
this.beforeTitle.push(HelperFunctions.getVocabularyLabel(this.result.provenanceAction, this.provenanceActionVocabulary));
let value = HelperFunctions.getVocabularyLabel(this.result.provenanceAction, this.provenanceActionVocabulary, false);
if(value) {
this.beforeTitle.push(value);
}
}
if(this.result.relationName) {
this.beforeTitle.push(HelperFunctions.getVocabularyLabel(this.result.relationName, this.relationsVocabulary));