2019-07-23 14:23:12 +02:00
|
|
|
import {Component, Input} from '@angular/core';
|
|
|
|
import {ClaimEntity} from './claimHelper.class';
|
2018-05-03 11:58:30 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
declare var UIkit: any;
|
2018-05-03 11:58:30 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-07-23 14:23:12 +02:00
|
|
|
selector: 'claim-results',
|
|
|
|
template: `
|
2018-05-03 11:58:30 +02:00
|
|
|
|
2022-05-16 16:25:35 +02:00
|
|
|
<div *ngIf="results.length > 0 " class="uk-margin-top">
|
2022-05-19 12:12:59 +02:00
|
|
|
<div *ngFor=" let entity of results " [class]="(isSelected(entity))?'uk-block-muted':''" class=" uk-card uk-card-default uk-card-body uk-margin-bottom claim-result-card">
|
2019-07-23 14:23:12 +02:00
|
|
|
<div>
|
2022-05-19 12:12:59 +02:00
|
|
|
<div class="uk-text-small uk-margin-small-bottom">
|
2019-07-23 14:23:12 +02:00
|
|
|
{{(!entity.result) ? entity.type : ((entity.result && entity.result.source == 'openaire') ? entity.type : (entity.result && entity.result.source + ' result'))}}
|
|
|
|
</div>
|
|
|
|
<div class="uk-grid">
|
2022-05-16 16:25:35 +02:00
|
|
|
<div class="uk-width-expand uk-margin-right">
|
2019-07-23 14:23:12 +02:00
|
|
|
<claim-title [entity]="entity"></claim-title>
|
|
|
|
<claim-result-metadata [entity]="entity"></claim-result-metadata>
|
|
|
|
<claim-project-metadata [entity]="entity"></claim-project-metadata>
|
|
|
|
</div>
|
2022-03-16 17:54:22 +01:00
|
|
|
<div class="uk-margin-auto-vertical uk-padding-remove-left uk-margin-small-left uk-margin-small-right" [title]="(this.selectedResults.length>=basketLimit)?'Basket reached the size limit':''">
|
2022-05-12 16:59:13 +02:00
|
|
|
<a [class]="(this.selectedResults.length>=basketLimit)?'uk-icon-button uk-disabled disabled':'uk-icon-button enabled'" *ngIf="!isSelected(entity)"
|
2019-07-23 14:23:12 +02:00
|
|
|
(click)="add(entity)">
|
|
|
|
<span class="uk-icon">
|
|
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="plus"
|
|
|
|
ratio="1"><rect x="9" y="1" width="1" height="17"></rect><rect x="1" y="9" width="17"
|
|
|
|
height="1"></rect></svg>
|
|
|
|
</span>
|
|
|
|
</a>
|
2022-05-12 16:59:13 +02:00
|
|
|
<a *ngIf="isSelected(entity)" class="uk-icon-button selected " (click)="remove(entity)">
|
2019-07-23 14:23:12 +02:00
|
|
|
<span class="uk-icon" >
|
|
|
|
<svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" icon="check" ratio="1"><polyline fill="none" stroke="#000" stroke-width="1.1" points="4,10 8,15 17,4"></polyline></svg>
|
|
|
|
</span>
|
2022-05-11 17:46:51 +02:00
|
|
|
</a>
|
2019-07-23 14:23:12 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-07-25 15:56:02 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
</div>
|
2022-03-16 17:54:22 +01:00
|
|
|
</div>
|
|
|
|
</div>`,
|
2018-05-03 11:58:30 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
export class ClaimResultsComponent {
|
2019-07-23 14:23:12 +02:00
|
|
|
@Input() results: ClaimEntity[];
|
|
|
|
@Input() selectedResults: ClaimEntity[];
|
|
|
|
@Input() localStoragePrefix: string = "";
|
2019-07-24 14:46:29 +02:00
|
|
|
@Input() basketLimit;
|
2019-07-23 14:23:12 +02:00
|
|
|
private isSelected(result: ClaimEntity) {
|
2018-05-03 11:58:30 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
let found: boolean = false;
|
|
|
|
const id = result.id;
|
|
|
|
for (let _i = 0; _i < this.selectedResults.length; _i++) {
|
|
|
|
let item = this.selectedResults[_i];
|
|
|
|
if (item.id && item.id == id) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
// indexOf doesn't work when results came from
|
|
|
|
// return this.selectedResults.indexOf(entity)!=-1;
|
|
|
|
}
|
2018-05-03 11:58:30 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
add(item: ClaimEntity) {
|
2019-07-24 14:46:29 +02:00
|
|
|
// if (this.selectedResults.length > this.basketLimit) {
|
|
|
|
// UIkit.notification({
|
|
|
|
// message: 'Your basket exceeds the number of allowed results (150)',
|
|
|
|
// status: 'warning',
|
|
|
|
// timeout: 1500,
|
|
|
|
// pos: 'top-center'
|
|
|
|
// });
|
|
|
|
// return;
|
|
|
|
// }
|
2019-07-23 14:23:12 +02:00
|
|
|
let found: boolean = this.isSelected(item);
|
|
|
|
if (!found) {
|
|
|
|
this.selectedResults.push(item);
|
|
|
|
if (this.selectedResults != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix, JSON.stringify(this.selectedResults));
|
2018-05-03 11:58:30 +02:00
|
|
|
}
|
2022-05-11 17:46:51 +02:00
|
|
|
UIkit.notification(item.type + ' added in your basket!', {
|
|
|
|
status: 'success',
|
|
|
|
timeout: 4000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
|
|
|
}
|
2022-05-11 17:46:51 +02:00
|
|
|
|
|
|
|
remove(item: any) {
|
|
|
|
const index: number = this.selectedResults.indexOf(item);
|
|
|
|
if (index > -1) {
|
|
|
|
this.selectedResults.splice(index, 1);
|
|
|
|
if (this.selectedResults != null) {
|
|
|
|
localStorage.setItem(this.localStoragePrefix, JSON.stringify(this.selectedResults));
|
|
|
|
}
|
|
|
|
UIkit.notification(item.type + ' removed from your basket!', {
|
|
|
|
status: 'warning',
|
|
|
|
timeout: 4000,
|
|
|
|
pos: 'bottom-right'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-05-03 11:58:30 +02:00
|
|
|
}
|