diff --git a/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.html b/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.html index af8700e..a0aaa73 100644 --- a/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.html +++ b/src/app/content/hemat-app/device/add-edit-device/add-edit-device.component.html @@ -11,7 +11,15 @@ (reloadFunction)="reloadProjectInfo($event)" > - Project Info (Reactive Forms Validation) +

+ {{ + isEditMode() + ? "Edit Device" + : isViewMode() + ? "View Device" + : "Add New Device" + }} +

{ + this.mode = data.mode; + console.log(this.mode); + }); this.breadcrumb = { mainlabel: "Basic Forms", links: [ @@ -85,6 +94,18 @@ export class AddEditDeviceComponent { }); } + isEditMode() { + return this.mode === "edit"; + } + + isViewMode() { + return this.mode === "view"; + } + + isAddMode() { + return this.mode === "add"; + } + get f() { return this.projectInfo.controls; } @@ -122,9 +143,7 @@ export class AddEditDeviceComponent { } } - addData(){ - - } + addData() {} cancel() { this.router.navigate(["/device"]); // Adjust the path as per your routing setup diff --git a/src/app/content/hemat-app/device/device.component.html b/src/app/content/hemat-app/device/device.component.html index 9f54bb6..7c15805 100644 --- a/src/app/content/hemat-app/device/device.component.html +++ b/src/app/content/hemat-app/device/device.component.html @@ -6,6 +6,25 @@
+
+
+ +
+
+ +
+
-
- {{ element.id }} + {{ rowIndex + 1 }} - - + + + + + + +
diff --git a/src/app/content/hemat-app/device/device.component.ts b/src/app/content/hemat-app/device/device.component.ts index 1927341..36300eb 100644 --- a/src/app/content/hemat-app/device/device.component.ts +++ b/src/app/content/hemat-app/device/device.component.ts @@ -8,6 +8,7 @@ import { } from "ngx-perfect-scrollbar"; import { TableApiService } from "src/app/_services/table-api.service"; import { ModalAddEditComponent } from "./modal-add-edit/modal-add-edit.component"; +import { ActivatedRoute, Router } from "@angular/router"; @Component({ selector: "app-device", @@ -16,6 +17,8 @@ import { ModalAddEditComponent } from "./modal-add-edit/modal-add-edit.component }) export class DeviceComponent implements OnInit { data: any; + filteredRows: any[]; + searchTerm: string = ''; @BlockUI("addRows") blockUIAddRows: NgBlockUI; @BlockUI("rowSelection") blockUIRowSelection: NgBlockUI; @@ -43,46 +46,49 @@ export class DeviceComponent implements OnInit { constructor( private tableApiservice: TableApiService, - private modalService: NgbModal + private modalService: NgbModal, + private router: Router ) {} ngOnInit() { - this.breadcrumb = { - mainlabel: "Device List", - links: [ - { - name: "Home", - isLink: false, - link: "/dashboard/sales", - }, - { - name: "Device", - isLink: false, - }, - ], - }; - this.tableApiservice.getTableApiData().subscribe((Response) => { - console.log(Response); + this.fetchData(); + } - this.data = Response; - this.getTabledata(); + fetchData() { + this.tableApiservice.getTableApiData().subscribe((response) => { + this.data = response; + this.filteredRows = this.data.rows; }); } - getTabledata() { - this.rows = this.data.rows; - this.row = this.data.row; + filterRows() { + if (!this.searchTerm) { + this.filteredRows = [...this.data.rows]; + } else { + this.filteredRows = this.data.rows.filter((row) => + this.rowContainsSearchTerm(row) + ); + } } - private newAttribute = { - id: 15, - name: "Mark", - position: "Otto", - office: "@mdo", - age: "31", - salary: "12000", - startdate: "16/05/2017", - }; + rowContainsSearchTerm(row: any): boolean { + const searchTermLC = this.searchTerm.toLowerCase(); + return Object.values(row).some( + (value) => + value !== null && + value.toString().toLowerCase().includes(searchTermLC) + ); + } + + // private newAttribute = { + // id: 15, + // name: "Mark", + // position: "Otto", + // office: "@mdo", + // age: "31", + // salary: "12000", + // startdate: "16/05/2017", + // }; // addFieldValue() { // this.rows.push(this.newAttribute); @@ -102,5 +108,20 @@ export class DeviceComponent implements OnInit { console.log(`Dismissed: ${reason}`); }); } + + viewRow(row) { + console.log("View row:", row); + this.router.navigate(['/device/view', row.id]); + } + + editRow(row) { + console.log("Edit row:", row); + this.router.navigate(['/device/edit', row.id]); + } + + deleteRow(row) { + console.log("Delete row:", row); + } + } diff --git a/src/app/content/hemat-app/device/device.module.ts b/src/app/content/hemat-app/device/device.module.ts index bf6b54a..c0fb3e4 100644 --- a/src/app/content/hemat-app/device/device.module.ts +++ b/src/app/content/hemat-app/device/device.module.ts @@ -43,7 +43,18 @@ import { ModalAddEditComponent } from './modal-add-edit/modal-add-edit.component }, { path: 'add-row', - component: AddEditDeviceComponent + component: AddEditDeviceComponent, + data: { mode: 'add' } + }, + { + path: 'edit/:id', + component: AddEditDeviceComponent, + data: { mode: 'edit' } + }, + { + path: 'view/:id', + component: AddEditDeviceComponent, + data: { mode: 'view' } } ]) ]