penambahan room list

This commit is contained in:
Fuzi_fauzia 2024-05-31 10:42:23 +07:00
parent 6a9451c2b5
commit b2c1020c22
10 changed files with 146 additions and 36 deletions

View File

@ -52,6 +52,15 @@
formControlName="address"
/>
</div>
<div class="form-group col-md-6">
<label for="address">KWH:</label>
<input
type="number"
class="form-control"
id="kwh"
formControlName="kwh"
/>
</div>
<div class="form-group col-md-6">
<label for="statusId">Status:</label>
<!-- <select

View File

@ -41,6 +41,7 @@ export class AddEditMasterBuildingComponent {
owner: ["", Validators.required],
address: ["", Validators.required],
phone: ["", Validators.required],
kwh: ["", Validators.required],
});
}
@ -53,6 +54,7 @@ export class AddEditMasterBuildingComponent {
owner: this.dataRow.owner,
address: this.dataRow.address,
phone: this.dataRow.phone,
kwh: this.dataRow.phone,
});
}

View File

@ -116,7 +116,7 @@ export class MasterBuildingComponent {
const confirmDelete = confirm("Are you sure you want to delete this item?");
if (confirmDelete) {
this.monitoringApiService
.deleteHeaderDetailParam(row.id)
.deleteMasterBuildingParam(row.id)
.subscribe((res) => {
this.fetchData();
});

View File

@ -17,7 +17,7 @@
<div class="card-body">
<form [formGroup]="userProfileForm" class="row">
<div class="form-group col-md-6 mb-2">
<label for="name">Building Name *</label>
<label for="name">Building*</label>
<select
id="buildingId"
class="form-control"
@ -27,32 +27,32 @@
}"
>
<option
*ngFor="let interest of interestedIn"
[value]="interest"
*ngFor="let list of listBuildingMaster"
[value]="list.id"
>
{{ interest }}
{{ list.name }}
</option>
</select>
</div>
<div class="form-group col-md-6 mb-2">
<label for="name">Floor*</label>
<label for="statusId">Status*</label>
<select
id="floorId"
id="statusId"
class="form-control"
formControlName="floorId"
formControlName="statusId"
[ngClass]="{
'is-invalid': submitted && f.interestedIn.errors
}"
>
<option
*ngFor="let interest of interestedIn"
[value]="interest"
*ngFor="let list of dataMasterstatus"
[value]="list.id"
>
{{ interest }}
{{ list.name }}
</option>
</select>
</div>
<div class="form-group col-12 mb-2">
<!-- <div class="form-group col-12 mb-2">
<label for="name">Status*</label>
<select
id="statusId"
@ -63,13 +63,13 @@
}"
>
<option
*ngFor="let interest of interestedIn"
[value]="interest"
*ngFor="let list of dataMasterstatus"
[value]="list.id"
>
{{ interest }}
{{ list.name }}
</option>
</select>
</div>
</div> -->
<div class="form-group col-12 mb-2 contact-repeater">
<div class="" formArrayName="userArray">
<div
@ -91,10 +91,10 @@
}"
>
<option
*ngFor="let interest of interestedIn"
[value]="interest"
*ngFor="let list of listRoomMaster"
[value]="list.id"
>
{{ interest }}
{{ list.name }}
</option>
</select>
<button
@ -133,10 +133,11 @@
type="button"
uiSref="work"
class="btn btn-info btn-raised"
(click)="save()"
>
Save
<span style="margin-left: 10px">
<i class="feather ft-chevron-right"></i>
<!-- <i class="feather ft-chevron-right"></i> -->
</span>
</button>
</div>

View File

@ -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) {

View File

@ -88,7 +88,7 @@
<div class="row mb-3">
<div
class="col-xl-6 col-md-6 col-12"
*ngFor="let top of data.topUse; let i = index"
*ngFor="let top of data.topUse | filterTopUse; let i = index"
>
<div>
<span class="mb-1 text-muted cardtext d-block"

View File

@ -14,7 +14,7 @@ export class BuildingComponent {
feedbacksdonutChart: any;
donutChart1: any;
filteredRows: any[];
dataTop: any;
topUseData: any;
searchTerm: string = "";
colorChart: string = "";
@ -52,17 +52,16 @@ export class BuildingComponent {
listBuilding() {
this.monitoringApiService.listBuilding().subscribe((res) => {
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) {

View File

@ -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,

View File

@ -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);
}
}

View File

@ -81,7 +81,7 @@ export class BuildingService {
return this.http.get<any>(url, { headers });
}
getMasterData(page: number = 1, limit: number = 10): Observable<any> {
getMasterData(page: number = 1, limit: number = 100): Observable<any> {
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<any>(url, { headers });
}
getListRoomData(): Observable<any> {
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<any>(url, { headers });
}
getMasterRoomData(page: number = 1, limit: number = 100): Observable<any> {
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<any>(url, data, { headers });
}
deleteMasterBuildingParam(id: any): Observable<any> {
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<any>(url, { headers });
}
postMasterRoomParam(data: any): Observable<any> {
const url = `https://kapi.absys.ninja/hemat/room`;
const headers = new HttpHeaders({
@ -167,4 +185,13 @@ export class BuildingService {
});
return this.http.put<any>(url, data, { headers });
}
postBatchBuilding(data: any): Observable<any> {
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<any>(url, data, { headers });
}
}