diff --git a/Gruntfile.js b/Gruntfile.js index 17024c1..0ce1a93 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -57,7 +57,8 @@ module.exports = function (grunt) { nomen: true, predef: [ // Global variables 'angular', 'inject', 'JustGage', - 'describe', 'beforeEach', 'it', 'expect' + 'describe', 'beforeEach', 'it', 'expect', + 'moment' ] }, options: { diff --git a/app/app.js b/app/app.js index 427e044..6271c4e 100644 --- a/app/app.js +++ b/app/app.js @@ -5,7 +5,8 @@ angular.module('adagios', [ 'adagios.sidebar', 'adagios.topbar', 'adagios.tactical', - 'adagios.table' + 'adagios.table', + 'adagios.filters' ]) .config(['$routeProvider', function ($routeProvider) { diff --git a/app/components/filters/filters.js b/app/components/filters/filters.js new file mode 100644 index 0000000..5e3d66d --- /dev/null +++ b/app/components/filters/filters.js @@ -0,0 +1,9 @@ +'use strict'; + +angular.module('adagios.filters', []) + + .filter('timeElapsed', [function () { + return function (input) { + return moment.unix(input).fromNow(); + }; + }]); diff --git a/app/components/live/get_services.js b/app/components/live/get_services.js index 5167005..95d1941 100644 --- a/app/components/live/get_services.js +++ b/app/components/live/get_services.js @@ -2,12 +2,41 @@ angular.module('adagios.live') - .factory('GetServices', ['$http', function ($http, columns) { + .constant('filterSuffixes', { contains: '__contains', + has_fields: '__has_field', + startswith: '__startswith', + endswith: '__endswith', + exists: '__exists', + in: '__in', + regex: '__regex' + }) - return function (columns) { - return $http.get('/rest/status/json/services/?fields=' + columns) - .error(function (data, status, headers, config) { - console.error('GetServices : GET Request failed'); - }); - }; - }]); + .factory('getServices', ['$http', 'filterSuffixes', + function ($http, filterSuffixes, columns, filters) { + return function (columns, filters) { + var filtersQuery = ''; + + function createFiltersQuery(filters) { + var builtQuery = ''; + angular.forEach(filters, function (value, key) { + var filterType = filterSuffixes[key]; + angular.forEach(value, function (fieldValues, fieldName) { + var filter = fieldName + filterType; + angular.forEach(fieldValues, function (_value) { + var filterQuery = '&' + filter + '=' + _value; + builtQuery += filterQuery; + }); + }); + }); + + return builtQuery; + } + + filtersQuery = createFiltersQuery(filters); + + return $http.get('/rest/status/json/services/?fields=' + columns + filtersQuery) + .error(function (data, status, headers, config) { + console.error('getServices : GET Request failed'); + }); + }; + }]); diff --git a/app/components/live/get_services_test.js b/app/components/live/get_services_test.js new file mode 100644 index 0000000..ce557e5 --- /dev/null +++ b/app/components/live/get_services_test.js @@ -0,0 +1,24 @@ +'use strict'; + +describe('In Adagios Live', function () { + var $httpBackend; + + beforeEach(module('adagios.live')); + + beforeEach(inject(function (_$httpBackend_) { + $httpBackend = _$httpBackend_; + })); + + describe('getServices', function () { + + it('should send the proper GET request', inject(function (getServices) { + var fields = ['host_name', 'host_state', 'description'], + filters = { contains: { host_name: ['srv', 'a'], plugin_output: ['SWAP'] }, + startswith: { host_name: ['srv'] } }; + + getServices(fields, filters); + $httpBackend.expectGET('/rest/status/json/services/?fields=host_name,host_state,description&host_name__contains=srv&host_name__contains=a&plugin_output__contains=SWAP&host_name__startswith=srv').respond(''); + $httpBackend.flush(); + })); + }); +}); diff --git a/app/components/live/notifications.js b/app/components/live/notifications.js index c309b81..1d3b552 100644 --- a/app/components/live/notifications.js +++ b/app/components/live/notifications.js @@ -2,7 +2,7 @@ angular.module('adagios.live') - .factory('GetProblems', ['$http', function ($http) { + .factory('getProblems', ['$http', function ($http) { var problem_number = 44; return problem_number; diff --git a/app/index.html b/app/index.html index 0e56d19..c839353 100644 --- a/app/index.html +++ b/app/index.html @@ -17,12 +17,15 @@ + + + @@ -36,6 +39,7 @@ + diff --git a/app/sidebar/sidebar.js b/app/sidebar/sidebar.js index 23d8ccb..c294687 100644 --- a/app/sidebar/sidebar.js +++ b/app/sidebar/sidebar.js @@ -3,9 +3,8 @@ angular.module('adagios.sidebar', []) .controller('SideBarCtrl', ['$scope', '$http', function ($scope, $http) { - return; - - }]) + angular.noop(); + }]) .directive('adgSidebar', function () { return { diff --git a/app/table/cell_duration/cell_duration.html b/app/table/cell_duration/cell_duration.html index fa4587d..b600355 100644 --- a/app/table/cell_duration/cell_duration.html +++ b/app/table/cell_duration/cell_duration.html @@ -1 +1 @@ -
{{entry.last_state_change}}
+
{{entry.last_state_change | timeElapsed}}
diff --git a/app/table/cell_last_check/cell_last_check.html b/app/table/cell_last_check/cell_last_check.html index bae530c..bb52c8c 100644 --- a/app/table/cell_last_check/cell_last_check.html +++ b/app/table/cell_last_check/cell_last_check.html @@ -1 +1 @@ -
{{entry.last_check}}
+
{{entry.last_check * 1000 | date: medium}}
diff --git a/app/table/table.js b/app/table/table.js index 16ca859..fd51632 100644 --- a/app/table/table.js +++ b/app/table/table.js @@ -4,27 +4,28 @@ angular.module('adagios.table', ['ngRoute', 'adagios.live' ]) - .controller('TableCtrl', ['$scope', 'GetServices', function ($scope, GetServices) { + .controller('TableCtrl', ['$scope', 'getServices', function ($scope, getServices) { - var requestFields = []; + var requestFields = [], + filters = {}; + + $scope.cells = ['host', 'service_check', 'duration', 'last_check']; // The module directory name must be cell_ + key $scope.cellToFieldsMap = { host: [ 'host_state', 'host_name' ], - service_check: ['state', 'description', 'plugin_output' ], + service_check: ['state', 'description', 'plugin_output'], duration: ['last_state_change'], last_check: ['last_check'] }; - $scope.cells = ['host', 'service_check', 'duration', 'last_check']; - angular.forEach($scope.cells, function (key, value) { angular.forEach($scope.cellToFieldsMap[key], function (_value) { requestFields.push(_value); }); }); - new GetServices(requestFields) + getServices(requestFields, filters) .success(function (data) { $scope.entries = data; }); @@ -33,7 +34,6 @@ angular.module('adagios.table', ['ngRoute', .directive('adgTable', function () { return { restrict: 'E', - replace: true, templateUrl: 'table/table.html' }; }) diff --git a/app/table/table_test.js b/app/table/table_test.js new file mode 100644 index 0000000..98abe84 --- /dev/null +++ b/app/table/table_test.js @@ -0,0 +1,39 @@ +'use strict'; + +describe('In Table module', function () { + var $compile, + $rootScope, + $httpBackend; + + beforeEach(module('adagios.table')); + + beforeEach(inject(function (_$compile_, _$rootScope_, _$httpBackend_) { + $compile = _$compile_; + $rootScope = _$rootScope_; + $httpBackend = _$httpBackend_; + })); + + describe('adgCell directive', function () { + + it('should send a get request to the proper cell template', function () { + var cells = ['host', 'service_check', 'duration', 'last_check']; + + angular.forEach(cells, function (cell) { + var elem = angular.element(''); + $compile(elem)($rootScope); + $httpBackend.expectGET('table/cell_' + cell + '/cell_' + cell + '.html').respond(''); + $httpBackend.flush(); + }); + }); + }); + + describe('adgTable directive', function () { + + it('should request table/table.html template', function () { + var elem = angular.element(''); + $compile(elem)($rootScope); + $httpBackend.expectGET('table/table.html').respond(''); + $httpBackend.flush(); + }); + }); +}); diff --git a/app/topbar/topbar.js b/app/topbar/topbar.js index 36bbb38..0cfe573 100644 --- a/app/topbar/topbar.js +++ b/app/topbar/topbar.js @@ -2,8 +2,8 @@ angular.module('adagios.topbar', ['adagios.live']) - .controller('TopBarCtrl', ['$scope', '$http', 'GetProblems', function ($scope, $http, GetProblems) { - $scope.notifications = GetProblems; + .controller('TopBarCtrl', ['$scope', '$http', 'getProblems', function ($scope, $http, getProblems) { + $scope.notifications = getProblems; }]) .directive('adgTopbar', function () { diff --git a/bower.json b/bower.json index c0ca983..a454676 100644 --- a/bower.json +++ b/bower.json @@ -13,6 +13,7 @@ "html5-boilerplate": "~4.3.0", "bootstrap-sass-official": "3.3.1", "fontawesome": "4.2.0", - "justgage-toorshia" : "master" + "justgage-toorshia": "master", + "moment": "~2.9.0" } }