feat: create, view, edit, delete data-table (#365)
- Add view-data-table - Add edit-data-table - Add create-data-table Fixes #171 Co-authored-by: Chirag Gupta <gchirag@apache.org>
This commit is contained in:
co-authored by
Chirag Gupta
parent
17197056bb
commit
b1a3646bc2
@@ -0,0 +1,78 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
|
||||
<button mat-raised-button color="primary" [routerLink]="['edit']">
|
||||
<fa-icon icon="edit"></fa-icon>
|
||||
Edit
|
||||
</button>
|
||||
|
||||
<button mat-raised-button color="warn" (click)="delete()">
|
||||
<fa-icon icon="trash"></fa-icon>
|
||||
Delete
|
||||
</button>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="container m-b-15" fxLayoutAlign="start">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="row wrap" fxLayout.lt-md="column" fxLayoutGap="12px">
|
||||
<div class="mat-body-strong">
|
||||
Associated With
|
||||
</div>
|
||||
<div>
|
||||
{{ dataTableData.applicationTableName }}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</mat-card-content>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="container mat-elevation-z8">
|
||||
|
||||
<table mat-table [dataSource]="dataSource" matSort>
|
||||
|
||||
<ng-container matColumnDef="columnName">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Field Name </th>
|
||||
<td mat-cell *matCellDef="let dataTableColumn"> {{ dataTableColumn.columnName }} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="columnDisplayType">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Type </th>
|
||||
<td mat-cell *matCellDef="let dataTable"> {{ dataTable.columnDisplayType }} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="columnLength">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Length </th>
|
||||
<td mat-cell *matCellDef="let dataTable"> {{ dataTable.columnLength }} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="columnCode">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Code </th>
|
||||
<td mat-cell *matCellDef="let dataTable"> {{ dataTable.columnCode }} </td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="isColumnPrimaryKey">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header> Mandatory </th>
|
||||
<td mat-cell *matCellDef="let dataTable">
|
||||
<fa-icon *ngIf="dataTable.isColumnPrimaryKey" icon="check-circle" size="lg" class="column-primary-key"
|
||||
matTooltip="Yes" matTooltipPosition="right"></fa-icon>
|
||||
<fa-icon *ngIf="!dataTable.isColumnPrimaryKey" icon="times-circle" size="lg"
|
||||
class="not-column-primary-key" matTooltip="No" matTooltipPosition="right"></fa-icon>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
|
||||
</table>
|
||||
|
||||
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
table {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
// TODO: CONFIGURE THESE CLASSES GLOBALLY
|
||||
.column-primary-key {
|
||||
color: #32cd32;
|
||||
}
|
||||
|
||||
.not-column-primary-key {
|
||||
color: #f44366;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ViewDataTableComponent } from './view-data-table.component';
|
||||
|
||||
describe('ViewDataTableComponent', () => {
|
||||
let component: ViewDataTableComponent;
|
||||
let fixture: ComponentFixture<ViewDataTableComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ ViewDataTableComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ViewDataTableComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,88 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { MatTableDataSource, MatPaginator, MatSort, MatDialog } from '@angular/material';
|
||||
|
||||
/** Custom Services */
|
||||
import { SystemService } from '../../system.service';
|
||||
|
||||
/** Custom Components */
|
||||
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
|
||||
|
||||
/**
|
||||
* View Data Table Component
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-view-data-table',
|
||||
templateUrl: './view-data-table.component.html',
|
||||
styleUrls: ['./view-data-table.component.scss']
|
||||
})
|
||||
export class ViewDataTableComponent implements OnInit {
|
||||
|
||||
/** Data Table Data */
|
||||
dataTableData: any;
|
||||
/** Column Data */
|
||||
columnsData: any;
|
||||
/** Columns to be displayed in columns table. */
|
||||
displayedColumns: string[] = ['columnName', 'columnDisplayType', 'columnLength', 'columnCode', 'isColumnPrimaryKey'];
|
||||
/** Data source for columns table. */
|
||||
dataSource: MatTableDataSource<any>;
|
||||
|
||||
/** Paginator for columns table. */
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
/** Sorter for columns table. */
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
|
||||
/**
|
||||
* Retrieves the data table data from `resolve`.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {SystemService} systemService System Service.
|
||||
* @param {Router} router Router for navigation.
|
||||
* @param {MatDialog} dialog Dialog reference.
|
||||
*/
|
||||
constructor(private route: ActivatedRoute,
|
||||
private systemService: SystemService,
|
||||
private router: Router,
|
||||
private dialog: MatDialog) {
|
||||
this.route.data.subscribe((data: { dataTable: any }) => {
|
||||
this.dataTableData = data.dataTable;
|
||||
this.columnsData = this.dataTableData.columnHeaderData;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the columns table.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.setColumnsTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the data source, paginator and sorter for columns table.
|
||||
*/
|
||||
setColumnsTable() {
|
||||
this.columnsData.shift();
|
||||
// TODO: Figure out a better approach in order to pass only updated parameters instead of all of them.
|
||||
this.dataSource = new MatTableDataSource(this.columnsData);
|
||||
this.dataSource.paginator = this.paginator;
|
||||
this.dataSource.sort = this.sort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the current data table.
|
||||
*/
|
||||
delete() {
|
||||
const deleteDataTableDialogRef = this.dialog.open(DeleteDialogComponent, {
|
||||
data: { deleteContext: `data table ${this.dataTableData.registeredTableName}` }
|
||||
});
|
||||
deleteDataTableDialogRef.afterClosed().subscribe((response: any) => {
|
||||
if (response.delete) {
|
||||
this.systemService.deleteDataTable(this.dataTableData.registeredTableName)
|
||||
.subscribe(() => {
|
||||
this.router.navigate(['/system/data-tables'], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user