From 2d14a3cad0c44d053d31c15654d701b3cdb12e55 Mon Sep 17 00:00:00 2001 From: flavien peyre Date: Tue, 11 Aug 2015 09:37:00 -0400 Subject: [PATCH] Add paging in actionbar Change-Id: If39fe55e5fad048fa3f1095ee77234434e472cbb --- app/assets/sass/temporary/temporary.scss | 8 ++++ .../config/defaultLayoutConfig.json | 27 ++++++++----- app/components/datasource/datasource.js | 31 ++++++++++++-- .../search_filter.html | 2 +- app/components/directive/service/service.js | 2 +- .../directive/table/pagingbar/pagingbar.html | 38 ++++++++++++++++++ .../directive/table/pagingbar/pagingbar.js | 40 +++++++++++++++++++ app/components/directive/table/table.html | 5 ++- app/components/directive/table/table.js | 7 +++- app/components/surveil/config.js | 8 ++-- app/components/surveil/query.js | 6 ++- app/components/surveil/status.js | 22 +++++----- app/index.html | 1 + 13 files changed, 163 insertions(+), 34 deletions(-) create mode 100644 app/components/directive/table/pagingbar/pagingbar.html create mode 100644 app/components/directive/table/pagingbar/pagingbar.js diff --git a/app/assets/sass/temporary/temporary.scss b/app/assets/sass/temporary/temporary.scss index 80cbd9f..0efdb31 100644 --- a/app/assets/sass/temporary/temporary.scss +++ b/app/assets/sass/temporary/temporary.scss @@ -87,3 +87,11 @@ margin-left:30px; font-family: Courier New; } + +.disabled { + cursor: not-allowed; +} + +.small__input { + width: 50px; +} diff --git a/app/components/config/defaultLayoutConfig.json b/app/components/config/defaultLayoutConfig.json index 5fc2f1c..b8e0872 100644 --- a/app/components/config/defaultLayoutConfig.json +++ b/app/components/config/defaultLayoutConfig.json @@ -176,7 +176,8 @@ "inputSource": "hostOpenProblems", "isWrappable": false, "checkColumn": true, - "noRepeatCell": "" + "noRepeatCell": "", + "pagingbar": false } }, { @@ -209,7 +210,8 @@ "inputSource": "serviceOpenProblemsOnly", "isWrappable": true, "checkColumn": true, - "noRepeatCell": "host" + "noRepeatCell": "host", + "pagingbar": false } } ] @@ -303,7 +305,8 @@ "inputSource": "hostsProblems", "isWrappable": false, "checkColumn": true, - "noRepeatCell": "" + "noRepeatCell": "", + "pagingbar": false } }, { @@ -336,7 +339,8 @@ "inputSource": "servicesProblems", "isWrappable": true, "checkColumn": true, - "noRepeatCell": "host" + "noRepeatCell": "host", + "pagingbar": false } } ] @@ -430,7 +434,8 @@ "inputSource": "hosts", "isWrappable": false, "noRepeatCell": "", - "checkColumn": true + "checkColumn": true, + "pagingbar": true } } ] @@ -520,7 +525,8 @@ "inputSource": "services", "isWrappable": false, "checkColumn": true, - "noRepeatCell": "host" + "noRepeatCell": "host", + "pagingbar": true } } ] @@ -602,7 +608,8 @@ "inputSource": "events", "isWrappable": false, "checkColumn": false, - "noRepeatCell": "" + "noRepeatCell": "", + "pagingbar": true } } ] @@ -765,7 +772,8 @@ "inputSource": "hostsConfig", "isWrappable": false, "noRepeatCell": "", - "checkColumn": false + "checkColumn": false, + "pagingbar": true } } ] @@ -839,7 +847,8 @@ "inputSource": "hostsConfigTemplate", "isWrappable": false, "noRepeatCell": "", - "checkColumn": false + "checkColumn": false, + "pagingbar": true } } ] diff --git a/app/components/datasource/datasource.js b/app/components/datasource/datasource.js index 767e817..a06c385 100644 --- a/app/components/datasource/datasource.js +++ b/app/components/datasource/datasource.js @@ -35,7 +35,7 @@ angular.module('bansho.datasource', ['bansho.surveil']) filter = componentsConfig.mergeFilters([config[tableId].queryFilter, filter]); } - promise = providerServices[inputSource.provider].getData([], filter, inputSource.endpoint); + promise = providerServices[inputSource.provider].getData([], filter, inputSource.endpoint, conf.queryPaging); promise.then(function (newData) { data[tableId] = newData; @@ -56,6 +56,13 @@ angular.module('bansho.datasource', ['bansho.surveil']) config[tableId].requestFields.push(_value); }); }); + + if (config[tableId].pagingbar) { + config[tableId].queryPaging = { + page: 0, + size: 50 + }; + } }, getConfig: function (tableId) { return config[tableId]; @@ -87,12 +94,30 @@ angular.module('bansho.datasource', ['bansho.surveil']) setSearchFilter: function (tableId, searchFilter) { config[tableId].searchFilter = searchFilter; filterData(tableId); - - notifyDataChanged(tableId); }, setQueryFilter: function (tableId, queryFilter) { config[tableId].queryFilter = queryFilter; refreshTableData(tableId); + }, + nextPage: function (tableId) { + config[tableId].queryPaging.page += 1; + refreshTableData(tableId); + }, + previousPage: function (tableId) { + if (config[tableId].queryPaging.page > 0) { + config[tableId].queryPaging.page -= 1; + refreshTableData(tableId); + } + }, + getPage: function (tableId) { + return config[tableId].queryPaging.page; + }, + setPageSize: function (tableId, pageSize) { + config[tableId].queryPaging.size = pageSize; + refreshTableData(tableId); + }, + getPageSize: function (tableId) { + return config[tableId].queryPaging.size; } }; }]) diff --git a/app/components/directive/actionbar/component_search_filter/search_filter.html b/app/components/directive/actionbar/component_search_filter/search_filter.html index c72eef8..12de0fb 100644 --- a/app/components/directive/actionbar/component_search_filter/search_filter.html +++ b/app/components/directive/actionbar/component_search_filter/search_filter.html @@ -18,4 +18,4 @@
  • ...
  • - + \ No newline at end of file diff --git a/app/components/directive/service/service.js b/app/components/directive/service/service.js index addf4e8..c4e2ab4 100644 --- a/app/components/directive/service/service.js +++ b/app/components/directive/service/service.js @@ -23,7 +23,7 @@ angular.module('bansho.service', ['bansho.datasource']) $scope.param.service.iframeUrls[metricName] = iframeUrl.getIFrameUrl("metric_" + metricName, hostname, serviceDescription); surveilStatus.getServiceMetric(hostname, serviceDescription, metricName).then(function(data) { // TODO: waiting for ORBER BY DESC support in InfluxDB - }) + }); }); }); }); diff --git a/app/components/directive/table/pagingbar/pagingbar.html b/app/components/directive/table/pagingbar/pagingbar.html new file mode 100644 index 0000000..6f077f5 --- /dev/null +++ b/app/components/directive/table/pagingbar/pagingbar.html @@ -0,0 +1,38 @@ + + + diff --git a/app/components/directive/table/pagingbar/pagingbar.js b/app/components/directive/table/pagingbar/pagingbar.js new file mode 100644 index 0000000..4a81714 --- /dev/null +++ b/app/components/directive/table/pagingbar/pagingbar.js @@ -0,0 +1,40 @@ +'use strict'; + +angular.module('bansho.table.pagingbar', ['bansho.datasource', 'bansho.surveil', 'bansho.notifications']) + .directive('banshoPagingbar', function () { + return { + restrict: 'E', + scope: { + options: '=' + }, + templateUrl: 'components/directive/table/pagingbar/pagingbar.html', + controller: ['$scope', 'datasource', + function ($scope, datasource) { + $scope.tableId = $scope.options.attributes.tableId; + $scope.pageSizes = [5, 25, 50, 75, 100]; + + $scope.page = datasource.getPage($scope.tableId); + $scope.size = datasource.getPageSize($scope.tableId); + + $scope.previousPage = function () { + datasource.previousPage($scope.tableId); + $scope.page = datasource.getPage($scope.tableId); + }; + + $scope.nextPage = function () { + datasource.nextPage($scope.tableId); + $scope.page = datasource.getPage($scope.tableId); + }; + + $scope.setPageSize = function (pageSize) { + $scope.size = pageSize; + }; + + $scope.$watch('size', function (newValue) { + if (newValue !== "") { + datasource.setPageSize($scope.tableId, newValue); + } + }); + }] + }; + }); diff --git a/app/components/directive/table/table.html b/app/components/directive/table/table.html index 477b2f2..9bd9f4a 100644 --- a/app/components/directive/table/table.html +++ b/app/components/directive/table/table.html @@ -1,6 +1,6 @@
    -

    tets{{title}}

    +

    {{title}}

    @@ -37,4 +37,5 @@
    -
    + + \ No newline at end of file diff --git a/app/components/directive/table/table.js b/app/components/directive/table/table.js index edf5c2d..083f503 100644 --- a/app/components/directive/table/table.js +++ b/app/components/directive/table/table.js @@ -11,6 +11,7 @@ angular.module('bansho.table', ['bansho.datasource', 'bansho.table.cell_status_host_status', 'bansho.table.cell_config_host', 'bansho.table.cell_config_host_register', + 'bansho.table.pagingbar', 'ngMaterial' ]) @@ -37,14 +38,16 @@ angular.module('bansho.table', ['bansho.datasource', conf.cells.name = $scope.options.attributes.cells.name; conf.inputSource = $scope.options.attributes.inputSource; - - conf.isWrappable = $scope.$eval($scope.options.attributes.isWrappable); + conf.isWrappable = $scope.options.attributes.isWrappable; + conf.pagingbar = $scope.options.attributes.pagingbar; conf.noRepeatCell = $scope.options.attributes.noRepeatCell; datasource.addTable($scope.tableId, conf); // Handle table layout $scope.checkColumn = $scope.options.attributes.checkColumn; + $scope.pagingbar = conf.pagingbar; + if ($scope.options.attributes.headerFollow) { headerFollow.activate(); diff --git a/app/components/surveil/config.js b/app/components/surveil/config.js index d72bec9..efa40dd 100644 --- a/app/components/surveil/config.js +++ b/app/components/surveil/config.js @@ -15,14 +15,14 @@ angular.module('bansho.surveil') }); }; - var getData = function (fields, filters, endpoint) { + var getData = function (fields, filters, endpoint, paging) { var promise = $q.defer(); if (!queryEndpoint[endpoint]) { throw new Error('getData in surveilConfig : Invalid endpoint ' + endpoint); } - queryEndpoint[endpoint](fields, filters, function (data) { + queryEndpoint[endpoint](fields, filters, paging, function (data) { promise.resolve(data); }); @@ -30,8 +30,8 @@ angular.module('bansho.surveil') }; var queryEndpoint = { - "hosts": function (fields, filters, callback) { - var hostQuery = surveilQuery(fields, filters.hosts), + "hosts": function (fields, filters, paging, callback) { + var hostQuery = surveilQuery(fields, filters.hosts, paging), method = 'POST', hostUrl = surveilApiConfig.endpoint('config') + '/hosts/'; diff --git a/app/components/surveil/query.js b/app/components/surveil/query.js index b9ed4e7..b145b19 100644 --- a/app/components/surveil/query.js +++ b/app/components/surveil/query.js @@ -11,7 +11,11 @@ angular.module('bansho.surveil') } query.filters = JSON.stringify(filters); - // TODO handle paging and timeInterval + if (paging) { + query.paging = paging; + } + + // TODO handle timeInterval return query; }; diff --git a/app/components/surveil/status.js b/app/components/surveil/status.js index d91667f..d7ae25d 100644 --- a/app/components/surveil/status.js +++ b/app/components/surveil/status.js @@ -58,23 +58,23 @@ angular.module('bansho.surveil') }); }; - var getData = function (fields, filters, endpoint) { + var getData = function (fields, filters, endpoint, paging) { var promise = $q.defer(); if (!queryEndpoint[endpoint]) { throw new Error('getData in surveilStatus : Invalid endpoint ' + endpoint); } - queryEndpoint[endpoint](fields, filters, function (data) { + queryEndpoint[endpoint](fields, filters, paging, function (data) { promise.resolve(data); }); return promise.promise; }; - var queryHostsServices = function (fields, filters, callback) { - var hostQuery = surveilQuery(fields, filters.hosts), - serviceQuery = surveilQuery(fields, filters.services); + var queryHostsServices = function (fields, filters, paging, callback) { + var hostQuery = surveilQuery(fields, filters.hosts, paging), + serviceQuery = surveilQuery(fields, filters.services, paging); executeQuery(surveilApiConfig.endpoint('status') + '/hosts/', 'POST', hostQuery) .success(function (hosts) { @@ -104,8 +104,8 @@ angular.module('bansho.surveil') }; var queryEndpoint = { - "services": function (fields, filters, callback) { - queryHostsServices(fields, filters, function (hosts, services) { + "services": function (fields, filters, paging, callback) { + queryHostsServices(fields, filters, paging, function (hosts, services) { var hostsDict = createHostsDict(hosts), response = []; @@ -124,8 +124,8 @@ angular.module('bansho.surveil') callback(response); }); }, - "hosts": function (fields, filters, callback) { - var hostQuery = surveilQuery(fields, filters.hosts), + "hosts": function (fields, filters, paging, callback) { + var hostQuery = surveilQuery(fields, filters.hosts, paging), method = 'POST', hostUrl = surveilApiConfig.endpoint('status') + '/hosts/'; @@ -141,8 +141,8 @@ angular.module('bansho.surveil') callback(response); }); }, - "events": function (fields, filters, callback) { - var query = surveilQuery(fields, filters.events); + "events": function (fields, filters, paging, callback) { + var query = surveilQuery(fields, filters.events, paging); executeQuery(surveilApiConfig.endpoint('status') + '/events/', 'POST', query) .success(function (events) { diff --git a/app/index.html b/app/index.html index afc63b1..5cbfdda 100644 --- a/app/index.html +++ b/app/index.html @@ -80,6 +80,7 @@ +