[chrome/appSwitcher] when navigating to an app, ensure the page reloads

This commit is contained in:
spalger 2015-09-21 14:37:53 -07:00
parent dfe8dcc7f0
commit 4d20063df3
3 changed files with 43 additions and 4 deletions

View file

@ -1,7 +1,7 @@
var $ = require('jquery');
var _ = require('lodash');
require('../appSwitcher/appSwitcher.less');
require('../appSwitcher');
var modules = require('ui/modules');
var ConfigTemplate = require('ui/ConfigTemplate');
require('ui/directives/config');

View file

@ -1,6 +1,12 @@
<div class="app-links">
<div class="app-link" ng-repeat="app in chrome.getNavLinks() | orderBy:'title'" ng-class="{ active: app.active }">
<a ng-href="{{ app.lastSubUrl || app.url }}">
<div app-switcher class="app-links">
<div
class="app-link"
ng-repeat="app in chrome.getNavLinks() | orderBy:'title'"
ng-class="{ active: app.active }">
<a
ng-click="switcher.ensureNavigation($event, app)"
ng-href="{{ app.active ? app.url : (app.lastSubUrl || app.url) }}">
<div ng-if="app.icon" ng-style="{ 'background-image': 'url(../' + app.icon + ')' }" class="app-icon"></div>
<div ng-if="!app.icon" class="app-icon app-icon-missing">{{app.title[0]}}</div>

View file

@ -0,0 +1,33 @@
var parse = require('url').parse;
require('../appSwitcher/appSwitcher.less');
require('ui/modules')
.get('kibana')
.directive('appSwitcher', function () {
return {
restrict: 'A',
controllerAs: 'switcher',
controller: function () {
// links don't cause full-navigation events in certain scenarios
// so we force them when needed
this.ensureNavigation = function (event, app) {
if (event.isDefaultPrevented() || event.altKey || event.metaKey || event.ctrlKey) {
return;
}
var toParsed = parse(app.url);
var fromParsed = parse(window.location.href);
var sameProto = toParsed.protocol === fromParsed.protocol;
var sameHost = toParsed.host === fromParsed.host;
var samePath = toParsed.path === fromParsed.path;
if (sameProto && sameHost && samePath) {
window.location.reload(true);
}
};
}
};
});