Feature: Filter Dashboard - Simple Filter for visible values
All checks were successful
Quality Check / Linting (push) Successful in 21s
Quality Check / Linting (pull_request) Successful in 21s

This commit is contained in:
Rajbir Singh 2025-01-15 15:17:27 +01:00
parent c08df8c2d8
commit 28f8cf7d64
3 changed files with 66 additions and 12 deletions

8
src/app/views/dashboard/Filter.d.ts vendored Normal file
View file

@ -0,0 +1,8 @@
import {Qualification} from '@core/ems';
interface Filter {
fuzzy: string,
qualification: Qualification|undefined
}
export default Filter;

View file

@ -3,11 +3,12 @@
<div class="dashboard__action-row"> <div class="dashboard__action-row">
<mat-form-field> <mat-form-field>
<mat-label>Search</mat-label> <mat-label>Search</mat-label>
<input matInput> <input matInput (keyup)="onFuzzyFilter($event)">
</mat-form-field> </mat-form-field>
<mat-form-field> <mat-form-field>
<mat-label>Qualification</mat-label> <mat-label>Qualification</mat-label>
<mat-select> <mat-select [(value)]="selectedQualificationFilter" (valueChange)="onFilterUpdate()">
<mat-option>None</mat-option>
@for (skill of ($qualifications|async); track skill) { @for (skill of ($qualifications|async); track skill) {
<mat-option [value]="skill">{{ skill.skill }}</mat-option> <mat-option [value]="skill">{{ skill.skill }}</mat-option>
} }
@ -18,7 +19,7 @@
<mat-icon>add</mat-icon> <mat-icon>add</mat-icon>
</button> </button>
</div> </div>
<mat-table [dataSource]="employeeDataSource" class="dashboard__employees"> <mat-table [dataSource]="employeeDataSource" class="dashboard__employees">
<ng-container matColumnDef="id"> <ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef>Id</th> <th mat-header-cell *matHeaderCellDef>Id</th>

View file

@ -10,6 +10,7 @@ import {MatSelectModule} from '@angular/material/select';
import {MatTableDataSource, MatTableModule} from '@angular/material/table'; import {MatTableDataSource, MatTableModule} from '@angular/material/table';
import {RouterLink} from '@angular/router'; import {RouterLink} from '@angular/router';
import {DeleteModelComponent} from '@app/delete-model/delete-model.component'; import {DeleteModelComponent} from '@app/delete-model/delete-model.component';
import Filter from '@app/views/dashboard/Filter';
import {AuthService} from '@core/auth/auth.service'; import {AuthService} from '@core/auth/auth.service';
import {Employee, EmployeeService, Qualification, QualificationService} from '@core/ems'; import {Employee, EmployeeService, Qualification, QualificationService} from '@core/ems';
import {NotificationService, NotificationType} from '@core/notification/notification.service'; import {NotificationService, NotificationType} from '@core/notification/notification.service';
@ -22,6 +23,8 @@ import {Observable} from 'rxjs';
styleUrl: './dashboard.component.scss' styleUrl: './dashboard.component.scss'
}) })
export class DashboardComponent { export class DashboardComponent {
selectedQualificationFilter: Qualification | undefined;
fuzzyFilter: string = '';
employeeDataSource: MatTableDataSource<Employee> = new MatTableDataSource<Employee>([]); employeeDataSource: MatTableDataSource<Employee> = new MatTableDataSource<Employee>([]);
employeesDisplayedColumns = ['id', 'first-name', 'last-name', 'skills', 'actions']; employeesDisplayedColumns = ['id', 'first-name', 'last-name', 'skills', 'actions'];
@ -37,6 +40,30 @@ export class DashboardComponent {
this.$qualifications = this.qualificationService.getAllQualifications(); this.$qualifications = this.qualificationService.getAllQualifications();
this.employeeService.getAllEmployees().subscribe((employees) => { this.employeeService.getAllEmployees().subscribe((employees) => {
this.employeeDataSource = new MatTableDataSource(employees); this.employeeDataSource = new MatTableDataSource(employees);
this.employeeDataSource.filterPredicate = (employee: Employee, rawFilter: string): boolean => {
const filter = JSON.parse(rawFilter) as Filter;
if (filter.fuzzy == '' && filter.qualification == undefined) {
return true;
}
if (
filter.qualification != undefined
&& !employee.skillSet.map((skill) => skill.id).includes(filter.qualification.id)
) {
return false;
}
if (
filter.fuzzy != ''
&& !employee.id.toString().includes(filter.fuzzy)
&& !employee.firstName.toLowerCase().includes(filter.fuzzy)
&& !employee.lastName.toLowerCase().includes(filter.fuzzy)
) {
return false;
}
return true;
};
}); });
} }
@ -66,4 +93,22 @@ export class DashboardComponent {
}); });
}); });
} }
onFuzzyFilter(event: KeyboardEvent) {
this.fuzzyFilter = (event.target as HTMLInputElement).value;
this.onFilterUpdate();
}
onFilterUpdate() {
const skill = this.selectedQualificationFilter;
const fuzzy = this.fuzzyFilter;
if (skill == undefined && fuzzy == '') {
this.employeeDataSource.filter = '';
return;
}
this.employeeDataSource.filter = JSON.stringify({
qualification: skill,
fuzzy: fuzzy.toLowerCase()
} as Filter);
}
} }