Moved to Angular 6.0
---- Pending * Table width for the points column in incentive * Linting * keyboard navigation where it was used earlier * can remove the unused totals calculated serverside in productledger * spinner and loading bars * Activate Guard for Employee Function tabs * Progress for Fingerprint uploads * deleted reconcile and receipe features as they were not being used * focus the right control on component load
This commit is contained in:
@ -0,0 +1,91 @@
|
||||
import {DataSource} from '@angular/cdk/collections';
|
||||
import {MatPaginator, MatSort} from '@angular/material';
|
||||
import {map, tap} from 'rxjs/operators';
|
||||
import {merge, Observable, of as observableOf} from 'rxjs';
|
||||
import {Employee} from '../employee';
|
||||
|
||||
|
||||
export class EmployeeListDataSource extends DataSource<Employee> {
|
||||
private dataObservable: Observable<Employee[]>;
|
||||
private filterValue: string;
|
||||
|
||||
constructor(private paginator: MatPaginator, private sort: MatSort, private filter: Observable<string>, public data: Employee[]) {
|
||||
super();
|
||||
this.filter = filter.pipe(
|
||||
tap(x => this.filterValue = x)
|
||||
);
|
||||
}
|
||||
|
||||
connect(): Observable<Employee[]> {
|
||||
this.dataObservable = observableOf(this.data);
|
||||
const dataMutations = [
|
||||
this.dataObservable,
|
||||
this.filter,
|
||||
this.paginator.page,
|
||||
this.sort.sortChange
|
||||
];
|
||||
|
||||
return merge(...dataMutations).pipe(
|
||||
map((x: any) => {
|
||||
return this.getPagedData(this.getSortedData(this.getFilteredData([...this.data])));
|
||||
}),
|
||||
tap((x: Employee[]) => this.paginator.length = x.length)
|
||||
);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
|
||||
private getFilteredData(data: Employee[]): Employee[] {
|
||||
const filter = (this.filterValue === undefined) ? '' : this.filterValue;
|
||||
return filter.split(' ').reduce((p: Employee[], c: string) => {
|
||||
return p.filter(x => {
|
||||
const employeeString = (
|
||||
x.code + ' ' + x.name + ' ' + x.designation + ' ' + x.costCentre + (x.isActive ? ' active' : ' deactive')
|
||||
).toLowerCase();
|
||||
return employeeString.indexOf(c) !== -1;
|
||||
}
|
||||
);
|
||||
}, Object.assign([], data));
|
||||
}
|
||||
|
||||
private getPagedData(data: Employee[]) {
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
return data.splice(startIndex, this.paginator.pageSize);
|
||||
}
|
||||
|
||||
private getSortedData(data: Employee[]) {
|
||||
if (!this.sort.active || this.sort.direction === '') {
|
||||
return data;
|
||||
}
|
||||
|
||||
return data.sort((a, b) => {
|
||||
const isAsc = this.sort.direction === 'asc';
|
||||
switch (this.sort.active) {
|
||||
case 'code':
|
||||
return compare(+a.code, +b.code, isAsc);
|
||||
case 'name':
|
||||
return compare(a.name, b.name, isAsc);
|
||||
case 'designation':
|
||||
return compare(a.designation, b.designation, isAsc);
|
||||
case 'salary':
|
||||
return compare(a.salary, b.salary, isAsc);
|
||||
case 'points':
|
||||
return compare(a.points, b.points, isAsc);
|
||||
case 'department':
|
||||
return compare(a.costCentre, b.costCentre, isAsc);
|
||||
case 'joiningDate':
|
||||
return compare(a.joiningDate, b.joiningDate, isAsc);
|
||||
case 'leavingDate':
|
||||
return compare(a.leavingDate, b.leavingDate, isAsc);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
|
||||
function compare(a, b, isAsc) {
|
||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Employees</mat-card-title>
|
||||
<a mat-button [routerLink]="['/Employee']">
|
||||
<mat-icon>add_box</mat-icon>
|
||||
Add
|
||||
</a>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"
|
||||
fxLayoutAlign="space-around start">
|
||||
<mat-form-field fxFlex>
|
||||
<input type="text" matInput #filterElement placeholder="Filter" formControlName="filter" autocomplete="off">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
||||
|
||||
<!-- Code Column -->
|
||||
<ng-container matColumnDef="code">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Code</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.code}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"><a [routerLink]="['/Employee', row.id]">{{row.name}}</a></mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Designation Column -->
|
||||
<ng-container matColumnDef="designation">
|
||||
<mat-header-cell *matHeaderCellDef>Designation</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.designation}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Salary Column -->
|
||||
<ng-container matColumnDef="salary">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Salary</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{row.salary | currency:'INR'}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Points Column -->
|
||||
<ng-container matColumnDef="points">
|
||||
<mat-header-cell *matHeaderCellDef class="right">Points</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row" class="right">{{row.points | number:'1.2-2'}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Department Column -->
|
||||
<ng-container matColumnDef="department">
|
||||
<mat-header-cell *matHeaderCellDef>Department</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.costCentre}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- JoiningDate Column -->
|
||||
<ng-container matColumnDef="joiningDate">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Joining On</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.joiningDate}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- LeavingDate Column -->
|
||||
<ng-container matColumnDef="leavingDate">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Left On</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.leavingDate}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
</mat-table>
|
||||
|
||||
<mat-paginator #paginator
|
||||
[length]="dataSource.data.length"
|
||||
[pageIndex]="0"
|
||||
[pageSize]="50"
|
||||
[pageSizeOptions]="[25, 50, 100, 250]">
|
||||
</mat-paginator>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
@ -0,0 +1,23 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {EmployeeListComponent} from './employee-list.component';
|
||||
|
||||
describe('EmployeeListComponent', () => {
|
||||
let component: EmployeeListComponent;
|
||||
let fixture: ComponentFixture<EmployeeListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [EmployeeListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(EmployeeListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,60 @@
|
||||
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||
import {MatPaginator, MatSort} from '@angular/material';
|
||||
import {EmployeeListDataSource} from './employee-list-datasource';
|
||||
import {Employee} from '../employee';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import {FormBuilder, FormGroup} from '@angular/forms';
|
||||
import {Observable} from 'rxjs';
|
||||
import {debounceTime, distinctUntilChanged, startWith} from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
selector: 'app-employee-list',
|
||||
templateUrl: './employee-list.component.html',
|
||||
styleUrls: ['./employee-list.component.css']
|
||||
})
|
||||
export class EmployeeListComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('filterElement') filterElement: ElementRef;
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
dataSource: EmployeeListDataSource;
|
||||
filter: Observable<string>;
|
||||
form: FormGroup;
|
||||
list: Employee[];
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['code', 'name', 'designation', 'salary', 'points', 'department', 'joiningDate', 'leavingDate'];
|
||||
|
||||
constructor(private route: ActivatedRoute, private fb: FormBuilder) {
|
||||
this.createForm();
|
||||
this.filter = this.listenToFilterChange();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
filter: ''
|
||||
});
|
||||
}
|
||||
|
||||
listenToFilterChange() {
|
||||
return this.form.get('filter').valueChanges
|
||||
.pipe(
|
||||
startWith(''),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged()
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: Employee[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new EmployeeListDataSource(this.paginator, this.sort, this.filter, this.list);
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.filterElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user