diff --git a/src/app/controllers/errorCtrl.js b/src/app/controllers/errorCtrl.js index 97f606fcaa3..9e70efb3ee4 100644 --- a/src/app/controllers/errorCtrl.js +++ b/src/app/controllers/errorCtrl.js @@ -8,13 +8,13 @@ function (angular) { var module = angular.module('grafana.controllers'); - module.controller('ErrorCtrl', function($scope) { + module.controller('ErrorCtrl', function($scope, contextSrv) { - var showSideMenu = $scope.grafana.sidemenu; - $scope.grafana.sidemenu = false; + var showSideMenu = contextSrv.sidemenu; + contextSrv.sidemenu = false; $scope.$on('$destroy', function() { - $scope.grafana.sidemenu = showSideMenu; + $scope.contextSrv.sidemenu = showSideMenu; }); }); diff --git a/src/app/controllers/grafanaCtrl.js b/src/app/controllers/grafanaCtrl.js index 3922af87be8..08ae1b9c1a8 100644 --- a/src/app/controllers/grafanaCtrl.js +++ b/src/app/controllers/grafanaCtrl.js @@ -10,11 +10,11 @@ function (angular, config, _, $, store) { var module = angular.module('grafana.controllers'); - module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, grafanaVersion, $rootScope, $controller, userSrv, $timeout) { + module.controller('GrafanaCtrl', function($scope, alertSrv, utilSrv, $rootScope, $controller, contextSrv) { $scope.init = function() { - $scope.grafana = {}; - $scope.grafana.version = grafanaVersion; + $scope.contextSrv = contextSrv; + $scope._ = _; $rootScope.profilingEnabled = store.getBool('profilingEnabled'); @@ -27,30 +27,12 @@ function (angular, config, _, $, store) { utilSrv.init(); $scope.dashAlerts = alertSrv; - $scope.grafana.lightTheme = false; - $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; - $scope.grafana.user = {}; - }); }; $scope.initDashboard = function(dashboardData, viewScope) { $controller('DashboardCtrl', { $scope: viewScope }).init(dashboardData); }; - $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) { var unbind = $rootScope.$on(name, callback); this.$on('$destroy', unbind); diff --git a/src/app/controllers/loginCtrl.js b/src/app/controllers/loginCtrl.js index 1afa133235d..5de773842f8 100644 --- a/src/app/controllers/loginCtrl.js +++ b/src/app/controllers/loginCtrl.js @@ -7,14 +7,14 @@ function (angular, config) { var module = angular.module('grafana.controllers'); - module.controller('LoginCtrl', function($scope, backendSrv) { + module.controller('LoginCtrl', function($scope, backendSrv, contextSrv) { $scope.formModel = { user: '', email: '', password: '', }; - $scope.grafana.sidemenu = false; + contextSrv.setSideMenuState(false); $scope.googleAuthEnabled = config.googleAuthEnabled; $scope.githubAuthEnabled = config.githubAuthEnabled; diff --git a/src/app/controllers/search.js b/src/app/controllers/search.js index 96af8db9cce..6aa525b7f91 100644 --- a/src/app/controllers/search.js +++ b/src/app/controllers/search.js @@ -74,8 +74,8 @@ function (angular, _, config, $) { .then(function(results) { if (localSearchId < $scope.currentSearchId) { return; } - if ($scope.query.query === "") { - results.dashboards.splice(0, 1, { title: 'Home', url: config.appSubUrl + '/', isHome: true }); + if ($scope.query.query === "" && !$scope.query.starred) { + results.dashboards.unshift({ title: 'Home', url: config.appSubUrl + '/', isHome: true }); } $scope.results.dashboards = results.dashboards; diff --git a/src/app/controllers/sidemenuCtrl.js b/src/app/controllers/sidemenuCtrl.js index c267131ba27..cb5027d3dd2 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) { + module.controller('SideMenuCtrl', function($scope, $location, contextSrv) { $scope.getUrl = function(url) { return config.appSubUrl + url; @@ -22,7 +22,7 @@ function (angular, _, $, config) { href: $scope.getUrl("/"), }); - if ($scope.grafana.user.accountRole === 'Admin') { + if (contextSrv.hasRole('Admin')) { $scope.menu.push({ text: "Data Sources", icon: "fa fa-database", @@ -35,7 +35,7 @@ function (angular, _, $, config) { }); } - if ($scope.grafana.user.isGrafanaAdmin) { + if (contextSrv.user.isGrafanaAdmin) { $scope.menu.push({ text: "Admin", href: $scope.getUrl("/admin/users"), icon: "fa fa-cube", diff --git a/src/app/directives/dashEditLink.js b/src/app/directives/dashEditLink.js index 1c3e3b6826b..0933d3f96f2 100644 --- a/src/app/directives/dashEditLink.js +++ b/src/app/directives/dashEditLink.js @@ -56,8 +56,8 @@ function (angular, $) { function showEditorPane(evt, payload, editview) { if (editview) { - scope.grafana.editview = editViewMap[editview]; - payload.src = scope.grafana.editview.src; + scope.contextSrv.editview = editViewMap[editview]; + payload.src = scope.contextSrv.editview.src; } if (lastEditor === payload.src) { @@ -106,12 +106,12 @@ function (angular, $) { if (newValue) { showEditorPane(null, {}, newValue); } else if (oldValue) { - scope.grafana.editview = null; + scope.contextSrv.editview = null; hideEditorPane(); } }); - scope.grafana.editview = null; + scope.contextSrv.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 index 039269cf27b..fb9d8a82ed1 100644 --- a/src/app/directives/topnav.js +++ b/src/app/directives/topnav.js @@ -7,7 +7,7 @@ function (angular) { angular .module('grafana.directives') - .directive('topnav', function() { + .directive('topnav', function($rootScope, contextSrv) { return { restrict: 'E', transclude: true, @@ -15,8 +15,6 @@ function (angular) { title: "@", section: "@", titleAction: "&", - toggle: "&", - showMenuBtn: "=", subnav: "=", }, template: @@ -43,6 +41,11 @@ function (angular) { '
', link: function(scope, elem, attrs) { scope.icon = attrs.icon; + scope.showMenuBtn = !contextSrv.sidemenu; + + scope.toggle = function() { + $rootScope.appEvent('toggle-sidemenu'); + }; } }; }); diff --git a/src/app/features/account/partials/account.html b/src/app/features/account/partials/account.html index d05cb90b1e1..ef575b914ce 100644 --- a/src/app/features/account/partials/account.html +++ b/src/app/features/account/partials/account.html @@ -1,4 +1,4 @@ - +