From ecc82e30c169f60517566e04d4311330d5457000 Mon Sep 17 00:00:00 2001 From: baldo Date: Sun, 26 Jun 2016 13:06:58 +0200 Subject: [PATCH] Fix: Correct total number of monitoring entries in admin panel. See: https://github.com/freifunkhamburg/ffffng/issues/16 --- server/services/monitoringService.js | 41 ++++++++++++++++------------ server/utils/resources.js | 2 ++ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/server/services/monitoringService.js b/server/services/monitoringService.js index 03b6811..a18eda3 100644 --- a/server/services/monitoringService.js +++ b/server/services/monitoringService.js @@ -355,9 +355,28 @@ angular.module('ffffng') return { getAll: function (restParams, callback) { + var sortFields = [ + 'id', + 'mac', + 'state', + 'last_seen', + 'import_timestamp', + 'last_status_mail_type', + 'last_status_mail_sent', + 'created_at', + 'modified_at' + ]; + var filterFields = [ + 'mac', + 'state', + 'last_status_mail_type' + ]; + + var where = Resources.whereCondition(restParams, filterFields); + Database.get( - 'SELECT count(*) AS total FROM node_state', - [], + 'SELECT count(*) AS total FROM node_state WHERE ' + where.query, + _.concat([], where.params), function (err, row) { if (err) { return callback(err); @@ -368,22 +387,8 @@ angular.module('ffffng') var filter = Resources.filterClause( restParams, 'id', - [ - 'id', - 'mac', - 'state', - 'last_seen', - 'import_timestamp', - 'last_status_mail_type', - 'last_status_mail_sent', - 'created_at', - 'modified_at' - ], - [ - 'mac', - 'state', - 'last_status_mail_type' - ] + sortFields, + filterFields ); Database.all( diff --git a/server/utils/resources.js b/server/utils/resources.js index ab9bf68..353995f 100644 --- a/server/utils/resources.js +++ b/server/utils/resources.js @@ -147,6 +147,8 @@ angular.module('ffffng').factory('Resources', function (_, Constraints, Validato return entities.slice((page - 1) * perPage, page * perPage); }, + whereCondition: filterCondition, + filterClause: function (restParams, defaultSortField, allowedSortFields, filterFields) { var orderBy = orderByClause( restParams,