mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[state_management] stop writing globalState to the url
This commit is contained in:
parent
4c8a49bc64
commit
4d83fea7b5
9 changed files with 19 additions and 17 deletions
|
@ -75,7 +75,7 @@ define(function (require) {
|
|||
|
||||
timefilter.enabled = true;
|
||||
$scope.timefilter = timefilter;
|
||||
$scope.$watchCollection('globalState.time', $scope.refresh);
|
||||
$scope.$listen(timefilter, 'update', $scope.refresh);
|
||||
|
||||
courier.setRootSearchSource(dash.searchSource);
|
||||
|
||||
|
|
|
@ -151,8 +151,7 @@ define(function (require) {
|
|||
segment: [agg],
|
||||
group: [],
|
||||
split: [],
|
||||
}),
|
||||
_g: globalState.toRISON()
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ define(function (require) {
|
|||
});
|
||||
|
||||
app.controller('discover', function ($scope, config, courier, $route, $window, $q, savedSearches, savedVisualizations,
|
||||
Notifier, $location, globalState, AppState, timefilter, Promise, Private, kbnUrl) {
|
||||
Notifier, $location, AppState, timefilter, Promise, Private, kbnUrl) {
|
||||
|
||||
var Vis = Private(require('components/vis/vis'));
|
||||
var SegmentedFetch = Private(require('apps/discover/_segmented_fetch'));
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
define(function (require) {
|
||||
var errors = require('errors');
|
||||
|
||||
return function RedirectWhenMissingFn($location, kbnUrl, globalState, Notifier) {
|
||||
return function RedirectWhenMissingFn($location, kbnUrl, Notifier) {
|
||||
var SavedObjectNotFound = errors.SavedObjectNotFound;
|
||||
|
||||
var notify = new Notifier();
|
||||
|
|
|
@ -17,8 +17,8 @@ define(function (require) {
|
|||
// if the url param is missing, write it back
|
||||
GlobalState.prototype._persistAcrossApps = true;
|
||||
|
||||
GlobalState.prototype.writeToUrl = function (url) {
|
||||
return qs.replaceParamInUrl(url, this._urlParam, this.toRISON());
|
||||
GlobalState.prototype.removeFromUrl = function (url) {
|
||||
return qs.replaceParamInUrl(url, this._urlParam, null);
|
||||
};
|
||||
|
||||
return new GlobalState();
|
||||
|
|
|
@ -30,13 +30,13 @@ define(function (require) {
|
|||
// path change
|
||||
if (type === 'path') {
|
||||
if (url !== $location.path()) {
|
||||
$location.path(globalState.writeToUrl(url));
|
||||
$location.path(globalState.removeFromUrl(url));
|
||||
doReload = (!self.matches(url));
|
||||
}
|
||||
// default to url change
|
||||
} else {
|
||||
if (url !== $location.url()) {
|
||||
$location.url(globalState.writeToUrl(url));
|
||||
$location.url(globalState.removeFromUrl(url));
|
||||
doReload = (!self.matches(url));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,9 +79,7 @@ define(function (require) {
|
|||
var notify = new Notifier();
|
||||
|
||||
$scope.appEmbedded = $location.search().embed;
|
||||
|
||||
$scope.httpActive = $http.pendingRequests;
|
||||
|
||||
window.$kibanaInjector = $injector;
|
||||
|
||||
// this is the only way to handle uncaught route.resolve errors
|
||||
|
@ -118,8 +116,10 @@ define(function (require) {
|
|||
var route = $location.path().split(/\//);
|
||||
var app = _.find($scope.apps, {id: route[1]});
|
||||
|
||||
if (!app) return;
|
||||
|
||||
// Record the last URL w/ state of the app, use for tab.
|
||||
lastPathFor(app, $location.url());
|
||||
lastPathFor(app, globalState.removeFromUrl($location.url()));
|
||||
|
||||
// Set class of container to application-<appId>
|
||||
$scope.activeApp = route ? route[1] : null;
|
||||
|
@ -130,20 +130,18 @@ define(function (require) {
|
|||
|
||||
var writeGlobalStateToLastPaths = function () {
|
||||
var currentUrl = $location.url();
|
||||
var _g = globalState.toRISON();
|
||||
|
||||
$scope.apps.forEach(function (app) {
|
||||
var url = lastPathFor(app);
|
||||
if (!url || url === currentUrl) return;
|
||||
|
||||
lastPathFor(app, qs.replaceParamInUrl(url, '_g', _g));
|
||||
lastPathFor(app, globalState.replaceParamInUrl(url));
|
||||
});
|
||||
};
|
||||
|
||||
$scope.$listen(timefilter, 'update', function (newVal, oldVal) {
|
||||
globalState.time = _.clone(timefilter.time);
|
||||
globalState.save();
|
||||
writeGlobalStateToLastPaths();
|
||||
});
|
||||
|
||||
$scope.$on('application.load', function () {
|
||||
|
|
|
@ -111,7 +111,12 @@ define(function (require) {
|
|||
qs.replaceParamInUrl = function (url, param, newVal) {
|
||||
var loc = qs.findInUrl(url);
|
||||
var parsed = qs.decode(url.substring(loc.start + 1, loc.end));
|
||||
parsed[param] = newVal;
|
||||
|
||||
if (newVal != null) {
|
||||
parsed[param] = newVal;
|
||||
} else {
|
||||
delete parsed[param];
|
||||
}
|
||||
|
||||
var chars = url.split('');
|
||||
chars.splice(loc.start, loc.end - loc.start, '?' + qs.encode(parsed));
|
||||
|
|
|
@ -16,7 +16,7 @@ define(function (require) {
|
|||
|
||||
function init() {
|
||||
globalStateMock = {
|
||||
writeToUrl: function (url) {
|
||||
removeFromUrl: function (url) {
|
||||
return url;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue