This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository mum. See http://git.chorem.org/mum.git commit 148b80d8c455064a03927faa53ca28b1aa8a608b Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Wed Jun 3 14:20:15 2015 +0200 dashboard: group view + subscriptions on groups + removed group page, controller and routing --- app/modules/storage_modules/shelve_db.py | 6 +- app/mum.py | 4 - static/js/controllers/dashboardCtrl.js | 34 ++++++- static/js/controllers/groupCtrl.js | 160 ------------------------------- static/js/mumApp.js | 4 - views/dashboard.html | 51 +++++++++- views/groups.html | 89 ----------------- views/index.html | 2 - 8 files changed, 78 insertions(+), 272 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 942d66e..7db31ef 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -1183,8 +1183,7 @@ class shelve_db: group = args['group'] self.open_db() try: - for username in args['subscription']: - self.db['groups'][group]['subscribers'][username] = args['subscription'][username] + self.db['groups'][group]['subscribers'] = args['subscription'] except Exception: print traceback.format_exc() finally: @@ -1420,8 +1419,7 @@ class shelve_db: addr_host = args['addr_host'] self.open_db() try: - for username in args['subscription']: - self.db['hosts'][addr_host]['conf']['subscribers'][username] = args['subscription'][username] + self.db['hosts'][addr_host]['conf']['subscribers'] = args['subscription'] except Exception: print traceback.format_exc() finally: diff --git a/app/mum.py b/app/mum.py index 8ae4817..ce802af 100755 --- a/app/mum.py +++ b/app/mum.py @@ -20,10 +20,6 @@ def index(section='home'): def angular(): return template('dashboard') -@route('/groups.html') -def angular(): - return template('groups') - @route('/hostpage.html') def angular(): return template('hostpage') diff --git a/static/js/controllers/dashboardCtrl.js b/static/js/controllers/dashboardCtrl.js index a31292b..c3b5ce5 100644 --- a/static/js/controllers/dashboardCtrl.js +++ b/static/js/controllers/dashboardCtrl.js @@ -1,4 +1,6 @@ mumApp.controller('dashboardCtrl', function ($scope, $routeParams, $location, $rootScope, $modal, DataHosts) { + /* Host view functions */ + $scope.param = $routeParams.param; // parameter in URL, null if none /*$scope.sort = { @@ -89,10 +91,6 @@ mumApp.controller('dashboardCtrl', function ($scope, $routeParams, $location, $r return res; }; - $scope.update_group = function(addr_host, grp_list){ - alert(grp_list); - }; - $scope.rem_host_to_group = function(addr_host, grp_name){ if(grp_name != 'all'){ var args = {}; @@ -129,6 +127,34 @@ mumApp.controller('dashboardCtrl', function ($scope, $routeParams, $location, $r } }); }; + + /* Group view functions */ + + $scope.group_obj = {}; /* {group_name:{"hosts":[addr1, ...],"status":"success"}, ...} */ + + $scope.update_group_obj = function (){ + var allGroups = $scope.allGroups(); + for (var i=0, l=allGroups.length ; i<l ; i++){ + var current_group_name = allGroups[i]; + $scope.group_obj[current_group_name] = {}; + $scope.group_obj[current_group_name].hosts = []; + $scope.group_obj[current_group_name].status = 'success'; + } + for (var pos_host=0, l=$scope.items.length ; pos_host < l ; pos_host++){ + var current_host_name = $scope.items[pos_host].addr; + for (var pos_grp=0, l_grp=$scope.items[pos_host].group.length ; pos_grp<l_grp ; pos_grp++){ + var current_group_name = $scope.items[pos_host].group[pos_grp]; + $scope.group_obj[current_group_name].hosts.push(current_host_name); + if ($scope.items[pos_host].status == 'danger'){ + $scope.group_obj[current_group_name].status = 'danger'; + } + else if ($scope.items[pos_host].status == 'warning' && $scope.group_obj[current_group_name].status != 'danger'){ + $scope.group_obj[current_group_name].status = 'warning'; + } + } + } + delete $scope.group_obj['all']; + }; }); mumApp.controller('ModalNotifInstanceCtrl', function ($scope, $rootScope, $modalInstance, $route, $timeout, notif_args) { diff --git a/static/js/controllers/groupCtrl.js b/static/js/controllers/groupCtrl.js deleted file mode 100644 index d853b26..0000000 --- a/static/js/controllers/groupCtrl.js +++ /dev/null @@ -1,160 +0,0 @@ -mumApp.controller('groupCtrl', function ($scope, $rootScope, $filter, $route, $routeParams, $modal, DataHosts) { - $scope.sort = { - sortingOrder : 'id', - reverse : false - }; - - $scope.items = DataHosts.Items; /* [ - { - "addr":"192.168.74.1", - "name":"www.example.com", - "status":val, //"success" or "warning" or "danger" or "" - "group":[ "all", ...], - "last_check":val //UNIX time - "subscribers":{ - "uid":val, - "priority":val - } - "warning": [mod_name, ...] - "danger": [mod_name, ...] - }, - ... - ] - */ - - $scope.group_filter = ''; - - $scope.selectedAll = false; - - $scope.selection = {}; // {addr_host: bool, ...} - - for (var i = 0, len = $scope.items.length ; i < len ; i++) { - $scope.selection[$scope.items[i]['addr']] = false; - } - - $scope.status = ''; - - $scope.grp = "all"; - - $scope.order_val = "group"; - - /*$scope.getGroupsByAddr = function(addr) { - res = ""; - for(var i = 0; i<$scope.items.length; i++){ - if($scope.items[i].addr === addr){ - res = $scope.items[i]['group'] - } - } - return res; - };*/ - - $scope.allGroups = function () { - var res = [] - for (var i = 0; i<$scope.items.length; i++) { - for (var j = 0; j<$scope.items[i].group.length; j++) { - res.push($scope.items[i].group[j]); - } - } - return res; - }; - - $scope.change_group_displayed = function () { - $scope.checkAll(false); - $scope.selection = {}; - for (i = 0 ; i < $scope.items.length ; i++) { - for (j = 0 ; j < $scope.items[i]['group'].length ; j++) { - if ($scope.grp == $scope.items[i]['group'][j]) { - $scope.selection[$scope.items[i]['addr']] = false; - } - } - } - }; - - $scope.checkAll = function (bool) { - $scope.selectedAll = bool; - for (host in $scope.selection) { - $scope.selection[host] = bool; - } - }; - - $scope.$on("resCall", function (event, args) { - if (args.func == 'remove_host_list_to_group') { - $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_HOSTS": ""})); - } - }); - - $scope.remove_host_list = function () { - var args = {}; - args['host_list'] = []; - for (host in $scope.selection) { - if ($scope.selection[host]) { - args['host_list'][args['host_list'].length] = host; - } - } - args['group'] = $scope.grp; - - $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'remove_host_list_to_group','args': args}})); - $route.reload(); - }; - - $scope.open_modal_group = function () { - var modalInstance = $modal.open({ - templateUrl: 'modal_group_label.html', - controller: 'ModalGroupInstanceCtrl', - resolve: { - group_args: function () { - var selected = []; - for (host in $scope.selection) { - if ($scope.selection[host]) { - selected[selected.length] = host; - } - } - var groups_without_all = []; - var allGroups = $scope.allGroups() - for (n in allGroups) { - if (allGroups[n] != 'all') { - groups_without_all[groups_without_all.length] = allGroups[n]; - } - } - return {"selected": selected, - "groups": groups_without_all}; - } - } - }); - }; -}); - -mumApp.controller('ModalGroupInstanceCtrl', function ($scope, $rootScope, $route, $modalInstance, group_args) { - $scope.group_args = group_args; /* { - 'selected' : tab_val, - 'groups': val - } */ - - $scope.new_grp_name = ""; - $scope.selected_grp = "all"; - - $scope.$on("resCall", function (event, args) { - if(args.func == 'add_host_list_to_group') { - $modalInstance.close(); - $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_HOSTS": ""})); - } - }); - - $scope.ok = function () { - var args = {}; - args['host_list'] = $scope.group_args['selected']; - if ($scope.new_grp_name == "") { - args['group'] = $scope.selected_grp; - } - else { - args['group'] = $scope.new_grp_name; - } - - $rootScope.$broadcast("sendViaWs", JSON.stringify({"CALL_FUNC_DB": {'func': 'add_host_list_to_group','args': args}})); - $route.reload(); - }; - - $scope.cancel = function () { - $modalInstance.close(); - }; -}); \ No newline at end of file diff --git a/static/js/mumApp.js b/static/js/mumApp.js index 1b50757..77fba04 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -18,10 +18,6 @@ mumApp.config(function ($routeProvider) { templateUrl : 'dashboard.html', controller : 'dashboardCtrl' }) - .when('/groups/',{ - templateUrl : 'groups.html', - controller : 'groupCtrl' - }) .when('/hostpage/:param/',{ templateUrl : 'hostpage.html', controller : 'hostPageCtrl' diff --git a/views/dashboard.html b/views/dashboard.html index 17d2649..9b65af6 100644 --- a/views/dashboard.html +++ b/views/dashboard.html @@ -3,10 +3,10 @@ <h1 class="page-header">Dashboard</h1> <input type="radio" value="host_view" ng-model="view"> Host view - <input type="radio" value="group_view" ng-model="view"> Group view + <input type="radio" value="group_view" ng-model="view" ng-click="update_group_obj()"> Group view <!-- Host view --> - <div ng-show="view == 'host_view'"> + <div ng-show="view == 'host_view' && items.length > 0"> <h2 class="sub-header">Hosts currently on monitoring</h2> <div class="row" ng-show="items.length > 0"> @@ -115,10 +115,50 @@ <!-- Group view --> - <div ng-show="view == 'group_view'"> - Group view + <div ng-show="view == 'group_view' && items.length > 0"> + <h2 class="sub-header">Hosts currently on monitoring (by group)</h2> + <div class="row"> + + <!-- + <div class="col-xs-3"> + <label for="name_f_grp_view">Name filter</label> + <input class="form-control" type="text" id="name_f_grp_view" ng-model="name_filter"> + </div>--> + + <table class="table table-condensed table-hover"> + <thead> + <tr> + <th><a ng-click="order_val='group'">Group</a></th> + <th><a ng-click="order_val='host'">Hosts</a></th> + <th><a ng-click="order_val='status'">Status</a></th> + </tr> + </thead> + + <tbody> + <tr ng-repeat="(groupname, group) in group_obj | + orderBy:order_val" + class="{{group.status}}"> <!-- group:{name:grp} --> + <td>{{groupname}}</td> + <td>{{group.hosts}}</td> + <td>{{group.status}}</td> + <td> + <button type="button" class="btn btn-primary btn-xs" aria-label="Subscribers" + popover-placement="left" + popover="Subscribers" + popover-trigger="mouseenter" + ng-click="open_modal_notif(null, groupname)"> + <span class="glyphicon glyphicon-user" aria-hidden="true"> + </span> + </button> + </td> + </tr> + </tbody> + </table> + </div> </div> + <!-- Message when no hosts on monitoring --> + <div ng-show="items.length == 0"> <p> No machines are under monitoring for the moment... @@ -134,9 +174,10 @@ <script type="text/ng-template" id="modal_notif_label.html"> <div class="modal-header"> - <h3 class="modal-title">Notifications for {{addr_host}}</h3> + <h3 class="modal-title">Notifications for {{addr_host}}{{grp_name}}</h3> </div> <div class="modal-body"> + {{subscribers}} <div ng-repeat="(username, subscriber) in subscribers"> {{username}} will be notified: <ul> diff --git a/views/groups.html b/views/groups.html deleted file mode 100644 index faf4252..0000000 --- a/views/groups.html +++ /dev/null @@ -1,89 +0,0 @@ -<div class="col-md-offset-2 main"> - - <h1 class="page-header">Group manager</h1> - - <div class="row"> - - <div class="col-xs-3"> - <label for="grpoption">Your existing groups</label> - <form class="form-inline" id="grpoption"> - <select class="form-control" ng-change="change_group_displayed()" ng-model="grp" ng-options="item for item in allGroups() | unique:'group'"> - </select> - </form> - </div> - - <div class="col-xs-3"> - <label for="addr_f">Address filter</label> - <input class="form-control" type="text" id="addr_f" ng-model="addr_filter"> - </div> - - <div class="col-xs-3"> - <label for="name_f">Name filter</label> - <input class="form-control" type="text" id="name_f" ng-model="name_filter"> - </div> - - <table class="table table-striped table-hover"> - <thead> - <tr> - <th><a ng-click="order_val='addr'">Address</a></th> - <th><a ng-click="order_val='name'">Name</a></th> - <th><a ng-click="order_val='group'">Groups</a></th> - <th><input type="checkbox" ng-model="selectedAll" ng-click="checkAll(!selectedAll)"></th> - </tr> - </thead> - - <tbody> - <tr ng-repeat="item in items | - filter:{addr:addr_filter, name:name_filter, group:grp} | - orderBy:order_val"> <!-- group:{name:grp} --> - <td>{{item.addr}}</td> - <td>{{item.name}}</td> - <td>{{item.group}}</td> - <td> - <input type="checkbox" ng-model="selection[item.addr]"/> - </td> - </tr> - </tbody> - </table> - - <button type="button" class="btn btn-primary" - ng-click="open_modal_group()" - ng-disable="selection=={}">Add selected to group...</button> - - <button ng-show="grp != 'all' || ''" type="button" class="btn btn-danger" ng-click="remove_host_list()">Remove selected from {{grp}}</button> - - </div> -</div> - -<script type="text/ng-template" id="modal_group_label.html"> - - <div class="modal-header"> - <h3 class="modal-title">Add {{group_args.selected}}</h3> - </div> - - <div class="modal-body"> - <form> - <div class="form-group"> - - <label for="list_grp">to an existing group</label> - <select class="form-control" id="list_grp" - ng-model="selected_grp" - ng-options="item for item in group_args.groups | unique:'group'" - ng-disabled="new_grp_name!=''"> - </select> - - <label for="grp_name">Or create a new group</label> - <input type="text" class="form-control" id="grp_name" - ng-model="new_grp_name" - ng-change="selected_grp = ''"> - - </div> - </form> - </div> - - <div class="modal-footer"> - <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="cancel()">Close</button> - <button type="button" class="btn btn-primary" ng-click="ok()">Save changes</button> - </div> - -</script> \ No newline at end of file diff --git a/views/index.html b/views/index.html index a4fc96f..4760e36 100644 --- a/views/index.html +++ b/views/index.html @@ -33,7 +33,6 @@ <script src="static/js/mumApp.js"></script> <script src="static/js/controllers/dashboardCtrl.js"></script> - <script src="static/js/controllers/groupCtrl.js"></script> <script src="static/js/controllers/hostPageCtrl.js"></script> <script src="static/js/controllers/headCtrl.js"></script> <script src="static/js/controllers/notificationsCtrl.js"></script> @@ -102,7 +101,6 @@ <ul class="nav nav-sidebar sidebar-fixed-left"> <li><a href="#dashboard">Dashboard</a></li> <li><a href="#scan">Scan for new machines</a></li> - <li><a href="#groups">Manage your groups</a></li> <li><a href="#settings">Check the default settings</a></li> <li><a href="#users">Users</a></li> <li><a href="#notifications">Notifications summary</a></li> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.