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 @@ -