[kibana] rely on basePath rather than scattered relative paths

This commit is contained in:
spalger 2015-11-05 17:26:10 -06:00
parent 0e8d481902
commit 645272e225
9 changed files with 60 additions and 8 deletions

View file

@ -3,7 +3,7 @@
<div class="container-fluid">
<ul class="nav navbar-nav">
<li ng-repeat="section in sections" ng-class="section.class">
<a class="navbar-link" ng-href="{{section.url}}">{{section.display}}</a>
<a class="navbar-link" kbn-href="{{section.url}}">{{section.display}}</a>
</li>
</ul>
</div>

View file

@ -2,7 +2,7 @@
<div class="kbn-settings-about container" ng-controller="settingsAbout">
<div class="col-md-4 col-md-offset-4 jumbotron">
<center>
<img src='../plugins/kibana/settings/sections/about/barcode.svg' alt="Kibana Barcode Logo" width="128" height="128"><br>
<img kbn-src="/plugins/kibana/settings/sections/about/barcode.svg" alt="Kibana Barcode Logo" width="128" height="128"><br>
<h1>Kibana</h1>
<p>
<table class="table table-condensed kbn-settings-about-versions">

View file

@ -5,6 +5,6 @@ define(function (require) {
order: 3,
name: 'status',
display: 'Status',
url: '../status'
url: '/status'
};
});

View file

@ -5,7 +5,7 @@ var notify = require('ui/notify');
require('plugins/statusPage/statusPageMetric');
require('plugins/statusPage/statusPage.less');
require('ui/chrome')
var chrome = require('ui/chrome')
.setTabs([
{
id: '',
@ -23,7 +23,7 @@ require('ui/chrome')
// go ahead and get the info you want
return $http
.get('./api/status')
.get(chrome.addBasePath('/api/status'))
.then(function (resp) {
if (ui.fetchError) {

View file

@ -21,7 +21,7 @@ module.exports = function (chrome, internals) {
.value('sessionId', Date.now())
.value('esUrl', (function () {
var a = document.createElement('a');
a.href = '../elasticsearch';
a.href = chrome.addBasePath('/elasticsearch');
return a.href;
}()))
.directive('kbnChrome', function ($rootScope) {

View file

@ -1,6 +1,7 @@
module.exports = function (chrome, internals) {
const { startsWith } = require('lodash');
const { startsWith, isString } = require('lodash');
import { parse, format } from 'url';
export default function (chrome, internals) {
chrome.getNavLinks = function () {
return internals.nav;
};
@ -9,6 +10,30 @@ module.exports = function (chrome, internals) {
return internals.appUrlStore.getItem(`lastSubUrl:${url}`);
};
chrome.getBasePath = function () {
return internals.basePath || '';
};
chrome.addBasePath = function (url) {
var isUrl = url && isString(url);
if (!isUrl) return url;
var parsed = parse(url);
if (!parsed.host && parsed.pathname) {
if (parsed.pathname[0] === '/') {
parsed.pathname = chrome.getBasePath() + parsed.pathname;
}
}
return format({
protocol: parsed.protocol,
host: parsed.host,
pathname: parsed.pathname,
query: parsed.query,
hash: parsed.hash,
});
};
internals.trackPossibleSubUrl = function (url) {
for (const link of internals.nav) {
if (startsWith(url, link.url)) {

View file

@ -14,6 +14,7 @@ var chrome = {};
var internals = _.defaults(
_.cloneDeep(metadata),
{
basePath: '',
rootController: null,
rootTemplate: null,
showAppsLink: null,

View file

@ -0,0 +1,23 @@
import UiModules from 'ui/modules';
import chrome from 'ui/chrome';
import { words, camelCase, kebabCase } from 'lodash';
export function kbnUrlDirective(name) {
const srcAttr = kebabCase(name);
const attr = kebabCase(words(name).slice(1));
UiModules
.get('kibana')
.directive(name, function (Private) {
return {
restrict: 'A',
link: function ($scope, $el, $attr) {
$attr.$observe(name, function (val) {
$attr.$set(attr, chrome.addBasePath(val));
});
}
};
});
}
kbnUrlDirective('kbnHref');

View file

@ -0,0 +1,3 @@
import { kbnUrlDirective } from './kbnHref';
kbnUrlDirective('kbnSrc');