From cd4fc78aec101ff2b55db846ea6bc9456a1b6b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 21 Jan 2015 16:29:04 +0100 Subject: [PATCH] trying to get dashboard settings, annotations and templating views be opened via url parameters --- src/app/controllers/sidemenuCtrl.js | 36 +++++++++++++++---- src/app/directives/dashEditLink.js | 21 +++++++++-- .../features/account/partials/apikeys.html | 2 +- .../account/partials/datasources.html | 2 +- src/app/features/account/partials/users.html | 2 +- src/app/features/dashboard/viewStateSrv.js | 5 +++ src/app/partials/sidemenu.html | 29 ++------------- 7 files changed, 59 insertions(+), 38 deletions(-) diff --git a/src/app/controllers/sidemenuCtrl.js b/src/app/controllers/sidemenuCtrl.js index 63edb5c5af9..89d1b308428 100644 --- a/src/app/controllers/sidemenuCtrl.js +++ b/src/app/controllers/sidemenuCtrl.js @@ -1,8 +1,9 @@ define([ 'angular', 'lodash', + 'jquery', ], -function (angular, _) { +function (angular, _, $) { 'use strict'; var module = angular.module('grafana.controllers'); @@ -13,11 +14,12 @@ function (angular, _) { { text: "Dashbord", href: "/", + startsWith: '/dashboard/', icon: "fa fa-th-large", links: [ - { text: 'Settings', href:"asd", icon: "fa fa-cogs" }, - { text: 'Templating', href:"asd", icon: "fa fa-cogs" }, - { text: 'Annotations', href:"asd", icon: "fa fa-bolt" }, + { text: 'Settings', editview: 'settings', icon: "fa fa-cogs" }, + { text: 'Templating', editview: 'templating', icon: "fa fa-cogs" }, + { text: 'Annotations', editview: 'annotations', icon: "fa fa-bolt" }, { text: 'More', href:"asd", icon: "fa fa-bolt" }, ] }, @@ -26,8 +28,8 @@ function (angular, _) { icon: "fa fa-shield", links: [ { text: 'Data sources', href:"/account/datasources", icon: "fa fa-sitemap" }, - { text: 'Users', href:"/account/datasources", icon: "fa fa-users" }, - { text: 'API Keys', href:"/account/datasources", icon: "fa fa-key" }, + { text: 'Users', href:"/account/users", icon: "fa fa-users" }, + { text: 'API Keys', href:"/account/apikeys", icon: "fa fa-key" }, ] }, { @@ -39,12 +41,18 @@ function (angular, _) { } ]; + $scope.onAppEvent('$routeUpdate', function() { + $scope.updateState(); + }); + $scope.onAppEvent('$routeChangeSuccess', function() { $scope.updateState(); }); $scope.updateState = function() { var currentPath = $location.path(); + var search = $location.search(); + _.each($scope.menu, function(item) { item.active = false; @@ -52,9 +60,25 @@ function (angular, _) { item.active = true; } + if (item.startsWith) { + if (currentPath.indexOf(item.startsWith) === 0) { + item.active = true; + } + } + _.each(item.links, function(link) { link.active = false; + if (link.editview) { + var params = {}; + _.each(search, function(value, key) { + if (value !== null) { params[key] = value; } + }); + + params.editview = link.editview; + link.href = currentPath + '?' + $.param(params); + } + if (link.href === currentPath) { item.active = true; link.active = true; diff --git a/src/app/directives/dashEditLink.js b/src/app/directives/dashEditLink.js index b0ac97d3423..263982d3258 100644 --- a/src/app/directives/dashEditLink.js +++ b/src/app/directives/dashEditLink.js @@ -5,6 +5,12 @@ define([ function (angular, $) { 'use strict'; + var editViewMap = { + 'settings': 'app/partials/dasheditor.html', + 'annotations': 'app/features/annotations/partials/editor.html', + 'templating': 'app/partials/templating_editor.html', + }; + angular .module('grafana.directives') .directive('dashEditorLink', function($timeout) { @@ -25,7 +31,7 @@ function (angular, $) { angular .module('grafana.directives') - .directive('dashEditorView', function($compile) { + .directive('dashEditorView', function($compile, $location) { return { restrict: 'A', link: function(scope, elem) { @@ -48,10 +54,13 @@ function (angular, $) { if (editorScope) { editorScope.dismiss(); } } - scope.onAppEvent("dashboard-loaded", hideEditorPane); scope.onAppEvent('hide-dash-editor', hideEditorPane); scope.onAppEvent('show-dash-editor', function(evt, payload) { + if (payload.editview) { + payload.src = editViewMap[payload.editview]; + } + if (lastEditor === payload.src) { hideEditorPane(); return; @@ -70,6 +79,14 @@ function (angular, $) { lastEditor = null; editorScope = null; hideScrollbars(false); + + if (payload.editview) { + var urlParams = $location.search(); + if (payload.editview === urlParams.editview) { + delete urlParams.editview; + $location.search(urlParams); + } + } }; // hide page scrollbars while edit pane is visible diff --git a/src/app/features/account/partials/apikeys.html b/src/app/features/account/partials/apikeys.html index f286360a811..489cd85c743 100644 --- a/src/app/features/account/partials/apikeys.html +++ b/src/app/features/account/partials/apikeys.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/app/features/account/partials/datasources.html b/src/app/features/account/partials/datasources.html index 4f5f2399d98..c936125aa37 100644 --- a/src/app/features/account/partials/datasources.html +++ b/src/app/features/account/partials/datasources.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/app/features/account/partials/users.html b/src/app/features/account/partials/users.html index dc6becf45b6..9b54b33fea8 100644 --- a/src/app/features/account/partials/users.html +++ b/src/app/features/account/partials/users.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/app/features/dashboard/viewStateSrv.js b/src/app/features/dashboard/viewStateSrv.js index c08d3cdba6b..2928e0800e9 100644 --- a/src/app/features/dashboard/viewStateSrv.js +++ b/src/app/features/dashboard/viewStateSrv.js @@ -81,6 +81,11 @@ function (angular, _, $) { }; DashboardViewState.prototype.syncState = function() { + if (this.state.editview) { + this.$scope.appEvent('show-dash-editor', { scope: this.$scope, editview: this.state.editview }); + return; + } + if (this.panelScopes.length === 0) { return; } if (this.fullscreen) { diff --git a/src/app/partials/sidemenu.html b/src/app/partials/sidemenu.html index f45622cfa6f..3983742497e 100644 --- a/src/app/partials/sidemenu.html +++ b/src/app/partials/sidemenu.html @@ -8,7 +8,7 @@
-
- - - - - - - - - - - - - - - - - - - - - - - - +
Admin @@ -62,7 +38,6 @@ Sign out -