diff --git a/src/app/content/hemat-app/device/device-control/device-control.component.html b/src/app/content/hemat-app/device/device-control/device-control.component.html index d68bf90..4283769 100644 --- a/src/app/content/hemat-app/device/device-control/device-control.component.html +++ b/src/app/content/hemat-app/device/device-control/device-control.component.html @@ -15,11 +15,12 @@
@@ -28,66 +29,57 @@
- -
- -
-
- + +
+
+
+
+
- +
+ +
- -
- -
@@ -133,7 +125,7 @@
lamp{{item.category_name}} @@ -143,7 +135,9 @@ class="switchery" switchColor="black" color="rgb(190, 242, 100)" - checked + size="small" + [checked]="item.status_id === 2" + (change)="switchChanged($event, item)" > 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 322f62a..51b39f6 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,12 +1,12 @@ -import { Component } from '@angular/core'; -import { Router } from '@angular/router'; -import { BuildingService } from '../../service/monitoring-api.service'; -import { DeviceService } from '../../service/device.service'; +import { Component } from "@angular/core"; +import { Router } from "@angular/router"; +import { BuildingService } from "../../service/monitoring-api.service"; +import { DeviceService } from "../../service/device.service"; @Component({ - selector: 'app-device-control', - templateUrl: './device-control.component.html', - styleUrls: ['./device-control.component.css'] + selector: "app-device-control", + templateUrl: "./device-control.component.html", + styleUrls: ["./device-control.component.css"], }) export class DeviceControlComponent { data: any; @@ -14,7 +14,16 @@ export class DeviceControlComponent { totalOff: any; filteredRows: any[]; searchTerm: string = ""; - rows: any = []; + buildingSelected: any; + statusSelected: any; + categorySelected: any; + dataMasterCategori: any; + dataBuildingList: any; + dataMasterStatus: any; + storedData: any; + spinnerFilterActive = false; + switchState: boolean; + public breadcrumb: any; spinnerActive: boolean = false; @@ -30,10 +39,10 @@ export class DeviceControlComponent { { item_id: 7, item_text: "New York" }, ]; - constructor( private router: Router, - private deviceService: DeviceService + private deviceService: DeviceService, + private monitoringApiService: BuildingService ) {} ngOnInit() { @@ -51,19 +60,60 @@ export class DeviceControlComponent { }, ], }; - this.fetchData(); + this.storedData = JSON.parse(localStorage.getItem("currentUser")); + this.buildingSelected = this.storedData.buildingId; + this.fetchData( + this.buildingSelected, + this.categorySelected, + this.statusSelected + ); + this.dataListMaster(); + this.dataListBuilding(); } - fetchData() { - this.deviceService.getDeviceLIst().subscribe((res) => { - console.log(res); - - this.data = res; - this.filteredRows = this.data.data; - console.log(this.filteredRows); + fetchData(buildingSelected, categorySelected, statusSelected) { + this.deviceService + .getDeviceData(buildingSelected, categorySelected, statusSelected) + .subscribe((res) => { + this.data = res; + this.filteredRows = this.data.results.data; + console.log(this.filteredRows); + }); + } + + dataListMaster() { + this.monitoringApiService.getMasterListData().subscribe((data) => { + const dataCategory = data.data.find( + (item) => item.name === "master_category" + ).headerDetailParam; + const dataStatus = data.data.find( + (item) => item.name === "master_status" + ).headerDetailParam; + this.dataMasterCategori = dataCategory.filter( + (item) => item.status === "2" + ); + this.dataMasterStatus = dataStatus.filter((item) => item.status === "2"); }); } + dataListBuilding() { + this.monitoringApiService.getBuildingList().subscribe((data) => { + this.dataBuildingList = data.data.filter((item) => item.statusId === 2); + }); + } + + doFilter() { + this.spinnerFilterActive = true; + this.fetchData( + this.buildingSelected, + this.categorySelected, + this.statusSelected + ); + setTimeout(() => { + this.spinnerFilterActive = false; + }, 3000); + } + filterRows() { if (!this.searchTerm) { this.filteredRows = [...this.data.results.data]; @@ -82,11 +132,21 @@ export class DeviceControlComponent { ); } - addFieldValue() { - + switchChanged(ev, data) { + console.log(ev); + console.log(data); + const requestData = { + device_id: data.device_id, + switch: data.mapping[0].switch, + value: ev, + command_type: "on_off", + }; + this.deviceService.deviceSwitch(requestData).subscribe((res) => { + console.log(res); + }); } - addDevice(): void { - - } + addFieldValue() {} + + addDevice(): void {} } diff --git a/src/app/content/hemat-app/device/device.component.ts b/src/app/content/hemat-app/device/device.component.ts index ac870d1..8dae940 100644 --- a/src/app/content/hemat-app/device/device.component.ts +++ b/src/app/content/hemat-app/device/device.component.ts @@ -34,16 +34,6 @@ export class DeviceComponent implements OnInit { singlebasicSelected: any; - singleSelectArray = [ - { item_id: 1, item_text: "Alaska" }, - { item_id: 2, item_text: "California" }, - { item_id: 3, item_text: "Colorado" }, - { item_id: 4, item_text: "New Mexico" }, - { item_id: 5, item_text: "Alabama" }, - { item_id: 6, item_text: "Connecticut" }, - { item_id: 7, item_text: "New York" }, - ]; - constructor( private modalService: NgbModal, private router: Router, diff --git a/src/app/content/hemat-app/service/device.service.ts b/src/app/content/hemat-app/service/device.service.ts index f6c0c09..98ff73a 100644 --- a/src/app/content/hemat-app/service/device.service.ts +++ b/src/app/content/hemat-app/service/device.service.ts @@ -50,4 +50,14 @@ export class DeviceService { }); return this.http.get(url, { headers }); } + + deviceSwitch(data): Observable { + const endpoint = `/devices`; + const url = `${BASE_URL}${endpoint}/device-switch`; + const headers = new HttpHeaders({ + "Content-Type": "application/json", + "x-api-key": "j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT", + }); + return this.http.post(url, data, { headers }); + } }