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 17ddcfca2c43ff0492222b04f5d6236761763c4e Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Tue Mar 10 16:23:06 2015 +0100 hostpage : paramètres avancés de connexion => ràf génération du formulaire --- app/app.py | 6 ++- app/module_loader.py | 7 +-- bower.json | 6 ++- static/js/controllers/headCtrl.js | 3 ++ static/js/controllers/hostPageCtrl.js | 89 ++++++++++++++++++++++++++++++++++- static/js/mumApp.js | 2 +- views/hostpage.html | 16 ++++++- views/index.html | 1 + 8 files changed, 120 insertions(+), 10 deletions(-) diff --git a/app/app.py b/app/app.py index eeb595d..1d793e1 100755 --- a/app/app.py +++ b/app/app.py @@ -5,6 +5,7 @@ __author__ = 'aguilbaud' from bottle import * from bottle_websocket import GeventWebSocketServer from bottle_websocket import websocket +from geventwebsocket import WebSocketError import json import threading from module_loader import ModuleLoader @@ -136,13 +137,14 @@ def receive(ws): elif code == "CALL_FUNC_DB": res = ml.launch_db_function(msg["CALL_FUNC_DB"]) if res is not None: - print res ws.send(json.dumps({"RES_CALL_FUNC_DB": res})) else: print 'res is None' + elif code == "GET_LOADED_CONN_MOD": + ws.send(json_dumps({"RES_GET_LOADED_CONN_MOD": ml.get_conection_modules_list()})) else: break - except: # Should be WebSocketError when closing the connection + except WebSocketError: # Should be WebSocketError when closing the connection wsc.remove_websocket(ws) break diff --git a/app/module_loader.py b/app/module_loader.py index 57ae88b..6b12871 100644 --- a/app/module_loader.py +++ b/app/module_loader.py @@ -207,13 +207,14 @@ class ModuleLoader: { mod_name: { - 'class_name': val, => the name of the class to instanciate - 'imported': module, => the module imported 'params': {param1: type1, param2: type2, ...} => the parameters necessary to create the connection } } """ - return self.loaded_mod_conn + res = {} + for mod in self.loaded_mod_conn: + res[mod] = self.loaded_mod_conn[mod]['params'] + return json.dumps(res) def update_global_conf(self): """ diff --git a/bower.json b/bower.json index c470f26..2dd7dba 100644 --- a/bower.json +++ b/bower.json @@ -6,6 +6,10 @@ "angular": "~1.2.28", "angular-toastr": "~0.5.2", "angular-route": "~1.2.28", - "angular-bootstrap": "~0.12.1" + "angular-bootstrap": "~0.12.1", + "angular-sanitize": "~1.2.28" + }, + "resolutions": { + "angular": "~1.2.28" } } diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js index e8aeb8d..fa1bd32 100644 --- a/static/js/controllers/headCtrl.js +++ b/static/js/controllers/headCtrl.js @@ -39,6 +39,9 @@ mumApp.controller('headCtrl', function($scope, $rootScope, toastr, $interval, $r $scope.items = DataHosts.Items; }); break; + case "RES_GET_LOADED_CONN_MOD": + $rootScope.$broadcast("resGetLoadedConnMod", JSON.parse(value)); + break; case "RES_CALL_FUNC_DB": // Get a result after calling a funcion on the db $rootScope.$broadcast("resCall", JSON.parse(value)); break; diff --git a/static/js/controllers/hostPageCtrl.js b/static/js/controllers/hostPageCtrl.js index b49ef66..669c62c 100644 --- a/static/js/controllers/hostPageCtrl.js +++ b/static/js/controllers/hostPageCtrl.js @@ -192,7 +192,7 @@ mumApp.controller('ModalIntervInstanceCtrl', function ($scope, $rootScope, $moda }; }); -mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalInstance, conn_args) { +mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalInstance, $modal, conn_args) { $scope.conn_args = conn_args; // {'addr_host' : val} $scope.current_config = {}; @@ -231,4 +231,89 @@ mumApp.controller('ModalConnInstanceCtrl', function ($scope, $rootScope, $modalI $scope.cancel = function () { $modalInstance.close(); }; -}); \ No newline at end of file + + $scope.open_modal_conf_conn = function (modname) { + var modalInstance = $modal.open({ + templateUrl: 'modal_conf_conn_label.html', + controller: 'ModalConfConnInstanceCtrl', + size: 'lg', + resolve: { + conf_conn_args: function(){ + return {'addr_host' : $scope.conn_args['addr_host'], 'modname': modname, 'current_config': $scope.current_config}; + } + } + }); + }; +}); + +mumApp.controller('ModalConfConnInstanceCtrl', function ($scope, $rootScope, $modalInstance, $templateCache, conf_conn_args) { + $scope.conf_conn_args = conf_conn_args; /* {'addr_host': val, + 'modname': val, + 'current_config': val} */ + + $scope.loaded_conn_mods = {}; /* { + mod_name: + { + 'class_name': val, => the name of the class to instanciate + 'imported': module, => the module imported + 'params': {param1: type1, param2: type2, ...} => the parameters necessary to create the connection + } + } */ + + + $rootScope.$broadcast("sendViaWs", JSON.stringify({"GET_LOADED_CONN_MOD": ""})); + + $scope.$on("resGetLoadedConnMod", function (event, args) { + $scope.$apply(function(){ + $scope.loaded_conn_mods = args; + for(mod in args){ + //alert(args[mod]); + for(param in args[mod]){ + //alert(param); + $scope.form += '<div class="row">'; + $scope.form += ' <div class="col-xs-3">'; + $scope.form += ' <label for="' + param + '">' + param + '</label>' + //if(mod['params'] == "string"){ + $scope.form += '<input type="text" id="' + param + '"/>'; + //} + $scope.form += ' </div>'; + $scope.form += '</div>'; + } + } + $templateCache.put('templateForm.html', $scope.form); + }); + }); + + $scope.ok = function () { + var args = {}; + + + $modalInstance.close(); + }; + + $scope.cancel = function () { + $modalInstance.close(); + }; +}); +/* +mumApp.directive("formLoader", ['$compile', '$templateCache', function ($compile, $templateCache) { + + var getTemplate = function(data) { + // use data to determine which template to use + var templateid = 'foo'; + var template = $templateCache.get(templateid); + return template; + } + + return { + templateUrl: 'views/partials/template.html', + scope: {data: '='}, + restrict: 'E', + link: function(scope, element) { + var template = getTemplate(scope.data); + + element.html(template); + $compile(element.contents())(scope); + } + }; +}]);*/ \ No newline at end of file diff --git a/static/js/mumApp.js b/static/js/mumApp.js index 9a8f2e8..c6c12c0 100644 --- a/static/js/mumApp.js +++ b/static/js/mumApp.js @@ -1,4 +1,4 @@ -var mumApp = angular.module('mumApp', ['ngRoute', 'ui.bootstrap', 'toastr']); +var mumApp = angular.module('mumApp', ['ngSanitize', 'ngRoute', 'ui.bootstrap', 'toastr']); mumApp.factory('DataHosts', function(){ return {Items: []}; diff --git a/views/hostpage.html b/views/hostpage.html index 3e2c553..b7df634 100644 --- a/views/hostpage.html +++ b/views/hostpage.html @@ -164,7 +164,7 @@ <td>{{modname}}</td> <td><input type="number" min="0" ng-model="priorities[modname]" disabled="{{isNotConfigured(modname)}}"></td> <td> - <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal_conf_conn">Advanced configuration</button> + <button type="button" class="btn btn-primary" ng-click="open_modal_conf_conn(modname)">Advanced configuration</button> <button type="button" class="btn btn-success">Test</button> </td> @@ -180,6 +180,20 @@ </div> </script> + + + <script type="text/ng-template" id="modal_conf_conn_label.html"> + <div class="modal-header"> + <h3 class="modal-title">Advanced settings for {{conf_conn_args['modname']}}</h3>{{loaded_conn_mods}} + </div> + {{form}} + <div ng-include=" 'templateForm.html' "></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> + <!-- <div class="modal fade bs-example-modal-lg" id="modal_conf_conn" tabindex="-1" role="dialog" aria-labelledby="modal_conf_conn_label" aria-hidden="true"> <div class="modal-dialog modal-lg"> diff --git a/views/index.html b/views/index.html index 3eeeeaf..1ac05c3 100644 --- a/views/index.html +++ b/views/index.html @@ -19,6 +19,7 @@ <!-- AngularJS --> <script src="bower_components/angular/angular.min.js"></script> + <script src="bower_components/angular-sanitize/angular-sanitize.min.js"></script> <script src="bower_components/angular-route/angular-route.min.js"></script> <script src="bower_components/angular-toastr/dist/angular-toastr.min.js"></script> <script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.