diff --git a/src/app/_layout/footer/footer.component.html b/src/app/_layout/footer/footer.component.html index c83616c..9f4d5a4 100644 --- a/src/app/_layout/footer/footer.component.html +++ b/src/app/_layout/footer/footer.component.html @@ -13,7 +13,7 @@ href="https://allbestsistem.com/" target="_blank" style="background-color: #ffffff !important;" - >Smart Building Management Systems (V@2024-08-22.2) + >Smart Building Management Systems (V@2024-08-26.2)

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 5575a54..419c2bc 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 @@ -94,6 +94,25 @@ + +
+ + +
+ Active is required. +
+
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 5f947b8..373b37a 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 @@ -1,6 +1,13 @@ import { Component, Input } from "@angular/core"; -import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms"; +import { + FormBuilder, + FormControl, + FormGroup, + Validators, +} from "@angular/forms"; import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap"; +import { DeviceService } from "../../service/device.service"; + @Component({ selector: "app-control-scheduler", @@ -8,27 +15,39 @@ import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap"; styleUrls: ["./control-scheduler.component.css"], }) export class ControlSchedulerComponent { - @Input() device: any; + @Input() deviceId: any; labelModal: string = ""; myForm: FormGroup; dataSwitch = [ { - label: 'On', - value: true - }, { - label: 'Off', - value: false - } + label: "On", + value: true, + }, + { + label: "Off", + value: false, + }, + ]; + + dataActive = [ + { + label: "Active", + value: true, + }, + { + label: "Non Active", + value: false, + }, ]; daysOfWeek = [ - { label: 'Monday', value: 'monday' }, - { label: 'Tuesday', value: 'tuesday' }, - { label: 'Wednesday', value: 'wednesday' }, - { label: 'Thursday', value: 'thursday' }, - { label: 'Friday', value: 'friday' }, - { label: 'Saturday', value: 'saturday' }, - { label: 'Sunday', value: 'sunday' } + { label: "Monday", value: "monday" }, + { label: "Tuesday", value: "tuesday" }, + { label: "Wednesday", value: "wednesday" }, + { label: "Thursday", value: "thursday" }, + { label: "Friday", value: "friday" }, + { label: "Saturday", value: "saturday" }, + { label: "Sunday", value: "sunday" }, ]; selectedDays: string[] = []; @@ -36,25 +55,25 @@ export class ControlSchedulerComponent { constructor( public activeModal: NgbActiveModal, private fb: FormBuilder, + private deviceService: DeviceService ) {} ngOnInit() { - this.createForm() - console.log(this.device); - + this.createForm(); } createForm() { const controls = { - name:["", Validators.required], + name: ["", Validators.required], timeset: ["", Validators.required], + active: [true], switch: [false], - recurring: [false], // Default value for repeat checkbox - device_id: this.device.id + recurring: [true], // Default value for repeat checkbox + device_id: this.deviceId, }; // Initialize checkboxes for each day of the week - this.daysOfWeek.forEach(day => { + this.daysOfWeek.forEach((day) => { controls[day.value] = [false]; // Each day starts as unchecked }); @@ -65,7 +84,7 @@ export class ControlSchedulerComponent { if (isChecked) { this.selectedDays.push(day); } else { - this.selectedDays = this.selectedDays.filter(d => d !== day); + this.selectedDays = this.selectedDays.filter((d) => d !== day); } } @@ -74,19 +93,35 @@ export class ControlSchedulerComponent { // Collect selected days' labels const selectedDays = this.daysOfWeek - .filter(day => formValues[day.value]) - .map(day => day.label); + .filter((day) => formValues[day.value]) + .map((day) => day.label); // Construct the final output const result = { name: formValues.name, - timeset: formValues.timeset, - switch: formValues.switch, - recurring: formValues.recurring, device_id: formValues.device_id, - days: selectedDays + timeset: formValues.timeset, + recurring: formValues.recurring, + active: formValues.active, + switch: formValues.switch, + days: selectedDays, }; - console.log("Form Result: ", result); + if (this.myForm.valid) { + this.activeModal.close(result); + } else { + this.markFormGroupTouched(this.myForm) + } + + // console.log("Form Result: ", result); + } + + markFormGroupTouched(formGroup: FormGroup) { + (Object as any).values(formGroup.controls).forEach((control) => { + control.markAsTouched(); + if (control.controls) { + this.markFormGroupTouched(control); + } + }); } } diff --git a/src/app/content/hemat-app/device/device-control/device-control.component.ts b/src/app/content/hemat-app/device/device-control/device-control.component.ts index fb407ca..a3a9117 100644 --- a/src/app/content/hemat-app/device/device-control/device-control.component.ts +++ b/src/app/content/hemat-app/device/device-control/device-control.component.ts @@ -175,6 +175,8 @@ export class DeviceControlComponent { } schedulerItem(row) { + console.log(row); + this.router.navigate(["/device/scheduler", row.id]); } diff --git a/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.html b/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.html index 1e46407..d9d90bc 100644 --- a/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.html +++ b/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.html @@ -25,7 +25,7 @@ border-color: #37a647 !important; color: #ffffff !important; " - (click)="addSchedulerItem(1)" + (click)="addSchedulerItem()" > Add Schedule @@ -38,14 +38,14 @@