diff --git a/src/app/_layout/footer/footer.component.html b/src/app/_layout/footer/footer.component.html index 599393c..6a5fa9d 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-26.3) + >Smart Building Management Systems (V@2024-08-27.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 15de807..ee3e4af 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 f0493b1..3a50203 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 @@ -8,7 +8,6 @@ import { import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap"; import { DeviceService } from "../../service/device.service"; - @Component({ selector: "app-control-scheduler", templateUrl: "./control-scheduler.component.html", @@ -62,9 +61,9 @@ export class ControlSchedulerComponent { ngOnInit() { this.createForm(); - if (this.mode === 'add') { + if (this.mode === "add") { this.labelModal = "Add Scheduler"; - } else if (this.mode === 'edit') { + } else if (this.mode === "edit") { this.editForm(); this.labelModal = "Edit Scheduler"; } @@ -88,7 +87,7 @@ export class ControlSchedulerComponent { this.myForm = this.fb.group(controls); } - editForm(){ + editForm() { this.selectedDays = this.data.days || []; this.myForm.patchValue({ name: this.data.name, @@ -97,7 +96,7 @@ export class ControlSchedulerComponent { active: this.data.active, switch: this.data.switch, }); - + // Patch the form with the selected days this.selectedDays.forEach((day) => { this.myForm.patchValue({ @@ -123,20 +122,35 @@ export class ControlSchedulerComponent { .map((day) => day.value); // Construct the final output - const result = { - name: formValues.name, - device_id: formValues.device_id, - timeset: formValues.timeset, - recurring: formValues.recurring, - active: formValues.active, - switch: formValues.switch, - days: selectedDays, - }; + let result = {}; + + if (this.mode === "add") { + result = { + name: formValues.name, + device_id: formValues.device_id, + timeset: formValues.timeset, + recurring: formValues.recurring, + active: formValues.active, + switch: formValues.switch, + days: selectedDays, + }; + } else { + result = { + id: this.data.id, + name: formValues.name, + device_id: formValues.device_id, + timeset: formValues.timeset, + recurring: formValues.recurring, + active: formValues.active, + switch: formValues.switch, + days: selectedDays, + }; + } if (this.myForm.valid) { this.activeModal.close(result); } else { - this.markFormGroupTouched(this.myForm) + this.markFormGroupTouched(this.myForm); } // 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 4d3068c..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,7 +175,9 @@ export class DeviceControlComponent { } schedulerItem(row) { - this.router.navigate(["/device/scheduler", row.id, row.name]); + console.log(row); + + this.router.navigate(["/device/scheduler", row.id]); } // schedulerItem(item) { diff --git a/src/app/content/hemat-app/device/device.module.ts b/src/app/content/hemat-app/device/device.module.ts index e255770..901aed6 100644 --- a/src/app/content/hemat-app/device/device.module.ts +++ b/src/app/content/hemat-app/device/device.module.ts @@ -69,7 +69,7 @@ import { SchedulerListComponent } from './scheduler-list/scheduler-list.componen data: { mode: 'view' } }, { - path: 'scheduler/:id/:name', + path: 'scheduler/:id', component: SchedulerListComponent, data: { mode: 'scheduler' } } diff --git a/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.css b/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.css index 918279b..0ca1ac6 100644 --- a/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.css +++ b/src/app/content/hemat-app/device/scheduler-list/scheduler-list.component.css @@ -52,4 +52,3 @@ background-color: #d1d9ff; color: #303f9f; } - \ No newline at end of file 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 289a87a..6863f27 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 @@ -15,7 +15,7 @@ >

- {{deviceName}} + {{ deviceName ? deviceName : '' }}

- + + + +
+ +
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 bd7cb80..688d6d5 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 @@ -14,6 +14,7 @@ export class SchedulerListComponent { listScheduler: any; deviceId: any; deviceName: any; + hasSelected: boolean = false; schedules = [ { id: 1, @@ -36,11 +37,10 @@ export class SchedulerListComponent { ngOnInit(): void { this.route.params.subscribe((params) => { const id = params["id"]; - const name = params["name"]; - this.deviceName = name; this.deviceId = id; if (id) { this.dataListScheduler(id); + this.dataDevice(id); } }); this.breadcrumb = { @@ -68,6 +68,24 @@ export class SchedulerListComponent { dataListScheduler(id) { this.deviceService.getDeviceScheduler(id).subscribe((data) => { this.listScheduler = data.results; + console.log(this.listScheduler); + + }); + } + + dataDevice(id) { + this.deviceService.getDeviceByid(id).subscribe((data) => { + this.deviceName = data.data.name + }); + } + + switchChanged(e, item) { + const data = { + id: item.id, + active: e, + }; + this.deviceService.putDeviceSchedulerActive(data, item.id).subscribe((res) => { + this.dataListScheduler(this.deviceId); }); } @@ -97,7 +115,6 @@ export class SchedulerListComponent { } editSchedule(data) { - console.log(data); const modalRef = this.modalService.open(ControlSchedulerComponent, { size: "md", backdrop: "static", @@ -111,9 +128,11 @@ export class SchedulerListComponent { modalRef.result.then( (result) => { if (result) { - this.deviceService.putDeviceScheduler(result, data.id).subscribe((res) => { - this.dataListScheduler(this.deviceId); - }); + this.deviceService + .putDeviceScheduler(result, data.id) + .subscribe((res) => { + this.dataListScheduler(this.deviceId); + }); } }, (reason) => { @@ -122,28 +141,52 @@ export class SchedulerListComponent { ); } + checkSelected() { + this.hasSelected = this.listScheduler.some((schedule) => schedule.selected); + } + + deleteSelectedSchedules() { + const selectedSchedules = this.listScheduler.filter( + (schedule) => schedule.selected + ); + + if (selectedSchedules.length > 0) { + Swal.fire({ + title: "Apakah kamu yakin ingin menghapus jadwal yang dipilih?", + text: "Tindakan ini tidak dapat dibatalkan.", + icon: "warning", + showCancelButton: true, + confirmButtonColor: "#37a647", + cancelButtonColor: "#d33", + confirmButtonText: "Ya, hapus!", + cancelButtonText: "Batal", + allowOutsideClick: false, + }).then((result) => { + if (result.isConfirmed) { + selectedSchedules.forEach((schedule) => { + this.deleteSchedule(schedule.id); + }); + + Swal.fire({ + title: "Terhapus!", + text: "Jadwal yang dipilih berhasil dihapus.", + icon: "success", + }); + } + }); + } else { + Swal.fire({ + title: "Tidak ada jadwal yang dipilih!", + text: "Pilih setidaknya satu jadwal untuk dihapus.", + icon: "info", + }); + } + } + deleteSchedule(id) { - Swal.fire({ - title: "Apakah kamu yakin ingin menghapus jadwal ini?", - text: "Tindakan ini tidak dapat dibatalkan.", - icon: "warning", - showCancelButton: true, - confirmButtonColor: "#37a647", - cancelButtonColor: "#d33", - confirmButtonText: "Ya, hapus!", - cancelButtonText: "Batal", - allowOutsideClick: false, - }).then((result) => { - if (result.isConfirmed) { - this.deviceService.deleteDeviceScheduler(id).subscribe((data) => { - this.dataListScheduler(this.deviceId); - }); - Swal.fire({ - title: "Terhapus!", - text: "Jadwal berhasil dihapus.", - icon: "success", - }); - } + this.deviceService.deleteDeviceScheduler(id).subscribe(() => { + this.dataListScheduler(this.deviceId); + this.hasSelected = false; }); } } diff --git a/src/app/content/hemat-app/list-monitoring/add-edit-list/add-edit-list.component.html b/src/app/content/hemat-app/list-monitoring/add-edit-list/add-edit-list.component.html index fca87fd..60bd6b1 100644 --- a/src/app/content/hemat-app/list-monitoring/add-edit-list/add-edit-list.component.html +++ b/src/app/content/hemat-app/list-monitoring/add-edit-list/add-edit-list.component.html @@ -105,15 +105,9 @@ New Floor - -
- Building is required -
-
+
+ Floor is required. +
diff --git a/src/app/content/hemat-app/service/device.service.ts b/src/app/content/hemat-app/service/device.service.ts index 6f94925..4601b60 100644 --- a/src/app/content/hemat-app/service/device.service.ts +++ b/src/app/content/hemat-app/service/device.service.ts @@ -99,6 +99,16 @@ export class DeviceService { return this.http.get(url, { headers }); } + getDeviceByid(id): Observable { + const endpoint = `/devices`; + const url = `${BASE_URL}${endpoint}/${id}`; + const headers = new HttpHeaders({ + 'Content-Type': 'application/json', + 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' + }); + return this.http.get(url, { headers }); + } + filterDashboard(building, floor): Observable { const endpoint = `/building/dashboard/list`; const params = new URLSearchParams({ @@ -146,6 +156,16 @@ export class DeviceService { return this.http.put(url, data, { headers }); } + putDeviceSchedulerActive(data, id): Observable { + const endpoint = `/device-scheduler/${id}/Active`; + const url = `${BASE_URL}${endpoint}`; + const headers = new HttpHeaders({ + "Content-Type": "application/json", + "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", + }); + return this.http.put(url, data, { headers }); + } + deleteDeviceScheduler(id): Observable { const endpoint = `/device-scheduler/${id}`; const url = `${BASE_URL}${endpoint}`; diff --git a/src/app/login/login.component.html b/src/app/login/login.component.html index bc791ab..d812386 100644 --- a/src/app/login/login.component.html +++ b/src/app/login/login.component.html @@ -138,7 +138,7 @@

- (v@2024.08.26.3) + (v@2024.08.27.2)