Fix: Autocomplete could fuck up and was definitely doing it in product.
When checking for .name, it would error out if the input was null Fix: Journal addRow reset would reset Debit/Credit
This commit is contained in:
@@ -5,7 +5,7 @@ import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { BehaviorSubject, Observable, of as observableOf } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, map, switchMap } from 'rxjs/operators';
|
||||
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { AttendanceType } from '../attendance/attendance-type';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
@@ -33,7 +33,7 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
form: FormGroup<{
|
||||
startDate: FormControl<Date>;
|
||||
finishDate: FormControl<Date>;
|
||||
employee: FormControl<Employee | string | null>;
|
||||
employee: FormControl<string | null>;
|
||||
attendances: FormArray<
|
||||
FormGroup<{
|
||||
attendanceType: FormControl<number>;
|
||||
@@ -60,13 +60,11 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
this.form = new FormGroup({
|
||||
startDate: new FormControl(new Date(), { nonNullable: true }),
|
||||
finishDate: new FormControl(new Date(), { nonNullable: true }),
|
||||
employee: new FormControl<Employee | string | null>(null),
|
||||
employee: new FormControl<string | null>(null),
|
||||
attendances: new FormArray<FormGroup<{ attendanceType: FormControl<number> }>>([]),
|
||||
});
|
||||
// Listen to Employee Value Changes
|
||||
this.employees = this.form.controls.employee.valueChanges.pipe(
|
||||
map((x) => ((x as Employee).name !== undefined ? (x as Employee).name : (x as string))),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.employeeSer.autocomplete(x))),
|
||||
@@ -81,7 +79,7 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
this.attendanceTypes = data.attendanceTypes;
|
||||
this.form.controls.startDate.setValue(moment(this.info.startDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.controls.finishDate.setValue(moment(this.info.finishDate, 'DD-MMM-YYYY').toDate());
|
||||
this.form.controls.employee.setValue(this.info.employee);
|
||||
this.form.controls.employee.setValue(this.info.employee.name);
|
||||
this.form.controls.attendances.reset();
|
||||
this.info.body.forEach((x) =>
|
||||
this.form.controls.attendances.push(
|
||||
@@ -103,8 +101,8 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
|
||||
}, 0);
|
||||
}
|
||||
|
||||
displayFn(employee?: Employee): string {
|
||||
return employee ? employee.name : '';
|
||||
displayFn(employee?: Employee | string): string {
|
||||
return !employee ? '' : typeof employee === 'string' ? employee : employee.name;
|
||||
}
|
||||
|
||||
selected(event: MatAutocompleteSelectedEvent): void {
|
||||
|
||||
Reference in New Issue
Block a user