From b195055651c7722d6b5ec686239a5d85796fc8a2 Mon Sep 17 00:00:00 2001 From: Fuzi_fauzia Date: Tue, 20 Aug 2024 15:37:50 +0700 Subject: [PATCH] perbaikan validasi penempatan device dalam ruangan --- .../add-edit-device.component.ts | 115 +++++++++++++----- .../add-edit-list.component.html | 16 +-- .../add-edit-master.component.ts | 2 - 3 files changed, 88 insertions(+), 45 deletions(-) diff --git a/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.ts b/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.ts index 7b53b3d..fe12280 100644 --- a/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.ts +++ b/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.ts @@ -4,13 +4,14 @@ import { ActivatedRoute, Router } from "@angular/router"; import { BlockUI, NgBlockUI } from "ng-block-ui"; import { BuildingService } from "../../service/monitoring-api.service"; import { LoginService } from "../../service/login.service"; +import Swal from "sweetalert2"; @Component({ selector: "app-add-edit-device", templateUrl: "./add-edit-device.component.html", styleUrls: ["./add-edit-device.component.css"], }) -export class AddEditDeviceComponent implements OnInit{ +export class AddEditDeviceComponent implements OnInit { @ViewChild("f", { read: true }) userProfileForm: NgForm; dataMasterCategori: any; dataMasterVoltage: any; @@ -43,8 +44,8 @@ export class AddEditDeviceComponent implements OnInit{ ngOnInit() { this.authService.startTokenCheck(); this.authService.startTrackingActivity(); - this.route.params.subscribe(params => { - const id = params['id']; + this.route.params.subscribe((params) => { + const id = params["id"]; this.deviceId = id; if (id) { this.loadDevice(id); @@ -52,7 +53,7 @@ export class AddEditDeviceComponent implements OnInit{ this.dataListRoomBuilding(); } }); - this.setBreadcrumb() + this.setBreadcrumb(); this.route.data.subscribe((data) => { this.mode = data.mode; }); @@ -69,52 +70,72 @@ export class AddEditDeviceComponent implements OnInit{ } loadDevice(deviceId: string) { - this.monitoringApiService.getDeviceById(deviceId).subscribe(data => { + this.monitoringApiService.getDeviceById(deviceId).subscribe((data) => { this.dataDevice = data; - this.formGetDevice(data) + this.formGetDevice(data); }); } dataListMaster() { - this.monitoringApiService.getMasterListData().subscribe(data => { + this.monitoringApiService.getMasterListData().subscribe((data) => { const dataCategory = data.data.find( (item) => item.name === "master_category" ).headerDetailParam; - this.dataMasterCategori = dataCategory.filter(item => item.statusName.toLowerCase() === "aktif" || item.status.toLowerCase() === "71") + this.dataMasterCategori = dataCategory.filter( + (item) => + item.statusName.toLowerCase() === "aktif" || + item.status.toLowerCase() === "71" + ); - const dataVoltage = data.data.find( + const dataVoltage = data.data.find( (item) => item.name === "master_voltage" ).headerDetailParam; - this.dataMasterVoltage = dataVoltage.filter(item => item.statusName.toLowerCase() === "aktif" || item.status.toLowerCase() === "71") + this.dataMasterVoltage = dataVoltage.filter( + (item) => + item.statusName.toLowerCase() === "aktif" || + item.status.toLowerCase() === "71" + ); const dataType = data.data.find( (item) => item.name === "master_type" ).headerDetailParam; - this.dataMasterType = dataType.filter(item => item.statusName.toLowerCase() === "aktif" || item.status.toLowerCase() === "71") + this.dataMasterType = dataType.filter( + (item) => + item.statusName.toLowerCase() === "aktif" || + item.status.toLowerCase() === "71" + ); const dataDuration = data.data.find( (item) => item.name === "master_duration" ).headerDetailParam; - this.dataMasterDuration = dataDuration.filter(item => item.statusName.toLowerCase() === "aktif" || item.status.toLowerCase() === "71") + this.dataMasterDuration = dataDuration.filter( + (item) => + item.statusName.toLowerCase() === "aktif" || + item.status.toLowerCase() === "71" + ); const dataStatus = data.data.find( (item) => item.name === "master_status" ).headerDetailParam; - this.dataMasterStatus = dataStatus.filter(item => item.statusName.toLowerCase() === "aktif" || item.status.toLowerCase() === "71") + this.dataMasterStatus = dataStatus.filter( + (item) => + item.statusName.toLowerCase() === "aktif" || + item.status.toLowerCase() === "71" + ); }); } dataListRoomBuilding() { - this.monitoringApiService.getBuildingRoomList().subscribe(data => { - const newArray = data.results.data.map(item => ({ + this.monitoringApiService.getBuildingRoomList().subscribe((data) => { + const newArray = data.results.data.map((item) => ({ id: item.id, - name: `${item.buildingEntity.name} (${item.roomEntity.name})` + name: `${item.buildingEntity.name} (${item.roomEntity.name})`, })); - this.dataBuildingRoomList = newArray + this.dataBuildingRoomList = newArray; }); } - formGetDevice(data){ + formGetDevice(data) { this.projectInfo.patchValue({ name: data.data.name, categoryId: data.data.categoryId, @@ -122,21 +143,24 @@ export class AddEditDeviceComponent implements OnInit{ typeId: data.data.typeId, durationId: data.data.durationId, roomBuildingId: data.data.roomBuildingId, - watt: data.data.watt + watt: data.data.watt, }); - if (this.mode === 'view') { + if (this.mode === "view") { this.formDisable(); } + if (this.projectInfo.get("roomBuildingId").value) { + this.projectInfo.get("roomBuildingId").disable(); + } } - formDisable(){ - this.projectInfo.get('name').disable() - this.projectInfo.get('categoryId').disable() - this.projectInfo.get('voltageId').disable() - this.projectInfo.get('typeId').disable() - this.projectInfo.get('durationId').disable() - this.projectInfo.get('roomBuildingId').disable() - this.projectInfo.get('watt').disable() + formDisable() { + this.projectInfo.get("name").disable(); + this.projectInfo.get("categoryId").disable(); + this.projectInfo.get("voltageId").disable(); + this.projectInfo.get("typeId").disable(); + this.projectInfo.get("durationId").disable(); + this.projectInfo.get("roomBuildingId").disable(); + this.projectInfo.get("watt").disable(); } setBreadcrumb() { @@ -226,12 +250,39 @@ export class AddEditDeviceComponent implements OnInit{ if (event.keyCode !== 8 && !pattern.test(inputChar)) { event.preventDefault(); } - } + } saveEdit() { - this.monitoringApiService.putDevice(this.projectInfo.value, this.deviceId).subscribe(data => { - this.router.navigate(["/device"]); - }); + if (this.projectInfo.get("roomBuildingId").value) { + this.monitoringApiService + .putDevice(this.projectInfo.value, this.deviceId) + .subscribe((data) => { + this.router.navigate(["/device"]); + }); + } else { + Swal.fire({ + title: "Apakah kamu yakin?", + text: "Data lokasi device tidak dapat diubah!", + icon: "warning", + showCancelButton: true, + confirmButtonColor: "#3085d6", + cancelButtonColor: "#d33", + confirmButtonText: "Yes, save it!", + }).then((result) => { + if (result.isConfirmed) { + this.monitoringApiService + .putDevice(this.projectInfo.value, this.deviceId) + .subscribe((data) => { + this.router.navigate(["/device"]); + }); + Swal.fire({ + title: "Saved!", + text: "Data berhasil disimpan.", + icon: "success", + }); + } + }); + } } cancel() { 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 e1a6744..23253f7 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 @@ -29,10 +29,10 @@ (ngSubmit)="onProjectInfoSubmit()" >
-

+
@@ -246,15 +246,9 @@
- -
- Status is required -
-
+
+ Status is required. +

diff --git a/src/app/content/hemat-app/master/add-edit-master/add-edit-master.component.ts b/src/app/content/hemat-app/master/add-edit-master/add-edit-master.component.ts index e850f9e..c588936 100644 --- a/src/app/content/hemat-app/master/add-edit-master/add-edit-master.component.ts +++ b/src/app/content/hemat-app/master/add-edit-master/add-edit-master.component.ts @@ -69,8 +69,6 @@ export class AddEditMasterComponent implements OnInit { editForm() { - console.log(this.dataRow); - const formControls = { id: this.dataRow.id, name: [this.dataRow.name, Validators.required],