Datatables enhacements to support products (#1641)
Co-authored-by: Jose Alberto Hernandez <alberto@MacBook-Pro.local>
This commit is contained in:
co-authored by
Jose Alberto Hernandez
parent
08a327fdbf
commit
f330e91aa4
@@ -1,5 +1,8 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
import { CheckboxBase } from 'app/shared/form-dialog/formfield/model/checkbox-base';
|
||||
import { DatepickerBase } from 'app/shared/form-dialog/formfield/model/datepicker-base';
|
||||
import { DateTimepickerBase } from 'app/shared/form-dialog/formfield/model/datetimepicker-base';
|
||||
import { InputBase } from 'app/shared/form-dialog/formfield/model/input-base';
|
||||
import { SelectBase } from 'app/shared/form-dialog/formfield/model/select-base';
|
||||
import { Dates } from './dates';
|
||||
@@ -9,7 +12,11 @@ import { Dates } from './dates';
|
||||
})
|
||||
export class Datatables {
|
||||
|
||||
constructor() { }
|
||||
systemFields: string[] = ['id', 'created_at', 'updated_at', 'client_id', 'savings_account_id',
|
||||
'loan_id', 'group_id', 'center_id', 'office_id', 'product_loan_id', 'savings_product_id'];
|
||||
|
||||
constructor(private dateUtils: Dates,
|
||||
private settingsService: SettingsService) { }
|
||||
|
||||
public getFormfields(columns: any, dateTransformColumns: string[], dataTableEntryObject: any) {
|
||||
return columns.map((column: any) => {
|
||||
@@ -43,22 +50,22 @@ export class Datatables {
|
||||
if (!dataTableEntryObject.dateFormat) {
|
||||
dataTableEntryObject.dateFormat = Dates.DEFAULT_DATEFORMAT;
|
||||
}
|
||||
return new InputBase({
|
||||
return new DatepickerBase({
|
||||
controlName: column.columnName,
|
||||
label: column.columnName,
|
||||
value: '',
|
||||
type: 'date',
|
||||
maxDate: this.settingsService.maxAllowedDate,
|
||||
required: (column.isColumnNullable) ? false : true
|
||||
});
|
||||
}
|
||||
case 'DATETIME': {
|
||||
dateTransformColumns.push(column.columnName);
|
||||
dataTableEntryObject.dateFormat = Dates.DEFAULT_DATETIMEFORMAT;
|
||||
return new InputBase({
|
||||
return new DateTimepickerBase({
|
||||
controlName: column.columnName,
|
||||
label: column.columnName,
|
||||
value: '',
|
||||
type: 'datetime-local',
|
||||
maxDate: this.settingsService.maxAllowedDate,
|
||||
required: (column.isColumnNullable) ? false : true
|
||||
});
|
||||
}
|
||||
@@ -66,4 +73,79 @@ export class Datatables {
|
||||
});
|
||||
}
|
||||
|
||||
public filterSystemColumns(columnHeaders: any): any {
|
||||
return columnHeaders.filter((column: any, index: number) => {
|
||||
if (!this.systemFields.includes(column.columnName)) {
|
||||
column.idx = index;
|
||||
return column;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public getInputName(datatableInput: any): string {
|
||||
if (datatableInput.columnName && datatableInput.columnName.includes('_cd_')) {
|
||||
return datatableInput.columnName.split('_cd_')[0];
|
||||
}
|
||||
return datatableInput.columnName;
|
||||
}
|
||||
|
||||
public isNumeric(columnType: string): boolean {
|
||||
return this.isColumnType(columnType, 'INTEGER') || this.isColumnType(columnType, 'DECIMAL');
|
||||
}
|
||||
|
||||
public isDate(columnType: string): boolean {
|
||||
return this.isColumnType(columnType, 'DATE') || this.isColumnType(columnType, 'DATETIME');
|
||||
}
|
||||
|
||||
public isBoolean(columnType: string): boolean {
|
||||
return this.isColumnType(columnType, 'BOOLEAN');
|
||||
}
|
||||
|
||||
public isDropdown(columnType: string): boolean {
|
||||
return this.isColumnType(columnType, 'CODELOOKUP');
|
||||
}
|
||||
|
||||
public isString(columnType: string): boolean {
|
||||
return this.isColumnType(columnType, 'STRING');
|
||||
}
|
||||
|
||||
public isText(columnType: string): boolean {
|
||||
return this.isColumnType(columnType, 'TEXT');
|
||||
}
|
||||
|
||||
public isColumnType(columnType: string, expectedType: string): boolean {
|
||||
return (columnType === expectedType);
|
||||
}
|
||||
|
||||
public buildPayload(datatableInputs: any, datatableDataValues: any, dateFormat: string, output: any): any {
|
||||
let existDate = false;
|
||||
datatableInputs.forEach((input: any) => {
|
||||
const controlName = this.getInputName(input);
|
||||
if (this.isNumeric(input.columnDisplayType)) {
|
||||
output[input.columnName] = datatableDataValues[controlName] * 1;
|
||||
} else if (this.isDate(input.columnDisplayType)) {
|
||||
output[input.columnName] = this.dateUtils.formatDate(datatableDataValues[controlName], dateFormat);
|
||||
existDate = true;
|
||||
} else {
|
||||
output[input.columnName] = datatableDataValues[controlName];
|
||||
}
|
||||
});
|
||||
|
||||
if (existDate) {
|
||||
output['dateFormat'] = dateFormat;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
public isSystemDefined(attr: string): boolean {
|
||||
return this.systemFields.includes(attr);
|
||||
}
|
||||
|
||||
public getName(columnName: any): string {
|
||||
if (columnName && columnName.includes('_cd_')) {
|
||||
return columnName.split('_cd_')[0];
|
||||
}
|
||||
return columnName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,6 +28,10 @@ export class Dates {
|
||||
}
|
||||
}
|
||||
|
||||
public parseDatetime(value: any): Date {
|
||||
return moment(value).toDate();
|
||||
}
|
||||
|
||||
public convertToDate(value: any, format: string): Date {
|
||||
return moment(value).toDate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user