Moved from tslint to eslint as tslint was depreciated.

Added prettier and also prettied all the typescript files using prettier

ESLint is using the AirBnB rules which are the most strict to lint the files.
This commit is contained in:
tanshu committed 2020-10-01 21:28:12 +05:30
1 parent 40e79ff949
commit 1350870f9e
545 files changed
+8455 -7036

No files matched your search

@@ -1,24 +1,24 @@
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import {FormBuilder, FormGroup} from '@angular/forms';
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
import { MatDialog } from '@angular/material/dialog';
import {ActivatedRoute, Router} from '@angular/router';
import {BehaviorSubject, Observable, of as observableOf} from 'rxjs';
import {EmployeeBenefitsDataSource} from './employee-benefits-datasource';
import {VoucherService} from '../core/voucher.service';
import {EmployeeBenefit, Voucher} from '../core/voucher';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
import { EmployeeBenefitsDataSource } from './employee-benefits-datasource';
import { VoucherService } from '../core/voucher.service';
import { EmployeeBenefit, Voucher } from '../core/voucher';
import * as moment from 'moment';
import {AuthService} from '../auth/auth.service';
import {ConfirmDialogComponent} from '../shared/confirm-dialog/confirm-dialog.component';
import {ToasterService} from '../core/toaster.service';
import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators';
import {Employee} from '../employee/employee';
import {EmployeeService} from '../employee/employee.service';
import { AuthService } from '../auth/auth.service';
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
import { ToasterService } from '../core/toaster.service';
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
import { Employee } from '../employee/employee';
import { EmployeeService } from '../employee/employee.service';
@Component({
selector: 'app-employee-benefits',
templateUrl: './employee-benefits.component.html',
styleUrls: ['./employee-benefits.component.css']
styleUrls: ['./employee-benefits.component.css'],
})
export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
@ViewChild('employeeElement', { static: true }) employeeElement: ElementRef;
@@ -30,7 +30,15 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
accBal: any;
displayedColumns = [
'name', 'designation', 'department', 'grossSalary', 'daysWorked', 'esiEmployee', 'pfEmployee', 'esiEmployer', 'pfEmployer'
'name',
'designation',
'department',
'grossSalary',
'daysWorked',
'esiEmployee',
'pfEmployee',
'esiEmployer',
'pfEmployer',
];
employees: Observable<Employee[]>;
@@ -43,17 +51,16 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
private toaster: ToasterService,
private auth: AuthService,
private ser: VoucherService,
private employeeSer: EmployeeService
private employeeSer: EmployeeService,
) {
this.createForm();
this.setupEmployeeAutocomplete();
}
ngOnInit() {
this.route.data
.subscribe((data: { voucher: Voucher }) => {
this.loadVoucher(data.voucher);
});
this.route.data.subscribe((data: { voucher: Voucher }) => {
this.loadVoucher(data.voucher);
});
}
ngAfterViewInit() {
@@ -69,8 +76,8 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
addRow: {
employee: '1',
grossSalary: '',
daysWorked: ''
}
daysWorked: '',
},
});
this.dataSource = new EmployeeBenefitsDataSource(this.benefitsObservable);
this.benefitsObservable.next(this.voucher.employeeBenefits);
@@ -82,22 +89,20 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
addRow: this.fb.group({
employee: '',
grossSalary: '',
daysWorked: ''
daysWorked: '',
}),
});
}
setupEmployeeAutocomplete(): void {
const control = this.form.get('addRow').get('employee');
this.employees = control.valueChanges
.pipe(
startWith(null),
map(x => (x !== null && x.length >= 1) ? x : null),
debounceTime(150),
distinctUntilChanged(),
switchMap(x => (x === null) ? observableOf([]) : this.employeeSer.autocomplete(x))
);
this.employees = control.valueChanges.pipe(
startWith(null),
map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150),
distinctUntilChanged(),
switchMap((x) => (x === null ? observableOf([]) : this.employeeSer.autocomplete(x))),
);
}
displayEmployeeName(employee?: Employee): string | undefined {
@@ -109,7 +114,9 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
}
addRow() {
const oldFiltered = this.voucher.employeeBenefits.filter((x) => x.employee.id === this.employee.id);
const oldFiltered = this.voucher.employeeBenefits.filter(
(x) => x.employee.id === this.employee.id,
);
if (oldFiltered.length) {
this.toaster.show('Danger', 'Employee has already been added');
return;
@@ -130,7 +137,7 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
esiEmployee: esi.ee,
pfEmployee: pf.ee,
esiEmployer: esi.er,
pfEmployer: pf.er
pfEmployer: pf.er,
});
this.benefitsObservable.next(this.voucher.employeeBenefits);
this.resetAddRow();
@@ -140,7 +147,7 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
this.form.get('addRow').reset({
employee: '',
grossSalary: null,
daysWorked: null
daysWorked: null,
});
this.employee = null;
setTimeout(() => {
@@ -157,18 +164,30 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
const limit = 21000,
employeeRate = 0.0175,
employerRate = 0.0475,
employee = (grossSalary > limit) ? 0 : Math.ceil(employeeRate * grossSalary * daysWorked / daysInMonth),
employer = (grossSalary > limit) ? 0 : Math.ceil(employerRate * grossSalary * daysWorked / daysInMonth);
return {ee: employee, er: employer, both: employee + employer};
employee =
grossSalary > limit
? 0
: Math.ceil((employeeRate * grossSalary * daysWorked) / daysInMonth),
employer =
grossSalary > limit
? 0
: Math.ceil((employerRate * grossSalary * daysWorked) / daysInMonth);
return { ee: employee, er: employer, both: employee + employer };
}
getPf(grossSalary, daysWorked, daysInMonth) {
const limit = 15000,
employeeRate = 0.12,
employerRate = 0.12 + 0.011 + 0.005 + 0.0001,
employee = (grossSalary > limit) ? 0 : Math.ceil(employeeRate * grossSalary * daysWorked / daysInMonth),
employer = (grossSalary > limit) ? 0 : Math.ceil(employerRate * grossSalary * daysWorked / daysInMonth);
return {ee: employee, er: employer, both: employee + employer};
employee =
grossSalary > limit
? 0
: Math.ceil((employeeRate * grossSalary * daysWorked) / daysInMonth),
employer =
grossSalary > limit
? 0
: Math.ceil((employerRate * grossSalary * daysWorked) / daysInMonth);
return { ee: employee, er: employer, both: employee + employer };
}
canSave() {
@@ -177,39 +196,40 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
} else if (this.voucher.posted && this.auth.user.perms.indexOf('edit-posted-vouchers') !== -1) {
return true;
} else {
return this.voucher.user.id === this.auth.user.id || this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1;
return (
this.voucher.user.id === this.auth.user.id ||
this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1
);
}
}
post() {
this.ser.post(this.voucher.id)
.subscribe(
(result) => {
this.loadVoucher(result);
this.toaster.show('Success', 'Voucher Posted');
},
(error) => {
this.toaster.show('Danger', error);
}
);
this.ser.post(this.voucher.id).subscribe(
(result) => {
this.loadVoucher(result);
this.toaster.show('Success', 'Voucher Posted');
},
(error) => {
this.toaster.show('Danger', error);
},
);
}
save() {
const voucher: Voucher = this.getVoucher();
this.ser.saveOrUpdate(voucher)
.subscribe(
(result) => {
this.toaster.show('Success', '');
if (voucher.id === result.id) {
this.loadVoucher(result);
} else {
this.ser.saveOrUpdate(voucher).subscribe(
(result) => {
this.toaster.show('Success', '');
if (voucher.id === result.id) {
this.loadVoucher(result);
} else {
this.router.navigate(['/employee-benefits', result.id]);
}
},
(error) => {
this.toaster.show('Danger', error);
}
);
},
(error) => {
this.toaster.show('Danger', error);
},
);
}
getVoucher(): Voucher {
@@ -219,22 +239,21 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
}
delete() {
this.ser.delete(this.voucher.id)
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigate(['/employee-benefits'], {replaceUrl: true});
},
(error) => {
this.toaster.show('Danger', error);
}
);
this.ser.delete(this.voucher.id).subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigate(['/employee-benefits'], { replaceUrl: true });
},
(error) => {
this.toaster.show('Danger', error);
},
);
}
confirmDelete(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Delete Voucher?', content: 'Are you sure? This cannot be undone.'}
data: { title: 'Delete Voucher?', content: 'Are you sure? This cannot be undone.' },
});
dialogRef.afterClosed().subscribe((result: boolean) => {