Skip to content
Snippets Groups Projects
Commit 53a5cde6 authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

fix(annuaire): filters

parent e3dc13d4
No related branches found
No related tags found
2 merge requests!525V2.3.0,!500fix(annuaire): filters
......@@ -11,48 +11,37 @@ export class FilterModalComponent implements OnInit, OnChanges {
@Input() public modalType: TypeModal;
@Input() public filtersTypes: string[];
@Input() public checkedFilters: string[];
@Output() searchEvent = new EventEmitter();
@Output() closeEvent = new EventEmitter();
@Input() public jobFilterChecked: string[];
@Input() public employerFilterChecked: string[];
@Output() fetchResults = new EventEmitter<string[]>();
public buttonTypeEnum = ButtonType;
public toggledCategories: string[] = [];
public currentCheckedFilters: string[] = [];
ngOnInit(): void {
this.currentCheckedFilters = [...this.checkedFilters];
this.currentCheckedFilters = this.checkedFilters.slice();
}
ngOnChanges(changes: SimpleChanges): void {
if (changes.modalType) this.currentCheckedFilters = [];
if (changes.modalType) this.currentCheckedFilters = this.checkedFilters.slice();
}
public isFilterChecked(filter: string): boolean {
return this.currentCheckedFilters.findIndex((_filter) => _filter === filter) > -1;
return this.currentCheckedFilters.includes(filter);
}
public toggleCheckbox(filter: string): void {
const filterExists = this.currentCheckedFilters.findIndex((_filterChecked) => _filterChecked === filter) !== -1;
const filterExists = this.currentCheckedFilters.includes(filter);
if (!filterExists) {
const index = this.filtersTypes.findIndex((_filter) => _filter === filter);
const index = this.filtersTypes.indexOf(filter);
this.currentCheckedFilters.push(this.filtersTypes[index]);
} else {
const filterToRemove = this.currentCheckedFilters.findIndex((_filterChecked) => _filterChecked === filter);
this.currentCheckedFilters.splice(filterToRemove);
const filterToRemove = this.currentCheckedFilters.indexOf(filter);
this.currentCheckedFilters.splice(filterToRemove, 1);
}
}
// Clear only filters in the current modal
public clearFilters(): void {
this.checkedFilters = [];
this.currentCheckedFilters = [];
this.emitModules(this.checkedFilters);
}
// Sends an array containing all modules
public emitModules(filters: string[]): void {
this.searchEvent.emit(filters);
}
public getModalType(): string {
switch (this.modalType) {
case TypeModal.employers:
......@@ -64,12 +53,18 @@ export class FilterModalComponent implements OnInit, OnChanges {
}
}
public closeModal(): void {
this.closeEvent.emit();
/** Clear only filters in the current modal */
public clearFilters(): void {
if (this.modalType === TypeModal.jobs) {
this.currentCheckedFilters = this.employerFilterChecked;
} else if (this.modalType === TypeModal.employers) {
this.currentCheckedFilters = this.jobFilterChecked;
}
this.fetchResults.emit(this.currentCheckedFilters);
}
public onSubmitFilters(): void {
this.checkedFilters = this.currentCheckedFilters;
this.emitModules(this.currentCheckedFilters);
this.fetchResults.emit(this.currentCheckedFilters);
}
}
......@@ -57,8 +57,10 @@
<app-filter-modal
[modalType]="modalTypeOpened"
[checkedFilters]="searchService.checkedFilterList"
[employerFilterChecked]="employerFilterChecked"
[jobFilterChecked]="jobFilterChecked"
[filtersTypes]="getModalCategory()"
(searchEvent)="fetchResults($event)"
(fetchResults)="fetchResults($event)"
(closeEvent)="closeModal()"
/>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment