Merge pull request #4627 from spalger/implement/injectVars
Implement/inject vars
This commit is contained in:
commit
87a37d304f
|
@ -13,7 +13,8 @@
|
|||
"private": false,
|
||||
"version": "4.2.0-snapshot",
|
||||
"build": {
|
||||
"num": 8095
|
||||
"number": 8173,
|
||||
"sha": "0102888deb393e4141369fbd1644a5d77f8732da"
|
||||
},
|
||||
"main": "src/server/KbnServer.js",
|
||||
"homepage": "https://www.elastic.co/products/kibana",
|
||||
|
@ -131,7 +132,6 @@
|
|||
"grunt-contrib-copy": "^0.8.0",
|
||||
"grunt-esvm": "^1.1.3",
|
||||
"grunt-karma": "^0.12.0",
|
||||
"grunt-replace": "^0.7.9",
|
||||
"grunt-run": "spalger/grunt-run#master",
|
||||
"grunt-s3": "^0.2.0-alpha.3",
|
||||
"grunt-simple-mocha": "^0.4.0",
|
||||
|
|
|
@ -34,9 +34,12 @@ module.exports = function (kibana) {
|
|||
'leaflet'
|
||||
),
|
||||
|
||||
constants: function (server, options) {
|
||||
injectVars: function (server, options) {
|
||||
let config = server.config();
|
||||
|
||||
return {
|
||||
defaultAppId: options.defaultAppId
|
||||
kbnIndex: config.get('kibana.index'),
|
||||
esShardTimeout: config.get('elasticsearch.shardTimeout')
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,18 @@ require('plugins/kibana/dashboard/index');
|
|||
require('plugins/kibana/settings/index');
|
||||
require('plugins/kibana/doc/index');
|
||||
|
||||
var chrome = require('ui/chrome');
|
||||
var routes = require('ui/routes');
|
||||
var modules = require('ui/modules');
|
||||
|
||||
var kibanaLogoUrl = require('ui/images/kibana.png');
|
||||
|
||||
require('ui/routes')
|
||||
routes
|
||||
.otherwise({
|
||||
redirectTo: '/discover'
|
||||
});
|
||||
|
||||
require('ui/chrome')
|
||||
chrome
|
||||
.setBrand({
|
||||
'logo': 'url(' + kibanaLogoUrl + ') left no-repeat',
|
||||
'smallLogo': 'url(' + kibanaLogoUrl + ') left no-repeat'
|
||||
|
@ -49,3 +53,4 @@ require('ui/chrome')
|
|||
courier.start();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
<tr>
|
||||
<td>Commit SHA</td>
|
||||
<td>{{commitSha | limitTo:7}}</td>
|
||||
<td>{{buildSha | limitTo:7}}</td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
|
|
|
@ -7,10 +7,10 @@ define(function (require) {
|
|||
});
|
||||
|
||||
require('ui/modules').get('apps/settings')
|
||||
.controller('settingsAbout', function ($scope, kbnVersion, buildNum, commitSha) {
|
||||
.controller('settingsAbout', function ($scope, kbnVersion, buildNum, buildSha) {
|
||||
$scope.kbnVersion = kbnVersion;
|
||||
$scope.buildNum = buildNum;
|
||||
$scope.commitSha = commitSha;
|
||||
$scope.buildSha = buildSha;
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
module.exports = require('lodash').template(
|
||||
`
|
||||
/**
|
||||
* Optimized application entry file
|
||||
* Test entry file
|
||||
*
|
||||
* This is programatically created and updated, do not modify
|
||||
*
|
||||
|
@ -19,6 +19,13 @@ env.pluginInfo.sort().forEach(function (plugin, i) {
|
|||
*
|
||||
*/
|
||||
|
||||
window.__KBN__ = {
|
||||
vars: {
|
||||
kbnIndex: '.kibana',
|
||||
esShardTimeout: 1500
|
||||
}
|
||||
};
|
||||
|
||||
require('ui/testHarness');
|
||||
<%
|
||||
|
||||
|
|
|
@ -58,18 +58,22 @@ module.exports = class Config {
|
|||
if (_.isObject(env)) env = env.name;
|
||||
if (!env) env = process.env.NODE_ENV || 'production';
|
||||
|
||||
let dev = env === 'development';
|
||||
let prod = env === 'production';
|
||||
|
||||
// pass the environment as context so that it can be refed in config
|
||||
let context = {
|
||||
env: env,
|
||||
prod: env === 'production',
|
||||
dev: env === 'development',
|
||||
notProd: env !== 'production',
|
||||
notDev: env !== 'development',
|
||||
prod: prod,
|
||||
dev: dev,
|
||||
notProd: !prod,
|
||||
notDev: !dev,
|
||||
version: _.get(pkg, 'version'),
|
||||
buildNum: env === 'development' ? Math.pow(2, 53) - 1 : _.get(pkg, 'build.num', NaN)
|
||||
buildNum: dev ? Math.pow(2, 53) - 1 : _.get(pkg, 'build.number', NaN),
|
||||
buildSha: dev ? 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' : _.get(pkg, 'build.sha', '')
|
||||
};
|
||||
|
||||
if (!context.dev && !context.prod && !context.test) {
|
||||
if (!context.dev && !context.prod) {
|
||||
throw new TypeError(
|
||||
`Unexpected environment "${env}", expected one of "development" or "production"`
|
||||
);
|
||||
|
|
|
@ -9,7 +9,8 @@ let fromRoot = utils('fromRoot');
|
|||
module.exports = Joi.object({
|
||||
pkg: Joi.object({
|
||||
version: Joi.string().default(Joi.ref('$version')),
|
||||
buildNum: Joi.number().default(Joi.ref('$buildNum'))
|
||||
buildNum: Joi.number().default(Joi.ref('$buildNum')),
|
||||
buildSha: Joi.string().default(Joi.ref('$buildSha')),
|
||||
}).default(),
|
||||
|
||||
env: Joi.object({
|
||||
|
|
|
@ -47,6 +47,12 @@ module.exports = class Plugin {
|
|||
let register = (server, options, next) => {
|
||||
this.server = server;
|
||||
|
||||
// bind the server and options to all
|
||||
// apps created by this plugin
|
||||
for (let app of this.apps) {
|
||||
app.getInjectedVars = _.partial(app.getInjectedVars, server, options);
|
||||
}
|
||||
|
||||
server.log(['plugins', 'debug'], {
|
||||
tmpl: 'Initializing plugin <%= plugin.id %>',
|
||||
plugin: this
|
||||
|
|
|
@ -19,7 +19,12 @@ class UiApp {
|
|||
this.hidden = this.spec.hidden;
|
||||
this.autoloadOverrides = this.spec.autoload;
|
||||
this.templateName = this.spec.templateName || 'uiApp';
|
||||
|
||||
// once this resolves, no reason to run it again
|
||||
this.getModules = _.once(this.getModules);
|
||||
|
||||
// variables that are injected into the browser, must serialize to JSON
|
||||
this.getInjectedVars = this.spec.injectVars || _.noop;
|
||||
}
|
||||
|
||||
getModules() {
|
||||
|
|
|
@ -13,6 +13,8 @@ class UiExports {
|
|||
}
|
||||
|
||||
consumePlugin(plugin) {
|
||||
plugin.apps = new UiAppCollection(this);
|
||||
|
||||
var types = _.keys(plugin.uiExportsSpecs);
|
||||
if (!types) return false;
|
||||
|
||||
|
@ -46,7 +48,8 @@ class UiExports {
|
|||
case 'apps':
|
||||
return (plugin, specs) => {
|
||||
for (let spec of [].concat(specs || [])) {
|
||||
this.apps.new(_.defaults({}, spec, { id: plugin.id }));
|
||||
let app = this.apps.new(_.defaults({}, spec, { id: plugin.id }));
|
||||
plugin.apps.add(app);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -81,18 +81,15 @@ module.exports = async (kbnServer, server, config) => {
|
|||
app: app,
|
||||
appCount: uiExports.apps.size,
|
||||
version: kbnServer.version,
|
||||
buildSha: _.get(kbnServer, 'build.sha', '@@buildSha'),
|
||||
buildNumber: _.get(kbnServer, 'build.number', '@@buildNum'),
|
||||
cacheBust: _.get(kbnServer, 'build.number', ''),
|
||||
kbnIndex: config.get('kibana.index'),
|
||||
esShardTimeout: config.get('elasticsearch.shardTimeout'),
|
||||
buildNum: config.get('pkg.buildNum'),
|
||||
buildSha: config.get('pkg.buildSha'),
|
||||
vars: app.getInjectedVars()
|
||||
};
|
||||
|
||||
return this.view(app.templateName, {
|
||||
app: app,
|
||||
cacheBust: payload.cacheBust,
|
||||
kibanaPayload: payload,
|
||||
loadingGif: loadingGif,
|
||||
kibanaPayload: payload
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
24
src/ui/public/chrome/api/angular.js
vendored
24
src/ui/public/chrome/api/angular.js
vendored
|
@ -6,22 +6,20 @@ module.exports = function (chrome, internals) {
|
|||
chrome.setupAngular = function () {
|
||||
var kibana = modules.get('kibana');
|
||||
|
||||
var esUrl = (function () {
|
||||
_.forOwn(chrome.getInjected(), function (val, name) {
|
||||
kibana.value(name, val);
|
||||
});
|
||||
|
||||
kibana
|
||||
.value('kbnVersion', internals.version)
|
||||
.value('buildNum', internals.buildNum)
|
||||
.value('buildSha', internals.buildSha)
|
||||
.value('sessionId', Date.now())
|
||||
.value('esUrl', (function () {
|
||||
var a = document.createElement('a');
|
||||
a.href = '/elasticsearch';
|
||||
return a.href;
|
||||
}());
|
||||
|
||||
kibana
|
||||
.constant('kbnVersion', internals.version)
|
||||
.constant('buildNum', internals.buildNumber)
|
||||
.constant('kbnIndex', internals.kbnIndex)
|
||||
.constant('esShardTimeout', internals.esShardTimeout)
|
||||
.constant('esUrl', esUrl)
|
||||
.constant('commitSha', internals.buildSha)
|
||||
.constant('cacheBust', internals.cacheBust)
|
||||
.constant('minimumElasticsearchVersion', '2.0.0')
|
||||
.constant('sessionId', Date.now())
|
||||
}()))
|
||||
.directive('kbnChrome', function ($rootScope) {
|
||||
return {
|
||||
compile: function ($el) {
|
||||
|
|
|
@ -31,4 +31,9 @@ module.exports = function (chrome, internals) {
|
|||
return internals.app.id;
|
||||
};
|
||||
|
||||
chrome.getInjected = function (name, def) {
|
||||
if (name == null) return _.clone(internals.vars) || {};
|
||||
return _.get(internals.vars, name, def);
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
module.exports = function (grunt) {
|
||||
var { join } = require('path');
|
||||
|
||||
var build = grunt.config.get('build');
|
||||
var src = grunt.config.get('src');
|
||||
var app = grunt.config.get('app');
|
||||
|
||||
var config = {
|
||||
options: {
|
||||
patterns: [
|
||||
{ match: 'version', replacement: '<%= pkg.version %>' },
|
||||
{ match: 'buildNum', replacement: '<%= buildNum %>' },
|
||||
{ match: 'commitSha', replacement: '<%= commitSha %>' }
|
||||
]
|
||||
},
|
||||
dist: {
|
||||
files: [
|
||||
{
|
||||
src: [join(src, 'server', 'bin', 'kibana.sh')],
|
||||
dest: join(build, 'dist', 'kibana', 'bin', 'kibana'),
|
||||
mode: parseInt('0755', 8)
|
||||
},
|
||||
{
|
||||
src: [join(src, 'server', 'bin', 'kibana.bat')],
|
||||
dest: join(build, 'dist', 'kibana', 'bin', 'kibana.bat')
|
||||
},
|
||||
{
|
||||
src: [join(src, 'server', 'config', 'index.js')],
|
||||
dest: join(build, 'dist', 'kibana', 'src', 'config', 'index.js')
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
return config;
|
||||
};
|
|
@ -10,7 +10,7 @@ module.exports = function (grunt) {
|
|||
version: pkg.version,
|
||||
build: {
|
||||
number: grunt.config.get('buildNum'),
|
||||
sha: grunt.config.get('commitSha')
|
||||
sha: grunt.config.get('buildSha')
|
||||
},
|
||||
repository: pkg.repository,
|
||||
dependencies: pkg.dependencies
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module.exports = function (grunt) {
|
||||
var exec = require('child_process').execSync;
|
||||
grunt.registerTask('get_build_props', function () {
|
||||
grunt.config.set('commitSha', String(exec('git rev-parse HEAD')).trim());
|
||||
grunt.config.set('buildSha', String(exec('git rev-parse HEAD')).trim());
|
||||
grunt.config.set('buildNum', parseFloat(exec('git log --format="%h" | wc -l')).trim());
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue