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,10 @@
|
|||||||
|
export const appTableData: { displayValue: string, value: string }[] = [
|
||||||
|
{ displayValue: 'Client', value: 'm_client' },
|
||||||
|
{ displayValue: 'Group', value: 'm_group' },
|
||||||
|
{ displayValue: 'Loan', value: 'm_loan' },
|
||||||
|
{ displayValue: 'Center', value: 'm_center' },
|
||||||
|
{ displayValue: 'Office', value: 'm_office' },
|
||||||
|
{ displayValue: 'Saving Account', value: 'm_savings_account' },
|
||||||
|
{ displayValue: 'Product Loan', value: 'm_product_loan' },
|
||||||
|
{ displayValue: 'Savings Product', value: 'm_savings_product' }
|
||||||
|
];
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<h1 mat-dialog-title>{{ data.columnName ? "Edit" : "Add" }} Column</h1>
|
||||||
|
|
||||||
|
<mat-dialog-content>
|
||||||
|
|
||||||
|
<form [formGroup]="columnForm">
|
||||||
|
|
||||||
|
<div fxLayout="column">
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Column Name</mat-label>
|
||||||
|
<input matInput required formControlName="name">
|
||||||
|
<mat-error *ngIf="columnForm.controls.name.hasError('required')">
|
||||||
|
Column Name is <strong>required</strong>
|
||||||
|
</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Column Type</mat-label>
|
||||||
|
<mat-select required formControlName="type">
|
||||||
|
<mat-option *ngFor="let columnType of columnTypeData" [value]="columnType.value">
|
||||||
|
{{ columnType.displayValue }}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<mat-checkbox labelPosition="before" formControlName="mandatory">Mandatory</mat-checkbox>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Column Length</mat-label>
|
||||||
|
<input matInput required type="number" formControlName="length">
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Column Code</mat-label>
|
||||||
|
<mat-select required formControlName="code">
|
||||||
|
<mat-option *ngFor="let columnCode of data.columnCodes" [value]="columnCode.name">
|
||||||
|
{{ columnCode.name }}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</mat-dialog-content>
|
||||||
|
|
||||||
|
<mat-dialog-actions align="end">
|
||||||
|
<button mat-button mat-dialog-close>Cancel</button>
|
||||||
|
<button mat-raised-button color="primary" [disabled]="!columnForm.valid || columnForm.pristine"
|
||||||
|
(click)="submit()">Submit</button>
|
||||||
|
</mat-dialog-actions>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ColumnDialogComponent } from './column-dialog.component';
|
||||||
|
|
||||||
|
describe('ColumnDialogComponent', () => {
|
||||||
|
let component: ColumnDialogComponent;
|
||||||
|
let fixture: ComponentFixture<ColumnDialogComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ ColumnDialogComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(ColumnDialogComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
/** Angular Imports */
|
||||||
|
import { Component, OnInit, Inject } from '@angular/core';
|
||||||
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
|
||||||
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||||
|
|
||||||
|
/** Data Imports */
|
||||||
|
import { columnTypeData } from '../column-type-data';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Column Dialog Component.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'mifosx-column-dialog',
|
||||||
|
templateUrl: './column-dialog.component.html',
|
||||||
|
styleUrls: ['./column-dialog.component.scss']
|
||||||
|
})
|
||||||
|
export class ColumnDialogComponent implements OnInit {
|
||||||
|
|
||||||
|
/** Column Form. */
|
||||||
|
columnForm: FormGroup;
|
||||||
|
/** Column Type Data */
|
||||||
|
columnTypeData = columnTypeData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {MatDialogRef} dialogRef Component reference to dialog.
|
||||||
|
* @param {FormBuilder} formBuilder Form Builder.
|
||||||
|
* @param {any} data Provides the column codes and values for the form (if available).
|
||||||
|
*/
|
||||||
|
constructor(public dialogRef: MatDialogRef<ColumnDialogComponent>,
|
||||||
|
public formBuilder: FormBuilder,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: any) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the add column form.
|
||||||
|
*/
|
||||||
|
ngOnInit() {
|
||||||
|
this.columnForm = this.formBuilder.group({
|
||||||
|
'name': [this.data ? this.data.columnName : '', Validators.required],
|
||||||
|
'type': [{ value: this.data ? (this.data.columnDisplayType === '' ? '' : this.getColumnType(this.data.columnDisplayType)) : '', disabled: this.data.type === 'existing' }, Validators.required],
|
||||||
|
'mandatory': [{ value: this.data ? this.data.isColumnPrimaryKey : false, disabled: this.data.type === 'existing' }],
|
||||||
|
'length': [{ value: this.data ? +this.data.columnLength : '', disabled: this.getColumnType(this.data.columnDisplayType) !== 'String' || this.data.type === 'existing' }, Validators.required],
|
||||||
|
'code': [{ value: this.data ? this.data.columnCode : '', disabled: this.getColumnType(this.data.columnDisplayType) !== 'Dropdown' || this.data.type === 'existing' }, Validators.required]
|
||||||
|
});
|
||||||
|
this.onColumnTypeChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the modified Column Type.
|
||||||
|
* @param {string} columnDisplayType Column Display Type.
|
||||||
|
* @returns {string} Column Type.
|
||||||
|
*/
|
||||||
|
getColumnType(columnDisplayType: string): string {
|
||||||
|
switch (columnDisplayType) {
|
||||||
|
case undefined: {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
case 'INTEGER': {
|
||||||
|
return 'Number';
|
||||||
|
}
|
||||||
|
case 'CODELOOKUP': {
|
||||||
|
return 'Dropdown';
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return columnDisplayType[0] + columnDisplayType.substr(1).toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watches on Column Type field to enable/diable certain fields.
|
||||||
|
*/
|
||||||
|
onColumnTypeChanges() {
|
||||||
|
this.columnForm.get('type').valueChanges
|
||||||
|
.subscribe(type => {
|
||||||
|
switch (type) {
|
||||||
|
case 'String': {
|
||||||
|
this.columnForm.get('length').enable();
|
||||||
|
this.columnForm.get('code').disable();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 'Dropdown': {
|
||||||
|
this.columnForm.get('code').enable();
|
||||||
|
this.columnForm.get('length').disable();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
this.columnForm.get('code').disable();
|
||||||
|
this.columnForm.get('length').disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the dialog and returns value of the form.
|
||||||
|
*/
|
||||||
|
submit() {
|
||||||
|
this.dialogRef.close(this.columnForm.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
export const columnTypeData: { displayValue: string, value: string }[] = [
|
||||||
|
{ displayValue: 'Boolean', value: 'Boolean' },
|
||||||
|
{ displayValue: 'Date', value: 'Date' },
|
||||||
|
{ displayValue: 'Date and Time', value: 'Datetime' },
|
||||||
|
{ displayValue: 'Decimal', value: 'Decimal' },
|
||||||
|
{ displayValue: 'Dropdown', value: 'Dropdown' },
|
||||||
|
{ displayValue: 'Number', value: 'Number' },
|
||||||
|
{ displayValue: 'String', value: 'String' },
|
||||||
|
{ displayValue: 'Text', value: 'Text' }
|
||||||
|
];
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<mat-card>
|
||||||
|
|
||||||
|
<form [formGroup]="dataTableForm" (ngSubmit)="submit()">
|
||||||
|
|
||||||
|
<mat-card-content>
|
||||||
|
|
||||||
|
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
|
||||||
|
|
||||||
|
<mat-form-field fxFlex="40%">
|
||||||
|
<mat-label>Data Table Name</mat-label>
|
||||||
|
<input matInput required formControlName="datatableName">
|
||||||
|
<mat-error *ngIf="dataTableForm.controls.datatableName.hasError('required')">
|
||||||
|
Data Table Name is <strong>required</strong>
|
||||||
|
</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field fxFlex="40%">
|
||||||
|
<mat-label>Application Table Name</mat-label>
|
||||||
|
<mat-select required formControlName="apptableName">
|
||||||
|
<mat-option *ngFor="let appTable of appTableData" [value]="appTable.value">
|
||||||
|
{{ appTable.displayValue }}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="dataTableForm.controls.apptableName.hasError('required')">
|
||||||
|
Application Table Name is <strong>required</strong>
|
||||||
|
</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<div fxFlex="14%" class="multi-row-wrapper">
|
||||||
|
<mat-checkbox labelPosition="before" formControlName="multiRow" class="multi-row">Multi Row</mat-checkbox>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div fxLayout="row wrap" fxLayoutGap="60%" fxLayout.lt-md="column">
|
||||||
|
|
||||||
|
<p fxFlex="20%" class="mat-title">Columns</p>
|
||||||
|
|
||||||
|
<button mat-raised-button fxFlex="20%" type="button" color="primary" (click)="addColumn()">
|
||||||
|
<fa-icon icon="plus"></fa-icon>
|
||||||
|
Add Column
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<table mat-table [dataSource]="dataSource" matSort>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="name">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.name }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="type">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Type </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.type }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="mandatory">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Mandatory </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.mandatory }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="length">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Length </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.length }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="code">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Code </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.code }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="actions">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Actions </th>
|
||||||
|
<td mat-cell *matCellDef="let column" fxLayoutGap="15%">
|
||||||
|
<button type="button" color="primary" mat-icon-button (click)="editColumn(column)">
|
||||||
|
<fa-icon icon="edit" size="lg"></fa-icon>
|
||||||
|
</button>
|
||||||
|
<button type="button" color="warn" mat-icon-button (click)="deleteColumn(column)">
|
||||||
|
<fa-icon icon="trash" size="lg"></fa-icon>
|
||||||
|
</button>
|
||||||
|
</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>
|
||||||
|
|
||||||
|
</mat-card-content>
|
||||||
|
|
||||||
|
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
|
||||||
|
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
|
||||||
|
<button mat-raised-button color="primary"
|
||||||
|
[disabled]="!dataTableForm.valid || columnData.length === 0">Submit</button>
|
||||||
|
</mat-card-actions>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</mat-card>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
@media (min-width: 992px) {
|
||||||
|
|
||||||
|
.multi-row-wrapper {
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.multi-row {
|
||||||
|
padding: 0 0 17.5px 0;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
right: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { CreateDataTableComponent } from './create-data-table.component';
|
||||||
|
|
||||||
|
describe('CreateDataTableComponent', () => {
|
||||||
|
let component: CreateDataTableComponent;
|
||||||
|
let fixture: ComponentFixture<CreateDataTableComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ CreateDataTableComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(CreateDataTableComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
/** Angular Imports */
|
||||||
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { MatTableDataSource, MatPaginator, MatSort, MatDialog } from '@angular/material';
|
||||||
|
|
||||||
|
/** Custom Services */
|
||||||
|
import { SystemService } from '../../system.service';
|
||||||
|
|
||||||
|
/** Data Imports */
|
||||||
|
import { appTableData } from '../app-table-data';
|
||||||
|
|
||||||
|
/** Custom Components */
|
||||||
|
import { ColumnDialogComponent } from '../column-dialog/column-dialog.component';
|
||||||
|
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Data Table Component.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'mifosx-create-data-table',
|
||||||
|
templateUrl: './create-data-table.component.html',
|
||||||
|
styleUrls: ['./create-data-table.component.scss']
|
||||||
|
})
|
||||||
|
export class CreateDataTableComponent implements OnInit {
|
||||||
|
|
||||||
|
/** Data Table Form */
|
||||||
|
dataTableForm: FormGroup;
|
||||||
|
/** Application Table Data */
|
||||||
|
appTableData = appTableData;
|
||||||
|
/** Column Data */
|
||||||
|
columnData: any[] = [];
|
||||||
|
/** Data passed to dialog. */
|
||||||
|
dataForDialog: {
|
||||||
|
columnName: string,
|
||||||
|
columnDisplayType: string,
|
||||||
|
isColumnPrimaryKey: boolean,
|
||||||
|
columnLength: string,
|
||||||
|
columnCode: string,
|
||||||
|
columnCodes: any,
|
||||||
|
type: string
|
||||||
|
} = {
|
||||||
|
columnName: undefined,
|
||||||
|
columnDisplayType: undefined,
|
||||||
|
isColumnPrimaryKey: undefined,
|
||||||
|
columnLength: undefined,
|
||||||
|
columnCode: undefined,
|
||||||
|
columnCodes: undefined,
|
||||||
|
type: undefined
|
||||||
|
};
|
||||||
|
/** Columns to be displayed in columns table. */
|
||||||
|
displayedColumns: string[] = ['name', 'type', 'mandatory', 'length', 'code', 'actions'];
|
||||||
|
/** 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 column codes data from `resolve`.
|
||||||
|
* @param {FormBuilder} formBuilder Form Builder.
|
||||||
|
* @param {SystemService} systemService System Service.
|
||||||
|
* @param {ActivatedRoute} route Activated Route.
|
||||||
|
* @param {Router} router Router for navigation.
|
||||||
|
* @param {MatDialog} dialog Dialog Reference.
|
||||||
|
*/
|
||||||
|
constructor(private formBuilder: FormBuilder,
|
||||||
|
private systemService: SystemService,
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private router: Router,
|
||||||
|
private dialog: MatDialog) {
|
||||||
|
this.route.data.subscribe((data: { columnCodes: any }) => {
|
||||||
|
this.dataForDialog.columnCodes = data.columnCodes;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates data table form and sets columns table.
|
||||||
|
*/
|
||||||
|
ngOnInit() {
|
||||||
|
this.createDataTableForm();
|
||||||
|
this.setColumns();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the data source, paginator and sorter for columns table.
|
||||||
|
*/
|
||||||
|
setColumns() {
|
||||||
|
this.dataSource = new MatTableDataSource(this.columnData);
|
||||||
|
this.dataSource.paginator = this.paginator;
|
||||||
|
this.dataSource.sort = this.sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the data table form.
|
||||||
|
*/
|
||||||
|
createDataTableForm() {
|
||||||
|
this.dataTableForm = this.formBuilder.group({
|
||||||
|
'datatableName': ['', Validators.required],
|
||||||
|
'apptableName': ['', Validators.required],
|
||||||
|
'multiRow': ['']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new column.
|
||||||
|
*/
|
||||||
|
addColumn() {
|
||||||
|
this.dataForDialog.columnName = undefined;
|
||||||
|
this.dataForDialog.columnDisplayType = undefined;
|
||||||
|
this.dataForDialog.isColumnPrimaryKey = false;
|
||||||
|
this.dataForDialog.columnLength = undefined;
|
||||||
|
this.dataForDialog.columnCode = undefined;
|
||||||
|
this.dataForDialog.type = 'new';
|
||||||
|
const addColumnDialogRef = this.dialog.open(ColumnDialogComponent, {
|
||||||
|
data: this.dataForDialog
|
||||||
|
});
|
||||||
|
addColumnDialogRef.afterClosed().subscribe((response: any) => {
|
||||||
|
if (response !== '') {
|
||||||
|
this.columnData.push({
|
||||||
|
name: response.name,
|
||||||
|
type: response.type,
|
||||||
|
mandatory: response.mandatory,
|
||||||
|
length: response.length,
|
||||||
|
code: response.code
|
||||||
|
});
|
||||||
|
this.dataSource.connect().next(this.columnData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits column.
|
||||||
|
* @param {any} column Column.
|
||||||
|
*/
|
||||||
|
editColumn(column: any) {
|
||||||
|
this.dataForDialog.columnName = column.name;
|
||||||
|
this.dataForDialog.columnDisplayType = column.type;
|
||||||
|
this.dataForDialog.isColumnPrimaryKey = column.mandatory;
|
||||||
|
this.dataForDialog.columnLength = column.length;
|
||||||
|
this.dataForDialog.columnCode = column.code;
|
||||||
|
this.dataForDialog.type = 'new';
|
||||||
|
const editColumnDialogRef = this.dialog.open(ColumnDialogComponent, {
|
||||||
|
data: this.dataForDialog
|
||||||
|
});
|
||||||
|
editColumnDialogRef.afterClosed().subscribe((response: any) => {
|
||||||
|
if (response !== '') {
|
||||||
|
this.columnData[this.columnData.findIndex(newColumn => newColumn.name === column.name)] = {
|
||||||
|
name: response.name,
|
||||||
|
type: response.type,
|
||||||
|
mandatory: response.mandatory,
|
||||||
|
length: response.length,
|
||||||
|
code: response.code
|
||||||
|
};
|
||||||
|
this.dataSource.connect().next(this.columnData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the column.
|
||||||
|
* @param {any} column Column.
|
||||||
|
*/
|
||||||
|
deleteColumn(column: any) {
|
||||||
|
const deleteColumnDialogRef = this.dialog.open(DeleteDialogComponent, {
|
||||||
|
data: { deleteContext: `column ${column.name}` }
|
||||||
|
});
|
||||||
|
deleteColumnDialogRef.afterClosed().subscribe((response: any) => {
|
||||||
|
if (response.delete) {
|
||||||
|
this.columnData.splice(this.columnData.indexOf(column), 1);
|
||||||
|
this.dataSource.connect().next(this.columnData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submits the data table form and creates data table,
|
||||||
|
* if successful redirects to view created data table.
|
||||||
|
*/
|
||||||
|
submit() {
|
||||||
|
this.dataTableForm.value.columns = this.columnData;
|
||||||
|
this.systemService.createDataTable(this.dataTableForm.value)
|
||||||
|
.subscribe((response: any) => {
|
||||||
|
this.router.navigate(['../', response.resourceIdentifier], { relativeTo: this.route });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/** Angular Imports */
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
|
||||||
|
|
||||||
|
/** rxjs Imports */
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
|
/** Custom Services */
|
||||||
|
import { SystemService } from '../system.service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data Table data resolver.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class DataTableResolver implements Resolve<Object> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {SystemService} systemService System service.
|
||||||
|
*/
|
||||||
|
constructor(private systemService: SystemService) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Data Table data.
|
||||||
|
* TODO: Delete the extra column to avoid multiple usages of `this.columnsData.shift()`.
|
||||||
|
* @returns {Observable<any>}
|
||||||
|
*/
|
||||||
|
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||||
|
const dataTableName = route.paramMap.get('datatableName');
|
||||||
|
return this.systemService.getDataTable(dataTableName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<mat-card>
|
||||||
|
|
||||||
|
<form [formGroup]="dataTableForm" (ngSubmit)="submit()">
|
||||||
|
|
||||||
|
<mat-card-content>
|
||||||
|
|
||||||
|
<div fxLayout="row wrap" fxLayoutGap="2%" fxLayout.lt-md="column">
|
||||||
|
|
||||||
|
<mat-form-field fxFlex="40%">
|
||||||
|
<mat-label>Data Table Name</mat-label>
|
||||||
|
<input matInput required formControlName="datatableName">
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
<mat-form-field fxFlex="40%">
|
||||||
|
<mat-label>Application Table Name</mat-label>
|
||||||
|
<mat-select required formControlName="apptableName">
|
||||||
|
<mat-option *ngFor="let appTable of appTableData" [value]="appTable.value">
|
||||||
|
{{ appTable.displayValue }}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
<mat-error *ngIf="dataTableForm.controls.apptableName.hasError('required')">
|
||||||
|
Application Table Name is <strong>required</strong>
|
||||||
|
</mat-error>
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div fxLayout="row wrap" fxLayoutGap="60%" fxLayout.lt-md="column">
|
||||||
|
|
||||||
|
<p fxFlex="20%" class="mat-title">Columns</p>
|
||||||
|
|
||||||
|
<button mat-raised-button fxFlex="20%" type="button" color="primary" (click)="addColumn()">
|
||||||
|
<fa-icon icon="plus"></fa-icon>
|
||||||
|
Add Column
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<table mat-table [dataSource]="dataSource" matSort>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="name">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.columnName }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="type">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Type </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.columnDisplayType }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="mandatory">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Mandatory </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.isColumnPrimaryKey }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="length">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Length </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.columnLength }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="code">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Code </th>
|
||||||
|
<td mat-cell *matCellDef="let column"> {{ column.columnCode }} </td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
|
<ng-container matColumnDef="actions">
|
||||||
|
<th mat-header-cell *matHeaderCellDef mat-sort-header> Actions </th>
|
||||||
|
<td mat-cell *matCellDef="let column" fxLayoutGap="15%">
|
||||||
|
<button type="button" color="primary" mat-icon-button (click)="editColumn(column)">
|
||||||
|
<fa-icon icon="edit" size="lg"></fa-icon>
|
||||||
|
</button>
|
||||||
|
<button type="button" color="warn" mat-icon-button (click)="deleteColumn(column)">
|
||||||
|
<fa-icon icon="trash" size="lg"></fa-icon>
|
||||||
|
</button>
|
||||||
|
</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>
|
||||||
|
|
||||||
|
</mat-card-content>
|
||||||
|
|
||||||
|
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
|
||||||
|
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
|
||||||
|
<button mat-raised-button color="primary"
|
||||||
|
[disabled]="!dataTableForm.valid || dataTableForm.pristine && !isFormEdited">Submit</button>
|
||||||
|
</mat-card-actions>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</mat-card>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { EditDataTableComponent } from './edit-data-table.component';
|
||||||
|
|
||||||
|
describe('EditDataTableComponent', () => {
|
||||||
|
let component: EditDataTableComponent;
|
||||||
|
let fixture: ComponentFixture<EditDataTableComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ EditDataTableComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(EditDataTableComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,305 @@
|
|||||||
|
/** Angular Imports */
|
||||||
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
import { MatTableDataSource, MatPaginator, MatSort, MatDialog } from '@angular/material';
|
||||||
|
|
||||||
|
/** Custom Services */
|
||||||
|
import { SystemService } from '../../system.service';
|
||||||
|
|
||||||
|
/** Data Imports */
|
||||||
|
import { appTableData } from '../app-table-data';
|
||||||
|
|
||||||
|
/** Custom Components */
|
||||||
|
import { ColumnDialogComponent } from '../column-dialog/column-dialog.component';
|
||||||
|
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit Data Table Component.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'mifosx-edit-data-table',
|
||||||
|
templateUrl: './edit-data-table.component.html',
|
||||||
|
styleUrls: ['./edit-data-table.component.scss']
|
||||||
|
})
|
||||||
|
export class EditDataTableComponent implements OnInit {
|
||||||
|
|
||||||
|
/** Data Table Form. */
|
||||||
|
dataTableForm: FormGroup;
|
||||||
|
/** Data Table Data. */
|
||||||
|
dataTableData: any;
|
||||||
|
/** Column Data. */
|
||||||
|
columnData: any[];
|
||||||
|
/** Application Table Data. */
|
||||||
|
appTableData = appTableData;
|
||||||
|
/** Boolean to check if form is edited or not. */
|
||||||
|
isFormEdited = false;
|
||||||
|
/** Data Table Changes Data. */
|
||||||
|
dataTableChangesData: {
|
||||||
|
apptableName: string,
|
||||||
|
dropColumns?: { name: string }[],
|
||||||
|
changeColumns: { name: string, newName?: string, code?: string, newCode?: string, mandatory: boolean, length?: number }[],
|
||||||
|
addColumns?: { name?: string, type?: string, code?: string, mandatory?: boolean, length?: number }[]
|
||||||
|
} = { apptableName: '', changeColumns: [], addColumns: [], dropColumns: [] };
|
||||||
|
/** Data passed to dialog. */
|
||||||
|
dataForDialog: {
|
||||||
|
columnName: string,
|
||||||
|
columnDisplayType: string,
|
||||||
|
isColumnPrimaryKey: boolean,
|
||||||
|
columnLength: string,
|
||||||
|
columnCode: string,
|
||||||
|
columnCodes: any,
|
||||||
|
type: string
|
||||||
|
} = {
|
||||||
|
columnName: undefined,
|
||||||
|
columnDisplayType: undefined,
|
||||||
|
isColumnPrimaryKey: undefined,
|
||||||
|
columnLength: undefined,
|
||||||
|
columnCode: undefined,
|
||||||
|
columnCodes: undefined,
|
||||||
|
type: undefined
|
||||||
|
};
|
||||||
|
/** Columns to be displayed in columns table. */
|
||||||
|
displayedColumns: string[] = ['name', 'type', 'mandatory', 'length', 'code', 'actions'];
|
||||||
|
/** 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 and column codes data from `resolve`.
|
||||||
|
* @param {ActivatedRoute} route Activated Route.
|
||||||
|
* @param {SystemService} systemService System Service.
|
||||||
|
* @param {Router} router Router for navigation.
|
||||||
|
* @param {FormBuilder} formBuilder Form Builder.
|
||||||
|
* @param {MatDialog} dialog Dialog Reference.
|
||||||
|
*/
|
||||||
|
constructor(private systemService: SystemService,
|
||||||
|
private formBuilder: FormBuilder,
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private router: Router,
|
||||||
|
private dialog: MatDialog) {
|
||||||
|
this.route.data.subscribe((data: { dataTable: any, columnCodes: any }) => {
|
||||||
|
this.dataTableData = data.dataTable;
|
||||||
|
this.columnData = this.dataTableData.columnHeaderData;
|
||||||
|
this.dataForDialog.columnCodes = data.columnCodes;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and sets data table form and columns table.
|
||||||
|
*/
|
||||||
|
ngOnInit() {
|
||||||
|
this.initData();
|
||||||
|
this.createDataTableForm();
|
||||||
|
this.setColumns();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the data source, paginator and sorter for columns table.
|
||||||
|
*/
|
||||||
|
setColumns() {
|
||||||
|
this.dataSource = new MatTableDataSource(this.columnData);
|
||||||
|
this.dataSource.paginator = this.paginator;
|
||||||
|
this.dataSource.sort = this.sort;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes data table changes and column data.
|
||||||
|
*/
|
||||||
|
initData() {
|
||||||
|
this.columnData.shift();
|
||||||
|
this.dataTableChangesData.apptableName = this.dataTableData.applicationTableName;
|
||||||
|
for (let index = 0; index < this.columnData.length; index++) {
|
||||||
|
this.columnData[index].columnDisplayType = this.getColumnType(this.columnData[index].columnDisplayType);
|
||||||
|
this.columnData[index].type = 'existing';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the data table form.
|
||||||
|
*/
|
||||||
|
createDataTableForm() {
|
||||||
|
this.dataTableForm = this.formBuilder.group({
|
||||||
|
'datatableName': [{ value: this.dataTableData.registeredTableName, disabled: true }, Validators.required],
|
||||||
|
'apptableName': [this.dataTableData.applicationTableName, Validators.required]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a new column.
|
||||||
|
*/
|
||||||
|
addColumn() {
|
||||||
|
this.dataForDialog.columnName = undefined;
|
||||||
|
this.dataForDialog.columnDisplayType = undefined;
|
||||||
|
this.dataForDialog.isColumnPrimaryKey = false;
|
||||||
|
this.dataForDialog.columnLength = undefined;
|
||||||
|
this.dataForDialog.columnCode = undefined;
|
||||||
|
this.dataForDialog.type = 'new';
|
||||||
|
const addColumnDialogRef = this.dialog.open(ColumnDialogComponent, {
|
||||||
|
data: this.dataForDialog
|
||||||
|
});
|
||||||
|
addColumnDialogRef.afterClosed().subscribe((response: any) => {
|
||||||
|
if (response !== '') {
|
||||||
|
this.isFormEdited = true;
|
||||||
|
this.dataTableChangesData.addColumns.push({
|
||||||
|
name: response.name,
|
||||||
|
type: response.type,
|
||||||
|
mandatory: response.mandatory,
|
||||||
|
length: response.length,
|
||||||
|
code: response.code
|
||||||
|
});
|
||||||
|
this.columnData.push({
|
||||||
|
columnName: response.name,
|
||||||
|
columnDisplayType: response.type,
|
||||||
|
isColumnPrimaryKey: response.mandatory,
|
||||||
|
columnLength: response.length,
|
||||||
|
columnCode: response.code,
|
||||||
|
type: 'new'
|
||||||
|
});
|
||||||
|
this.dataSource.connect().next(this.columnData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edits column.
|
||||||
|
* @param {any} column Column.
|
||||||
|
*/
|
||||||
|
editColumn(column: any) {
|
||||||
|
this.dataForDialog.columnName = column.columnName;
|
||||||
|
this.dataForDialog.columnDisplayType = column.columnDisplayType;
|
||||||
|
this.dataForDialog.isColumnPrimaryKey = column.isColumnPrimaryKey;
|
||||||
|
this.dataForDialog.columnLength = column.columnLength;
|
||||||
|
this.dataForDialog.columnCode = column.columnCode;
|
||||||
|
this.dataForDialog.type = column.type;
|
||||||
|
const editColumnDialogRef = this.dialog.open(ColumnDialogComponent, {
|
||||||
|
data: this.dataForDialog
|
||||||
|
});
|
||||||
|
editColumnDialogRef.afterClosed().subscribe((response: any) => {
|
||||||
|
if (response !== '') {
|
||||||
|
this.isFormEdited = true;
|
||||||
|
if (column.type === 'new') {
|
||||||
|
this.dataTableChangesData.addColumns[this.dataTableChangesData.addColumns
|
||||||
|
.findIndex(newColumn => newColumn.name === column.columnName
|
||||||
|
&& newColumn.type === column.columnDisplayType
|
||||||
|
&& newColumn.mandatory === column.isColumnPrimaryKey)] = {
|
||||||
|
name: response.name,
|
||||||
|
type: response.type,
|
||||||
|
code: response.code,
|
||||||
|
mandatory: response.mandatory,
|
||||||
|
length: response.length
|
||||||
|
};
|
||||||
|
this.columnData[this.columnData.indexOf(column)] = {
|
||||||
|
columnName: response.name,
|
||||||
|
columnDisplayType: response.type,
|
||||||
|
isColumnPrimaryKey: response.mandatory,
|
||||||
|
columnLength: response.length,
|
||||||
|
columnCode: response.code,
|
||||||
|
type: 'new'
|
||||||
|
};
|
||||||
|
} else if (column.type === 'existing') {
|
||||||
|
this.columnData[this.columnData.indexOf(column)] = {
|
||||||
|
columnName: response.name,
|
||||||
|
columnDisplayType: column.columnDisplayType,
|
||||||
|
isColumnPrimaryKey: column.isColumnPrimaryKey,
|
||||||
|
columnLength: column.columnLength,
|
||||||
|
columnCode: column.columnCode,
|
||||||
|
type: 'existing'
|
||||||
|
};
|
||||||
|
|
||||||
|
const index = this.dataTableChangesData.changeColumns.findIndex(newColumn => newColumn.newName === column.columnName);
|
||||||
|
if (index === -1) {
|
||||||
|
this.dataTableChangesData.changeColumns.push({
|
||||||
|
name: column.columnName,
|
||||||
|
newName: response.name,
|
||||||
|
code: column.columnCode,
|
||||||
|
newCode: response.code,
|
||||||
|
mandatory: response.mandatory,
|
||||||
|
length: response.length
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.dataTableChangesData.changeColumns[index] = {
|
||||||
|
name: column.columnName,
|
||||||
|
newName: response.name,
|
||||||
|
code: column.columnCode,
|
||||||
|
newCode: response.code,
|
||||||
|
mandatory: response.mandatory,
|
||||||
|
length: response.length
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.dataSource.connect().next(this.columnData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the column.
|
||||||
|
* @param {any} column Column.
|
||||||
|
*/
|
||||||
|
deleteColumn(column: any) {
|
||||||
|
const deleteColumnDialogRef = this.dialog.open(DeleteDialogComponent, {
|
||||||
|
data: { deleteContext: `column ${column.columnName}` }
|
||||||
|
});
|
||||||
|
deleteColumnDialogRef.afterClosed().subscribe((response: any) => {
|
||||||
|
if (response.delete) {
|
||||||
|
this.isFormEdited = true;
|
||||||
|
this.columnData.splice(this.columnData.indexOf(column), 1);
|
||||||
|
this.dataSource.connect().next(this.columnData);
|
||||||
|
if (column.type === 'existing') {
|
||||||
|
this.dataTableChangesData.dropColumns.push({
|
||||||
|
name: column.columnName
|
||||||
|
});
|
||||||
|
} else if (column.type === 'new') {
|
||||||
|
this.dataTableChangesData.addColumns.splice(this.dataTableChangesData.addColumns
|
||||||
|
.findIndex(newColumn => newColumn.name === column.columnName
|
||||||
|
&& newColumn.type === column.columnDisplayType
|
||||||
|
&& newColumn.mandatory === column.isColumnPrimaryKey), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the modified Column Type.
|
||||||
|
* @param {string} columnDisplayType Column Display Type.
|
||||||
|
* @returns {string} Column Type.
|
||||||
|
*/
|
||||||
|
getColumnType(columnDisplayType: string): string {
|
||||||
|
switch (columnDisplayType) {
|
||||||
|
case 'INTEGER': {
|
||||||
|
return 'Number';
|
||||||
|
}
|
||||||
|
case 'CODELOOKUP': {
|
||||||
|
return 'Dropdown';
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return columnDisplayType[0] + columnDisplayType.substr(1).toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submits the data table form and updates data table,
|
||||||
|
* if successful redirects to view updated data table.
|
||||||
|
*/
|
||||||
|
submit() {
|
||||||
|
if (!this.dataTableChangesData.addColumns || this.dataTableChangesData.addColumns.length === 0) {
|
||||||
|
this.dataTableChangesData.addColumns = undefined;
|
||||||
|
}
|
||||||
|
if (!this.dataTableChangesData.changeColumns || this.dataTableChangesData.changeColumns.length === 0) {
|
||||||
|
this.dataTableChangesData.changeColumns = undefined;
|
||||||
|
}
|
||||||
|
if (!this.dataTableChangesData.dropColumns || this.dataTableChangesData.dropColumns.length === 0) {
|
||||||
|
this.dataTableChangesData.dropColumns = undefined;
|
||||||
|
}
|
||||||
|
this.systemService.updateDataTable(this.dataTableChangesData, this.dataTableData.registeredTableName)
|
||||||
|
.subscribe((response: any) => {
|
||||||
|
this.router.navigate(['../'], { relativeTo: this.route });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||||
<button mat-raised-button color="primary">
|
<button mat-raised-button color="primary" [routerLink]="['create']">
|
||||||
<fa-icon icon="plus"></fa-icon>
|
<fa-icon icon="plus"></fa-icon>
|
||||||
Create Data Table
|
Create Data Table
|
||||||
</button>
|
</button>
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" class="select-row"></tr>
|
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="[row.registeredTableName]" class="select-row"></tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,9 @@ import { ViewCodeComponent } from './codes/view-code/view-code.component';
|
|||||||
import { EditCodeComponent } from './codes/edit-code/edit-code.component';
|
import { EditCodeComponent } from './codes/edit-code/edit-code.component';
|
||||||
import { ExternalServicesComponent } from './external-services/external-services.component';
|
import { ExternalServicesComponent } from './external-services/external-services.component';
|
||||||
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
||||||
|
import { CreateDataTableComponent } from './manage-data-tables/create-data-table/create-data-table.component';
|
||||||
|
import { ViewDataTableComponent } from './manage-data-tables/view-data-table/view-data-table.component';
|
||||||
|
import { EditDataTableComponent } from './manage-data-tables/edit-data-table/edit-data-table.component';
|
||||||
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
||||||
import { ViewHookComponent } from './manage-hooks/view-hook/view-hook.component';
|
import { ViewHookComponent } from './manage-hooks/view-hook/view-hook.component';
|
||||||
import { CreateHookComponent } from './manage-hooks/create-hook/create-hook.component';
|
import { CreateHookComponent } from './manage-hooks/create-hook/create-hook.component';
|
||||||
@@ -45,6 +48,7 @@ import { CodesResolver } from './codes/codes.resolver';
|
|||||||
import { CodeResolver } from './codes/code.resolver';
|
import { CodeResolver } from './codes/code.resolver';
|
||||||
import { CodeValuesResolver } from './codes/view-code/code-values.resolver';
|
import { CodeValuesResolver } from './codes/view-code/code-values.resolver';
|
||||||
import { ManageDataTablesResolver } from './manage-data-tables/manage-data-tables.resolver';
|
import { ManageDataTablesResolver } from './manage-data-tables/manage-data-tables.resolver';
|
||||||
|
import { DataTableResolver } from './manage-data-tables/data-table.resolver';
|
||||||
import { ManageHooksResolver } from './manage-hooks/manage-hooks.resolver';
|
import { ManageHooksResolver } from './manage-hooks/manage-hooks.resolver';
|
||||||
import { HookResolver } from './manage-hooks/view-hook/hook.resolver';
|
import { HookResolver } from './manage-hooks/view-hook/hook.resolver';
|
||||||
import { HooksTemplateResolver } from './manage-hooks/hooks-template.resolver';
|
import { HooksTemplateResolver } from './manage-hooks/hooks-template.resolver';
|
||||||
@@ -211,11 +215,46 @@ const routes: Routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'data-tables',
|
path: 'data-tables',
|
||||||
component: ManageDataTablesComponent,
|
|
||||||
resolve: {
|
|
||||||
dataTables: ManageDataTablesResolver
|
|
||||||
},
|
|
||||||
data: { title: extract('Manage Data Tables'), breadcrumb: 'Manage Data Tables' },
|
data: { title: extract('Manage Data Tables'), breadcrumb: 'Manage Data Tables' },
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
component: ManageDataTablesComponent,
|
||||||
|
resolve: {
|
||||||
|
dataTables: ManageDataTablesResolver
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'create',
|
||||||
|
component: CreateDataTableComponent,
|
||||||
|
data: { title: extract('Create Data Table'), breadcrumb: 'Create'},
|
||||||
|
resolve: {
|
||||||
|
columnCodes: CodesResolver
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: ':datatableName',
|
||||||
|
data: { title: extract('View Data Table'), routeParamBreadcrumb: 'datatableName'},
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
component: ViewDataTableComponent,
|
||||||
|
resolve: {
|
||||||
|
dataTable: DataTableResolver
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'edit',
|
||||||
|
component: EditDataTableComponent,
|
||||||
|
data: { title: extract('Edit Data table'), breadcrumb: 'Edit', routeParamBreadcrumb: false},
|
||||||
|
resolve: {
|
||||||
|
dataTable: DataTableResolver,
|
||||||
|
columnCodes: CodesResolver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'hooks',
|
path: 'hooks',
|
||||||
@@ -414,6 +453,7 @@ const routes: Routes = [
|
|||||||
CodeResolver,
|
CodeResolver,
|
||||||
CodeValuesResolver,
|
CodeValuesResolver,
|
||||||
ManageDataTablesResolver,
|
ManageDataTablesResolver,
|
||||||
|
DataTableResolver,
|
||||||
ManageHooksResolver,
|
ManageHooksResolver,
|
||||||
HookResolver,
|
HookResolver,
|
||||||
HooksTemplateResolver,
|
HooksTemplateResolver,
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ import { SystemComponent } from './system.component';
|
|||||||
import { CreateCodeComponent } from './codes/create-code/create-code.component';
|
import { CreateCodeComponent } from './codes/create-code/create-code.component';
|
||||||
import { ExternalServicesComponent } from './external-services/external-services.component';
|
import { ExternalServicesComponent } from './external-services/external-services.component';
|
||||||
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
import { ManageDataTablesComponent } from './manage-data-tables/manage-data-tables.component';
|
||||||
|
import { CreateDataTableComponent } from './manage-data-tables/create-data-table/create-data-table.component';
|
||||||
|
import { ViewDataTableComponent } from './manage-data-tables/view-data-table/view-data-table.component';
|
||||||
|
import { EditDataTableComponent } from './manage-data-tables/edit-data-table/edit-data-table.component';
|
||||||
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
import { ManageHooksComponent } from './manage-hooks/manage-hooks.component';
|
||||||
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
import { RolesAndPermissionsComponent } from './roles-and-permissions/roles-and-permissions.component';
|
||||||
import { AddRoleComponent } from './roles-and-permissions/add-role/add-role.component';
|
import { AddRoleComponent } from './roles-and-permissions/add-role/add-role.component';
|
||||||
@@ -39,6 +42,7 @@ import { EditReportComponent } from './manage-reports/edit-report/edit-report.co
|
|||||||
import { EditHookComponent } from './manage-hooks/edit-hook/edit-hook.component';
|
import { EditHookComponent } from './manage-hooks/edit-hook/edit-hook.component';
|
||||||
import { ViewHookComponent } from './manage-hooks/view-hook/view-hook.component';
|
import { ViewHookComponent } from './manage-hooks/view-hook/view-hook.component';
|
||||||
import { CreateHookComponent } from './manage-hooks/create-hook/create-hook.component';
|
import { CreateHookComponent } from './manage-hooks/create-hook/create-hook.component';
|
||||||
|
import { ColumnDialogComponent } from './manage-data-tables/column-dialog/column-dialog.component';
|
||||||
|
|
||||||
/** Dialog Component Imports */
|
/** Dialog Component Imports */
|
||||||
import { ReportParameterDialogComponent } from './manage-reports/report-parameter-dialog/report-parameter-dialog.component';
|
import { ReportParameterDialogComponent } from './manage-reports/report-parameter-dialog/report-parameter-dialog.component';
|
||||||
@@ -57,6 +61,9 @@ import { AddEventDialogComponent } from './manage-hooks/add-event-dialog/add-eve
|
|||||||
EditCodeComponent,
|
EditCodeComponent,
|
||||||
ExternalServicesComponent,
|
ExternalServicesComponent,
|
||||||
ManageDataTablesComponent,
|
ManageDataTablesComponent,
|
||||||
|
CreateDataTableComponent,
|
||||||
|
ViewDataTableComponent,
|
||||||
|
EditDataTableComponent,
|
||||||
ManageHooksComponent,
|
ManageHooksComponent,
|
||||||
RolesAndPermissionsComponent,
|
RolesAndPermissionsComponent,
|
||||||
ManageSurveysComponent,
|
ManageSurveysComponent,
|
||||||
@@ -84,11 +91,13 @@ import { AddEventDialogComponent } from './manage-hooks/add-event-dialog/add-eve
|
|||||||
EditHookComponent,
|
EditHookComponent,
|
||||||
ViewHookComponent,
|
ViewHookComponent,
|
||||||
CreateHookComponent,
|
CreateHookComponent,
|
||||||
AddEventDialogComponent
|
AddEventDialogComponent,
|
||||||
|
ColumnDialogComponent
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
ReportParameterDialogComponent,
|
ReportParameterDialogComponent,
|
||||||
AddEventDialogComponent
|
AddEventDialogComponent,
|
||||||
|
ColumnDialogComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class SystemModule { }
|
export class SystemModule { }
|
||||||
|
|||||||
@@ -184,6 +184,39 @@ export class SystemService {
|
|||||||
return this.http.post('/codes', code);
|
return this.http.post('/codes', code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {any} dataTable Data Table to be created.
|
||||||
|
* @return {Observable<any>}
|
||||||
|
*/
|
||||||
|
createDataTable(dataTable: any): Observable<any> {
|
||||||
|
return this.http.post('/datatables', dataTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param dataTableName Data Table Name.
|
||||||
|
* @return {Observable<any>}
|
||||||
|
*/
|
||||||
|
getDataTable(dataTableName: string): Observable<any> {
|
||||||
|
return this.http.get(`/datatables/${dataTableName}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param dataTableName Data Table Name.
|
||||||
|
* @return {Observable<any>}
|
||||||
|
*/
|
||||||
|
deleteDataTable(dataTableName: string): Observable<any> {
|
||||||
|
return this.http.delete(`/datatables/${dataTableName}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param dataTable Data Table.
|
||||||
|
* @param dataTableName Data Table Name.
|
||||||
|
* @return {Observable<any>}
|
||||||
|
*/
|
||||||
|
updateDataTable(dataTable: any, dataTableName: string): Observable<any> {
|
||||||
|
return this.http.put(`/datatables/${dataTableName}`, dataTable);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {Observable<any>} Configurations data.
|
* @returns {Observable<any>} Configurations data.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user