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:
@ -1,20 +1,20 @@
|
||||
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 { MatDialog } from '@angular/material/dialog';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import * as moment from 'moment';
|
||||
|
||||
import {ToasterService} from '../../core/toaster.service';
|
||||
import {EmployeeService} from '../employee.service';
|
||||
import {Employee} from '../employee';
|
||||
import {CostCentre} from '../../core/cost-centre';
|
||||
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { EmployeeService } from '../employee.service';
|
||||
import { Employee } from '../employee';
|
||||
import { CostCentre } from '../../core/cost-centre';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
|
||||
@Component({
|
||||
selector: 'app-employee-detail',
|
||||
templateUrl: './employee-detail.component.html',
|
||||
styleUrls: ['./employee-detail.component.css']
|
||||
styleUrls: ['./employee-detail.component.css'],
|
||||
})
|
||||
export class EmployeeDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@ -28,7 +28,7 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit {
|
||||
private dialog: MatDialog,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: EmployeeService
|
||||
private ser: EmployeeService,
|
||||
) {
|
||||
this.createForm();
|
||||
this.listenToIsActiveChanges();
|
||||
@ -36,7 +36,7 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
code: {value: '', disabled: true},
|
||||
code: { value: '', disabled: true },
|
||||
name: '',
|
||||
designation: '',
|
||||
salary: '',
|
||||
@ -44,16 +44,15 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit {
|
||||
isActive: '',
|
||||
costCentre: '',
|
||||
joiningDate: '',
|
||||
leavingDate: ''
|
||||
leavingDate: '',
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: Employee, costCentres: CostCentre[] }) => {
|
||||
this.costCentres = data.costCentres;
|
||||
this.showItem(data.item);
|
||||
});
|
||||
this.route.data.subscribe((data: { item: Employee; costCentres: CostCentre[] }) => {
|
||||
this.costCentres = data.costCentres;
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: Employee) {
|
||||
@ -66,8 +65,12 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit {
|
||||
points: this.item.points || '',
|
||||
isActive: this.item.isActive,
|
||||
costCentre: this.item.costCentre.id,
|
||||
joiningDate: this.item.joiningDate ? moment(this.item.joiningDate, 'DD-MMM-YYYY').toDate() : '',
|
||||
leavingDate: this.item.isActive ? null : moment(this.item.leavingDate, 'DD-MMM-YYYY').toDate()
|
||||
joiningDate: this.item.joiningDate
|
||||
? moment(this.item.joiningDate, 'DD-MMM-YYYY').toDate()
|
||||
: '',
|
||||
leavingDate: this.item.isActive
|
||||
? null
|
||||
: moment(this.item.leavingDate, 'DD-MMM-YYYY').toDate(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -78,40 +81,37 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
listenToIsActiveChanges(): void {
|
||||
this.form.get('isActive').valueChanges
|
||||
.subscribe(x => this.item.isActive = x);
|
||||
this.form.get('isActive').valueChanges.subscribe((x) => (this.item.isActive = x));
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/employees');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/employees');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/employees');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.delete(this.item.id).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/employees');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Employee?', content: 'Are you sure? This cannot be undone.'}
|
||||
data: { title: 'Delete Employee?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
@ -130,7 +130,9 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit {
|
||||
this.item.isActive = formModel.isActive;
|
||||
this.item.costCentre.id = formModel.costCentre;
|
||||
this.item.joiningDate = moment(formModel.joiningDate).format('DD-MMM-YYYY');
|
||||
this.item.leavingDate = (this.item.isActive) ? null : moment(formModel.leavingDate).format('DD-MMM-YYYY');
|
||||
this.item.leavingDate = this.item.isActive
|
||||
? null
|
||||
: moment(formModel.leavingDate).format('DD-MMM-YYYY');
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user