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 131a4f4e743ca31961f89f673810b44a5b787880 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Mar 17 13:44:43 2015 +0100 groups: les hôtes peuvent être retirés d'un groupe + changement du res de get_host() concernant les groupes => pb du filtre des groupes résolu --- app/modules/storage_modules/shelve_db.py | 22 +++++------ static/js/controllers/groupCtrl.js | 65 ++++++++++++++++++++------------ views/groups.html | 10 ++--- 3 files changed, 54 insertions(+), 43 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index fffe6c8..4522c9a 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -284,14 +284,7 @@ class shelve_db: "addr":"192.168.74.1", "name":"www.example.com", "status":val, //"success" or "warning" or "danger" or "" - "group":[ // at least 1 group "all" - { - "name":"all" - }, - { - "name":"mygroup1" - } - ], + "group":[ "all", ...], "last_check":val //UNIX time "subscribers":{ "uid":val, @@ -322,7 +315,7 @@ class shelve_db: info_host["status"] = "" info_host["group"] = [] for group in self.db["hosts"][host]["conf"]["groups"]: - info_host["group"].append({"name": group}) + info_host["group"].append(group) if "date" in self.db["hosts"][host]["status"]: info_host["last_check"] = self.db["hosts"][host]["status"]["date"] else: @@ -735,12 +728,17 @@ class shelve_db: finally: self.close_db() - def remove_host_list_to_group(self, host_list, group): + def remove_host_list_to_group(self, args): """ Remove given hosts to a group. If the group is empty afterwards, il will be also deleted. - :param host_list: a list of IP adresses - :param group: the name of the group + :param args: a dictionary containing : + { + 'host_list': val, # a list of IP adresses + 'group'; val # the group name + } """ + group = args['group'] + host_list = args['host_list'] self.open_db() try: for host in host_list: diff --git a/static/js/controllers/groupCtrl.js b/static/js/controllers/groupCtrl.js index 449cc10..b9bb876 100644 --- a/static/js/controllers/groupCtrl.js +++ b/static/js/controllers/groupCtrl.js @@ -1,4 +1,4 @@ -mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, DataHosts){ +mumApp.controller('groupCtrl', function($scope, $rootScope, $filter, $route, $routeParams, $modal, DataHosts){ $scope.sort = { sortingOrder : 'id', reverse : false @@ -9,14 +9,7 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D "addr":"192.168.74.1", "name":"www.example.com", "status":val, //"success" or "warning" or "danger" or "" - "group":[ // at least 1 group "all" - { - "name":"all" - }, - { - "name":"mygroup1" - } - ], + "group":[ "all", ...], "last_check":val //UNIX time "subscribers":{ "uid":val, @@ -31,6 +24,8 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D $scope.group_filter = ''; + $scope.selectedAll = false; + $scope.selection = {}; // {addr_host: bool, ...} for(i = 0 ; i < $scope.items.length ; i++){ @@ -42,12 +37,10 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D $scope.grp = "all"; $scope.getGroupsByAddr = function(addr) { - res = "" + res = ""; for(var i = 0; i<$scope.items.length; i++){ if($scope.items[i].addr === addr){ - for(var j = 0; j<$scope.items[i].group.length; j++){ - res += $scope.items[i].group[j].name + " "; - } + res = $scope.items[i]['group'] } } return res; @@ -57,24 +50,46 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D 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].name); + res.push($scope.items[i].group[j]); } } return res; }; - $scope.checkAll = function(){ - if($scope.selectedAll){ - $scope.selectedAll = true; - } - else{ - $scope.selectedAll = false; - } - angular.forEach($scope.items, function(item){ - item.Selected = $scope.selectedAll; - }); + $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.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', @@ -84,7 +99,7 @@ mumApp.controller('groupCtrl', function($scope, $filter, $routeParams, $modal, D var selected = []; for(host in $scope.selection){ if($scope.selection[host]){ - selected[selected.length] = host + selected[selected.length] = host; } } return {"selected": selected, diff --git a/views/groups.html b/views/groups.html index 763d555..1be9016 100644 --- a/views/groups.html +++ b/views/groups.html @@ -5,7 +5,7 @@ <div class="col-xs-3"> <label for="grpoption">Your existing groups</label> <form class="form-inline" id="grpoption"> - <select class="form-control" ng-model="grp" ng-options="item for item in allGroups() | unique:'group'"> + <select class="form-control" ng-change="change_group_displayed()" ng-model="grp" ng-options="item for item in allGroups() | unique:'group'"> </select> </form> </div> @@ -17,18 +17,17 @@ <label for="name_f">Name filter</label> <input class="form-control" type="text" id="name_f" ng-model="name_filter"> </div> - {{selection}} <table class="table table-striped table-hover"> <thead> <tr> <th>Address</th> <th>Name</th> <th>Groups</th> - <th><input type="checkbox" ng-model="selectedAll" ng-click="checkAll()"></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:{name:grp} --> + <tr ng-repeat="item in items | filter:{addr:addr_filter, name:name_filter, group:grp}"> <!-- group:{name:grp} --> <td>{{item.addr}}</td> <td>{{item.name}}</td> <td>{{getGroupsByAddr(item.addr)}}</td> @@ -39,7 +38,7 @@ </tbody> </table> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal_add" ng-click="open_modal_group()">Add selected to group...</button> - <button ng-show="grp != 'all' || ''" type="button" class="btn btn-danger">Remove selected from {{grp}}</button> + <button ng-show="grp != 'all' || ''" type="button" class="btn btn-danger" ng-click="remove_host_list()">Remove selected from {{grp}}</button> </div> </div> @@ -48,7 +47,6 @@ <h3 class="modal-title">Add to group</h3> </div> <div class="modal-body"> - {{group_args}} <form> <div class="form-group"> <label for="list_grp">From an existing group</label> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.