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 d195dd8ca8927dc09500ce056d9e0de07372d9c2 Author: Alexis Guilbaud <guilbaud@codelutin.com> Date: Mon Mar 2 14:23:15 2015 +0100 séparation des controlleurs angular --- static/js/controllers/dashboardCtrl.js | 141 +++++++++++ static/js/controllers/headCtrl.js | 141 +++++++++++ static/js/controllers/mainCtrl.js | 431 --------------------------------- static/js/mumApp.js | 147 +++++++++++ views/index.html | 5 +- 5 files changed, 433 insertions(+), 432 deletions(-) diff --git a/static/js/controllers/dashboardCtrl.js b/static/js/controllers/dashboardCtrl.js new file mode 100644 index 0000000..f649cba --- /dev/null +++ b/static/js/controllers/dashboardCtrl.js @@ -0,0 +1,141 @@ +mumApp.controller('dashboardController', function($scope, $filter, $routeParams, DataHosts){ + $scope.param = $routeParams.param; + + $scope.sort = { + sortingOrder : 'id', + reverse : false + }; + + $scope.gap = 5; + + $scope.items = []; + + $scope.$on("hostsUpdate", function (event) { + $scope.items = DataHosts.Items; + }); + + $scope.filteredItems = []; + $scope.groupedItems = []; + $scope.itemsPerPage = 25; + $scope.pagedItems = []; + $scope.currentPage = 0; + + $scope.addr_filter = ''; + $scope.name_filter = ''; + + if($routeParams.param == null){ + $scope.status_filter = ''; + } + else{ + $scope.status_filter = $routeParams.param; + } + + $scope.group_filter = ''; + + $scope.status = ''; + + $scope.grp = "all"; + + $scope.toto = function(){ + $scope.items = DataHosts.Items; + alert(DataHosts.Items[0].status); + }; + + // Concerning the table manipulation + var searchMatch = function (haystack, needle) { + if (!needle) { + return true; + } + return haystack.toLowerCase().indexOf(needle.toLowerCase()) !== -1; + }; + + // init the filtered items + $scope.search = function () { + $scope.filteredItems = $filter('filter')($scope.items, function (item) { + for(var attr in item) { + if (searchMatch(item[attr], $scope.query)) + return true; + } + return false; + }); + // take care of the sorting order + if ($scope.sort.sortingOrder !== '') { + $scope.filteredItems = $filter('orderBy')($scope.filteredItems, $scope.sort.sortingOrder, $scope.sort.reverse); + } + $scope.currentPage = 0; + // now group by pages + $scope.groupToPages(); + }; + + + // calculate page in place + $scope.groupToPages = function () { + $scope.pagedItems = []; + + for (var i = 0; i < $scope.filteredItems.length; i++) { + if (i % $scope.itemsPerPage === 0) { + $scope.pagedItems[Math.floor(i / $scope.itemsPerPage)] = [ $scope.filteredItems[i] ]; + } else { + $scope.pagedItems[Math.floor(i / $scope.itemsPerPage)].push($scope.filteredItems[i]); + } + } + }; + + $scope.range = function (size,start, end) { + var ret = []; + console.log(size,start, end); + + if (size < end) { + end = size; + start = size-$scope.gap; + } + for (var i = start; i < end; i++) { + ret.push(i); + } + console.log(ret); + return ret; + }; + + $scope.prevPage = function () { + if ($scope.currentPage > 0) { + $scope.currentPage--; + } + }; + + $scope.nextPage = function () { + if ($scope.currentPage < $scope.pagedItems.length - 1) { + $scope.currentPage++; + } + }; + + $scope.setPage = function () { + $scope.currentPage = this.n; + }; + + // functions have been describe process the data for display + $scope.search(); + + // $scope.groupsByAddr = {} + + $scope.getGroupsByAddr = function(addr) { + 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 + " "; + } + } + } + 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].name); + } + } + return res; + }; +}); \ No newline at end of file diff --git a/static/js/controllers/headCtrl.js b/static/js/controllers/headCtrl.js new file mode 100644 index 0000000..231c143 --- /dev/null +++ b/static/js/controllers/headCtrl.js @@ -0,0 +1,141 @@ +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 + */ + $scope.stateNumber = function(){ + var res = [0,0,0]; + for(var i = 0; i<$scope.items.length; i++){ + if($scope.items[i].status === "success"){ + res[0]++; + } + if($scope.items[i].status === "warning"){ + res[1]++; + } + if($scope.items[i].status === "danger"){ + res[2]++; + } + } + 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; + }); + }; +}); \ No newline at end of file diff --git a/static/js/controllers/mainCtrl.js b/static/js/controllers/mainCtrl.js deleted file mode 100644 index 5bb8ee1..0000000 --- a/static/js/controllers/mainCtrl.js +++ /dev/null @@ -1,431 +0,0 @@ -var mumApp = angular.module('mumApp', ['ngRoute', 'toastr']); - -mumApp.factory('DataHosts', function(){ - return {Items: []}; -}); - -mumApp.config(function($routeProvider){ - $routeProvider - .when('/',{ - templateUrl : 'dashboard.html', - controller : 'dashboardController' - }) - .when('/dashboard',{ - templateUrl : 'dashboard.html', - controller : 'dashboardController' - }) - .when('/dashboard/:param',{ - templateUrl : 'dashboard.html', - //controller : 'mainController' - }) - .when('/groups',{ - templateUrl : 'groups.html', - //controller : 'mainController' - }) - .when('/hostpage/:param',{ - templateUrl : 'hostpage.html', - //controller : 'mainController' - }) - .when('/notifications',{ - templateUrl : 'notifications.html', - //controller : 'mainController' - }) - .when('/profile',{ - templateUrl : 'profile.html', - //controller : 'mainController' - }) - .when('/scan',{ - templateUrl : 'scan.html', - //controller : 'mainController' - }) - .when('/settings',{ - templateUrl : 'settings.html', - //controller : 'mainController' - }) - .when('/signin',{ - templateUrl : 'signin.html', - //controller : 'mainController' - }) - .when('/stats',{ - templateUrl : 'stats.html', - //controller : 'mainController' - }) - .when('/users',{ - templateUrl : 'users.html', - //controller : 'mainController' - }) - .otherwise({ - redirectTo: '/' - }); -}); - -/*mumApp.config(function($locationProvider)){ - $locationProvider.html5Mode(false).hashPrefix("!"); -});*/ - -mumApp.controller('dashboardController', function($scope, $filter, $routeParams, DataHosts){ - $scope.param = $routeParams.param; - - $scope.sort = { - sortingOrder : 'id', - reverse : false - }; - - $scope.gap = 5; - - $scope.items = []; - - $scope.$on("hostsUpdate", function (event) { - $scope.items = DataHosts.Items; - }); - - $scope.filteredItems = []; - $scope.groupedItems = []; - $scope.itemsPerPage = 25; - $scope.pagedItems = []; - $scope.currentPage = 0; - - $scope.addr_filter = ''; - $scope.name_filter = ''; - - if($routeParams.param == null){ - $scope.status_filter = ''; - } - else{ - $scope.status_filter = $routeParams.param; - } - - $scope.group_filter = ''; - - $scope.status = ''; - - $scope.grp = "all"; - - $scope.toto = function(){ - $scope.items = DataHosts.Items; - alert(DataHosts.Items[0].status); - }; - - // Concerning the table manipulation - var searchMatch = function (haystack, needle) { - if (!needle) { - return true; - } - return haystack.toLowerCase().indexOf(needle.toLowerCase()) !== -1; - }; - - // init the filtered items - $scope.search = function () { - $scope.filteredItems = $filter('filter')($scope.items, function (item) { - for(var attr in item) { - if (searchMatch(item[attr], $scope.query)) - return true; - } - return false; - }); - // take care of the sorting order - if ($scope.sort.sortingOrder !== '') { - $scope.filteredItems = $filter('orderBy')($scope.filteredItems, $scope.sort.sortingOrder, $scope.sort.reverse); - } - $scope.currentPage = 0; - // now group by pages - $scope.groupToPages(); - }; - - - // calculate page in place - $scope.groupToPages = function () { - $scope.pagedItems = []; - - for (var i = 0; i < $scope.filteredItems.length; i++) { - if (i % $scope.itemsPerPage === 0) { - $scope.pagedItems[Math.floor(i / $scope.itemsPerPage)] = [ $scope.filteredItems[i] ]; - } else { - $scope.pagedItems[Math.floor(i / $scope.itemsPerPage)].push($scope.filteredItems[i]); - } - } - }; - - $scope.range = function (size,start, end) { - var ret = []; - console.log(size,start, end); - - if (size < end) { - end = size; - start = size-$scope.gap; - } - for (var i = start; i < end; i++) { - ret.push(i); - } - console.log(ret); - return ret; - }; - - $scope.prevPage = function () { - if ($scope.currentPage > 0) { - $scope.currentPage--; - } - }; - - $scope.nextPage = function () { - if ($scope.currentPage < $scope.pagedItems.length - 1) { - $scope.currentPage++; - } - }; - - $scope.setPage = function () { - $scope.currentPage = this.n; - }; - - // functions have been describe process the data for display - $scope.search(); - - // $scope.groupsByAddr = {} - - $scope.getGroupsByAddr = function(addr) { - 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 + " "; - } - } - } - 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].name); - } - } - 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 - */ - $scope.stateNumber = function(){ - var res = [0,0,0]; - for(var i = 0; i<$scope.items.length; i++){ - if($scope.items[i].status === "success"){ - res[0]++; - } - if($scope.items[i].status === "warning"){ - res[1]++; - } - if($scope.items[i].status === "danger"){ - res[2]++; - } - } - 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; - }); - }; -}); - -mumApp.$inject = ['$scope', '$filter']; - -mumApp.directive("customSort", function() { -return { -restrict: 'A', -transclude: true, -scope: { - order: '=', - sort: '=' -}, -template : - ' <a ng-click="sort_by(order)" style="color: #555555;">'+ - ' <span ng-transclude></span>'+ - ' <i ng-class="selectedCls(order)"></i>'+ - '</a>', -link: function(scope) { - -// change sorting order -scope.sort_by = function(newSortingOrder) { - var sort = scope.sort; - - if (sort.sortingOrder == newSortingOrder){ - sort.reverse = !sort.reverse; - } - - sort.sortingOrder = newSortingOrder; -}; - - -scope.selectedCls = function(column) { - if(column == scope.sort.sortingOrder){ - return ('icon-chevron-' + ((scope.sort.reverse) ? 'down' : 'up')); - } - else{ - return'icon-sort' - } -}; -}// end link -} - - -}); - -// https://github.com/angular-ui/angular-ui-OLDREPO/blob/master/modules/filters... (MIT licence) -mumApp.filter('unique', function () { - -return function (items, filterOn) { - - if (filterOn === false) { - return items; - } - - if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) { - var hashCheck = {}, newItems = []; - - var extractValueToCompare = function (item) { - if (angular.isObject(item) && angular.isString(filterOn)) { - return item[filterOn]; - } else { - return item; - } - }; - - angular.forEach(items, function (item) { - var valueToCheck, isDuplicate = false; - - for (var i = 0; i < newItems.length; i++) { - if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) { - isDuplicate = true; - break; - } - } - if (!isDuplicate) { - newItems.push(item); - } - - }); - items = newItems; - } - return items; -}; -}); \ No newline at end of file diff --git a/static/js/mumApp.js b/static/js/mumApp.js new file mode 100644 index 0000000..3844456 --- /dev/null +++ b/static/js/mumApp.js @@ -0,0 +1,147 @@ +var mumApp = angular.module('mumApp', ['ngRoute', 'toastr']); + +mumApp.factory('DataHosts', function(){ + return {Items: []}; +}); + +mumApp.config(function($routeProvider){ + $routeProvider + .when('/',{ + templateUrl : 'dashboard.html', + controller : 'dashboardController' + }) + .when('/dashboard',{ + templateUrl : 'dashboard.html', + controller : 'dashboardController' + }) + .when('/dashboard/:param',{ + templateUrl : 'dashboard.html', + //controller : 'mainController' + }) + .when('/groups',{ + templateUrl : 'groups.html', + //controller : 'mainController' + }) + .when('/hostpage/:param',{ + templateUrl : 'hostpage.html', + //controller : 'mainController' + }) + .when('/notifications',{ + templateUrl : 'notifications.html', + //controller : 'mainController' + }) + .when('/profile',{ + templateUrl : 'profile.html', + //controller : 'mainController' + }) + .when('/scan',{ + templateUrl : 'scan.html', + //controller : 'mainController' + }) + .when('/settings',{ + templateUrl : 'settings.html', + //controller : 'mainController' + }) + .when('/signin',{ + templateUrl : 'signin.html', + //controller : 'mainController' + }) + .when('/stats',{ + templateUrl : 'stats.html', + //controller : 'mainController' + }) + .when('/users',{ + templateUrl : 'users.html', + //controller : 'mainController' + }) + .otherwise({ + redirectTo: '/' + }); +}); + +/*mumApp.config(function($locationProvider)){ + $locationProvider.html5Mode(false).hashPrefix("!"); +});*/ + +mumApp.$inject = ['$scope', '$filter']; + +mumApp.directive("customSort", function() { +return { +restrict: 'A', +transclude: true, +scope: { + order: '=', + sort: '=' +}, +template : + ' <a ng-click="sort_by(order)" style="color: #555555;">'+ + ' <span ng-transclude></span>'+ + ' <i ng-class="selectedCls(order)"></i>'+ + '</a>', +link: function(scope) { + +// change sorting order +scope.sort_by = function(newSortingOrder) { + var sort = scope.sort; + + if (sort.sortingOrder == newSortingOrder){ + sort.reverse = !sort.reverse; + } + + sort.sortingOrder = newSortingOrder; +}; + + +scope.selectedCls = function(column) { + if(column == scope.sort.sortingOrder){ + return ('icon-chevron-' + ((scope.sort.reverse) ? 'down' : 'up')); + } + else{ + return'icon-sort' + } +}; +}// end link +} + + +}); + +// https://github.com/angular-ui/angular-ui-OLDREPO/blob/master/modules/filters... (MIT licence) +mumApp.filter('unique', function () { + +return function (items, filterOn) { + + if (filterOn === false) { + return items; + } + + if ((filterOn || angular.isUndefined(filterOn)) && angular.isArray(items)) { + var hashCheck = {}, newItems = []; + + var extractValueToCompare = function (item) { + if (angular.isObject(item) && angular.isString(filterOn)) { + return item[filterOn]; + } else { + return item; + } + }; + + angular.forEach(items, function (item) { + var valueToCheck, isDuplicate = false; + + for (var i = 0; i < newItems.length; i++) { + if (angular.equals(extractValueToCompare(newItems[i]), extractValueToCompare(item))) { + isDuplicate = true; + break; + } + } + if (!isDuplicate) { + newItems.push(item); + } + + }); + items = newItems; + } + return items; +}; +}); \ No newline at end of file diff --git a/views/index.html b/views/index.html index b3f0e29..5df1a23 100644 --- a/views/index.html +++ b/views/index.html @@ -20,7 +20,10 @@ <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="static/js/mumApp.js"></script> + <script src="static/js/controllers/dashboardCtrl.js"></script> + <script src="static/js/controllers/headCtrl.js"></script> <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> <!--[if lt IE 9]><!-- -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.