diff --git a/src/app/clients/clients-view/datatable-tab/multi-row/multi-row.component.html b/src/app/clients/clients-view/datatable-tab/multi-row/multi-row.component.html index d1753b1d7..c185f9c26 100644 --- a/src/app/clients/clients-view/datatable-tab/multi-row/multi-row.component.html +++ b/src/app/clients/clients-view/datatable-tab/multi-row/multi-row.component.html @@ -4,6 +4,9 @@ + @@ -14,6 +17,4 @@
- - \ No newline at end of file diff --git a/src/app/clients/clients-view/datatable-tab/multi-row/multi-row.component.ts b/src/app/clients/clients-view/datatable-tab/multi-row/multi-row.component.ts index c8df33fce..288ab70a0 100644 --- a/src/app/clients/clients-view/datatable-tab/multi-row/multi-row.component.ts +++ b/src/app/clients/clients-view/datatable-tab/multi-row/multi-row.component.ts @@ -5,10 +5,12 @@ import { MatDialog } from '@angular/material'; import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base'; import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base'; import { SelectBase } from 'app/shared/form-dialog/formfield/model/select-base'; +import { CheckboxBase } from 'app/shared/form-dialog/formfield/model/checkbox-base'; import { DatePipe } from '@angular/common'; /** Custom Components */ import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component'; +import { DeleteDialogComponent } from '../../../../shared/delete-dialog/delete-dialog.component'; /** Custom Services */ import { ClientsService } from '../../../clients.service'; @@ -25,10 +27,11 @@ export class MultiRowComponent implements OnInit, OnChanges { datatableColumns: string[] = []; datatableData: any; clientId: string; + showDeleteBotton: boolean; constructor(private route: ActivatedRoute, private datePipe: DatePipe, - private clientService: ClientsService, + private clientsService: ClientsService, private dialog: MatDialog) { this.clientId = this.route.parent.parent.snapshot.paramMap.get('clientId'); } @@ -43,6 +46,7 @@ export class MultiRowComponent implements OnInit, OnChanges { return columnHeader.columnName; }); this.datatableData = this.dataObject.data; + this.showDeleteBotton = this.datatableData[0] ? true : false; } add() { @@ -54,47 +58,54 @@ export class MultiRowComponent implements OnInit, OnChanges { return ((column.columnName !== 'id') && (column.columnName !== 'client_id')); }); const formfields: FormfieldBase[] = columns.map((column: any) => { - if (column.columnDisplayType === 'INTEGER' || column.columnDisplayType === 'STRING') { - return new InputBase({ + switch (column.columnDisplayType) { + case 'INTEGER': + case 'STRING': + case 'DECIMAL': + case 'TEXT': return new InputBase({ controlName: column.columnName, label: column.columnName, value: '', - type: (column.columnDisplayType === 'INTEGER') ? 'number' : 'text', + type: (column.columnDisplayType === 'INTEGER' || column.columnDisplayType === 'DECIMAL') ? 'number' : 'text', required: (column.isColumnNullable) ? false : true }); - } - if (column.columnDisplayType === 'CODELOOKUP') { - return new SelectBase({ + case 'BOOLEAN': return new CheckboxBase({ + controlName: column.columnName, + label: column.columnName, + value: '', + type: 'checkbox', + required: (column.isColumnNullable) ? false : true + }); + case 'CODELOOKUP': return new SelectBase({ controlName: column.columnName, label: column.columnName, value: '', options: { label: 'value', value: 'id', data: column.columnValues }, required: (column.isColumnNullable) ? false : true }); + case 'DATE': { + dateTransformColumns.push(column.columnName); + dataTableEntryObject.dateFormat = 'yyyy-MM-dd'; + return new InputBase({ + controlName: column.columnName, + label: column.columnName, + value: '', + type: 'date', + required: (column.isColumnNullable) ? false : true + }); + } + case 'DATETIME': { + dateTransformColumns.push(column.columnName); + dataTableEntryObject.dateFormat = 'yyyy-MM-dd HH:mm'; + return new InputBase({ + controlName: column.columnName, + label: column.columnName, + value: '', + type: 'datetime-local', + required: (column.isColumnNullable) ? false : true + }); + } } - if (column.columnDisplayType === 'DATE') { - dateTransformColumns.push(column.columnName); - dataTableEntryObject.dateFormat = 'yyyy-MM-dd'; - return new InputBase({ - controlName: column.columnName, - label: column.columnName, - value: '', - type: 'date', - required: (column.isColumnNullable) ? false : true - }); - } - if (column.columnDisplayType === 'DATETIME') { - dateTransformColumns.push(column.columnName); - dataTableEntryObject.dateFormat = 'yyyy-MM-dd HH:mm'; - return new InputBase({ - controlName: column.columnName, - label: column.columnName, - value: '', - type: 'datetime-local', - required: (column.isColumnNullable) ? false : true - }); - } - }); const data = { title: 'Add ' + this.datatableName, @@ -108,8 +119,8 @@ export class MultiRowComponent implements OnInit, OnChanges { response.data.value[column] = this.datePipe.transform(response.data.value[column], dataTableEntryObject.dateFormat); }); dataTableEntryObject = { ...response.data.value, ...dataTableEntryObject }; - this.clientService.addClientDatatableEntry(this.clientId, this.datatableName, dataTableEntryObject).subscribe(() => { - this.clientService.getClientDatatable(this.clientId, this.datatableName).subscribe((dataObject: any) => { + this.clientsService.addClientDatatableEntry(this.clientId, this.datatableName, dataTableEntryObject).subscribe(() => { + this.clientsService.getClientDatatable(this.clientId, this.datatableName).subscribe((dataObject: any) => { this.datatableData = dataObject.data; this.dataTableRef.renderRows(); }); @@ -118,4 +129,22 @@ export class MultiRowComponent implements OnInit, OnChanges { }); } + delete() { + const deleteDataTableDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `the contents of ${this.datatableName}` } + }); + deleteDataTableDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.clientsService.deleteDatatableContent(this.clientId, this.datatableName) + .subscribe(() => { + this.clientsService.getClientDatatable(this.clientId, this.datatableName).subscribe((dataObject: any) => { + this.datatableData = dataObject.data; + this.showDeleteBotton = false; + this.dataTableRef.renderRows(); + }); + }); + } + }); + } + } diff --git a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.html b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.html index 201ee46c3..006478747 100644 --- a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.html +++ b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.html @@ -1,9 +1,15 @@

{{datatableName}}

- + +
diff --git a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.scss b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.scss index 877efd996..ce3593d7b 100644 --- a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.scss +++ b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.scss @@ -1,4 +1,8 @@ .tab-container { - padding:1%; - margin: 1%; -} \ No newline at end of file + padding: 1%; + margin: 1%; + + .delete-button { + margin-left: 1%; + } +} diff --git a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.ts b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.ts index ba4b7762d..42f3d3835 100644 --- a/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.ts +++ b/src/app/clients/clients-view/datatable-tab/single-row/single-row.component.ts @@ -1,5 +1,20 @@ import { Component, OnInit, Input } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; +import { MatDialog } from '@angular/material'; +import { FormfieldBase } from 'app/shared/form-dialog/formfield/model/formfield-base'; +import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base'; +import { SelectBase } from 'app/shared/form-dialog/formfield/model/select-base'; +import { CheckboxBase } from 'app/shared/form-dialog/formfield/model/checkbox-base'; +import { DatePipe } from '@angular/common'; + +/** Custom Components */ +import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component'; +import { DeleteDialogComponent } from '../../../../shared/delete-dialog/delete-dialog.component'; + +/** Custom Services */ +import { ClientsService } from '../../../clients.service'; + + @Component({ selector: 'mifosx-single-row', @@ -7,9 +22,17 @@ import { ActivatedRoute } from '@angular/router'; styleUrls: ['./single-row.component.scss'] }) export class SingleRowComponent implements OnInit { + @Input() dataObject: any; - datatableName: String; - constructor(private route: ActivatedRoute) { } + datatableName: string; + clientId: string; + + constructor(private route: ActivatedRoute, + private datePipe: DatePipe, + private dialog: MatDialog, + private clientsService: ClientsService) { + this.clientId = this.route.parent.parent.snapshot.paramMap.get('clientId'); + } ngOnInit() { this.route.params.subscribe((routeParams: any) => { @@ -17,4 +40,137 @@ export class SingleRowComponent implements OnInit { }); } + add() { + let dataTableEntryObject: any = { + locale: 'en' + }; + const dateTransformColumns: string[] = []; + const columns = this.dataObject.columnHeaders.filter((column: any) => { + return ((column.columnName !== 'id') && (column.columnName !== 'client_id')); + }); + const formfields: FormfieldBase[] = this.getFormfields(columns, dateTransformColumns, dataTableEntryObject); + const data = { + title: 'Add ' + this.datatableName, + formfields: formfields + }; + const addDialogRef = this.dialog.open(FormDialogComponent, { data }); + addDialogRef.afterClosed().subscribe((response: any) => { + if (response.data) { + // format Dates + dateTransformColumns.forEach((column) => { + response.data.value[column] = this.datePipe.transform(response.data.value[column], dataTableEntryObject.dateFormat); + }); + dataTableEntryObject = { ...response.data.value, ...dataTableEntryObject }; + this.clientsService.addClientDatatableEntry(this.clientId, this.datatableName, dataTableEntryObject).subscribe(() => { + this.clientsService.getClientDatatable(this.clientId, this.datatableName).subscribe((dataObject: any) => { + this.dataObject = dataObject; + }); + }); + } + }); + } + + edit() { + let dataTableEntryObject: any = { + locale: 'en' + }; + const dateTransformColumns: string[] = []; + const columns = this.dataObject.columnHeaders.filter((column: any) => { + return ((column.columnName !== 'id') && (column.columnName !== 'client_id')); + }); + let formfields: FormfieldBase[] = this.getFormfields(columns, dateTransformColumns, dataTableEntryObject); + formfields = formfields.map((formfield: FormfieldBase, index: number) => { + formfield.value = (this.dataObject.data[0].row[index + 1]) ? this.dataObject.data[0].row[index + 1] : ''; + return formfield; + }); + const data = { + title: 'Edit ' + this.datatableName, + formfields: formfields + }; + const editDialogRef = this.dialog.open(FormDialogComponent, { data }); + editDialogRef.afterClosed().subscribe((response: any) => { + if (response.data) { + // format Dates + dateTransformColumns.forEach((column) => { + response.data.value[column] = this.datePipe.transform(response.data.value[column], dataTableEntryObject.dateFormat); + }); + dataTableEntryObject = { ...response.data.value, ...dataTableEntryObject }; + this.clientsService.editClientDatatableEntry(this.clientId, this.datatableName, dataTableEntryObject).subscribe(() => { + this.clientsService.getClientDatatable(this.clientId, this.datatableName).subscribe((dataObject: any) => { + this.dataObject = dataObject; + }); + }); + } + }); + } + + delete() { + const deleteDataTableDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `the contents of ${this.datatableName}` } + }); + deleteDataTableDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.clientsService.deleteDatatableContent(this.clientId, this.datatableName) + .subscribe(() => { + this.clientsService.getClientDatatable(this.clientId, this.datatableName).subscribe((dataObject: any) => { + this.dataObject = dataObject; + }); + }); + } + }); + } + + getFormfields(columns: any, dateTransformColumns: string[], dataTableEntryObject: any) { + return columns.map((column: any) => { + switch (column.columnDisplayType) { + case 'INTEGER': + case 'STRING': + case 'DECIMAL': + case 'TEXT': return new InputBase({ + controlName: column.columnName, + label: column.columnName, + value: '', + type: (column.columnDisplayType === 'INTEGER' || column.columnDisplayType === 'DECIMAL') ? 'number' : 'text', + required: (column.isColumnNullable) ? false : true + }); + case 'BOOLEAN': return new CheckboxBase({ + controlName: column.columnName, + label: column.columnName, + value: '', + type: 'checkbox', + required: (column.isColumnNullable) ? false : true + }); + case 'CODELOOKUP': return new SelectBase({ + controlName: column.columnName, + label: column.columnName, + value: '', + options: { label: 'value', value: 'id', data: column.columnValues }, + required: (column.isColumnNullable) ? false : true + }); + case 'DATE': { + dateTransformColumns.push(column.columnName); + dataTableEntryObject.dateFormat = 'yyyy-MM-dd'; + return new InputBase({ + controlName: column.columnName, + label: column.columnName, + value: '', + type: 'date', + required: (column.isColumnNullable) ? false : true + }); + } + case 'DATETIME': { + dateTransformColumns.push(column.columnName); + dataTableEntryObject.dateFormat = 'yyyy-MM-dd HH:mm'; + return new InputBase({ + controlName: column.columnName, + label: column.columnName, + value: '', + type: 'datetime-local', + required: (column.isColumnNullable) ? false : true + }); + } + } + }); + } + } diff --git a/src/app/clients/clients.service.ts b/src/app/clients/clients.service.ts index 3343da192..7e00b94fe 100644 --- a/src/app/clients/clients.service.ts +++ b/src/app/clients/clients.service.ts @@ -48,6 +48,16 @@ export class ClientsService { return this.http.post(`/datatables/${datatableName}/${clientId}`, data, { params: httpParams }); } + editClientDatatableEntry(clientId: string, datatableName: string, data: any) { + const httpParams = new HttpParams().set('genericResultSet', 'true'); + return this.http.put(`/datatables/${datatableName}/${clientId}`, data, { params: httpParams }); + } + + deleteDatatableContent(clientId: string, datatableName: string) { + const httpParams = new HttpParams().set('genericResultSet', 'true'); + return this.http.delete(`/datatables/${datatableName}/${clientId}`, { params: httpParams }); + } + getClientAccountData(clientId: string) { return this.http.get(`/clients/${clientId}/accounts`); } diff --git a/src/app/shared/form-dialog/formfield/formfield.component.html b/src/app/shared/form-dialog/formfield/formfield.component.html index c2c96c7cd..10b733e1a 100644 --- a/src/app/shared/form-dialog/formfield/formfield.component.html +++ b/src/app/shared/form-dialog/formfield/formfield.component.html @@ -1,25 +1,35 @@
- +
- {{ formfield.label }} +
+ + -
+ {{ formfield.label }} - + - - - {{ option[formfield.options.label] }} - - + + + {{ option[formfield.options.label] }} + + + + {{ formfield.label }} is required + + +
- - {{ formfield.label }} is required - + + {{ formfield.label }} + -
+
-
+
\ No newline at end of file diff --git a/src/app/shared/form-dialog/formfield/model/checkbox-base.ts b/src/app/shared/form-dialog/formfield/model/checkbox-base.ts new file mode 100644 index 000000000..4dbb0da4a --- /dev/null +++ b/src/app/shared/form-dialog/formfield/model/checkbox-base.ts @@ -0,0 +1,10 @@ +import { FormfieldBase } from './formfield-base'; + +export class CheckboxBase extends FormfieldBase { + controlType = 'checkbox'; + + constructor(options: any) { + super(options); + } + +}