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: `
|
2022-07-18 17:56:59 +02:00
|
|
|
<div *ngIf="results.length > 0 " class="uk-margin-top">
|
2023-07-04 09:16:08 +02:00
|
|
|
<div *ngFor="let entity of results" class="uk-card">
|
|
|
|
<div class="uk-padding-small">
|
2019-07-23 14:23:12 +02:00
|
|
|
<div class="uk-grid">
|
2022-05-16 16:25:35 +02:00
|
|
|
<div class="uk-width-expand uk-margin-right">
|
2022-06-06 16:35:26 +02:00
|
|
|
<claim-title [entity]="entity" [showIcon]="false"></claim-title>
|
2019-07-23 14:23:12 +02:00
|
|
|
<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':''">
|
2023-07-04 09:16:08 +02:00
|
|
|
<button class="linking-add-button uk-icon-button-small" [class.uk-disabled]="(this.selectedResults.length>=basketLimit)" *ngIf="!isSelected(entity)"
|
2019-07-23 14:23:12 +02:00
|
|
|
(click)="add(entity)">
|
2022-07-18 17:56:59 +02:00
|
|
|
<icon name="add" [flex]="true"></icon>
|
|
|
|
</button>
|
2023-07-04 09:16:08 +02:00
|
|
|
<button *ngIf="isSelected(entity)" class="linking-selected-button uk-icon-button-small" (click)="remove(entity)">
|
2022-07-18 17:56:59 +02:00
|
|
|
<icon name="check" [flex]="true"></icon>
|
|
|
|
</button>
|
2019-07-23 14:23:12 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-16 17:54:22 +01:00
|
|
|
</div>
|
2023-07-04 09:16:08 +02:00
|
|
|
</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;
|
2023-07-04 09:16:08 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
}
|
|
|
|
|
2022-07-18 23:46:45 +02:00
|
|
|
public isSelected(item: ClaimEntity) {
|
|
|
|
return !!this.selectedResults.find(result => item.id === result.id);
|
2019-07-23 14:23:12 +02:00
|
|
|
}
|
2018-05-03 11:58:30 +02:00
|
|
|
|
2019-07-23 14:23:12 +02:00
|
|
|
add(item: ClaimEntity) {
|
|
|
|
let found: boolean = this.isSelected(item);
|
|
|
|
if (!found) {
|
|
|
|
this.selectedResults.push(item);
|
2022-07-18 23:46:45 +02:00
|
|
|
localStorage.setItem(this.localStoragePrefix, JSON.stringify(this.selectedResults));
|
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
|
|
|
|
2022-07-18 23:46:45 +02:00
|
|
|
remove(item: ClaimEntity) {
|
|
|
|
const index: number = this.selectedResults.findIndex(result => item.id === result.id);
|
2022-05-11 17:46:51 +02:00
|
|
|
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
|
|
|
}
|