work in progress on custom fields
This commit is contained in:
parent
361af18384
commit
86fce404a9
29 changed files with 1088 additions and 198 deletions
|
@ -3,7 +3,9 @@
|
|||
const knex = require('../lib/knex');
|
||||
const permissions = require('../lib/permissions');
|
||||
|
||||
async function ajaxList(params, queryFun, columns, mapFun) {
|
||||
async function ajaxList(params, queryFun, columns, options) {
|
||||
options = options || {};
|
||||
|
||||
return await knex.transaction(async (tx) => {
|
||||
const columnsNames = [];
|
||||
const columnsSelect = [];
|
||||
|
@ -69,7 +71,11 @@ async function ajaxList(params, queryFun, columns, mapFun) {
|
|||
query.select(columnsSelect);
|
||||
|
||||
for (const order of params.order) {
|
||||
query.orderBy(columnsNames[params.columns[order.column].data], order.dir);
|
||||
if (options.orderByBuilder) {
|
||||
options.orderByBuilder(query, columnsNames[params.columns[order.column].data], order.dir);
|
||||
} else {
|
||||
query.orderBy(columnsNames[params.columns[order.column].data], order.dir);
|
||||
}
|
||||
}
|
||||
|
||||
query.options({rowsAsArray:true});
|
||||
|
@ -78,8 +84,8 @@ async function ajaxList(params, queryFun, columns, mapFun) {
|
|||
const rowsOfArray = rows.map(row => {
|
||||
const arr = Object.keys(row).map(field => row[field]);
|
||||
|
||||
if (mapFun) {
|
||||
const result = mapFun(arr);
|
||||
if (options.mapFun) {
|
||||
const result = options.mapFun(arr);
|
||||
return result || arr;
|
||||
} else {
|
||||
return arr;
|
||||
|
@ -98,7 +104,9 @@ async function ajaxList(params, queryFun, columns, mapFun) {
|
|||
});
|
||||
}
|
||||
|
||||
async function ajaxListWithPermissions(context, fetchSpecs, params, queryFun, columns, map) {
|
||||
async function ajaxListWithPermissions(context, fetchSpecs, params, queryFun, columns, options) {
|
||||
options = options || {};
|
||||
|
||||
const permCols = [];
|
||||
for (const fetchSpec of fetchSpecs) {
|
||||
const entityType = permissions.getEntityType(fetchSpec.entityTypeId);
|
||||
|
@ -136,10 +144,21 @@ async function ajaxListWithPermissions(context, fetchSpecs, params, queryFun, co
|
|||
...columns,
|
||||
...permCols
|
||||
],
|
||||
data => {
|
||||
for (let idx = 0; idx < fetchSpecs.length; idx++) {
|
||||
data[columns.length + idx] = data[columns.length + idx].split(';');
|
||||
}
|
||||
{
|
||||
mapFun: data => {
|
||||
for (let idx = 0; idx < fetchSpecs.length; idx++) {
|
||||
data[columns.length + idx] = data[columns.length + idx].split(';');
|
||||
}
|
||||
|
||||
if (options.mapFun) {
|
||||
const result = options.mapFun(data);
|
||||
return result || data;
|
||||
} else {
|
||||
return data;
|
||||
}
|
||||
},
|
||||
|
||||
orderByBuilder: options.orderByBuilder
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue