perbaikan master

This commit is contained in:
Fuzi_fauzia 2024-07-02 22:45:07 +07:00
parent b2d8a8e2f6
commit b095f870dd
17 changed files with 166 additions and 57 deletions

View File

@ -13,7 +13,7 @@
href="https://allbestsistem.com/"
target="_blank"
style="background-color: #000000 !important;"
>Smart Building Management Systems (V@2024-07-1.01)
>Smart Building Management Systems (V@2024-07-2.02)
</a></span
>
</p>

View File

@ -12,17 +12,20 @@ interface Icon {
export class SelectIconComponent {
// @Output() iconSelected: EventEmitter<string> = new EventEmitter<string>();
@Output() iconSelected = new EventEmitter<string>();
@Input() selectedIcon: string;
@Input() selectedIcon = undefined;
icons: any[] = [];
constructor(private masterService: MasterService) {}
ngOnInit(): void {
this.masterService.getIconData().subscribe((res) => {
this.icons = res.rows;
});
if (!this.selectedIcon) {
this.selectedIcon = undefined;
}
}
onSelect(icon: Icon): void {
console.log(icon);
if (icon) {
this.iconSelected.emit(icon.icon);
} else {

View File

@ -1,6 +1,6 @@
<div class="modal-header" style="background-color: #000000 !important">
<h4 class="modal-title" style="color: #ffffff">Add New Row</h4>
<button type="button" class="close" aria-label="Close">
<h4 class="modal-title" style="color: #ffffff">{{labelModal}}</h4>
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>
@ -16,13 +16,17 @@
formControlName="name"
maxlength="50"
/>
<div *ngIf="myForm.get('name').touched && myForm.get('name').invalid" class="text-danger">
Name is required.
</div>
</div>
<div class="form-group col-md-6" *ngIf="category">
<label for="status" style="color: #ffffff">Icon:</label>
<label for="icon" style="color: #ffffff">Icon:</label>
<app-select-icon [selectedIcon]="selectedIcon" (iconSelected)="onIconSelected($event)"></app-select-icon>
<!-- <input type="hidden" formControlName="icon"> -->
<div *ngIf="myForm.get('icon').touched && myForm.get('icon').invalid" class="text-danger">
Icon is required.
</div>
</div>
<div class="form-group col-md-6">
<label for="status" style="color: #ffffff">Status:</label>
<select
@ -34,6 +38,9 @@
{{ data.name }}
</option>
</select>
<div *ngIf="myForm.get('status').touched && myForm.get('status').invalid" class="text-danger">
Status is required.
</div>
</div>
</div>
</form>
@ -53,6 +60,6 @@
class="btn btn-primary"
(click)="addRow()"
>
Save Changes
Save
</button>
</div>

View File

@ -16,6 +16,7 @@ export class AddEditMasterComponent implements OnInit {
myForm: FormGroup;
dataMasterStatus: any;
selectedIcon: string = '';
labelModal: string = '';
constructor(
public activeModal: NgbActiveModal,
@ -26,7 +27,11 @@ export class AddEditMasterComponent implements OnInit {
ngOnInit() {
this.createForm();
this.dataListMaster();
console.log(this.dataRow);
if (this.mode === "add") {
this.labelModal = "Add Row"
} else {
this.labelModal = "Edit Row"
}
if (this.dataRow) {
this.editForm();
@ -36,7 +41,7 @@ export class AddEditMasterComponent implements OnInit {
createForm() {
const formControls = {
name: ["", Validators.required],
status: [2, Validators.required],
status: ["", Validators.required],
headerId: this.headerId
};
@ -50,14 +55,14 @@ export class AddEditMasterComponent implements OnInit {
editForm() {
const formControls = {
id: this.dataRow.id,
name: this.dataRow.name,
status: this.dataRow.status,
name: [this.dataRow.name, Validators.required],
status: [this.dataRow.status, Validators.required],
headerId: this.dataRow.headerId,
};
if (this.category) {
formControls['icon'] = this.dataRow.icon || "";
this.selectedIcon = this.dataRow.icon || "";
formControls['icon'] = [this.dataRow.icon || undefined , Validators.required];
this.selectedIcon = this.dataRow.icon || undefined;
}
this.myForm = this.fb.group(formControls);
@ -75,9 +80,20 @@ export class AddEditMasterComponent implements OnInit {
addRow() {
if (this.myForm.valid) {
this.activeModal.close(this.myForm.value);
} else {
this.markFormGroupTouched(this.myForm)
}
}
markFormGroupTouched(formGroup: FormGroup) {
(Object as any).values(formGroup.controls).forEach((control) => {
control.markAsTouched();
if (control.controls) {
this.markFormGroupTouched(control);
}
});
}
addDepartment() {
let newDept = prompt("Enter new department name:");
if (newDept) {

View File

@ -36,7 +36,7 @@ export class AddEditMasterBuildingComponent {
createForm() {
this.myForm = this.fb.group({
name: ["", Validators.required],
statusId: [0, Validators.required],
statusId: ["", Validators.required],
email: ["", [Validators.required, Validators.email]],
owner: ["", Validators.required],
address: ["", Validators.required],
@ -48,13 +48,16 @@ export class AddEditMasterBuildingComponent {
editForm() {
this.myForm = this.fb.group({
id: this.dataRow.id,
name: this.dataRow.name,
statusId: this.dataRow.statusId,
name: [this.dataRow.name, Validators.required],
statusId: [this.dataRow.statusId, Validators.required],
email: [this.dataRow.email, [Validators.required, Validators.email]],
owner: this.dataRow.owner,
address: this.dataRow.address,
phone: [this.dataRow.phone, [Validators.required, Validators.pattern("^[0-9]*$")]],
kwh: this.dataRow.kwh,
owner: [this.dataRow.owner, Validators.required],
address: [this.dataRow.address, Validators.required],
phone: [
this.dataRow.phone,
[Validators.required, Validators.pattern("^[0-9]*$")],
],
kwh: [this.dataRow.kwh, Validators.required],
});
}
@ -66,7 +69,7 @@ export class AddEditMasterBuildingComponent {
);
this.dataStatus = this.dataMasterStatus.headerDetailParam;
console.log(this.dataStatus);
this.filteredDataStatus = this.dataStatus.filter(
(item) => item.status === "2"
);
@ -76,9 +79,20 @@ export class AddEditMasterBuildingComponent {
addRow() {
if (this.myForm.valid) {
this.activeModal.close(this.myForm.value);
} else {
this.markFormGroupTouched(this.myForm);
}
}
markFormGroupTouched(formGroup: FormGroup) {
(Object as any).values(formGroup.controls).forEach((control) => {
control.markAsTouched();
if (control.controls) {
this.markFormGroupTouched(control);
}
});
}
addDepartment() {
let newDept = prompt("Enter new department name:");
if (newDept) {

View File

@ -83,6 +83,8 @@ export class MasterCategoryComponent implements OnInit {
openAddMasterModal() {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;
@ -119,6 +121,8 @@ export class MasterCategoryComponent implements OnInit {
editRow(row) {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;

View File

@ -76,6 +76,8 @@ export class MasterDurationUseComponent {
openAddMasterModal() {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;
@ -101,6 +103,8 @@ export class MasterDurationUseComponent {
editRow(row) {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;

View File

@ -76,6 +76,8 @@ export class MasterFloorComponent {
openAddMasterModal() {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;
@ -101,6 +103,8 @@ export class MasterFloorComponent {
editRow(row) {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;

View File

@ -76,6 +76,8 @@ export class MasterRoleComponent {
openAddMasterModal() {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;
@ -101,6 +103,8 @@ export class MasterRoleComponent {
editRow(row) {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;

View File

@ -1,6 +1,6 @@
<div class="modal-header" style="background-color: #000000 !important">
<h4 class="modal-title" style="color: #ffffff">Add New Row</h4>
<button type="button" class="close" aria-label="Close">
<h4 class="modal-title" style="color: #ffffff">{{labelRoom}}</h4>
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>
@ -16,6 +16,12 @@
formControlName="name"
maxlength="50"
/>
<div
*ngIf="myForm.get('name').touched && myForm.get('name').invalid"
class="text-danger"
>
Name is required.
</div>
</div>
<div class="form-group col-md-6">
<label for="statusId" style="color: #ffffff">Building:</label>
@ -28,6 +34,14 @@
{{ data.name }}
</option>
</select>
<div
*ngIf="
myForm.get('buildingId').touched && myForm.get('buildingId').invalid
"
class="text-danger"
>
Building is required.
</div>
</div>
<div class="form-group col-md-6">
<label for="description" style="color: #ffffff">Description:</label>
@ -38,19 +52,25 @@
formControlName="description"
maxlength="50"
/>
<div *ngIf="myForm.get('description').touched && myForm.get('description').invalid" class="text-danger">
Description is required.
</div>
</div>
<div class="form-group col-md-6">
<label for="statusId" style="color: #ffffff">Status:</label>
<select
id="projectinput5"
class="form-control"
formControlName="statusId"
>
<option *ngFor="let data of filteredDataStatus" [value]="data.id">
{{ data.name }}
</option>
</select>
<label for="statusId" style="color: #ffffff">Status:</label>
<select
id="projectinput5"
class="form-control"
formControlName="statusId"
>
<option *ngFor="let data of filteredDataStatus" [value]="data.id">
{{ data.name }}
</option>
</select>
<div *ngIf="myForm.get('statusId').touched && myForm.get('statusId').invalid" class="text-danger">
Status is required.
</div>
</div>
</div>
</form>
</div>
@ -73,6 +93,6 @@
style="color: #000000 !important; background-color: #c3f164 !important"
(click)="addRow()"
>
Save Changes
Save
</button>
</div>

View File

@ -1,12 +1,12 @@
import { Component, Input } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { BuildingService } from '../../../service/monitoring-api.service';
import { Component, Input } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
import { BuildingService } from "../../../service/monitoring-api.service";
@Component({
selector: 'app-add-edit-master-room',
templateUrl: './add-edit-master-room.component.html',
styleUrls: ['./add-edit-master-room.component.css']
selector: "app-add-edit-master-room",
templateUrl: "./add-edit-master-room.component.html",
styleUrls: ["./add-edit-master-room.component.css"],
})
export class AddEditMasterRoomComponent {
@Input() dataRow: any;
@ -19,6 +19,7 @@ export class AddEditMasterRoomComponent {
filteredDataStatus: any[];
filteredDataBuilding: any[];
dataMasterStatus: any;
labelRoom: string = "";
constructor(
public activeModal: NgbActiveModal,
@ -30,7 +31,12 @@ export class AddEditMasterRoomComponent {
this.createForm();
this.listDataStatus();
this.listDataBuilding();
console.log(this.mode);
if (this.mode) {
this.labelRoom = "Add New Row"
} else {
this.labelRoom = "Add New Row"
}
if (this.dataRow) {
this.editForm();
}
@ -39,8 +45,8 @@ export class AddEditMasterRoomComponent {
createForm() {
this.myForm = this.fb.group({
name: ["", Validators.required],
statusId: [0, Validators.required],
buildingId: [0, Validators.required],
statusId: ["", Validators.required],
buildingId: ["", Validators.required],
description: ["", Validators.required],
});
}
@ -48,10 +54,10 @@ export class AddEditMasterRoomComponent {
editForm() {
this.myForm = this.fb.group({
id: this.dataRow.id,
name: this.dataRow.name,
statusId: this.dataRow.statusId,
buildingId: this.dataRow.buildingId,
description: this.dataRow.description,
name: [this.dataRow.name, Validators.required],
statusId: [this.dataRow.statusId, Validators.required],
buildingId: [this.dataRow.buildingId, Validators.required],
description: [this.dataRow.description, Validators.required],
});
}
@ -65,23 +71,32 @@ export class AddEditMasterRoomComponent {
this.filteredDataStatus = this.dataStatus.filter(
(item) => item.status === "2"
);
});
}
listDataBuilding(){
listDataBuilding() {
this.monitoringApiService.getMasterBuildingData().subscribe((res) => {
this.dataBuilding = res.results.data;
this.filteredDataBuilding = this.dataBuilding.filter(
(item) => item.statusId === 2
);
});
}
addRow() {
if (this.myForm.valid) {
this.activeModal.close(this.myForm.value);
} else {
this.markFormGroupTouched(this.myForm);
}
}
markFormGroupTouched(formGroup: FormGroup) {
(Object as any).values(formGroup.controls).forEach((control) => {
control.markAsTouched();
if (control.controls) {
this.markFormGroupTouched(control);
}
});
}
}

View File

@ -43,14 +43,16 @@ export class MasterRoomComponent {
this.monitoringApiService.getBuildingRoomList().subscribe((res) => {
this.data = res;
this.filteredRows = this.data.results.data;
console.log(this.filteredRows);
});
}
filterRows() {
if (!this.searchTerm) {
this.filteredRows = [...this.data];
this.filteredRows = [...this.data.results.data];
} else {
this.filteredRows = this.data.filter((row) =>
this.filteredRows = this.data.results.data.filter((row) =>
this.rowContainsSearchTerm(row)
);
}
@ -67,6 +69,8 @@ export class MasterRoomComponent {
openAddMasterModal() {
const modalRef = this.modalService.open(AddEditMasterRoomComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.mode = "add";
@ -102,6 +106,8 @@ export class MasterRoomComponent {
editRow(row) {
const modalRef = this.modalService.open(AddEditMasterRoomComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.dataRow = row;

View File

@ -76,6 +76,8 @@ export class MasterStatusComponent {
openAddMasterModal() {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;
@ -101,6 +103,8 @@ export class MasterStatusComponent {
editRow(row) {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;

View File

@ -76,6 +76,8 @@ export class MasterTypeComponent {
openAddMasterModal() {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;
@ -101,6 +103,8 @@ export class MasterTypeComponent {
editRow(row) {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;

View File

@ -76,6 +76,8 @@ export class MasterVoltageComponent {
openAddMasterModal() {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;
@ -101,6 +103,8 @@ export class MasterVoltageComponent {
editRow(row) {
const modalRef = this.modalService.open(AddEditMasterComponent, {
size: "lg",
backdrop: 'static', // Add this line
keyboard: false // Add this line
});
modalRef.componentInstance.headerId = this.dataMasterCategori.id;

View File

@ -198,7 +198,7 @@ export class BuildingService {
return this.http.post<any>(url, data, { headers });
}
getBuildingRoomList(page: number = 1, limit: number = 100): Observable<any> {
getBuildingRoomList(page: number = 1, limit: number = 1000): Observable<any> {
const url = `https://kapi.absys.ninja/hemat/room-building?page=${page}&limit=${limit}`;
const headers = new HttpHeaders({
"Content-Type": "application/json",

View File

@ -138,7 +138,7 @@
<p
class="card-subtitle line-on-side text-muted text-center font-small-3 mx-2 my-1"
>
<span>(v@2024.07.1.01)</span>
<span>(v@2024.07.2.02)</span>
</p>
<!-- <div class="card-body">
<a