diff --git a/src/app/controllers/pro/accountCtrl.js b/src/app/controllers/pro/accountCtrl.js
index 8325c698254..704c7bc979c 100644
--- a/src/app/controllers/pro/accountCtrl.js
+++ b/src/app/controllers/pro/accountCtrl.js
@@ -1,43 +1,63 @@
define([
'angular',
+ 'lodash',
+ 'services/pro/backendSrv',
],
-function (angular) {
+function (angular, _) {
'use strict';
var module = angular.module('grafana.controllers');
- module.controller('AccountCtrl', function($scope, $http, alertSrv) {
+ module.controller('AccountCtrl', function($scope, $http, backendSrv) {
$scope.collaborator = {};
$scope.init = function() {
- $scope.getAccountInfo();
+ $scope.getAccount();
+ $scope.getOtherAccounts();
};
- $scope.getAccountInfo = function() {
- $http.get('/api/account').then(function(result) {
- $scope.account = result.data;
- console.log("value", result.data);
- }, function(err) {
-
+ $scope.getAccount = function() {
+ backendSrv.get('/api/account/').then(function(account) {
+ $scope.account = account;
+ $scope.collaborators = account.collaborators;
});
};
+ $scope.getOtherAccounts = function() {
+ backendSrv.get('/api/account/others').then(function(otherAccounts) {
+ $scope.otherAccounts = otherAccounts;
+ });
+ };
+
+ $scope.setUsingAccount = function(otherAccount) {
+ backendSrv.request({
+ method: 'POST',
+ url: '/api/account/using/' + otherAccount.id,
+ desc: 'Change active account',
+ }).then($scope.getOtherAccounts);
+ };
+
+ $scope.removeCollaborator = function(collaborator) {
+ backendSrv.request({
+ method: 'POST',
+ url: '/api/account/collaborators/remove',
+ data: { accountId: collaborator.accountId },
+ desc: 'Remove collaborator',
+ }).then($scope.getAccount);
+ };
+
$scope.addCollaborator = function() {
if (!$scope.addCollaboratorForm.$valid) {
return;
}
- $http.post('/api/account/collaborators/add', $scope.collaborator).then(function() {
- alertSrv.set('Collaborator added', '', 'success', 3000);
- }, function(err) {
- if (err.data && err.data.status) {
- alertSrv.set('Could not add collaborator', err.data.status, 'warning', 10000);
- }
- else if (err.statusText) {
- alertSrv.set('Could not add collaborator', err.data.status, 'warning', 10000);
- }
- });
+ backendSrv.request({
+ method: 'POST',
+ url: '/api/account/collaborators/add',
+ data: $scope.collaborator,
+ desc: 'Add collaborator'
+ }).then($scope.getAccount);
};
$scope.init();
diff --git a/src/app/partials/pro/account.html b/src/app/partials/pro/account.html
index 8deb137496c..33789cda881 100644
--- a/src/app/partials/pro/account.html
+++ b/src/app/partials/pro/account.html
@@ -51,18 +51,28 @@
-
+
+
-
- | {{Name}} |
+ |
+ | name: {{other.name}} |
+ role: {{other.role}} |
+
+ currently using this account
+ |
+
+
+ Select
+
+ |
@@ -94,7 +104,15 @@
- | {{collaborator.accountId}} |
+ | {{collaborator.email}} |
+
+ {{collaborator.role}}
+ |
+
+
+
+
+ |
diff --git a/src/app/services/pro/backendSrv.js b/src/app/services/pro/backendSrv.js
new file mode 100644
index 00000000000..4b72c847337
--- /dev/null
+++ b/src/app/services/pro/backendSrv.js
@@ -0,0 +1,47 @@
+define([
+ 'angular',
+ 'lodash',
+],
+function (angular, _) {
+ 'use strict';
+
+ var module = angular.module('grafana.services');
+
+ module.service('backendSrv', function($http, alertSrv) {
+
+ this.get = function(url) {
+ return this.request({ method: 'GET', url: url });
+ };
+
+ this.request = function(options) {
+ var httpOptions = {
+ url: options.url,
+ method: options.method,
+ data: options.data
+ };
+
+ return $http(httpOptions).then(function(results) {
+ if (options.method !== 'GET') {
+ alertSrv.set(options.desc + ' OK ', '', 'success', 3000);
+ }
+ return results.data;
+ }, function(err) {
+ var data = err.data || { message: 'Unexpected error' };
+
+ if (_.isString(data)) {
+ data = { message: data };
+ }
+
+ data.severity = 'error';
+
+ if (err.status < 500) {
+ data.severity = "warning";
+ }
+
+ alertSrv.set(options.desc + ' failed', data.message, data.severity, 10000);
+ });
+ };
+
+
+ });
+});