diff --git a/public/js/app.js b/public/js/app.js index 6c1dbafcbe1099fe58133070cdfa12e27d775726..699b9909715e57e3dcf67157367727d6496b5d94 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -486,8 +486,8 @@ angular.module('cerebro').factory('ClusterSettingsDataService', ['DataService', ]); angular.module('cerebro').controller('ConnectController', [ - '$scope', '$location', 'ConnectDataService', 'AlertService', 'DataService', - function($scope, $location, ConnectDataService, AlertService, DataService) { + '$scope', '$location', 'ConnectDataService', 'AlertService', + function($scope, $location, ConnectDataService, AlertService) { $scope.hosts = undefined; @@ -518,7 +518,7 @@ angular.module('cerebro').controller('ConnectController', [ var success = function(data) { $scope.connecting = false; if (data.status >= 200 && data.status < 300) { - DataService.setHost(host); + ConnectDataService.connect(host); $location.path('/overview'); } else { if (data.status === 401) { @@ -532,11 +532,11 @@ angular.module('cerebro').controller('ConnectController', [ $scope.connecting = false; AlertService.error('Error connecting to [' + host + ']', data); }; - ConnectDataService.connect(host, success, error); + ConnectDataService.testConnection(host, success, error); } }; - $scope.authorize = function(host, username, password) { + $scope.authorize = function(host, username, pwd) { $scope.feedback = undefined; $scope.connecting = true; var feedback = function(message) { @@ -549,7 +549,7 @@ angular.module('cerebro').controller('ConnectController', [ feedback('Invalid username or password'); break; case 200: - DataService.setHost(host, username, password); + ConnectDataService.connectWithCredentials(host, username, pwd); $location.path('/overview'); break; default: @@ -560,13 +560,13 @@ angular.module('cerebro').controller('ConnectController', [ $scope.connecting = false; AlertService.error('Error connecting to [' + host + ']', data); }; - ConnectDataService.authorize(host, username, password, success, error); + ConnectDataService.testCredentials(host, username, pwd, success, error); }; }]); -angular.module('cerebro').factory('ConnectDataService', ['$http', - function($http) { +angular.module('cerebro').factory('ConnectDataService', ['$http', 'DataService', + function($http, DataService) { this.getHosts = function(success, error) { var config = {method: 'GET', url: 'connect/hosts'}; @@ -580,17 +580,25 @@ angular.module('cerebro').factory('ConnectDataService', ['$http', $http(config).success(handleSuccess).error(error); }; - this.connect = function(host, success, error) { + this.testConnection = function(host, success, error) { var config = {method: 'POST', url: 'connect', data: {host: host}}; $http(config).success(success).error(error); }; - this.authorize = function(host, username, password, success, error) { + this.testCredentials = function(host, username, password, success, error) { var data = {host: host, username: username, password: password}; var config = {method: 'POST', url: 'connect', data: data}; $http(config).success(success).error(error); }; + this.connect = function(host) { + DataService.setHost(host); + }; + + this.connectWithCredentials = function(host, username, password) { + DataService.setHost(host, username, password); + }; + return this; } diff --git a/src/app/components/connect/controller.js b/src/app/components/connect/controller.js index b3099be69921ac1f70fdbf57caa6ba249d6cba85..a819c0fd031cca39383efc59a4f69d71bed7a3ef 100644 --- a/src/app/components/connect/controller.js +++ b/src/app/components/connect/controller.js @@ -1,6 +1,6 @@ angular.module('cerebro').controller('ConnectController', [ - '$scope', '$location', 'ConnectDataService', 'AlertService', 'DataService', - function($scope, $location, ConnectDataService, AlertService, DataService) { + '$scope', '$location', 'ConnectDataService', 'AlertService', + function($scope, $location, ConnectDataService, AlertService) { $scope.hosts = undefined; @@ -31,7 +31,7 @@ angular.module('cerebro').controller('ConnectController', [ var success = function(data) { $scope.connecting = false; if (data.status >= 200 && data.status < 300) { - DataService.setHost(host); + ConnectDataService.connect(host); $location.path('/overview'); } else { if (data.status === 401) { @@ -45,11 +45,11 @@ angular.module('cerebro').controller('ConnectController', [ $scope.connecting = false; AlertService.error('Error connecting to [' + host + ']', data); }; - ConnectDataService.connect(host, success, error); + ConnectDataService.testConnection(host, success, error); } }; - $scope.authorize = function(host, username, password) { + $scope.authorize = function(host, username, pwd) { $scope.feedback = undefined; $scope.connecting = true; var feedback = function(message) { @@ -62,7 +62,7 @@ angular.module('cerebro').controller('ConnectController', [ feedback('Invalid username or password'); break; case 200: - DataService.setHost(host, username, password); + ConnectDataService.connectWithCredentials(host, username, pwd); $location.path('/overview'); break; default: @@ -73,7 +73,7 @@ angular.module('cerebro').controller('ConnectController', [ $scope.connecting = false; AlertService.error('Error connecting to [' + host + ']', data); }; - ConnectDataService.authorize(host, username, password, success, error); + ConnectDataService.testCredentials(host, username, pwd, success, error); }; }]); diff --git a/src/app/components/connect/data.js b/src/app/components/connect/data.js index ef138c50d19e5ac745ce79c0bc8e76ab2dc3107a..1c2daf74ab25c9858c9bd1b87aef5cc43f05fe3b 100644 --- a/src/app/components/connect/data.js +++ b/src/app/components/connect/data.js @@ -1,5 +1,5 @@ -angular.module('cerebro').factory('ConnectDataService', ['$http', - function($http) { +angular.module('cerebro').factory('ConnectDataService', ['$http', 'DataService', + function($http, DataService) { this.getHosts = function(success, error) { var config = {method: 'GET', url: 'connect/hosts'}; @@ -13,17 +13,25 @@ angular.module('cerebro').factory('ConnectDataService', ['$http', $http(config).success(handleSuccess).error(error); }; - this.connect = function(host, success, error) { + this.testConnection = function(host, success, error) { var config = {method: 'POST', url: 'connect', data: {host: host}}; $http(config).success(success).error(error); }; - this.authorize = function(host, username, password, success, error) { + this.testCredentials = function(host, username, password, success, error) { var data = {host: host, username: username, password: password}; var config = {method: 'POST', url: 'connect', data: data}; $http(config).success(success).error(error); }; + this.connect = function(host) { + DataService.setHost(host); + }; + + this.connectWithCredentials = function(host, username, password) { + DataService.setHost(host, username, password); + }; + return this; }