From 9654cf92e8c89932d7930755d330e64bc0e9d823 Mon Sep 17 00:00:00 2001 From: Fuzi_fauzia Date: Thu, 22 Aug 2024 15:45:48 +0700 Subject: [PATCH] perbakan UI scheduler --- .../control-scheduler.component.html | 69 +++++++++------- .../control-scheduler.component.ts | 81 +++++++++++++------ .../device-control.component.ts | 11 ++- 3 files changed, 109 insertions(+), 52 deletions(-) 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 cc61db2..61aab4a 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 @@ -13,15 +13,15 @@
- +
Time On is required. @@ -29,37 +29,50 @@
- - -
- Time Off is required. -
-
- -
- +
- Status is required. + Switch is required. +
+
+ + +
+ +
+
+ + +
+
+
+ + +
+ +
+ +
@@ -82,7 +95,7 @@ type="button" style="color: #ffffff !important; background-color: #37a647 !important" class="btn btn-primary" - (click)="addRow()" + (click)="save()" > Save 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 495bcba..cee02fa 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,7 +1,6 @@ import { Component } from "@angular/core"; -import { FormBuilder, FormGroup, Validators } from "@angular/forms"; +import { FormBuilder, FormControl, FormGroup, Validators } from "@angular/forms"; import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap"; -import { BuildingService } from "../../service/monitoring-api.service"; @Component({ selector: "app-control-scheduler", @@ -11,40 +10,76 @@ import { BuildingService } from "../../service/monitoring-api.service"; export class ControlSchedulerComponent { labelModal: string = ""; myForm: FormGroup; - dataMasterStatus: any; + dataSwitch = [ + { + label: 'On', + value: true + }, { + label: 'Off', + 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' } + ]; + + selectedDays: string[] = []; constructor( public activeModal: NgbActiveModal, - private monitoringApiService: BuildingService, private fb: FormBuilder, ) {} ngOnInit() { - - this.dataListMaster(); this.createForm() } - addRow() {} - createForm() { - this.myForm = this.fb.group({ - timeOn: ["", Validators.required], - status: ["", Validators.required], - timeOff: ["", Validators.required], + const controls = { + timeset: ["", Validators.required], + switch: [false], + repeat: [false], // Default value for repeat checkbox + }; + + // Initialize checkboxes for each day of the week + this.daysOfWeek.forEach(day => { + controls[day.value] = [false]; // Each day starts as unchecked }); + + this.myForm = this.fb.group(controls); } - dataListMaster() { - this.monitoringApiService.getMasterListData().subscribe((data) => { - const dataCategory = data.data.find( - (item) => item.name === "master_status" - ).headerDetailParam; - this.dataMasterStatus = dataCategory.filter( - (item) => item.statusName.toLowerCase() === "aktif" - ); - console.log(this.dataMasterStatus); - - }); + onDayChange(day: string, isChecked: boolean) { + if (isChecked) { + this.selectedDays.push(day); + } else { + this.selectedDays = this.selectedDays.filter(d => d !== day); + } + } + + save() { + const formValues = this.myForm.value; + + // Collect selected days' labels + const selectedDays = this.daysOfWeek + .filter(day => formValues[day.value]) + .map(day => day.label); + + // Construct the final output + const result = { + timeset: formValues.timeset, + switch: formValues.switch, + repeat: formValues.repeat, + day: selectedDays + }; + + console.log("Form Result: ", result); } } 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 4c5c357..c0cb859 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 @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, HostListener } from "@angular/core"; import { Router } from "@angular/router"; import { BuildingService } from "../../service/monitoring-api.service"; import { DeviceService } from "../../service/device.service"; @@ -196,4 +196,13 @@ export class DeviceControlComponent { ); // Handle edit action } + + @HostListener('document:click', ['$event']) + clickout(event) { + if (!event.target.closest('.menu-popup') && !event.target.closest('.btn')) { + this.filteredDeviceRows.forEach(item => { + item.menuOpen = false; + }); + } + } }