From efe7279eadeffc4ba9f5a7b340e4ecdf4d208218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 19 Jan 2015 18:57:25 +0100 Subject: [PATCH] Quick fix for frontend for account to user split --- src/app/features/account/accountCtrl.js | 48 ------------------ src/app/features/account/accountUsersCtrl.js | 48 ++++++++++++++++++ src/app/features/account/collaboratorsCtrl.js | 50 ------------------- .../{collaborators.html => users.html} | 20 ++++---- src/app/features/admin/accountsCtrl.js | 26 ---------- src/app/features/admin/adminUsersCtrl.js | 25 ++++++++++ .../partials/{accounts.html => users.html} | 14 +++--- src/app/features/all.js | 6 +-- .../partials/profile.html} | 24 ++++----- src/app/features/profile/profileCtrl.js | 45 +++++++++++++++++ src/app/partials/sidemenu.html | 19 ++++--- src/app/routes/backend/all.js | 18 +++---- 12 files changed, 170 insertions(+), 173 deletions(-) delete mode 100644 src/app/features/account/accountCtrl.js create mode 100644 src/app/features/account/accountUsersCtrl.js delete mode 100644 src/app/features/account/collaboratorsCtrl.js rename src/app/features/account/partials/{collaborators.html => users.html} (62%) delete mode 100644 src/app/features/admin/accountsCtrl.js create mode 100644 src/app/features/admin/adminUsersCtrl.js rename src/app/features/admin/partials/{accounts.html => users.html} (77%) rename src/app/features/{account/partials/account.html => profile/partials/profile.html} (70%) create mode 100644 src/app/features/profile/profileCtrl.js diff --git a/src/app/features/account/accountCtrl.js b/src/app/features/account/accountCtrl.js deleted file mode 100644 index 069d0c29096..00000000000 --- a/src/app/features/account/accountCtrl.js +++ /dev/null @@ -1,48 +0,0 @@ -define([ - 'angular', -], -function (angular) { - 'use strict'; - - var module = angular.module('grafana.controllers'); - - module.controller('AccountCtrl', function($scope, $http, backendSrv) { - - $scope.collaborator = {}; - - $scope.init = function() { - $scope.getAccount(); - $scope.getOtherAccounts(); - - }; - - $scope.getAccount = function() { - backendSrv.get('/api/account/').then(function(account) { - $scope.account = account; - }); - }; - - $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.accountId, - desc: 'Change active account', - }).then($scope.getOtherAccounts); - }; - - $scope.update = function() { - if (!$scope.accountForm.$valid) { return; } - - backendSrv.post('/api/account/', $scope.account); - }; - - $scope.init(); - - }); -}); diff --git a/src/app/features/account/accountUsersCtrl.js b/src/app/features/account/accountUsersCtrl.js new file mode 100644 index 00000000000..f167625a26b --- /dev/null +++ b/src/app/features/account/accountUsersCtrl.js @@ -0,0 +1,48 @@ +define([ + 'angular', +], +function (angular) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('AccountUsersCtrl', function($scope, $http, backendSrv) { + + $scope.user = { + loginOrEmail: '', + role: 'Viewer', + }; + + $scope.init = function() { + $scope.get(); + }; + + $scope.get = function() { + backendSrv.get('/api/account/users').then(function(users) { + $scope.users = users; + }); + }; + + $scope.removeUser = function(user) { + backendSrv.request({ + method: 'DELETE', + url: '/api/account/users/' + user.id, + }).then($scope.get); + }; + + $scope.addUser = function() { + if (!$scope.form.$valid) { + return; + } + + backendSrv.request({ + method: 'PUT', + url: '/api/account/users', + data: $scope.user, + }).then($scope.get); + }; + + $scope.init(); + + }); +}); diff --git a/src/app/features/account/collaboratorsCtrl.js b/src/app/features/account/collaboratorsCtrl.js deleted file mode 100644 index 88b9fab7782..00000000000 --- a/src/app/features/account/collaboratorsCtrl.js +++ /dev/null @@ -1,50 +0,0 @@ -define([ - 'angular', -], -function (angular) { - 'use strict'; - - var module = angular.module('grafana.controllers'); - - module.controller('CollaboratorsCtrl', function($scope, $http, backendSrv) { - - $scope.collaborator = { - loginOrEmail: '', - role: 'Viewer', - }; - - $scope.init = function() { - $scope.get(); - }; - - $scope.get = function() { - backendSrv.get('/api/account/collaborators').then(function(collaborators) { - $scope.collaborators = collaborators; - }); - }; - - $scope.removeCollaborator = function(collaborator) { - backendSrv.request({ - method: 'DELETE', - url: '/api/account/collaborators/' + collaborator.id, - desc: 'Remove collaborator', - }).then($scope.get); - }; - - $scope.addCollaborator = function() { - if (!$scope.form.$valid) { - return; - } - - backendSrv.request({ - method: 'PUT', - url: '/api/account/collaborators', - data: $scope.collaborator, - desc: 'Add collaborator' - }).then($scope.get); - }; - - $scope.init(); - - }); -}); diff --git a/src/app/features/account/partials/collaborators.html b/src/app/features/account/partials/users.html similarity index 62% rename from src/app/features/account/partials/collaborators.html rename to src/app/features/account/partials/users.html index 4d3f581c069..87662c13618 100644 --- a/src/app/features/account/partials/collaborators.html +++ b/src/app/features/account/partials/users.html @@ -1,11 +1,11 @@ -
+
- Collaborators + Account users
@@ -17,20 +17,20 @@
  • - username or email + Username or Email
  • - +
  • role
  • -
  • - +
@@ -42,13 +42,13 @@
- - + + diff --git a/src/app/features/admin/accountsCtrl.js b/src/app/features/admin/accountsCtrl.js deleted file mode 100644 index 9be27e719a5..00000000000 --- a/src/app/features/admin/accountsCtrl.js +++ /dev/null @@ -1,26 +0,0 @@ -define([ - 'angular', -], -function (angular) { - 'use strict'; - - var module = angular.module('grafana.controllers'); - - module.controller('AccountsCtrl', function($scope, backendSrv) { - - $scope.init = function() { - $scope.accounts = []; - $scope.getAccounts(); - }; - - $scope.getAccounts = function() { - backendSrv.get('/api/admin/accounts').then(function(accounts) { - console.log(accounts); - $scope.accounts = accounts; - }); - }; - - $scope.init(); - - }); -}); diff --git a/src/app/features/admin/adminUsersCtrl.js b/src/app/features/admin/adminUsersCtrl.js new file mode 100644 index 00000000000..d013465778f --- /dev/null +++ b/src/app/features/admin/adminUsersCtrl.js @@ -0,0 +1,25 @@ +define([ + 'angular', +], +function (angular) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('AdminUsersCtrl', function($scope, backendSrv) { + + $scope.init = function() { + $scope.accounts = []; + $scope.getUsers(); + }; + + $scope.getUsers = function() { + backendSrv.get('/api/admin/users').then(function(users) { + $scope.users = users; + }); + }; + + $scope.init(); + + }); +}); diff --git a/src/app/features/admin/partials/accounts.html b/src/app/features/admin/partials/users.html similarity index 77% rename from src/app/features/admin/partials/accounts.html rename to src/app/features/admin/partials/users.html index d8dffe75044..0a2b48aa435 100644 --- a/src/app/features/admin/partials/accounts.html +++ b/src/app/features/admin/partials/users.html @@ -1,4 +1,4 @@ -
+
@@ -15,12 +15,12 @@
- - - - - - + + + + + +
{{collaborator.email}}
{{user.email}} - {{collaborator.role}} + {{user.role}} - + Admin
{{account.id}}{{account.login}}{{account.email}}{{account.name}}{{account.isAdmin}}
{{user.id}}{{user.login}}{{user.email}}{{user.name}}{{user.isAdmin}} diff --git a/src/app/features/all.js b/src/app/features/all.js index f3833c65906..54946bb0fc2 100644 --- a/src/app/features/all.js +++ b/src/app/features/all.js @@ -7,11 +7,11 @@ define([ './opentsdb/datasource', './elasticsearch/datasource', './dashboard/all', - './account/accountCtrl', - './account/collaboratorsCtrl', + './profile/profileCtrl', + './account/accountUsersCtrl', './account/datasourcesCtrl', './account/apiKeysCtrl', './account/importCtrl', - './admin/accountsCtrl', + './admin/adminUsersCtrl', './grafanaDatasource/datasource', ], function () {}); diff --git a/src/app/features/account/partials/account.html b/src/app/features/profile/partials/profile.html similarity index 70% rename from src/app/features/account/partials/account.html rename to src/app/features/profile/partials/profile.html index f68fdaa3ad4..5d256513af0 100644 --- a/src/app/features/account/partials/account.html +++ b/src/app/features/profile/partials/profile.html @@ -1,4 +1,4 @@ -
+
@@ -7,13 +7,13 @@
- Account details + Your info
-
+
    @@ -21,7 +21,7 @@ Name
  • - +
@@ -32,7 +32,7 @@ Email
  • - +
  • @@ -43,7 +43,7 @@ Username
  • - +
  • @@ -65,14 +65,14 @@
    - - - - + + + - diff --git a/src/app/features/profile/profileCtrl.js b/src/app/features/profile/profileCtrl.js new file mode 100644 index 00000000000..3683fdc5621 --- /dev/null +++ b/src/app/features/profile/profileCtrl.js @@ -0,0 +1,45 @@ +define([ + 'angular', +], +function (angular) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('ProfileCtrl', function($scope, $http, backendSrv) { + + $scope.init = function() { + $scope.getUser(); + $scope.getUserAccounts(); + }; + + $scope.getUser = function() { + backendSrv.get('/api/user').then(function(user) { + $scope.user = user; + }); + }; + + $scope.getUserAccounts = function() { + backendSrv.get('/api/user/accounts').then(function(accounts) { + $scope.accounts = accounts; + }); + }; + + $scope.setUsingAccount = function(account) { + backendSrv.request({ + method: 'POST', + url: '/api/user/using/' + account.accountId, + desc: 'Change active account', + }).then($scope.getUserAccounts); + }; + + $scope.update = function() { + if (!$scope.userForm.$valid) { return; } + + backendSrv.post('/api/user/', $scope.user); + }; + + $scope.init(); + + }); +}); diff --git a/src/app/partials/sidemenu.html b/src/app/partials/sidemenu.html index 207688965b9..fb3b5206899 100644 --- a/src/app/partials/sidemenu.html +++ b/src/app/partials/sidemenu.html @@ -16,12 +16,8 @@ Data - - - Account - - - Collaborators + + Users API Keys @@ -30,10 +26,17 @@ Import - + + + + Profile + + + Admin - + + Sign out diff --git a/src/app/routes/backend/all.js b/src/app/routes/backend/all.js index 740baf48c17..ab63cdc55ec 100644 --- a/src/app/routes/backend/all.js +++ b/src/app/routes/backend/all.js @@ -34,9 +34,9 @@ define([ templateUrl: 'app/features/account/partials/datasources.html', controller : 'DataSourcesCtrl', }) - .when('/account/collaborators', { - templateUrl: 'app/features/account/partials/collaborators.html', - controller : 'CollaboratorsCtrl', + .when('/account/users', { + templateUrl: 'app/features/account/partials/users.html', + controller : 'AccountUsersCtrl', }) .when('/account/apikeys', { templateUrl: 'app/features/account/partials/apikeys.html', @@ -46,13 +46,13 @@ define([ templateUrl: 'app/features/account/partials/import.html', controller : 'ImportCtrl', }) - .when('/account', { - templateUrl: 'app/features/account/partials/account.html', - controller : 'AccountCtrl', + .when('/profile', { + templateUrl: 'app/features/profile/partials/profile.html', + controller : 'ProfileCtrl', }) - .when('/admin/accounts', { - templateUrl: 'app/features/admin/partials/accounts.html', - controller : 'AccountsCtrl', + .when('/admin/users', { + templateUrl: 'app/features/admin/partials/users.html', + controller : 'AdminUsersCtrl', }) .when('/login', { templateUrl: 'app/partials/login.html',
    email: {{other.email}}role: {{other.role}} +
    email: {{ac.email}}role: {{ac.role}} currently using this account - + + Select