Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/app switcher #4994

Merged
merged 16 commits into from
Sep 23, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions src/ui/public/chrome/api/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ module.exports = function (chrome, internals) {
a.setAttribute('href', link.url);
link.url = a.href;
link.lastSubUrl = chrome.getLastSubUrlFor(link.url);

if (link.url === chrome.getAppUrl()) {
link.active = true;
}
});

};
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'">
<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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a test

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to stop propagation here? I'm being sent to the href after reloading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call

}
};

}
};
});
14 changes: 12 additions & 2 deletions src/ui/public/chrome/appSwitcher/appSwitcher.less
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
@import (reference) "~ui/styles/variables";

@app-icon-size: 48px;
@app-icon-padding: 10px;

.app-links {
text-align: justify;

.app-link {
display: inline-block;
vertical-align: top;
width: @app-icon-size;
margin: 0px 10px;
text-align: left;
width: @app-icon-size + (@app-icon-padding * 2);
margin: 0px 10px;
padding: @app-icon-padding;
border-radius: @border-radius-base;

.app-icon {
display: block;
Expand Down Expand Up @@ -43,6 +46,13 @@
text-decoration: underline;
}

&.active {
background: @gray-lighter;
.app-title {
text-decoration: underline;
}
}

}

}