mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
refactor change and changePath - reuse the same code
This commit is contained in:
parent
5662396d78
commit
3df2fb9183
1 changed files with 22 additions and 21 deletions
|
@ -10,6 +10,16 @@ define(function (require) {
|
|||
self.reloading = false;
|
||||
|
||||
self.change = function (url, paramObj, forceReload) {
|
||||
self._changeLocation('url', url, paramObj, forceReload);
|
||||
};
|
||||
|
||||
self.changePath = function (url, paramObj, forceReload) {
|
||||
self._changeLocation('path', url, paramObj, forceReload);
|
||||
};
|
||||
|
||||
self._changeLocation = function (type, url, paramObj, forceReload) {
|
||||
var doReload = false;
|
||||
|
||||
if (_.isBoolean(paramObj)) {
|
||||
forceReload = paramObj;
|
||||
paramObj = undefined;
|
||||
|
@ -17,30 +27,21 @@ define(function (require) {
|
|||
|
||||
url = self.eval(url, paramObj);
|
||||
|
||||
if (url !== $location.url()) {
|
||||
$location.url(globalState.writeToUrl(url));
|
||||
if (forceReload || !self.matches(url)) {
|
||||
self.reload();
|
||||
// path change
|
||||
if (type === 'path') {
|
||||
if (url !== $location.path()) {
|
||||
$location.path(globalState.writeToUrl(url));
|
||||
doReload = (!self.matches(url));
|
||||
}
|
||||
// default to url change
|
||||
} else {
|
||||
if (url !== $location.url()) {
|
||||
$location.url(globalState.writeToUrl(url));
|
||||
doReload = (!self.matches(url));
|
||||
}
|
||||
} else if (forceReload) {
|
||||
self.reload();
|
||||
}
|
||||
};
|
||||
|
||||
self.changePath = function (path, paramObj, forceReload) {
|
||||
if (_.isBoolean(paramObj)) {
|
||||
forceReload = paramObj;
|
||||
paramObj = undefined;
|
||||
}
|
||||
|
||||
path = self.eval(path, paramObj);
|
||||
|
||||
if (path !== $location.path()) {
|
||||
$location.path(globalState.writeToUrl(path));
|
||||
if (forceReload || !self.matches(path)) {
|
||||
self.reload();
|
||||
}
|
||||
} else if (forceReload) {
|
||||
if (forceReload || doReload) {
|
||||
self.reload();
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue