import {Component, Input, Output, EventEmitter} from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import {ClaimResult} from '../claim-utils/claimEntities.class'; declare var UIkit:any; @Component({ selector: 'claim-results', template:` `, }) export class ClaimResultsComponent { @Input() results; @Input() selectedResults; @Input() localStoragePrefix:string = ""; private isSelected(id:string){ var found:boolean = false; for (var _i = 0; _i < this.selectedResults.length; _i++) { let item = this.selectedResults[_i]; if(item.id == id){ found=true; } } return found; } add(item){ if(this.selectedResults.length > 150){ UIkit.notification({ message : 'Your basket exceeds the number of allowed results (150)', status : 'warning', timeout : 1500, pos : 'top-center' }); return; } var found:boolean = this.isSelected( item.id); if (!found) { this.selectedResults.push(item); UIkit.notification({ message : 'A new research result added in your basket.', status : 'primary', timeout : 1500, pos : 'top-center' }); if(this.results != null){ localStorage.setItem(this.localStoragePrefix + "results", JSON.stringify(this.selectedResults)); } }else{ UIkit.notification({ message : 'The research result is already in your basket.', status : 'warning', timeout : 1500, pos : 'top-center' }); } } }