Fix: Login deleting old clients was conflicting with login history
Chore: Moved to angular linting using the recommended plugins / settings
This commit is contained in:
@ -8,9 +8,7 @@ import { map, tap } from 'rxjs/operators';
|
||||
import { Employee } from '../employee';
|
||||
|
||||
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
|
||||
function compare(a: string | number, b: string | number, isAsc: boolean) {
|
||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
}
|
||||
const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
export class EmployeeListDataSource extends DataSource<Employee> {
|
||||
private filterValue = '';
|
||||
|
||||
@ -35,14 +33,20 @@ export class EmployeeListDataSource extends DataSource<Employee> {
|
||||
| EventEmitter<PageEvent>
|
||||
| EventEmitter<Sort>
|
||||
)[] = [observableOf(this.data), this.filter];
|
||||
if (this.paginator) dataMutations.push((this.paginator as MatPaginator).page);
|
||||
if (this.sort) dataMutations.push((this.sort as MatSort).sortChange);
|
||||
if (this.paginator) {
|
||||
dataMutations.push((this.paginator as MatPaginator).page);
|
||||
}
|
||||
if (this.sort) {
|
||||
dataMutations.push((this.sort as MatSort).sortChange);
|
||||
}
|
||||
|
||||
return merge(...dataMutations)
|
||||
.pipe(
|
||||
map(() => this.getFilteredData([...this.data])),
|
||||
tap((x: Employee[]) => {
|
||||
if (this.paginator) this.paginator.length = x.length;
|
||||
if (this.paginator) {
|
||||
this.paginator.length = x.length;
|
||||
}
|
||||
}),
|
||||
)
|
||||
.pipe(map((x: Employee[]) => this.getPagedData(this.getSortedData(x))));
|
||||
@ -64,13 +68,17 @@ export class EmployeeListDataSource extends DataSource<Employee> {
|
||||
}
|
||||
|
||||
private getPagedData(data: Employee[]) {
|
||||
if (this.paginator === undefined) return data;
|
||||
if (this.paginator === undefined) {
|
||||
return data;
|
||||
}
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
return data.splice(startIndex, this.paginator.pageSize);
|
||||
}
|
||||
|
||||
private getSortedData(data: Employee[]) {
|
||||
if (this.sort === undefined) return data;
|
||||
if (this.sort === undefined) {
|
||||
return data;
|
||||
}
|
||||
if (!this.sort.active || this.sort.direction === '') {
|
||||
return data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user