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

Merge branch '226-annuaire-filters' into 'dev'

fix(annuaire): filters

See merge request !500
parents e3dc13d4 53a5cde6
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 { ...@@ -11,48 +11,37 @@ export class FilterModalComponent implements OnInit, OnChanges {
@Input() public modalType: TypeModal; @Input() public modalType: TypeModal;
@Input() public filtersTypes: string[]; @Input() public filtersTypes: string[];
@Input() public checkedFilters: string[]; @Input() public checkedFilters: string[];
@Output() searchEvent = new EventEmitter(); @Input() public jobFilterChecked: string[];
@Output() closeEvent = new EventEmitter(); @Input() public employerFilterChecked: string[];
@Output() fetchResults = new EventEmitter<string[]>();
public buttonTypeEnum = ButtonType; public buttonTypeEnum = ButtonType;
public toggledCategories: string[] = []; public toggledCategories: string[] = [];
public currentCheckedFilters: string[] = []; public currentCheckedFilters: string[] = [];
ngOnInit(): void { ngOnInit(): void {
this.currentCheckedFilters = [...this.checkedFilters]; this.currentCheckedFilters = this.checkedFilters.slice();
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
if (changes.modalType) this.currentCheckedFilters = []; if (changes.modalType) this.currentCheckedFilters = this.checkedFilters.slice();
} }
public isFilterChecked(filter: string): boolean { public isFilterChecked(filter: string): boolean {
return this.currentCheckedFilters.findIndex((_filter) => _filter === filter) > -1; return this.currentCheckedFilters.includes(filter);
} }
public toggleCheckbox(filter: string): void { public toggleCheckbox(filter: string): void {
const filterExists = this.currentCheckedFilters.findIndex((_filterChecked) => _filterChecked === filter) !== -1; const filterExists = this.currentCheckedFilters.includes(filter);
if (!filterExists) { if (!filterExists) {
const index = this.filtersTypes.findIndex((_filter) => _filter === filter); const index = this.filtersTypes.indexOf(filter);
this.currentCheckedFilters.push(this.filtersTypes[index]); this.currentCheckedFilters.push(this.filtersTypes[index]);
} else { } else {
const filterToRemove = this.currentCheckedFilters.findIndex((_filterChecked) => _filterChecked === filter); const filterToRemove = this.currentCheckedFilters.indexOf(filter);
this.currentCheckedFilters.splice(filterToRemove); 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 { public getModalType(): string {
switch (this.modalType) { switch (this.modalType) {
case TypeModal.employers: case TypeModal.employers:
...@@ -64,12 +53,18 @@ export class FilterModalComponent implements OnInit, OnChanges { ...@@ -64,12 +53,18 @@ export class FilterModalComponent implements OnInit, OnChanges {
} }
} }
public closeModal(): void { /** Clear only filters in the current modal */
this.closeEvent.emit(); 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 { public onSubmitFilters(): void {
this.checkedFilters = this.currentCheckedFilters; this.fetchResults.emit(this.currentCheckedFilters);
this.emitModules(this.currentCheckedFilters);
} }
} }
...@@ -57,8 +57,10 @@ ...@@ -57,8 +57,10 @@
<app-filter-modal <app-filter-modal
[modalType]="modalTypeOpened" [modalType]="modalTypeOpened"
[checkedFilters]="searchService.checkedFilterList" [checkedFilters]="searchService.checkedFilterList"
[employerFilterChecked]="employerFilterChecked"
[jobFilterChecked]="jobFilterChecked"
[filtersTypes]="getModalCategory()" [filtersTypes]="getModalCategory()"
(searchEvent)="fetchResults($event)" (fetchResults)="fetchResults($event)"
(closeEvent)="closeModal()" (closeEvent)="closeModal()"
/> />
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment