Feature: Filter Dashboard - Simple Filter for visible values
This commit is contained in:
parent
c08df8c2d8
commit
28f8cf7d64
3 changed files with 66 additions and 12 deletions
8
src/app/views/dashboard/Filter.d.ts
vendored
Normal file
8
src/app/views/dashboard/Filter.d.ts
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
import {Qualification} from '@core/ems';
|
||||||
|
|
||||||
|
interface Filter {
|
||||||
|
fuzzy: string,
|
||||||
|
qualification: Qualification|undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Filter;
|
|
@ -3,13 +3,14 @@
|
||||||
<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>
|
||||||
}
|
}
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
@ -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>
|
||||||
|
|
|
@ -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'];
|
||||||
|
@ -34,31 +37,55 @@ export class DashboardComponent {
|
||||||
private dialog: MatDialog,
|
private dialog: MatDialog,
|
||||||
private notifications: NotificationService
|
private notifications: NotificationService
|
||||||
) {
|
) {
|
||||||
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;
|
||||||
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onDelete(employee: Employee){
|
onDelete(employee: Employee) {
|
||||||
const dialogRef = this.dialog.open(DeleteModelComponent, {
|
const dialogRef = this.dialog.open(DeleteModelComponent, {
|
||||||
data:{
|
data: {
|
||||||
title:`Delete ${employee.firstName} ${employee.lastName}`,
|
title: `Delete ${employee.firstName} ${employee.lastName}`,
|
||||||
description: `Do you really want to delete ${employee.firstName} ${employee.lastName}?`,
|
description: `Do you really want to delete ${employee.firstName} ${employee.lastName}?`,
|
||||||
cancel: 'No',
|
cancel: 'No',
|
||||||
ok: 'Yes',
|
ok: 'Yes',
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dialogRef.afterClosed().subscribe((accepted:boolean) => {
|
dialogRef.afterClosed().subscribe((accepted: boolean) => {
|
||||||
if (!accepted){
|
if (!accepted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.employeeService.deleteEmployee({id:employee.id}).subscribe(()=> {
|
this.employeeService.deleteEmployee({id: employee.id}).subscribe(() => {
|
||||||
const data = this.employeeDataSource.data;
|
const data = this.employeeDataSource.data;
|
||||||
const i = data.indexOf(employee);
|
const i = data.indexOf(employee);
|
||||||
if (i != -1){
|
if (i != -1) {
|
||||||
data.splice(i, 1);
|
data.splice(i, 1);
|
||||||
this.employeeDataSource.data = data;
|
this.employeeDataSource.data = data;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue