Merge pull request #12 from Freddrickk/filters
Add a few features and some unit tests
This commit is contained in:
commit
b7af587212
@ -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: {
|
||||
|
@ -5,7 +5,8 @@ angular.module('adagios', [
|
||||
'adagios.sidebar',
|
||||
'adagios.topbar',
|
||||
'adagios.tactical',
|
||||
'adagios.table'
|
||||
'adagios.table',
|
||||
'adagios.filters'
|
||||
])
|
||||
|
||||
.config(['$routeProvider', function ($routeProvider) {
|
||||
|
9
app/components/filters/filters.js
Normal file
9
app/components/filters/filters.js
Normal file
@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
angular.module('adagios.filters', [])
|
||||
|
||||
.filter('timeElapsed', [function () {
|
||||
return function (input) {
|
||||
return moment.unix(input).fromNow();
|
||||
};
|
||||
}]);
|
@ -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');
|
||||
});
|
||||
};
|
||||
}]);
|
||||
|
24
app/components/live/get_services_test.js
Normal file
24
app/components/live/get_services_test.js
Normal file
@ -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();
|
||||
}));
|
||||
});
|
||||
});
|
@ -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;
|
||||
|
@ -17,12 +17,15 @@
|
||||
|
||||
<!-- Application -->
|
||||
<script src="app.js"></script>
|
||||
|
||||
<!-- COMPONENTS -->
|
||||
<script src="components/live/live.js"></script>
|
||||
<script src="components/live/notifications.js"></script>
|
||||
<script src="components/live/get_services.js"></script>
|
||||
<script src="components/ng-justgage/ng-justgage.js"></script>
|
||||
|
||||
<script src="components/filters/filters.js"></script>
|
||||
|
||||
<!-- MODULES -->
|
||||
<script src="sidebar/sidebar.js"></script>
|
||||
|
||||
@ -36,6 +39,7 @@
|
||||
<script src="table/table.js"></script>
|
||||
|
||||
<script src="bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js"></script>
|
||||
<script src="bower_components/moment/moment.js"></script>
|
||||
</head>
|
||||
|
||||
<body class="layout color-scheme--dark">
|
||||
|
@ -3,9 +3,8 @@
|
||||
angular.module('adagios.sidebar', [])
|
||||
|
||||
.controller('SideBarCtrl', ['$scope', '$http', function ($scope, $http) {
|
||||
return;
|
||||
|
||||
}])
|
||||
angular.noop();
|
||||
}])
|
||||
|
||||
.directive('adgSidebar', function () {
|
||||
return {
|
||||
|
@ -1 +1 @@
|
||||
<div>{{entry.last_state_change}}</div>
|
||||
<div>{{entry.last_state_change | timeElapsed}}</div>
|
||||
|
@ -1 +1 @@
|
||||
<div>{{entry.last_check}}</div>
|
||||
<div>{{entry.last_check * 1000 | date: medium}}</div>
|
||||
|
@ -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'
|
||||
};
|
||||
})
|
||||
|
39
app/table/table_test.js
Normal file
39
app/table/table_test.js
Normal file
@ -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('<adg-cell type="' + cell + '"></adg-cell>');
|
||||
$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('<adg-table></adg-table>');
|
||||
$compile(elem)($rootScope);
|
||||
$httpBackend.expectGET('table/table.html').respond('');
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
});
|
@ -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 () {
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user