From c14a90a3d080668e14cb4c19dd5ac2c5bffe1eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 26 Feb 2015 13:01:34 +0100 Subject: [PATCH] A lot of work on new organization selection and sidenav dropdown, #1506 --- src/app/controllers/sidemenuCtrl.js | 85 ++++++++++-------- src/app/features/org/all.js | 1 + src/app/features/org/newOrgCtrl.js | 18 ++++ src/app/features/org/partials/newOrg.html | 34 +++++++ src/app/features/org/partials/orgApiKeys.html | 89 ++++++++++--------- src/app/features/org/partials/orgDetails.html | 82 ++++++++--------- src/app/features/org/partials/orgUsers.html | 1 - .../features/profile/partials/profile.html | 24 +---- src/app/features/profile/profileCtrl.js | 6 -- src/app/partials/sidemenu.html | 65 ++++++++++++-- src/app/routes/backend/all.js | 6 +- src/app/services/contextSrv.js | 2 + src/css/less/sidemenu.less | 2 +- src/css/less/variables.dark.less | 2 +- 14 files changed, 250 insertions(+), 167 deletions(-) create mode 100644 src/app/features/org/newOrgCtrl.js create mode 100644 src/app/features/org/partials/newOrg.html diff --git a/src/app/controllers/sidemenuCtrl.js b/src/app/controllers/sidemenuCtrl.js index 83a94c527da..f5a9197caac 100644 --- a/src/app/controllers/sidemenuCtrl.js +++ b/src/app/controllers/sidemenuCtrl.js @@ -9,7 +9,7 @@ function (angular, _, $, config) { var module = angular.module('grafana.controllers'); - module.controller('SideMenuCtrl', function($scope, $location, contextSrv) { + module.controller('SideMenuCtrl', function($scope, $location, contextSrv, backendSrv) { $scope.getUrl = function(url) { return config.appSubUrl + url; @@ -29,35 +29,57 @@ function (angular, _, $, config) { href: $scope.getUrl("/datasources"), }); } + }; - if (contextSrv.user.isSignedIn) { - $scope.bottomLinks.push({ - text: contextSrv.user.name, - imgSrc: contextSrv.user.gravatarUrl, - href: $scope.getUrl("/profile"), - }); + $scope.loadOrgs = function() { + $scope.orgMenu = []; - $scope.bottomLinks.push({ - text: contextSrv.user.orgName, + if (contextSrv.hasRole('Admin')) { + $scope.orgMenu.push({ + text: "Organization settings", href: $scope.getUrl("/org"), - icon: "fa fa-fw fa-users", }); - - if (contextSrv.hasRole('Admin')) { - $scope.bottomLinks.push({ - text: "Grafana admin", - icon: "fa fa-fw fa-cog", - href: $scope.getUrl("/admin/settings"), - }); - } - - $scope.bottomLinks.push({ - text: "Sign out", - target: "_self", - icon: "fa fa-fw fa-sign-out", - href: $scope.getUrl("/logout"), + $scope.orgMenu.push({ + text: "Users", + href: $scope.getUrl("/org/users"), + }); + $scope.orgMenu.push({ + text: "API Keys", + href: $scope.getUrl("/org/apikeys"), }); } + + if ($scope.orgMenu.length > 0) { + $scope.orgMenu.push({ cssClass: 'divider' }); + } + + backendSrv.get('/api/user/orgs').then(function(orgs) { + _.each(orgs, function(org) { + if (org.isUsing) { + return; + } + + $scope.orgMenu.push({ + text: "Switch to " + org.name, + icon: "fa fa-fw fa-random", + click: function() { + $scope.switchOrg(org.orgId); + } + }); + }); + + $scope.orgMenu.push({ + text: "New Organization", + icon: "fa fa-fw fa-plus", + href: $scope.getUrl('/org/new') + }); + }); + }; + + $scope.switchOrg = function(orgId) { + backendSrv.post('/api/user/using/' + orgId).then(function() { + window.location.href = $scope.getUrl('/'); + }); }; $scope.setupAdminNav = function() { @@ -81,25 +103,12 @@ function (angular, _, $, config) { icon: "fa fa-fw fa-users", href: $scope.getUrl("/admin/orgs"), }); - - $scope.bottomLinks.push({ - text: "Exit admin", - icon: "fa fa-fw fa-backward", - href: $scope.getUrl("/"), - }); - - $scope.bottomLinks.push({ - text: "Sign out", - icon: "fa fa-fw fa-sign-out", - target: "_self", - href: $scope.getUrl("/logout"), - }); }; $scope.updateMenu = function() { $scope.systemSection = false; $scope.mainLinks = []; - $scope.bottomLinks = []; + $scope.orgMenu = []; var currentPath = $location.path(); if (currentPath.indexOf('/admin') === 0) { diff --git a/src/app/features/org/all.js b/src/app/features/org/all.js index 6a8cd68ae47..ba51b99369b 100644 --- a/src/app/features/org/all.js +++ b/src/app/features/org/all.js @@ -2,6 +2,7 @@ define([ './datasourcesCtrl', './datasourceEditCtrl', './orgUsersCtrl', + './newOrgCtrl', './orgApiKeysCtrl', './orgDetailsCtrl', ], function () {}); diff --git a/src/app/features/org/newOrgCtrl.js b/src/app/features/org/newOrgCtrl.js new file mode 100644 index 00000000000..2dbee087687 --- /dev/null +++ b/src/app/features/org/newOrgCtrl.js @@ -0,0 +1,18 @@ +define([ + 'angular', +], +function (angular) { + 'use strict'; + + var module = angular.module('grafana.controllers'); + + module.controller('NewOrgCtrl', function($scope, $http, backendSrv) { + + $scope.newOrg = {name: ''}; + + $scope.createOrg = function() { + backendSrv.post('/api/org/', $scope.newOrg).then($scope.getUserOrgs); + }; + + }); +}); diff --git a/src/app/features/org/partials/newOrg.html b/src/app/features/org/partials/newOrg.html new file mode 100644 index 00000000000..56d08da701e --- /dev/null +++ b/src/app/features/org/partials/newOrg.html @@ -0,0 +1,34 @@ + + + + +
+
+ +

Add Organization

+ +
+
+
+
    +
  • + Org. name +
  • +
  • + +
  • +
  • +
  • +
+
+
+
+
+ +
+ +
+
+ diff --git a/src/app/features/org/partials/orgApiKeys.html b/src/app/features/org/partials/orgApiKeys.html index bc9a3657a56..96763856dec 100644 --- a/src/app/features/org/partials/orgApiKeys.html +++ b/src/app/features/org/partials/orgApiKeys.html @@ -1,51 +1,52 @@ - + + -
-
-
-
-
-
    -
  • - Add a key -
  • -
  • - -
  • -
  • - Role -
  • -
  • - -
  • - - -
-
-
-
+
+
-
-
- - - - - - - -
{{t.name}}{{t.role}}{{t.key}} - - - -
-
-
+

+ API Keys +

+ +
+
    +
  • + Add a key +
  • +
  • + +
  • +
  • + Role +
  • +
  • + +
  • +
  • + +
  • +
    +
+
+
+ + + + + + + + +
{{t.name}}{{t.role}}{{t.key}} + + + +
+
- diff --git a/src/app/features/org/partials/orgDetails.html b/src/app/features/org/partials/orgDetails.html index d2e0645f45f..e3a21706913 100644 --- a/src/app/features/org/partials/orgDetails.html +++ b/src/app/features/org/partials/orgDetails.html @@ -1,21 +1,20 @@
-

Organization Details

+

Organization info

  • - Name + Org. name
  • @@ -23,52 +22,45 @@
+
+
    +
  • + Address 1 +
  • +
  • + +
  • +
+
+
+
+
    +
  • + Address 2 +
  • +
  • + +
  • +
+
+
+
+
    +
  • + City +
  • +
  • + +
  • +
+
+
+

-

- API Keys -

- -
-
-
    -
  • - Add a key -
  • -
  • - -
  • -
  • - Role -
  • -
  • - -
  • -
  • - -
  • -
    -
-
-
- - - - - - - - -
{{t.name}}{{t.role}}{{t.key}} - - - -
-
-
diff --git a/src/app/features/org/partials/orgUsers.html b/src/app/features/org/partials/orgUsers.html index 8d4e2476c7a..1543db10b08 100644 --- a/src/app/features/org/partials/orgUsers.html +++ b/src/app/features/org/partials/orgUsers.html @@ -1,6 +1,5 @@ diff --git a/src/app/features/profile/partials/profile.html b/src/app/features/profile/partials/profile.html index eb1e7b81fd7..7e0351d4af1 100644 --- a/src/app/features/profile/partials/profile.html +++ b/src/app/features/profile/partials/profile.html @@ -1,4 +1,4 @@ - +
diff --git a/src/app/features/profile/profileCtrl.js b/src/app/features/profile/profileCtrl.js index 2f419305b31..e63d8a89a07 100644 --- a/src/app/features/profile/profileCtrl.js +++ b/src/app/features/profile/profileCtrl.js @@ -9,8 +9,6 @@ function (angular, config) { module.controller('ProfileCtrl', function($scope, backendSrv) { - $scope.newOrg = {name: ''}; - $scope.init = function() { $scope.getUser(); $scope.getUserOrgs(); @@ -39,10 +37,6 @@ function (angular, config) { backendSrv.put('/api/user/', $scope.user); }; - $scope.createOrg = function() { - backendSrv.post('/api/org/', $scope.newOrg).then($scope.getUserOrgs); - }; - $scope.init(); }); diff --git a/src/app/partials/sidemenu.html b/src/app/partials/sidemenu.html index a690890a3cc..782ef427f07 100644 --- a/src/app/partials/sidemenu.html +++ b/src/app/partials/sidemenu.html @@ -1,4 +1,3 @@ -
    @@ -27,13 +26,65 @@
-
diff --git a/src/app/routes/backend/all.js b/src/app/routes/backend/all.js index 06d817bd7f8..c6063ec789d 100644 --- a/src/app/routes/backend/all.js +++ b/src/app/routes/backend/all.js @@ -50,13 +50,17 @@ define([ templateUrl: 'app/features/org/partials/orgDetails.html', controller : 'OrgDetailsCtrl', }) + .when('/org/new', { + templateUrl: 'app/features/org/partials/newOrg.html', + controller : 'NewOrgCtrl', + }) .when('/org/users', { templateUrl: 'app/features/org/partials/orgUsers.html', controller : 'OrgUsersCtrl', }) .when('/org/apikeys', { templateUrl: 'app/features/org/partials/orgApiKeys.html', - controller : 'ApiKeysCtrl', + controller : 'OrgApiKeysCtrl', }) .when('/profile', { templateUrl: 'app/features/profile/partials/profile.html', diff --git a/src/app/services/contextSrv.js b/src/app/services/contextSrv.js index 4f9dc69994e..24373fff6eb 100644 --- a/src/app/services/contextSrv.js +++ b/src/app/services/contextSrv.js @@ -20,6 +20,8 @@ function (angular, _, store) { this.version = grafanaVersion; this.lightTheme = false; this.user = new User(); + this.isSignedIn = this.user.isSignedIn; + this.isGrafanaAdmin = this.user.isGrafanaAdmin; this.sidemenu = store.getBool('grafana.sidemenu'); // events diff --git a/src/css/less/sidemenu.less b/src/css/less/sidemenu.less index e374073d52c..f5338b6a190 100644 --- a/src/css/less/sidemenu.less +++ b/src/css/less/sidemenu.less @@ -42,7 +42,7 @@ margin: 0; padding: 0; - li { + >li { margin-bottom: 9px; } diff --git a/src/css/less/variables.dark.less b/src/css/less/variables.dark.less index 65adf89729a..9dfcabf53eb 100644 --- a/src/css/less/variables.dark.less +++ b/src/css/less/variables.dark.less @@ -144,7 +144,7 @@ @dropdownBackground: @heroUnitBackground; @dropdownBorder: rgba(0,0,0,.2); @dropdownDividerTop: transparent; -@dropdownDividerBottom: #222; +@dropdownDividerBottom: #444; @dropdownLinkColor: @textColor; @dropdownLinkColorHover: @white;