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,24 +1,24 @@
|
||||
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||
import {FormArray, FormBuilder, FormGroup} from '@angular/forms';
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormArray, 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 {EmployeeAttendanceDataSource} from './employee-attendance-datasource';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
|
||||
import { EmployeeAttendanceDataSource } from './employee-attendance-datasource';
|
||||
import * as moment from 'moment';
|
||||
import {AuthService} from '../auth/auth.service';
|
||||
import {ToasterService} from '../core/toaster.service';
|
||||
import {EmployeeAttendanceService} from './employee-attendance.service';
|
||||
import {EmployeeAttendance, EmployeeAttendanceItem} from './employee-attendance';
|
||||
import {EmployeeService} from '../employee/employee.service';
|
||||
import {Employee} from '../employee/employee';
|
||||
import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxjs/operators';
|
||||
import {AttendanceType} from '../attendance/attendance-type';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { EmployeeAttendanceService } from './employee-attendance.service';
|
||||
import { EmployeeAttendance, EmployeeAttendanceItem } from './employee-attendance';
|
||||
import { EmployeeService } from '../employee/employee.service';
|
||||
import { Employee } from '../employee/employee';
|
||||
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
|
||||
import { AttendanceType } from '../attendance/attendance-type';
|
||||
|
||||
@Component({
|
||||
selector: 'app-employee-attendance',
|
||||
templateUrl: './employee-attendance.component.html',
|
||||
styleUrls: ['./employee-attendance.component.css']
|
||||
styleUrls: ['./employee-attendance.component.css'],
|
||||
})
|
||||
export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('employeeElement', { static: true }) employeeElement: ElementRef;
|
||||
@@ -41,30 +41,34 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
private toaster: ToasterService,
|
||||
private auth: AuthService,
|
||||
private ser: EmployeeAttendanceService,
|
||||
private employeeSer: EmployeeService
|
||||
private employeeSer: EmployeeService,
|
||||
) {
|
||||
this.createForm();
|
||||
this.listenToEmployeeValueChanges();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { info: EmployeeAttendance, attendanceTypes: AttendanceType[] }) => {
|
||||
this.route.data.subscribe(
|
||||
(data: { info: EmployeeAttendance; attendanceTypes: AttendanceType[] }) => {
|
||||
this.info = data.info;
|
||||
this.attendanceTypes = data.attendanceTypes;
|
||||
this.form.get('startDate').setValue(moment(this.info.startDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.get('finishDate').setValue(moment(this.info.finishDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.get('employee').setValue(this.info.employee);
|
||||
this.form.setControl('attendances', this.fb.array(
|
||||
this.info.body.map(
|
||||
x => this.fb.group({
|
||||
attendanceType: x.attendanceType.id
|
||||
})
|
||||
)
|
||||
));
|
||||
this.form.setControl(
|
||||
'attendances',
|
||||
this.fb.array(
|
||||
this.info.body.map((x) =>
|
||||
this.fb.group({
|
||||
attendanceType: x.attendanceType.id,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
this.dataSource = new EmployeeAttendanceDataSource(this.employeeAttendanceObservable);
|
||||
this.employeeAttendanceObservable.next(this.info.body);
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
@@ -78,20 +82,18 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
startDate: '',
|
||||
finishDate: '',
|
||||
employee: '',
|
||||
attendances: this.fb.array([])
|
||||
attendances: this.fb.array([]),
|
||||
});
|
||||
}
|
||||
|
||||
listenToEmployeeValueChanges() {
|
||||
this.employees = this.form.get('employee').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 = this.form.get('employee').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))),
|
||||
);
|
||||
}
|
||||
|
||||
displayFn(employee?: Employee): string | undefined {
|
||||
@@ -102,10 +104,10 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
this.info.employee = event.option.value;
|
||||
}
|
||||
|
||||
getClass(index: number) {
|
||||
getClass(index: number) {
|
||||
const array = this.form.get('attendances') as FormArray;
|
||||
const id = array.controls[index].value.attendanceType;
|
||||
const name: string = this.attendanceTypes.filter(x => x.id === id)[0].name;
|
||||
const name: string = this.attendanceTypes.filter((x) => x.id === id)[0].name;
|
||||
return name.toLowerCase().replace(/(\s+\+\s+)|(\s+)/g, '-');
|
||||
}
|
||||
|
||||
@@ -116,22 +118,20 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
this.router.navigate(['/employee-attendance', this.info.employee.id], {
|
||||
queryParams: {
|
||||
startDate: this.info.startDate,
|
||||
finishDate: this.info.finishDate
|
||||
}
|
||||
finishDate: this.info.finishDate,
|
||||
},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.save(this.getEmployeeAttendance())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.save(this.getEmployeeAttendance()).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
getEmployeeAttendance(): EmployeeAttendance {
|
||||
|
||||
Reference in New Issue
Block a user