Skip to content

Commit

Permalink
[chrome] use chromNavControls rather than a hard coded list
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Dec 18, 2015
1 parent e3ee17a commit 0fe1760
Show file tree
Hide file tree
Showing 15 changed files with 231 additions and 96 deletions.
1 change: 0 additions & 1 deletion src/plugins/kibana/public/discover/controllers/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ define(function (require) {
require('ui/doc_table');
require('ui/visualize');
require('ui/notify');
require('ui/timepicker');
require('ui/fixedScroll');
require('ui/directives/validate_json');
require('ui/filters/moment');
Expand Down
1 change: 1 addition & 0 deletions src/plugins/kibana/public/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ require('plugins/kibana/visualize/index');
require('plugins/kibana/dashboard/index');
require('plugins/kibana/settings/index');
require('plugins/kibana/doc/index');
require('ui/timepicker');

var moment = require('moment-timezone');

Expand Down
1 change: 1 addition & 0 deletions src/ui/UiExports.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class UiExports {
case 'visTypes':
case 'fieldFormats':
case 'spyModes':
case 'chromeNavControls':
return (plugin, spec) => {
this.aliases[type] = _.union(this.aliases[type] || [], spec);
};
Expand Down
2 changes: 1 addition & 1 deletion src/ui/autoload.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ exports.reload = function () {
'ui/stringify/register',
'ui/styleCompile',
'ui/timefilter',
'ui/timepicker',
'ui/timepicker', // TODO: remove this for 5.0
'ui/tooltip',
'ui/typeahead',
'ui/url',
Expand Down
73 changes: 73 additions & 0 deletions src/ui/public/chrome/__tests__/nav_controls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import ngMock from 'ngMock';
import $ from 'jquery';
import expect from 'expect.js';

import uiModules from 'ui/modules';
import chromeNavControlsRegistry from 'ui/registry/chrome_nav_controls';
import Registry from 'ui/registry/_registry';

describe('chrome nav controls', function () {
let compile;
let stubRegistry;

beforeEach(ngMock.module('kibana', function (PrivateProvider) {
stubRegistry = new Registry({
order: ['order']
});

PrivateProvider.swap(chromeNavControlsRegistry, stubRegistry);
}));

beforeEach(ngMock.inject(function ($compile, $rootScope) {
compile = function () {
const $el = $('<div kbn-chrome-append-nav-controls>');
$rootScope.$apply();
$compile($el)($rootScope);
return $el;
};
}));

it('injects templates from the ui/registry/chrome_nav_controls registry', function () {
stubRegistry.register(function () {
return {
name: 'control',
order: 100,
template: `<span id="testTemplateEl"></span>`
};
});

var $el = compile();
expect($el.find('#testTemplateEl')).to.have.length(1);
});

it('renders controls in order', function () {
stubRegistry.register(function () {
return {
name: 'control2',
order: 2,
template: `<span id="2", class="testControl"></span>`
};
});
stubRegistry.register(function () {
return {
name: 'control1',
order: 1,
template: `<span id="1", class="testControl"></span>`
};
});
stubRegistry.register(function () {
return {
name: 'control3',
order: 3,
template: `<span id="3", class="testControl"></span>`
};
});

var $el = compile();
expect(
$el.find('.testControl')
.toArray()
.map(el => el.id)
).to.eql(['1', '2', '3']);
});
});
55 changes: 3 additions & 52 deletions src/ui/public/chrome/api/angular.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
var $ = require('jquery');
var _ = require('lodash');

var modules = require('ui/modules');
var ConfigTemplate = require('ui/ConfigTemplate');
require('ui/directives/config');

module.exports = function (chrome, internals) {

chrome.setupAngular = function () {
var modules = require('ui/modules');
var kibana = modules.get('kibana');

_.forOwn(chrome.getInjected(), function (val, name) {
Expand All @@ -23,53 +20,7 @@ module.exports = function (chrome, internals) {
a.href = chrome.addBasePath('/elasticsearch');
return a.href;
}()))
.config(chrome.$setupXsrfRequestInterceptor)
.directive('kbnChrome', function ($rootScope) {
return {
template: function ($el) {
var $content = $(require('ui/chrome/chrome.html'));
var $app = $content.find('.application');

if (internals.rootController) {
$app.attr('ng-controller', internals.rootController);
}

if (internals.rootTemplate) {
$app.removeAttr('ng-view');
$app.html(internals.rootTemplate);
}

return $content;
},
controllerAs: 'chrome',
controller: function ($scope, $rootScope, $location, $http) {

// are we showing the embedded version of the chrome?
internals.setVisibleDefault(!$location.search().embed);

// listen for route changes, propogate to tabs
var onRouteChange = function () {
let { href } = window.location;
let persist = chrome.getVisible();
internals.trackPossibleSubUrl(href);
internals.tabs.consumeRouteUpdate(href, persist);
};

$rootScope.$on('$routeChangeSuccess', onRouteChange);
$rootScope.$on('$routeUpdate', onRouteChange);
onRouteChange();

// and some local values
$scope.httpActive = $http.pendingRequests;
$scope.notifList = require('ui/notify')._notifs;
$scope.appSwitcherTemplate = new ConfigTemplate({
switcher: '<app-switcher></app-switcher>'
});

return chrome;
}
};
});
.config(chrome.$setupXsrfRequestInterceptor);

require('../directives')(chrome, internals);

Expand Down
43 changes: 2 additions & 41 deletions src/ui/public/chrome/chrome.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<!-- /Mobile navbar -->

<!-- Full navbar -->
<div collapse="!showCollapsed" class="navbar-collapse">
<div collapse="!showCollapsed" class="navbar-collapse" kbn-chrome-append-nav-controls>
<ul class="nav navbar-nav" role="navigation">
<li
ng-if="chrome.getBrand('logo')"
Expand Down Expand Up @@ -52,50 +52,11 @@
</a>
</li>
</ul>

<ul ng-show="timefilter.enabled" class="nav navbar-nav navbar-right navbar-timepicker">
<li>
<a
ng-click="toggleRefresh()"
ng-show="timefilter.refreshInterval.value > 0">

<i class="fa" ng-class="timefilter.refreshInterval.pause ? 'fa-play' : 'fa-pause'"></i>
</a>
</li>

<li
ng-class="{active: pickerTemplate.is('interval') }"
ng-show="timefilter.refreshInterval.value > 0 || !!pickerTemplate.current"
class="to-body">

<a ng-click="pickerTemplate.toggle('interval')" class="navbar-timepicker-auto-refresh-desc">
<span ng-show="timefilter.refreshInterval.value === 0"><i class="fa fa-repeat"></i> Auto-refresh</span>
<span ng-show="timefilter.refreshInterval.value > 0">{{timefilter.refreshInterval.display}}</span>
</a>

</li>

<li class="to-body" ng-class="{active: pickerTemplate.is('filter')}">
<a
ng-click="pickerTemplate.toggle('filter')"
aria-haspopup="true"
aria-expanded="false"
class="navbar-timepicker-time-desc">
<i aria-hidden="true" class="fa fa-clock-o"></i>
<pretty-duration from="timefilter.time.from" to="timefilter.time.to"></pretty-duration>
</a>
</li>
</ul>

<ul class="nav navbar-nav navbar-right navbar-timepicker" >
<li ng-show="httpActive.length" class="navbar-text hidden-xs">
<div class="spinner"></div>
</li>
</ul>
</div>
<!-- /Full navbar -->
</nav>

<!-- TODO: These config dropdowns shouldn't be hard coded -->
<config
config-template="appSwitcherTemplate"
config-object="chrome"
Expand Down
1 change: 1 addition & 0 deletions src/ui/public/chrome/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ define(function (require) {

require('ui/modules')
.get('kibana')
// TODO: all of this really belongs in the timepicker
.directive('chromeContext', function (timefilter, globalState) {

var listenForUpdates = _.once(function ($scope) {
Expand Down
26 changes: 26 additions & 0 deletions src/ui/public/chrome/directives/append_nav_controls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import $ from 'jquery';

import chromeNavControlsRegistry from 'ui/registry/chrome_nav_controls';
import UiModules from 'ui/modules';

export default function (chrome, internals) {

UiModules
.get('kibana')
.directive('kbnChromeAppendNavControls', function (Private) {
return {
template: function ($element) {
const parts = [$element.html()];
const controls = Private(chromeNavControlsRegistry);

for (const control of controls.inOrder) {
parts.push(`<!-- nav control ${control.name} -->`);
parts.push(control.template);
}

return parts.join('\n');
}
};
});

}
6 changes: 5 additions & 1 deletion src/ui/public/chrome/directives/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'ui/directives/config';

import appSwitcherProv from './app_switcher';
import './app_switcher';
import kbnChromeProv from './kbn_chrome';
import kbnChromeNavControlsProv from './append_nav_controls';

export default function (chrome, internals) {
kbnChromeProv(chrome, internals);
kbnChromeNavControlsProv(chrome, internals);
}
58 changes: 58 additions & 0 deletions src/ui/public/chrome/directives/kbn_chrome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import $ from 'jquery';

import UiModules from 'ui/modules';
import ConfigTemplate from 'ui/ConfigTemplate';

export default function (chrome, internals) {

UiModules
.get('kibana')
.directive('kbnChrome', function ($rootScope) {
return {
template($el) {
const $content = $(require('ui/chrome/chrome.html'));
const $app = $content.find('.application');

if (internals.rootController) {
$app.attr('ng-controller', internals.rootController);
}

if (internals.rootTemplate) {
$app.removeAttr('ng-view');
$app.html(internals.rootTemplate);
}

return $content;
},

controllerAs: 'chrome',
controller($scope, $rootScope, $location, $http) {

// are we showing the embedded version of the chrome?
internals.setVisibleDefault(!$location.search().embed);

// listen for route changes, propogate to tabs
const onRouteChange = function () {
let { href } = window.location;
let persist = chrome.getVisible();
internals.trackPossibleSubUrl(href);
internals.tabs.consumeRouteUpdate(href, persist);
};

$rootScope.$on('$routeChangeSuccess', onRouteChange);
$rootScope.$on('$routeUpdate', onRouteChange);
onRouteChange();

// and some local values
$scope.httpActive = $http.pendingRequests;
$scope.notifList = require('ui/notify')._notifs;
$scope.appSwitcherTemplate = new ConfigTemplate({
switcher: '<app-switcher></app-switcher>'
});

return chrome;
}
};
});

}
6 changes: 6 additions & 0 deletions src/ui/public/registry/chrome_nav_controls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
define(function (require) {
return require('ui/registry/_registry')({
name: 'chromeNavControls',
order: ['order']
});
});
1 change: 1 addition & 0 deletions src/ui/public/timepicker/timepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define(function (require) {
require('ui/timepicker/quick_ranges');
require('ui/timepicker/refresh_intervals');
require('ui/timepicker/time_units');
require('ui/timepicker/toggle');

module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshIntervals) {
return {
Expand Down
37 changes: 37 additions & 0 deletions src/ui/public/timepicker/toggle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<ul
kbn-timpicker-toggle
ng-show="timefilter.enabled"
class="nav navbar-nav navbar-right navbar-timepicker">

<li>
<a
ng-click="toggleRefresh()"
ng-show="timefilter.refreshInterval.value > 0">

<i class="fa" ng-class="timefilter.refreshInterval.pause ? 'fa-play' : 'fa-pause'"></i>
</a>
</li>

<li
ng-class="{active: pickerTemplate.is('interval') }"
ng-show="timefilter.refreshInterval.value > 0 || !!pickerTemplate.current"
class="to-body">

<a ng-click="pickerTemplate.toggle('interval')" class="navbar-timepicker-auto-refresh-desc">
<span ng-show="timefilter.refreshInterval.value === 0"><i class="fa fa-repeat"></i> Auto-refresh</span>
<span ng-show="timefilter.refreshInterval.value > 0">{{timefilter.refreshInterval.display}}</span>
</a>

</li>

<li class="to-body" ng-class="{active: pickerTemplate.is('filter')}">
<a
ng-click="pickerTemplate.toggle('filter')"
aria-haspopup="true"
aria-expanded="false"
class="navbar-timepicker-time-desc">
<i aria-hidden="true" class="fa fa-clock-o"></i>
<pretty-duration from="timefilter.time.from" to="timefilter.time.to"></pretty-duration>
</a>
</li>
</ul>
Loading

0 comments on commit 0fe1760

Please sign in to comment.