diff --git a/src/app/content/hemat-app/master/master-building/add-edit-master-building/add-edit-master-building.component.html b/src/app/content/hemat-app/master/master-building/add-edit-master-building/add-edit-master-building.component.html index b3a73b4..943d1f3 100644 --- a/src/app/content/hemat-app/master/master-building/add-edit-master-building/add-edit-master-building.component.html +++ b/src/app/content/hemat-app/master/master-building/add-edit-master-building/add-edit-master-building.component.html @@ -52,6 +52,15 @@ formControlName="address" /> +
+ + +
diff --git a/src/app/content/hemat-app/monitoring/add-new-building-room/add-new-building-room.component.ts b/src/app/content/hemat-app/monitoring/add-new-building-room/add-new-building-room.component.ts index 26281eb..ee7c98d 100644 --- a/src/app/content/hemat-app/monitoring/add-new-building-room/add-new-building-room.component.ts +++ b/src/app/content/hemat-app/monitoring/add-new-building-room/add-new-building-room.component.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from "@angular/core"; import { FormArray, FormBuilder, FormGroup, Validators } from "@angular/forms"; import { ActivatedRoute, Router } from "@angular/router"; import { BlockUI, NgBlockUI } from "ng-block-ui"; +import { BuildingService } from "../../service/monitoring-api.service"; @Component({ selector: "app-add-new-building-room", @@ -10,6 +11,9 @@ import { BlockUI, NgBlockUI } from "ng-block-ui"; }) export class AddNewBuildingRoomComponent implements OnInit { public breadcrumb: any; + dataMasterstatus: any; + listRoomMaster: any; + listBuildingMaster: any; mode: string; userProfileForm: FormGroup; public userList: FormArray; @@ -21,7 +25,8 @@ export class AddNewBuildingRoomComponent implements OnInit { constructor( private formBuilder: FormBuilder, private router: Router, - private route: ActivatedRoute + private route: ActivatedRoute, + private monitoringApiService: BuildingService, ) {} ngOnInit() { @@ -36,22 +41,72 @@ export class AddNewBuildingRoomComponent implements OnInit { }; this.userProfileForm = this.formBuilder.group({ buildingId: ['', Validators.required], - roomId: ['', Validators.required], - floorId: ['', Validators.required], - userArray: this.formBuilder.array([this.createPhone()]), + roomId: [''], + statusId: ['', Validators.required], + userArray: this.formBuilder.array([this.createRoom()]), }); this.userList = this.userProfileForm.get('userArray') as FormArray; + this.listMaster(); + this.listRoom(); + this.listBuilding(); } - createPhone(): FormGroup { + createRoom(): FormGroup { return this.formBuilder.group({ roomId: ['', Validators.required] }); } + listMaster() { + this.monitoringApiService.getMasterData().subscribe((res) => { + this.dataMasterstatus = res.results.data.find( + (item) => item.name === "master_status" + ).headerDetailParam; + + }); + } + + listRoom() { + this.monitoringApiService.getListRoomData().subscribe((res) => { + this.listRoomMaster = res.results; + }); + } + + listBuilding(){ + this.monitoringApiService.getMasterBuildingData().subscribe((res) => { + this.listBuildingMaster = res.results.data; + console.log(this.listBuildingMaster); + + }); + } + + save(){ + console.log(this.userProfileForm); + console.log(this.userProfileForm.valid); + this.submitted = true; + + if (this.userProfileForm.invalid) { + return; + } + + const formData = this.userProfileForm.value; + const transformedData = { + buildingId: formData.buildingId, + roomId: formData.userArray.map(room => room.roomId), + statusId: formData.statusId + }; + + console.log(transformedData); + + this.monitoringApiService.postBatchBuilding(transformedData).subscribe((res) => { + console.log(res); + }); + + } + addPhone() { - this.userList.push(this.createPhone()); + this.userList.push(this.createRoom()); } removePhone(index) { diff --git a/src/app/content/hemat-app/monitoring/building/building.component.html b/src/app/content/hemat-app/monitoring/building/building.component.html index 6b713e1..7be6a13 100644 --- a/src/app/content/hemat-app/monitoring/building/building.component.html +++ b/src/app/content/hemat-app/monitoring/building/building.component.html @@ -88,7 +88,7 @@
{ - console.log(res.data); this.data = res.data; this.filteredRows = res.data; }); } - buildingData() { - this.monitoringApiService.getBuildingData().subscribe((res) => { - console.log(res); - }); - } + // buildingData() { + // this.monitoringApiService.getBuildingData().subscribe((res) => { + // console.log(res); + // }); + // } filterRows() { if (!this.searchTerm) { diff --git a/src/app/content/hemat-app/monitoring/monitoring.module.ts b/src/app/content/hemat-app/monitoring/monitoring.module.ts index 16750ab..2c367d0 100644 --- a/src/app/content/hemat-app/monitoring/monitoring.module.ts +++ b/src/app/content/hemat-app/monitoring/monitoring.module.ts @@ -23,6 +23,7 @@ import { NgxPhotoswipeModule } from '@fnxone/ngx-photoswipe'; import { NgxMasonryModule } from 'ngx-masonry'; import { UiSwitchModule } from 'ngx-ui-switch'; import { DetailRoomComponent } from './detail-room/detail-room.component'; +import { FilterTopUsePipe } from './monitoring.pipe'; @NgModule({ declarations: [ @@ -30,7 +31,8 @@ import { DetailRoomComponent } from './detail-room/detail-room.component'; RoomComponent, AddNewBuildingRoomComponent, DetailComponent, - DetailRoomComponent + DetailRoomComponent, + FilterTopUsePipe ], imports: [ CommonModule, diff --git a/src/app/content/hemat-app/monitoring/monitoring.pipe.ts b/src/app/content/hemat-app/monitoring/monitoring.pipe.ts new file mode 100644 index 0000000..e996cb3 --- /dev/null +++ b/src/app/content/hemat-app/monitoring/monitoring.pipe.ts @@ -0,0 +1,15 @@ +// create a new file named filter-top-use.pipe.ts +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'filterTopUse' +}) +export class FilterTopUsePipe implements PipeTransform { + + transform(items: any[]): any[] { + if (!items) { + return []; + } + return items.filter(item => item.label !== null && item.value !== null); + } +} diff --git a/src/app/content/hemat-app/service/monitoring-api.service.ts b/src/app/content/hemat-app/service/monitoring-api.service.ts index 86f7b2c..cd0c050 100644 --- a/src/app/content/hemat-app/service/monitoring-api.service.ts +++ b/src/app/content/hemat-app/service/monitoring-api.service.ts @@ -81,7 +81,7 @@ export class BuildingService { return this.http.get(url, { headers }); } - getMasterData(page: number = 1, limit: number = 10): Observable { + getMasterData(page: number = 1, limit: number = 100): Observable { const url = `https://kapi.absys.ninja/hemat/header-param?page=${page}&limit=${limit}`; const headers = new HttpHeaders({ 'Content-Type': 'application/json', @@ -99,6 +99,15 @@ export class BuildingService { return this.http.get(url, { headers }); } + getListRoomData(): Observable { + const url = `https://kapi.absys.ninja/hemat/room/list`; + const headers = new HttpHeaders({ + 'Content-Type': 'application/json', + 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' + }); + return this.http.get(url, { headers }); + } + getMasterRoomData(page: number = 1, limit: number = 100): Observable { const url = `https://kapi.absys.ninja/hemat/room?page=${page}&limit=${limit}`; const headers = new HttpHeaders({ @@ -151,6 +160,15 @@ export class BuildingService { return this.http.put(url, data, { headers }); } + deleteMasterBuildingParam(id: any): Observable { + const url = `https://kapi.absys.ninja/hemat/building/${id}`; + const headers = new HttpHeaders({ + 'Content-Type': 'application/json', + 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' + }); + return this.http.delete(url, { headers }); + } + postMasterRoomParam(data: any): Observable { const url = `https://kapi.absys.ninja/hemat/room`; const headers = new HttpHeaders({ @@ -167,4 +185,13 @@ export class BuildingService { }); return this.http.put(url, data, { headers }); } + + postBatchBuilding(data: any): Observable { + const url = `https://kapi.absys.ninja/hemat/room-building/post-batch/room`; + const headers = new HttpHeaders({ + 'Content-Type': 'application/json', + 'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' + }); + return this.http.post(url, data, { headers }); + } }