import {Component, Input} from '@angular/core';
import {ClaimEntity} from './claimHelper.class';
declare var UIkit: any;
@Component({
selector: 'claim-results',
template: `
0 " class="uk-list uk-list-divider">
-
{{(!entity.result) ? entity.type : ((entity.result && entity.result.source == 'openaire') ? entity.type : (entity.result && entity.result.source + ' result'))}}
`,
})
export class ClaimResultsComponent {
@Input() results: ClaimEntity[];
@Input() selectedResults: ClaimEntity[];
@Input() localStoragePrefix: string = "";
@Input() basketLimit;
private isSelected(result: ClaimEntity) {
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;
}
add(item: ClaimEntity) {
// 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;
// }
let found: boolean = this.isSelected(item);
if (!found) {
this.selectedResults.push(item);
if (this.selectedResults != null) {
localStorage.setItem(this.localStoragePrefix, JSON.stringify(this.selectedResults));
}
}
}
}