openaire-library/claims/linking/selected/ClaimEntityResultMetadata.c...

80 lines
2.7 KiB
TypeScript
Raw Normal View History

import {Component, Input} from '@angular/core';
import {ClaimEntity} from '../../claim-utils/claimHelper.class';
import {StringUtils} from "../../../utils/string-utils.class";
@Component({
selector: 'claim-result-metadata',
template:
`
<div *ngIf="entity.result">
<div *ngIf="entity.result.authors && entity.result.authors.length >0 " class="uk-text-small">
<span class="uk-text-muted">Authors </span>
{{sliceArray(entity.result.authors)}}
</div>
<div *ngIf="!shortVersion && entity.result.editors&& entity.result.editors.length > 0" class="uk-text-small">
<span class="uk-text-muted">Editors </span>
{{sliceArray(entity.result.editors)}}
</div>
<div *ngIf="!shortVersion" class="uk-grid uk-margin-remove uk-text-small">
<div class="uk-width-1-2 uk-padding-remove-left">
<span *ngIf="entity.result.publisher!=null"><span
class="uk-text-muted">Publisher</span> {{entity.result.publisher}}</span>
<span *ngIf="entity.result.journal!=null"><span
class="uk-text-muted">Journal</span> {{entity.result.journal}}</span>
</div>
<div class="uk-width-1-2">
<span *ngIf="entity.result.date"><span class="uk-text-muted">Published in </span> <span
[class]="(getProjectDurationMessage(entity)?'uk-text-warning':'')">{{entity.result.date}}</span></span>
<div [class]="(getProjectDurationMessage(entity)?'uk-text-warning':'')">{{getProjectDurationMessage(entity)}}
</div>
</div>
</div>
</div>
`
})
export class ClaimEntityResultMetadataComponent {
@Input() entity: ClaimEntity;
@Input() slice: boolean = false;
@Input() sliceSize: number = 45;
@Input() shortVersion: boolean = false;
ngOnInit() {
}
sliceArray(array): string {
if (this.slice) {
let sliced = array.slice(0, this.sliceSize);
return sliced.join("; ") + (array.length>this.sliceSize ? "...":"");
}
return array.join("; ");
}
addStringToNumber(str: string, num: number) {
return (+str) + num;
}
getProjectDurationMessage(result: ClaimEntity) {
if(!result.warningMessages){
return null;
}
for (let message of result.warningMessages) {
if (message.type == "projectDuration") {
return "Should be from " + message.projectInfo.startDate + ((message.projectInfo.endDate) ? (" to " + ((5 + +message.projectInfo.endDate))) : "");
}
}
return null;
}
// getEmbargoEndDateMessage(result: ClaimEntity) {
// for (var message of result.warningMessages) {
// if (message.type == "embargoEndDate") {
// return "Embargo end date must be later than published date";
// }
// }
// return null;
// }
}