diff --git a/src/app/routes/dashboard-from-db.js b/src/app/routes/dashboard-from-db.js
index d10de12939d..dfbcf3af3b1 100644
--- a/src/app/routes/dashboard-from-db.js
+++ b/src/app/routes/dashboard-from-db.js
@@ -30,13 +30,7 @@ function (angular) {
db.getDashboard($routeParams.id, isTemp)
.then(function(dashboard) {
-
- dashboard.$state = {
- panelId: parseInt($routeParams.panelId)
- };
-
$scope.emitAppEvent('setup-dashboard', dashboard);
-
}).then(null, function(error) {
alertSrv.set('Error', error, 'error');
});
diff --git a/src/app/services/dashboard/dashboardKeyBindings.js b/src/app/services/dashboard/dashboardKeyBindings.js
index 304e10ea5d3..ef245839233 100644
--- a/src/app/services/dashboard/dashboardKeyBindings.js
+++ b/src/app/services/dashboard/dashboardKeyBindings.js
@@ -12,16 +12,12 @@ function(angular, $) {
this.shortcuts = function(scope) {
- scope.onAppEvent('panel-fullscreen-enter', function() {
- $rootScope.fullscreen = true;
- });
-
scope.onAppEvent('panel-fullscreen-exit', function() {
- $rootScope.fullscreen = false;
+ scope.dashboardViewState.update({ fullscreen: false });
});
scope.onAppEvent('dashboard-saved', function() {
- if ($rootScope.fullscreen) {
+ if (scope.dashboardViewState.fullscreen) {
scope.emitAppEvent('panel-fullscreen-exit');
}
});
diff --git a/src/app/services/dashboard/dashboardSrv.js b/src/app/services/dashboard/dashboardSrv.js
index 865946ea86b..26c1c3b8f5b 100644
--- a/src/app/services/dashboard/dashboardSrv.js
+++ b/src/app/services/dashboard/dashboardSrv.js
@@ -10,7 +10,7 @@ function (angular, $, kbn, _) {
var module = angular.module('grafana.services');
- module.service('dashboardSrv', function(timer, $rootScope, $timeout) {
+ module.factory('dashboardSrv', function(timer, $rootScope, $timeout, $location) {
function DashboardModel (data) {
@@ -150,9 +150,35 @@ function (angular, $, kbn, _) {
this.version = 3;
};
+ // represents the transient view state
+ // like fullscreen panel & edit
+ function DashboardViewState() {
+ var queryParams = $location.search();
+ this.update({
+ panelId: parseInt(queryParams.panelId),
+ fullscreen: queryParams.fullscreen ? true : false,
+ edit: queryParams.edit ? true : false
+ });
+ }
+
+ DashboardViewState.prototype.update = function(state) {
+ _.extend(this, state);
+ if (!this.fullscreen) {
+ delete this.fullscreen;
+ delete this.panelId;
+ delete this.edit;
+ }
+ if (!this.edit) { delete this.edit; }
+
+ $location.search(this);
+ };
+
return {
create: function(dashboard) {
return new DashboardModel(dashboard);
+ },
+ createViewState: function(state) {
+ return new DashboardViewState(state);
}
};
diff --git a/src/app/services/panelSrv.js b/src/app/services/panelSrv.js
index c4d18fdd2e8..8ea70df999f 100644
--- a/src/app/services/panelSrv.js
+++ b/src/app/services/panelSrv.js
@@ -7,7 +7,7 @@ function (angular, _, $) {
'use strict';
var module = angular.module('grafana.services');
- module.service('panelSrv', function($rootScope, $timeout, datasourceSrv, $location) {
+ module.service('panelSrv', function($rootScope, $timeout, datasourceSrv) {
this.init = function($scope) {
if (!$scope.panel.span) {
@@ -101,12 +101,11 @@ function (angular, _, $) {
$(window).scrollTop(0);
+ $scope.dashboardViewState.update({ fullscreen: true, edit: $scope.editMode, panelId: $scope.panel.id });
+
$scope.fullscreen = true;
- $rootScope.$emit('panel-fullscreen-enter');
-
$timeout(function() {
- $location.search({panelId: $scope.panel.id, mode: $scope.editMode ? 'edit' : 'full' });
$scope.$emit('render');
});
@@ -155,7 +154,7 @@ function (angular, _, $) {
};
$scope.otherPanelInFullscreenMode = function() {
- return $rootScope.fullscreen && !$scope.fullscreen;
+ return $scope.dashboardViewState.fullscreen && !$scope.fullscreen;
};
// Post init phase
@@ -168,9 +167,9 @@ function (angular, _, $) {
$scope.datasources = datasourceSrv.getMetricSources();
$scope.setDatasource($scope.panel.datasource);
-// if ($scope.dashboard.$state.panelId === $scope.panel.id) {
-// $scope.enterFullscreenMode({edit: false});
-// }
+ if ($scope.dashboardViewState.panelId === $scope.panel.id) {
+ $scope.enterFullscreenMode({edit: $scope.dashboardViewState.edit});
+ }
if ($scope.get_data) {
var panel_get_data = $scope.get_data;
diff --git a/src/index.html b/src/index.html
index 3d9d95ed484..8c5c8ff5c91 100644
--- a/src/index.html
+++ b/src/index.html
@@ -27,7 +27,7 @@
{{alert.title}} {{$index + 1}} alert(s)