integrasi edit scheduler

This commit is contained in:
Fuzi_fauzia 2024-08-26 11:43:22 +07:00
parent 45e280c007
commit ecef25f30d
3 changed files with 29 additions and 3 deletions

View File

@ -83,7 +83,7 @@
</div> </div>
<!-- Checkbox for Repeat --> <!-- Checkbox for Repeat -->
<div class="form-group col-md-12"> <!-- <div class="form-group col-md-12">
<label style="color: #242222">Repeat:</label> <label style="color: #242222">Repeat:</label>
<div class="form-check"> <div class="form-check">
<input <input
@ -93,7 +93,7 @@
/> />
<label class="form-check-label" style="color: #242222">Yes</label> <label class="form-check-label" style="color: #242222">Yes</label>
</div> </div>
</div> </div> -->
<div class="form-group col-md-12"> <div class="form-group col-md-12">
<label for="active" style="color: #242222">Active:</label> <label for="active" style="color: #242222">Active:</label>

View File

@ -16,6 +16,8 @@ import { DeviceService } from "../../service/device.service";
}) })
export class ControlSchedulerComponent { export class ControlSchedulerComponent {
@Input() deviceId: any; @Input() deviceId: any;
@Input() data: any;
@Input() mode: any;
labelModal: string = ""; labelModal: string = "";
myForm: FormGroup; myForm: FormGroup;
dataSwitch = [ dataSwitch = [
@ -60,6 +62,12 @@ export class ControlSchedulerComponent {
ngOnInit() { ngOnInit() {
this.createForm(); this.createForm();
if (this.mode === 'add') {
this.labelModal = "Add Scheduler";
} else if (this.mode === 'edit') {
this.editForm();
this.labelModal = "Edit Scheduler";
}
} }
createForm() { createForm() {
@ -80,6 +88,24 @@ export class ControlSchedulerComponent {
this.myForm = this.fb.group(controls); this.myForm = this.fb.group(controls);
} }
editForm(){
this.selectedDays = this.data.days || [];
this.myForm.patchValue({
name: this.data.name,
timeset: this.data.timeset,
recurring: this.data.recurring,
active: this.data.active,
switch: this.data.switch,
});
// Patch the form with the selected days
this.selectedDays.forEach((day) => {
this.myForm.patchValue({
[day]: true,
});
});
}
onDayChange(day: string, isChecked: boolean) { onDayChange(day: string, isChecked: boolean) {
if (isChecked) { if (isChecked) {
this.selectedDays.push(day); this.selectedDays.push(day);

View File

@ -104,7 +104,7 @@ export class SchedulerListComponent {
modalRef.componentInstance.deviceId = this.deviceId; modalRef.componentInstance.deviceId = this.deviceId;
modalRef.componentInstance.data = data; modalRef.componentInstance.data = data;
modalRef.componentInstance.mode = "add"; modalRef.componentInstance.mode = "edit";
modalRef.result.then( modalRef.result.then(
(result) => { (result) => {
if (result) { if (result) {