Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Upgraded Sense to work with latest Kibana 42 branch
Browse files Browse the repository at this point in the history
Main issues encountered and fixed:
- Putting Sense's code under webpachShims caused it to not be optimized/compiled. This mean ES6 commands (ala let) weren't replaced causing browser compatibility issues.
- Sense code now lives under src
- Removed vendor prefixes - all 3rd party code is under webpackShims
- Cleaned up all define() method and replaced with modern top level code (using module.export)
- Fixed moment importing issues causing the history panel not to work.

Closes elastic#36
Closes #35
  • Loading branch information
bleskes committed Oct 16, 2015
1 parent e76d2f2 commit 9ae0937
Show file tree
Hide file tree
Showing 100 changed files with 7,965 additions and 8,153 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/agent/.local-execution-hints.log
.DS_Store
*.iml
/kibana/vendor/kibana
/kibana/kibana
/node_modules
/build
/.aws-config.json
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ Setting up a development environment
```
git clone https://github.com/elastic/kibana.git kibana
cd kibana
git checkout 327f5898a79564123651f71fe71fb1a17477f977
git checkout 4.2
```

- Finish installation according to https://github.com/elastic/kibana/blob/327f5898a79564123651f71fe71fb1a17477f977/CONTRIBUTING.md#development-environment-setup
- Finish installation according to https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#development-environment-setup
- Skip running elasticsearch
- Do not run `./bin/kibana --dev` just yet.

Expand Down
2 changes: 1 addition & 1 deletion api_server/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* from Elasticsearch Incorporated.
*/

let _ = require("../public/webpackShims/vendor/_");
let _ = require("../public/webpackShims/_");

'use strict';

Expand Down
2 changes: 1 addition & 1 deletion api_server/es_1_0.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

'use strict';

let _ = require('../public/webpackShims/vendor/_');
let _ = require('../public/webpackShims/_');
let Api = require('./api');

let parts = [
Expand Down
2 changes: 1 addition & 1 deletion api_server/es_1_0/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

'use strict';

let _ = require("../../public/webpackShims/vendor/_");
let _ = require("../../public/webpackShims/_");

function addSimpleCat(endpoint, api, params, patterns) {
var url_params = {"help": "__flag__", "v": "__flag__", "bytes": ["b"]};
Expand Down
2 changes: 1 addition & 1 deletion api_server/es_1_0/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

'use strict';

let _ = require("../../public/webpackShims/vendor/_");
let _ = require("../../public/webpackShims/_");


var SPAN_QUERIES = {
Expand Down
2 changes: 1 addition & 1 deletion api_server/es_2_0.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

'use strict';

let _ = require("../public/webpackShims/vendor/_");
let _ = require("../public/webpackShims/_");
let Api = require('./api');
let parts = [
require('./es_2_0/aliases'),
Expand Down
2 changes: 1 addition & 1 deletion api_server/es_2_0/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

'use strict';

let _ = require("../../public/webpackShims/vendor/_");
let _ = require("../../public/webpackShims/_");

function addSimpleCat(endpoint, api, params, patterns) {
var url_params = {"help": "__flag__", "v": "__flag__", "bytes": ["b"]};
Expand Down
2 changes: 1 addition & 1 deletion api_server/es_2_0/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

'use strict';

let _ = require("../../public/webpackShims/vendor/_");
let _ = require("../../public/webpackShims/_");

var INDEX_SETTING = {
__one_of: ['analyzed', 'not_analyzed', 'no']
Expand Down
2 changes: 1 addition & 1 deletion api_server/es_2_0/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
'use strict';

let _ = require("../../public/webpackShims/vendor/_");
let _ = require("../../public/webpackShims/_");

var SPAN_QUERIES = {
// TODO add one_of for objects
Expand Down
2 changes: 1 addition & 1 deletion api_server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* from Elasticsearch Incorporated.
*/

let _ = require("../public/webpackShims/vendor/_");
let _ = require("../public/webpackShims/_");

module.exports.resolveApi = function (sense_version, apis, reply) {
let result = {};
Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = function (kibana) {
let Joi = require('joi');
let Boom = require('boom');
let modules = resolve(__dirname, 'public/webpackShims/');
let src = resolve(__dirname, 'public/src/');

return new kibana.Plugin({
id: 'sense',
Expand Down Expand Up @@ -81,8 +82,8 @@ module.exports = function (kibana) {

noParse: [
join(modules, 'ace' + sep),
join(modules, 'vendor/moment_src/moment' + sep),
resolve(modules, 'sense_editor/mode/worker.js'),
join(modules, 'moment_src/moment' + sep),
join(src, 'sense_editor/mode/worker.js')
]
}
})
Expand Down
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<link id="bootstrapThemeCss" href="/plugins/sense/webpackShims/vendor/bootstrap/css/bootstrap.light.min.css"
<link id="bootstrapThemeCss" href="/plugins/sense/webpackShims/bootstrap/css/bootstrap.light.min.css"
type="text/css" rel="stylesheet"/>
<link href="/plugins/sense/webpackShims/vendor/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet"/>
<link href="/plugins/sense/webpackShims/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet"/>
<link id="senseThemeCss" href="/plugins/sense/css/sense.light.css" rel="stylesheet" type="text/css"/>
<link href="/plugins/sense/css/sense.css" rel="stylesheet" type="text/css"/>
<link rel="shortcut icon" href="/plugins/sense/favicon.ico">
Expand Down
2 changes: 1 addition & 1 deletion public/sense.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ require('ui/chrome')
}])
.setRootTemplate(require('./index.html'))
.setRootController(function () {
require('app');
require('./src/app');
});
239 changes: 239 additions & 0 deletions public/src/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
/**
* ELASTICSEARCH CONFIDENTIAL
* _____________________________
*
* [2014] Elasticsearch Incorporated All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Elasticsearch Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Elasticsearch Incorporated
* and its suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Elasticsearch Incorporated.
*/

var $ = require('jquery');
$(require('./modals.html')).appendTo('body');

let curl = require('./curl');
let $helpPopup = require('./help_popup');
let history = require('./history');
let input = require('./input');
let mappings = require('./mappings');
let output = require('./output');
let miscInputs = require('./misc_inputs');
let es = require('./es');
let utils = require('./utils');
let _ = require('_');
let ga = require('analytics');


$(document.body).removeClass('fouc');

var $esServer = miscInputs.$esServer;

var marvelOpts = localStorage.getItem('marvelOpts');
if (marvelOpts) {
try {
marvelOpts = JSON.parse(marvelOpts);
if (marvelOpts.version && marvelOpts.report) {
ga.pageview();
}
} catch (e) {
marvelOpts = {status: 'trial'};
} // Meh! Who cares...
}
else {
marvelOpts = {status: 'trial'};
}

// set the value of the server and/or the input and clear the output
function resetToValues(server, content) {
if (server != null) {
es.setBaseUrl(server);
}
if (content != null) {
input.update(content);
}
output.update("");
}

function loadSavedState() {
var sourceLocation = utils.getUrlParam('load_from') || "stored";
var previousSaveState = history.getSavedEditorState();

var defaultHost = "localhost:9200";
if (document.location.pathname && document.location.pathname.indexOf("_plugin") == 1) {
// running as an ES plugin. Always assume we are using that elasticsearch
defaultHost = document.location.host;
}

if (sourceLocation == "stored") {
if (previousSaveState) {
resetToValues(previousSaveState.server, previousSaveState.content);
}
else {
resetToValues(defaultHost);
input.autoIndent();
}
}
else if (/^https?:\/\//.test(sourceLocation)) {
var loadFrom = {url: sourceLocation, dataType: "text"};
if (/https?:\/\/api.github.com/.test(sourceLocation)) {
loadFrom.headers = {Accept: "application/vnd.github.v3.raw"};
}
$.ajax(loadFrom).done(function (data) {
resetToValues(defaultHost, data);
input.moveToNextRequestEdge(true);
input.highlightCurrentRequestsAndUpdateActionBar();
input.updateActionsBar();
});
}
else if (previousSaveState) {
resetToValues(previousSaveState.server);
}
else {
resetToValues(defaultHost);
}
input.moveToNextRequestEdge(true);
}

function setupAutosave() {
var timer;
var saveDelay = 500;

function doSave() {
saveCurrentState();
}

input.getSession().on("change", function onChange(e) {
if (timer) {
timer = clearTimeout(timer);
}
timer = setTimeout(doSave, saveDelay);
});
}

function saveCurrentState() {
try {
var content = input.getValue();
var server = $esServer.val();
history.updateCurrentState(server, content);
}
catch (e) {
console.log("Ignoring saving error: " + e);
}
}

// stupid simple restore function, called when the user
// chooses to restore a request from the history
// PREVENTS history from needing to know about the input
history.restoreFromHistory = function applyHistoryElem(req) {
var session = input.getSession();
var pos = input.getCursorPosition();
var prefix = "";
var suffix = "\n";
if (input.parser.isStartRequestRow(pos.row)) {
pos.column = 0;
suffix += "\n";
}
else if (input.parser.isEndRequestRow(pos.row)) {
var line = session.getLine(pos.row);
pos.column = line.length;
prefix = "\n\n";
}
else if (input.parser.isInBetweenRequestsRow(pos.row)) {
pos.column = 0;
}
else {
pos = input.nextRequestEnd(pos);
prefix = "\n\n";
}

var s = prefix + req.method + " " + req.endpoint;
if (req.data) {
s += "\n" + req.data;
}

s += suffix;

session.insert(pos, s);
input.clearSelection();
input.moveCursorTo(pos.row + prefix.length, 0);
input.focus();
};

(function stuffThatsTooHardWithCSS() {
var $editors = input.$el.parent().add(output.$el.parent());
var $resizer = miscInputs.$resizer;
var $header = miscInputs.$header;

var delay;
var headerHeight;
var resizerHeight;

$resizer
.html('&#xFE19;') // vertical elipses
.css('vertical-align', 'middle');

function update() {
var newHeight;

if (delay) {
delay = clearTimeout(delay);
}

newHeight = $header.outerHeight();
if (headerHeight != newHeight) {
headerHeight = newHeight;
$editors.css('top', newHeight + 10);
}

newHeight = $resizer.height();
if (resizerHeight != newHeight) {
resizerHeight = newHeight;
$resizer.css('line-height', newHeight + 'px');
}
input.resize(true);
output.resize(true);
}

// update at key moments in the loading process
$(update);


// and when the window resizes (once every 30 ms)
$(window)
.resize(function (event) {
if (!delay && event.target === window) {
delay = setTimeout(update, 30);
}
});

}());

/**
* Display the welcome popup if it has not been shown yet
*/
if (!localStorage.getItem("version_welcome_shown")) {
let $welcomePopup = require('./welcome_popup');
$welcomePopup.on('shown', function () {
localStorage.setItem("version_welcome_shown", '@@SENSE_REVISION');
});
$welcomePopup.one('hidden', function () {
loadSavedState();
setupAutosave();
});
$welcomePopup.modal('show');
}
else {
loadSavedState();
setupAutosave();
}

if (marvelOpts.status && marvelOpts.version && marvelOpts.report) {
ga.pageview();
}
Loading

0 comments on commit 9ae0937

Please sign in to comment.