mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
eschew class syntax, add template parsing, internalize reloading state, add auto-reloading, add force reloading, remove changePath, include service in kibana
This commit is contained in:
parent
c6492905b0
commit
adca72a769
2 changed files with 32 additions and 20 deletions
|
@ -1,27 +1,30 @@
|
|||
define(function (require) {
|
||||
var _ = require('lodash');
|
||||
var location = require('modules').get('kibana/url');
|
||||
|
||||
location.service('kbnUrl', function ($route, $location, $rootScope, globalState) {
|
||||
var reloading = false;
|
||||
var self = this;
|
||||
self.reloading = false;
|
||||
|
||||
function KbnUrl() {
|
||||
}
|
||||
|
||||
KbnUrl.prototype.changePath = function (path) {
|
||||
if (path !== $location.path()) {
|
||||
$location.path(globalState.writeToUrl(path));
|
||||
reload();
|
||||
self.change = function (url, paramObj, forceReload) {
|
||||
if (!_.isBoolean(paramObj)) {
|
||||
forceReload = paramObj;
|
||||
paramObj = undefined;
|
||||
}
|
||||
|
||||
if (_.isObject(paramObj)) {
|
||||
url = parseUrlPrams(url, paramObj);
|
||||
}
|
||||
};
|
||||
|
||||
KbnUrl.prototype.change = function (url) {
|
||||
if (url !== $location.url()) {
|
||||
$location.url(globalState.writeToUrl(url));
|
||||
reload();
|
||||
if (forceReload) {
|
||||
reload();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
KbnUrl.prototype.matches = function (url) {
|
||||
self.matches = function (url) {
|
||||
var route = $route.current.$$route;
|
||||
if (!route || !route.regexp) return null;
|
||||
return route.regexp.test(url);
|
||||
|
@ -30,15 +33,23 @@ define(function (require) {
|
|||
$rootScope.$on('$routeUpdate', reloadingComplete);
|
||||
$rootScope.$on('$routeChangeStart', reloadingComplete);
|
||||
|
||||
function parseUrlPrams(url, paramObj) {
|
||||
return url.replace(/\{([^\}]+)\}/g, function (match, key) {
|
||||
if (_.isUndefined(paramObj[key])) {
|
||||
throw new Error('Replacement failed, key not found: ' + key);
|
||||
}
|
||||
|
||||
return paramObj[key];
|
||||
});
|
||||
}
|
||||
|
||||
function reload() {
|
||||
if (!reloading) $route.reload();
|
||||
reloading = true;
|
||||
if (!self.reloading) $route.reload();
|
||||
self.reloading = true;
|
||||
}
|
||||
|
||||
function reloadingComplete() {
|
||||
reloading = false;
|
||||
self.reloading = false;
|
||||
}
|
||||
|
||||
return new KbnUrl();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,11 +8,12 @@ define(function (require) {
|
|||
|
||||
require('components/config/config');
|
||||
require('components/courier/courier');
|
||||
require('components/notify/notify');
|
||||
require('components/state_management/app_state_factory');
|
||||
require('components/filter_bar/filter_bar');
|
||||
require('components/storage/storage');
|
||||
require('components/notify/notify');
|
||||
require('components/persisted_log/persisted_log');
|
||||
require('components/state_management/app_state_factory');
|
||||
require('components/storage/storage');
|
||||
require('components/url/url');
|
||||
require('directives/click_focus');
|
||||
require('directives/info');
|
||||
require('directives/spinner');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue