integrasi table device dan table master category

This commit is contained in:
2024-05-18 20:26:44 +07:00
parent cfa140b6ea
commit e92c576844
15 changed files with 431 additions and 60 deletions

View File

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

View File

@@ -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">&times;</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>

View File

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

View File

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

View File

@@ -29,6 +29,7 @@
<div class="col-md-6 text-right">
<button
class="btn btn-secondary"
(click)="openAddMasterModal()"
>
<i class="feather ft-plus"></i>&nbsp; Add new master
</button>
@@ -74,7 +75,7 @@
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column
name="Salary"
name="Status"
[flexGrow]="1"
[minWidth]="90"
>
@@ -85,7 +86,7 @@
ngx-datatable-cell-template
let-value="value"
>
{{ value }}
{{ value === '1' ? 'Aktif' : 'Tidak Aktif'}}
</ng-template>
</ngx-datatable-column>
<ngx-datatable-column
@@ -98,20 +99,16 @@
let-rowIndex="rowIndex"
let-row="row"
>
<button
class="btn btn-sm btn-info mr-1"
>
<i class="ficon feather ft-eye"></i>
</button>
<button
class="btn btn-sm btn-warning mr-1"
(click)="editRow(row)"
>
<i class="ficon feather ft-edit"></i>
</button>
<button
class="btn btn-sm btn-danger"
(click)="deleteRow(row)"
>
<i class="ficon feather ft-trash-2"></i>

View File

@@ -1,27 +1,31 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { BlockUI, NgBlockUI } from 'ng-block-ui';
import { TableApiService } from 'src/app/_services/table-api.service';
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
import { BlockUI, NgBlockUI } from "ng-block-ui";
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({
selector: 'app-master-category',
templateUrl: './master-category.component.html',
styleUrls: ['./master-category.component.css']
selector: "app-master-category",
templateUrl: "./master-category.component.html",
styleUrls: ["./master-category.component.css"],
})
export class MasterCategoryComponent implements OnInit{
export class MasterCategoryComponent implements OnInit {
data: any;
filteredRows: any[];
searchTerm: string = "";
rows: any = [];
public breadcrumb: any;
dataMasterCategori: any;
@BlockUI("zeroConfiguration") blockUIZeroConfiguration: NgBlockUI;
constructor(
private tableApiservice: TableApiService,
private modalService: NgbModal,
private router: Router
private router: Router,
private monitoringApiService: BuildingService
) {}
ngOnInit() {
@@ -42,19 +46,25 @@ export class MasterCategoryComponent implements OnInit{
}
fetchData() {
this.tableApiservice.getTableInitialisationData().subscribe((response) => {
this.data = response;
this.filteredRows = this.data.rows;
this.monitoringApiService.getMasterData().subscribe((res) => {
this.data = res.data.data;
this.dataMasterCategori = res.data.data.find(
(item) => item.name === "master_category"
);
this.filteredRows = this.dataMasterCategori.headerDetailParam;
});
}
filterRows() {
if (!this.searchTerm) {
this.filteredRows = [...this.data.rows];
this.filteredRows = [
...this.data.find((item) => item.name === "master_category")
.headerDetailParam,
];
} else {
this.filteredRows = this.data.rows.filter((row) =>
this.rowContainsSearchTerm(row)
);
this.filteredRows = this.data
.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();
return Object.values(row).some(
(value) =>
value !== null &&
value.toString().toLowerCase().includes(searchTermLC)
value !== null && value.toString().toLowerCase().includes(searchTermLC)
);
}
viewRow(row) {
console.log("View row:", row);
this.router.navigate(["/device/view", row.name]);
openAddMasterModal() {
const modalRef = this.modalService.open(AddEditMasterComponent, {
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) {
console.log("Edit row:", row);
this.router.navigate(["/device/edit", row.name]);
const modalRef = this.modalService.open(AddEditMasterComponent, {
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) {
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();
});
}
}
}

View File

@@ -8,7 +8,7 @@ import { MasterTypeComponent } from './master-type/master-type.component';
import { RouterModule } from '@angular/router';
import { ChartistModule } from 'ng-chartist';
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 { NgChartsModule } from 'ng2-charts';
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 { MasterUserComponent } from './master-user/master-user.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,
MasterDurationUseComponent,
MasterUserComponent,
MasterRoleComponent
MasterRoleComponent,
AddEditMasterComponent
],
imports: [
CommonModule,
@@ -45,6 +47,7 @@ import { MasterRoleComponent } from './master-role/master-role.component';
NgxDatatableModule,
PerfectScrollbarModule,
BreadcrumbModule,
ReactiveFormsModule,
NgbModule,
BlockUIModule.forRoot({
template: BlockTemplateComponent