diff --git a/src/plugins/kibana/public/dashboard/index.js b/src/plugins/kibana/public/dashboard/index.js index a0a1874bf5ecc..da6afb2160d28 100644 --- a/src/plugins/kibana/public/dashboard/index.js +++ b/src/plugins/kibana/public/dashboard/index.js @@ -2,7 +2,6 @@ import _ from 'lodash'; import $ from 'jquery'; import angular from 'angular'; import chrome from 'ui/chrome'; -import 'ui/directives/kbn_top_nav'; import 'ui/courier'; import 'ui/config'; import 'ui/notify'; diff --git a/src/ui/public/autoload/modules.js b/src/ui/public/autoload/modules.js index 32aef92c482e3..aae542cf95911 100644 --- a/src/ui/public/autoload/modules.js +++ b/src/ui/public/autoload/modules.js @@ -1,6 +1,7 @@ import 'angular'; import 'ui/chrome'; import 'ui/bind'; +import 'ui/kbn_top_nav'; import 'ui/bound_to_config_obj'; import 'ui/config'; import 'ui/courier'; diff --git a/src/ui/public/chrome/directives/index.js b/src/ui/public/chrome/directives/index.js index c553db6a1d837..c39bb921d3a5b 100644 --- a/src/ui/public/chrome/directives/index.js +++ b/src/ui/public/chrome/directives/index.js @@ -1,5 +1,3 @@ -import 'ui/directives/kbn_top_nav'; - import './app_switcher'; import kbnChromeProv from './kbn_chrome'; import kbnChromeNavControlsProv from './append_nav_controls'; diff --git a/src/ui/public/kbn_top_nav/kbn_top_nav.js b/src/ui/public/kbn_top_nav/kbn_top_nav.js index 6ca7d9ece5d46..4014377b994cf 100644 --- a/src/ui/public/kbn_top_nav/kbn_top_nav.js +++ b/src/ui/public/kbn_top_nav/kbn_top_nav.js @@ -3,126 +3,83 @@ import 'ui/watch_multi'; import angular from 'angular'; import 'ui/directives/input_focus'; import uiModules from 'ui/modules'; -var module = uiModules.get('kibana'); +import KbnTopNavControllerProvider from './kbn_top_nav_controller'; +const module = uiModules.get('kibana'); /** * kbnTopNav directive * * The top section that shows the timepicker, load, share and save dialogues. + * * ``` * * ``` + * + * Menu items/templates are passed to the kbnTopNav via the config attribute + * and should be defined as an array of objects. Each object represents a menu + * item and should have the following properties: + * + * @param {Array|KbnTopNavController} config + * @param {string} config[].key + * - the uniq key for this menu item. + * @param {string} [config[].label] + * - optional, string that will be displayed for the menu button. + * Defaults to the key + * @param {string} [config[].description] + * - optional, used for the screen-reader description of this menu + * item, defaults to "Toggle ${key} view" for templated menu items + * and just "${key}" for programatic menu items + * @param {boolean} [config[].hideButton] + * - optional, set to true to prevent a menu item from being created. + * This allow injecting templates into the navbar that don't have + * an associated template + * @param {function} [config[].run] + * - optional, function to call when the menu item is clicked, defaults + * to toggling the template + * + * Programatic control of the navbar can be acheived one of two ways */ - module.directive('kbnTopNav', function (Private) { - const filterTemplate = require('ui/chrome/config/filter.html'); - const intervalTemplate = require('ui/chrome/config/interval.html'); - function optionsNormalizer(defaultFunction, opt) { - if (!opt.key) { - return false; - } - return _.assign({ - label: _.capitalize(opt.key), - hasFunction: !!opt.run, - description: ('Toggle ' + opt.key), - noButton: !!opt.noButton, - run: defaultFunction - }, opt); - } - function getTemplatesMap(configs) { - const templateMap = {}; - configs.forEach(conf => { - if (conf.template) { - templateMap[conf.key] = conf.template; - } - }); - return templateMap; - } return { restrict: 'E', transclude: true, - template: function ($el, $attrs) { + template($el, $attrs) { // This is ugly // This is necessary because of navbar-extensions // It will no accept any programatic way of setting its name // besides this because it happens so early in the digest cycle return ` - -
-