Skip to content

Commit

Permalink
[chrome/appSwitcher] when navigating to an app, ensure the page reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Sep 21, 2015
1 parent dfe8dcc commit 4d20063
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ui/public/chrome/api/angular.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
12 changes: 9 additions & 3 deletions src/ui/public/chrome/appSwitcher/appSwitcher.html
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
33 changes: 33 additions & 0 deletions src/ui/public/chrome/appSwitcher/appSwitcher.js
Original file line number Diff line number Diff line change
@@ -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);
}
};

}
};
});

0 comments on commit 4d20063

Please sign in to comment.