integrasi table device dan table master category
This commit is contained in:
		
							parent
							
								
									cfa140b6ea
								
							
						
					
					
						commit
						e92c576844
					
				| @ -36,19 +36,19 @@ | |||||||
|                             type="text" |                             type="text" | ||||||
|                             id="projectinput1" |                             id="projectinput1" | ||||||
|                             class="form-control" |                             class="form-control" | ||||||
|                             formControlName="firstName" |                             formControlName="name" | ||||||
|                             placeholder="First Name" |                             placeholder="Device Name" | ||||||
|                             [ngClass]="{ |                             [ngClass]="{ | ||||||
|                               'is-invalid': submitted && f.firstName.errors |                               'is-invalid': submitted && f.name.errors | ||||||
|                             }" |                             }" | ||||||
|                           /> |                           /> | ||||||
|                           <small |                           <small | ||||||
|                             class="form-text text-muted danger" |                             class="form-text text-muted danger" | ||||||
|                             *ngIf="submitted && f.firstName.errors" |                             *ngIf="submitted && f.name.errors" | ||||||
|                             class="invalid-feedback" |                             class="invalid-feedback" | ||||||
|                           > |                           > | ||||||
|                             <div *ngIf="f.firstName.errors.required"> |                             <div *ngIf="f.name.errors.required"> | ||||||
|                               First Name is required |                               Device Name is required | ||||||
|                             </div> |                             </div> | ||||||
|                           </small> |                           </small> | ||||||
|                         </div> |                         </div> | ||||||
| @ -430,7 +430,7 @@ | |||||||
|                     > |                     > | ||||||
|                       <i class="feather ft-x"></i> Cancel |                       <i class="feather ft-x"></i> Cancel | ||||||
|                     </button> |                     </button> | ||||||
|                     <button type="submit" class="btn btn-primary"> |                     <button type="submit" class="btn btn-primary" (click)="saveEdit()"> | ||||||
|                       <i class="la la-check"></i> Save |                       <i class="la la-check"></i> Save | ||||||
|                     </button> |                     </button> | ||||||
|                   </div> |                   </div> | ||||||
|  | |||||||
| @ -2,6 +2,7 @@ import { Component, OnInit, ViewChild } from "@angular/core"; | |||||||
| import { FormBuilder, FormGroup, NgForm, Validators } from "@angular/forms"; | import { FormBuilder, FormGroup, NgForm, Validators } from "@angular/forms"; | ||||||
| import { ActivatedRoute, Router } from "@angular/router"; | import { ActivatedRoute, Router } from "@angular/router"; | ||||||
| import { BlockUI, NgBlockUI } from "ng-block-ui"; | import { BlockUI, NgBlockUI } from "ng-block-ui"; | ||||||
|  | import { BuildingService } from "../../service/monitoring-api.service"; | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: "app-add-edit-device", |   selector: "app-add-edit-device", | ||||||
| @ -53,17 +54,32 @@ export class AddEditDeviceComponent implements OnInit{ | |||||||
|   constructor( |   constructor( | ||||||
|     private formBuilder: FormBuilder, |     private formBuilder: FormBuilder, | ||||||
|     private router: Router, |     private router: Router, | ||||||
|     private route: ActivatedRoute |     private route: ActivatedRoute, | ||||||
|  |     private monitoringApiService: BuildingService, | ||||||
|   ) {} |   ) {} | ||||||
| 
 | 
 | ||||||
|   ngOnInit() { |   ngOnInit() { | ||||||
|     this.route.data.subscribe((data) => { |     this.route.data.subscribe((data) => { | ||||||
|  |       console.log(data); | ||||||
|  |        | ||||||
|       this.mode = data.mode; |       this.mode = data.mode; | ||||||
|  |       console.log(this.mode); | ||||||
|  |        | ||||||
|  |     }); | ||||||
|  |     this.route.params.subscribe(params => { | ||||||
|  |       console.log(params); | ||||||
|  |        | ||||||
|  |       const deviceId = params['id']; | ||||||
|  |       console.log(deviceId); | ||||||
|  |        | ||||||
|  |       if (deviceId) { | ||||||
|  |         this.loadDevice(deviceId); | ||||||
|  |       } | ||||||
|     }); |     }); | ||||||
|     this.setBreadcrumb() |     this.setBreadcrumb() | ||||||
| 
 | 
 | ||||||
|     this.projectInfo = this.formBuilder.group({ |     this.projectInfo = this.formBuilder.group({ | ||||||
|       firstName: ["", Validators.required], |       name: ["", Validators.required], | ||||||
|       lastName: ["", Validators.required], |       lastName: ["", Validators.required], | ||||||
|       email: ["", [Validators.required, Validators.email]], |       email: ["", [Validators.required, Validators.email]], | ||||||
|       phone: ["", Validators.required], |       phone: ["", Validators.required], | ||||||
| @ -75,6 +91,15 @@ export class AddEditDeviceComponent implements OnInit{ | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   loadDevice(deviceId: string) { | ||||||
|  |     this.monitoringApiService.getDeviceById(deviceId).subscribe(data => { | ||||||
|  |       console.log(data); | ||||||
|  |       this.projectInfo = this.formBuilder.group({ | ||||||
|  |         name: data.name, | ||||||
|  |       }); | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|   setBreadcrumb() { |   setBreadcrumb() { | ||||||
|     if (this.isAddMode()) { |     if (this.isAddMode()) { | ||||||
|       this.breadcrumb = { |       this.breadcrumb = { | ||||||
| @ -164,7 +189,11 @@ export class AddEditDeviceComponent implements OnInit{ | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   addData() {} |    | ||||||
|  | 
 | ||||||
|  |   saveEdit() { | ||||||
|  |      | ||||||
|  |   } | ||||||
| 
 | 
 | ||||||
|   cancel() { |   cancel() { | ||||||
|     this.router.navigate(["/device"]); |     this.router.navigate(["/device"]); | ||||||
|  | |||||||
| @ -63,6 +63,20 @@ | |||||||
|                         {{ rowIndex + 1 }} |                         {{ rowIndex + 1 }} | ||||||
|                       </ng-template> |                       </ng-template> | ||||||
|                     </ngx-datatable-column> |                     </ngx-datatable-column> | ||||||
|  |                     <ngx-datatable-column | ||||||
|  |                       name="icon" | ||||||
|  |                       [flexGrow]="1" | ||||||
|  |                       [minWidth]="140" | ||||||
|  |                     > | ||||||
|  |                     <ng-template ngx-datatable-header-template> | ||||||
|  |                       <span>Device Name</span> | ||||||
|  |                     </ng-template> | ||||||
|  |                       <ng-template ngx-datatable-cell-template let-row="row"> | ||||||
|  |                         <span class="avatar avatar-sm rounded-circle"> | ||||||
|  |                           <img [src]="row.icon" /><i></i | ||||||
|  |                         ></span> | ||||||
|  |                       </ng-template> | ||||||
|  |                     </ngx-datatable-column> | ||||||
|                     <ngx-datatable-column |                     <ngx-datatable-column | ||||||
|                       name="Name" |                       name="Name" | ||||||
|                       [flexGrow]="1" |                       [flexGrow]="1" | ||||||
| @ -175,12 +189,12 @@ | |||||||
|                         > |                         > | ||||||
|                           <i class="ficon feather ft-edit"></i> |                           <i class="ficon feather ft-edit"></i> | ||||||
|                         </button> |                         </button> | ||||||
|                         <button |                         <!-- <button | ||||||
|                           class="btn btn-sm btn-danger" |                           class="btn btn-sm btn-danger" | ||||||
|                           (click)="deleteRow(row)" |                           (click)="deleteRow(row)" | ||||||
|                         > |                         > | ||||||
|                           <i class="ficon feather ft-trash-2"></i> |                           <i class="ficon feather ft-trash-2"></i> | ||||||
|                         </button> |                         </button> --> | ||||||
|                       </ng-template> |                       </ng-template> | ||||||
|                     </ngx-datatable-column> |                     </ngx-datatable-column> | ||||||
|                   </ngx-datatable> |                   </ngx-datatable> | ||||||
| @ -198,11 +212,13 @@ | |||||||
|                 <div class="card-body"> |                 <div class="card-body"> | ||||||
|                   <div class="media d-flex"> |                   <div class="media d-flex"> | ||||||
|                     <div class="media-body text-left"> |                     <div class="media-body text-left"> | ||||||
|                       <h6 class="text-muted">Total Use </h6> |                       <h6 class="text-muted">Total Use</h6> | ||||||
|                       <h3>3,568</h3> |                       <h3>3,568</h3> | ||||||
|                     </div> |                     </div> | ||||||
|                     <div class="align-self-center"> |                     <div class="align-self-center"> | ||||||
|                       <i class="feather ft-zap danger font-large-2 float-right"></i> |                       <i | ||||||
|  |                         class="feather ft-zap danger font-large-2 float-right" | ||||||
|  |                       ></i> | ||||||
|                     </div> |                     </div> | ||||||
|                   </div> |                   </div> | ||||||
|                 </div> |                 </div> | ||||||
| @ -219,7 +235,9 @@ | |||||||
|                       <h3>Rp 1.000.000.000.000</h3> |                       <h3>Rp 1.000.000.000.000</h3> | ||||||
|                     </div> |                     </div> | ||||||
|                     <div class="align-self-center"> |                     <div class="align-self-center"> | ||||||
|                       <i class="feather ft-trending-up success font-large-2 float-right"></i> |                       <i | ||||||
|  |                         class="feather ft-trending-up success font-large-2 float-right" | ||||||
|  |                       ></i> | ||||||
|                     </div> |                     </div> | ||||||
|                   </div> |                   </div> | ||||||
|                 </div> |                 </div> | ||||||
|  | |||||||
| @ -4,6 +4,7 @@ import { NgBlockUI, BlockUI } from "ng-block-ui"; | |||||||
| import { TableApiService } from "src/app/_services/table-api.service"; | import { TableApiService } from "src/app/_services/table-api.service"; | ||||||
| import { ModalAddEditComponent } from "./modal-add-edit/modal-add-edit.component"; | import { ModalAddEditComponent } from "./modal-add-edit/modal-add-edit.component"; | ||||||
| import { ActivatedRoute, Router } from "@angular/router"; | import { ActivatedRoute, Router } from "@angular/router"; | ||||||
|  | import { BuildingService } from "../service/monitoring-api.service"; | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: "app-device", |   selector: "app-device", | ||||||
| @ -23,7 +24,8 @@ export class DeviceComponent implements OnInit { | |||||||
|   constructor( |   constructor( | ||||||
|     private tableApiservice: TableApiService, |     private tableApiservice: TableApiService, | ||||||
|     private modalService: NgbModal, |     private modalService: NgbModal, | ||||||
|     private router: Router |     private router: Router, | ||||||
|  |     private monitoringApiService: BuildingService, | ||||||
|   ) {} |   ) {} | ||||||
| 
 | 
 | ||||||
|   ngOnInit() { |   ngOnInit() { | ||||||
| @ -45,9 +47,10 @@ export class DeviceComponent implements OnInit { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   fetchData() { |   fetchData() { | ||||||
|     this.tableApiservice.getTableInitialisationData().subscribe((response) => { |     this.monitoringApiService.getDeviceData().subscribe((res) => { | ||||||
|       this.data = response; |       console.log(res); | ||||||
|       this.filteredRows = this.data.rows; |       this.data = res; | ||||||
|  |       this.filteredRows = this.data.data; | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -98,11 +101,11 @@ export class DeviceComponent implements OnInit { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   viewRow(row) { |   viewRow(row) { | ||||||
|     this.router.navigate(["/device/view", row.name]); |     this.router.navigate(["/device/view", row.id]); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   editRow(row) { |   editRow(row) { | ||||||
|     this.router.navigate(["/device/edit", row.name]); |     this.router.navigate(["/device/edit", row.id]); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   deleteRow(row) { |   deleteRow(row) { | ||||||
| @ -112,6 +115,9 @@ export class DeviceComponent implements OnInit { | |||||||
|   addDevice(): void { |   addDevice(): void { | ||||||
|     // Aktifkan spinner
 |     // Aktifkan spinner
 | ||||||
|     this.spinnerActive = true; |     this.spinnerActive = true; | ||||||
|  |     this.monitoringApiService.getSyncDeviceData().subscribe((res) => { | ||||||
|  |       console.log(res); | ||||||
|  |     }); | ||||||
| 
 | 
 | ||||||
|     // Lakukan proses tambahan (misalnya, panggil API atau proses yang memakan waktu)
 |     // Lakukan proses tambahan (misalnya, panggil API atau proses yang memakan waktu)
 | ||||||
|     setTimeout(() => { |     setTimeout(() => { | ||||||
|  | |||||||
| @ -0,0 +1,56 @@ | |||||||
|  | /* modal-add-edit.component.css */ | ||||||
|  | ::ng-deep .modal-backdrop.show { | ||||||
|  |     z-index: auto !important; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   ::ng-deep .input-group-append .btn { | ||||||
|  |       border-top-left-radius: 0; | ||||||
|  |       border-bottom-left-radius: 0; | ||||||
|  |       border-radius: 0; | ||||||
|  |       border-left: 0; | ||||||
|  |       flex-grow: 0; | ||||||
|  |       border-left: 1px solid #ced4da; | ||||||
|  |       padding: 0.375rem 0.75rem; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   ::ng-deep .input-group { | ||||||
|  |     display: flex; | ||||||
|  |     flex-wrap: nowrap; /* Prevents wrapping of the items */ | ||||||
|  |     align-items: center; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   ::ng-deep .form-control { | ||||||
|  |     flex-grow: 1; /* Ensures select takes up available space */ | ||||||
|  |     padding-right: 0.5rem; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   ::ng-deep .input-group select,  | ||||||
|  |   ::ng-deep .input-group .input-group-append .btn { | ||||||
|  |     padding-right: 5px; /* Adjust padding if necessary */ | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   ::ng-deep .input-group .form-control { | ||||||
|  |     margin-right: 2px; /* Adjust margin to make space */ | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |    | ||||||
|  |   .form-group { | ||||||
|  |     margin-bottom: 1rem; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   .form-control { | ||||||
|  |     display: block; | ||||||
|  |     width: 100%; | ||||||
|  |     height: calc(1.5em + 0.75rem + 2px); | ||||||
|  |     padding: 0.375rem 0.75rem; | ||||||
|  |     font-size: 1rem; | ||||||
|  |     font-weight: 400; | ||||||
|  |     line-height: 1.5; | ||||||
|  |     color: #495057; | ||||||
|  |     background-color: #fff; | ||||||
|  |     background-clip: padding-box; | ||||||
|  |     border: 1px solid #ced4da; | ||||||
|  |     border-radius: 0.25rem; | ||||||
|  |     transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; | ||||||
|  |   } | ||||||
|  |    | ||||||
| @ -0,0 +1,44 @@ | |||||||
|  | <div class="modal-header"> | ||||||
|  |   <h4 class="modal-title">Add New Row</h4> | ||||||
|  |   <button type="button" class="close" aria-label="Close"> | ||||||
|  |     <span aria-hidden="true">×</span> | ||||||
|  |   </button> | ||||||
|  | </div> | ||||||
|  | <div class="modal-body"> | ||||||
|  |   <form [formGroup]="myForm"> | ||||||
|  |     <div class="form-row"> | ||||||
|  |       <div class="form-group col-md-6"> | ||||||
|  |         <label for="name">Name:</label> | ||||||
|  |         <input | ||||||
|  |           type="text" | ||||||
|  |           class="form-control" | ||||||
|  |           id="name" | ||||||
|  |           formControlName="name" | ||||||
|  |         /> | ||||||
|  |       </div> | ||||||
|  |       <div class="form-group col-md-6"> | ||||||
|  |         <label for="status">Status:</label> | ||||||
|  |         <select | ||||||
|  |           id="projectinput5" | ||||||
|  |           class="form-control" | ||||||
|  |           formControlName="status" | ||||||
|  |         > | ||||||
|  |           <option value="1">Aktif</option> | ||||||
|  |           <option value="0">Tidak Aktif</option> | ||||||
|  |         </select> | ||||||
|  |       </div> | ||||||
|  |     </div> | ||||||
|  |   </form> | ||||||
|  | </div> | ||||||
|  | <div class="modal-footer"> | ||||||
|  |   <button | ||||||
|  |     type="button" | ||||||
|  |     class="btn btn-secondary" | ||||||
|  |     (click)="activeModal.dismiss('Cross click')" | ||||||
|  |   > | ||||||
|  |     Close | ||||||
|  |   </button> | ||||||
|  |   <button type="button" class="btn btn-primary" (click)="addRow()"> | ||||||
|  |     Save Changes | ||||||
|  |   </button> | ||||||
|  | </div> | ||||||
| @ -0,0 +1,23 @@ | |||||||
|  | import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||||||
|  | 
 | ||||||
|  | import { AddEditMasterComponent } from './add-edit-master.component'; | ||||||
|  | 
 | ||||||
|  | describe('AddEditMasterComponent', () => { | ||||||
|  |   let component: AddEditMasterComponent; | ||||||
|  |   let fixture: ComponentFixture<AddEditMasterComponent>; | ||||||
|  | 
 | ||||||
|  |   beforeEach(async () => { | ||||||
|  |     await TestBed.configureTestingModule({ | ||||||
|  |       declarations: [ AddEditMasterComponent ] | ||||||
|  |     }) | ||||||
|  |     .compileComponents(); | ||||||
|  | 
 | ||||||
|  |     fixture = TestBed.createComponent(AddEditMasterComponent); | ||||||
|  |     component = fixture.componentInstance; | ||||||
|  |     fixture.detectChanges(); | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  |   it('should create', () => { | ||||||
|  |     expect(component).toBeTruthy(); | ||||||
|  |   }); | ||||||
|  | }); | ||||||
| @ -0,0 +1,54 @@ | |||||||
|  | import { Component, Input, OnInit } from '@angular/core'; | ||||||
|  | import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||||||
|  | import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; | ||||||
|  | 
 | ||||||
|  | @Component({ | ||||||
|  |   selector: 'app-add-edit-master', | ||||||
|  |   templateUrl: './add-edit-master.component.html', | ||||||
|  |   styleUrls: ['./add-edit-master.component.css'] | ||||||
|  | }) | ||||||
|  | export class AddEditMasterComponent implements OnInit{ | ||||||
|  |   @Input() headerId: number; | ||||||
|  |   @Input() dataRow: any; | ||||||
|  |   @Input() mode: any; | ||||||
|  |   myForm: FormGroup; | ||||||
|  | 
 | ||||||
|  |   constructor(public activeModal: NgbActiveModal, private fb: FormBuilder) {} | ||||||
|  | 
 | ||||||
|  |   ngOnInit() { | ||||||
|  |     this.createForm(); | ||||||
|  |     if (this.dataRow) { | ||||||
|  |       this.editForm(); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   createForm() { | ||||||
|  |     this.myForm = this.fb.group({ | ||||||
|  |       name: ['', Validators.required], | ||||||
|  |       status: ['', Validators.required], | ||||||
|  |       headerId: this.headerId | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   editForm(){ | ||||||
|  |     this.myForm = this.fb.group({ | ||||||
|  |       id: this.dataRow.id, | ||||||
|  |       name: this.dataRow.name, | ||||||
|  |       status: this.dataRow.status, | ||||||
|  |       headerId: this.dataRow.headerId | ||||||
|  |     }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   addRow() { | ||||||
|  |     if (this.myForm.valid) { | ||||||
|  |       this.activeModal.close(this.myForm.value); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   addDepartment() { | ||||||
|  |     let newDept = prompt("Enter new department name:"); | ||||||
|  |     if (newDept) { | ||||||
|  |       alert(`Department ${newDept} added! (simulated)`); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -29,6 +29,7 @@ | |||||||
|                     <div class="col-md-6 text-right"> |                     <div class="col-md-6 text-right"> | ||||||
|                       <button |                       <button | ||||||
|                         class="btn btn-secondary" |                         class="btn btn-secondary" | ||||||
|  |                         (click)="openAddMasterModal()" | ||||||
|                       > |                       > | ||||||
|                         <i class="feather ft-plus"></i>  Add new master |                         <i class="feather ft-plus"></i>  Add new master | ||||||
|                       </button> |                       </button> | ||||||
| @ -74,7 +75,7 @@ | |||||||
|                         </ng-template> |                         </ng-template> | ||||||
|                       </ngx-datatable-column> |                       </ngx-datatable-column> | ||||||
|                       <ngx-datatable-column |                       <ngx-datatable-column | ||||||
|                         name="Salary" |                         name="Status" | ||||||
|                         [flexGrow]="1" |                         [flexGrow]="1" | ||||||
|                         [minWidth]="90" |                         [minWidth]="90" | ||||||
|                       > |                       > | ||||||
| @ -85,7 +86,7 @@ | |||||||
|                           ngx-datatable-cell-template |                           ngx-datatable-cell-template | ||||||
|                           let-value="value" |                           let-value="value" | ||||||
|                         > |                         > | ||||||
|                           {{ value }} |                           {{ value === '1' ? 'Aktif' : 'Tidak Aktif'}} | ||||||
|                         </ng-template> |                         </ng-template> | ||||||
|                       </ngx-datatable-column> |                       </ngx-datatable-column> | ||||||
|                       <ngx-datatable-column |                       <ngx-datatable-column | ||||||
| @ -98,20 +99,16 @@ | |||||||
|                           let-rowIndex="rowIndex" |                           let-rowIndex="rowIndex" | ||||||
|                           let-row="row" |                           let-row="row" | ||||||
|                         > |                         > | ||||||
|                           <button |  | ||||||
|                             class="btn btn-sm btn-info mr-1" |  | ||||||
|                              |  | ||||||
|                           > |  | ||||||
|                             <i class="ficon feather ft-eye"></i> |  | ||||||
|                           </button> |  | ||||||
|                           <button |                           <button | ||||||
|                             class="btn btn-sm btn-warning mr-1" |                             class="btn btn-sm btn-warning mr-1" | ||||||
|  |                             (click)="editRow(row)" | ||||||
|                              |                              | ||||||
|                           > |                           > | ||||||
|                             <i class="ficon feather ft-edit"></i> |                             <i class="ficon feather ft-edit"></i> | ||||||
|                           </button> |                           </button> | ||||||
|                           <button |                           <button | ||||||
|                             class="btn btn-sm btn-danger" |                             class="btn btn-sm btn-danger" | ||||||
|  |                             (click)="deleteRow(row)" | ||||||
|                              |                              | ||||||
|                           > |                           > | ||||||
|                             <i class="ficon feather ft-trash-2"></i> |                             <i class="ficon feather ft-trash-2"></i> | ||||||
|  | |||||||
| @ -1,27 +1,31 @@ | |||||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from "@angular/core"; | ||||||
| import { Router } from '@angular/router'; | import { Router } from "@angular/router"; | ||||||
| import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; | import { NgbModal } from "@ng-bootstrap/ng-bootstrap"; | ||||||
| import { BlockUI, NgBlockUI } from 'ng-block-ui'; | import { BlockUI, NgBlockUI } from "ng-block-ui"; | ||||||
| import { TableApiService } from 'src/app/_services/table-api.service'; | import { TableApiService } from "src/app/_services/table-api.service"; | ||||||
|  | import { BuildingService } from "../../service/monitoring-api.service"; | ||||||
|  | import { AddEditMasterComponent } from "../add-edit-master/add-edit-master.component"; | ||||||
| 
 | 
 | ||||||
| @Component({ | @Component({ | ||||||
|   selector: 'app-master-category', |   selector: "app-master-category", | ||||||
|   templateUrl: './master-category.component.html', |   templateUrl: "./master-category.component.html", | ||||||
|   styleUrls: ['./master-category.component.css'] |   styleUrls: ["./master-category.component.css"], | ||||||
| }) | }) | ||||||
| export class MasterCategoryComponent implements OnInit{ | export class MasterCategoryComponent implements OnInit { | ||||||
|   data: any; |   data: any; | ||||||
|   filteredRows: any[]; |   filteredRows: any[]; | ||||||
|   searchTerm: string = ""; |   searchTerm: string = ""; | ||||||
|   rows: any = []; |   rows: any = []; | ||||||
|   public breadcrumb: any; |   public breadcrumb: any; | ||||||
|  |   dataMasterCategori: any; | ||||||
| 
 | 
 | ||||||
|   @BlockUI("zeroConfiguration") blockUIZeroConfiguration: NgBlockUI; |   @BlockUI("zeroConfiguration") blockUIZeroConfiguration: NgBlockUI; | ||||||
| 
 | 
 | ||||||
|   constructor( |   constructor( | ||||||
|     private tableApiservice: TableApiService, |     private tableApiservice: TableApiService, | ||||||
|     private modalService: NgbModal, |     private modalService: NgbModal, | ||||||
|     private router: Router |     private router: Router, | ||||||
|  |     private monitoringApiService: BuildingService | ||||||
|   ) {} |   ) {} | ||||||
| 
 | 
 | ||||||
|   ngOnInit() { |   ngOnInit() { | ||||||
| @ -42,19 +46,25 @@ export class MasterCategoryComponent implements OnInit{ | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   fetchData() { |   fetchData() { | ||||||
|     this.tableApiservice.getTableInitialisationData().subscribe((response) => { |     this.monitoringApiService.getMasterData().subscribe((res) => { | ||||||
|       this.data = response; |       this.data = res.data.data; | ||||||
|       this.filteredRows = this.data.rows; |       this.dataMasterCategori = res.data.data.find( | ||||||
|  |         (item) => item.name === "master_category" | ||||||
|  |       ); | ||||||
|  |       this.filteredRows = this.dataMasterCategori.headerDetailParam; | ||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   filterRows() { |   filterRows() { | ||||||
|     if (!this.searchTerm) { |     if (!this.searchTerm) { | ||||||
|       this.filteredRows = [...this.data.rows]; |       this.filteredRows = [ | ||||||
|  |         ...this.data.find((item) => item.name === "master_category") | ||||||
|  |           .headerDetailParam, | ||||||
|  |       ]; | ||||||
|     } else { |     } else { | ||||||
|       this.filteredRows = this.data.rows.filter((row) => |       this.filteredRows = this.data | ||||||
|         this.rowContainsSearchTerm(row) |         .find((item) => item.name === "master_category") | ||||||
|       ); |         .headerDetailParam.filter((row) => this.rowContainsSearchTerm(row)); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -62,22 +72,69 @@ export class MasterCategoryComponent implements OnInit{ | |||||||
|     const searchTermLC = this.searchTerm.toLowerCase(); |     const searchTermLC = this.searchTerm.toLowerCase(); | ||||||
|     return Object.values(row).some( |     return Object.values(row).some( | ||||||
|       (value) => |       (value) => | ||||||
|         value !== null && |         value !== null && value.toString().toLowerCase().includes(searchTermLC) | ||||||
|         value.toString().toLowerCase().includes(searchTermLC) |  | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   viewRow(row) { |   openAddMasterModal() { | ||||||
|     console.log("View row:", row); |     const modalRef = this.modalService.open(AddEditMasterComponent, { | ||||||
|     this.router.navigate(["/device/view", row.name]); |       size: "lg", | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     modalRef.componentInstance.headerId = this.dataMasterCategori.id; | ||||||
|  |     modalRef.componentInstance.mode = "add"; | ||||||
|  |     modalRef.result.then( | ||||||
|  |       (result) => { | ||||||
|  |         console.log(result); | ||||||
|  |         if (result) { | ||||||
|  |           this.monitoringApiService | ||||||
|  |             .postHeaderDetailParam(result) | ||||||
|  |             .subscribe((res) => { | ||||||
|  |               console.log(res); | ||||||
|  |               this.fetchData(); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |       }, | ||||||
|  |       (reason) => { | ||||||
|  |         console.log(`Dismissed: ${reason}`); | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   editRow(row) { |   editRow(row) { | ||||||
|     console.log("Edit row:", row); |     const modalRef = this.modalService.open(AddEditMasterComponent, { | ||||||
|     this.router.navigate(["/device/edit", row.name]); |       size: "lg", | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     modalRef.componentInstance.headerId = this.dataMasterCategori.id; | ||||||
|  |     modalRef.componentInstance.dataRow = row; | ||||||
|  |     modalRef.componentInstance.mode = "edit"; | ||||||
|  |     modalRef.result.then( | ||||||
|  |       (result) => { | ||||||
|  |         console.log(result); | ||||||
|  |         if (result) { | ||||||
|  |           this.monitoringApiService | ||||||
|  |             .putHeaderDetailParam(result, row.id) | ||||||
|  |             .subscribe((res) => { | ||||||
|  |               console.log(res); | ||||||
|  |               this.fetchData(); | ||||||
|  |             }); | ||||||
|  |         } | ||||||
|  |       }, | ||||||
|  |       (reason) => { | ||||||
|  |         console.log(`Dismissed: ${reason}`); | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   deleteRow(row) { |   deleteRow(row) { | ||||||
|     console.log("Delete row:", row); |     const confirmDelete = confirm("Are you sure you want to delete this item?"); | ||||||
|  |     if (confirmDelete) { | ||||||
|  |       this.monitoringApiService | ||||||
|  |         .deleteHeaderDetailParam(row.id) | ||||||
|  |         .subscribe((res) => { | ||||||
|  |           this.fetchData(); | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -8,7 +8,7 @@ import { MasterTypeComponent } from './master-type/master-type.component'; | |||||||
| import { RouterModule } from '@angular/router'; | import { RouterModule } from '@angular/router'; | ||||||
| import { ChartistModule } from 'ng-chartist'; | import { ChartistModule } from 'ng-chartist'; | ||||||
| import { NgxDatatableModule } from '@swimlane/ngx-datatable'; | import { NgxDatatableModule } from '@swimlane/ngx-datatable'; | ||||||
| import { FormsModule } from '@angular/forms'; | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | ||||||
| import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; | import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; | ||||||
| import { NgChartsModule } from 'ng2-charts'; | import { NgChartsModule } from 'ng2-charts'; | ||||||
| import { BlockUIModule } from 'ng-block-ui'; | import { BlockUIModule } from 'ng-block-ui'; | ||||||
| @ -21,6 +21,7 @@ import { MasterStatusComponent } from './master-status/master-status.component'; | |||||||
| import { MasterDurationUseComponent } from './master-duration-use/master-duration-use.component'; | import { MasterDurationUseComponent } from './master-duration-use/master-duration-use.component'; | ||||||
| import { MasterUserComponent } from './master-user/master-user.component'; | import { MasterUserComponent } from './master-user/master-user.component'; | ||||||
| import { MasterRoleComponent } from './master-role/master-role.component'; | import { MasterRoleComponent } from './master-role/master-role.component'; | ||||||
|  | import { AddEditMasterComponent } from './add-edit-master/add-edit-master.component'; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -33,7 +34,8 @@ import { MasterRoleComponent } from './master-role/master-role.component'; | |||||||
|     MasterStatusComponent, |     MasterStatusComponent, | ||||||
|     MasterDurationUseComponent, |     MasterDurationUseComponent, | ||||||
|     MasterUserComponent, |     MasterUserComponent, | ||||||
|     MasterRoleComponent |     MasterRoleComponent, | ||||||
|  |     AddEditMasterComponent | ||||||
|   ], |   ], | ||||||
|   imports: [ |   imports: [ | ||||||
|     CommonModule, |     CommonModule, | ||||||
| @ -45,6 +47,7 @@ import { MasterRoleComponent } from './master-role/master-role.component'; | |||||||
|     NgxDatatableModule, |     NgxDatatableModule, | ||||||
|     PerfectScrollbarModule, |     PerfectScrollbarModule, | ||||||
|     BreadcrumbModule, |     BreadcrumbModule, | ||||||
|  |     ReactiveFormsModule, | ||||||
|     NgbModule, |     NgbModule, | ||||||
|     BlockUIModule.forRoot({ |     BlockUIModule.forRoot({ | ||||||
|       template: BlockTemplateComponent |       template: BlockTemplateComponent | ||||||
|  | |||||||
| @ -43,7 +43,7 @@ | |||||||
|                       class="text-muted mb-0" |                       class="text-muted mb-0" | ||||||
|                       style="font-family: Montserrat, sans-serif" |                       style="font-family: Montserrat, sans-serif" | ||||||
|                     > |                     > | ||||||
|                       {{ data.build_name }} |                       {{ data.build_name ? data.build_name : data.name}} | ||||||
|                     </h3> |                     </h3> | ||||||
|                   </div> |                   </div> | ||||||
|                 </div> |                 </div> | ||||||
|  | |||||||
| @ -48,10 +48,25 @@ export class BuildingComponent { | |||||||
|       }, |       }, | ||||||
|     }; |     }; | ||||||
|     this.fetchData(); |     this.fetchData(); | ||||||
|     this.buildingData(); |     // this.buildingData();
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   fetchData() { |   fetchData() { | ||||||
|  |     // this.monitoringApiService.getBuildingData().subscribe((res) => {
 | ||||||
|  |     //   this.data = res;
 | ||||||
|  |     //   this.filteredRows = res.data;
 | ||||||
|  |     //   console.log(this.filteredRows);
 | ||||||
|  |        | ||||||
|  |     //   this.dataTop = [];
 | ||||||
|  |     //   for (let i = 0; i < res.length; i++) {
 | ||||||
|  |     //     if (res[i].topUse.label[i]) {
 | ||||||
|  |     //       this.dataTop.push({
 | ||||||
|  |     //         label: res[i].topUse.label ? res[i].topUse.label : '',
 | ||||||
|  |     //         value: res[i].topUse.value ? res[i].topUse.value : 0,
 | ||||||
|  |     //       });
 | ||||||
|  |     //     }
 | ||||||
|  |     //   }
 | ||||||
|  |     // });
 | ||||||
|     this.monitoringService.getMonitoringBuildingData().subscribe((res) => { |     this.monitoringService.getMonitoringBuildingData().subscribe((res) => { | ||||||
|       this.data = res; |       this.data = res; | ||||||
|       this.filteredRows = res; |       this.filteredRows = res; | ||||||
|  | |||||||
| @ -9,8 +9,74 @@ export class BuildingService { | |||||||
|   constructor(private http: HttpClient) {} |   constructor(private http: HttpClient) {} | ||||||
| 
 | 
 | ||||||
|   getBuildingData(page: number = 1, limit: number = 10): Observable<any> { |   getBuildingData(page: number = 1, limit: number = 10): Observable<any> { | ||||||
|     const url = `http://167.86.72.99:3100/building?page=${page}&limit=${limit}`; |     const url = `https://kapi.absys.ninja/hemat/building?page=${page}&limit=${limit}`; | ||||||
|     const headers = new HttpHeaders().set('Content-Type', 'application/json'); |     // const headers = new HttpHeaders().set('Content-Type', 'application/json');
 | ||||||
|  |     const headers = new HttpHeaders({ | ||||||
|  |       'Content-Type': 'application/json', | ||||||
|  |       'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' | ||||||
|  |     }); | ||||||
|     return this.http.get<any>(url, { headers }); |     return this.http.get<any>(url, { headers }); | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   getDeviceData(page: number = 1, limit: number = 10): Observable<any> { | ||||||
|  |     const url = `https://kapi.absys.ninja/hemat/devices?page=${page}&limit=${limit}`; | ||||||
|  |     const headers = new HttpHeaders({ | ||||||
|  |       'Content-Type': 'application/json', | ||||||
|  |       'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' | ||||||
|  |     }); | ||||||
|  |     return this.http.get<any>(url, { headers }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   getSyncDeviceData(page: number = 1, limit: number = 10): Observable<any> { | ||||||
|  |     const url = `https://kapi.absys.ninja/hemat/devices/Synchronization`; | ||||||
|  |     const headers = new HttpHeaders({ | ||||||
|  |       'Content-Type': 'application/json', | ||||||
|  |       'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' | ||||||
|  |     }); | ||||||
|  |     return this.http.get<any>(url, { headers }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   getDeviceById(deviceId: any): Observable<any> { | ||||||
|  |     const url = `https://kapi.absys.ninja/hemat/devices/${deviceId}`; | ||||||
|  |     const headers = new HttpHeaders({ | ||||||
|  |       'Content-Type': 'application/json', | ||||||
|  |       'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' | ||||||
|  |     }); | ||||||
|  |     return this.http.get<any>(url, { headers }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   getMasterData(page: number = 1, limit: number = 10): Observable<any> { | ||||||
|  |     const url = `https://kapi.absys.ninja/hemat/header-param?page=${page}&limit=${limit}`; | ||||||
|  |     const headers = new HttpHeaders({ | ||||||
|  |       'Content-Type': 'application/json', | ||||||
|  |       'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' | ||||||
|  |     }); | ||||||
|  |     return this.http.get<any>(url, { headers }); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   postHeaderDetailParam(data: any): Observable<any> { | ||||||
|  |     const url = `https://kapi.absys.ninja/hemat/header-detail-param`; | ||||||
|  |     const headers = new HttpHeaders({ | ||||||
|  |       'Content-Type': 'application/json', | ||||||
|  |       'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' | ||||||
|  |     }); | ||||||
|  |     return this.http.post<any>(url, data, { headers }); | ||||||
|  |   } | ||||||
|  |   putHeaderDetailParam(data: any, id: any): Observable<any> { | ||||||
|  |     const url = `https://kapi.absys.ninja/hemat/header-detail-param/${id}`; | ||||||
|  |     const headers = new HttpHeaders({ | ||||||
|  |       'Content-Type': 'application/json', | ||||||
|  |       'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' | ||||||
|  |     }); | ||||||
|  |     return this.http.put<any>(url, data, { headers }); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   deleteHeaderDetailParam(id: any): Observable<any> { | ||||||
|  |     const url = `https://kapi.absys.ninja/hemat/header-detail-param/${id}`; | ||||||
|  |     const headers = new HttpHeaders({ | ||||||
|  |       'Content-Type': 'application/json', | ||||||
|  |       'x-api-key': 'j2yaYvPSQcsEEmHh3NEobfiXyyXmmnHT' | ||||||
|  |     }); | ||||||
|  |     return this.http.delete<any>(url, { headers }); | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -64,8 +64,11 @@ export class LoginComponent implements OnInit { | |||||||
|       email: this.f.email.value, |       email: this.f.email.value, | ||||||
|       password: this.f.password.value, |       password: this.f.password.value, | ||||||
|     }; |     }; | ||||||
|  | 
 | ||||||
|     this.authService.doLogin(value).then( |     this.authService.doLogin(value).then( | ||||||
|       (res) => { |       (res) => { | ||||||
|  |         console.log(res, 'res login'); | ||||||
|  |          | ||||||
|         if ( |         if ( | ||||||
|           this.loginForm.controls["rememberMe"] && |           this.loginForm.controls["rememberMe"] && | ||||||
|           this.loginForm.controls["rememberMe"].value |           this.loginForm.controls["rememberMe"].value | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user