diff --git a/src/app/controllers/grafanaCtrl.js b/src/app/controllers/grafanaCtrl.js index 8df9b4155d6..33c7f028567 100644 --- a/src/app/controllers/grafanaCtrl.js +++ b/src/app/controllers/grafanaCtrl.js @@ -10,7 +10,7 @@ function (angular, config, _, $, store) { var module = angular.module('grafana.controllers'); - module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, grafanaVersion, $rootScope, $controller, userSrv) { + module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, grafanaVersion, $rootScope, $controller, userSrv, $timeout) { $scope.init = function() { $scope.grafana = {}; @@ -30,6 +30,7 @@ function (angular, config, _, $, store) { $scope.grafana.style = 'dark'; $scope.grafana.user = userSrv.getSignedInUser(); $scope.grafana.sidemenu = store.getBool('grafana.sidemenu'); + $scope.topnav = { title: 'Grafana' }; $scope.onAppEvent('logged-out', function() { $scope.grafana.sidemenu = false; @@ -44,6 +45,10 @@ function (angular, config, _, $, store) { $scope.toggleSideMenu = function() { $scope.grafana.sidemenu = !$scope.grafana.sidemenu; store.set('grafana.sidemenu', $scope.grafana.sidemenu); + + $timeout(function() { + $scope.$broadcast("render"); + }, 50); }; $rootScope.onAppEvent = function(name, callback) { diff --git a/src/app/controllers/sidemenuCtrl.js b/src/app/controllers/sidemenuCtrl.js index 28e826646e8..93954006309 100644 --- a/src/app/controllers/sidemenuCtrl.js +++ b/src/app/controllers/sidemenuCtrl.js @@ -17,17 +17,16 @@ function (angular, _, $, config) { $scope.menu = []; $scope.menu.push({ - text: "Dashbord", + text: "Dashbords", + icon: "fa fa-th-large", href: $scope.getUrl("/"), startsWith: config.appSubUrl + '/dashboard/', - icon: "fa fa-th-large", - links: [ - { text: 'Settings', editview: 'settings'}, - { text: 'Templating', editview: 'templating'}, - { text: 'Annotations', editview: 'annotations'}, - { text: 'Export', href:""}, - { text: 'JSON', href:""}, - ] + }); + + $scope.menu.push({ + text: "Data Sources", + icon: "fa fa-database", + href: $scope.getUrl("/account/datasources"), }); if ($scope.grafana.user.accountRole === 'Admin') { @@ -35,12 +34,16 @@ function (angular, _, $, config) { text: "Account", href: $scope.getUrl("/account"), requireRole: "Admin", icon: "fa fa-shield", - links: [ - { text: 'Info', href: $scope.getUrl("/account")}, - { text: 'Data sources', href: $scope.getUrl("/account/datasources")}, - { text: 'Users', href: $scope.getUrl("/account/users")}, - { text: 'API Keys', href: $scope.getUrl("/account/apikeys")}, - ] + }); + $scope.menu.push({ + text: "Users", href: $scope.getUrl("/account/users"), + requireRole: "Admin", + icon: "fa fa-users", + }); + $scope.menu.push({ + text: "API Keys", href: $scope.getUrl("/account/apikeys"), + requireRole: "Admin", + icon: "fa fa-key", }); } @@ -48,11 +51,6 @@ function (angular, _, $, config) { $scope.menu.push({ text: "Profile", href: $scope.getUrl("/profile"), icon: "fa fa-user", - requireSignedIn: true, - links: [ - { text: 'Info', href: $scope.getUrl("/profile"), icon: "fa fa-sitemap" }, - { text: 'Password', href:"", icon: "fa fa-lock" }, - ] }); } @@ -69,6 +67,14 @@ function (angular, _, $, config) { }); } + if ($scope.grafana.user.isSignedIn) { + $scope.menu.push({ + text: "Sign out", href: $scope.getUrl("/logout"), + target: "_self", + icon: "fa fa-sign-out", + }); + } + $scope.onAppEvent('$routeUpdate', function() { $scope.updateState(); }); @@ -80,18 +86,21 @@ function (angular, _, $, config) { $scope.updateState = function() { var currentPath = config.appSubUrl + $location.path(); var search = $location.search(); + var activeIndex; - _.each($scope.menu, function(item) { + _.each($scope.menu, function(item, index) { item.active = false; if (item.href === currentPath) { item.active = true; + activeIndex = index; } if (item.startsWith) { if (currentPath.indexOf(item.startsWith) === 0) { item.active = true; item.href = currentPath; + activeIndex = index; } } @@ -114,6 +123,8 @@ function (angular, _, $, config) { } }); }); + + //$scope.menu.splice(0, 0, $scope.menu.splice(activeIndex, 1)[0]); }; $scope.init = function() { diff --git a/src/app/directives/all.js b/src/app/directives/all.js index 879b61e2512..4126ec81b9a 100644 --- a/src/app/directives/all.js +++ b/src/app/directives/all.js @@ -16,4 +16,5 @@ define([ './graphiteSegment', './grafanaVersionCheck', './dropdown.typeahead', + './topnav', ], function () {}); diff --git a/src/app/directives/dashEditLink.js b/src/app/directives/dashEditLink.js index b44b048f9d4..b17c73bc14d 100644 --- a/src/app/directives/dashEditLink.js +++ b/src/app/directives/dashEditLink.js @@ -6,9 +6,9 @@ function (angular, $) { 'use strict'; var editViewMap = { - 'settings': 'app/partials/dasheditor.html', - 'annotations': 'app/features/annotations/partials/editor.html', - 'templating': 'app/partials/templating_editor.html', + 'settings': { src: 'app/partials/dasheditor.html', title: "Settings" }, + 'annotations': { src: 'app/features/annotations/partials/editor.html', title: "Annotations" }, + 'templating': { src: 'app/partials/templating_editor.html', title: "Templating" } }; angular @@ -55,7 +55,10 @@ function (angular, $) { } function showEditorPane(evt, payload, editview) { - if (editview) { payload.src = editViewMap[editview]; } + if (editview) { + scope.grafana.editview = editViewMap[editview]; + payload.src = scope.grafana.editview.src; + } if (lastEditor === payload.src) { hideEditorPane(); @@ -89,7 +92,7 @@ function (angular, $) { hideScrollbars(true); var src = "'" + payload.src + "'"; - var view = $('
'); + var view = $(''); elem.append(view); $compile(elem.contents())(editorScope); } @@ -98,10 +101,12 @@ function (angular, $) { if (newValue) { showEditorPane(null, {}, newValue); } else if (oldValue) { + scope.grafana.editview = null; hideEditorPane(); } }); + scope.grafana.editview = null; scope.$on("$destroy", hideEditorPane); scope.onAppEvent('hide-dash-editor', hideEditorPane); scope.onAppEvent('show-dash-editor', showEditorPane); diff --git a/src/app/directives/topnav.js b/src/app/directives/topnav.js new file mode 100644 index 00000000000..9228ce9fcb0 --- /dev/null +++ b/src/app/directives/topnav.js @@ -0,0 +1,51 @@ +define([ + 'angular', + 'kbn' +], +function (angular) { + 'use strict'; + + angular + .module('grafana.directives') + .directive('topnav', function() { + return { + restrict: 'E', + transclude: true, + scope: { + title: "@", + section: "@", + titleAction: "&", + toggle: "&", + showMenuBtn: "=", + }, + template: + ' ', + link: function(scope, elem, attrs) { + scope.icon = attrs.icon; + } + }; + }); + +}); diff --git a/src/app/features/account/partials/account.html b/src/app/features/account/partials/account.html index 5465d0c7094..56e65c8de35 100644 --- a/src/app/features/account/partials/account.html +++ b/src/app/features/account/partials/account.html @@ -1,15 +1,8 @@ - +