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 98c7577d5babe9c4dbf21e80197ef9cfb2a536a6 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 14:04:23 2015 +0100 séparation des controlleurs angular --- app/app.py | 4 +- static/js/controllers/mainCtrl.js | 249 +++++++++++++++++++++----------------- views/dashboard.html | 3 +- views/index.html | 136 ++++++++++----------- 4 files changed, 208 insertions(+), 184 deletions(-) diff --git a/app/app.py b/app/app.py index c51e833..c55e720 100755 --- a/app/app.py +++ b/app/app.py @@ -142,12 +142,12 @@ def receive(ws): elif code == GET_HOSTS_DEMAND: db = module_loader.load_db() hosts= db.get_hosts() - print hosts ws.send(json.dumps({GET_HOSTS_RESPONSE: db.get_hosts()})) del db elif code == HOST_INFO_DEMAND: db = module_loader.load_db() - ws.send({INFO_HOST: db.get_host_inoformations(msg[HOST_INFO_DEMAND])}) + ws.send(json.dumps({INFO_HOST: db.get_host_inoformations(msg[HOST_INFO_DEMAND])})) + del db else: break except: # Should be WebSocketError when closing the connection diff --git a/static/js/controllers/mainCtrl.js b/static/js/controllers/mainCtrl.js index 79ca4a8..5bb8ee1 100644 --- a/static/js/controllers/mainCtrl.js +++ b/static/js/controllers/mainCtrl.js @@ -1,54 +1,58 @@ var mumApp = angular.module('mumApp', ['ngRoute', 'toastr']); +mumApp.factory('DataHosts', function(){ + return {Items: []}; +}); + mumApp.config(function($routeProvider){ $routeProvider .when('/',{ templateUrl : 'dashboard.html', - controller : 'mainController' + controller : 'dashboardController' }) .when('/dashboard',{ templateUrl : 'dashboard.html', - controller : 'mainController' + controller : 'dashboardController' }) .when('/dashboard/:param',{ templateUrl : 'dashboard.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/groups',{ templateUrl : 'groups.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/hostpage/:param',{ templateUrl : 'hostpage.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/notifications',{ templateUrl : 'notifications.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/profile',{ templateUrl : 'profile.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/scan',{ templateUrl : 'scan.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/settings',{ templateUrl : 'settings.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/signin',{ templateUrl : 'signin.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/stats',{ templateUrl : 'stats.html', - controller : 'mainController' + //controller : 'mainController' }) .when('/users',{ templateUrl : 'users.html', - controller : 'mainController' + //controller : 'mainController' }) .otherwise({ redirectTo: '/' @@ -59,11 +63,7 @@ mumApp.config(function($routeProvider){ $locationProvider.html5Mode(false).hashPrefix("!"); });*/ -mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', '$routeParams', '$location', - function($scope, toastr, $interval, $filter, $routeParams, $location) { - - // init - $scope.master = {}; +mumApp.controller('dashboardController', function($scope, $filter, $routeParams, DataHosts){ $scope.param = $routeParams.param; $scope.sort = { @@ -73,6 +73,12 @@ mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', $scope.gap = 5; + $scope.items = []; + + $scope.$on("hostsUpdate", function (event) { + $scope.items = DataHosts.Items; + }); + $scope.filteredItems = []; $scope.groupedItems = []; $scope.itemsPerPage = 25; @@ -91,105 +97,15 @@ mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', $scope.group_filter = ''; - $scope.items = []; - $scope.status = ''; $scope.grp = "all"; - // Concerning the scan form - - $scope.ip_range = "" // la plage d'ip entree dans le champ - $scope.state = ""; // l'etat general du scan en cours - $scope.validated = false; // pour afficher ou non certaines parties de la page - $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page - $scope.ip_scanned = {}; - - /* - // Concerning the hostpage - $scope.host_informations = null; - $scope.get_host_informations = function(addr_host){ - var request = '{"13" : "'+ addr_host + '"}'; - ws.send(request); - }*/ - - // Concerning WebSocket - var ws = new WebSocket("ws://" + $location.host() + ":1337/websocket"); - - ws.onopen = function() { - var request = '{"14" : ""}'; - ws.send(request); + $scope.toto = function(){ + $scope.items = DataHosts.Items; + alert(DataHosts.Items[0].status); }; - - ws.onmessage = function (evt) { // actions effectuees lors de la reception d'un message via la websocket - JSON.parse(evt.data, function (key, value) { - switch(parseInt(key)){ - case 20: // Success of a module execution - $scope.$apply(function(){ - $scope.state = "Success!"; - $scope.ip_scanned = value; - }); - toastr.success(value, "Success on module execution"); - case 21: // Informations concerning one host - /*$scope.$apply(function(){ - $scope.host_informations = JSON.parse(value); - });*/ - break; - case 22: // List of hosts under monitoring - $scope.$apply(function(){ - $scope.items = JSON.parse(value); - }); - break; - case 30: - $scope.$apply(function(){ - $scope.state = value; - }); - toastr.info(value, "Current status is :"); - /* - $scope.$apply(function(){ - $scope.state = value - });*/ - break; - case 31: - params = value.split(','); - if(params[0]=='success'){ - $scope.pop_success("Success on " + params[1], params[2]); - } - else if(params[0] == 'warning'){ - $scope.pop_warning("Warning on " + params[1], params[2]); - } - else if(params[0] == 'danger'){ - $scope.pop_danger("Danger on "+ params[1], params[2]); - } - break; - case 40: - toastr.error(value, "Server error"); - break; - default: - break; - } - }); - - }; - - $scope.pop_success = function(title, msg){ - toastr.success(msg, title); - }; - - $scope.pop_warning = function(title, msg){ - toastr.success(msg, title); - }; - - $scope.pop_danger = function(title, msg){ - toastr.error(msg, title); - }; - - $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire - var request = '{"10" : "' + $scope.ip_range + '"}'; - ws.send(request); - } - // Concerning the table manipulation var searchMatch = function (haystack, needle) { if (!needle) { @@ -287,6 +203,117 @@ mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', } return res; }; +}); + +mumApp.controller('headController', function($scope, $rootScope, toastr, $interval, $routeParams, $location, DataHosts) { + + // init + //$scope.master = {}; + + $scope.items = []; + + $scope.$on("hostsUpdate", function (event) { + $scope.items = DataHosts.Items; + }); + + // Concerning the scan form + + $scope.ip_range = "" // la plage d'ip entree dans le champ + $scope.state = ""; // l'etat general du scan en cours + $scope.validated = false; // pour afficher ou non certaines parties de la page + $scope.scan_is_over = false; // pour afficher ou non certaines parties de la page + $scope.ip_scanned = {}; + + + // Concerning the hostpage + $scope.host_informations = null; + $scope.get_host_informations = function(addr_host){ + alert("jobep"); + var request = '{"13" : "'+ addr_host + '"}'; + ws.send(request); + } + + // Concerning WebSocket + var ws = new WebSocket("ws://" + $location.host() + ":1337/websocket"); + + ws.onopen = function() { + var request = '{"14" : ""}'; + ws.send(request); + }; + + + ws.onmessage = function (evt) { // actions effectuees lors de la reception d'un message via la websocket + JSON.parse(evt.data, function (key, value) { + switch(parseInt(key)){ + case 20: // Success of a module execution + $scope.$apply(function(){ + $scope.state = "Success!"; + $scope.ip_scanned = value; + }); + toastr.success(value, "Success on module execution"); + /*case 21: // Informations concerning one host + $scope.$apply(function(){ + DataHosts.Items = JSON.parse(value); + alert(value); + }); + break;*/ + case 22: // List of hosts under monitoring + DataHosts.Items = JSON.parse(value); + $rootScope.$broadcast("hostsUpdate"); + $scope.$apply(function(){ + $scope.items = DataHosts.Items; + }); + break; + case 30: + $scope.$apply(function(){ + $scope.state = value; + }); + toastr.info(value, "Current status is :"); + /* + $scope.$apply(function(){ + $scope.state = value + });*/ + break; + case 31: + params = value.split(','); + if(params[0]=='success'){ + $scope.pop_success("Success on " + params[1], params[2]); + } + else if(params[0] == 'warning'){ + $scope.pop_warning("Warning on " + params[1], params[2]); + } + else if(params[0] == 'danger'){ + $scope.pop_danger("Danger on "+ params[1], params[2]); + } + break; + case 40: + toastr.error(value, "Server error"); + break; + default: + break; + } + }); + + }; + + $scope.pop_success = function(title, msg){ + toastr.success(msg, title); + }; + + $scope.pop_warning = function(title, msg){ + toastr.success(msg, title); + }; + + $scope.pop_danger = function(title, msg){ + toastr.error(msg, title); + }; + + $scope.post_val = function(){ //lace la detection apres remplissage du champ et validation du formulaire + var request = '{"10" : "' + $scope.ip_range + '"}'; + ws.send(request); + } + + /* * Return a vector with the number of hosts with a status of : success, warning, danger @@ -318,7 +345,7 @@ mumApp.controller('mainController', ['$scope', 'toastr', '$interval', '$filter', item.Selected = $scope.selectedAll; }); }; -}]); +}); mumApp.$inject = ['$scope', '$filter']; diff --git a/views/dashboard.html b/views/dashboard.html index 13e67b0..fc69e6a 100644 --- a/views/dashboard.html +++ b/views/dashboard.html @@ -2,7 +2,6 @@ <div class="col-md-offset-2 main"> <h1 class="page-header">Dashboard</h1> <h2 class="sub-header">Hosts currently on monitoring</h2> - <div class="row"> <div class="col-xs-3"> <label for="addr_f">Address filter</label> @@ -68,7 +67,7 @@ orderBy:sort.sortingOrder:sort.reverse | filter:{addr:addr_filter, name:name_filter, status:status_filter, group:{name:group_filter}}" class={{item.status}}> - <td><a href="#/hostpage/{{item.addr}}" ng-click="get_host_informations({{item.addr}})">{{item.addr}}</a></td> + <td><a href="#/hostpage/{{item.addr}}">{{item.addr}}</a></td> <td>{{item.name}}</td> <td>warning : {{item.warning}}<br/> danger : {{item.danger}}</td> diff --git a/views/index.html b/views/index.html index bce6dea..b3f0e29 100644 --- a/views/index.html +++ b/views/index.html @@ -1,81 +1,79 @@ <!DOCTYPE html> <html lang="en" ng-app="mumApp"> -<head> - <meta charset="utf-8"> - <meta http-equiv="X-UA-Compatible" content="IE=edge"> - <meta name="viewport" content="width=device-width, initial-scale=2"> - <meta name="description" content=""> - <meta name="author" content=""> - <link rel="icon" href="favicon.ico"> + <head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <meta name="viewport" content="width=device-width, initial-scale=2"> + <meta name="description" content=""> + <meta name="author" content=""> + <link rel="icon" href="favicon.ico"> - <title>Mum : Dashboard</title> + <title>Mum : Dashboard</title> - <!-- Bootstrap core CSS --> - <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> + <!-- Bootstrap core CSS --> + <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> - <!-- Custom styles for this template --> - <link href="static/css/dashboard.css" rel="stylesheet"> - <link href="bower_components/angular-toastr/dist/angular-toastr.min.css" rel="stylesheet"/> + <!-- Custom styles for this template --> + <link href="static/css/dashboard.css" rel="stylesheet"> + <link href="bower_components/angular-toastr/dist/angular-toastr.min.css" rel="stylesheet"/> - <script src="bower_components/angular/angular.min.js"></script> - <script src="bower_components/angular-toastr/dist/angular-toastr.min.js"></script> - <script src="bower_components/angular-route/angular-route.min.js"></script> - <script src="static/js/controllers/mainCtrl.js"></script> + <script src="bower_components/angular/angular.min.js"></script> + <script src="bower_components/angular-toastr/dist/angular-toastr.min.js"></script> + <script src="bower_components/angular-route/angular-route.min.js"></script> + <script src="static/js/controllers/mainCtrl.js"></script> - <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> - <!--[if lt IE 9]><!-- - <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> - <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> - <![endif]--> -</head> + <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> + <!--[if lt IE 9]><!-- + <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> + <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> + <![endif]--> + </head> -<body ng-controller="mainController"> + <body> - <nav class="navbar navbar-inverse navbar-fixed-top"> - <div class="container-fluid"> - <div class="navbar-header"> - <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> - <span class="sr-only">Toggle navigation</span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - <span class="icon-bar"></span> - </button> - <a class="navbar-brand" href="dashboard.html">Mum</a> - <p class="navbar-text navbar-left"><a href="#dashboard/success" style="color:green">OK : {{stateNumber()[0]}}</a></p> - <p class="navbar-text navbar-left"><a href="#dashboard/warning" style="color:orange">Warning : {{stateNumber()[1]}}</a></p> - <p class="navbar-text navbar-left"><a href="#dashboard/danger" style="color:red">KO : {{stateNumber()[2]}}</a></p> - </div> - <div id="navbar" class="navbar-collapse collapse"> - <ul class="nav navbar-nav navbar-right"> - <li><a href="#profile">Profile</a></li> - <li><a href="signin.html">Logout</a></li> - </ul> - </div> - </div> - </nav> - <div class="container-fluid"> - <div class="row"> - <div class="col-sm-3 col-md-2 sidebar"> - <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">Notification parameters</a></li> - <li><a href="#stats">See the statistics</a></li> - </ul> + <nav class="navbar navbar-inverse navbar-fixed-top"> + <div class="container-fluid"> + <div class="navbar-header" ng-controller="headController"> + <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> + <span class="sr-only">Toggle navigation</span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + <span class="icon-bar"></span> + </button> + <a class="navbar-brand" href="dashboard.html">Mum</a> + <p class="navbar-text navbar-left"><a href="#dashboard/success" style="color:green">OK : {{stateNumber()[0]}}</a></p> + <p class="navbar-text navbar-left"><a href="#dashboard/warning" style="color:orange">Warning : {{stateNumber()[1]}}</a></p> + <p class="navbar-text navbar-left"><a href="#dashboard/danger" style="color:red">KO : {{stateNumber()[2]}}</a></p> + </div> + <div id="navbar" class="navbar-collapse collapse"> + <ul class="nav navbar-nav navbar-right"> + <li><a href="#profile">Profile</a></li> + <li><a href="signin.html">Logout</a></li> + </ul> + </div> </div> - - - <div id="main"> - <div ng-view></div> - </div> - <!-- Bootstrap core JavaScript - ================================================== --> - <!-- Placed at the end of the document so the pages load faster --> - <script src="bower_components/jquery/dist/jquery.min.js"></script> - <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> -</body> + </nav> + <div class="container-fluid"> + <div class="row"> + <div class="col-sm-3 col-md-2 sidebar"> + <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">Notification parameters</a></li> + <li><a href="#stats">See the statistics</a></li> + </ul> + </div> + <div id="main"> + <div ng-view></div> + </div> + <!-- Bootstrap core JavaScript + ================================================== --> + <!-- Placed at the end of the document so the pages load faster --> + <script src="bower_components/jquery/dist/jquery.min.js"></script> + <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script> + </body> </html> -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.