diff --git a/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.html b/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.html index 419c2bc..15de807 100644 --- a/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.html +++ b/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.html @@ -83,7 +83,7 @@ -
+
diff --git a/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.ts b/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.ts index b01e434..f0493b1 100644 --- a/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.ts +++ b/src/app/content/hemat-app/device/control-scheduler/control-scheduler.component.ts @@ -16,6 +16,8 @@ import { DeviceService } from "../../service/device.service"; }) export class ControlSchedulerComponent { @Input() deviceId: any; + @Input() data: any; + @Input() mode: any; labelModal: string = ""; myForm: FormGroup; dataSwitch = [ @@ -60,6 +62,12 @@ export class ControlSchedulerComponent { ngOnInit() { this.createForm(); + if (this.mode === 'add') { + this.labelModal = "Add Scheduler"; + } else if (this.mode === 'edit') { + this.editForm(); + this.labelModal = "Edit Scheduler"; + } } createForm() { @@ -80,6 +88,24 @@ export class ControlSchedulerComponent { 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) { if (isChecked) { this.selectedDays.push(day); diff --git a/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.ts b/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.ts index 145f64c..656a40f 100644 --- a/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.ts +++ b/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.ts @@ -104,7 +104,7 @@ export class SchedulerListComponent { modalRef.componentInstance.deviceId = this.deviceId; modalRef.componentInstance.data = data; - modalRef.componentInstance.mode = "add"; + modalRef.componentInstance.mode = "edit"; modalRef.result.then( (result) => { if (result) {