Просмотр исходного кода

Quick fix for frontend for account to user split

Torkel Ödegaard 11 лет назад
Родитель
Сommit
efe7279ead

+ 0 - 48
src/app/features/account/accountCtrl.js

@@ -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();
-
-  });
-});

+ 48 - 0
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();
+
+  });
+});

+ 0 - 50
src/app/features/account/collaboratorsCtrl.js

@@ -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();
-
-  });
-});

+ 10 - 10
src/app/features/account/partials/collaborators.html → src/app/features/account/partials/users.html

@@ -1,11 +1,11 @@
-<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Account > Collaborators'"></div>
+<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Account > Users'"></div>
 
 <div class="dashboard-edit-view" style="min-height: 500px">
 
 	<div class="dashboard-editor-header">
 		<div class="dashboard-editor-title">
 			<i class="fa fa-users"></i>
-			Collaborators
+			Account users
 		</div>
 	</div>
 
@@ -17,20 +17,20 @@
 					<div class="tight-form">
 						<ul class="tight-form-list">
 							<li class="tight-form-item" style="width: 160px">
-								<strong>username or email</strong>
+								<strong>Username or Email</strong>
 							</li>
 							<li>
-								<input type="text" ng-model="collaborator.loginoremail" required class="input-xlarge tight-form-input" placeholder="collaborator@email.com">
+								<input type="text" ng-model="user.loginOrEmail" required class="input-xlarge tight-form-input" placeholder="user@email.com or username">
 							</li>
 							<li class="tight-form-item">
 								role
 							</li>
 							<li>
-								<select type="text" ng-model="collaborator.role" class="input-small tight-form-input" ng-options="f for f in ['viewer', 'editor', 'admin']">
+								<select type="text" ng-model="user.role" class="input-small tight-form-input" ng-options="f for f in ['viewer', 'editor', 'admin']">
 								</select>
 							</li>
 							<li>
-								<button class="btn btn-success tight-form-btn" ng-click="addcollaborator()">add</button>
+								<button class="btn btn-success tight-form-btn" ng-click="addUser()">Add</button>
 							</li>
 						</ul>
 						<div class="clearfix"></div>
@@ -42,13 +42,13 @@
 
 		<div class="editor-row row">
 			<table class="grafana-options-table span5">
-				<tr ng-repeat="collaborator in collaborators">
-					<td>{{collaborator.email}}</td>
+				<tr ng-repeat="user in users">
+					<td>{{user.email}}</td>
 					<td>
-						{{collaborator.role}}
+						{{user.role}}
 					</td>
 					<td style="width: 1%">
-						<a ng-click="removeCollaborator(collaborator)" class="btn btn-danger btn-mini">
+						<a ng-click="removeUser(user)" class="btn btn-danger btn-mini">
 							<i class="fa fa-remove"></i>
 						</a>
 					</td>

+ 0 - 26
src/app/features/admin/accountsCtrl.js

@@ -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();
-
-  });
-});

+ 25 - 0
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();
+
+  });
+});

+ 7 - 7
src/app/features/admin/partials/accounts.html → src/app/features/admin/partials/users.html

@@ -1,4 +1,4 @@
-<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Admin > Accounts'"></div>
+<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Admin > Users'"></div>
 
 <div class="dashboard-edit-view" style="min-height: 500px">
 
@@ -15,12 +15,12 @@
 						<th>Admin</th>
 						<th></th>
 					</tr>
-					<tr ng-repeat="account in accounts">
-						<td>{{account.id}}</td>
-						<td>{{account.login}}</td>
-						<td>{{account.email}}</td>
-						<td>{{account.name}}</td>
-						<td>{{account.isAdmin}}</td>
+					<tr ng-repeat="user in users">
+						<td>{{user.id}}</td>
+						<td>{{user.login}}</td>
+						<td>{{user.email}}</td>
+						<td>{{user.name}}</td>
+						<td>{{user.isAdmin}}</td>
 						<td style="width: 1%">
 							<a ng-click="edit(variable)" class="btn btn-success btn-small">
 								<i class="fa fa-edit"></i>

+ 3 - 3
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 () {});

+ 12 - 12
src/app/features/account/partials/account.html → src/app/features/profile/partials/profile.html

@@ -1,4 +1,4 @@
-<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Account Settings'"></div>
+<div ng-include="'app/partials/navbar.html'" ng-init="pageTitle='Profile'"></div>
 
 <div class="dashboard-edit-view">
 	<div class="editor-row">
@@ -7,13 +7,13 @@
 			<div class="dashboard-editor-header">
 				<div class="dashboard-editor-title">
 					<i class="fa fa-user"></i>
-					Account details
+					Your info
 				</div>
 			</div>
 
 			<div class="dashboard-editor-body">
 
-				<form name="accountForm">
+				<form name="userForm">
 
 					<div class="tight-form">
 						<ul class="tight-form-list">
@@ -21,7 +21,7 @@
 								<strong>Name</strong>
 							</li>
 							<li>
-								<input type="text" required ng-model="account.name" class="input-xxlarge tight-form-input last" >
+								<input type="text" required ng-model="user.name" class="input-xxlarge tight-form-input last" >
 							</li>
 						</ul>
 						<div class="clearfix"></div>
@@ -32,7 +32,7 @@
 								<strong>Email</strong>
 							</li>
 							<li>
-								<input type="text" required ng-model="account.email" class="input-xxlarge tight-form-input last" >
+								<input type="text" required ng-model="user.email" class="input-xxlarge tight-form-input last" >
 							</li>
 						</ul>
 						<div class="clearfix"></div>
@@ -43,7 +43,7 @@
 								<strong>Username</strong>
 							</li>
 							<li>
-								<input type="text" required ng-model="account.login" class="input-xxlarge tight-form-input last" >
+								<input type="text" required ng-model="user.login" class="input-xxlarge tight-form-input last" >
 							</li>
 						</ul>
 						<div class="clearfix"></div>
@@ -65,14 +65,14 @@
 			<br>
 
 			<table class="grafana-options-table">
-				<tr ng-repeat="other in otherAccounts">
-					<td>email: {{other.email}}</td>
-					<td>role: {{other.role}}</td>
-					<td ng-show="other.isUsing">
+				<tr ng-repeat="ac in accounts">
+					<td>email: {{ac.email}}</td>
+					<td>role: {{ac.role}}</td>
+					<td ng-show="ac.isUsing">
 						currently using this account
 					</td>
-					<td ng-show="!other.isUsing">
-						<a ng-click="setUsingAccount(other)" class="btn btn-success btn-mini">
+					<td ng-show="!ac.isUsing">
+						<a ng-click="setUsingAccount(ac)" class="btn btn-success btn-mini">
 							Select
 						</a>
 					</td>

+ 45 - 0
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();
+
+  });
+});

+ 11 - 8
src/app/partials/sidemenu.html

@@ -16,12 +16,8 @@
 		<i class="fa fa-sitemap"></i>
 		Data
 	</a>
-	<a class="pro-sidemenu-link" href="account">
-		<i class="fa fa-user"></i>
-		Account
-	</a>
-	<a class="pro-sidemenu-link" href="account/collaborators">
-		<i class="fa fa-users"></i>Collaborators
+	<a class="pro-sidemenu-link" href="account/users">
+		<i class="fa fa-users"></i>Users
 	</a>
 	<a class="pro-sidemenu-link" href="account/apikeys">
 		<i class="fa fa-key"></i>API Keys
@@ -30,10 +26,17 @@
 		<i class="fa fa-download"></i>
 		Import
 	</a>
-	<a class="pro-sidemenu-link" href="admin/accounts" ng-if="grafana.user.isGrafanaAdmin">
+
+	<a class="pro-sidemenu-link" href="profile">
+		<i class="fa fa-user"></i>
+		Profile
+	</a>
+
+	<a class="pro-sidemenu-link" href="admin/users" ng-if="grafana.user.isGrafanaAdmin">
 		<i class="fa fa-institution"></i>Admin
 	</a>
-	<a class="pro-sidemenu-link" href="login?logout">
+
+  <a class="pro-sidemenu-link" href="login?logout">
 		<i class="fa fa-sign-out"></i>Sign out
 	</a>
 

+ 9 - 9
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',