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
+13
-39
@@ -1,6 +1,6 @@
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
|
||||
import { Dates } from 'app/core/utils/dates';
|
||||
import { Datatables } from 'app/core/utils/datatables';
|
||||
import { SettingsService } from 'app/settings/settings.service';
|
||||
|
||||
@Component({
|
||||
@@ -18,12 +18,10 @@ export class ClientDatatableStepComponent implements OnInit {
|
||||
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private settingsService: SettingsService,
|
||||
private dateUtils: Dates) { }
|
||||
private datatableService: Datatables) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.datatableInputs = this.datatableData.columnHeaderData.filter((column: any) => {
|
||||
return ((column.columnName !== 'id') && (column.columnName !== 'client_id') && (column.columnName !== 'created_at') && (column.columnName !== 'updated_at'));
|
||||
});
|
||||
this.datatableInputs = this.datatableService.filterSystemColumns(this.datatableData.columnHeaderData);
|
||||
const inputItems: any = {};
|
||||
this.datatableInputs.forEach((input: any) => {
|
||||
input.controlName = this.getInputName(input);
|
||||
@@ -41,68 +39,44 @@ export class ClientDatatableStepComponent implements OnInit {
|
||||
}
|
||||
|
||||
getInputName(datatableInput: any): string {
|
||||
if (datatableInput.columnName && datatableInput.columnName.includes('_cd_')) {
|
||||
return datatableInput.columnName.split('_cd_')[0];
|
||||
}
|
||||
return datatableInput.columnName;
|
||||
return this.datatableService.getInputName(datatableInput);
|
||||
}
|
||||
|
||||
isNumeric(columnType: string) {
|
||||
return this.isColumnType(columnType, 'INTEGER') || this.isColumnType(columnType, 'DECIMAL');
|
||||
return this.datatableService.isNumeric(columnType);
|
||||
}
|
||||
|
||||
isDate(columnType: string) {
|
||||
return this.isColumnType(columnType, 'DATE') || this.isColumnType(columnType, 'DATETIME');
|
||||
return this.datatableService.isDate(columnType);
|
||||
}
|
||||
|
||||
isBoolean(columnType: string) {
|
||||
return this.isColumnType(columnType, 'BOOLEAN');
|
||||
return this.datatableService.isBoolean(columnType);
|
||||
}
|
||||
|
||||
isDropdown(columnType: string) {
|
||||
return this.isColumnType(columnType, 'CODELOOKUP');
|
||||
return this.datatableService.isDropdown(columnType);
|
||||
}
|
||||
|
||||
isString(columnType: string) {
|
||||
return this.isColumnType(columnType, 'STRING');
|
||||
return this.datatableService.isString(columnType);
|
||||
}
|
||||
|
||||
isText(columnType: string) {
|
||||
return this.isColumnType(columnType, 'TEXT');
|
||||
}
|
||||
|
||||
isColumnType(columnType: string, expectedType: string) {
|
||||
return (columnType === expectedType);
|
||||
return this.datatableService.isText(columnType);
|
||||
}
|
||||
|
||||
get payload(): any {
|
||||
const dateFormat = this.settingsService.dateFormat;
|
||||
const datatableDataValues = this.datatableForm.value;
|
||||
const data = {
|
||||
locale: this.settingsService.language.code
|
||||
};
|
||||
let existDate = false;
|
||||
this.datatableInputs.forEach((input: any) => {
|
||||
const controlName = this.getInputName(input);
|
||||
if (this.isNumeric(input.columnDisplayType)) {
|
||||
data[input.columnName] = datatableDataValues[controlName] * 1;
|
||||
} else if (this.isDate(input.columnDisplayType)) {
|
||||
data[input.columnName] = this.dateUtils.formatDate(datatableDataValues[controlName], dateFormat);
|
||||
existDate = true;
|
||||
} else {
|
||||
data[input.columnName] = datatableDataValues[controlName];
|
||||
}
|
||||
});
|
||||
|
||||
if (existDate) {
|
||||
data['dateFormat'] = dateFormat;
|
||||
}
|
||||
const data = this.datatableService.buildPayload(this.datatableInputs, datatableDataValues, dateFormat,
|
||||
{ locale: this.settingsService.language.code });
|
||||
|
||||
const payload = {
|
||||
return {
|
||||
registeredTableName: this.datatableData.registeredTableName,
|
||||
data: data
|
||||
};
|
||||
return payload;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user