132 lines
4.7 KiB
TypeScript
132 lines
4.7 KiB
TypeScript
import {Component, EventEmitter, Input, OnInit, Output, ChangeDetectionStrategy} from '@angular/core';
|
|
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
|
import {WorkPlanGroup} from '../../../_models/Attendance/workPlanGroup';
|
|
import {EmployeeServices} from '../../../_services/employee/employee.service';
|
|
import {AttendanceServices} from '../../../_services/attendance/attendance.service';
|
|
import {ApiService} from '../../../app.api.service';
|
|
import {HRMNotificationService} from '../../../app.notification.service';
|
|
import {DataTransferService} from '../../../data.transfer.service';
|
|
import {AppWindowPopUp} from '../../../app.windowPopup.service';
|
|
import {UntilityHandlerService} from '../../../utility.hanldler.service';
|
|
import {Shift} from '../../../_models/Attendance/shift';
|
|
import {EnumDayOfWeek, EnumExtension, EnumStatus, EnumWorkPlanGroup, HolidayDayOfWeek} from '../../../_models/enums';
|
|
import {ShiftRotation} from '../../../_models/Attendance/shiftRotation';
|
|
import { loadingPanelService } from '../../../hrm-loding panel/loding.panel.service';
|
|
|
|
import { LoadingPanelComponent } from 'src/app/hrm-loding panel/loading-panel.component';
|
|
import { ButtonModule } from '@progress/kendo-angular-buttons';
|
|
import { DropDownListModule } from '@progress/kendo-angular-dropdowns';
|
|
import { ReactiveFormsModule } from '@angular/forms';
|
|
import { FormsModule } from '@angular/forms';
|
|
import { DialogModule } from '@progress/kendo-angular-dialog';
|
|
import { KENDO_GRID } from '@progress/kendo-angular-grid';
|
|
import { DatePickerModule } from '@progress/kendo-angular-dateinputs';
|
|
@Component({
|
|
selector: 'app-roster-entry',
|
|
templateUrl: './roster-entry.component.html',
|
|
styleUrls: ['./roster-entry.component.css'],
|
|
changeDetection: ChangeDetectionStrategy.Eager,
|
|
standalone: false,
|
|
|
|
})
|
|
|
|
export class RosterEntryComponent implements OnInit {
|
|
rosterForm: FormGroup;
|
|
workPlanGroup: WorkPlanGroup;
|
|
shiftRotationList: ShiftRotation[];
|
|
shifts: Shift[];
|
|
isTypeDisable = false;
|
|
types: any = EnumExtension.getNamesAndValues(EnumWorkPlanGroup);
|
|
holidays: any = EnumExtension.getNamesAndValues(HolidayDayOfWeek);
|
|
@Output() saveHandler = new EventEmitter<WorkPlanGroup>();
|
|
|
|
@Input()
|
|
public set InputObject(InputObject: WorkPlanGroup) {
|
|
this.workPlanGroup = InputObject;
|
|
}
|
|
|
|
constructor(public employeeService: EmployeeServices,
|
|
public attendanceServices: AttendanceServices,
|
|
public apiService: ApiService,
|
|
public notificationService: HRMNotificationService,
|
|
public dataTransferService: DataTransferService,
|
|
public WindowPopUp: AppWindowPopUp,
|
|
public utilityHandlerService: UntilityHandlerService, public loadingPanel: loadingPanelService,
|
|
) {
|
|
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.createForm();
|
|
this.loadData();
|
|
}
|
|
|
|
createForm() {
|
|
this.rosterForm = new FormBuilder().group({
|
|
group: ['', Validators.required],
|
|
type: ['', Validators.required],
|
|
initialShift: [''],
|
|
saturday: [''],
|
|
sunday: [''],
|
|
monday: [''],
|
|
tuesday: [''],
|
|
wednesday: [''],
|
|
thursday: [''],
|
|
friday: [''],
|
|
weeklyHoliday1: ['', Validators.required],
|
|
});
|
|
}
|
|
|
|
loadData() {
|
|
this.attendanceServices.getShifts(EnumStatus.Regardless).subscribe(
|
|
(resp) => {
|
|
this.shifts = resp;
|
|
},
|
|
() => {
|
|
},
|
|
() => {
|
|
}
|
|
);
|
|
|
|
this.attendanceServices.getShiftRotationByStatus(EnumStatus.Active).subscribe(
|
|
(resp: any) => {
|
|
this.shiftRotationList = resp;
|
|
},
|
|
() => {},
|
|
() => {}
|
|
);
|
|
|
|
}
|
|
|
|
selectedType() {
|
|
//console.log(this.workPlanGroup.type, EnumWorkPlanGroup.Fixed);
|
|
this.isTypeDisable = this.workPlanGroup.type !== EnumWorkPlanGroup.Fixed;
|
|
}
|
|
|
|
|
|
onCancel() {
|
|
this.saveHandler.emit(undefined);
|
|
}
|
|
|
|
onSave() {
|
|
if (!this.rosterForm.valid) {
|
|
return;
|
|
}
|
|
this.loadingPanel.ShowLoadingPanel = true;
|
|
this.attendanceServices.saveWorkPlanGroup(this.workPlanGroup).subscribe(
|
|
(resc) => {
|
|
this.workPlanGroup.id = resc;
|
|
},
|
|
(x) => {
|
|
this.loadingPanel.ShowLoadingPanel = false;
|
|
this.notificationService.showError("Failed to save data")
|
|
},
|
|
() => {
|
|
this.loadingPanel.ShowLoadingPanel = false;
|
|
this.saveHandler.emit(this.workPlanGroup);
|
|
this.notificationService.showSuccess("Data successfully saved.")
|
|
}
|
|
);
|
|
}
|
|
}
|