added a change method to the $route service

This commit is contained in:
Spencer Alger 2014-06-16 16:45:16 -07:00
parent 9c3765e3d4
commit 81e1426ed1
4 changed files with 35 additions and 8 deletions

View file

@ -1,6 +1,4 @@
define(function (require) {
// require('angular-ui-ace');
var module = require('modules').get('app/visualize');
module.directive('visualizeExtras', function (Private, $compile) {

View file

@ -27,8 +27,7 @@ define(function (require) {
if (!url) url = '/';
notify.error(err);
$location.url(globalState.writeToUrl(url));
$route.reload();
$route.changeUrl(globalState.writeToUrl(url));
return;
};
};

View file

@ -7,8 +7,7 @@ define(function (require) {
return function promiseHandler(patterns) {
if (!patterns || patterns.length === 0) {
notify.warning(new errors.NoDefinedIndexPatterns());
$location.path('/settings/indices');
$route.reload();
$route.change('/settings/indices');
}
return patterns;

View file

@ -8,6 +8,37 @@ define(function (require) {
require('setup/setup');
require('modules').get('kibana/controllers')
.config(function ($provide) {
$provide.decorator('$route', function ($delegate, $location, $rootScope) {
// flag tracking when we are waiting for a reload
var reloading;
var doneReloading = function () { reloading = false; };
$rootScope.$on('$routeUpdate', doneReloading);
$rootScope.$on('$routeChangeStart', doneReloading);
var reload = function () {
if (!reloading) $delegate.reload();
reloading = true;
};
$delegate.change = function (path) {
if (path !== $location.path()) {
$location.path(path); reload();
}
};
$delegate.changeUrl = function (url) {
if (url !== $location.url()) {
$location.url(url); reload();
}
};
return $delegate;
});
});
var setup = function ($q, kbnSetup, config) {
var prom = $q.all([
kbnSetup(),
@ -19,14 +50,14 @@ define(function (require) {
return prom;
};
var prepWork = function ($injector, config, $location, $route, Notifier) {
return $injector.invoke(setup)
.then(function () {
if ($location.path().indexOf('/settings/indices') !== 0 && !config.get('defaultIndex')) {
var notify = new Notifier();
notify.error('Please specify a default index pattern');
$location.path('/settings/indices');
$route.reload();
$route.change('/settings/indices');
}
});
};