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 5bea208acea38f176b1a34d9c208604e7b12ce61 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Thu Mar 5 10:13:53 2015 +0100 hostpage : sauvegarde des informations custom du textarea dans bdd --- app/modules/storage_modules/shelve_db.py | 12 +++++-- static/js/controllers/hostPageCtrl.js | 56 +++++++++++++++++++++++++------- views/hostpage.html | 15 ++++----- 3 files changed, 61 insertions(+), 22 deletions(-) diff --git a/app/modules/storage_modules/shelve_db.py b/app/modules/storage_modules/shelve_db.py index 9da7e16..069bee0 100644 --- a/app/modules/storage_modules/shelve_db.py +++ b/app/modules/storage_modules/shelve_db.py @@ -339,12 +339,18 @@ class shelve_db: finally: self.close_db() - def update_custom_informations(self, addr_host, txt): + def update_custom_informations(self, args): """ Updates the custom informations stored on the host's configuration - :param addr_host: the IP adress of the host - :param txt: the new text to put on custom informations + :param args: a structure containing the values : + { + 'addr_host': val, + 'txt': val + } """ + print args + addr_host = args['addr_host'] + txt = args['txt'] self.open_db() try: self.db["hosts"][addr_host]["conf"]["custom_info"] = txt diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index 0d218b1..ba62faa 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -1,30 +1,61 @@ mumApp.controller('hostPageCtrl', function($scope, $rootScope, $routeParams, $modal) { - $scope.host_informations = null; $scope.addr_host = $routeParams.param - $rootScope.$broadcast("sendViaWs", JSON.stringify({"13": $routeParams.param})); - $scope.items = []; + // asks for host informations + $rootScope.$broadcast("sendViaWs", JSON.stringify({"13": $routeParams.param})); - $scope.custom_infos = ''; + $scope.items = [];/* result of get_host_informations => + { + "interventions":list, + "detected": + { + modname: + { + key:val, + ... + } + } + "hostname":val, + "monitoring": + { + modname: + { + "date":val, + "state":val, + "value":val + } + }, + "custom_infos":val + } + */ + $scope.model = {custom_infos : ''}; + + $scope.watch('model.custom_infos', function(){ + console.log($scope.model.custom_infos); + }) $scope.get_addr_host = function(){ return($scope.addr_host); }; - $scope.call_func = function(func, args){ - dict_instr = {'func': func, 'args': args}; - //$rootScope.$broadcast("sendViaWs", JSON.stringify({"15": dict_instr})); - }; - + // receiving the host informations $scope.$on("hostInfos", function (event, args) { $scope.$apply(function(){ $scope.items = args; - $scope.custom_infos = args.custom_infos; + $scope.model.custom_infos = args.custom_infos; }); }); + // save custom informations + $scope.save_custom_infos = function(){ + var args = {}; + args.addr_host = $scope.addr_host; + args.txt = $scope.model.custom_infos; + $rootScope.$broadcast("sendViaWs", JSON.stringify({"15": {'func': 'update_custom_informations', 'args': args}})); + }; + // creation of modals $scope.open = function (mod_name) { var modalInstance = $modal.open({ templateUrl: 'modal_conf_label.html', @@ -53,6 +84,7 @@ mumApp.controller('ModalConfInstanceCtrl', function ($scope, $rootScope, $modalI } */ + // init fields $scope.freq = 0; $scope.minor_limit_percent = 0; @@ -63,6 +95,7 @@ mumApp.controller('ModalConfInstanceCtrl', function ($scope, $rootScope, $modalI $scope.limit_bool = 'minor'; + // when the actual conf of the module is received $scope.$on("resCall", function (event, args) { $scope.$apply(function(){ $scope.items = args; @@ -83,8 +116,9 @@ mumApp.controller('ModalConfInstanceCtrl', function ($scope, $rootScope, $modalI }); }); + // after validation $scope.ok = function () { - args = {}; + var args = {}; args.addr_host = $scope.conf_args.addr_host; args.mod_name = $scope.conf_args.mod_name; args.freq = $scope.freq; diff --git a/views/hostpage.html b/views/hostpage.html index cc97937..f44faaf 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -5,8 +5,7 @@ <button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modal_conn">Connection settings</button> <button type="button" class="btn btn-info btn-xs">Launch a new detection</button> <button type="button" class="btn btn-danger btn-xs" ng-click="call_func('remove_host', [addr_host])">Remove this host</button> - {{host_informations}} - <table class="table table-condensed table-hover"> + <table class="table table-condensed table-hover"> <thead> <tr> @@ -44,8 +43,8 @@ <accordion-group heading="Custom informations"> <label for="custom_info">Add any information here :</label> - <textarea class="form-control" rows="3" id="custom_info" ng-model="custom_infos"></textarea> - <button type="button" class="btn btn-info btn-xs">Save</button> + <textarea class="form-control" rows="3" id="custom_info" ng-model="model.custom_infos"></textarea> + <button type="button" class="btn btn-info btn-xs" ng-click="save_custom_infos()">Save</button> </accordion-group> <accordion-group heading="Interventions done"> @@ -83,21 +82,21 @@ <input type="text" class="form-control" id="freq" ng-model="freq"> <div ng-show="items.unit == '%'"> <label for="minor_%">Minor notification at {{minor_limit}}% of charge</label> - <input type="range" name="cpu_warn" min="0" max="99" id="minor_%" ng-model="minor_limit_percent"> + <input type="range" min="0" max="99" id="minor_%" ng-model="minor_limit_percent"> <label for="major_%">Major notification at {{major_limit}}% of charge</label> - <input type="range" name="cpu_danger" min="{{minor_limit}}" max="100" id="major_%" ng-model="major_limit_percent"> + <input type="range" min="{{minor_limit}}" max="100" id="major_%" ng-model="major_limit_percent"> </div> <div ng-show="items.unit == 'bool'"> <label for="minor_bool">If down, send a </label> <div class="radio"> <label> - <input type="radio" name="http_crit" id="minor_bool" value="minor" ng-model="limit_bool"> + <input type="radio" id="minor_bool" value="minor" ng-model="limit_bool"> minor notification </label> </div> <div class="radio"> <label> - <input type="radio" name="http_crit" id="major_bool" value="major" ng-model="limit_bool"> + <input type="radio" id="major_bool" value="major" ng-model="limit_bool"> major notification </label> </div> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.