Skip to content

Commit

Permalink
created ConnectDataService
Browse files Browse the repository at this point in the history
  • Loading branch information
lmenezes committed Oct 25, 2017
1 parent 834c786 commit 4ad428c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
31 changes: 31 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions src/app/components/connect/data.js
Original file line number Diff line number Diff line change
@@ -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;

}
]);

0 comments on commit 4ad428c

Please sign in to comment.