From 4ad428c3b11288bd173186b0bd723af883410876 Mon Sep 17 00:00:00 2001 From: Leonardo Menezes <mail@lmenezes.com> Date: Wed, 25 Oct 2017 19:59:07 +0200 Subject: [PATCH] created ConnectDataService --- public/js/app.js | 31 ++++++++++++++++++++++++++++++ src/app/components/connect/data.js | 30 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/app/components/connect/data.js diff --git a/public/js/app.js b/public/js/app.js index ae86c6f..fff8f06 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -514,6 +514,37 @@ angular.module('cerebro').controller('ConnectController', [ }]); +angular.module('cerebro').factory('ConnectDataService', ['$http', + function($http) { + + this.getHosts = function(success, error) { + var config = {method: 'GET', url: 'connect/hosts'}; + var handleSuccess = function(data) { + if (data.status >= 200 && data.status < 300) { + success(data.body); + } else { + error(data.body); + } + }; + $http(config).success(handleSuccess).error(error); + }; + + this.connect = 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) { + var data = {host: host, username: username, password: password}; + var config = {method: 'POST', url: 'connect', data: data}; + $http(config).success(success).error(error); + }; + + return this; + + } +]); + angular.module('cerebro').controller('CreateIndexController', ['$scope', 'AlertService', 'DataService', 'AceEditorService', 'RefreshService', function($scope, AlertService, DataService, AceEditorService, diff --git a/src/app/components/connect/data.js b/src/app/components/connect/data.js new file mode 100644 index 0000000..ef138c5 --- /dev/null +++ b/src/app/components/connect/data.js @@ -0,0 +1,30 @@ +angular.module('cerebro').factory('ConnectDataService', ['$http', + function($http) { + + this.getHosts = function(success, error) { + var config = {method: 'GET', url: 'connect/hosts'}; + var handleSuccess = function(data) { + if (data.status >= 200 && data.status < 300) { + success(data.body); + } else { + error(data.body); + } + }; + $http(config).success(handleSuccess).error(error); + }; + + this.connect = 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) { + var data = {host: host, username: username, password: password}; + var config = {method: 'POST', url: 'connect', data: data}; + $http(config).success(success).error(error); + }; + + return this; + + } +]); -- GitLab