penambahan icon pada master category

This commit is contained in:
Fuzi_fauzia 2024-06-25 21:54:12 +07:00
parent fc9947da15
commit 89203b9984
11 changed files with 164 additions and 45 deletions

View File

@ -2,6 +2,7 @@
[items]="icons" [items]="icons"
bindLabel="name" bindLabel="name"
(change)="onSelect($event)" (change)="onSelect($event)"
[(ngModel)]="selectedIcon"
bindValue="icon" bindValue="icon"
placeholder="Select an icon" placeholder="Select an icon"
> >

View File

@ -1,4 +1,4 @@
import { Component, EventEmitter, Output } from "@angular/core"; import { Component, EventEmitter, Input, Output } from "@angular/core";
import { MasterService } from "../../service/master-api.service"; import { MasterService } from "../../service/master-api.service";
interface Icon { interface Icon {
name: string; name: string;
@ -10,7 +10,9 @@ interface Icon {
styleUrls: ["./select-icon.component.css"], styleUrls: ["./select-icon.component.css"],
}) })
export class SelectIconComponent { export class SelectIconComponent {
@Output() iconSelected: EventEmitter<string> = new EventEmitter<string>(); // @Output() iconSelected: EventEmitter<string> = new EventEmitter<string>();
@Output() iconSelected = new EventEmitter<string>();
@Input() selectedIcon: string;
icons: any[] = []; icons: any[] = [];
constructor(private masterService: MasterService) {} constructor(private masterService: MasterService) {}
ngOnInit(): void { ngOnInit(): void {
@ -20,6 +22,12 @@ export class SelectIconComponent {
} }
onSelect(icon: Icon): void { onSelect(icon: Icon): void {
this.iconSelected.emit(icon.icon); console.log(icon);
if (icon) {
this.iconSelected.emit(icon.icon);
} else {
this.iconSelected.emit(undefined);
}
} }
} }

View File

@ -16,9 +16,10 @@
formControlName="name" formControlName="name"
/> />
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6" *ngIf="category">
<label for="status" style="color: #ffffff">Icon:</label> <label for="status" style="color: #ffffff">Icon:</label>
<app-select-icon (iconSelected)="onIconSelected($event)"></app-select-icon> <app-select-icon [selectedIcon]="selectedIcon" (iconSelected)="onIconSelected($event)"></app-select-icon>
<!-- <input type="hidden" formControlName="icon"> -->
</div> </div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">

View File

@ -12,6 +12,7 @@ export class AddEditMasterComponent implements OnInit {
@Input() headerId: number; @Input() headerId: number;
@Input() dataRow: any; @Input() dataRow: any;
@Input() mode: any; @Input() mode: any;
@Input() category: boolean = false;
myForm: FormGroup; myForm: FormGroup;
dataMasterStatus: any; dataMasterStatus: any;
selectedIcon: string = ''; selectedIcon: string = '';
@ -25,26 +26,41 @@ export class AddEditMasterComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.createForm(); this.createForm();
this.dataListMaster(); this.dataListMaster();
console.log(this.dataRow);
if (this.dataRow) { if (this.dataRow) {
this.editForm(); this.editForm();
} }
} }
createForm() { createForm() {
this.myForm = this.fb.group({ const formControls = {
name: ["", Validators.required], name: ["", Validators.required],
status: [2, Validators.required], status: [2, Validators.required],
headerId: this.headerId, headerId: this.headerId
}); };
if (this.category) {
formControls['icon'] = [undefined, Validators.required];
}
this.myForm = this.fb.group(formControls);
} }
editForm() { editForm() {
this.myForm = this.fb.group({ const formControls = {
id: this.dataRow.id, id: this.dataRow.id,
name: this.dataRow.name, name: this.dataRow.name,
status: this.dataRow.status, status: this.dataRow.status,
headerId: this.dataRow.headerId, headerId: this.dataRow.headerId,
}); };
if (this.category) {
formControls['icon'] = this.dataRow.icon || "";
this.selectedIcon = this.dataRow.icon || "";
}
this.myForm = this.fb.group(formControls);
} }
dataListMaster() { dataListMaster() {
@ -70,7 +86,9 @@ export class AddEditMasterComponent implements OnInit {
} }
onIconSelected(icon: string): void { onIconSelected(icon: string): void {
console.log(icon);
this.selectedIcon = icon; this.selectedIcon = icon;
this.myForm.get('selectedIcon').setValue(icon); // Set nilai selectedIcon ke dalam form this.myForm.get('icon').setValue(icon); // Set nilai icon ke dalam form
} }
} }

View File

@ -78,6 +78,21 @@
<p style="color: #ffffff">{{ value }}</p> <p style="color: #ffffff">{{ value }}</p>
</ng-template> </ng-template>
</ngx-datatable-column> </ngx-datatable-column>
<ngx-datatable-column
name="icon"
[flexGrow]="1"
[minWidth]="90"
>
<ng-template ngx-datatable-header-template>
<span style="color: #ffffff">Icon</span>
</ng-template>
<ng-template
let-value="value"
ngx-datatable-cell-template
>
<p style="color: #ffffff">{{ value }}</p>
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column <ngx-datatable-column
name="Status" name="Status"
[flexGrow]="1" [flexGrow]="1"

View File

@ -54,6 +54,8 @@ export class MasterCategoryComponent implements OnInit {
(item) => item.name === "master_category" (item) => item.name === "master_category"
); );
this.filteredRows = this.dataMasterCategori.headerDetailParam; this.filteredRows = this.dataMasterCategori.headerDetailParam;
console.log(this.filteredRows);
}); });
} }
@ -85,6 +87,7 @@ export class MasterCategoryComponent implements OnInit {
modalRef.componentInstance.headerId = this.dataMasterCategori.id; modalRef.componentInstance.headerId = this.dataMasterCategori.id;
modalRef.componentInstance.mode = "add"; modalRef.componentInstance.mode = "add";
modalRef.componentInstance.category = true;
modalRef.result.then( modalRef.result.then(
(result) => { (result) => {
console.log(result); console.log(result);
@ -121,6 +124,7 @@ export class MasterCategoryComponent implements OnInit {
modalRef.componentInstance.headerId = this.dataMasterCategori.id; modalRef.componentInstance.headerId = this.dataMasterCategori.id;
modalRef.componentInstance.dataRow = row; modalRef.componentInstance.dataRow = row;
modalRef.componentInstance.mode = "edit"; modalRef.componentInstance.mode = "edit";
modalRef.componentInstance.category = true;
modalRef.result.then( modalRef.result.then(
(result) => { (result) => {
console.log(result); console.log(result);

View File

@ -16,6 +16,18 @@
formControlName="name" formControlName="name"
/> />
</div> </div>
<div class="form-group col-md-6">
<label for="statusId" style="color: #ffffff">Building:</label>
<select
id="projectinput5"
class="form-control"
formControlName="buildingId"
>
<option *ngFor="let data of filteredDataBuilding" [value]="data.id">
{{ data.name }}
</option>
</select>
</div>
<div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="description" style="color: #ffffff">Description:</label> <label for="description" style="color: #ffffff">Description:</label>
<input <input
@ -25,8 +37,8 @@
formControlName="description" formControlName="description"
/> />
</div> </div>
<!-- <div class="form-group col-md-6"> <div class="form-group col-md-6">
<label for="statusId">Status:</label> <label for="statusId" style="color: #ffffff">Status:</label>
<select <select
id="projectinput5" id="projectinput5"
class="form-control" class="form-control"
@ -36,7 +48,7 @@
{{ data.name }} {{ data.name }}
</option> </option>
</select> </select>
</div> --> </div>
</div> </div>
</form> </form>
</div> </div>

View File

@ -15,7 +15,9 @@ export class AddEditMasterRoomComponent {
data: any; data: any;
dataStatus: any[]; dataStatus: any[];
dataBuilding: any[];
filteredDataStatus: any[]; filteredDataStatus: any[];
filteredDataBuilding: any[];
dataMasterStatus: any; dataMasterStatus: any;
constructor( constructor(
@ -27,6 +29,7 @@ export class AddEditMasterRoomComponent {
ngOnInit() { ngOnInit() {
this.createForm(); this.createForm();
this.listDataStatus(); this.listDataStatus();
this.listDataBuilding();
if (this.dataRow) { if (this.dataRow) {
this.editForm(); this.editForm();
@ -36,7 +39,8 @@ export class AddEditMasterRoomComponent {
createForm() { createForm() {
this.myForm = this.fb.group({ this.myForm = this.fb.group({
name: ["", Validators.required], name: ["", Validators.required],
// statusId: [0, Validators.required], statusId: [0, Validators.required],
buildingId: [0, Validators.required],
description: ["", Validators.required], description: ["", Validators.required],
}); });
} }
@ -45,7 +49,8 @@ export class AddEditMasterRoomComponent {
this.myForm = this.fb.group({ this.myForm = this.fb.group({
id: this.dataRow.id, id: this.dataRow.id,
name: this.dataRow.name, name: this.dataRow.name,
// statusId: this.dataRow.statusId, statusId: this.dataRow.statusId,
buildingId: this.dataRow.buildingId,
description: this.dataRow.description, description: this.dataRow.description,
}); });
} }
@ -58,8 +63,19 @@ export class AddEditMasterRoomComponent {
); );
this.dataStatus = this.dataMasterStatus.headerDetailParam; this.dataStatus = this.dataMasterStatus.headerDetailParam;
this.filteredDataStatus = this.dataStatus.filter( this.filteredDataStatus = this.dataStatus.filter(
(item) => item.status === "1" (item) => item.status === "2"
); );
});
}
listDataBuilding(){
this.monitoringApiService.getMasterBuildingData().subscribe((res) => {
this.dataBuilding = res.results.data;
this.filteredDataBuilding = this.dataBuilding.filter(
(item) => item.statusId === 2
);
}); });
} }
@ -68,11 +84,4 @@ export class AddEditMasterRoomComponent {
this.activeModal.close(this.myForm.value); this.activeModal.close(this.myForm.value);
} }
} }
addDepartment() {
let newDept = prompt("Enter new department name:");
if (newDept) {
alert(`Department ${newDept} added! (simulated)`);
}
}
} }

View File

@ -64,23 +64,55 @@
</ng-template> </ng-template>
</ngx-datatable-column> </ngx-datatable-column>
<ngx-datatable-column <ngx-datatable-column
name="Name" name="roomEntity"
[flexGrow]="1" [flexGrow]="1"
[minWidth]="90" [minWidth]="90"
> >
<ng-template ngx-datatable-header-template> <ng-template ngx-datatable-header-template>
<span style="color: #ffffff">Room Name</span> <span style="color: #ffffff">Room</span>
</ng-template> </ng-template>
<ng-template <ng-template
let-value="value" let-value="value"
ngx-datatable-cell-template ngx-datatable-cell-template
> >
<p style="color: #ffffff">{{ value }}</p> <p style="color: #ffffff">{{ value.name }}</p>
</ng-template> </ng-template>
</ngx-datatable-column> </ngx-datatable-column>
<ngx-datatable-column <ngx-datatable-column
name="statusId" name="buildingEntity"
[flexGrow]="1"
[minWidth]="90"
>
<ng-template ngx-datatable-header-template>
<span style="color: #ffffff">Building</span>
</ng-template>
<ng-template
let-value="value"
ngx-datatable-cell-template
>
<p style="color: #ffffff">{{ value.name }}</p>
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column
name="roomEntity"
[flexGrow]="1"
[minWidth]="90"
>
<ng-template ngx-datatable-header-template>
<span style="color: #ffffff">Description</span>
</ng-template>
<ng-template
ngx-datatable-cell-template
let-value="value"
>
<p style="color: #ffffff">{{ value.description }}</p>
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column
name="statusEntity"
[flexGrow]="1" [flexGrow]="1"
[minWidth]="90" [minWidth]="90"
> >
@ -91,7 +123,7 @@
ngx-datatable-cell-template ngx-datatable-cell-template
let-value="value" let-value="value"
> >
<p style="color: #ffffff">{{ value === 2 ? "Aktif" : "Tidak Aktif" }}</p> <p style="color: #ffffff">{{ value.name }}</p>
</ng-template> </ng-template>
</ngx-datatable-column> </ngx-datatable-column>
<ngx-datatable-column <ngx-datatable-column

View File

@ -1,14 +1,14 @@
import { Component } from '@angular/core'; import { Component } from "@angular/core";
import { AddEditMasterRoomComponent } from './add-edit-master-room/add-edit-master-room.component'; import { AddEditMasterRoomComponent } from "./add-edit-master-room/add-edit-master-room.component";
import { TableApiService } from 'src/app/_services/table-api.service'; import { TableApiService } from "src/app/_services/table-api.service";
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
import { Router } from '@angular/router'; import { Router } from "@angular/router";
import { BuildingService } from '../../service/monitoring-api.service'; import { BuildingService } from "../../service/monitoring-api.service";
@Component({ @Component({
selector: 'app-master-room', selector: "app-master-room",
templateUrl: './master-room.component.html', templateUrl: "./master-room.component.html",
styleUrls: ['./master-room.component.css'] styleUrls: ["./master-room.component.css"],
}) })
export class MasterRoomComponent { export class MasterRoomComponent {
data: any; data: any;
@ -18,9 +18,7 @@ export class MasterRoomComponent {
public breadcrumb: any; public breadcrumb: any;
constructor( constructor(
private tableApiservice: TableApiService,
private modalService: NgbModal, private modalService: NgbModal,
private router: Router,
private monitoringApiService: BuildingService private monitoringApiService: BuildingService
) {} ) {}
@ -42,9 +40,9 @@ export class MasterRoomComponent {
} }
fetchData() { fetchData() {
this.monitoringApiService.getMasterRoomData().subscribe((res) => { this.monitoringApiService.getBuildingRoomList().subscribe((res) => {
this.data = res.results.data; this.data = res;
this.filteredRows = this.data; this.filteredRows = this.data.results.data;
}); });
} }
@ -75,10 +73,23 @@ export class MasterRoomComponent {
modalRef.result.then( modalRef.result.then(
(result) => { (result) => {
if (result) { if (result) {
const filteredData = {
name: result.name,
description: result.description,
};
this.monitoringApiService this.monitoringApiService
.postMasterRoomParam(result) .postMasterRoomParam(filteredData)
.subscribe((res) => { .subscribe((res) => {
this.fetchData(); const transformedData = {
buildingId: result.buildingId,
roomId: res.data.id,
statusId: result.statusId,
};
this.monitoringApiService
.postBatchBuilding(transformedData)
.subscribe((res) => {
this.fetchData();
});
}); });
} }
}, },

View File

@ -16,6 +16,14 @@
"name": "Plug Line", "name": "Plug Line",
"icon": "ri-plug-2-line" "icon": "ri-plug-2-line"
}, },
{
"name": "Camera Line",
"icon": "ri-dv-line"
},
{
"name": "Camera Fill",
"icon": "ri-dv-fill"
},
{ {
"name": "Airplay Fill", "name": "Airplay Fill",
"icon": "ri-airplay-fill" "icon": "ri-airplay-fill"