Commit b89480a2 by Torkel Ödegaard

refactored use of localStorage

parent 5846c710
......@@ -33,4 +33,4 @@ function () {
});
return _;
});
\ No newline at end of file
});
......@@ -8,6 +8,7 @@ require.config({
config: ['../config', '../config.sample'],
settings: 'components/settings',
kbn: 'components/kbn',
store: 'components/store',
css: '../vendor/require/css',
text: '../vendor/require/text',
......
define([], function() {
'use strict';
return {
get: function(key) {
return window.localStorage[key];
},
set: function(key, value) {
window.localStorage[key] = value;
},
getBool: function(key) {
return window.localStorage[key] === 'true' ? true : false;
},
delete: function(key) {
window.localStorage.removeItem(key);
}
};
});
......@@ -2,12 +2,13 @@ define([
'angular',
'lodash',
'moment',
'store'
],
function (angular, _, moment) {
function (angular, _, moment, store) {
'use strict';
var module = angular.module('grafana.controllers');
var consoleEnabled = window.localStorage && window.localStorage.grafanaConsole === 'true';
var consoleEnabled = store.getBool('grafanaConsole');
if (!consoleEnabled) {
return;
......
......@@ -3,9 +3,10 @@ define([
'lodash',
'moment',
'config',
'store',
'filesaver'
],
function (angular, _, moment, config) {
function (angular, _, moment, config, store) {
'use strict';
var module = angular.module('grafana.controllers');
......@@ -26,12 +27,12 @@ function (angular, _, moment, config) {
};
$scope.set_default = function() {
window.localStorage.grafanaDashboardDefault = $location.path();
store.set('grafanaDashboardDefault', $location.path());
alertSrv.set('Home Set','This page has been set as your default dashboard','success',5000);
};
$scope.purge_default = function() {
delete window.localStorage.grafanaDashboardDefault;
store.delete('grafanaDashboardDefault');
alertSrv.set('Local Default Clear','Your default dashboard has been reset to the default','success', 5000);
};
......
......@@ -3,8 +3,9 @@ define([
'config',
'lodash',
'jquery',
'store',
],
function (angular, config, _, $) {
function (angular, config, _, $, store) {
"use strict";
var module = angular.module('grafana.controllers');
......@@ -12,26 +13,23 @@ function (angular, config, _, $) {
module.controller('GrafanaCtrl', function($scope, alertSrv, grafanaVersion, $rootScope) {
$scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
$scope.consoleEnabled = (window.localStorage && window.localStorage.grafanaConsole === 'true');
$scope.consoleEnabled = store.getBool('grafanaConsole');
$rootScope.profilingEnabled = (window.localStorage && window.localStorage.profilingEnabled === 'true');
$rootScope.profilingEnabled = store.getBool('profilingEnabled');
$rootScope.performance = { loadStart: new Date().getTime() };
$scope.init = function() {
$scope._ = _;
if ($rootScope.profilingEnabled) {
$scope.initProfiling();
}
if ($rootScope.profilingEnabled) { $scope.initProfiling(); }
$scope.dashAlerts = alertSrv;
$scope.grafana = {
style: 'dark'
};
$scope.grafana = { style: 'dark' };
};
$scope.toggleConsole = function() {
$scope.consoleEnabled = !$scope.consoleEnabled;
window.localStorage.grafanaConsole = $scope.consoleEnabled ? 'true' : 'false';
store.set('grafanaConsole', $scope.consoleEnabled);
};
$rootScope.onAppEvent = function(name, callback) {
......
define([
'angular',
'config'
'config',
'store'
],
function (angular, config) {
function (angular, config, store) {
"use strict";
var module = angular.module('grafana.routes');
......@@ -11,12 +12,7 @@ function (angular, config) {
$routeProvider
.when('/', {
redirectTo: function() {
if (window.localStorage && window.localStorage.grafanaDashboardDefault) {
return window.localStorage.grafanaDashboardDefault;
}
else {
return config.default_route;
}
return store.get('grafanaDashboardDefault') || config.default_route;
}
});
});
......
define([
'angular',
'lodash',
'kbn'
'kbn',
'store'
],
function (angular, _, kbn) {
function (angular, _, kbn, store) {
'use strict';
var module = angular.module('grafana.services');
......@@ -13,14 +14,14 @@ function (angular, _, kbn) {
var favorites = { dashboards: [] };
this.init = function() {
var existingJson = window.localStorage["grafana-favorites"];
var existingJson = store.get("grafana-favorites");
if (existingJson) {
favorites = angular.fromJson(existingJson);
}
};
this._save = function() {
window.localStorage["grafana-favorites"] = angular.toJson(favorites);
store.set('grafana-favorites', angular.toJson(favorites));
};
this._find = function(title) {
......
......@@ -6,6 +6,7 @@ require.config({
mocks: '../test/mocks',
config: '../config.sample',
kbn: 'components/kbn',
store: 'components/store',
settings: 'components/settings',
lodash: 'components/lodash.extended',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment