Lists and Templates overviews refactored to use ajax. Before the refactoring, they behaved and looked a bit different to the other (Ajax) tables. The main difference in the behavior was in the row numbers (1st column) when sort order was switched. The non-ajax tables rearranged the numbers in the 1st column while the ajax-tables didn't.
Some small tweaks in table-helpers to allow selecting which fields are pulled from DB (and how they are renamed).
This commit is contained in:
parent
e5190c9b20
commit
9fdf52674e
12 changed files with 246 additions and 192 deletions
|
@ -4,13 +4,13 @@ let db = require('./db');
|
|||
let tools = require('./tools');
|
||||
let log = require('npmlog');
|
||||
|
||||
module.exports.list = (source, orderBy, start, limit, callback) => {
|
||||
module.exports.list = (source, fields, orderBy, start, limit, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
connection.query('SELECT SQL_CALC_FOUND_ROWS * FROM ' + source + ' ORDER BY ' + orderBy + ' DESC LIMIT ? OFFSET ?', [limit, start], (err, rows) => {
|
||||
connection.query('SELECT SQL_CALC_FOUND_ROWS ' + fields.join(', ') + ' FROM ' + source + ' ORDER BY ' + orderBy + ' DESC LIMIT ? OFFSET ?', [limit, start], (err, rows) => {
|
||||
if (err) {
|
||||
connection.release();
|
||||
return callback(err);
|
||||
|
@ -26,8 +26,23 @@ module.exports.list = (source, orderBy, start, limit, callback) => {
|
|||
});
|
||||
};
|
||||
|
||||
module.exports.quicklist = (source, fields, orderBy, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
module.exports.filter = (source, request, columns, searchFields, defaultOrdering, queryData, callback) => {
|
||||
connection.query('SELECT ' + fields.join(', ') + ' FROM ' + source + ' ORDER BY ' + orderBy + ' LIMIT 1000', (err, rows) => {
|
||||
connection.release();
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
return callback(null, (rows || []).map(tools.convertKeys));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.filter = (source, fields, request, columns, searchFields, defaultOrdering, queryData, callback) => {
|
||||
db.getConnection((err, connection) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
@ -41,6 +56,8 @@ module.exports.filter = (source, request, columns, searchFields, defaultOrdering
|
|||
values = values.concat(queryData.values || []);
|
||||
}
|
||||
|
||||
log.info("tableHelpers", query);
|
||||
|
||||
connection.query(query, values, (err, total) => {
|
||||
if (err) {
|
||||
connection.release();
|
||||
|
@ -56,7 +73,7 @@ module.exports.filter = (source, request, columns, searchFields, defaultOrdering
|
|||
let orderField = columns[Number(order.column)];
|
||||
let orderDirection = (order.dir || '').toString().toLowerCase() === 'desc' ? 'DESC' : 'ASC';
|
||||
if (orderField) {
|
||||
ordering.push('`' + orderField + '` ' + orderDirection);
|
||||
ordering.push(orderField + ' ' + orderDirection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -75,9 +92,11 @@ module.exports.filter = (source, request, columns, searchFields, defaultOrdering
|
|||
searchArgs = searchFields.map(field => searchVal)
|
||||
}
|
||||
|
||||
let query = 'SELECT SQL_CALC_FOUND_ROWS * FROM ' + source +' WHERE ' + (searchWhere ? '(' + searchWhere + ')': '1') + (queryData ? ' AND (' + queryData.where + ')' : '') + ' ORDER BY ' + ordering.join(', ') + ' LIMIT ? OFFSET ?';
|
||||
let query = 'SELECT SQL_CALC_FOUND_ROWS ' + fields.join(', ') + ' FROM ' + source +' WHERE ' + (searchWhere ? '(' + searchWhere + ')': '1') + (queryData ? ' AND (' + queryData.where + ')' : '') + ' ORDER BY ' + ordering.join(', ') + ' LIMIT ? OFFSET ?';
|
||||
let args = searchArgs.concat(queryData ? queryData.values : []).concat([Number(request.length) || 50, Number(request.start) || 0]);
|
||||
|
||||
log.info("tableHelpers", query);
|
||||
|
||||
connection.query(query, args, (err, rows) => {
|
||||
if (err) {
|
||||
connection.release();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue