-
Notifications
You must be signed in to change notification settings - Fork 0
/
options-filter.ts
39 lines (29 loc) · 997 Bytes
/
options-filter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Component, EventEmitter, Input } from "@angular/core";
import { Filter } from "clarity-angular";
@Component({
moduleId: module.id,
selector: "options-filter",
templateUrl: "options-filter.html",
styleUrls: ["options-filter.css"]
})
export class OptionsFilter implements Filter<any> {
@Input()
options: any[];
@Input()
property: string;
selectedOptions: { [option: string]: boolean } = {};
nbOptions = 0;
changes: EventEmitter<any> = new EventEmitter<any>(false);
toggleBox(i) {
let option = this.options[i].value;
this.selectedOptions[option] = !this.selectedOptions[option];
this.selectedOptions[option] ? this.nbOptions++ : this.nbOptions--;
this.changes.emit(true);
}
accepts(object: any) {
return this.nbOptions === 0 || this.selectedOptions[object[this.property]];
}
isActive(): boolean {
return this.nbOptions > 0;
}
}