ng-implementation/my-workspace/projects/sae-lib/inputs/multi-selector/multi-selector.ts

95 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-09-25 16:55:38 +02:00
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
2025-09-22 14:53:02 +02:00
import {CommonModule} from '@angular/common';
2025-08-22 11:57:56 +02:00
@Component({
selector: 'sae-multi-selector',
2025-09-10 16:02:31 +02:00
imports: [
2025-09-22 14:53:02 +02:00
CommonModule
2025-09-10 16:02:31 +02:00
],
2025-08-22 11:57:56 +02:00
templateUrl: './multi-selector.html',
styleUrl: './multi-selector.scss'
})
2025-09-25 16:55:38 +02:00
export class MultiSelector implements OnInit {
2025-09-10 16:02:31 +02:00
@Input() disabled: boolean = false;
2025-08-22 12:52:30 +02:00
@Input() label!: string;
2025-09-25 16:55:38 +02:00
@Input() availableChoices: any = [{
label : 'aaaaaa',
value: 'AAAAA'
}];
@Input() selectedChoices: any = [ ];
2025-09-17 15:41:04 +02:00
@Input() displayDropdown: boolean = true;
2025-09-15 13:03:21 +02:00
@Input() store: any;
@Input() actionTypes: any;
2025-09-17 15:41:04 +02:00
2025-09-10 16:02:31 +02:00
@Output() selectedChoicesChange = new EventEmitter<any>();
@Output() availableChoicesChange = new EventEmitter<any>();
2025-08-22 11:57:56 +02:00
searchText: string = '';
2025-09-10 16:02:31 +02:00
constructor() {
2025-09-25 16:55:38 +02:00
}
ngOnInit() {
console.log('constructor multi selector', this.label, this.availableChoices, this.selectedChoices);
2025-09-10 16:02:31 +02:00
}
onSearchInput(event: any) {
this.searchText = (event?.target?.value || '').toLowerCase();
}
getFilteredSelectedChoices() {
if (!this.searchText) {
return this.selectedChoices || [];
}
return (this.selectedChoices || []).filter((c: any) =>
(c?.label || '').toLowerCase().includes(this.searchText)
);
}
getFilteredAvailableChoices() {
if (!this.searchText) {
return this.availableChoices || [];
}
return (this.availableChoices || []).filter((c: any) =>
(c?.label || '').toLowerCase().includes(this.searchText)
);
}
2025-09-10 16:02:31 +02:00
selectedChoicesChangeToggleItem(choice: any) {
console.log('toggle selected choice ', choice, 'in filter ', this.label);
this.selectedChoicesChange.emit(choice);
2025-09-25 16:55:38 +02:00
console.log(choice);
this.store.dispatch({
type: this.actionTypes.UPDATE_FILTER,
payload: {
filter: this.label,
selectedChoice: choice
}
})
2025-09-10 16:02:31 +02:00
}
availableChoicesChangeToggleItem(choice: any) {
this.availableChoicesChange.emit(choice);
console.log('toggle available choice ', choice, 'in filter ', this.label);
2025-09-25 16:55:38 +02:00
this.store.dispatch({
type: this.actionTypes.UPDATE_FILTER,
payload: {
filter: this.label,
availableChoice: choice
}
}
)
2025-09-10 16:02:31 +02:00
}
onClickInput() {
2025-09-23 18:54:13 +02:00
if (this.disabled) {
console.info('disabled input');
return;
}
this.displayDropdown = !this.displayDropdown;
console.log('Toggled dropdown:', this.displayDropdown);
2025-09-10 16:02:31 +02:00
}
2025-08-22 11:57:56 +02:00
}