mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Lots of progress on account management
This commit is contained in:
parent
e0dc530e94
commit
5dfeddf583
@ -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();
|
||||
|
@ -51,18 +51,28 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="section">
|
||||
|
||||
<div class="section">
|
||||
<div class="dashboard-editor-header">
|
||||
<div class="dashboard-editor-title">
|
||||
<i class="icon icon-eye-open"></i>
|
||||
Active account
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
|
||||
<table class="grafana-options-table">
|
||||
<tr ng-repeat="account in accounts">
|
||||
<td>{{Name}}<td>
|
||||
<tr ng-repeat="other in otherAccounts">
|
||||
<td>name: {{other.name}}</td>
|
||||
<td>role: {{other.role}}</td>
|
||||
<td ng-show="other.isUsing">
|
||||
currently using this account
|
||||
</td>
|
||||
<td ng-show="!other.isUsing">
|
||||
<a ng-click="setUsingAccount(other)" class="btn btn-success btn-mini">
|
||||
Select
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -94,7 +104,15 @@
|
||||
<div class="editor-row row">
|
||||
<table class="grafana-options-table span5">
|
||||
<tr ng-repeat="collaborator in account.collaborators">
|
||||
<td>{{collaborator.accountId}}<td>
|
||||
<td>{{collaborator.email}}</td>
|
||||
<td>
|
||||
{{collaborator.role}}
|
||||
</td>
|
||||
<td style="width: 1%">
|
||||
<a ng-click="removeCollaborator(collaborator)" class="btn btn-danger btn-mini">
|
||||
<i class="icon-remove"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
47
src/app/services/pro/backendSrv.js
Normal file
47
src/app/services/pro/backendSrv.js
Normal file
@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user