Refactored sense to use require.js
Highights of the Changes: - What was previously the editor is now input - Editor is now SenseEditor, a (somewhat) generic class that inherits from AceEditor and mixes in RowParser. will eventually be used by the output as well - input is an instance of SenseEditor that has an autocomplete object at `input.autocomplete` - Moved all network/sendToES logic into the app module - History no longer does any manipulation of the input, that is handled by the app (reduces inter module dependencies) - help popup and welcome popup are now seperate modules - welcome popup is not loaded unless needed - SenseEditor#getCurrentRequestRange and SenseEditor#getCurrentRequest are now async, and will return their value once tokenization has completed. - Replaced "Copy as cURL" functionality, using ZeroClipboard for now.
|
@ -9,18 +9,19 @@ module.exports = function (grunt) {
|
|||
exporterDir: 'exporter',
|
||||
buildDir: 'build',
|
||||
packageDir: 'packages',
|
||||
senseDir: './sense',
|
||||
esPort: {
|
||||
dev: '"'+ (grunt.option('es_port') || 9200) +'"',
|
||||
dist: "(window.location.port !== '' ? ':'+window.location.port : '')"
|
||||
},
|
||||
kibanaPort: grunt.option('port') || 5601,
|
||||
kibanaHost: 'localhost'
|
||||
|
||||
};
|
||||
|
||||
// more detailed config
|
||||
config['buildTempDir'] = config['buildDir'] + '/tmp'; // kibana and custom panels will be merged here
|
||||
config['buildSiteDir'] = config['buildDir'] + '/_site'; // compressed minified marvel site will be outputted here
|
||||
config['buildSiteDir'] = config['buildDir'] + '/_site'; // compressed minified marvel site will be output here
|
||||
config['buildSenseDir'] = config['buildSiteDir'] + '/sense'; // compressed minified sense site will be here
|
||||
|
||||
// Utility function to load plugin settings into the above config object
|
||||
function loadConfig(config, path) {
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
"devDependencies": {
|
||||
"rjs-build-analysis": "0.0.3",
|
||||
"grunt": "~0.4.1",
|
||||
"grunt-contrib": "~0.8.0",
|
||||
"grunt-contrib-copy": "~0.4.1",
|
||||
"grunt-contrib-clean": "~0.5.0",
|
||||
"grunt-contrib-compress": "~0.5.2",
|
||||
|
@ -20,8 +19,8 @@
|
|||
"grunt-ngmin": "0.0.3",
|
||||
"grunt-contrib-less": "~0.7.0",
|
||||
"grunt-git-describe": "~2.3.2",
|
||||
"grunt-contrib-cssmin": "~0.6.1",
|
||||
"grunt-contrib-jshint": "~0.6.0",
|
||||
"grunt-contrib-cssmin": "~0.6.2",
|
||||
"grunt-contrib-jshint": "~0.8.0",
|
||||
"grunt-contrib-htmlmin": "~0.1.3",
|
||||
"grunt-contrib-requirejs": "~0.4.1",
|
||||
"grunt-angular-templates": "~0.3.12",
|
||||
|
@ -33,7 +32,8 @@
|
|||
"grunt-string-replace": "~0.2.4",
|
||||
"grunt-shell": "~0.6.0",
|
||||
"grunt-contrib-connect": "~0.5.0",
|
||||
"grunt-connect-rewrite": "~0.1.1"
|
||||
"grunt-connect-rewrite": "~0.1.1",
|
||||
"csso": "~1.3.10"
|
||||
},
|
||||
"license": "Apache License"
|
||||
}
|
||||
|
|
41
sense/.jshintrc
Normal file
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"white": false,
|
||||
"curly": false,
|
||||
"eqeqeq": false,
|
||||
"unused": false,
|
||||
"noempty": false,
|
||||
"asi": true,
|
||||
"-W021": true,
|
||||
"-W018": true,
|
||||
"-W041": true,
|
||||
"-W027": true,
|
||||
"-W044": true,
|
||||
"-W043": true,
|
||||
|
||||
"browser": true,
|
||||
"bitwise":false,
|
||||
"eqnull": true,
|
||||
"strict": true,
|
||||
"devel": true,
|
||||
"forin": false,
|
||||
"immed": true,
|
||||
"supernew": true,
|
||||
"expr": true,
|
||||
"indent": 2,
|
||||
"latedef": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"undef": true,
|
||||
"boss": true,
|
||||
"trailing": false,
|
||||
"laxbreak": true,
|
||||
"laxcomma": true,
|
||||
"sub": true,
|
||||
"maxlen": 140,
|
||||
|
||||
"globals": {
|
||||
"define": false,
|
||||
"require": false,
|
||||
"SENSE_VERSION": true
|
||||
}
|
||||
}
|
20
sense/app/analytics.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
/* google analytics */
|
||||
var _gaq = window._gaq = (window._gaq || []);
|
||||
_gaq.push(['_setAccount', 'UA-11830182-16']);
|
||||
_gaq.push(['_setCustomVar', 1, 'Version', SENSE_VERSION, 1]);
|
||||
_gaq.push(['_trackPageview']);
|
||||
|
||||
(function () {
|
||||
var ga = document.createElement('script');
|
||||
ga.type = 'text/javascript';
|
||||
ga.async = true;
|
||||
ga.src = 'https://ssl.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0];
|
||||
s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
|
||||
return _gaq
|
||||
});
|
223
sense/app/app.js
Normal file
|
@ -0,0 +1,223 @@
|
|||
define([
|
||||
'ace',
|
||||
'analytics',
|
||||
'curl',
|
||||
'help_popup',
|
||||
'history',
|
||||
'input',
|
||||
'jquery',
|
||||
'mappings',
|
||||
'output',
|
||||
'misc_inputs',
|
||||
'settings',
|
||||
'utils'
|
||||
],
|
||||
function (ace, _gaq, curl, $helpPopup, history, input, $, mappings, output, miscInputs, settings, utils) {
|
||||
'use strict';
|
||||
|
||||
$(document.body).removeClass('fouc');
|
||||
|
||||
var $esServer = miscInputs.$esServer;
|
||||
var $send = miscInputs.$send;
|
||||
|
||||
function submitCurrentRequestToES(cb) {
|
||||
cb = typeof cb === 'function' ? cb : $.noop;
|
||||
|
||||
input.getCurrentRequest(function (req) {
|
||||
if (!req) return;
|
||||
|
||||
$("#notification").text("Calling ES....").css("visibility", "visible");
|
||||
|
||||
var es_server = $esServer.val();
|
||||
var es_url = req.url;
|
||||
var es_method = req.method;
|
||||
var es_data = req.data.join("\n");
|
||||
if (es_data) es_data += "\n"; //append a new line for bulk requests.
|
||||
|
||||
utils.callES(es_server, es_url, es_method, es_data, null, function (xhr, status) {
|
||||
$("#notification").text("").css("visibility", "hidden");
|
||||
if (typeof xhr.status == "number" &&
|
||||
((xhr.status >= 400 && xhr.status < 600) ||
|
||||
(xhr.status >= 200 && xhr.status < 300)
|
||||
)) {
|
||||
// we have someone on the other side. Add to history
|
||||
history.addToHistory(es_server, es_url, es_method, es_data);
|
||||
|
||||
|
||||
var value = xhr.responseText;
|
||||
try {
|
||||
value = JSON.stringify(JSON.parse(value), null, 3);
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
}
|
||||
cb(value);
|
||||
}
|
||||
else {
|
||||
cb("Request failed to get to the server (status code: " + xhr.status + "):" + xhr.responseText);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
saveCurrentState();
|
||||
|
||||
_gaq.push(['_trackEvent', "elasticsearch", 'query']);
|
||||
});
|
||||
}
|
||||
|
||||
// set the value of the server and/or the input and clear the output
|
||||
function resetToValues(server, content) {
|
||||
if (server != null) {
|
||||
$esServer.val(server);
|
||||
mappings.notifyServerChange(server);
|
||||
}
|
||||
if (content != null) {
|
||||
input.update(content);
|
||||
}
|
||||
output.update("");
|
||||
}
|
||||
|
||||
(function loadSavedState() {
|
||||
var sourceLocation = utils.getUrlParam('load_from') || "stored";
|
||||
var previousSaveState = history.getSavedEditorState();
|
||||
|
||||
if (sourceLocation == "stored") {
|
||||
if (previousSaveState) {
|
||||
resetToValues(previousSaveState.server, previousSaveState.content);
|
||||
} else {
|
||||
input.autoIndent();
|
||||
}
|
||||
} else if (/^https?:\/\//.exec(sourceLocation)) {
|
||||
$.get(sourceLocation, null, function (data) {
|
||||
resetToValues(null, data);
|
||||
input.highlightCurrentRequestAndUpdateActionBar();
|
||||
input.updateActionsBar();
|
||||
});
|
||||
} else if (previousSaveState) {
|
||||
resetToValues(previousSaveState.server);
|
||||
}
|
||||
|
||||
if (document.location.pathname && document.location.pathname.indexOf("_plugin") == 1) {
|
||||
// running as an ES plugin. Always assume we are using that elasticsearch
|
||||
resetToValues(document.location.host);
|
||||
}
|
||||
}());
|
||||
|
||||
(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();
|
||||
};
|
||||
|
||||
/**
|
||||
* Make the editor resizeable
|
||||
*/
|
||||
input.$el.resizable({
|
||||
autoHide: false,
|
||||
handles: 'e',
|
||||
start: function (e, ui) {
|
||||
$(".ui-resizable-e").addClass("active");
|
||||
},
|
||||
stop: function (e, ui) {
|
||||
$(".ui-resizable-e").removeClass("active");
|
||||
var parent = ui.element.parent();
|
||||
var editorSize = ui.element.outerWidth();
|
||||
output.$el.css("left", editorSize+20);
|
||||
input.$actions.css("margin-right", -editorSize + 3);
|
||||
input.resize(true);
|
||||
output.resize(true);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Setup the "send" shortcut
|
||||
*/
|
||||
input.commands.addCommand({
|
||||
name: 'send to elasticsearch',
|
||||
bindKey: {win: 'Ctrl-Enter', mac: 'Command-Enter'},
|
||||
exec: function () {
|
||||
output.update('');
|
||||
submitCurrentRequestToES(function (resp) {
|
||||
output.update(resp);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
$send.click(function () {
|
||||
submitCurrentRequestToES();
|
||||
return false;
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Display the welcome popul if it has not been shown yet
|
||||
*/
|
||||
if (!localStorage.getItem("version_welcome_shown")) {
|
||||
require(['welcome_popup'], function ($welcomePopup) {
|
||||
$welcomePopup.one('shown', function () {
|
||||
localStorage.setItem("version_welcome_shown", SENSE_VERSION);
|
||||
});
|
||||
$welcomePopup.modal('show');
|
||||
});
|
||||
}
|
||||
});
|
1312
sense/app/autocomplete.js
Normal file
|
@ -1,3 +1,4 @@
|
|||
/* jshint ignore:start */
|
||||
chrome.browserAction.onClicked.addListener(function (tab) {
|
||||
chrome.tabs.create({'url': chrome.extension.getURL('index.html')}, function (tab) {
|
||||
});
|
74
sense/app/curl.js
Normal file
|
@ -0,0 +1,74 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
function detectCURL(text) {
|
||||
// returns true if text matches a curl request
|
||||
if (!text) return false;
|
||||
return text.match(/^\s*?curl\s+(-X[A-Z]+)?\s*['"]?.*?['"]?(\s*$|\s+?-d\s*?['"])/);
|
||||
|
||||
}
|
||||
|
||||
function parseCURL(text) {
|
||||
var matches = text.match(/^\s*?curl\s+(?:-s\s+)?(-X\s*[A-Z]+)?\s*/);
|
||||
var ret = {
|
||||
method: "",
|
||||
server: "",
|
||||
endpoint: "",
|
||||
data: ""
|
||||
};
|
||||
if (matches[1]) {
|
||||
ret.method = matches[1].substring(2).trim(); // strip -X
|
||||
}
|
||||
text = text.substring(matches[0].length); // strip everything so far.
|
||||
if (text.length == 0) return ret;
|
||||
if (text[0] == '"') {
|
||||
matches = text.match(/^"([^"]*)"/);
|
||||
}
|
||||
else if (text[0] == "'") {
|
||||
matches = text.match(/^'([^']*)'/);
|
||||
}
|
||||
else {
|
||||
matches = text.match(/^(\S*)/);
|
||||
}
|
||||
|
||||
if (!matches) return ret;
|
||||
var url = matches[1];
|
||||
|
||||
if (!url.match(/:\/\//)) url = "http://" + url; // inject http as curl does
|
||||
|
||||
var urlAnchor = document.createElement("a");
|
||||
urlAnchor.href = url;
|
||||
|
||||
ret.server = (urlAnchor.protocol || "http") + "//" + urlAnchor.hostname;
|
||||
if (urlAnchor.port && urlAnchor.port != 0) ret.server += ":" + urlAnchor.port;
|
||||
ret.url = (urlAnchor.pathname || "") + (urlAnchor.search || "");
|
||||
|
||||
text = text.substring(matches[0].length);
|
||||
|
||||
// now search for -d
|
||||
matches = text.match(/.*-d\s*?'/);
|
||||
if (matches) {
|
||||
ret.data = text.substring(matches[0].length).replace(/'\s*$/, '');
|
||||
}
|
||||
else {
|
||||
matches = text.match(/.*-d\s*?"/);
|
||||
if (matches) {
|
||||
ret.data = text.substring(matches[0].length).replace(/"\s*$/, '');
|
||||
ret.data = ret.data.replace(/\\(.)/gi, "$1");
|
||||
}
|
||||
}
|
||||
|
||||
if (ret.data) {
|
||||
ret.data = ret.data.trim();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
parseCURL: parseCURL,
|
||||
detectCURL: detectCURL
|
||||
};
|
||||
|
||||
});
|
37
sense/app/help_popup.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
define([
|
||||
'ace',
|
||||
'analytics',
|
||||
'jquery',
|
||||
|
||||
'bootstrap'
|
||||
], function (ace, _gaq, $) {
|
||||
'use strict';
|
||||
|
||||
var $helpPopup = $("#help_popup");
|
||||
|
||||
var html = [
|
||||
'<div id="help_example_editor">PUT index/type/1',
|
||||
'{',
|
||||
' "body": "here"',
|
||||
'}',
|
||||
'',
|
||||
'GET index/type/1',
|
||||
'</div>'
|
||||
].join('\n');
|
||||
|
||||
$helpPopup.on('shown', function () {
|
||||
_gaq.push(['_trackEvent', "help", 'shown']);
|
||||
$(html).appendTo("#help_example_container");
|
||||
var example_editor = ace.edit("help_example_editor");
|
||||
example_editor.getSession().setMode("ace/mode/sense");
|
||||
example_editor.getSession().setFoldStyle('markbeginend');
|
||||
example_editor.setReadOnly(true);
|
||||
example_editor.renderer.setShowPrintMargin(false);
|
||||
});
|
||||
|
||||
$helpPopup.on('hidden', function () {
|
||||
$('#example_editor').remove();
|
||||
});
|
||||
|
||||
return $helpPopup;
|
||||
})
|
180
sense/app/history.js
Normal file
|
@ -0,0 +1,180 @@
|
|||
define([
|
||||
'_',
|
||||
'sense_editor/editor',
|
||||
'analytics',
|
||||
'jquery',
|
||||
'moment'
|
||||
], function (_, SenseEditor, _gaq, $, moment) {
|
||||
'use strict';
|
||||
|
||||
function History() {
|
||||
var $historyPopup = $("#history_popup");
|
||||
var historyViewer;
|
||||
function restoreNotImplemented() {
|
||||
// default method for history.restoreFromHistory
|
||||
// replace externally to do something when the user chooses
|
||||
// to relive a bit of history
|
||||
throw new Error('not implemented');
|
||||
}
|
||||
|
||||
function getHistoryKeys() {
|
||||
var keys = [];
|
||||
for (var i = 0; i < localStorage.length; i++) {
|
||||
var k = localStorage.key(i);
|
||||
if (k.indexOf("hist_elem") == 0) {
|
||||
keys.push(k);
|
||||
}
|
||||
}
|
||||
|
||||
keys.sort();
|
||||
keys.reverse();
|
||||
return keys;
|
||||
}
|
||||
|
||||
function getHistory() {
|
||||
var hist_items = [];
|
||||
$.each(getHistoryKeys(), function (i, key) {
|
||||
hist_items.push(JSON.parse(localStorage.getItem(key)));
|
||||
});
|
||||
|
||||
return hist_items;
|
||||
}
|
||||
|
||||
function getHistoricalServers() {
|
||||
var servers = {};
|
||||
$.each(getHistory(), function (i, h) {
|
||||
servers[h.server] = 1;
|
||||
});
|
||||
|
||||
var server_list = [];
|
||||
for (var s in servers) server_list.push(s);
|
||||
|
||||
return server_list;
|
||||
}
|
||||
|
||||
function populateHistElem(hist_elem) {
|
||||
var s = hist_elem.method + " " + hist_elem.endpoint + "\n" + (hist_elem.data || "");
|
||||
historyViewer.setValue(s);
|
||||
historyViewer.clearSelection();
|
||||
}
|
||||
|
||||
function addToHistory(server, endpoint, method, data) {
|
||||
var keys = getHistoryKeys();
|
||||
keys.splice(0, 500); // only maintain most recent X;
|
||||
$.each(keys, function (i, k) {
|
||||
localStorage.removeItem(k);
|
||||
});
|
||||
|
||||
var timestamp = new Date().getTime();
|
||||
var k = "hist_elem_" + timestamp;
|
||||
localStorage.setItem(k, JSON.stringify({
|
||||
time: timestamp,
|
||||
server: server,
|
||||
endpoint: endpoint,
|
||||
method: method,
|
||||
data: data
|
||||
}));
|
||||
}
|
||||
|
||||
function updateCurrentState(server, content) {
|
||||
var timestamp = new Date().getTime();
|
||||
localStorage.setItem("editor_state", JSON.stringify(
|
||||
{ 'time': timestamp, 'server': server, 'content': content })
|
||||
);
|
||||
}
|
||||
|
||||
function getSavedEditorState(server, content) {
|
||||
return JSON.parse(localStorage.getItem("editor_state"));
|
||||
}
|
||||
|
||||
$historyPopup.on('show', function () {
|
||||
$historyPopup.find(".modal-body").append('<div id="history_viewer">No history available</div>');
|
||||
|
||||
historyViewer = new SenseEditor($("#history_viewer"));
|
||||
historyViewer.setReadOnly(true);
|
||||
historyViewer.renderer.setShowPrintMargin(false);
|
||||
// historyViewer.setTheme("ace/theme/monokai");
|
||||
|
||||
(function setupHistoryViewerSession(session) {
|
||||
session.setMode("ace/mode/sense");
|
||||
session.setFoldStyle('markbeginend');
|
||||
session.setUseWrapMode(true);
|
||||
}(historyViewer.getSession()));
|
||||
|
||||
$.each(getHistory(), function (i, hist_elem) {
|
||||
var li = $('<li><a href="#"><i class="icon-chevron-right"></i><span/></a></li>');
|
||||
var disc = hist_elem.endpoint;
|
||||
var date = moment(hist_elem.time);
|
||||
if (date.diff(moment(), "days") < -7)
|
||||
disc += " (" + date.format("MMM D") + ")";
|
||||
else
|
||||
disc += " (" + date.fromNow() + ")";
|
||||
|
||||
li.find("span").text(disc);
|
||||
li.attr("title", disc);
|
||||
|
||||
li.find("a").click(function () {
|
||||
$historyPopup.find('.modal-body .nav li').removeClass("active");
|
||||
li.addClass("active");
|
||||
populateHistElem(hist_elem);
|
||||
return false;
|
||||
});
|
||||
|
||||
li.dblclick(function () {
|
||||
li.addClass("active");
|
||||
$historyPopup.find(".btn-primary").click();
|
||||
});
|
||||
|
||||
li.hover(function () {
|
||||
populateHistElem(hist_elem);
|
||||
return false;
|
||||
}, function () {
|
||||
$historyPopup.find(".modal-body .nav li.active a").click();
|
||||
});
|
||||
|
||||
li.bind('apply', function () {
|
||||
_gaq.push(['_trackEvent', "history", 'applied']);
|
||||
this.restoreFromHistory(hist_elem);
|
||||
});
|
||||
|
||||
li.appendTo($historyPopup.find(".modal-body .nav"));
|
||||
});
|
||||
|
||||
$historyPopup.find(".modal-body .nav li:first a").click();
|
||||
});
|
||||
|
||||
$historyPopup.on('hidden', function () {
|
||||
$historyPopup.find('.modal-body #historyViewer').remove();
|
||||
$historyPopup.find('.modal-body .nav li').remove();
|
||||
historyViewer = null;
|
||||
});
|
||||
|
||||
$historyPopup.find(".btn-primary").click(function () {
|
||||
$historyPopup.find(".modal-body .nav li.active").trigger("apply");
|
||||
});
|
||||
|
||||
$historyPopup.find("#hist_clear").click(function () {
|
||||
var keys = getHistoryKeys();
|
||||
$.each(keys, function (i, k) {
|
||||
localStorage.removeItem(k);
|
||||
});
|
||||
$historyPopup.find(".modal-body .nav").html("");
|
||||
historyViewer.getSession().setValue("No history available");
|
||||
});
|
||||
|
||||
_.assign(this, {
|
||||
updateCurrentState: updateCurrentState,
|
||||
addToHistory: addToHistory,
|
||||
getSavedEditorState: getSavedEditorState,
|
||||
getHistoricalServers: getHistoricalServers,
|
||||
restoreFromHistory: restoreNotImplemented
|
||||
});
|
||||
}
|
||||
|
||||
return new History();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
120
sense/app/input.js
Normal file
|
@ -0,0 +1,120 @@
|
|||
define([
|
||||
'analytics',
|
||||
'autocomplete',
|
||||
'jquery',
|
||||
'mappings',
|
||||
'output',
|
||||
'require',
|
||||
'sense_editor/editor',
|
||||
'utils',
|
||||
'zeroclip'
|
||||
], function (_gaq, Autocomplete, $, mappings, output, require, SenseEditor, utils, ZeroClipboard) {
|
||||
'use strict';
|
||||
|
||||
var input = new SenseEditor($('#editor'));
|
||||
input.autocomplete = new Autocomplete(input);
|
||||
|
||||
input.commands.addCommand({
|
||||
name: 'autocomplete',
|
||||
bindKey: {win: 'Ctrl-Space', mac: 'Ctrl-Space'},
|
||||
exec: function () {
|
||||
input.autocomplete.show();
|
||||
}
|
||||
});
|
||||
input.commands.addCommand({
|
||||
name: 'auto indent request',
|
||||
bindKey: {win: 'Ctrl-I', mac: 'Command-I'},
|
||||
exec: function () {
|
||||
input.autoIndent();
|
||||
}
|
||||
});
|
||||
input.commands.addCommand({
|
||||
name: 'move to previous request start or end',
|
||||
bindKey: {win: 'Ctrl-Up', mac: 'Command-Up'},
|
||||
exec: function () {
|
||||
input.moveToPreviousRequestEdge()
|
||||
}
|
||||
});
|
||||
input.commands.addCommand({
|
||||
name: 'move to next request start or end',
|
||||
bindKey: {win: 'Ctrl-Down', mac: 'Command-Down'},
|
||||
exec: function () {
|
||||
input.moveToNextRequestEdge()
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* COPY AS CURL
|
||||
*
|
||||
* Since the copy functionality is powered by a flash movie (via ZeroClipboard)
|
||||
* the only way to trigger the copy is with a litteral mouseclick from the user.
|
||||
*
|
||||
* The original shortcut will now just open the menu and highlight the
|
||||
*
|
||||
*/
|
||||
var $copyAsCURL = $('#copy_as_curl');
|
||||
var zc = (function setupZeroClipboard() {
|
||||
ZeroClipboard.setDefaults({
|
||||
moviePath: require.toUrl("../vendor/zero_clipboard/zero_clipboard.swf"),
|
||||
debug: false
|
||||
});
|
||||
var zc = new ZeroClipboard($copyAsCURL); // the ZeroClipboard instance
|
||||
|
||||
zc.on('wrongflash noflash', function () {
|
||||
if (!localStorage.getItem('flash_warning_shown')) {
|
||||
alert('Sense needs flash version 10.0 or greater in order to provide "Copy as cURL" functionality');
|
||||
localStorage.setItem('flash_warning_shown');
|
||||
}
|
||||
$copyAsCURL.hide();
|
||||
});
|
||||
|
||||
zc.on('load', function () {
|
||||
function setupCopyButton (cb) {
|
||||
cb = typeof cb === 'function' ? cb : $.noop;
|
||||
$copyAsCURL.css('visibility', 'hidden');
|
||||
input.getCurrentRequestAsCURL(function (curl) {
|
||||
$copyAsCURL.attr('data-clipboard-text', curl);
|
||||
$copyAsCURL.css('visibility', 'visible');
|
||||
cb();
|
||||
});
|
||||
}
|
||||
|
||||
input.$actions.on('mouseenter', function () {
|
||||
if (!$(this).hasClass('open')) {
|
||||
setupCopyButton();
|
||||
}
|
||||
});
|
||||
|
||||
input.commands.addCommand({
|
||||
name: 'copy as cUrl',
|
||||
bindKey: {win: 'Ctrl-Shift-C', mac: 'Command-Shift-C'},
|
||||
exec: function () {
|
||||
input.$actions.find('[data-toggle=dropdown]:not(.open)').click();
|
||||
setupCopyButton();
|
||||
var toggles = 5;
|
||||
(function toggle () {
|
||||
$copyAsCURL.toggleClass('zeroclipboard-is-hover', toggles % 1);
|
||||
if (--toggles) setTimeout(toggle, 125);
|
||||
}());
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
zc.on('complete', function () {
|
||||
_gaq.push(['_trackEvent', "curl", 'copied']);
|
||||
$copyAsCURL.click();
|
||||
});
|
||||
|
||||
return zc;
|
||||
}());
|
||||
|
||||
/**
|
||||
* Init the editor
|
||||
*/
|
||||
input.focus();
|
||||
input.highlightCurrentRequestAndUpdateActionBar();
|
||||
input.updateActionsBar();
|
||||
|
||||
return input;
|
||||
})
|
40
sense/app/kb/aliases.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addEndpointDescription('_aliases', {
|
||||
match: /_aliases/,
|
||||
def_method: 'GET',
|
||||
methods: ['GET', 'POST'],
|
||||
endpoint_autocomplete: [
|
||||
'_aliases'
|
||||
],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
'actions': {
|
||||
__template: [
|
||||
{ 'add': { 'index': 'test1', 'alias': 'alias1' } }
|
||||
],
|
||||
__any_of: [
|
||||
{
|
||||
add: {
|
||||
index: '$INDEX$',
|
||||
alias: '',
|
||||
filter: {},
|
||||
routing: '1',
|
||||
search_routing: '1,2',
|
||||
index_routing: '1'
|
||||
},
|
||||
remove: {
|
||||
index: '',
|
||||
alias: ''
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
40
sense/app/kb/cluster.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addEndpointDescription('_cluster/nodes/stats', {
|
||||
methods: ['GET'],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none'
|
||||
});
|
||||
|
||||
kb.addEndpointDescription('_cluster/state', {
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: ['_cluster/state'],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none'
|
||||
});
|
||||
|
||||
kb.addEndpointDescription('_cluster/health', {
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: ['_cluster/health'],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none'
|
||||
});
|
||||
|
||||
kb.addEndpointDescription('_cluster/settings', {
|
||||
methods: ['GET', 'PUT'],
|
||||
endpoint_autocomplete: ['_cluster/settings'],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
persistent: {
|
||||
'routing.allocation.same_shard.host' : { __one_of: [ false, true ]}
|
||||
},
|
||||
transient: {
|
||||
__scope_link: '.persistent'
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
111
sense/app/kb/facets.js
Normal file
|
@ -0,0 +1,111 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addGlobalAutocompleteRules('facets', {
|
||||
'*': {
|
||||
terms: {
|
||||
__template: {
|
||||
field: 'FIELD',
|
||||
size: 10
|
||||
},
|
||||
field: '$FIELD$',
|
||||
fields: ['$FIELD$'],
|
||||
size: 10,
|
||||
script: '',
|
||||
script_field: '',
|
||||
order: {
|
||||
__one_of: ['count', 'term', 'reverse_count', 'reverse_term']
|
||||
},
|
||||
all_terms: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
exclude: ['TERM'],
|
||||
regex: '',
|
||||
regex_flags: ''
|
||||
},
|
||||
range: {
|
||||
__template: {
|
||||
field: 'FIELD',
|
||||
ranges: [{
|
||||
'to': 50
|
||||
}, {
|
||||
'from': 20,
|
||||
'to': 70
|
||||
}, {
|
||||
'from': 70,
|
||||
'to': 120
|
||||
}, {
|
||||
'from': 150
|
||||
}]
|
||||
},
|
||||
field: '$FIELD$',
|
||||
ranges: [{
|
||||
to: 10,
|
||||
from: 20
|
||||
}]
|
||||
},
|
||||
histogram: {
|
||||
__template: {
|
||||
field: 'FIELD',
|
||||
interval: 100
|
||||
},
|
||||
field: '$FIELD$',
|
||||
interval: 100,
|
||||
time_interval: '1.5h',
|
||||
key_field: '$FIELD$',
|
||||
value_field: '$FIELD$',
|
||||
key_script: '',
|
||||
value_script: '',
|
||||
params: {}
|
||||
},
|
||||
date_histogram: {
|
||||
__template: {
|
||||
field: 'FIELD',
|
||||
'interval': 'day'
|
||||
},
|
||||
field: '$FIELD$',
|
||||
interval: {
|
||||
__one_of: ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', '1h', '1d', '1w']
|
||||
},
|
||||
post_zone: -1,
|
||||
pre_zone: -1,
|
||||
factor: 1000,
|
||||
pre_offset: '1d',
|
||||
post_offset: '1d',
|
||||
key_field: '$FIELD$',
|
||||
value_field: '$FIELD$',
|
||||
value_script: ''
|
||||
},
|
||||
filter: {},
|
||||
query: {},
|
||||
facet_filter: {
|
||||
__scope_link: 'GLOBAL.filter'
|
||||
},
|
||||
statistical: {
|
||||
__template: {
|
||||
field: 'FIELD'
|
||||
},
|
||||
field: '$FIELD$',
|
||||
fields: ['$FIELD$'],
|
||||
script: ''
|
||||
},
|
||||
terms_stats: {
|
||||
__template: {
|
||||
key_field: 'FIELD',
|
||||
value_field: 'FIELD'
|
||||
},
|
||||
key_field: '$FIELD$',
|
||||
value_field: '$FIELD$',
|
||||
value_script: '',
|
||||
size: 10,
|
||||
order: {
|
||||
__one_of: ['count', 'term', 'reverse_term', 'reverse_count', 'total', 'reverse_total',
|
||||
'min', 'reverse_min', 'max', 'reverse_max', 'mean', 'reverse_mean'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
406
sense/app/kb/filter.js
Normal file
|
@ -0,0 +1,406 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
var filters = {};
|
||||
|
||||
filters.and = {
|
||||
__template: {
|
||||
filters: [{}]
|
||||
},
|
||||
filters: [{
|
||||
__scope_link: '.filter'
|
||||
}],
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.bool = {
|
||||
must: [{
|
||||
__scope_link: '.filter'
|
||||
}],
|
||||
must_not: [{
|
||||
__scope_link: '.filter'
|
||||
}],
|
||||
should: [{
|
||||
__scope_link: '.filter'
|
||||
}],
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.exists = {
|
||||
__template: {
|
||||
'FIELD': 'VALUE'
|
||||
},
|
||||
'$FIELD$': ''
|
||||
};
|
||||
|
||||
|
||||
filters.ids = {
|
||||
__template: {
|
||||
'values': ['ID']
|
||||
},
|
||||
'type': '$TYPE$',
|
||||
'values': ['']
|
||||
};
|
||||
|
||||
|
||||
filters.limit = {
|
||||
__template: {
|
||||
value: 100
|
||||
},
|
||||
value: 100
|
||||
};
|
||||
|
||||
|
||||
filters.type = {
|
||||
__template: {
|
||||
value: 'TYPE'
|
||||
},
|
||||
value: '$TYPE$'
|
||||
};
|
||||
|
||||
|
||||
filters.geo_bounding_box = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'top_left': {
|
||||
'lat': 40.73,
|
||||
'lon': -74.1
|
||||
},
|
||||
'bottom_right': {
|
||||
'lat': 40.717,
|
||||
'lon': -73.99
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
'$FIELD$': {
|
||||
top_left: {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
},
|
||||
bottom_right: {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
}
|
||||
},
|
||||
type: {
|
||||
__one_of: ['memory', 'indexed']
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.geo_distance = {
|
||||
__template: {
|
||||
distance: 100,
|
||||
distance_unit: 'km',
|
||||
'FIELD': {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
}
|
||||
},
|
||||
distance: 100,
|
||||
distance_unit: {
|
||||
__one_of: ['km', 'miles']
|
||||
},
|
||||
distance_type: {
|
||||
__one_of: ['arc', 'plane']
|
||||
},
|
||||
optimize_bbox: {
|
||||
__one_of: ['memory', 'indexed', 'none']
|
||||
},
|
||||
'$FIELD$': {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.geo_distance_range = {
|
||||
__template: {
|
||||
from: 100,
|
||||
to: 200,
|
||||
distance_unit: 'km',
|
||||
'FIELD': {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
}
|
||||
},
|
||||
from: 100,
|
||||
to: 200,
|
||||
|
||||
distance_unit: {
|
||||
__one_of: ['km', 'miles']
|
||||
},
|
||||
distance_type: {
|
||||
__one_of: ['arc', 'plane']
|
||||
},
|
||||
include_lower: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
include_upper: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
|
||||
'$FIELD$': {
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.geo_polygon = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'points': [{
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
}, {
|
||||
lat: 40.83,
|
||||
lon: -75.1
|
||||
}]
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
points: [{
|
||||
lat: 40.73,
|
||||
lon: -74.1
|
||||
}]
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.geo_shape = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
shape: {
|
||||
type: 'envelope',
|
||||
coordinates: [
|
||||
[-45, 45],
|
||||
[45, -45]
|
||||
]
|
||||
},
|
||||
'relation': 'within'
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
shape: {
|
||||
type: '',
|
||||
coordinates: []
|
||||
},
|
||||
indexed_shape: {
|
||||
id: '',
|
||||
index: '$INDEX$',
|
||||
type: '$TYPE$',
|
||||
shape_field_name: 'shape'
|
||||
},
|
||||
relation: {
|
||||
__one_of: ['within', 'intersects', 'disjoint']
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.has_child = {
|
||||
__template: {
|
||||
type: 'TYPE',
|
||||
query: {}
|
||||
},
|
||||
type: '$TYPE$',
|
||||
query: {},
|
||||
_scope: ''
|
||||
};
|
||||
|
||||
|
||||
filters.has_parent = {
|
||||
__template: {
|
||||
type: 'TYPE',
|
||||
query: {}
|
||||
},
|
||||
type: '$TYPE$',
|
||||
query: {},
|
||||
_scope: ''
|
||||
};
|
||||
|
||||
|
||||
filters.m = filters.missing = {
|
||||
__template: {
|
||||
field: 'FIELD'
|
||||
},
|
||||
existence: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
null_value: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
field: '$FIELD$'
|
||||
};
|
||||
|
||||
|
||||
filters.not = {
|
||||
__template: {
|
||||
filter: {}
|
||||
},
|
||||
filter: {
|
||||
__scope_link: '.filter'
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.numeric_range = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
from: 10,
|
||||
to: 20
|
||||
}
|
||||
},
|
||||
from: 1,
|
||||
to: 20,
|
||||
include_lower: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
include_upper: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.or = {
|
||||
__template: {
|
||||
filters: [{}]
|
||||
},
|
||||
filters: [{
|
||||
__scope_link: '.filter'
|
||||
}],
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.prefix = {
|
||||
__template: {
|
||||
'FIELD': 'VALUE'
|
||||
},
|
||||
'$FIELD$': '',
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.query = {
|
||||
__scope_link: '.query'
|
||||
};
|
||||
|
||||
|
||||
filters.fquery = {
|
||||
__template: {
|
||||
query: {},
|
||||
_cache: true
|
||||
},
|
||||
query: {
|
||||
__scope_link: '.query'
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.range = {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
from: 10,
|
||||
to: 20
|
||||
}
|
||||
},
|
||||
from: 1,
|
||||
to: 20,
|
||||
include_lower: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
include_upper: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.script = {
|
||||
__template: {
|
||||
script: 'SCRIPT',
|
||||
params: {}
|
||||
},
|
||||
script: '',
|
||||
params: {},
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.term = {
|
||||
__template: {
|
||||
'FIELD': 'VALUE'
|
||||
},
|
||||
'$FIELD$': '',
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.terms = {
|
||||
__template: {
|
||||
'FIELD': ['VALUE1', 'VALUE2']
|
||||
},
|
||||
field: ['$FIELD$'],
|
||||
execution: {
|
||||
__one_of: ['plain', 'bool', 'and', 'or', 'bool_nocache', 'and_nocache', 'or_nocache']
|
||||
},
|
||||
_cache: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
filters.nested = {
|
||||
__template: {
|
||||
path: 'path_to_nested_doc',
|
||||
query: {}
|
||||
},
|
||||
query: {},
|
||||
path: '',
|
||||
_cache: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
_name: ''
|
||||
};
|
||||
|
||||
return function init(kb) {
|
||||
kb.addGlobalAutocompleteRules('filter', filters);
|
||||
};
|
||||
});
|
26
sense/app/kb/globals.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addGlobalAutocompleteRules('highlight', {
|
||||
pre_tags: {},
|
||||
post_tags: {},
|
||||
tags_schema: {},
|
||||
fields: {
|
||||
'$FIELD$': {
|
||||
fragment_size: 20,
|
||||
number_of_fragments: 3
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// only used with scope links as there is no common name for scripts
|
||||
kb.addGlobalAutocompleteRules('SCRIPT_ENV', {
|
||||
__template: { 'script': ''},
|
||||
script: '',
|
||||
lang: '',
|
||||
params: {}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
149
sense/app/kb/index.js
Normal file
|
@ -0,0 +1,149 @@
|
|||
define([
|
||||
'_',
|
||||
'../mappings',
|
||||
'kb/aliases',
|
||||
'kb/cluster',
|
||||
'kb/facets',
|
||||
'kb/filter',
|
||||
'kb/globals',
|
||||
'kb/indices',
|
||||
'kb/mappings',
|
||||
'kb/misc',
|
||||
'kb/query',
|
||||
'kb/search',
|
||||
'kb/settings',
|
||||
'kb/templates',
|
||||
'kb/warmers'
|
||||
], function (_, mappings) {
|
||||
'use strict';
|
||||
|
||||
var GLOBAL_AUTOCOMPLETE_RULES = {};
|
||||
var ES_SCHEME_BY_ENDPOINT = {};
|
||||
|
||||
function escapeRegex(text) {
|
||||
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
}
|
||||
|
||||
function addGlobalAutocompleteRules(parentNode, rules) {
|
||||
GLOBAL_AUTOCOMPLETE_RULES[parentNode] = rules;
|
||||
}
|
||||
|
||||
function getGlobalAutocompleteRules() {
|
||||
return GLOBAL_AUTOCOMPLETE_RULES;
|
||||
}
|
||||
|
||||
function addEndpointDescription(endpoint, description) {
|
||||
if (!description.endpoint_autocomplete)
|
||||
description.endpoint_autocomplete = [endpoint];
|
||||
|
||||
if (!description.match) {
|
||||
var l = _.map(description.endpoint_autocomplete, escapeRegex);
|
||||
description.match = "(?:" + l.join(")|(?:") + ")";
|
||||
}
|
||||
|
||||
if (typeof description.match == "string") description.match = new RegExp(description.match);
|
||||
|
||||
var copiedDescription = {};
|
||||
_.extend(copiedDescription, description);
|
||||
copiedDescription._id = endpoint;
|
||||
|
||||
ES_SCHEME_BY_ENDPOINT[endpoint] = copiedDescription;
|
||||
}
|
||||
|
||||
function getEndpointDescriptionByEndpoint(endpoint) {
|
||||
return ES_SCHEME_BY_ENDPOINT[endpoint];
|
||||
}
|
||||
|
||||
function getEndpointsForIndicesTypesAndId(indices, types, id) {
|
||||
var ret = [];
|
||||
var index_mode = "none";
|
||||
if (indices && indices.length > 0) {
|
||||
indices = mappings.expandAliases(indices);
|
||||
index_mode = typeof indices == "string" ? "single" : "multi";
|
||||
}
|
||||
|
||||
var type_mode = "none";
|
||||
if (types && types.length > 0) type_mode = types.length > 1 ? "multi" : "single";
|
||||
var id_mode = "none";
|
||||
if (id && id.length > 0) id_mode = "single";
|
||||
|
||||
for (var endpoint in ES_SCHEME_BY_ENDPOINT) {
|
||||
var scheme = ES_SCHEME_BY_ENDPOINT[endpoint];
|
||||
switch (scheme.indices_mode) {
|
||||
case "none":
|
||||
if (index_mode !== "none") continue;
|
||||
break;
|
||||
case "single":
|
||||
if (index_mode !== "single") continue;
|
||||
break;
|
||||
case "required_multi":
|
||||
if (index_mode === "none") continue;
|
||||
break;
|
||||
case "multi": // always good
|
||||
break;
|
||||
}
|
||||
switch (scheme.types_mode) {
|
||||
case "none":
|
||||
if (type_mode !== "none") continue;
|
||||
break;
|
||||
case "single":
|
||||
if (type_mode !== "single") continue;
|
||||
break;
|
||||
case "multi": // always good
|
||||
break;
|
||||
}
|
||||
|
||||
switch (scheme.doc_id_mode) {
|
||||
case "none":
|
||||
if (id_mode !== "none") continue;
|
||||
break;
|
||||
case "required_single":
|
||||
if (id_mode === "none") continue;
|
||||
break;
|
||||
}
|
||||
|
||||
ret.push(endpoint);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function getEndpointDescriptionByPath(path, indices, types, id) {
|
||||
var endpoints = getEndpointsForIndicesTypesAndId(indices, types, id);
|
||||
for (var i = 0; i < endpoints.length; i++) {
|
||||
var scheme = ES_SCHEME_BY_ENDPOINT[endpoints[i]];
|
||||
if (scheme.match.test(path || "")) return scheme;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getEndpointAutocomplete(indices, types, id) {
|
||||
var ret = [];
|
||||
var endpoints = getEndpointsForIndicesTypesAndId(indices, types, id);
|
||||
for (var i = 0; i < endpoints.length; i++) {
|
||||
var scheme = ES_SCHEME_BY_ENDPOINT[endpoints[i]];
|
||||
ret.push.apply(ret, scheme.endpoint_autocomplete);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function clear() {
|
||||
ES_SCHEME_BY_ENDPOINT = {};
|
||||
GLOBAL_AUTOCOMPLETE_RULES = {};
|
||||
}
|
||||
|
||||
var kb = {
|
||||
addGlobalAutocompleteRules: addGlobalAutocompleteRules,
|
||||
getGlobalAutocompleteRules: getGlobalAutocompleteRules,
|
||||
addEndpointDescription: addEndpointDescription,
|
||||
getEndpointAutocomplete: getEndpointAutocomplete,
|
||||
getEndpointDescriptionByPath: getEndpointDescriptionByPath,
|
||||
getEndpointDescriptionByEndpoint: getEndpointDescriptionByEndpoint,
|
||||
clear: clear
|
||||
};
|
||||
|
||||
_(arguments).rest(2).each(function (kbSection) {
|
||||
kbSection(kb);
|
||||
});
|
||||
|
||||
return kb;
|
||||
});
|
51
sense/app/kb/indices.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addEndpointDescription('_refresh', {
|
||||
def_method: 'POST',
|
||||
methods: ['POST'],
|
||||
endpoint_autocomplete: [
|
||||
'_refresh'
|
||||
],
|
||||
indices_mode: 'multi'
|
||||
});
|
||||
|
||||
kb.addEndpointDescription('_stats', {
|
||||
def_method: 'GET',
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: [
|
||||
'_stats'
|
||||
],
|
||||
indices_mode: 'multi'
|
||||
});
|
||||
|
||||
kb.addEndpointDescription('_segments', {
|
||||
def_method: 'GET',
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: [
|
||||
'_segments'
|
||||
],
|
||||
indices_mode: 'multi'
|
||||
});
|
||||
|
||||
kb.addEndpointDescription('__create_index__', {
|
||||
methods: ['PUT', 'DELETE'],
|
||||
indices_mode: 'single',
|
||||
types_mode: 'none',
|
||||
match: '^/?$',
|
||||
endpoint_autocomplete: [
|
||||
''
|
||||
],
|
||||
data_autocomplete_rules: {
|
||||
mappings: {
|
||||
__scope_link: '_mapping'
|
||||
},
|
||||
settings: {
|
||||
__scope_link: '_settings.index'
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
128
sense/app/kb/mappings.js
Normal file
|
@ -0,0 +1,128 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addEndpointDescription('_mapping', {
|
||||
def_method: 'GET',
|
||||
methods: ['GET', 'PUT'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'multi',
|
||||
data_autocomplete_rules: {
|
||||
'$TYPE$': {
|
||||
__template: {
|
||||
properties: {
|
||||
'FIELD': {}
|
||||
}
|
||||
},
|
||||
'_parent': {
|
||||
__template: {
|
||||
'type': ''
|
||||
},
|
||||
'type': '$TYPE$'
|
||||
},
|
||||
'index_analyzer': 'standard',
|
||||
'search_analyzer': 'standard',
|
||||
'analyzer': 'standard',
|
||||
'dynamic_date_formats': ['yyyy-MM-dd'],
|
||||
'date_detection': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'numeric_detection': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'properties': {
|
||||
'*': {
|
||||
type: {
|
||||
__one_of: ['string', 'float', 'double', 'byte', 'short', 'integer', 'long', 'date', 'boolean',
|
||||
'binary', 'object', 'nested', 'multi_field'
|
||||
]
|
||||
},
|
||||
|
||||
// strings
|
||||
index_name: '',
|
||||
store: {
|
||||
__one_of: ['no', 'yes']
|
||||
},
|
||||
index: {
|
||||
__one_of: ['analyzed', 'not_analyzed', 'no']
|
||||
},
|
||||
term_vector: {
|
||||
__one_of: ['no', 'yes', 'with_offsets', 'with_positions', 'with_positions_offsets']
|
||||
},
|
||||
boost: 1.0,
|
||||
null_value: '',
|
||||
omit_norms: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
index_options: {
|
||||
__one_of: ['docs', 'freqs', 'positions']
|
||||
},
|
||||
analyzer: 'standard',
|
||||
index_analyzer: 'standard',
|
||||
search_analyzer: 'standard',
|
||||
include_in_all: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
ignore_above: 10,
|
||||
position_offset_gap: 0,
|
||||
|
||||
// numeric
|
||||
precision_step: 4,
|
||||
ignore_malformed: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
|
||||
// dates
|
||||
format: {
|
||||
__one_of: ['basic_date', 'basic_date_time', 'basic_date_time_no_millis',
|
||||
'basic_ordinal_date', 'basic_ordinal_date_time', 'basic_ordinal_date_time_no_millis',
|
||||
'basic_time', 'basic_time_no_millis', 'basic_t_time', 'basic_t_time_no_millis',
|
||||
'basic_week_date', 'basic_week_date_time', 'basic_week_date_time_no_millis',
|
||||
'date', 'date_hour', 'date_hour_minute', 'date_hour_minute_second', 'date_hour_minute_second_fraction',
|
||||
'date_hour_minute_second_millis', 'date_optional_time', 'date_time', 'date_time_no_millis',
|
||||
'hour', 'hour_minute', 'hour_minute_second', 'hour_minute_second_fraction', 'hour_minute_second_millis',
|
||||
'ordinal_date', 'ordinal_date_time', 'ordinal_date_time_no_millis', 'time', 'time_no_millis',
|
||||
't_time', 't_time_no_millis', 'week_date', 'week_date_time', 'weekDateTimeNoMillis', 'week_year',
|
||||
'weekyearWeek', 'weekyearWeekDay', 'year', 'year_month', 'year_month_day'
|
||||
]
|
||||
},
|
||||
|
||||
fielddata: {
|
||||
filter: {
|
||||
regex: '',
|
||||
frequency: {
|
||||
min: 0.001,
|
||||
max: 0.1,
|
||||
min_segment_size: 500
|
||||
}
|
||||
}
|
||||
},
|
||||
postings_format: {
|
||||
__one_of: ['direct', 'memory', 'pulsing', 'bloom_default', 'bloom_pulsing', 'default']
|
||||
},
|
||||
similarity: {
|
||||
__one_of: ['default', 'BM25']
|
||||
},
|
||||
|
||||
// objects
|
||||
properties: {
|
||||
__scope_link: '_mapping.$TYPE$.properties'
|
||||
},
|
||||
|
||||
// multi_field
|
||||
path: {
|
||||
__one_of: ['just_name', 'full']
|
||||
},
|
||||
fields: {
|
||||
'*': {
|
||||
__scope_link: '_mapping.$TYPE$.properties.$FIELD$'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
32
sense/app/kb/misc.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addEndpointDescription('_stats', {
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: ['_stats'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none'
|
||||
});
|
||||
|
||||
kb.addEndpointDescription('_cache/clear', {
|
||||
methods: ['GET'],
|
||||
endpoint_autocomplete: ['_cache/clear'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none'
|
||||
});
|
||||
|
||||
kb.addEndpointDescription('_status', {
|
||||
methods: ['GET'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
endpoint_autocomplete: ['_status']
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
});
|
487
sense/app/kb/query.js
Normal file
|
@ -0,0 +1,487 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
var SPAN_QUERIES = {
|
||||
// TODO add one_of for objects
|
||||
span_first: {
|
||||
__scope_link: '.query.span_first'
|
||||
},
|
||||
span_near: {
|
||||
__scope_link: '.query.span_near'
|
||||
},
|
||||
span_or: {
|
||||
__scope_link: '.query.span_or'
|
||||
},
|
||||
span_not: {
|
||||
__scope_link: '.query.span_not'
|
||||
},
|
||||
span_term: {
|
||||
__scope_link: '.query.span_term'
|
||||
}
|
||||
};
|
||||
|
||||
return function init(kb) {
|
||||
kb.addGlobalAutocompleteRules('query', {
|
||||
match: {
|
||||
__template: {
|
||||
'FIELD': 'TEXT'
|
||||
},
|
||||
'$FIELD$': {
|
||||
'query': '',
|
||||
'operator': {
|
||||
__one_of: ['and', 'or']
|
||||
},
|
||||
'type': {
|
||||
__one_of: ['phrase', 'phrase_prefix', 'boolean']
|
||||
},
|
||||
'max_expansions': 10,
|
||||
'analyzer': '',
|
||||
'fuzziness': 1.0,
|
||||
'prefix_length': 1
|
||||
}
|
||||
},
|
||||
match_phrase: {
|
||||
__template: {
|
||||
'FIELD': 'PHRASE'
|
||||
},
|
||||
'$FIELD$': {
|
||||
query: '',
|
||||
analyzer: ''
|
||||
}
|
||||
},
|
||||
match_phrase_prefix: {
|
||||
__template: {
|
||||
'FIELD': 'PREFIX'
|
||||
},
|
||||
'$FIELD$': {
|
||||
query: '',
|
||||
analyzer: '',
|
||||
max_expansions: 10,
|
||||
prefix_length: 1,
|
||||
fuzziness: 0.1
|
||||
}
|
||||
},
|
||||
multi_match: {
|
||||
__template: {
|
||||
'query': '',
|
||||
'fields': []
|
||||
},
|
||||
query: '',
|
||||
fields: ['$FIELD$'],
|
||||
use_dis_max: {
|
||||
__template: true,
|
||||
__one_of: [true, false]
|
||||
},
|
||||
tie_breaker: 0.0
|
||||
},
|
||||
bool: {
|
||||
must: [{
|
||||
__scope_link: 'GLOBAL.query'
|
||||
}],
|
||||
must_not: [{
|
||||
__scope_link: 'GLOBAL.query'
|
||||
}],
|
||||
should: [{
|
||||
__scope_link: 'GLOBAL.query'
|
||||
}],
|
||||
minimum_number_should_match: 1,
|
||||
boost: 1.0
|
||||
},
|
||||
boosting: {
|
||||
positive: {
|
||||
__scope_link: '.query'
|
||||
},
|
||||
negative: {
|
||||
__scope_link: '.query'
|
||||
},
|
||||
negative_boost: 0.2
|
||||
},
|
||||
ids: {
|
||||
type: '',
|
||||
values: []
|
||||
},
|
||||
custom_score: {
|
||||
__template: {
|
||||
query: {},
|
||||
script: ''
|
||||
},
|
||||
query: {},
|
||||
script: '',
|
||||
params: {},
|
||||
lang: 'mvel'
|
||||
},
|
||||
custom_boost_factor: {
|
||||
__template: {
|
||||
query: {},
|
||||
boost_factor: 1.1
|
||||
},
|
||||
query: {},
|
||||
boost_factor: 1.1
|
||||
},
|
||||
constant_score: {
|
||||
__template: {
|
||||
filter: {},
|
||||
boost: 1.2
|
||||
},
|
||||
query: {},
|
||||
filter: {},
|
||||
boost: 1.2
|
||||
},
|
||||
dis_max: {
|
||||
__template: {
|
||||
tie_breaker: 0.7,
|
||||
boost: 1.2,
|
||||
queries: []
|
||||
},
|
||||
tie_breaker: 0.7,
|
||||
boost: 1.2,
|
||||
queries: [{
|
||||
__scope_link: '.query'
|
||||
}]
|
||||
},
|
||||
field: {
|
||||
'$FIELD$': {
|
||||
query: '',
|
||||
boost: 2.0,
|
||||
enable_position_increments: {
|
||||
__template: false,
|
||||
__one_of: [true, false]
|
||||
}
|
||||
}
|
||||
},
|
||||
filtered: {
|
||||
__template: {
|
||||
query: {},
|
||||
filter: {}
|
||||
},
|
||||
query: {},
|
||||
filter: {}
|
||||
},
|
||||
fuzzy_like_this: {
|
||||
fields: [],
|
||||
like_text: '',
|
||||
max_query_terms: 12
|
||||
},
|
||||
flt: {
|
||||
__scope_link: '.query.fuzzy_like_this'
|
||||
},
|
||||
fuzzy: {
|
||||
'$FIELD$': {
|
||||
'value': '',
|
||||
'boost': 1.0,
|
||||
'min_similarity': 0.5,
|
||||
'prefix_length': 0
|
||||
}
|
||||
},
|
||||
has_child: {
|
||||
'type': '$TYPE$',
|
||||
'score_type': {
|
||||
__one_of: ['none', 'max', 'sum', 'avg']
|
||||
},
|
||||
'_scope': '',
|
||||
'query': {}
|
||||
},
|
||||
has_parent: {
|
||||
'parent_type': '$TYPE$',
|
||||
'score_type': {
|
||||
__one_of: ['none', 'score']
|
||||
},
|
||||
'_scope': '',
|
||||
'query': {}
|
||||
},
|
||||
match_all: {},
|
||||
more_like_this: {
|
||||
__template: {
|
||||
'fields': ['FIELD'],
|
||||
'like_text': 'text like this one',
|
||||
'min_term_freq': 1,
|
||||
'max_query_terms': 12
|
||||
},
|
||||
fields: ['$FIELD$ '],
|
||||
like_text: '',
|
||||
percent_terms_to_match: 0.3,
|
||||
min_term_freq: 2,
|
||||
max_query_terms: 25,
|
||||
stop_words: [''],
|
||||
min_doc_freq: 5,
|
||||
max_doc_freq: 100,
|
||||
min_word_len: 0,
|
||||
max_word_len: 0,
|
||||
boost_terms: 1,
|
||||
boost: 1.0,
|
||||
analyzer: ''
|
||||
},
|
||||
more_like_this_field: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'like_text': 'text like this one',
|
||||
'min_term_freq': 1,
|
||||
'max_query_terms': 12
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
like_text: '',
|
||||
percent_terms_to_match: 0.3,
|
||||
min_term_freq: 2,
|
||||
max_query_terms: 25,
|
||||
stop_words: [''],
|
||||
min_doc_freq: 5,
|
||||
max_doc_freq: 100,
|
||||
min_word_len: 0,
|
||||
max_word_len: 0,
|
||||
boost_terms: 1,
|
||||
boost: 1.0,
|
||||
analyzer: ''
|
||||
}
|
||||
},
|
||||
prefix: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'value': ''
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
value: '',
|
||||
boost: 1.0
|
||||
}
|
||||
},
|
||||
query_string: {
|
||||
__template: {
|
||||
'default_field': 'FIELD',
|
||||
'query': 'this AND that OR thus'
|
||||
},
|
||||
query: '',
|
||||
default_field: '$FIELD$',
|
||||
fields: ['$FIELD$'],
|
||||
default_operator: {
|
||||
__one_of: ['OR', 'AND']
|
||||
},
|
||||
analyzer: '',
|
||||
allow_leading_wildcard: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
lowercase_expanded_terms: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
enable_position_increments: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
fuzzy_max_expansions: 50,
|
||||
fuzzy_min_sim: 0.5,
|
||||
fuzzy_prefix_length: 0,
|
||||
phrase_slop: 0,
|
||||
boost: 1.0,
|
||||
analyze_wildcard: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
auto_generate_phrase_queries: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
minimum_should_match: '20%',
|
||||
lenient: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
use_dis_max: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
tie_breaker: 0
|
||||
},
|
||||
range: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
from: 10,
|
||||
to: 20
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
__template: {
|
||||
from: 10,
|
||||
to: 20
|
||||
},
|
||||
from: 1,
|
||||
to: 20,
|
||||
include_lower: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
include_upper: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
boost: 1.0
|
||||
}
|
||||
},
|
||||
span_first: {
|
||||
__template: {
|
||||
'match': {
|
||||
'span_term': {
|
||||
'FIELD': 'VALUE'
|
||||
}
|
||||
},
|
||||
'end': 3
|
||||
},
|
||||
match: SPAN_QUERIES
|
||||
},
|
||||
span_near: {
|
||||
__template: {
|
||||
'clauses': [{
|
||||
span_term: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
}
|
||||
}],
|
||||
slop: 12,
|
||||
in_order: false
|
||||
},
|
||||
clauses: [
|
||||
SPAN_QUERIES
|
||||
],
|
||||
slop: 12,
|
||||
in_order: {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
collect_payloads: {
|
||||
__one_of: [false, true]
|
||||
}
|
||||
},
|
||||
span_term: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
value: '',
|
||||
boost: 2.0
|
||||
}
|
||||
},
|
||||
span_not: {
|
||||
__template: {
|
||||
include: {
|
||||
span_term: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
}
|
||||
},
|
||||
exclude: {
|
||||
span_term: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
include: SPAN_QUERIES,
|
||||
exclude: SPAN_QUERIES
|
||||
},
|
||||
span_or: {
|
||||
__template: {
|
||||
clauses: [{
|
||||
span_term: {
|
||||
'FIELD': {
|
||||
'value': 'VALUE'
|
||||
}
|
||||
}
|
||||
}]
|
||||
},
|
||||
clauses: [
|
||||
SPAN_QUERIES
|
||||
]
|
||||
},
|
||||
term: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
value: 'VALUE'
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
value: '',
|
||||
boost: 2.0
|
||||
}
|
||||
},
|
||||
terms: {
|
||||
__template: {
|
||||
'FIELD': ['VALUE1', 'VALUE2']
|
||||
},
|
||||
'$FIELD$': [''],
|
||||
minimum_match: 1
|
||||
},
|
||||
top_children: {
|
||||
__template: {
|
||||
type: 'CHILD_TYPE',
|
||||
query: {}
|
||||
},
|
||||
type: '$CHILD_TYPE$',
|
||||
query: {},
|
||||
score: {
|
||||
__one_of: ['max', 'sum', 'avg']
|
||||
},
|
||||
factor: 5,
|
||||
incremental_factor: 2
|
||||
},
|
||||
wildcard: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
value: 'VALUE'
|
||||
}
|
||||
},
|
||||
'$FIELD$': {
|
||||
value: '',
|
||||
boost: 2.0
|
||||
}
|
||||
},
|
||||
nested: {
|
||||
__template: {
|
||||
path: 'path_to_nested_doc',
|
||||
query: {}
|
||||
},
|
||||
path: '',
|
||||
query: {},
|
||||
filter: {},
|
||||
score_mode: {
|
||||
__one_of: ['avg', 'total', 'max', 'none']
|
||||
}
|
||||
},
|
||||
custom_filters_score: {
|
||||
__template: {
|
||||
query: {},
|
||||
filters: [{
|
||||
filter: {}
|
||||
}]
|
||||
},
|
||||
query: {},
|
||||
filters: [{
|
||||
filter: {},
|
||||
boost: 2.0,
|
||||
script: ''
|
||||
}],
|
||||
score_mode: {
|
||||
__one_of: ['first', 'min', 'max', 'total', 'avg', 'multiply']
|
||||
},
|
||||
max_boost: 2.0,
|
||||
params: {},
|
||||
lang: ''
|
||||
},
|
||||
indices: {
|
||||
__template: {
|
||||
indices: ['INDEX1', 'INDEX2'],
|
||||
query: {}
|
||||
},
|
||||
indices: ['$INDEX$'],
|
||||
query: {},
|
||||
no_match_query: {
|
||||
__scope_link: '.query'
|
||||
}
|
||||
},
|
||||
geo_shape: {
|
||||
__template: {
|
||||
location: {},
|
||||
relation: 'within'
|
||||
},
|
||||
__scope_link: '.filter.geo_shape'
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
});
|
86
sense/app/kb/search.js
Normal file
|
@ -0,0 +1,86 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addEndpointDescription('_search', {
|
||||
def_method: 'POST',
|
||||
methods: ['GET', 'POST'],
|
||||
endpoint_autocomplete: [
|
||||
'_search'
|
||||
],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'multi',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
query: {
|
||||
// populated by a global rule
|
||||
},
|
||||
facets: {
|
||||
__template: {
|
||||
'NAME': {
|
||||
'TYPE': {}
|
||||
}
|
||||
}
|
||||
// populated by a global rule
|
||||
},
|
||||
filter: {
|
||||
// added by global rules.
|
||||
},
|
||||
size: {
|
||||
__template: 20
|
||||
},
|
||||
from: {},
|
||||
sort: {
|
||||
__template: [{
|
||||
'FIELD': {
|
||||
'order': 'desc'
|
||||
}
|
||||
}],
|
||||
__any_of: [
|
||||
{
|
||||
'$FIELD$': {
|
||||
'order': {
|
||||
__one_of: ['desc', 'asc']
|
||||
}
|
||||
}
|
||||
},
|
||||
'$FIELD$',
|
||||
'_score'
|
||||
]
|
||||
},
|
||||
search_type: {},
|
||||
fields: ['$FIELD$'],
|
||||
script_fields: {
|
||||
__template: {
|
||||
'FIELD': {
|
||||
'script': ''
|
||||
}
|
||||
},
|
||||
'*': {
|
||||
__scope_link: 'GLOBAL.SCRIPT_ENV'
|
||||
}
|
||||
},
|
||||
partial_fields: {
|
||||
__template: {
|
||||
'NAME': {
|
||||
include: []
|
||||
}
|
||||
},
|
||||
'*': {
|
||||
include: [],
|
||||
exclude: []
|
||||
}
|
||||
},
|
||||
highlight: {
|
||||
// populated by a global rule
|
||||
},
|
||||
explain: {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
stats: ['']
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
72
sense/app/kb/settings.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addEndpointDescription('_settings', {
|
||||
match: /_settings/,
|
||||
methods: ['GET', 'PUT'],
|
||||
endpoint_autocomplete: ['_settings'],
|
||||
indices_mode: 'multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
index: {
|
||||
refresh_interval: '1s',
|
||||
number_of_shards: 5,
|
||||
number_of_replicas: 1,
|
||||
'blocks.read_only': {
|
||||
__one_of: [false, true]
|
||||
},
|
||||
'blocks.read': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'blocks.write': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'blocks.metadata': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
term_index_interval: 32,
|
||||
term_index_divisor: 1,
|
||||
'translog.flush_threshold_ops': 5000,
|
||||
'translog.flush_threshold_size': '200mb',
|
||||
'translog.flush_threshold_period': '30m',
|
||||
'translog.disable_flush': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
'cache.filter.max_size': '2gb',
|
||||
'cache.filter.expire': '2h',
|
||||
'gateway.snapshot_interval': '10s',
|
||||
routing: {
|
||||
allocation: {
|
||||
include: {
|
||||
tag: ''
|
||||
},
|
||||
exclude: {
|
||||
tag: ''
|
||||
},
|
||||
require: {
|
||||
tag: ''
|
||||
},
|
||||
total_shards_per_node: -1
|
||||
}
|
||||
},
|
||||
'recovery.initial_shards': {
|
||||
__one_of: ['quorum', 'quorum-1', 'half', 'full', 'full-1']
|
||||
},
|
||||
'ttl.disable_purge': {
|
||||
__one_of: [true, false]
|
||||
},
|
||||
analysis: {
|
||||
analyzer: {},
|
||||
tokenizer: {},
|
||||
filter: {},
|
||||
char_filter: {}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
24
sense/app/kb/templates.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addEndpointDescription('_template', {
|
||||
match: /\/?_template/,
|
||||
def_method: 'PUT',
|
||||
methods: ['GET', 'PUT', 'DELETE'],
|
||||
endpoint_autocomplete: [
|
||||
'_template/TEMPLATE_ID'
|
||||
],
|
||||
indices_mode: 'none',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
template: 'index*',
|
||||
warmers: { __scope_link: '_warmer' },
|
||||
mappings: {},
|
||||
settings: {}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
26
sense/app/kb/warmers.js
Normal file
|
@ -0,0 +1,26 @@
|
|||
define(function () {
|
||||
'use strict';
|
||||
|
||||
return function init(kb) {
|
||||
kb.addEndpointDescription('_warmer', {
|
||||
match: /_warmer/,
|
||||
def_method: 'PUT',
|
||||
methods: ['GET', 'PUT', 'DELETE'],
|
||||
endpoint_autocomplete: [
|
||||
'_warmer', '_warmer/WARMER_ID'
|
||||
],
|
||||
indices_mode: 'required_multi',
|
||||
types_mode: 'none',
|
||||
doc_id_mode: 'none',
|
||||
data_autocomplete_rules: {
|
||||
query: {
|
||||
// populated by a global rule
|
||||
},
|
||||
facets: {
|
||||
// populated by a global rule
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
});
|
232
sense/app/mappings.js
Normal file
|
@ -0,0 +1,232 @@
|
|||
define([
|
||||
'jquery',
|
||||
'utils'
|
||||
], function ($, utils) {
|
||||
'use strict';
|
||||
|
||||
var currentServer;
|
||||
var per_index_types = {};
|
||||
var per_alias_indexes = [];
|
||||
|
||||
function expandAliases(indicesOrAliases) {
|
||||
// takes a list of indices or aliases or a string which may be either and returns a list of indices
|
||||
// returns a list for multiple values or a string for a single.
|
||||
|
||||
if (!indicesOrAliases) return indicesOrAliases;
|
||||
|
||||
if (typeof indicesOrAliases === "string") indicesOrAliases = [indicesOrAliases];
|
||||
indicesOrAliases = $.map(indicesOrAliases, function (iOrA) {
|
||||
if (per_alias_indexes[iOrA]) return per_alias_indexes[iOrA];
|
||||
return [iOrA];
|
||||
});
|
||||
var ret = [].concat.apply([], indicesOrAliases);
|
||||
ret.sort();
|
||||
var last;
|
||||
ret = $.map(ret, function (v) {
|
||||
var r = last == v ? null : v;
|
||||
last = v;
|
||||
return r;
|
||||
});
|
||||
return ret.length > 1 ? ret : ret[0];
|
||||
}
|
||||
|
||||
function getFields(indices, types) {
|
||||
// get fields for indices and types. Both can be a list, a string or null (meaning all).
|
||||
var ret = [];
|
||||
indices = expandAliases(indices);
|
||||
if (typeof indices == "string") {
|
||||
|
||||
var type_dict = per_index_types[indices];
|
||||
if (!type_dict) return [];
|
||||
|
||||
if (typeof types == "string") {
|
||||
var f = type_dict[types];
|
||||
ret = f ? f : [];
|
||||
}
|
||||
else {
|
||||
// filter what we need
|
||||
$.each(type_dict, function (type, fields) {
|
||||
if (!types || types.length == 0 || $.inArray(type, types) != -1)
|
||||
ret.push(fields);
|
||||
});
|
||||
|
||||
ret = [].concat.apply([], ret);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// multi index mode.
|
||||
$.each(per_index_types, function (index) {
|
||||
if (!indices || indices.length == 0 || $.inArray(index, indices) != -1)
|
||||
ret.push(getFields(index, types));
|
||||
});
|
||||
ret = [].concat.apply([], ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function getTypes(indices) {
|
||||
var ret = [];
|
||||
indices = expandAliases(indices);
|
||||
if (typeof indices == "string") {
|
||||
var type_dict = per_index_types[indices];
|
||||
if (!type_dict) return [];
|
||||
|
||||
// filter what we need
|
||||
$.each(type_dict, function (type, fields) {
|
||||
ret.push(type);
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
// multi index mode.
|
||||
$.each(per_index_types, function (index) {
|
||||
if (!indices || $.inArray(index, indices) != -1)
|
||||
ret.push(getTypes(index));
|
||||
});
|
||||
ret = [].concat.apply([], ret);
|
||||
}
|
||||
|
||||
return ret.filter(function (v, i, a) {
|
||||
return a.indexOf(v) == i
|
||||
}); // dedupe array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getIndices(include_aliases) {
|
||||
var ret = [];
|
||||
$.each(per_index_types, function (index) {
|
||||
ret.push(index);
|
||||
});
|
||||
if (typeof include_aliases === "undefined" ? true : include_aliases) {
|
||||
$.each(per_alias_indexes, function (alias) {
|
||||
ret.push(alias);
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function getFieldNamesFromFieldMapping(field_name, field_mapping) {
|
||||
if (field_mapping['enabled'] == false) return [];
|
||||
var nested_fields;
|
||||
|
||||
function applyPathSettings(nested_field_names) {
|
||||
var path_type = field_mapping['path'] || "full";
|
||||
if (path_type == "full") {
|
||||
return $.map(nested_field_names, function (f) {
|
||||
return field_name + "." + f;
|
||||
});
|
||||
}
|
||||
return nested_field_names;
|
||||
}
|
||||
|
||||
if (field_mapping["properties"]) {
|
||||
// derived object type
|
||||
nested_fields = getFieldNamesFromTypeMapping(field_mapping);
|
||||
return applyPathSettings(nested_fields);
|
||||
}
|
||||
|
||||
if (field_mapping['type'] == 'multi_field') {
|
||||
nested_fields = $.map(field_mapping['fields'], function (field_mapping, field_name) {
|
||||
return getFieldNamesFromFieldMapping(field_name, field_mapping);
|
||||
});
|
||||
|
||||
return applyPathSettings(nested_fields);
|
||||
}
|
||||
|
||||
if (field_mapping["index_name"]) return [field_mapping["index_name"]];
|
||||
|
||||
return [field_name];
|
||||
}
|
||||
|
||||
function getFieldNamesFromTypeMapping(type_mapping) {
|
||||
var field_list =
|
||||
$.map(type_mapping['properties'], function (field_mapping, field_name) {
|
||||
return getFieldNamesFromFieldMapping(field_name, field_mapping);
|
||||
});
|
||||
|
||||
// deduping
|
||||
var last;
|
||||
field_list.sort();
|
||||
return $.map(field_list, function (f) {
|
||||
var r = (f === last) ? null : f;
|
||||
last = f;
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
function loadMappings(mappings) {
|
||||
per_index_types = {};
|
||||
$.each(mappings, function (index, index_mapping) {
|
||||
var normalized_index_mappings = {};
|
||||
$.each(index_mapping, function (type_name, type_mapping) {
|
||||
var field_list = getFieldNamesFromTypeMapping(type_mapping);
|
||||
normalized_index_mappings[type_name] = field_list;
|
||||
});
|
||||
per_index_types[index] = normalized_index_mappings;
|
||||
});
|
||||
}
|
||||
|
||||
function loadAliases(aliases) {
|
||||
per_alias_indexes = {}
|
||||
$.each(aliases, function (index, index_aliases) {
|
||||
$.each(index_aliases.aliases, function (alias) {
|
||||
if (alias === index) return; // alias which is identical to index means no index.
|
||||
var cur_aliases = per_alias_indexes[alias];
|
||||
if (!cur_aliases) {
|
||||
cur_aliases = [];
|
||||
per_alias_indexes[alias] = cur_aliases;
|
||||
}
|
||||
cur_aliases.push(index);
|
||||
});
|
||||
});
|
||||
|
||||
per_alias_indexes['_all'] = getIndices(false);
|
||||
}
|
||||
|
||||
function clear() {
|
||||
per_index_types = {};
|
||||
per_alias_indexes = {};
|
||||
}
|
||||
|
||||
function retrieveMappingFromServer() {
|
||||
if (!currentServer) return;
|
||||
utils.callES(currentServer, "_mapping", "GET", null, function (data, status, xhr) {
|
||||
loadMappings(data);
|
||||
});
|
||||
utils.callES(currentServer, "_aliases", "GET", null, function (data, status, xhr) {
|
||||
loadAliases(data);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function notifyServerChange(newServer) {
|
||||
if (newServer.indexOf("://") < 0) newServer = "http://" + newServer;
|
||||
newServer = newServer.trim("/");
|
||||
if (newServer === currentServer) return; // already have it.
|
||||
currentServer = newServer;
|
||||
retrieveMappingFromServer();
|
||||
}
|
||||
|
||||
function mapping_retriever() {
|
||||
retrieveMappingFromServer();
|
||||
setTimeout(function () {
|
||||
mapping_retriever();
|
||||
}, 60000);
|
||||
}
|
||||
|
||||
mapping_retriever();
|
||||
|
||||
return {
|
||||
getFields: getFields,
|
||||
getIndices: getIndices,
|
||||
getTypes: getTypes,
|
||||
loadMappings: loadMappings,
|
||||
loadAliases: loadAliases,
|
||||
expandAliases: expandAliases,
|
||||
clear: clear,
|
||||
notifyServerChange: notifyServerChange
|
||||
};
|
||||
|
||||
});
|
40
sense/app/misc_inputs.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
define([
|
||||
'jquery',
|
||||
'history',
|
||||
'input',
|
||||
'mappings',
|
||||
|
||||
'bootstrap',
|
||||
'jquery-ui'
|
||||
], function ($, history, input, mappings) {
|
||||
'use strict';
|
||||
|
||||
var $esServer = $("#es_server");
|
||||
|
||||
$esServer.blur(function () {
|
||||
mappings.notifyServerChange($esServer.val());
|
||||
});
|
||||
|
||||
// initialize auto complete
|
||||
$esServer.autocomplete({
|
||||
minLength: 0,
|
||||
source: []
|
||||
});
|
||||
|
||||
$esServer.focus(function () {
|
||||
$esServer.autocomplete("option", "source", history.getHistoricalServers());
|
||||
});
|
||||
|
||||
var $send = $("#send").tooltip();
|
||||
|
||||
var $autoIndent = $("#auto_indent").click(function (e) {
|
||||
input.autoIndent();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
return {
|
||||
$esServer: $esServer,
|
||||
$send: $send,
|
||||
$autoIndent: $autoIndent
|
||||
};
|
||||
})
|
24
sense/app/output.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
define([
|
||||
'ace',
|
||||
'jquery'
|
||||
], function (ace, $) {
|
||||
'use strict';
|
||||
|
||||
var output = ace.edit("output");
|
||||
|
||||
output.update = function (val, cb) {
|
||||
output.getSession().setValue(val);
|
||||
if (typeof cb === 'function') {
|
||||
setTimeout(cb);
|
||||
}
|
||||
};
|
||||
|
||||
output.$el = $('#output');
|
||||
output.getSession().setMode("ace/mode/json");
|
||||
output.getSession().setFoldStyle('markbeginend');
|
||||
output.getSession().setUseWrapMode(true);
|
||||
output.setShowPrintMargin(false);
|
||||
output.setReadOnly(true);
|
||||
|
||||
return output;
|
||||
})
|
39
sense/app/require.config.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Bootstrap require with the needed config
|
||||
*/
|
||||
require.config({
|
||||
baseUrl: 'app',
|
||||
paths: {
|
||||
_: '../vendor/lodash',
|
||||
ace: '../vendor/ace/ace',
|
||||
bootstrap: '../vendor/bootstrap/js/bootstrap',
|
||||
jquery: '../vendor/jquery/jquery-1.8.3',
|
||||
'jquery-ui': '../vendor/jquery/jquery-ui-1.9.2.custom.min',
|
||||
moment: '../vendor/moment',
|
||||
zeroclip: '../vendor/zero_clipboard/zero_clipboard',
|
||||
},
|
||||
map: {
|
||||
'*': {
|
||||
css: '../vendor/require/css/css'
|
||||
}
|
||||
},
|
||||
shim: {
|
||||
jquery: {
|
||||
exports: 'jQuery'
|
||||
},
|
||||
'bootstrap': {
|
||||
deps: ['jquery'],
|
||||
},
|
||||
'jquery-ui': {
|
||||
deps: ['jquery', 'css!../vendor/jquery/jquery-ui-1.9.2.custom.min.css']
|
||||
},
|
||||
ace: {
|
||||
exports: 'ace'
|
||||
}
|
||||
},
|
||||
waitSeconds: 60,
|
||||
});
|
||||
})();
|
397
sense/app/sense_editor/editor.js
Normal file
|
@ -0,0 +1,397 @@
|
|||
define([
|
||||
'_',
|
||||
'ace',
|
||||
'analytics',
|
||||
'curl',
|
||||
'jquery',
|
||||
'sense_editor/row_parser',
|
||||
'utils'
|
||||
], function (_, ace, _gaq, curl, $, RowParser, utils) {
|
||||
'use strict';
|
||||
|
||||
function isInt(x) {
|
||||
return !isNaN(parseInt(x, 10));
|
||||
}
|
||||
|
||||
function createInstance($el) {
|
||||
var aceEditor = ace.edit($el[0]);
|
||||
|
||||
// we must create a custom class for each instance, so that the prototype
|
||||
// can be the unique aceEditor it extends
|
||||
var CustomSenseEditor = function () {};
|
||||
CustomSenseEditor.prototype = {};
|
||||
|
||||
function bindProp(key) {
|
||||
Object.defineProperty(CustomSenseEditor.prototype, key, {
|
||||
get: function () {
|
||||
return aceEditor[key];
|
||||
},
|
||||
set: function (val) {
|
||||
aceEditor[key] = val;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// itterate all of the accessible properties/method, on the prototype and beyond
|
||||
for (var key in aceEditor) {
|
||||
switch (typeof aceEditor[key]) {
|
||||
case 'function':
|
||||
CustomSenseEditor.prototype[key] = _.bindKey(aceEditor, key);
|
||||
break;
|
||||
default:
|
||||
bindProp(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var editor = new CustomSenseEditor();
|
||||
editor.__ace = aceEditor;
|
||||
return editor;
|
||||
}
|
||||
|
||||
function SenseEditor($el) {
|
||||
var editor = createInstance($el);
|
||||
var CURRENT_REQ_RANGE = null;
|
||||
|
||||
editor.$el = $el;
|
||||
editor.$actions = $("#editor_actions");
|
||||
|
||||
// mixin the RowParser
|
||||
editor.parser = new RowParser(editor);
|
||||
|
||||
// dirty check for tokenizer state, uses a lot less cylces
|
||||
// than listening for tokenizerUpdate
|
||||
var onceDoneTokenizing = function (func, cancelAlreadyScheduledCalls) {
|
||||
var session = editor.getSession();
|
||||
var timer = false;
|
||||
var checkInterval = 25;
|
||||
|
||||
return function () {
|
||||
var self = this;
|
||||
var args = [].slice.call(arguments, 0);
|
||||
|
||||
if (cancelAlreadyScheduledCalls) {
|
||||
timer = clearTimeout(timer);
|
||||
}
|
||||
|
||||
setTimeout(function check () {
|
||||
if (session.bgTokenizer.running) {
|
||||
timer = setTimeout(check, checkInterval);
|
||||
} else {
|
||||
func.apply(self, args);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
ace.require("ace/mode/sense");
|
||||
editor.setShowPrintMargin(false);
|
||||
(function (session) {
|
||||
session.setMode("ace/mode/sense");
|
||||
session.setFoldStyle('markbeginend');
|
||||
session.setTabSize(2);
|
||||
session.setUseWrapMode(true);
|
||||
})(editor.getSession())
|
||||
|
||||
editor.prevRequestStart = function (pos) {
|
||||
pos = pos || editor.getCursorPosition();
|
||||
var curRow = pos.row;
|
||||
while (curRow > 0 && !editor.parser.isStartRequestRow(curRow, editor)) curRow--;
|
||||
|
||||
return { row: curRow, column: 0};
|
||||
};
|
||||
|
||||
editor.autoIndent = onceDoneTokenizing(function () {
|
||||
editor.getCurrentRequestRange(function (req_range) {
|
||||
if (!req_range) return;
|
||||
editor.getCurrentRequest(function (parsed_req) {
|
||||
if (parsed_req.data && parsed_req.data.length > 0) {
|
||||
var indent = parsed_req.data.length == 1; // unindent multi docs by default
|
||||
var formatted_data = utils.reformatData(parsed_req.data, indent);
|
||||
if (!formatted_data.changed) {
|
||||
// toggle.
|
||||
formatted_data = utils.reformatData(parsed_req.data, !indent);
|
||||
}
|
||||
parsed_req.data = formatted_data.data;
|
||||
|
||||
editor.replaceRequestRange(parsed_req, req_range);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
editor.update = function (data, callback) {
|
||||
callback = typeof callback === 'function' ? callback : null;
|
||||
var session = editor.getSession();
|
||||
|
||||
if (callback) {
|
||||
session.on('tokenizerUpdate', function onTokenizerUpdate() {
|
||||
session.removeListener('tokenizerUpdate', onTokenizerUpdate);
|
||||
if (session.bgTokenizer.running) {
|
||||
setTimeout(onTokenizerUpdate, 50); // poll until done
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
session.setValue(data);
|
||||
};
|
||||
|
||||
editor.replaceRequestRange = function (newRequest, requestRange) {
|
||||
var text = utils.textFromRequest(newRequest);
|
||||
if (requestRange) {
|
||||
editor.getSession().replace(requestRange, text);
|
||||
}
|
||||
else {
|
||||
// just insert where we are
|
||||
editor.insert(text);
|
||||
}
|
||||
};
|
||||
|
||||
editor.iterForCurrentLoc = function () {
|
||||
var pos = editor.getCursorPosition();
|
||||
return editor.iterForPosition(pos.row, pos.column, editor);
|
||||
};
|
||||
|
||||
editor.iterForPosition = function (row, column) {
|
||||
return new (ace.require("ace/token_iterator").TokenIterator)(editor.getSession(), row, column);
|
||||
};
|
||||
|
||||
editor.getCurrentRequestRange = onceDoneTokenizing(function (cb) {
|
||||
if (typeof cb !== 'function') return;
|
||||
|
||||
if (editor.parser.isInBetweenRequestsRow(null)) {
|
||||
cb(null);
|
||||
return
|
||||
}
|
||||
|
||||
var reqStart = editor.prevRequestStart(null, editor);
|
||||
var reqEnd = editor.nextRequestEnd(reqStart, editor);
|
||||
cb(new (ace.require("ace/range").Range)(
|
||||
reqStart.row, reqStart.column,
|
||||
reqEnd.row, reqEnd.column
|
||||
));
|
||||
});
|
||||
|
||||
editor.getCurrentRequest = onceDoneTokenizing(function (cb) {
|
||||
if (typeof cb !== 'function') return;
|
||||
if (editor.parser.isInBetweenRequestsRow(null)) {
|
||||
cb(null);
|
||||
return;
|
||||
}
|
||||
|
||||
var request = {
|
||||
method: "",
|
||||
data: [],
|
||||
url: null
|
||||
};
|
||||
|
||||
editor.getCurrentRequestRange(function (currentReqRange) {
|
||||
var pos = currentReqRange.start;
|
||||
var tokenIter = editor.iterForPosition(pos.row, pos.column, editor);
|
||||
var t = tokenIter.getCurrentToken();
|
||||
request.method = t.value;
|
||||
t = editor.parser.nextNonEmptyToken(tokenIter);
|
||||
if (!t || t.type == "method") return null;
|
||||
request.url = "";
|
||||
while (t && t.type && t.type.indexOf("url") == 0) {
|
||||
request.url += t.value;
|
||||
t = tokenIter.stepForward();
|
||||
}
|
||||
|
||||
var bodyStartRow = (t ? 0 : 1) + tokenIter.getCurrentTokenRow(); // artificially increase end of docs.
|
||||
var bodyStartColumn = 0;
|
||||
var dataEndPos;
|
||||
while (bodyStartRow < currentReqRange.end.row
|
||||
|| (
|
||||
bodyStartRow == currentReqRange.end.row
|
||||
&& bodyStartColumn < currentReqRange.end.column
|
||||
)
|
||||
) {
|
||||
dataEndPos = editor.nextDataDocEnd({ row: bodyStartRow, column: bodyStartColumn});
|
||||
var bodyRange = new (ace.require("ace/range").Range)(
|
||||
bodyStartRow, bodyStartColumn,
|
||||
dataEndPos.row, dataEndPos.column
|
||||
);
|
||||
var data = editor.getSession().getTextRange(bodyRange);
|
||||
request.data.push(data.trim());
|
||||
bodyStartRow = dataEndPos.row + 1;
|
||||
bodyStartColumn = 0;
|
||||
}
|
||||
|
||||
cb(request);
|
||||
});
|
||||
});
|
||||
|
||||
editor.moveToPreviousRequestEdge = onceDoneTokenizing(function () {
|
||||
var pos = editor.getCursorPosition();
|
||||
for (pos.row--; pos.row > 0 && !editor.parser.isRequestEdge(pos.row); pos.row--) {
|
||||
}
|
||||
editor.moveCursorTo(pos.row, 0);
|
||||
});
|
||||
|
||||
editor.moveToNextRequestEdge = onceDoneTokenizing(function () {
|
||||
var pos = editor.getCursorPosition();
|
||||
var maxRow = editor.getSession().getLength();
|
||||
for (pos.row++; pos.row < maxRow && !editor.parser.isRequestEdge(pos.row); pos.row++) {
|
||||
}
|
||||
editor.moveCursorTo(pos.row, 0);
|
||||
});
|
||||
|
||||
editor.nextRequestEnd = function (pos) {
|
||||
pos = pos || editor.getCursorPosition();
|
||||
var session = editor.getSession();
|
||||
var curRow = pos.row;
|
||||
var maxLines = session.getLength();
|
||||
for (; curRow < maxLines - 1; curRow++) {
|
||||
var curRowMode = editor.parser.getRowParseMode(curRow, editor);
|
||||
if ((curRowMode & RowParser.MODE_REQUEST_END) > 0) break;
|
||||
if (curRow != pos.row && (curRowMode & RowParser.MODE_REQUEST_START) > 0) break;
|
||||
}
|
||||
|
||||
var column = (session.getLine(curRow) || "").length;
|
||||
|
||||
return { row: curRow, column: column};
|
||||
};
|
||||
|
||||
editor.nextDataDocEnd = function (pos) {
|
||||
pos = pos || editor.getCursorPosition();
|
||||
var session = editor.getSession();
|
||||
var curRow = pos.row;
|
||||
var maxLines = session.getLength();
|
||||
for (; curRow < maxLines - 1; curRow++) {
|
||||
var curRowMode = editor.parser.getRowParseMode(curRow, editor);
|
||||
if ((curRowMode & RowParser.REQUEST_END) > 0) {
|
||||
break;
|
||||
}
|
||||
if ((curRowMode & RowParser.MODE_MULTI_DOC_CUR_DOC_END) > 0) break;
|
||||
if (curRow != pos.row && (curRowMode & RowParser.MODE_REQUEST_START) > 0) break;
|
||||
}
|
||||
|
||||
var column = (session.getLine(curRow) || "").length;
|
||||
|
||||
return { row: curRow, column: column };
|
||||
};
|
||||
|
||||
// overwrite the actual aceEditor's onPaste method
|
||||
var origOnPaste = editor.__ace.onPaste;
|
||||
editor.__ace.onPaste = function (text) {
|
||||
if (text && curl.detectCURL(text)) {
|
||||
editor.handleCURLPaste(text);
|
||||
return;
|
||||
}
|
||||
origOnPaste.call(null, text);
|
||||
};
|
||||
|
||||
editor.handleCURLPaste = function (text) {
|
||||
_gaq.push(['_trackEvent', "curl", 'pasted']);
|
||||
var curlInput = curl.parseCURL(text);
|
||||
if ($("#es_server").val()) curlInput.server = null; // do not override server
|
||||
|
||||
if (!curlInput.method) curlInput.method = "GET";
|
||||
|
||||
editor.insert(utils.textFromRequest(curlInput));
|
||||
};
|
||||
|
||||
editor.highlightCurrentRequestAndUpdateActionBar = onceDoneTokenizing(function () {
|
||||
var session = editor.getSession();
|
||||
editor.getCurrentRequestRange(function (new_current_req_range) {
|
||||
if (new_current_req_range == null && CURRENT_REQ_RANGE == null) return;
|
||||
if (new_current_req_range != null && CURRENT_REQ_RANGE != null &&
|
||||
new_current_req_range.start.row == CURRENT_REQ_RANGE.start.row &&
|
||||
new_current_req_range.end.row == CURRENT_REQ_RANGE.end.row
|
||||
) {
|
||||
// same request, now see if we are on the first line and update the action bar
|
||||
var cursorRow = editor.getCursorPosition().row;
|
||||
if (cursorRow == CURRENT_REQ_RANGE.start.row) {
|
||||
editor.updateActionsBar();
|
||||
}
|
||||
return; // nothing to do..
|
||||
}
|
||||
|
||||
if (CURRENT_REQ_RANGE) {
|
||||
session.removeMarker(CURRENT_REQ_RANGE.marker_id);
|
||||
}
|
||||
|
||||
CURRENT_REQ_RANGE = new_current_req_range;
|
||||
if (CURRENT_REQ_RANGE) {
|
||||
CURRENT_REQ_RANGE.marker_id = session.addMarker(CURRENT_REQ_RANGE, "ace_snippet-marker", "fullLine");
|
||||
}
|
||||
editor.updateActionsBar();
|
||||
});
|
||||
}, true);
|
||||
|
||||
editor.getCurrentRequestAsCURL = function (cb) {
|
||||
cb = typeof cb === 'function' ? cb : $.noop;
|
||||
editor.getCurrentRequest(function (req) {
|
||||
if (!req) return;
|
||||
|
||||
var es_server = $("#es_server").val(),
|
||||
es_url = req.url,
|
||||
es_method = req.method,
|
||||
es_data = req.data;
|
||||
|
||||
var url = utils.constructESUrl(es_server, es_url);
|
||||
|
||||
var curl = 'curl -X' + es_method + ' "' + url + '"';
|
||||
if (es_data && es_data.length) {
|
||||
curl += " -d'\n";
|
||||
// since Sense doesn't allow single quote json string any single qoute is within a string.
|
||||
curl += es_data.join("\n").replace(/'/g, '\\"');
|
||||
if (es_data.length > 1) curl += "\n"; // end with a new line
|
||||
curl += "'";
|
||||
}
|
||||
|
||||
cb(curl);
|
||||
});
|
||||
};
|
||||
|
||||
editor.getSession().on('tokenizerUpdate', function (e) {
|
||||
editor.highlightCurrentRequestAndUpdateActionBar();
|
||||
});
|
||||
|
||||
editor.getSession().selection.on('changeCursor', function (e) {
|
||||
editor.highlightCurrentRequestAndUpdateActionBar();
|
||||
});
|
||||
|
||||
editor.updateActionsBar = function () {
|
||||
var editor_actions = $("#editor_actions");
|
||||
|
||||
if (CURRENT_REQ_RANGE) {
|
||||
var row = CURRENT_REQ_RANGE.start.row;
|
||||
var column = CURRENT_REQ_RANGE.start.column;
|
||||
var session = editor.session;
|
||||
var firstLine = session.getLine(row);
|
||||
var offset = 0;
|
||||
if (firstLine.length > session.getScreenWidth() - 5) {
|
||||
// overlap first row
|
||||
if (row > 0) row--; else row++;
|
||||
}
|
||||
var screen_pos = editor.renderer.textToScreenCoordinates(row, column);
|
||||
offset += screen_pos.pageY;
|
||||
var end_offset = editor.renderer.textToScreenCoordinates(CURRENT_REQ_RANGE.end.row,
|
||||
CURRENT_REQ_RANGE.end.column).pageY;
|
||||
|
||||
offset = Math.min(end_offset, Math.max(offset, 47));
|
||||
if (offset >= 47) {
|
||||
editor_actions.css("top", Math.max(offset, 47));
|
||||
editor_actions.css('visibility', 'visible');
|
||||
}
|
||||
else {
|
||||
editor_actions.css("top", 0);
|
||||
editor_actions.css('visibility', 'hidden');
|
||||
}
|
||||
}
|
||||
else {
|
||||
editor_actions.css("top", 0);
|
||||
editor_actions.css('visibility', 'hidden');
|
||||
}
|
||||
};
|
||||
|
||||
editor.getSession().on("changeScrollTop", editor.updateActionsBar);
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
return SenseEditor;
|
||||
})
|
114
sense/app/sense_editor/row_parser.js
Normal file
|
@ -0,0 +1,114 @@
|
|||
define([], function () {
|
||||
'use strict';
|
||||
|
||||
function RowParser(editor) {
|
||||
var defaultEditor = editor;
|
||||
|
||||
this.getRowParseMode = function (row) {
|
||||
if (row == null || typeof row == "undefined") row = editor.getCursorPosition().row;
|
||||
|
||||
var session = editor.getSession();
|
||||
if (row >= session.getLength()) return RowParser.MODE_BETWEEN_REQUESTS;
|
||||
var mode = (session.getState(row) || {}).name;
|
||||
if (!mode)
|
||||
return RowParser.MODE_BETWEEN_REQUESTS; // shouldn't really happen
|
||||
|
||||
|
||||
if (mode != "start") return RowParser.MODE_IN_REQUEST;
|
||||
var line = (session.getLine(row) || "").trim();
|
||||
if (!line || line[0] === '#') return RowParser.MODE_BETWEEN_REQUESTS; // empty line or a comment waiting for a new req to start
|
||||
|
||||
if (line.indexOf("}", line.length - 1) >= 0) {
|
||||
// check for a multi doc request (must start a new json doc immediately after this one end.
|
||||
row++;
|
||||
if (row < session.getLength()) {
|
||||
line = (session.getLine(row) || "").trim();
|
||||
if (line.indexOf("{") === 0) { // next line is another doc in a multi doc
|
||||
return RowParser.MODE_MULTI_DOC_CUR_DOC_END | RowParser.MODE_IN_REQUEST;
|
||||
}
|
||||
|
||||
}
|
||||
return RowParser.MODE_REQUEST_END | RowParser.MODE_MULTI_DOC_CUR_DOC_END; // end of request
|
||||
}
|
||||
|
||||
// check for single line requests
|
||||
row++;
|
||||
if (row >= session.getLength()) {
|
||||
return RowParser.MODE_REQUEST_START | RowParser.MODE_REQUEST_END;
|
||||
}
|
||||
line = (session.getLine(row) || "").trim();
|
||||
if (line.indexOf("{") !== 0) { // next line is another request
|
||||
return RowParser.MODE_REQUEST_START | RowParser.MODE_REQUEST_END;
|
||||
}
|
||||
|
||||
return RowParser.MODE_REQUEST_START;
|
||||
}
|
||||
|
||||
this.rowPredicate = function (row, editor, value) {
|
||||
var mode = this.getRowParseMode(row, editor);
|
||||
return (mode & value) > 0;
|
||||
}
|
||||
|
||||
this.isEndRequestRow = function (row, _e) {
|
||||
var editor = _e || defaultEditor;
|
||||
return this.rowPredicate(row, editor, RowParser.MODE_REQUEST_END);
|
||||
};
|
||||
|
||||
this.isRequestEdge = function (row, _e) {
|
||||
var editor = _e || defaultEditor;
|
||||
return this.rowPredicate(row, editor, RowParser.MODE_REQUEST_END | RowParser.MODE_REQUEST_START);
|
||||
};
|
||||
|
||||
this.isStartRequestRow = function (row, _e) {
|
||||
var editor = _e || defaultEditor;
|
||||
return this.rowPredicate(row, editor, RowParser.MODE_REQUEST_START);
|
||||
};
|
||||
|
||||
this.isInBetweenRequestsRow = function (row, _e) {
|
||||
var editor = _e || defaultEditor;
|
||||
return this.rowPredicate(row, editor, RowParser.MODE_BETWEEN_REQUESTS);
|
||||
};
|
||||
|
||||
this.isInRequestsRow = function (row, _e) {
|
||||
var editor = _e || defaultEditor;
|
||||
return this.rowPredicate(row, editor, RowParser.MODE_IN_REQUEST);
|
||||
};
|
||||
|
||||
this.isMultiDocDocEndRow = function (row, _e) {
|
||||
var editor = _e || defaultEditor;
|
||||
return this.rowPredicate(row, editor, RowParser.MODE_MULTI_DOC_CUR_DOC_END);
|
||||
};
|
||||
|
||||
this.isEmptyToken = function (tokenOrTokenIter) {
|
||||
var token = tokenOrTokenIter && tokenOrTokenIter.getCurrentToken ? tokenOrTokenIter.getCurrentToken() : tokenOrTokenIter;
|
||||
return !token || token.type == "whitespace"
|
||||
};
|
||||
|
||||
this.isUrlOrMethodToken = function (tokenOrTokenIter) {
|
||||
var t = tokenOrTokenIter.getCurrentToken ? tokenOrTokenIter.getCurrentToken() : tokenOrTokenIter;
|
||||
return t && t.type && (t.type == "method" || t.type.indexOf("url") === 0);
|
||||
};
|
||||
|
||||
|
||||
this.nextNonEmptyToken = function (tokenIter) {
|
||||
var t = tokenIter.stepForward();
|
||||
while (t && this.isEmptyToken(t)) t = tokenIter.stepForward();
|
||||
return t;
|
||||
};
|
||||
|
||||
this.prevNonEmptyToken = function (tokenIter) {
|
||||
var t = tokenIter.stepBackward();
|
||||
// empty rows return null token.
|
||||
while ((t || tokenIter.getCurrentTokenRow() > 0) && this.isEmptyToken(t)) t = tokenIter.stepBackward();
|
||||
return t;
|
||||
};
|
||||
}
|
||||
|
||||
RowParser.MODE_REQUEST_START = 2;
|
||||
RowParser.MODE_IN_REQUEST = 4;
|
||||
RowParser.MODE_MULTI_DOC_CUR_DOC_END = 8;
|
||||
RowParser.MODE_REQUEST_END = 16;
|
||||
RowParser.MODE_BETWEEN_REQUESTS = 32;
|
||||
|
||||
return RowParser;
|
||||
})
|
88
sense/app/settings.js
Normal file
|
@ -0,0 +1,88 @@
|
|||
define([
|
||||
'input',
|
||||
'output',
|
||||
'jquery'
|
||||
], function (input, output, $) {
|
||||
'use strict';
|
||||
|
||||
function getFontSize() {
|
||||
return localStorage.getItem("font_size") || "12";
|
||||
}
|
||||
|
||||
function setFontSize(size) {
|
||||
if (!/^([1-9]\d*)$/.test(size)) return false;
|
||||
localStorage.setItem("font_size", size);
|
||||
$("#editor").css("font-size", size + "px");
|
||||
$("#output").css("font-size", size + "px");
|
||||
return true;
|
||||
}
|
||||
|
||||
function getWrapMode() {
|
||||
var mode = localStorage.getItem("wrap_mode") || "true";
|
||||
return mode == "true";
|
||||
}
|
||||
|
||||
function setWrapMode(mode) {
|
||||
if (typeof mode !== "boolean") return false;
|
||||
localStorage.setItem("wrap_mode", mode);
|
||||
|
||||
input.getSession().setUseWrapMode(mode);
|
||||
output.getSession().setUseWrapMode(mode);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function getTheme() {
|
||||
var mode = localStorage.getItem("theme") || "light";
|
||||
return mode;
|
||||
}
|
||||
|
||||
function setTheme(mode) {
|
||||
localStorage.setItem("theme", mode);
|
||||
|
||||
$("#bootstrapThemeCss").attr("href", "vendor/bootstrap/css/bootstrap." + mode + ".min.css");
|
||||
$("#senseThemeCss").attr("href", "css/sense." + mode + ".css");
|
||||
|
||||
var aceTheme = mode === "light" ? "" : "ace/theme/sense-dark";
|
||||
input.setTheme(aceTheme);
|
||||
output.setTheme(aceTheme);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
var settings_popup = $("#settings_popup");
|
||||
|
||||
var font_size_ctl = settings_popup.find("#font_size");
|
||||
var fs = getFontSize();
|
||||
font_size_ctl.val(fs);
|
||||
setFontSize(fs);
|
||||
|
||||
var wrap_mode_ctl = settings_popup.find("#wrap_mode");
|
||||
var wm = getWrapMode();
|
||||
wrap_mode_ctl.prop('checked', wm);
|
||||
setWrapMode(wm);
|
||||
|
||||
var theme_ctl = settings_popup.find("#theme");
|
||||
var theme = getTheme();
|
||||
theme_ctl.val(theme);
|
||||
setTheme(theme);
|
||||
|
||||
function save() {
|
||||
if (!setFontSize(font_size_ctl.val())) font_size_ctl.val(getFontSize());
|
||||
if (!setWrapMode(wrap_mode_ctl.prop("checked"))) wrap_mode_ctl.prop('checked', getWrapMode());
|
||||
if (!setTheme(theme_ctl.val())) theme_ctl.val(getTheme());
|
||||
input.focus();
|
||||
return true;
|
||||
}
|
||||
|
||||
var save_button = settings_popup.find(".btn-primary");
|
||||
save_button.click(save);
|
||||
settings_popup.find(".btn-primary").click(save);
|
||||
settings_popup.find("form").submit(function () {
|
||||
save_button.click();
|
||||
return false
|
||||
});
|
||||
|
||||
return {};
|
||||
});
|
82
sense/app/utils.js
Normal file
|
@ -0,0 +1,82 @@
|
|||
define([
|
||||
'ace',
|
||||
'jquery'
|
||||
], function (ace, $) {
|
||||
'use strict';
|
||||
|
||||
var utils = {};
|
||||
|
||||
utils.textFromRequest = function (request) {
|
||||
var data = request.data;
|
||||
if (typeof data != "string") {
|
||||
data = data.join("\n");
|
||||
}
|
||||
return request.method + " " + request.url + "\n" + data;
|
||||
};
|
||||
|
||||
utils.getUrlParam = function (name) {
|
||||
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
|
||||
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
||||
results = regex.exec(location.search);
|
||||
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||
};
|
||||
|
||||
utils.reformatData = function (data, indent) {
|
||||
var changed = false;
|
||||
var formatted_data = [];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var cur_doc = data[i];
|
||||
try {
|
||||
var new_doc = JSON.stringify(JSON.parse(cur_doc), null, indent ? 2 : 0);
|
||||
changed = changed || new_doc != cur_doc;
|
||||
formatted_data.push(new_doc);
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
formatted_data.push(cur_doc);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
changed: changed,
|
||||
data: formatted_data
|
||||
};
|
||||
}
|
||||
|
||||
utils.callES = function (server, url, method, data, successCallback, completeCallback) {
|
||||
url = utils.constructESUrl(server, url);
|
||||
var uname_password_re = /^(https?:\/\/)?(?:(?:([^\/]*):)?([^\/]*?)@)?(.*)$/;
|
||||
var url_parts = url.match(uname_password_re);
|
||||
|
||||
var uname = url_parts[2];
|
||||
var password = url_parts[3];
|
||||
url = url_parts[1] + url_parts[4];
|
||||
console.log("Calling " + url + " (uname: " + uname + " pwd: " + password + ")");
|
||||
if (data && method == "GET") method = "POST";
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: method == "GET" ? null : data,
|
||||
password: password,
|
||||
username: uname,
|
||||
crossDomain: true,
|
||||
type: method,
|
||||
dataType: "json",
|
||||
complete: completeCallback,
|
||||
success: successCallback
|
||||
});
|
||||
};
|
||||
|
||||
utils.constructESUrl = function (server, url) {
|
||||
if (url.indexOf("://") >= 0) return url;
|
||||
if (server.indexOf("://") < 0) server = "http://" + server;
|
||||
if (server.substr(-1) == "/") {
|
||||
server = server.substr(0, server.length - 1);
|
||||
}
|
||||
if (url.charAt(0) === "/") url = url.substr(1);
|
||||
|
||||
return server + "/" + url;
|
||||
};
|
||||
|
||||
return utils;
|
||||
});
|
|
@ -6,7 +6,7 @@
|
|||
</p>
|
||||
|
||||
<p>Sense understands requests in a compact format, similar to cURL:
|
||||
<div id="example_editor_container"></div>
|
||||
<div id="welcome_example_container"></div>
|
||||
|
||||
<p>While typing a request, Sense will make suggestions which you can than accept by hitting Enter/Tab.
|
||||
These suggestions are made based on the request structure <i>as well as</i> your indices and types.
|
41
sense/app/welcome_popup.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
define([
|
||||
'ace',
|
||||
'analytics',
|
||||
'jquery',
|
||||
|
||||
'bootstrap'
|
||||
], function (ace, _gaq, $) {
|
||||
'use strict';
|
||||
|
||||
var $welcomePopup = $("#welcome_popup");
|
||||
|
||||
var $example;
|
||||
var html = [
|
||||
'<div id="welcome_example_editor">PUT index/type/1',
|
||||
'{',
|
||||
' "body": "here"',
|
||||
'}',
|
||||
'',
|
||||
'GET index/type/1',
|
||||
'</div>'
|
||||
].join('\n');
|
||||
|
||||
$welcomePopup.modal();
|
||||
$welcomePopup.on('shown', function () {
|
||||
$example = $(html)
|
||||
.appendTo("#welcome_example_container");
|
||||
|
||||
var editor = ace.edit("welcome_example_editor");
|
||||
editor.getSession().setMode("ace/mode/sense");
|
||||
editor.getSession().setFoldStyle('markbeginend');
|
||||
editor.setReadOnly(true);
|
||||
editor.renderer.setShowPrintMargin(false);
|
||||
});
|
||||
|
||||
$welcomePopup.on('hidden', function () {
|
||||
$example.remove();
|
||||
$example = null;
|
||||
});
|
||||
|
||||
return $welcomePopup;
|
||||
})
|
|
@ -3,6 +3,10 @@ body {
|
|||
overflow: hidden;
|
||||
}
|
||||
|
||||
body.fouc {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.pull-right-btn {
|
||||
float: right;
|
||||
margin-right: 5px;
|
||||
|
@ -116,14 +120,16 @@ body {
|
|||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#example_editor_container {
|
||||
#help_example_container,
|
||||
#welcome_example_container {
|
||||
width: 100%;
|
||||
height: 10em;
|
||||
margin: 10px 0;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
#example_editor_container #example_editor {
|
||||
#help_example_editor,
|
||||
#welcome_example_editor {
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
|
@ -218,4 +224,20 @@ body {
|
|||
|
||||
.ui-resizable-e.active {
|
||||
background-color: rgba(194, 193, 208, 100);
|
||||
}
|
||||
}
|
||||
|
||||
/** COPIED FROM BOOTSTRAP, MODIFIED SELECTORS **/
|
||||
.dropdown-menu li>a.zeroclipboard-is-hover,
|
||||
.dropdown-menu li>a.zeroclipboard-is-active {
|
||||
color: #FFF;
|
||||
text-decoration: none;
|
||||
background-color: #0081C2;
|
||||
background-image: -moz-linear-gradient(top,#08c,#0077b3);
|
||||
background-image: -webkit-gradient(linear,0 0,0 100%,from(#08C),to(#0077B3));
|
||||
background-image: -webkit-linear-gradient(top,#08C,#0077B3);
|
||||
background-image: -o-linear-gradient(top,#08c,#0077b3);
|
||||
background-image: linear-gradient(to bottom,#08C,#0077B3);
|
||||
background-repeat: repeat-x;
|
||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff0088cc',endColorstr='#ff0077b3',GradientType=0);
|
||||
}
|
||||
/** END COPIED **/
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 4.2 KiB |
337
sense/index.html
|
@ -1,210 +1,189 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" xmlns="http://www.w3.org/1999/html">
|
||||
<head>
|
||||
<title>Sense - a JSON aware interface to ElasticSearch</title>
|
||||
<link id="bootstrapThemeCss" href="lib/bootstrap/css/bootstrap.light.min.css" type="text/css" rel="stylesheet"/>
|
||||
<link href="lib/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet"/>
|
||||
<link href="lib/jqueryui/jquery-ui-1.9.2.custom.min.css" type="text/css" rel="stylesheet"/>
|
||||
<link href="css/sense.css" rel="stylesheet" type="text/css"/>
|
||||
<link id="senseThemeCss" href="css/sense.light.css" rel="stylesheet" type="text/css"/>
|
||||
<title>Sense - a JSON aware interface to ElasticSearch</title>
|
||||
<link id="bootstrapThemeCss" href="vendor/bootstrap/css/bootstrap.light.min.css" type="text/css" rel="stylesheet"/>
|
||||
<link href="vendor/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet"/>
|
||||
<link id="senseThemeCss" href="css/sense.light.css" rel="stylesheet" type="text/css"/>
|
||||
<link href="css/sense.css" rel="stylesheet" type="text/css"/>
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
<body class="fouc">
|
||||
<div class="navbar navbar-static-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<span class="brand" id="server_label">Server</span>
|
||||
|
||||
<form class="navbar-form pull-left">
|
||||
<input id="es_server" type="text" class="span5" value="localhost:9200"/>
|
||||
</form>
|
||||
<span class="pull-left btn btn-link">
|
||||
<span id="notification" style="visibility: hidden"
|
||||
class="label label-info"></span></span>
|
||||
<ul class="nav pull-right">
|
||||
<li id="history_btn" data-toggle="modal" data-target="#history_popup">
|
||||
<a title="History" href="#" data-placement="bottom"><i class="fa fa-clock-o"></i></a>
|
||||
</li>
|
||||
<li id="settings_btn" data-toggle="modal" data-target="#settings_popup">
|
||||
<a title="Settings" href="#" data-placement="bottom"><i class="fa fa-cog"></i></a>
|
||||
</li>
|
||||
<li id="help_btn" data-toggle="modal" data-target="#help_popup">
|
||||
<a title="Help" href="#" data-placement="bottom"><i class="fa fa-question-circle"></i></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<span class="brand" id="server_label">Server</span>
|
||||
|
||||
<form class="navbar-form pull-left">
|
||||
<input id="es_server" type="text" class="span5" value="localhost:9200"/>
|
||||
</form>
|
||||
<span class="pull-left btn btn-link"><span id="notification" style="visibility: hidden"
|
||||
class="label label-info"></span></span>
|
||||
<ul class="nav pull-right">
|
||||
<li id="history_btn" data-toggle="modal" data-target="#history_popup">
|
||||
<a title="History" href="#" data-placement="bottom"><i class="fa fa-clock-o"></i></a>
|
||||
</li>
|
||||
<li id="settings_btn" data-toggle="modal" data-target="#settings_popup">
|
||||
<a title="Settings" href="#" data-placement="bottom"><i class="fa fa-cog"></i></a>
|
||||
</li>
|
||||
<li id="help_btn" data-toggle="modal" data-target="#help_popup">
|
||||
<a title="Help" href="#" data-placement="bottom"><i class="fa fa-question-circle"></i></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div id="main" class="container-fluid">
|
||||
<div id="editor" class="editor_position">GET _search
|
||||
{
|
||||
"query": { "match_all": {} }
|
||||
}
|
||||
</div>
|
||||
<div id="output">{}</div>
|
||||
<div id="editor_actions">
|
||||
<a id="send" href="#" data-toggle="tooltip" title="click to send request"><i
|
||||
class="fa fa-play"></i></a>
|
||||
<a id="request_wrench" data-toggle="dropdown" href="#"><i
|
||||
class="fa fa-wrench"></i></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a id="copy_as_curl" tabindex="-1" href="#">Copy as cURL</a></li>
|
||||
<li><a id="auto_indent" tabindex="-1" href="#">Auto indent</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<ul id="autocomplete" style="left: -1000px;"></ul>
|
||||
<div id="editor" class="editor_position">GET _search
|
||||
{
|
||||
"query": { "match_all": {} }
|
||||
}
|
||||
</div>
|
||||
<div id="output">{}</div>
|
||||
<div id="editor_actions">
|
||||
<a id="send" href="#" data-toggle="tooltip" title="click to send request"><i
|
||||
class="fa fa-play"></i></a>
|
||||
<a id="request_wrench" data-toggle="dropdown" href="#"><i
|
||||
class="fa fa-wrench"></i></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a id="copy_as_curl" tabindex="-1" href="#">Copy as cURL</a></li>
|
||||
<li><a id="auto_indent" tabindex="-1" href="#">Auto indent</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<ul id="autocomplete" style="left: -1000px;"></ul>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="help_popup" class="modal hide fade" data-keyboard="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>Help</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<h4>Request format</h4>
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>Help</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<h4>Request format</h4>
|
||||
|
||||
<div id="help_requests">
|
||||
You can type one or more requests in the white editor. Sense understands requests in a compact format:
|
||||
<div id="example_editor_container">
|
||||
</div>
|
||||
</div>
|
||||
<h4>Keyboard tips</h4>
|
||||
<dl class="dl-horizontal">
|
||||
<dt></dt>
|
||||
<dd><strong>General editing</strong></dd>
|
||||
<dt>Ctrl/Cmd + I</dt>
|
||||
<dd>Auto indent current request</dd>
|
||||
<dt>Ctrl + Space</dt>
|
||||
<dd>Open Auto complete (even if not typing)</dd>
|
||||
<dt>Ctrl/Cmd + Enter</dt>
|
||||
<dd>Submit request</dd>
|
||||
<dt>Ctrl/Cmd + Shift + C</dt>
|
||||
<dd>Copy request in cURL format</dd>
|
||||
<dt>Ctrl/Cmd + Up/Down</dt>
|
||||
<dd>Jump to the previous/next request start or end.</dd>
|
||||
<dt>Ctrl/Cmd + Alt + L</dt>
|
||||
<dd>Collapse/expand current scope.</dd>
|
||||
</dl>
|
||||
<dl class="dl-horizontal">
|
||||
<dt></dt>
|
||||
<dd><strong>When auto-complete is visible</strong></dd>
|
||||
<dt>Down arrow</dt>
|
||||
<dd>Switch focus to auto-complete menu. Use arrows to further select a term</dd>
|
||||
<dt>Enter/Tab</dt>
|
||||
<dd>Select the currently selected or the top most term in auto-complete menu</dd>
|
||||
<dt>Esc</dt>
|
||||
<dd>Close auto-complete menu</dd>
|
||||
</dl>
|
||||
<div id="help_requests">
|
||||
You can type one or more requests in the white editor. Sense understands requests in a compact format:
|
||||
<div id="help_example_container"></div>
|
||||
</div>
|
||||
<h4>Keyboard tips</h4>
|
||||
<dl class="dl-horizontal">
|
||||
<dt></dt>
|
||||
<dd><strong>General editing</strong></dd>
|
||||
<dt>Ctrl/Cmd + I</dt>
|
||||
<dd>Auto indent current request</dd>
|
||||
<dt>Ctrl + Space</dt>
|
||||
<dd>Open Auto complete (even if not typing)</dd>
|
||||
<dt>Ctrl/Cmd + Enter</dt>
|
||||
<dd>Submit request</dd>
|
||||
<dt>Ctrl/Cmd + Shift + C</dt>
|
||||
<dd>Copy request in cURL format</dd>
|
||||
<dt>Ctrl/Cmd + Up/Down</dt>
|
||||
<dd>Jump to the previous/next request start or end.</dd>
|
||||
<dt>Ctrl/Cmd + Alt + L</dt>
|
||||
<dd>Collapse/expand current scope.</dd>
|
||||
</dl>
|
||||
<dl class="dl-horizontal">
|
||||
<dt></dt>
|
||||
<dd><strong>When auto-complete is visible</strong></dd>
|
||||
<dt>Down arrow</dt>
|
||||
<dd>Switch focus to auto-complete menu. Use arrows to further select a term</dd>
|
||||
<dt>Enter/Tab</dt>
|
||||
<dd>Select the currently selected or the top most term in auto-complete menu</dd>
|
||||
<dt>Esc</dt>
|
||||
<dd>Close auto-complete menu</dd>
|
||||
</dl>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Got it</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Got it</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="history_popup" class="modal hide fade" data-keyboard="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>History</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<ul class="nav nav-list">
|
||||
<!--<li><a href="#"><i class="icon-chevron-right"></i><span></span></a></li>-->
|
||||
</ul>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn pull-left" id="hist_clear">Clear</a>
|
||||
|
||||
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Apply</a>
|
||||
</div>
|
||||
<div id="history_popup" class="modal hide fade" data-keyboard="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>History</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<ul class="nav nav-list">
|
||||
<!--<li><a href="#"><i class="icon-chevron-right"></i><span></span></a></li>-->
|
||||
</ul>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn pull-left" id="hist_clear">Clear</a>
|
||||
|
||||
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Apply</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="settings_popup" class="modal hide fade" data-keyboard="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>Settings</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<h5>Editor & Output pane settings</h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="font_size">Font Size</label>
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>Settings</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form class="form-horizontal">
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<h5>Editor & Output pane settings</h5>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="font_size">Font Size</label>
|
||||
|
||||
<div class="controls">
|
||||
<input type="number" id="font_size">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input id="wrap_mode" type="checkbox"> Wrap long lines </input>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="font_size">Theme</label>
|
||||
<div class="controls">
|
||||
<input type="number" id="font_size">
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<div class="controls">
|
||||
<label class="checkbox">
|
||||
<input id="wrap_mode" type="checkbox"> Wrap long lines </input>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="font_size">Theme</label>
|
||||
|
||||
<div class="controls">
|
||||
<select id="theme">
|
||||
<option value="dark">Dark</option>
|
||||
<option value="light">Light</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
|
||||
<a id="accept_settings" href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Save</a>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<select id="theme">
|
||||
<option value="dark">Dark</option>
|
||||
<option value="light">Light</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn" data-dismiss="modal">Cancel</a>
|
||||
<a id="accept_settings" href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Save</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="welcome_popup" class="modal hide fade" data-keyboard="true" data-remote="welcome.html">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>Welcome to Sense</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Get to work</a>
|
||||
</div>
|
||||
<div id="welcome_popup" class="modal hide fade" data-keyboard="true" data-remote="app/welcome.html">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3>Welcome to Sense</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<a href="#" class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Get to work</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<textarea class="out_of_screen" id="clipboardStaging"> </textarea>
|
||||
<!-- initialize require.js -->
|
||||
<script src="vendor/require/require.js"></script>
|
||||
<script src="app/require.config.js"></script>
|
||||
<script>
|
||||
var SENSE_VERSION = '0.9.0';
|
||||
require(['app'], function () {});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
<script src="lib/jquery-1.8.3.min.js" type="text/javascript"></script>
|
||||
<script src="lib/jqueryui/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
|
||||
<script src="lib/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
|
||||
<script src="lib/moment.min.js" type="text/javascript"></script>
|
||||
<script src="lib/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/utils.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/kb.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/aliases.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/cluster.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/filter.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/facets.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/globals.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/indices.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/query.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/search.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/settings.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/templates.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/warmers.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/mappings.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="kb/misc.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/curl.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/settings.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/base.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/mappings.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/history.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/autocomplete.js" type="text/javascript" charset="utf-8"></script>
|
||||
</html>
|
|
@ -1,34 +0,0 @@
|
|||
sense.kb.addEndpointDescription('_aliases', {
|
||||
match: /_aliases/,
|
||||
def_method: "GET",
|
||||
methods: ["GET", "POST"],
|
||||
endpoint_autocomplete: [
|
||||
"_aliases"
|
||||
],
|
||||
indices_mode: "multi",
|
||||
types_mode: "none",
|
||||
doc_id_mode: "none",
|
||||
data_autocomplete_rules: {
|
||||
"actions": {
|
||||
__template: [
|
||||
{ "add": { "index": "test1", "alias": "alias1" } }
|
||||
],
|
||||
__any_of: [
|
||||
{
|
||||
add: {
|
||||
index: "$INDEX$",
|
||||
alias: "",
|
||||
filter: {},
|
||||
routing: "1",
|
||||
search_routing: "1,2",
|
||||
index_routing: "1"
|
||||
},
|
||||
remove: {
|
||||
index: "",
|
||||
alias: ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,34 +0,0 @@
|
|||
sense.kb.addEndpointDescription('_cluster/nodes/stats', {
|
||||
methods: ["GET"],
|
||||
indices_mode: "none",
|
||||
types_mode: "none"
|
||||
});
|
||||
sense.kb.addEndpointDescription('_cluster/state', {
|
||||
methods: ["GET"],
|
||||
endpoint_autocomplete: ['_cluster/state'],
|
||||
indices_mode: "none",
|
||||
types_mode: "none"
|
||||
});
|
||||
|
||||
sense.kb.addEndpointDescription('_cluster/health', {
|
||||
methods: ["GET"],
|
||||
endpoint_autocomplete: ['_cluster/health'],
|
||||
indices_mode: "none",
|
||||
types_mode: "none"
|
||||
});
|
||||
|
||||
sense.kb.addEndpointDescription('_cluster/settings', {
|
||||
methods: ["GET", "PUT"],
|
||||
endpoint_autocomplete: ['_cluster/settings'],
|
||||
indices_mode: "none",
|
||||
types_mode: "none",
|
||||
data_autocomplete_rules: {
|
||||
persistent: {
|
||||
"routing.allocation.same_shard.host" : { __one_of: [ false, true ]}
|
||||
},
|
||||
|
||||
transient: {
|
||||
__scope_link: ".persistent"
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,92 +0,0 @@
|
|||
sense.kb.addGlobalAutocompleteRules("facets", {
|
||||
"*": {
|
||||
terms: {
|
||||
__template: {
|
||||
field: "FIELD",
|
||||
size: 10
|
||||
},
|
||||
field: "$FIELD$",
|
||||
fields: ["$FIELD$"],
|
||||
size: 10,
|
||||
script: "",
|
||||
script_field: "",
|
||||
order: { __one_of: ["count", "term", "reverse_count", "reverse_term"]},
|
||||
all_terms: { __one_of: [false, true]},
|
||||
exclude: ["TERM"],
|
||||
regex: "",
|
||||
regex_flags: ""
|
||||
},
|
||||
range: {
|
||||
__template: {
|
||||
field: "FIELD",
|
||||
ranges: [
|
||||
{ "to": 50 },
|
||||
{ "from": 20, "to": 70 },
|
||||
{ "from": 70, "to": 120 },
|
||||
{ "from": 150 }
|
||||
]
|
||||
},
|
||||
field: "$FIELD$",
|
||||
ranges: [
|
||||
{ to: 10, from: 20}
|
||||
]
|
||||
},
|
||||
histogram: {
|
||||
__template: {
|
||||
field: "FIELD", interval: 100
|
||||
},
|
||||
field: "$FIELD$",
|
||||
interval: 100,
|
||||
time_interval: "1.5h",
|
||||
key_field: "$FIELD$",
|
||||
value_field: "$FIELD$",
|
||||
key_script: "",
|
||||
value_script: "",
|
||||
params: {}
|
||||
},
|
||||
date_histogram: {
|
||||
__template: {
|
||||
field: "FIELD",
|
||||
"interval": "day"
|
||||
},
|
||||
field: "$FIELD$",
|
||||
interval: { __one_of: ["year", "quarter", "month", "week", "day", "hour", "minute", "1h", "1d", "1w"]},
|
||||
post_zone: -1,
|
||||
pre_zone: -1,
|
||||
factor: 1000,
|
||||
pre_offset: "1d",
|
||||
post_offset: "1d",
|
||||
key_field: "$FIELD$",
|
||||
value_field: "$FIELD$",
|
||||
value_script: ""
|
||||
},
|
||||
filter: {
|
||||
},
|
||||
query: {
|
||||
},
|
||||
facet_filter: {
|
||||
__scope_link: "GLOBAL.filter"
|
||||
},
|
||||
statistical: {
|
||||
__template: {
|
||||
field: "FIELD"
|
||||
},
|
||||
field: "$FIELD$",
|
||||
fields: ["$FIELD$"],
|
||||
script: ""
|
||||
},
|
||||
terms_stats: {
|
||||
__template: {
|
||||
key_field: "FIELD",
|
||||
value_field: "FIELD"
|
||||
},
|
||||
key_field: "$FIELD$",
|
||||
value_field: "$FIELD$",
|
||||
value_script: "",
|
||||
size: 10,
|
||||
order: {__one_of: ["count", "term", "reverse_term", "reverse_count", "total", "reverse_total",
|
||||
"min", "reverse_min", "max", "reverse_max", "mean", "reverse_mean"]}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
|
@ -1,255 +0,0 @@
|
|||
sense.kb.addGlobalAutocompleteRules("filter", {
|
||||
and: {
|
||||
__template: {
|
||||
filters: [
|
||||
{}
|
||||
]
|
||||
},
|
||||
filters: [
|
||||
{ __scope_link: ".filter" }
|
||||
],
|
||||
_cache: {__one_of: [ false, true ]}
|
||||
},
|
||||
bool: {
|
||||
must: [
|
||||
{ __scope_link: ".filter"}
|
||||
],
|
||||
must_not: [
|
||||
{ __scope_link: ".filter"}
|
||||
],
|
||||
should: [
|
||||
{ __scope_link: ".filter"}
|
||||
],
|
||||
_cache: {__one_of: [ false, true ]}
|
||||
},
|
||||
exists: {
|
||||
__template: { "FIELD": "VALUE"},
|
||||
"$FIELD$": ""
|
||||
},
|
||||
ids: {
|
||||
__template: { "values": ["ID"] },
|
||||
"type": "$TYPE$",
|
||||
"values": [""]
|
||||
},
|
||||
limit: {
|
||||
__template: { value: 100},
|
||||
value: 100
|
||||
},
|
||||
type: {
|
||||
__template: { value: "TYPE"},
|
||||
value: "$TYPE$"
|
||||
},
|
||||
geo_bounding_box: {
|
||||
__template: {
|
||||
"FIELD": {
|
||||
"top_left": {
|
||||
"lat": 40.73,
|
||||
"lon": -74.1
|
||||
},
|
||||
"bottom_right": {
|
||||
"lat": 40.717,
|
||||
"lon": -73.99
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"$FIELD$": {
|
||||
top_left: { lat: 40.73, lon: -74.1 },
|
||||
bottom_right: { lat: 40.73, lon: -74.1 }
|
||||
},
|
||||
type: { __one_of: ["memory", "indexed"]},
|
||||
_cache: {__one_of: [ false, true ]}
|
||||
},
|
||||
geo_distance: {
|
||||
__template: {
|
||||
distance: 100,
|
||||
distance_unit: "km",
|
||||
"FIELD": { lat: 40.73, lon: -74.1 }
|
||||
},
|
||||
distance: 100,
|
||||
distance_unit: { __one_of: [ "km", "miles"]},
|
||||
distance_type: { __one_of: [ "arc", "plane"]},
|
||||
optimize_bbox: { __one_of: [ "memory", "indexed", "none"]},
|
||||
"$FIELD$": { lat: 40.73, lon: -74.1 },
|
||||
_cache: {__one_of: [ false, true ]}
|
||||
},
|
||||
geo_distance_range: {
|
||||
__template: {
|
||||
from: 100,
|
||||
to: 200,
|
||||
distance_unit: "km",
|
||||
"FIELD": { lat: 40.73, lon: -74.1 }
|
||||
},
|
||||
from: 100,
|
||||
to: 200,
|
||||
|
||||
distance_unit: { __one_of: [ "km", "miles"]},
|
||||
distance_type: { __one_of: [ "arc", "plane"]},
|
||||
include_lower: { __one_of: [ true, false]},
|
||||
include_upper: { __one_of: [ true, false]},
|
||||
|
||||
"$FIELD$": { lat: 40.73, lon: -74.1 },
|
||||
_cache: {__one_of: [ false, true ]}
|
||||
},
|
||||
geo_polygon: {
|
||||
__template: {
|
||||
"FIELD": {
|
||||
"points": [
|
||||
{ lat: 40.73, lon: -74.1 },
|
||||
{ lat: 40.83, lon: -75.1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
"$FIELD$": {
|
||||
points: [
|
||||
{ lat: 40.73, lon: -74.1 }
|
||||
]
|
||||
},
|
||||
_cache: {__one_of: [ false, true ]}
|
||||
},
|
||||
geo_shape: {
|
||||
__template: {
|
||||
"FIELD": {
|
||||
shape: {
|
||||
type: "envelope",
|
||||
coordinates: [
|
||||
[-45, 45],
|
||||
[45, -45]
|
||||
]
|
||||
},
|
||||
"relation": "within"
|
||||
}
|
||||
},
|
||||
"$FIELD$": {
|
||||
shape: {
|
||||
type: "",
|
||||
coordinates: []
|
||||
},
|
||||
indexed_shape: {
|
||||
id: "",
|
||||
index: "$INDEX$",
|
||||
type: "$TYPE$",
|
||||
shape_field_name: "shape"
|
||||
},
|
||||
relation: { __one_of: ["within", "intersects", "disjoint"]}
|
||||
}
|
||||
},
|
||||
has_child: {
|
||||
__template: {
|
||||
type: "TYPE",
|
||||
query: {}
|
||||
},
|
||||
type: "$TYPE$",
|
||||
query: {},
|
||||
_scope: ""
|
||||
},
|
||||
has_parent: {
|
||||
__template: {
|
||||
type: "TYPE",
|
||||
query: {}
|
||||
},
|
||||
type: "$TYPE$",
|
||||
query: {},
|
||||
_scope: ""
|
||||
},
|
||||
match_all: { },
|
||||
missing: {
|
||||
__template: {
|
||||
field: "FIELD"
|
||||
},
|
||||
existence: { __one_of: [ true, false]},
|
||||
null_value: { __one_of: [ true, false]},
|
||||
field: "$FIELD$"
|
||||
},
|
||||
not: {
|
||||
__template: {
|
||||
filter: {}
|
||||
},
|
||||
filter: { __scope_link: ".filter"},
|
||||
_cache: { __one_of: [ true, false]}
|
||||
},
|
||||
numeric_range: {
|
||||
__template: {
|
||||
"FIELD": {
|
||||
from: 10,
|
||||
to: 20
|
||||
}
|
||||
},
|
||||
from: 1,
|
||||
to: 20,
|
||||
include_lower: { __one_of: [ true, false]},
|
||||
include_upper: { __one_of: [ true, false]}
|
||||
},
|
||||
or: {
|
||||
__template: {
|
||||
filters: [
|
||||
{}
|
||||
]
|
||||
},
|
||||
filters: [
|
||||
{ __scope_link: ".filter" }
|
||||
],
|
||||
_cache: {__one_of: [ false, true ]}
|
||||
},
|
||||
prefix: {
|
||||
__template: {
|
||||
"FIELD": "VALUE"
|
||||
},
|
||||
"$FIELD$": "",
|
||||
_cache: { __one_of: [ true, false]}
|
||||
},
|
||||
query: { __scope_link: ".query"},
|
||||
fquery: {
|
||||
__template: {
|
||||
query: {},
|
||||
_cache: true
|
||||
},
|
||||
query: { __scope_link: ".query"},
|
||||
_cache: { __one_of: [ true, false]}
|
||||
},
|
||||
range: {
|
||||
__template: {
|
||||
"FIELD": {
|
||||
from: 10,
|
||||
to: 20
|
||||
}
|
||||
},
|
||||
from: 1,
|
||||
to: 20,
|
||||
include_lower: { __one_of: [ true, false]},
|
||||
include_upper: { __one_of: [ true, false]},
|
||||
_cache: { __one_of: [ false, true ]}
|
||||
},
|
||||
script: {
|
||||
__template: {
|
||||
script: "SCRIPT",
|
||||
params: {}
|
||||
},
|
||||
script: "",
|
||||
params: {},
|
||||
_cache: { __one_of: [ true, false]}
|
||||
},
|
||||
term: {
|
||||
__template: {
|
||||
"FIELD": "VALUE"
|
||||
},
|
||||
"$FIELD$": "",
|
||||
_cache: { __one_of: [ false, true]}
|
||||
},
|
||||
terms: {
|
||||
__template: { "FIELD": ["VALUE1", "VALUE2"]},
|
||||
field: [ "$FIELD$"],
|
||||
execution: { __one_of: [ "plain", "bool", "and", "or", "bool_nocache", "and_nocache", "or_nocache"]},
|
||||
_cache: { __one_of: [ false, true ]}
|
||||
},
|
||||
nested: {
|
||||
__template: {
|
||||
path: "path_to_nested_doc",
|
||||
query: {}
|
||||
},
|
||||
query: {},
|
||||
path: "",
|
||||
_cache: { __one_of: [ true, false]},
|
||||
_name: ""
|
||||
}
|
||||
});
|
|
@ -1,14 +0,0 @@
|
|||
sense.kb.addGlobalAutocompleteRules("highlight", {
|
||||
pre_tags: {}, post_tags: {}, tags_schema: {},
|
||||
fields: { "$FIELD$": { "fragment_size": 20, "number_of_fragments": 3 }}
|
||||
}
|
||||
);
|
||||
|
||||
// only used with scope links as there is no common name for scripts
|
||||
sense.kb.addGlobalAutocompleteRules("SCRIPT_ENV", {
|
||||
__template: { "script": ""},
|
||||
script: "",
|
||||
lang: "",
|
||||
params: {}
|
||||
}
|
||||
);
|
|
@ -1,47 +0,0 @@
|
|||
sense.kb.addEndpointDescription('_refresh', {
|
||||
def_method: "POST",
|
||||
methods: ["POST"],
|
||||
endpoint_autocomplete: [
|
||||
"_refresh"
|
||||
],
|
||||
indices_mode: "multi"
|
||||
});
|
||||
|
||||
sense.kb.addEndpointDescription('_stats', {
|
||||
def_method: "GET",
|
||||
methods: ["GET"],
|
||||
endpoint_autocomplete: [
|
||||
"_stats"
|
||||
],
|
||||
indices_mode: "multi"
|
||||
});
|
||||
|
||||
sense.kb.addEndpointDescription('_segments', {
|
||||
def_method: "GET",
|
||||
methods: ["GET"],
|
||||
endpoint_autocomplete: [
|
||||
"_segments"
|
||||
],
|
||||
indices_mode: "multi"
|
||||
});
|
||||
|
||||
sense.kb.addEndpointDescription('__create_index__', {
|
||||
methods: ["PUT", "DELETE"],
|
||||
indices_mode: "single",
|
||||
types_mode: "none",
|
||||
match: "^/?$",
|
||||
endpoint_autocomplete: [
|
||||
""
|
||||
],
|
||||
data_autocomplete_rules: {
|
||||
mappings: {
|
||||
__scope_link: "_mapping"
|
||||
},
|
||||
settings: {
|
||||
__scope_link: "_settings.index"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
|
@ -1,93 +0,0 @@
|
|||
sense.kb.addEndpointDescription('_mapping', {
|
||||
def_method: "GET",
|
||||
methods: ["GET", "PUT"],
|
||||
indices_mode: "multi",
|
||||
types_mode: "multi",
|
||||
data_autocomplete_rules: {
|
||||
"$TYPE$": {
|
||||
__template: {
|
||||
properties: {
|
||||
"FIELD": {}
|
||||
}
|
||||
},
|
||||
"_parent": {
|
||||
__template: {
|
||||
"type": ""
|
||||
},
|
||||
"type": "$TYPE$"
|
||||
},
|
||||
"index_analyzer": "standard",
|
||||
"search_analyzer": "standard",
|
||||
"analyzer": "standard",
|
||||
"dynamic_date_formats": ["yyyy-MM-dd"],
|
||||
"date_detection": { __one_of: [ true, false ]},
|
||||
"numeric_detection": { __one_of: [ true, false ]},
|
||||
"properties": {
|
||||
"*": {
|
||||
type: { __one_of: ["string", "float", "double", "byte", "short", "integer", "long", "date", "boolean",
|
||||
"binary", "object", "nested", "multi_field"]},
|
||||
|
||||
// strings
|
||||
index_name: "",
|
||||
store: { __one_of: ["no", "yes"]},
|
||||
index: { __one_of: ["analyzed", "not_analyzed", "no"]},
|
||||
term_vector: { __one_of: ["no", "yes", "with_offsets", "with_positions", "with_positions_offsets"]},
|
||||
boost: 1.0,
|
||||
null_value: "",
|
||||
omit_norms: { __one_of: [ true, false]},
|
||||
index_options: { __one_of: [ "docs", "freqs", "positions"]},
|
||||
analyzer: "standard",
|
||||
index_analyzer: "standard",
|
||||
search_analyzer: "standard",
|
||||
include_in_all: { __one_of: [ false, true]},
|
||||
ignore_above: 10,
|
||||
position_offset_gap: 0,
|
||||
|
||||
// numeric
|
||||
precision_step: 4,
|
||||
ignore_malformed: { __one_of: [ true, false]},
|
||||
|
||||
// dates
|
||||
format: { __one_of: [ "basic_date", "basic_date_time", "basic_date_time_no_millis",
|
||||
"basic_ordinal_date", "basic_ordinal_date_time", "basic_ordinal_date_time_no_millis",
|
||||
"basic_time", "basic_time_no_millis", "basic_t_time", "basic_t_time_no_millis",
|
||||
"basic_week_date", "basic_week_date_time", "basic_week_date_time_no_millis",
|
||||
"date", "date_hour", "date_hour_minute", "date_hour_minute_second", "date_hour_minute_second_fraction",
|
||||
"date_hour_minute_second_millis", "date_optional_time", "date_time", "date_time_no_millis",
|
||||
"hour", "hour_minute", "hour_minute_second", "hour_minute_second_fraction", "hour_minute_second_millis",
|
||||
"ordinal_date", "ordinal_date_time", "ordinal_date_time_no_millis", "time", "time_no_millis",
|
||||
"t_time", "t_time_no_millis", "week_date", "week_date_time", "weekDateTimeNoMillis", "week_year",
|
||||
"weekyearWeek", "weekyearWeekDay", "year", "year_month", "year_month_day"]},
|
||||
|
||||
fielddata: {
|
||||
filter: {
|
||||
regex: "",
|
||||
frequency: {
|
||||
min: 0.001,
|
||||
max: 0.1,
|
||||
min_segment_size: 500
|
||||
}
|
||||
}
|
||||
},
|
||||
postings_format: { __one_of: ["direct", "memory", "pulsing", "bloom_default", "bloom_pulsing", "default"]},
|
||||
similarity: { __one_of: [ "default", "BM25" ]},
|
||||
|
||||
// objects
|
||||
properties: {
|
||||
__scope_link: "_mapping.$TYPE$.properties"
|
||||
},
|
||||
|
||||
// multi_field
|
||||
path: { __one_of: [ "just_name", "full"]},
|
||||
fields: {
|
||||
"*": {
|
||||
__scope_link: "_mapping.$TYPE$.properties.$FIELD$"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,23 +0,0 @@
|
|||
sense.kb.addEndpointDescription('_stats', {
|
||||
methods: ["GET"],
|
||||
endpoint_autocomplete: ['_stats'],
|
||||
indices_mode: "multi",
|
||||
types_mode: "none",
|
||||
doc_id_mode: "none"
|
||||
});
|
||||
|
||||
sense.kb.addEndpointDescription('_cache/clear', {
|
||||
methods: ["GET"],
|
||||
endpoint_autocomplete: ['_cache/clear'],
|
||||
indices_mode: "multi",
|
||||
types_mode: "none",
|
||||
doc_id_mode: "none"
|
||||
});
|
||||
sense.kb.addEndpointDescription('_status', {
|
||||
methods: ["GET"],
|
||||
indices_mode: "multi",
|
||||
types_mode: "none",
|
||||
doc_id_mode: "none",
|
||||
endpoint_autocomplete: ['_status']
|
||||
});
|
||||
|
|
@ -1,351 +0,0 @@
|
|||
SPAN_QUERIES = {
|
||||
// TODO add one_of for objects
|
||||
span_first: {__scope_link: ".query.span_first"},
|
||||
span_near: {__scope_link: ".query.span_near"},
|
||||
span_or: {__scope_link: ".query.span_or"},
|
||||
span_not: {__scope_link: ".query.span_not"},
|
||||
span_term: {__scope_link: ".query.span_term"}
|
||||
};
|
||||
|
||||
sense.kb.addGlobalAutocompleteRules("query", {
|
||||
match: { __template: { "FIELD": "TEXT" },
|
||||
"$FIELD$": {
|
||||
"query": "",
|
||||
"operator": { __one_of: ["and" , "or"]},
|
||||
"type": { __one_of: [ "phrase", "phrase_prefix", "boolean"]},
|
||||
"max_expansions": 10,
|
||||
"analyzer": "",
|
||||
"fuzziness": 1.0,
|
||||
"prefix_length": 1
|
||||
} },
|
||||
match_phrase: { __template: { "FIELD": "PHRASE" },
|
||||
"$FIELD$": {
|
||||
query: "",
|
||||
analyzer: ""
|
||||
} },
|
||||
match_phrase_prefix: { __template: { "FIELD": "PREFIX" },
|
||||
"$FIELD$": {
|
||||
query: "",
|
||||
analyzer: "",
|
||||
max_expansions: 10,
|
||||
prefix_length: 1,
|
||||
fuzziness: 0.1
|
||||
} },
|
||||
multi_match: { __template: { "query": "", "fields": [] },
|
||||
query: "",
|
||||
fields: ["$FIELD$"],
|
||||
use_dis_max: { __template: true, __one_of: [ true, false ]},
|
||||
tie_breaker: 0.0
|
||||
},
|
||||
bool: {
|
||||
must: [
|
||||
{ __scope_link: "GLOBAL.query"}
|
||||
],
|
||||
must_not: [
|
||||
{ __scope_link: "GLOBAL.query"}
|
||||
],
|
||||
should: [
|
||||
{ __scope_link: "GLOBAL.query" }
|
||||
],
|
||||
minimum_number_should_match: 1,
|
||||
boost: 1.0
|
||||
},
|
||||
boosting: {
|
||||
positive: { __scope_link: ".query" },
|
||||
negative: { __scope_link: ".query" },
|
||||
negative_boost: 0.2
|
||||
},
|
||||
ids: { type: "", values: [] },
|
||||
custom_score: {
|
||||
__template: { query: {}, script: ""},
|
||||
query: {},
|
||||
script: "",
|
||||
params: {},
|
||||
lang: "mvel"
|
||||
},
|
||||
custom_boost_factor: {
|
||||
__template: { query: {}, boost_factor: 1.1 },
|
||||
query: {},
|
||||
boost_factor: 1.1
|
||||
},
|
||||
constant_score: {
|
||||
__template: { filter: {}, boost: 1.2 },
|
||||
query: {},
|
||||
filter: {},
|
||||
boost: 1.2
|
||||
},
|
||||
dis_max: {
|
||||
__template: { tie_breaker: 0.7, boost: 1.2, queries: []},
|
||||
tie_breaker: 0.7,
|
||||
boost: 1.2,
|
||||
queries: [
|
||||
{ __scope_link: ".query"}
|
||||
]
|
||||
},
|
||||
field: {
|
||||
"$FIELD$": {
|
||||
query: "", boost: 2.0,
|
||||
enable_position_increments: { __template: false, __one_of: [ true, false ]}
|
||||
} },
|
||||
filtered: {
|
||||
__template: {
|
||||
query: {},
|
||||
filter: {}
|
||||
},
|
||||
query: {},
|
||||
filter: {}
|
||||
},
|
||||
fuzzy_like_this: {
|
||||
fields: [],
|
||||
like_text: "",
|
||||
max_query_terms: 12
|
||||
},
|
||||
flt: {
|
||||
__scope_link: ".query.fuzzy_like_this"
|
||||
},
|
||||
fuzzy: {
|
||||
"$FIELD$": {
|
||||
"value": "",
|
||||
"boost": 1.0,
|
||||
"min_similarity": 0.5,
|
||||
"prefix_length": 0
|
||||
}
|
||||
},
|
||||
has_child: {
|
||||
"type": "$TYPE$",
|
||||
"score_type": { __one_of: ["none", "max", "sum", "avg"]},
|
||||
"_scope": "",
|
||||
"query": {
|
||||
}
|
||||
},
|
||||
has_parent: {
|
||||
"parent_type": "$TYPE$",
|
||||
"score_type": { __one_of: ["none", "score"]},
|
||||
"_scope": "",
|
||||
"query": {
|
||||
}
|
||||
},
|
||||
match_all: {},
|
||||
more_like_this: {
|
||||
__template: {
|
||||
"fields": ["FIELD"],
|
||||
"like_text": "text like this one",
|
||||
"min_term_freq": 1,
|
||||
"max_query_terms": 12
|
||||
},
|
||||
fields: [ "$FIELD$ "],
|
||||
like_text: "",
|
||||
percent_terms_to_match: 0.3,
|
||||
min_term_freq: 2,
|
||||
max_query_terms: 25,
|
||||
stop_words: [""],
|
||||
min_doc_freq: 5,
|
||||
max_doc_freq: 100,
|
||||
min_word_len: 0,
|
||||
max_word_len: 0,
|
||||
boost_terms: 1,
|
||||
boost: 1.0,
|
||||
analyzer: ""
|
||||
},
|
||||
more_like_this_field: {
|
||||
__template: {
|
||||
"FIELD": {
|
||||
"like_text": "text like this one",
|
||||
"min_term_freq": 1,
|
||||
"max_query_terms": 12
|
||||
} },
|
||||
"$FIELD$": {
|
||||
like_text: "",
|
||||
percent_terms_to_match: 0.3,
|
||||
min_term_freq: 2,
|
||||
max_query_terms: 25,
|
||||
stop_words: [""],
|
||||
min_doc_freq: 5,
|
||||
max_doc_freq: 100,
|
||||
min_word_len: 0,
|
||||
max_word_len: 0,
|
||||
boost_terms: 1,
|
||||
boost: 1.0,
|
||||
analyzer: ""
|
||||
}
|
||||
},
|
||||
prefix: {
|
||||
__template: {
|
||||
"FIELD": { "value": "" }
|
||||
},
|
||||
"$FIELD$": {
|
||||
value: "",
|
||||
boost: 1.0
|
||||
}
|
||||
},
|
||||
query_string: {
|
||||
__template: {
|
||||
"default_field": "FIELD",
|
||||
"query": "this AND that OR thus"
|
||||
},
|
||||
query: "",
|
||||
default_field: "$FIELD$",
|
||||
fields: ["$FIELD$"],
|
||||
default_operator: { __one_of: ["OR", "AND"] },
|
||||
analyzer: "",
|
||||
allow_leading_wildcard: { __one_of: [ true, false]},
|
||||
lowercase_expanded_terms: { __one_of: [ true, false]},
|
||||
enable_position_increments: { __one_of: [ true, false]},
|
||||
fuzzy_max_expansions: 50,
|
||||
fuzzy_min_sim: 0.5,
|
||||
fuzzy_prefix_length: 0,
|
||||
phrase_slop: 0,
|
||||
boost: 1.0,
|
||||
analyze_wildcard: { __one_of: [ false, true ]},
|
||||
auto_generate_phrase_queries: { __one_of: [ false, true ]},
|
||||
minimum_should_match: "20%",
|
||||
lenient: { __one_of: [ false, true ]},
|
||||
use_dis_max: { __one_of: [ true, false]},
|
||||
tie_breaker: 0
|
||||
},
|
||||
range: {
|
||||
__template: {
|
||||
"FIELD": {
|
||||
from: 10,
|
||||
to: 20
|
||||
}
|
||||
},
|
||||
"$FIELD$": {
|
||||
__template: { from: 10, to: 20},
|
||||
from: 1,
|
||||
to: 20,
|
||||
include_lower: { __one_of: [ true, false]},
|
||||
include_upper: { __one_of: [ true, false]},
|
||||
boost: 1.0
|
||||
}
|
||||
},
|
||||
span_first: {
|
||||
__template: {
|
||||
"match": {
|
||||
"span_term": { "FIELD": "VALUE" }
|
||||
},
|
||||
"end": 3
|
||||
},
|
||||
match: SPAN_QUERIES
|
||||
},
|
||||
span_near: {
|
||||
__template: {
|
||||
"clauses": [
|
||||
{ span_term: { "FIELD": { "value": "VALUE"} } }
|
||||
],
|
||||
slop: 12,
|
||||
in_order: false
|
||||
},
|
||||
clauses: [
|
||||
SPAN_QUERIES
|
||||
],
|
||||
slop: 12,
|
||||
in_order: {__one_of: [ false, true ]},
|
||||
collect_payloads: {__one_of: [ false, true ]}
|
||||
},
|
||||
span_term: {
|
||||
__template: { "FIELD": { "value": "VALUE"}},
|
||||
"$FIELD$": {
|
||||
value: "",
|
||||
boost: 2.0
|
||||
}
|
||||
},
|
||||
span_not: {
|
||||
__template: {
|
||||
include: {
|
||||
span_term: { "FIELD": { "value": "VALUE"} }
|
||||
},
|
||||
exclude: {
|
||||
span_term: { "FIELD": { "value": "VALUE"} }
|
||||
}
|
||||
},
|
||||
include: SPAN_QUERIES,
|
||||
exclude: SPAN_QUERIES
|
||||
},
|
||||
span_or: {
|
||||
__template: {
|
||||
clauses: [
|
||||
{ span_term: { "FIELD": { "value": "VALUE"} } }
|
||||
]
|
||||
},
|
||||
clauses: [
|
||||
SPAN_QUERIES
|
||||
]
|
||||
},
|
||||
term: {
|
||||
__template: { "FIELD": { value: "VALUE" }},
|
||||
"$FIELD$": {
|
||||
value: "",
|
||||
boost: 2.0
|
||||
}
|
||||
},
|
||||
terms: {
|
||||
__template: {
|
||||
"FIELD": [ "VALUE1", "VALUE2"]
|
||||
},
|
||||
"$FIELD$": [ "" ],
|
||||
minimum_match: 1
|
||||
},
|
||||
top_children: {
|
||||
__template: {
|
||||
type: "CHILD_TYPE",
|
||||
query: {}
|
||||
},
|
||||
type: "$CHILD_TYPE$",
|
||||
query: { },
|
||||
score: { __one_of: [ "max", "sum", "avg"] },
|
||||
factor: 5,
|
||||
incremental_factor: 2
|
||||
},
|
||||
wildcard: {
|
||||
__template: {
|
||||
"FIELD": { value: "VALUE"}
|
||||
},
|
||||
"$FIELD$": { value: "", boost: 2.0 }
|
||||
},
|
||||
nested: {
|
||||
__template: {
|
||||
path: "path_to_nested_doc",
|
||||
query: {}
|
||||
},
|
||||
path: "",
|
||||
query: {},
|
||||
filter: {},
|
||||
score_mode: { __one_of: ["avg", "total", "max", "none"]}
|
||||
},
|
||||
custom_filters_score: {
|
||||
__template: {
|
||||
query: {},
|
||||
filters: [
|
||||
{
|
||||
filter: {}
|
||||
}
|
||||
]
|
||||
},
|
||||
query: {},
|
||||
filters: [
|
||||
{ filter: {}, boost: 2.0, script: ""}
|
||||
],
|
||||
score_mode: { __one_of: [ "first", "min", "max", "total", "avg", "multiply"] },
|
||||
max_boost: 2.0,
|
||||
params: {},
|
||||
lang: ""
|
||||
},
|
||||
indices: {
|
||||
__template: {
|
||||
indices: ["INDEX1", "INDEX2"],
|
||||
query: {}
|
||||
},
|
||||
indices: ["$INDEX$"],
|
||||
query: {},
|
||||
no_match_query: { __scope_link: ".query"}
|
||||
},
|
||||
geo_shape: {
|
||||
__template: {
|
||||
location: {},
|
||||
relation: "within"
|
||||
},
|
||||
__scope_link: ".filter.geo_shape"
|
||||
}
|
||||
|
||||
});
|
|
@ -1,68 +0,0 @@
|
|||
sense.kb.addEndpointDescription('_search', {
|
||||
def_method: "POST",
|
||||
methods: ["GET", "POST"],
|
||||
endpoint_autocomplete: [
|
||||
"_search"
|
||||
],
|
||||
indices_mode: "multi",
|
||||
types_mode: "multi",
|
||||
doc_id_mode: "none",
|
||||
data_autocomplete_rules: {
|
||||
query: {
|
||||
// populated by a global rule
|
||||
},
|
||||
facets: {
|
||||
__template: {
|
||||
"NAME": {
|
||||
"TYPE": {
|
||||
}
|
||||
}
|
||||
}
|
||||
// populated by a global rule
|
||||
},
|
||||
filter: {
|
||||
// added by global rules.
|
||||
},
|
||||
size: { __template: 20 },
|
||||
from: {},
|
||||
sort: {
|
||||
__template: [
|
||||
{ "FIELD": { "order": "desc"} }
|
||||
],
|
||||
__any_of: [
|
||||
{
|
||||
"$FIELD$": {
|
||||
"order": { __one_of: ["desc", "asc"]}
|
||||
}
|
||||
},
|
||||
"$FIELD$",
|
||||
"_score"
|
||||
]
|
||||
},
|
||||
search_type: {},
|
||||
fields: [ "$FIELD$" ],
|
||||
script_fields: {
|
||||
__template: { "FIELD": {
|
||||
"script": ""
|
||||
}},
|
||||
"*": {
|
||||
__scope_link: "GLOBAL.SCRIPT_ENV"
|
||||
}
|
||||
},
|
||||
partial_fields: {
|
||||
__template: {
|
||||
"NAME": { include: [] }
|
||||
},
|
||||
"*": {
|
||||
include: [],
|
||||
exclude: []
|
||||
}
|
||||
},
|
||||
highlight: {
|
||||
// populated by a global rule
|
||||
},
|
||||
explain: { __one_of: [ true, false ]},
|
||||
stats: [ "" ]
|
||||
|
||||
}
|
||||
});
|
|
@ -1,46 +0,0 @@
|
|||
sense.kb.addEndpointDescription('_settings', {
|
||||
match: /_settings/,
|
||||
methods: ["GET", "PUT"],
|
||||
endpoint_autocomplete: ['_settings'],
|
||||
indices_mode: "multi",
|
||||
types_mode: "none",
|
||||
doc_id_mode: "none",
|
||||
data_autocomplete_rules: {
|
||||
index: {
|
||||
refresh_interval: "1s",
|
||||
number_of_shards: 5,
|
||||
number_of_replicas: 1,
|
||||
"blocks.read_only": { __one_of: [ false, true ]},
|
||||
"blocks.read": { __one_of: [ true, false ]},
|
||||
"blocks.write": { __one_of: [ true, false ]},
|
||||
"blocks.metadata": { __one_of: [ true, false] },
|
||||
term_index_interval: 32,
|
||||
term_index_divisor: 1,
|
||||
"translog.flush_threshold_ops": 5000,
|
||||
"translog.flush_threshold_size": "200mb",
|
||||
"translog.flush_threshold_period": "30m",
|
||||
"translog.disable_flush": { __one_of: [ true, false ]},
|
||||
"cache.filter.max_size": "2gb",
|
||||
"cache.filter.expire": "2h",
|
||||
"gateway.snapshot_interval": "10s",
|
||||
routing: {
|
||||
allocation: {
|
||||
include: { tag: "" },
|
||||
exclude: { tag: ""},
|
||||
require: { tag: ""},
|
||||
total_shards_per_node: -1
|
||||
}
|
||||
},
|
||||
"recovery.initial_shards": { __one_of: ["quorum", "quorum-1", "half", "full", "full-1" ]},
|
||||
"ttl.disable_purge": { __one_of: [ true, false ]},
|
||||
analysis: {
|
||||
analyzer: {},
|
||||
tokenizer: {},
|
||||
filter: {},
|
||||
char_filter: {}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,18 +0,0 @@
|
|||
sense.kb.addEndpointDescription('_template', {
|
||||
match: /\/?_template/,
|
||||
def_method: "PUT",
|
||||
methods: ["GET", "PUT", "DELETE"],
|
||||
endpoint_autocomplete: [
|
||||
"_template/TEMPLATE_ID"
|
||||
],
|
||||
indices_mode: "none",
|
||||
types_mode: "none",
|
||||
doc_id_mode: "none",
|
||||
|
||||
data_autocomplete_rules: {
|
||||
template: "index*",
|
||||
warmers: { __scope_link: "_warmer" },
|
||||
mappings: {},
|
||||
settings: {}
|
||||
}
|
||||
});
|
|
@ -1,19 +0,0 @@
|
|||
sense.kb.addEndpointDescription('_warmer', {
|
||||
match: /_warmer/,
|
||||
def_method: "PUT",
|
||||
methods: ["GET", "PUT", "DELETE"],
|
||||
endpoint_autocomplete: [
|
||||
"_warmer", "_warmer/WARMER_ID"
|
||||
],
|
||||
indices_mode: "required_multi",
|
||||
types_mode: "none",
|
||||
doc_id_mode: "none",
|
||||
data_autocomplete_rules: {
|
||||
query: {
|
||||
// populated by a global rule
|
||||
},
|
||||
facets: {
|
||||
// populated by a global rule
|
||||
}
|
||||
}
|
||||
});
|
6
sense/lib/bootstrap/js/bootstrap.min.js
vendored
2
sense/lib/jquery-1.8.3.min.js
vendored
6
sense/lib/moment.min.js
vendored
|
@ -1,566 +0,0 @@
|
|||
if (!sense)
|
||||
sense = { };
|
||||
|
||||
sense.VERSION = "0.9.0";
|
||||
|
||||
function autoRetryIfTokenizing(func, cancelAlreadyScheduledCalls) {
|
||||
var timer = false;
|
||||
var wrapper;
|
||||
wrapper = function () {
|
||||
|
||||
if (!sense.utils.isTokenizationStable()) {
|
||||
var self = this;
|
||||
var args = arguments;
|
||||
if (cancelAlreadyScheduledCalls && typeof timer == "number") {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
timer = setTimeout(function () {
|
||||
wrapper.apply(self, args)
|
||||
}, 100);
|
||||
return undefined;
|
||||
}
|
||||
timer = true;
|
||||
try {
|
||||
// now call the original method
|
||||
return func.apply(this, arguments);
|
||||
}
|
||||
finally {
|
||||
timer = false;
|
||||
}
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
function resetToValues(server, content) {
|
||||
if (server != null) {
|
||||
$("#es_server").val(server);
|
||||
sense.mappings.notifyServerChange(server);
|
||||
}
|
||||
if (content != null) sense.editor.getSession().setValue(content);
|
||||
sense.output.getSession().setValue("");
|
||||
|
||||
}
|
||||
|
||||
function constructESUrl(server, url) {
|
||||
if (url.indexOf("://") >= 0) return url;
|
||||
if (server.indexOf("://") < 0) server = "http://" + server;
|
||||
if (server.substr(-1) == "/") {
|
||||
server = server.substr(0, server.length - 1);
|
||||
}
|
||||
if (url.charAt(0) === "/") url = url.substr(1);
|
||||
|
||||
return server + "/" + url;
|
||||
}
|
||||
|
||||
function callES(server, url, method, data, successCallback, completeCallback) {
|
||||
|
||||
url = constructESUrl(server, url);
|
||||
var uname_password_re = /^(https?:\/\/)?(?:(?:([^\/]*):)?([^\/]*?)@)?(.*)$/;
|
||||
var url_parts = url.match(uname_password_re);
|
||||
|
||||
var uname = url_parts[2];
|
||||
var password = url_parts[3];
|
||||
url = url_parts[1] + url_parts[4];
|
||||
console.log("Calling " + url + " (uname: " + uname + " pwd: " + password + ")");
|
||||
if (data && method == "GET") method = "POST";
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: method == "GET" ? null : data,
|
||||
// xhrFields: {
|
||||
// withCredentials: true
|
||||
// },
|
||||
// headers: {
|
||||
// "Authorization": "Basic " + btoa(uname + ":" + password)
|
||||
// },
|
||||
// beforeSend: function(xhr){
|
||||
// xhr.withCredentials = true;
|
||||
// xhr.setRequestHeader("Authorization", "Basic " + btoa(uname + ":" + password));
|
||||
// },
|
||||
|
||||
password: password,
|
||||
username: uname,
|
||||
crossDomain: true,
|
||||
type: method,
|
||||
dataType: "json",
|
||||
complete: completeCallback,
|
||||
success: successCallback
|
||||
});
|
||||
}
|
||||
|
||||
function submitCurrentRequestToES() {
|
||||
var req = sense.utils.getCurrentRequest();
|
||||
if (!req) return;
|
||||
|
||||
$("#notification").text("Calling ES....").css("visibility", "visible");
|
||||
sense.output.getSession().setValue('');
|
||||
|
||||
var es_server = $("#es_server").val(),
|
||||
es_url = req.url,
|
||||
es_method = req.method,
|
||||
es_data = req.data.join("\n");
|
||||
if (es_data) es_data += "\n"; //append a new line for bulk requests.
|
||||
|
||||
callES(es_server, es_url, es_method, es_data, null, function (xhr, status) {
|
||||
$("#notification").text("").css("visibility", "hidden");
|
||||
if (typeof xhr.status == "number" &&
|
||||
((xhr.status >= 400 && xhr.status < 600) ||
|
||||
(xhr.status >= 200 && xhr.status < 300)
|
||||
)) {
|
||||
// we have someone on the other side. Add to history
|
||||
sense.history.addToHistory(es_server, es_url, es_method, es_data);
|
||||
|
||||
|
||||
var value = xhr.responseText;
|
||||
try {
|
||||
value = JSON.stringify(JSON.parse(value), null, 3);
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
}
|
||||
sense.output.getSession().setValue(value);
|
||||
}
|
||||
else {
|
||||
sense.output.getSession().setValue("Request failed to get to the server (status code: " + xhr.status + "):" + xhr.responseText);
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
saveEditorState();
|
||||
|
||||
_gaq.push(['_trackEvent', "elasticsearch", 'query']);
|
||||
}
|
||||
|
||||
submitCurrentRequestToES = autoRetryIfTokenizing(submitCurrentRequestToES);
|
||||
|
||||
function reformatData(data, indent) {
|
||||
var changed = false;
|
||||
var formatted_data = [];
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var cur_doc = data[i];
|
||||
try {
|
||||
var new_doc = JSON.stringify(JSON.parse(cur_doc), null, indent ? 3 : 0);
|
||||
changed = changed || new_doc != cur_doc;
|
||||
formatted_data.push(new_doc);
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e);
|
||||
formatted_data.push(cur_doc);
|
||||
}
|
||||
}
|
||||
|
||||
return { changed: changed, data: formatted_data}
|
||||
}
|
||||
|
||||
|
||||
function autoIndent() {
|
||||
var req_range = sense.utils.getCurrentRequestRange();
|
||||
if (!req_range) return;
|
||||
var parsed_req = sense.utils.getCurrentRequest();
|
||||
if (parsed_req.data && parsed_req.data.length > 0) {
|
||||
var indent = parsed_req.data.length == 1; // unindent multi docs by default
|
||||
var formatted_data = reformatData(parsed_req.data, indent);
|
||||
if (!formatted_data.changed) {
|
||||
// toggle.
|
||||
formatted_data = reformatData(parsed_req.data, !indent);
|
||||
}
|
||||
parsed_req.data = formatted_data.data;
|
||||
|
||||
sense.utils.replaceCurrentRequest(parsed_req, req_range);
|
||||
}
|
||||
}
|
||||
|
||||
autoIndent = autoRetryIfTokenizing(autoIndent);
|
||||
|
||||
function copyToClipboard(value) {
|
||||
var currentActive = document.activeElement;
|
||||
var clipboardStaging = $("#clipboardStaging");
|
||||
clipboardStaging.val(value);
|
||||
clipboardStaging.select();
|
||||
document.execCommand("Copy", false);
|
||||
$(currentActive).focus(); // restore focus.
|
||||
}
|
||||
|
||||
function copyAsCURL() {
|
||||
var req = sense.utils.getCurrentRequest();
|
||||
if (!req) return;
|
||||
|
||||
_gaq.push(['_trackEvent', "curl", 'copied']);
|
||||
|
||||
var es_server = $("#es_server").val(),
|
||||
es_url = req.url,
|
||||
es_method = req.method,
|
||||
es_data = req.data;
|
||||
|
||||
var url = constructESUrl(es_server, es_url);
|
||||
|
||||
var curl = 'curl -X' + es_method + ' "' + url + '"';
|
||||
if (es_data && es_data.length) {
|
||||
curl += " -d'\n";
|
||||
// since Sense doesn't allow single quote json string any single qoute is within a string.
|
||||
curl += es_data.join("\n").replace(/'/g, '\\"');
|
||||
if (es_data.length > 1) curl += "\n"; // end with a new line
|
||||
curl += "'";
|
||||
}
|
||||
|
||||
//console.log(curl);
|
||||
copyToClipboard(curl);
|
||||
|
||||
}
|
||||
|
||||
copyAsCURL = autoRetryIfTokenizing(copyAsCURL, true);
|
||||
|
||||
|
||||
function handleCURLPaste(text) {
|
||||
_gaq.push(['_trackEvent', "curl", 'pasted']);
|
||||
var curlInput = sense.curl.parseCURL(text);
|
||||
if ($("#es_server").val()) curlInput.server = null; // do not override server
|
||||
|
||||
if (!curlInput.method) curlInput.method = "GET";
|
||||
|
||||
sense.editor.insert(sense.utils.textFromRequest(curlInput));
|
||||
|
||||
}
|
||||
|
||||
|
||||
var CURRENT_REQ_RANGE = null;
|
||||
|
||||
|
||||
function saveEditorState() {
|
||||
try {
|
||||
var content = sense.editor.getValue();
|
||||
var server = $("#es_server").val();
|
||||
sense.history.saveCurrentEditorState(server, content);
|
||||
}
|
||||
catch (e) {
|
||||
console.log("Ignoring saving error: " + e)
|
||||
}
|
||||
}
|
||||
|
||||
function updateEditorActionsBar() {
|
||||
var editor_actions = $("#editor_actions");
|
||||
|
||||
if (CURRENT_REQ_RANGE) {
|
||||
var row = CURRENT_REQ_RANGE.start.row;
|
||||
var column = CURRENT_REQ_RANGE.start.column;
|
||||
var session = sense.editor.session;
|
||||
var firstLine = session.getLine(row);
|
||||
var offset = 0;
|
||||
if (firstLine.length > session.getScreenWidth() - 5) {
|
||||
// overlap first row
|
||||
if (row > 0) row--; else row++;
|
||||
}
|
||||
var screen_pos = sense.editor.renderer.textToScreenCoordinates(row, column);
|
||||
offset += screen_pos.pageY;
|
||||
var end_offset = sense.editor.renderer.textToScreenCoordinates(CURRENT_REQ_RANGE.end.row,
|
||||
CURRENT_REQ_RANGE.end.column).pageY;
|
||||
|
||||
offset = Math.min(end_offset, Math.max(offset, 47));
|
||||
if (offset >= 47) {
|
||||
editor_actions.css("top", Math.max(offset, 47));
|
||||
editor_actions.css('visibility', 'visible');
|
||||
}
|
||||
else {
|
||||
editor_actions.css("top", 0);
|
||||
editor_actions.css('visibility', 'hidden');
|
||||
}
|
||||
}
|
||||
else {
|
||||
editor_actions.css("top", 0);
|
||||
editor_actions.css('visibility', 'hidden');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function highlighCurrentRequestAndUpdateActionBar() {
|
||||
var session = sense.editor.getSession();
|
||||
var new_current_req_range = sense.utils.getCurrentRequestRange();
|
||||
if (new_current_req_range == null && CURRENT_REQ_RANGE == null) return;
|
||||
if (new_current_req_range != null && CURRENT_REQ_RANGE != null &&
|
||||
new_current_req_range.start.row == CURRENT_REQ_RANGE.start.row &&
|
||||
new_current_req_range.end.row == CURRENT_REQ_RANGE.end.row
|
||||
) {
|
||||
// same request, now see if we are on the first line and update the action bar
|
||||
var cursorRow = sense.editor.getCursorPosition().row;
|
||||
if (cursorRow == CURRENT_REQ_RANGE.start.row) {
|
||||
updateEditorActionsBar();
|
||||
}
|
||||
return; // nothing to do..
|
||||
}
|
||||
|
||||
if (CURRENT_REQ_RANGE) {
|
||||
session.removeMarker(CURRENT_REQ_RANGE.marker_id);
|
||||
}
|
||||
|
||||
CURRENT_REQ_RANGE = new_current_req_range;
|
||||
if (CURRENT_REQ_RANGE) {
|
||||
CURRENT_REQ_RANGE.marker_id = session.addMarker(CURRENT_REQ_RANGE, "ace_snippet-marker", "fullLine");
|
||||
}
|
||||
updateEditorActionsBar();
|
||||
}
|
||||
|
||||
highlighCurrentRequestAndUpdateActionBar = autoRetryIfTokenizing(highlighCurrentRequestAndUpdateActionBar, true);
|
||||
|
||||
function moveToPreviousRequestEdge() {
|
||||
var pos = sense.editor.getCursorPosition();
|
||||
for (pos.row--; pos.row > 0 && !sense.utils.isRequestEdge(pos.row); pos.row--) {
|
||||
}
|
||||
sense.editor.moveCursorTo(pos.row, 0);
|
||||
}
|
||||
|
||||
moveToPreviousRequestEdge = autoRetryIfTokenizing(moveToPreviousRequestEdge);
|
||||
|
||||
|
||||
function moveToNextRequestEdge() {
|
||||
var pos = sense.editor.getCursorPosition();
|
||||
var maxRow = sense.editor.getSession().getLength();
|
||||
for (pos.row++; pos.row < maxRow && !sense.utils.isRequestEdge(pos.row); pos.row++) {
|
||||
}
|
||||
sense.editor.moveCursorTo(pos.row, 0);
|
||||
}
|
||||
|
||||
moveToNextRequestEdge = autoRetryIfTokenizing(moveToNextRequestEdge);
|
||||
|
||||
function init() {
|
||||
|
||||
sense.editor = ace.edit("editor");
|
||||
ace.require("ace/mode/sense");
|
||||
sense.editor.getSession().setMode("ace/mode/sense");
|
||||
sense.editor.setShowPrintMargin(false);
|
||||
sense.editor.getSession().setFoldStyle('markbeginend');
|
||||
sense.editor.getSession().setUseWrapMode(true);
|
||||
sense.editor.commands.addCommand({
|
||||
name: 'autocomplete',
|
||||
bindKey: {win: 'Ctrl-Space', mac: 'Ctrl-Space'},
|
||||
exec: sense.autocomplete.editorAutocompleteCommand
|
||||
});
|
||||
sense.editor.commands.addCommand({
|
||||
name: 'auto indent request',
|
||||
bindKey: {win: 'Ctrl-I', mac: 'Command-I'},
|
||||
exec: autoIndent
|
||||
});
|
||||
sense.editor.commands.addCommand({
|
||||
name: 'send to elasticsearch',
|
||||
bindKey: {win: 'Ctrl-Enter', mac: 'Command-Enter'},
|
||||
exec: submitCurrentRequestToES
|
||||
});
|
||||
|
||||
sense.editor.commands.addCommand({
|
||||
name: 'copy as cUrl',
|
||||
bindKey: {win: 'Ctrl-Shift-C', mac: 'Command-Shift-C'},
|
||||
exec: copyAsCURL
|
||||
});
|
||||
|
||||
sense.editor.commands.addCommand({
|
||||
name: 'move to previous request start or end',
|
||||
bindKey: {win: 'Ctrl-Up', mac: 'Command-Up'},
|
||||
exec: moveToPreviousRequestEdge
|
||||
});
|
||||
|
||||
sense.editor.commands.addCommand({
|
||||
name: 'move to next request start or end',
|
||||
bindKey: {win: 'Ctrl-Down', mac: 'Command-Down'},
|
||||
exec: moveToNextRequestEdge
|
||||
});
|
||||
|
||||
|
||||
var orig_paste = sense.editor.onPaste;
|
||||
sense.editor.onPaste = function (text) {
|
||||
if (text && sense.curl.detectCURL(text)) {
|
||||
handleCURLPaste(text);
|
||||
return;
|
||||
}
|
||||
orig_paste.call(this, text);
|
||||
};
|
||||
|
||||
sense.editor.getSession().on('tokenizerUpdate', function (e) {
|
||||
highlighCurrentRequestAndUpdateActionBar();
|
||||
});
|
||||
|
||||
sense.editor.getSession().selection.on('changeCursor', function (e) {
|
||||
highlighCurrentRequestAndUpdateActionBar();
|
||||
});
|
||||
|
||||
|
||||
var save_generation = 0;
|
||||
|
||||
function get_save_callback(for_generation) {
|
||||
return function () {
|
||||
if (save_generation == for_generation) {
|
||||
saveEditorState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sense.editor.getSession().on("change", function (e) {
|
||||
setTimeout(get_save_callback(++save_generation), 500);
|
||||
});
|
||||
|
||||
sense.editor.getSession().on("changeScrollTop", updateEditorActionsBar);
|
||||
|
||||
|
||||
sense.output = ace.edit("output");
|
||||
sense.output.getSession().setMode("ace/mode/json");
|
||||
sense.output.getSession().setFoldStyle('markbeginend');
|
||||
sense.output.getSession().setUseWrapMode(true);
|
||||
sense.output.setShowPrintMargin(false);
|
||||
sense.output.setReadOnly(true);
|
||||
|
||||
var editorElement = $("#editor"),
|
||||
outputElement = $("#output"),
|
||||
editorActions = $("#editor_actions");
|
||||
|
||||
|
||||
editorElement.resizable(
|
||||
{
|
||||
autoHide: false,
|
||||
handles: 'e',
|
||||
start: function (e, ui) {
|
||||
editor_resizebar = $(".ui-resizable-e").addClass("active");
|
||||
},
|
||||
stop: function (e, ui) {
|
||||
editor_resizebar = $(".ui-resizable-e").removeClass("active");
|
||||
|
||||
var parent = ui.element.parent();
|
||||
var editorSize = ui.element.outerWidth();
|
||||
outputElement.css("left", editorSize+20);
|
||||
editorActions.css("margin-right", -editorSize + 3);
|
||||
sense.editor.resize(true);
|
||||
sense.output.resize(true);
|
||||
}
|
||||
});
|
||||
|
||||
sense.history.init();
|
||||
sense.autocomplete.init();
|
||||
sense.settings.init();
|
||||
|
||||
$("#send").tooltip();
|
||||
$("#send").click(function () {
|
||||
submitCurrentRequestToES();
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#copy_as_curl").click(function (e) {
|
||||
copyAsCURL();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
$("#auto_indent").click(function (e) {
|
||||
autoIndent();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
var help_popup = $("#help_popup");
|
||||
|
||||
help_popup.on('shown', function () {
|
||||
_gaq.push(['_trackEvent', "help", 'shown']);
|
||||
$('<div id="example_editor">PUT index/type/1\n'
|
||||
+ '{\n'
|
||||
+ ' "body": "here"\n'
|
||||
+ '}\n\n'
|
||||
+ 'GET index/type/1\n'
|
||||
+ '</div>').appendTo(help_popup.find("#example_editor_container"));
|
||||
|
||||
var example_editor = ace.edit("example_editor");
|
||||
example_editor.getSession().setMode("ace/mode/sense");
|
||||
example_editor.getSession().setFoldStyle('markbeginend');
|
||||
example_editor.setReadOnly(true);
|
||||
example_editor.renderer.setShowPrintMargin(false);
|
||||
});
|
||||
|
||||
help_popup.on('hidden', function () {
|
||||
help_popup.find('#example_editor').remove();
|
||||
|
||||
});
|
||||
|
||||
|
||||
var es_server = $("#es_server");
|
||||
|
||||
es_server.blur(function () {
|
||||
sense.mappings.notifyServerChange(es_server.val());
|
||||
});
|
||||
|
||||
var editor_source = sense.utils.getUrlParam('load_from') || "stored";
|
||||
var last_editor_state = sense.history.getSavedEditorState();
|
||||
if (editor_source == "stored") {
|
||||
if (last_editor_state) {
|
||||
resetToValues(last_editor_state.server, last_editor_state.content);
|
||||
}
|
||||
else {
|
||||
autoIndent();
|
||||
}
|
||||
}
|
||||
else if (/^https?:\/\//.exec(editor_source)) {
|
||||
$.get(editor_source, null, function (data) {
|
||||
resetToValues(null, data);
|
||||
highlighCurrentRequestAndUpdateActionBar();
|
||||
updateEditorActionsBar();
|
||||
});
|
||||
}
|
||||
else {
|
||||
if (last_editor_state) {
|
||||
resetToValues(last_editor_state.server);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.location.pathname && document.location.pathname.indexOf("_plugin") == 1) {
|
||||
// running as an ES plugin. Always assume we are using that elasticsearch
|
||||
resetToValues(document.location.host);
|
||||
}
|
||||
|
||||
sense.editor.focus();
|
||||
highlighCurrentRequestAndUpdateActionBar();
|
||||
updateEditorActionsBar();
|
||||
|
||||
if (!localStorage.getItem("version_welcome_shown")) {
|
||||
localStorage.setItem("version_welcome_shown", sense.VERSION);
|
||||
var welcome_popup = $("#welcome_popup");
|
||||
welcome_popup.modal();
|
||||
welcome_popup.on('shown', function () {
|
||||
$('<div id="example_editor">PUT index/type/1\n'
|
||||
+ '{\n'
|
||||
+ ' "body": "here"\n'
|
||||
+ '}\n\n'
|
||||
+ 'GET index/type/1\n'
|
||||
+ '</div>').appendTo(welcome_popup.find("#example_editor_container"));
|
||||
|
||||
var example_editor = ace.edit("example_editor");
|
||||
example_editor.getSession().setMode("ace/mode/sense");
|
||||
example_editor.getSession().setFoldStyle('markbeginend');
|
||||
example_editor.setReadOnly(true);
|
||||
example_editor.renderer.setShowPrintMargin(false);
|
||||
});
|
||||
|
||||
welcome_popup.on('hidden', function () {
|
||||
welcome_popup.find('#example_editor').remove();
|
||||
|
||||
});
|
||||
// welcome_popup.modal('show');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(init);
|
||||
|
||||
/* google analytics */
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-11830182-16']);
|
||||
_gaq.push(['_setCustomVar',
|
||||
1, // This custom var is set to slot #1. Required parameter.
|
||||
'Version', // The name of the custom variable. Required parameter.
|
||||
sense.VERSION, // The value of the custom variable. Required parameter.
|
||||
1 // Sets the scope to visitor-level. Optional parameter.
|
||||
]);
|
||||
|
||||
_gaq.push(['_trackPageview']);
|
||||
|
||||
(function () {
|
||||
var ga = document.createElement('script');
|
||||
ga.type = 'text/javascript';
|
||||
ga.async = true;
|
||||
ga.src = 'https://ssl.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0];
|
||||
s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
(function () {
|
||||
var global = window;
|
||||
if (!global.sense)
|
||||
global.sense = {};
|
||||
|
||||
function detectCURL(text) {
|
||||
// returns true if text matches a curl request
|
||||
if (!text) return false;
|
||||
return text.match(/^\s*?curl\s+(-X[A-Z]+)?\s*['"]?.*?['"]?(\s*$|\s+?-d\s*?['"])/);
|
||||
|
||||
}
|
||||
|
||||
function parseCURL(text) {
|
||||
var matches = text.match(/^\s*?curl\s+(?:-s\s+)?(-X\s*[A-Z]+)?\s*/);
|
||||
var ret = {
|
||||
method: "",
|
||||
server: "",
|
||||
endpoint: "",
|
||||
data: ""
|
||||
};
|
||||
if (matches[1]) {
|
||||
ret.method = matches[1].substring(2).trim(); // strip -X
|
||||
}
|
||||
text = text.substring(matches[0].length); // strip everything so far.
|
||||
if (text.length == 0) return ret;
|
||||
if (text[0] == '"') {
|
||||
matches = text.match(/^"([^"]*)"/);
|
||||
}
|
||||
else if (text[0] == "'") {
|
||||
matches = text.match(/^'([^']*)'/);
|
||||
}
|
||||
else {
|
||||
matches = text.match(/^(\S*)/);
|
||||
}
|
||||
|
||||
if (!matches) return ret;
|
||||
var url = matches[1];
|
||||
|
||||
if (!url.match(/:\/\//)) url = "http://" + url; // inject http as curl does
|
||||
|
||||
var urlAnchor = document.createElement("a");
|
||||
urlAnchor.href = url;
|
||||
|
||||
ret.server = (urlAnchor.protocol || "http") + "//" + urlAnchor.hostname;
|
||||
if (urlAnchor.port && urlAnchor.port != 0) ret.server += ":" + urlAnchor.port;
|
||||
ret.url = (urlAnchor.pathname || "") + (urlAnchor.search || "");
|
||||
|
||||
text = text.substring(matches[0].length);
|
||||
|
||||
// now search for -d
|
||||
matches = text.match(/.*-d\s*?'/);
|
||||
if (matches) {
|
||||
ret.data = text.substring(matches[0].length).replace(/'\s*$/, '');
|
||||
}
|
||||
else {
|
||||
matches = text.match(/.*-d\s*?"/);
|
||||
if (matches) {
|
||||
ret.data = text.substring(matches[0].length).replace(/"\s*$/, '');
|
||||
ret.data = ret.data.replace(/\\(.)/gi, "$1");
|
||||
}
|
||||
}
|
||||
|
||||
if (ret.data) {
|
||||
ret.data = ret.data.trim();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
global.sense.curl = {};
|
||||
global.sense.curl.parseCURL = parseCURL;
|
||||
global.sense.curl.detectCURL = detectCURL;
|
||||
|
||||
})();
|
|
@ -1,199 +0,0 @@
|
|||
(function () {
|
||||
|
||||
var global = window;
|
||||
|
||||
var history_viewer, history_popup;
|
||||
|
||||
function getHistoryKeys() {
|
||||
var keys = [];
|
||||
for (var i = 0; i < localStorage.length; i++) {
|
||||
var k = localStorage.key(i);
|
||||
if (k.indexOf("hist_elem") == 0) {
|
||||
keys.push(k);
|
||||
}
|
||||
}
|
||||
|
||||
keys.sort();
|
||||
keys.reverse();
|
||||
return keys;
|
||||
}
|
||||
|
||||
function getHistory() {
|
||||
var hist_items = [];
|
||||
$.each(getHistoryKeys(), function (i, key) {
|
||||
hist_items.push(JSON.parse(localStorage.getItem(key)));
|
||||
});
|
||||
|
||||
return hist_items;
|
||||
}
|
||||
|
||||
function getHistoricalServers() {
|
||||
var servers = {};
|
||||
$.each(getHistory(), function (i, h) {
|
||||
servers[h.server] = 1;
|
||||
});
|
||||
|
||||
var server_list = [];
|
||||
for (var s in servers) server_list.push(s);
|
||||
|
||||
return server_list;
|
||||
}
|
||||
|
||||
function populateHistElem(hist_elem) {
|
||||
var s = hist_elem.method + " " + hist_elem.endpoint + "\n" + (hist_elem.data || "");
|
||||
history_viewer.setValue(s);
|
||||
history_viewer.clearSelection();
|
||||
}
|
||||
|
||||
function applyHistElem(hist_elem) {
|
||||
var session = sense.editor.getSession();
|
||||
var pos = sense.editor.getCursorPosition();
|
||||
var prefix = "";
|
||||
var suffix = "\n";
|
||||
if (sense.utils.isStartRequestRow(pos.row)) {
|
||||
pos.column = 0;
|
||||
suffix += "\n";
|
||||
}
|
||||
else if (sense.utils.isEndRequestRow(pos.row)) {
|
||||
var line = session.getLine(pos.row);
|
||||
pos.column = line.length;
|
||||
prefix = "\n\n";
|
||||
}
|
||||
else if (sense.utils.isInBetweenRequestsRow(pos.row)) {
|
||||
pos.column = 0;
|
||||
}
|
||||
else {
|
||||
pos = sense.utils.nextRequestEnd(pos);
|
||||
prefix = "\n\n";
|
||||
}
|
||||
|
||||
var s = prefix + hist_elem.method + " " + hist_elem.endpoint;
|
||||
if (hist_elem.data) s += "\n" + hist_elem.data;
|
||||
|
||||
s += suffix;
|
||||
|
||||
session.insert(pos, s);
|
||||
sense.editor.clearSelection();
|
||||
sense.editor.moveCursorTo(pos.row + prefix.length, 0);
|
||||
sense.editor.focus();
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
history_popup = $("#history_popup");
|
||||
|
||||
|
||||
history_popup.on('shown', function () {
|
||||
$('<div id="history_viewer">No history available</div>').appendTo(history_popup.find(".modal-body"));
|
||||
|
||||
history_viewer = ace.edit("history_viewer");
|
||||
history_viewer.getSession().setMode("ace/mode/sense");
|
||||
// history_viewer.setTheme("ace/theme/monokai");
|
||||
history_viewer.getSession().setFoldStyle('markbeginend');
|
||||
history_viewer.setReadOnly(true);
|
||||
history_viewer.renderer.setShowPrintMargin(false);
|
||||
sense.editor.getSession().setUseWrapMode(true);
|
||||
|
||||
$.each(getHistory(), function (i, hist_elem) {
|
||||
var li = $('<li><a href="#"><i class="icon-chevron-right"></i><span/></a></li>');
|
||||
var disc = hist_elem.endpoint;
|
||||
var date = moment(hist_elem.time);
|
||||
if (date.diff(moment(), "days") < -7)
|
||||
disc += " (" + date.format("MMM D") + ")";
|
||||
else
|
||||
disc += " (" + date.fromNow() + ")";
|
||||
|
||||
li.find("span").text(disc);
|
||||
li.attr("title", disc);
|
||||
|
||||
li.find("a").click(function () {
|
||||
history_popup.find('.modal-body .nav li').removeClass("active");
|
||||
li.addClass("active");
|
||||
populateHistElem(hist_elem);
|
||||
return false;
|
||||
});
|
||||
|
||||
li.dblclick(function () {
|
||||
li.addClass("active");
|
||||
history_popup.find(".btn-primary").click();
|
||||
});
|
||||
|
||||
li.hover(function () {
|
||||
populateHistElem(hist_elem);
|
||||
return false;
|
||||
}, function () {
|
||||
history_popup.find(".modal-body .nav li.active a").click();
|
||||
});
|
||||
|
||||
li.bind('apply', function () {
|
||||
_gaq.push(['_trackEvent', "history", 'applied']);
|
||||
applyHistElem(hist_elem);
|
||||
});
|
||||
|
||||
|
||||
li.appendTo(history_popup.find(".modal-body .nav"));
|
||||
});
|
||||
|
||||
history_popup.find(".modal-body .nav li:first a").click();
|
||||
|
||||
});
|
||||
|
||||
history_popup.on('hidden', function () {
|
||||
history_popup.find('.modal-body #history_viewer').remove();
|
||||
history_popup.find('.modal-body .nav li').remove();
|
||||
history_viewer = null;
|
||||
});
|
||||
|
||||
history_popup.find(".btn-primary").click(function () {
|
||||
history_popup.find(".modal-body .nav li.active").trigger("apply");
|
||||
});
|
||||
|
||||
history_popup.find("#hist_clear").click(function () {
|
||||
var keys = getHistoryKeys();
|
||||
$.each(keys, function (i, k) {
|
||||
localStorage.removeItem(k);
|
||||
});
|
||||
history_popup.find(".modal-body .nav").html("");
|
||||
history_viewer.getSession().setValue("No history available");
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function addToHistory(server, endpoint, method, data) {
|
||||
var keys = getHistoryKeys();
|
||||
keys.splice(0, 500); // only maintain most recent X;
|
||||
$.each(keys, function (i, k) {
|
||||
localStorage.removeItem(k);
|
||||
});
|
||||
|
||||
var timestamp = new Date().getTime();
|
||||
var k = "hist_elem_" + timestamp;
|
||||
localStorage.setItem(k, JSON.stringify(
|
||||
{ 'time': timestamp, 'server': server, 'endpoint': endpoint, 'method': method, 'data': data }));
|
||||
}
|
||||
|
||||
function saveCurrentEditorState(server, content) {
|
||||
var timestamp = new Date().getTime();
|
||||
localStorage.setItem("editor_state", JSON.stringify(
|
||||
{ 'time': timestamp, 'server': server, 'content': content }));
|
||||
|
||||
}
|
||||
|
||||
function getSavedEditorState(server, content) {
|
||||
return JSON.parse(localStorage.getItem("editor_state"));
|
||||
}
|
||||
|
||||
global.sense.history = {
|
||||
init: init,
|
||||
addToHistory: addToHistory,
|
||||
getHistoricalServers: getHistoricalServers,
|
||||
saveCurrentEditorState: saveCurrentEditorState,
|
||||
getSavedEditorState: getSavedEditorState
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
||||
|
129
sense/src/kb.js
|
@ -1,129 +0,0 @@
|
|||
(function () {
|
||||
|
||||
var global = window;
|
||||
var GLOBAL_AUTOCOMPLETE_RULES = {}, ES_SCHEME_BY_ENDPOINT = {};
|
||||
|
||||
function escapeRegex(text) {
|
||||
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
}
|
||||
|
||||
function addGlobalAutocompleteRules(parentNode, rules) {
|
||||
GLOBAL_AUTOCOMPLETE_RULES[parentNode] = rules;
|
||||
}
|
||||
|
||||
function getGlobalAutocompleteRules() {
|
||||
return GLOBAL_AUTOCOMPLETE_RULES;
|
||||
}
|
||||
|
||||
|
||||
function addEndpointDescription(endpoint, description) {
|
||||
if (!description.endpoint_autocomplete)
|
||||
description.endpoint_autocomplete = [endpoint];
|
||||
|
||||
if (!description.match) {
|
||||
var l = $.map(description.endpoint_autocomplete, escapeRegex);
|
||||
description.match = "(?:" + l.join(")|(?:") + ")";
|
||||
}
|
||||
|
||||
if (typeof description.match == "string") description.match = new RegExp(description.match);
|
||||
|
||||
var copiedDescription = {};
|
||||
$.extend(copiedDescription, description);
|
||||
copiedDescription._id = endpoint;
|
||||
|
||||
ES_SCHEME_BY_ENDPOINT[endpoint] = copiedDescription;
|
||||
}
|
||||
|
||||
function getEndpointDescriptionByEndpoint(endpoint) {
|
||||
return ES_SCHEME_BY_ENDPOINT[endpoint];
|
||||
}
|
||||
|
||||
function getEndpointsForIndicesTypesAndId(indices, types, id) {
|
||||
var ret = [];
|
||||
var index_mode = "none";
|
||||
if (indices && indices.length > 0) {
|
||||
indices = sense.mappings.expandAliases(indices);
|
||||
index_mode = typeof indices == "string" ? "single" : "multi";
|
||||
}
|
||||
|
||||
var type_mode = "none";
|
||||
if (types && types.length > 0) type_mode = types.length > 1 ? "multi" : "single";
|
||||
var id_mode = "none";
|
||||
if (id && id.length > 0) id_mode = "single";
|
||||
|
||||
for (var endpoint in ES_SCHEME_BY_ENDPOINT) {
|
||||
var scheme = ES_SCHEME_BY_ENDPOINT[endpoint];
|
||||
switch (scheme.indices_mode) {
|
||||
case "none":
|
||||
if (index_mode !== "none") continue;
|
||||
break;
|
||||
case "single":
|
||||
if (index_mode !== "single") continue;
|
||||
break;
|
||||
case "required_multi":
|
||||
if (index_mode === "none") continue;
|
||||
break;
|
||||
case "multi": // always good
|
||||
break;
|
||||
}
|
||||
switch (scheme.types_mode) {
|
||||
case "none":
|
||||
if (type_mode !== "none") continue;
|
||||
break;
|
||||
case "single":
|
||||
if (type_mode !== "single") continue;
|
||||
break;
|
||||
case "multi": // always good
|
||||
break;
|
||||
}
|
||||
|
||||
switch (scheme.doc_id_mode) {
|
||||
case "none":
|
||||
if (id_mode !== "none") continue;
|
||||
break;
|
||||
case "required_single":
|
||||
if (id_mode === "none") continue;
|
||||
break;
|
||||
}
|
||||
|
||||
ret.push(endpoint);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function getEndpointDescriptionByPath(path, indices, types, id) {
|
||||
var endpoints = getEndpointsForIndicesTypesAndId(indices, types, id);
|
||||
for (var i = 0; i < endpoints.length; i++) {
|
||||
var scheme = ES_SCHEME_BY_ENDPOINT[endpoints[i]];
|
||||
if (scheme.match.test(path || "")) return scheme;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getEndpointAutocomplete(indices, types, id) {
|
||||
var ret = [];
|
||||
var endpoints = getEndpointsForIndicesTypesAndId(indices, types, id);
|
||||
for (var i = 0; i < endpoints.length; i++) {
|
||||
var scheme = ES_SCHEME_BY_ENDPOINT[endpoints[i]];
|
||||
ret.push.apply(ret, scheme.endpoint_autocomplete);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function clear() {
|
||||
ES_SCHEME_BY_ENDPOINT = {};
|
||||
GLOBAL_AUTOCOMPLETE_RULES = {};
|
||||
}
|
||||
|
||||
if (!global.sense) global.sense = {};
|
||||
global.sense.kb = {};
|
||||
global.sense.kb.addGlobalAutocompleteRules = addGlobalAutocompleteRules;
|
||||
global.sense.kb.getGlobalAutocompleteRules = getGlobalAutocompleteRules;
|
||||
global.sense.kb.addEndpointDescription = addEndpointDescription;
|
||||
global.sense.kb.getEndpointAutocomplete = getEndpointAutocomplete;
|
||||
global.sense.kb.getEndpointDescriptionByPath = getEndpointDescriptionByPath;
|
||||
global.sense.kb.getEndpointDescriptionByEndpoint = getEndpointDescriptionByEndpoint;
|
||||
global.sense.kb.clear = clear;
|
||||
|
||||
|
||||
})();
|
|
@ -1,231 +0,0 @@
|
|||
(function () {
|
||||
|
||||
var global = window;
|
||||
|
||||
var currentServer;
|
||||
var per_index_types = {};
|
||||
var per_alias_indexes = [];
|
||||
|
||||
|
||||
function expandAliases(indicesOrAliases) {
|
||||
// takes a list of indices or aliases or a string which may be either and returns a list of indices
|
||||
// returns a list for multiple values or a string for a single.
|
||||
|
||||
if (!indicesOrAliases) return indicesOrAliases;
|
||||
|
||||
if (typeof indicesOrAliases === "string") indicesOrAliases = [indicesOrAliases];
|
||||
indicesOrAliases = $.map(indicesOrAliases, function (iOrA) {
|
||||
if (per_alias_indexes[iOrA]) return per_alias_indexes[iOrA];
|
||||
return [iOrA];
|
||||
});
|
||||
var ret = [].concat.apply([], indicesOrAliases);
|
||||
ret.sort();
|
||||
var last;
|
||||
ret = $.map(ret, function (v) {
|
||||
var r = last == v ? null : v;
|
||||
last = v;
|
||||
return r;
|
||||
});
|
||||
return ret.length > 1 ? ret : ret[0];
|
||||
}
|
||||
|
||||
function getFields(indices, types) {
|
||||
// get fields for indices and types. Both can be a list, a string or null (meaning all).
|
||||
var ret = [];
|
||||
indices = expandAliases(indices);
|
||||
if (typeof indices == "string") {
|
||||
|
||||
var type_dict = per_index_types[indices];
|
||||
if (!type_dict) return [];
|
||||
|
||||
if (typeof types == "string") {
|
||||
var f = type_dict[types];
|
||||
ret = f ? f : [];
|
||||
}
|
||||
else {
|
||||
// filter what we need
|
||||
$.each(type_dict, function (type, fields) {
|
||||
if (!types || types.length == 0 || $.inArray(type, types) != -1)
|
||||
ret.push(fields);
|
||||
});
|
||||
|
||||
ret = [].concat.apply([], ret);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// multi index mode.
|
||||
$.each(per_index_types, function (index) {
|
||||
if (!indices || indices.length == 0 || $.inArray(index, indices) != -1)
|
||||
ret.push(getFields(index, types));
|
||||
});
|
||||
ret = [].concat.apply([], ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function getTypes(indices) {
|
||||
var ret = [];
|
||||
indices = expandAliases(indices);
|
||||
if (typeof indices == "string") {
|
||||
var type_dict = per_index_types[indices];
|
||||
if (!type_dict) return [];
|
||||
|
||||
// filter what we need
|
||||
$.each(type_dict, function (type, fields) {
|
||||
ret.push(type);
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
// multi index mode.
|
||||
$.each(per_index_types, function (index) {
|
||||
if (!indices || $.inArray(index, indices) != -1)
|
||||
ret.push(getTypes(index));
|
||||
});
|
||||
ret = [].concat.apply([], ret);
|
||||
}
|
||||
|
||||
return ret.filter(function (v, i, a) {
|
||||
return a.indexOf(v) == i
|
||||
}); // dedupe array;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getIndices(include_aliases) {
|
||||
var ret = [];
|
||||
$.each(per_index_types, function (index) {
|
||||
ret.push(index);
|
||||
});
|
||||
if (typeof include_aliases === "undefined" ? true : include_aliases) {
|
||||
$.each(per_alias_indexes, function (alias) {
|
||||
ret.push(alias);
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
function getFieldNamesFromFieldMapping(field_name, field_mapping) {
|
||||
if (field_mapping['enabled'] == false) return [];
|
||||
|
||||
|
||||
function applyPathSettings(nested_field_names) {
|
||||
var path_type = field_mapping['path'] || "full";
|
||||
if (path_type == "full") {
|
||||
return $.map(nested_field_names, function (f) {
|
||||
return field_name + "." + f;
|
||||
});
|
||||
}
|
||||
return nested_field_names;
|
||||
}
|
||||
|
||||
if (field_mapping["properties"]) {
|
||||
// derived object type
|
||||
var nested_fields = getFieldNamesFromTypeMapping(field_mapping);
|
||||
return applyPathSettings(nested_fields);
|
||||
}
|
||||
|
||||
if (field_mapping['type'] == 'multi_field') {
|
||||
var nested_fields = $.map(field_mapping['fields'], function (field_mapping, field_name) {
|
||||
return getFieldNamesFromFieldMapping(field_name, field_mapping);
|
||||
});
|
||||
|
||||
return applyPathSettings(nested_fields);
|
||||
}
|
||||
|
||||
if (field_mapping["index_name"]) return [field_mapping["index_name"]];
|
||||
|
||||
return [field_name];
|
||||
}
|
||||
|
||||
function getFieldNamesFromTypeMapping(type_mapping) {
|
||||
var field_list =
|
||||
$.map(type_mapping['properties'], function (field_mapping, field_name) {
|
||||
return getFieldNamesFromFieldMapping(field_name, field_mapping);
|
||||
});
|
||||
|
||||
// deduping
|
||||
var last = undefined;
|
||||
field_list.sort();
|
||||
return $.map(field_list, function (f) {
|
||||
var r = (f === last) ? null : f;
|
||||
last = f;
|
||||
return r;
|
||||
});
|
||||
}
|
||||
|
||||
function loadMappings(mappings) {
|
||||
per_index_types = {};
|
||||
$.each(mappings, function (index, index_mapping) {
|
||||
var normalized_index_mappings = {};
|
||||
$.each(index_mapping, function (type_name, type_mapping) {
|
||||
var field_list = getFieldNamesFromTypeMapping(type_mapping);
|
||||
normalized_index_mappings[type_name] = field_list;
|
||||
});
|
||||
per_index_types[index] = normalized_index_mappings;
|
||||
});
|
||||
}
|
||||
|
||||
function loadAliases(aliases) {
|
||||
per_alias_indexes = {}
|
||||
$.each(aliases, function (index, index_aliases) {
|
||||
$.each(index_aliases.aliases, function (alias) {
|
||||
if (alias === index) return; // alias which is identical to index means no index.
|
||||
var cur_aliases = per_alias_indexes[alias];
|
||||
if (!cur_aliases) {
|
||||
cur_aliases = [];
|
||||
per_alias_indexes[alias] = cur_aliases;
|
||||
}
|
||||
cur_aliases.push(index);
|
||||
});
|
||||
});
|
||||
|
||||
per_alias_indexes['_all'] = getIndices(false);
|
||||
}
|
||||
|
||||
function clear() {
|
||||
per_index_types = {};
|
||||
per_alias_indexes = {};
|
||||
}
|
||||
|
||||
function retrieveMappingFromServer() {
|
||||
if (!currentServer) return;
|
||||
callES(currentServer, "_mapping", "GET", null, function (data, status, xhr) {
|
||||
loadMappings(data);
|
||||
});
|
||||
callES(currentServer, "_aliases", "GET", null, function (data, status, xhr) {
|
||||
loadAliases(data);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function notifyServerChange(newServer) {
|
||||
if (newServer.indexOf("://") < 0) newServer = "http://" + newServer;
|
||||
newServer = newServer.trim("/");
|
||||
if (newServer === currentServer) return; // already have it.
|
||||
currentServer = newServer;
|
||||
retrieveMappingFromServer();
|
||||
}
|
||||
|
||||
function mapping_retriever() {
|
||||
retrieveMappingFromServer();
|
||||
setTimeout(function () {
|
||||
mapping_retriever();
|
||||
}, 60000);
|
||||
}
|
||||
|
||||
mapping_retriever();
|
||||
|
||||
if (!global.sense) global.sense = {};
|
||||
global.sense.mappings = {};
|
||||
global.sense.mappings.getFields = getFields;
|
||||
global.sense.mappings.getIndices = getIndices;
|
||||
global.sense.mappings.getTypes = getTypes;
|
||||
global.sense.mappings.loadMappings = loadMappings;
|
||||
global.sense.mappings.loadAliases = loadAliases;
|
||||
global.sense.mappings.expandAliases = expandAliases;
|
||||
global.sense.mappings.clear = clear;
|
||||
global.sense.mappings.notifyServerChange = notifyServerChange;
|
||||
|
||||
})();
|
|
@ -1,91 +0,0 @@
|
|||
(function () {
|
||||
var global = window;
|
||||
if (!global.sense)
|
||||
global.sense = {};
|
||||
|
||||
function getFontSize() {
|
||||
return localStorage.getItem("font_size") || "12";
|
||||
}
|
||||
|
||||
function setFontSize(size) {
|
||||
if (!/^([1-9]\d*)$/.test(size)) return false;
|
||||
localStorage.setItem("font_size", size);
|
||||
$("#editor").css("font-size", size + "px");
|
||||
$("#output").css("font-size", size + "px");
|
||||
return true;
|
||||
}
|
||||
|
||||
function getWrapMode() {
|
||||
var mode = localStorage.getItem("wrap_mode") || "true";
|
||||
return mode == "true";
|
||||
}
|
||||
|
||||
function setWrapMode(mode) {
|
||||
if (typeof mode !== "boolean") return false;
|
||||
localStorage.setItem("wrap_mode", mode);
|
||||
|
||||
sense.editor.getSession().setUseWrapMode(mode);
|
||||
sense.output.getSession().setUseWrapMode(mode);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function getTheme() {
|
||||
var mode = localStorage.getItem("theme") || "dark";
|
||||
return mode;
|
||||
}
|
||||
|
||||
function setTheme(mode) {
|
||||
localStorage.setItem("theme", mode);
|
||||
|
||||
$("#bootstrapThemeCss").attr("href", "lib/bootstrap/css/bootstrap." + mode + ".min.css");
|
||||
$("#senseThemeCss").attr("href", "css/sense." + mode + ".css");
|
||||
|
||||
var aceTheme = mode === "light" ? "" : "ace/theme/sense-dark";
|
||||
sense.editor.setTheme(aceTheme);
|
||||
sense.output.setTheme(aceTheme);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
var settings_popup = $("#settings_popup");
|
||||
|
||||
var font_size_ctl = settings_popup.find("#font_size");
|
||||
var fs = getFontSize();
|
||||
font_size_ctl.val(fs);
|
||||
setFontSize(fs);
|
||||
|
||||
var wrap_mode_ctl = settings_popup.find("#wrap_mode");
|
||||
var wm = getWrapMode();
|
||||
wrap_mode_ctl.prop('checked', wm);
|
||||
setWrapMode(wm);
|
||||
|
||||
var theme_ctl = settings_popup.find("#theme");
|
||||
var theme = getTheme();
|
||||
theme_ctl.val(theme);
|
||||
setTheme(theme);
|
||||
|
||||
function save() {
|
||||
if (!setFontSize(font_size_ctl.val())) font_size_ctl.val(getFontSize());
|
||||
if (!setWrapMode(wrap_mode_ctl.prop("checked"))) wrap_mode_ctl.prop('checked', getWrapMode());
|
||||
if (!setTheme(theme_ctl.val())) theme_ctl.val(getTheme());
|
||||
global.sense.editor.focus();
|
||||
return true;
|
||||
}
|
||||
|
||||
var save_button = settings_popup.find(".btn-primary");
|
||||
save_button.click(save);
|
||||
settings_popup.find(".btn-primary").click(save);
|
||||
settings_popup.find("form").submit(function () {
|
||||
save_button.click();
|
||||
return false
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
global.sense.settings = {};
|
||||
global.sense.settings.init = init;
|
||||
})();
|
|
@ -1,278 +0,0 @@
|
|||
(function () {
|
||||
|
||||
var global = window;
|
||||
if (!global.sense)
|
||||
global.sense = {};
|
||||
|
||||
var ns = {};
|
||||
global.sense.utils = ns;
|
||||
|
||||
var sense = global.sense;
|
||||
|
||||
ROW_PARSE_MODE = {
|
||||
REQUEST_START: 2,
|
||||
IN_REQUEST: 4,
|
||||
MULTI_DOC_CUR_DOC_END: 8,
|
||||
REQUEST_END: 16,
|
||||
BETWEEN_REQUESTS: 32
|
||||
};
|
||||
|
||||
getRowParseMode = function (row, editor) {
|
||||
editor = editor || sense.editor;
|
||||
if (row == null || typeof row == "undefined") row = editor.getCursorPosition().row;
|
||||
|
||||
var session = editor.getSession();
|
||||
if (row >= session.getLength()) return ROW_PARSE_MODE.BETWEEN_REQUESTS;
|
||||
var mode = (session.getState(row) || {}).name;
|
||||
if (!mode)
|
||||
return ROW_PARSE_MODE.BETWEEN_REQUESTS; // shouldn't really happen
|
||||
|
||||
|
||||
if (mode != "start") return ROW_PARSE_MODE.IN_REQUEST;
|
||||
var line = (session.getLine(row) || "").trim();
|
||||
if (!line || line[0] === '#') return ROW_PARSE_MODE.BETWEEN_REQUESTS; // empty line or a comment waiting for a new req to start
|
||||
|
||||
if (line.indexOf("}", line.length - 1) >= 0) {
|
||||
// check for a multi doc request (must start a new json doc immediately after this one end.
|
||||
row++;
|
||||
if (row < session.getLength()) {
|
||||
line = (session.getLine(row) || "").trim();
|
||||
if (line.indexOf("{") == 0) { // next line is another doc in a multi doc
|
||||
return ROW_PARSE_MODE.MULTI_DOC_CUR_DOC_END | ROW_PARSE_MODE.IN_REQUEST;
|
||||
}
|
||||
|
||||
}
|
||||
return ROW_PARSE_MODE.REQUEST_END | ROW_PARSE_MODE.MULTI_DOC_CUR_DOC_END; // end of request
|
||||
}
|
||||
|
||||
// check for single line requests
|
||||
row++;
|
||||
if (row >= session.getLength()) {
|
||||
return ROW_PARSE_MODE.REQUEST_START | ROW_PARSE_MODE.REQUEST_END;
|
||||
}
|
||||
line = (session.getLine(row) || "").trim();
|
||||
if (line.indexOf("{") != 0) { // next line is another request
|
||||
return ROW_PARSE_MODE.REQUEST_START | ROW_PARSE_MODE.REQUEST_END;
|
||||
}
|
||||
|
||||
return ROW_PARSE_MODE.REQUEST_START;
|
||||
};
|
||||
|
||||
function rowPredicate(row, editor, value) {
|
||||
var mode = getRowParseMode(row, editor);
|
||||
return (mode & value) > 0;
|
||||
}
|
||||
|
||||
ns.isEndRequestRow = function (row, editor) {
|
||||
return rowPredicate(row, editor, ROW_PARSE_MODE.REQUEST_END);
|
||||
};
|
||||
|
||||
ns.isRequestEdge = function (row, editor) {
|
||||
return rowPredicate(row, editor, ROW_PARSE_MODE.REQUEST_END | ROW_PARSE_MODE.REQUEST_START);
|
||||
};
|
||||
|
||||
|
||||
ns.isStartRequestRow = function (row, editor) {
|
||||
return rowPredicate(row, editor, ROW_PARSE_MODE.REQUEST_START);
|
||||
};
|
||||
|
||||
ns.isInBetweenRequestsRow = function (row, editor) {
|
||||
return rowPredicate(row, editor, ROW_PARSE_MODE.BETWEEN_REQUESTS);
|
||||
};
|
||||
|
||||
ns.isInRequestsRow = function (row, editor) {
|
||||
return rowPredicate(row, editor, ROW_PARSE_MODE.IN_REQUEST);
|
||||
};
|
||||
|
||||
ns.isMultiDocDocEndRow = function (row, editor) {
|
||||
return rowPredicate(row, editor, ROW_PARSE_MODE.MULTI_DOC_CUR_DOC_END);
|
||||
};
|
||||
|
||||
|
||||
ns.iterForCurrentLoc = function (editor) {
|
||||
editor = editor || sense.editor;
|
||||
var pos = editor.getCursorPosition();
|
||||
return ns.iterForPosition(pos.row, pos.column, editor);
|
||||
};
|
||||
|
||||
ns.iterForPosition = function (row, column, editor) {
|
||||
editor = editor || sense.editor;
|
||||
return new (ace.require("ace/token_iterator").TokenIterator)(editor.getSession(), row, column);
|
||||
};
|
||||
|
||||
ns.isEmptyToken = function (tokenOrTokenIter) {
|
||||
var token = tokenOrTokenIter && tokenOrTokenIter.getCurrentToken ? tokenOrTokenIter.getCurrentToken() : tokenOrTokenIter;
|
||||
return !token || token.type == "whitespace"
|
||||
};
|
||||
|
||||
ns.isUrlOrMethodToken = function (tokenOrTokenIter) {
|
||||
var t = tokenOrTokenIter.getCurrentToken ? tokenOrTokenIter.getCurrentToken() : tokenOrTokenIter;
|
||||
return t && t.type && (t.type == "method" || t.type.indexOf("url") == 0);
|
||||
};
|
||||
|
||||
|
||||
ns.nextNonEmptyToken = function (tokenIter) {
|
||||
var t = tokenIter.stepForward();
|
||||
while (t && ns.isEmptyToken(t)) t = tokenIter.stepForward();
|
||||
return t;
|
||||
};
|
||||
|
||||
ns.prevNonEmptyToken = function (tokenIter) {
|
||||
var t = tokenIter.stepBackward();
|
||||
// empty rows return null token.
|
||||
while ((t || tokenIter.getCurrentTokenRow() > 0) && ns.isEmptyToken(t)) t = tokenIter.stepBackward();
|
||||
return t;
|
||||
};
|
||||
|
||||
ns.prevRequestStart = function (pos, editor) {
|
||||
editor = editor || sense.editor;
|
||||
pos = pos || editor.getCursorPosition();
|
||||
var curRow = pos.row;
|
||||
while (curRow > 0 && !ns.isStartRequestRow(curRow, editor)) curRow--;
|
||||
|
||||
return { row: curRow, column: 0};
|
||||
};
|
||||
|
||||
ns.nextRequestEnd = function (pos, editor) {
|
||||
editor = editor || sense.editor;
|
||||
pos = pos || editor.getCursorPosition();
|
||||
var session = editor.getSession();
|
||||
var curRow = pos.row;
|
||||
var maxLines = session.getLength();
|
||||
for (; curRow < maxLines - 1; curRow++) {
|
||||
var curRowMode = getRowParseMode(curRow, editor);
|
||||
if ((curRowMode & ROW_PARSE_MODE.REQUEST_END) > 0) break;
|
||||
if (curRow != pos.row && (curRowMode & ROW_PARSE_MODE.REQUEST_START) > 0) break;
|
||||
}
|
||||
|
||||
var column = (session.getLine(curRow) || "").length;
|
||||
|
||||
return { row: curRow, column: column};
|
||||
};
|
||||
|
||||
ns.nextDataDocEnd = function (pos, editor) {
|
||||
editor = editor || sense.editor;
|
||||
pos = pos || editor.getCursorPosition();
|
||||
var session = editor.getSession();
|
||||
var curRow = pos.row;
|
||||
var maxLines = session.getLength();
|
||||
for (; curRow < maxLines - 1; curRow++) {
|
||||
var curRowMode = getRowParseMode(curRow, editor);
|
||||
if ((curRowMode & ROW_PARSE_MODE.REQUEST_END) > 0) {
|
||||
break;
|
||||
}
|
||||
if ((curRowMode & ROW_PARSE_MODE.MULTI_DOC_CUR_DOC_END) > 0) break;
|
||||
if (curRow != pos.row && (curRowMode & ROW_PARSE_MODE.REQUEST_START) > 0) break;
|
||||
}
|
||||
|
||||
var column = (session.getLine(curRow) || "").length;
|
||||
|
||||
return { row: curRow, column: column };
|
||||
};
|
||||
|
||||
|
||||
ns.getCurrentRequestRange = function (editor) {
|
||||
if (ns.isInBetweenRequestsRow(null, editor)) return null;
|
||||
|
||||
var reqStart = ns.prevRequestStart(null, editor);
|
||||
var reqEnd = ns.nextRequestEnd(reqStart, editor);
|
||||
return new (ace.require("ace/range").Range)(
|
||||
reqStart.row, reqStart.column,
|
||||
reqEnd.row, reqEnd.column
|
||||
);
|
||||
};
|
||||
|
||||
ns.getCurrentRequest = function (editor) {
|
||||
editor = editor || sense.editor;
|
||||
|
||||
if (ns.isInBetweenRequestsRow(null, editor)) return null;
|
||||
|
||||
var request = {
|
||||
method: "",
|
||||
data: [],
|
||||
url: null
|
||||
};
|
||||
|
||||
var currentReqRange = ns.getCurrentRequestRange(editor);
|
||||
|
||||
var pos = currentReqRange.start;
|
||||
var tokenIter = ns.iterForPosition(pos.row, pos.column, editor);
|
||||
var t = tokenIter.getCurrentToken();
|
||||
request.method = t.value;
|
||||
t = ns.nextNonEmptyToken(tokenIter);
|
||||
if (!t || t.type == "method") return null;
|
||||
request.url = "";
|
||||
while (t && t.type && t.type.indexOf("url") == 0) {
|
||||
request.url += t.value;
|
||||
t = tokenIter.stepForward();
|
||||
}
|
||||
|
||||
var bodyStartRow = (t ? 0 : 1) + tokenIter.getCurrentTokenRow(); // artificially increase end of docs.
|
||||
var bodyStartColumn = 0;
|
||||
while (bodyStartRow < currentReqRange.end.row ||
|
||||
(bodyStartRow == currentReqRange.end.row &&
|
||||
bodyStartColumn < currentReqRange.end.column
|
||||
)) {
|
||||
dataEndPos = ns.nextDataDocEnd({ row: bodyStartRow, column: bodyStartColumn}, editor);
|
||||
var bodyRange = new (ace.require("ace/range").Range)(
|
||||
bodyStartRow, bodyStartColumn,
|
||||
dataEndPos.row, dataEndPos.column
|
||||
);
|
||||
var data = editor.getSession().getTextRange(bodyRange);
|
||||
request.data.push(data.trim());
|
||||
bodyStartRow = dataEndPos.row + 1;
|
||||
bodyStartColumn = 0;
|
||||
}
|
||||
return request;
|
||||
};
|
||||
|
||||
ns.textFromRequest = function (request) {
|
||||
var data = request.data;
|
||||
if (typeof data != "string") {
|
||||
data = data.join("\n");
|
||||
}
|
||||
return request.method + " " + request.url + "\n" + data;
|
||||
};
|
||||
|
||||
ns.replaceCurrentRequest = function (newRequest, curRequestRange) {
|
||||
if (!curRequestRange) curRequestRange = ns.getCurrentRequestRange();
|
||||
var text = ns.textFromRequest(newRequest);
|
||||
if (curRequestRange) {
|
||||
sense.editor.getSession().replace(curRequestRange, text);
|
||||
}
|
||||
else {
|
||||
// just insert where we are
|
||||
sense.editor.insert(text);
|
||||
}
|
||||
};
|
||||
|
||||
ns.getUrlParam = function (name) {
|
||||
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
|
||||
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
||||
results = regex.exec(location.search);
|
||||
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||
};
|
||||
|
||||
ns.isTokenizationStable = function (editor) {
|
||||
editor = editor || sense.editor;
|
||||
return !editor.getSession().bgTokenizer.running;
|
||||
};
|
||||
|
||||
ns.updateEditorAndCallWhenUpdated = function (data, editor, callback) {
|
||||
editor = editor || sense.editor;
|
||||
var session = editor.getSession();
|
||||
|
||||
function mycallback() {
|
||||
session.removeListener(mycallback);
|
||||
if (session.bgTokenizer.running) {
|
||||
setTimeout(mycallback, 50); // wait
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
session.on('tokenizerUpdate', mycallback);
|
||||
session.setValue(data);
|
||||
}
|
||||
|
||||
})();
|
16
sense/tests/.jshintrc
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"extends": "../.jshintrc",
|
||||
"globals": {
|
||||
"SENSE_VERSION": true,
|
||||
"define": false,
|
||||
"require": false,
|
||||
"module": false,
|
||||
"deepEqual": false,
|
||||
"test": false,
|
||||
"ok": false,
|
||||
"asyncTest": false,
|
||||
"start": false,
|
||||
"stop": false,
|
||||
"equal": false
|
||||
}
|
||||
}
|
|
@ -1,37 +1,70 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Sense unittests</title>
|
||||
<link rel="stylesheet" href="lib/qunit-1.10.0.css">
|
||||
<style type="text/css">
|
||||
#editor {
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
bottom: 20px;
|
||||
left: 20px;
|
||||
right: 20px;
|
||||
z-index: 200;
|
||||
}
|
||||
</style>
|
||||
<meta charset="utf-8">
|
||||
<title>Sense unittests</title>
|
||||
<link rel="stylesheet" href="lib/qunit-1.10.0.css">
|
||||
<style type="text/css">
|
||||
#editor {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
bottom: 20px;
|
||||
left: 20px;
|
||||
right: 20px;
|
||||
z-index: 200;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
#output {
|
||||
display: none;
|
||||
position: absolute;
|
||||
height: 250px;
|
||||
width: 350px;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
z-index: 201;
|
||||
border: 1px solid #333;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<script src="../lib/jquery-1.8.3.min.js" type="text/javascript"></script>
|
||||
<script src="../lib/jqueryui/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
|
||||
<script src="../lib/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="../src/utils.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="../src/curl.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="../src/kb.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="../src/autocomplete.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="../src/mappings.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="lib/qunit-1.10.0.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/curl_tests.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/kb_tests.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/mapping_tests.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/utils_tests.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/autocomplete_tests.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/tokenization_tests.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="src/integration_tests.js" type="text/javascript" charset="utf-8"></script>
|
||||
<div id="editor"></div>
|
||||
<div id="output"></div>
|
||||
<script src="lib/qunit-1.10.0.js"></script>
|
||||
<script src="../vendor/require/require.js"></script>
|
||||
<script src="../app/require.config.js"></script>
|
||||
<script>
|
||||
var SENSE_VERSION = '0.9.0';
|
||||
require.config({
|
||||
baseUrl: '../app'
|
||||
});
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/* global QUnit */
|
||||
QUnit.config.autostart = false;
|
||||
|
||||
var tests = [
|
||||
'../tests/src/curl_tests.js',
|
||||
'../tests/src/kb_tests.js',
|
||||
'../tests/src/mapping_tests.js',
|
||||
'../tests/src/editor_tests.js',
|
||||
'../tests/src/tokenization_tests.js',
|
||||
'../tests/src/integration_tests.js'
|
||||
];
|
||||
|
||||
// load the tests in series
|
||||
(function next(){
|
||||
if (tests.length) {
|
||||
require(tests.splice(0, 1), next);
|
||||
} else {
|
||||
QUnit.start();
|
||||
console.log('all tests loaded');
|
||||
}
|
||||
}());
|
||||
|
||||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -1,14 +0,0 @@
|
|||
var global = window;
|
||||
|
||||
module("Autocomplete", {
|
||||
setup: function () {
|
||||
if (!global.sense)
|
||||
global.sense = {};
|
||||
var sense = global.sense;
|
||||
sense.tests = {};
|
||||
},
|
||||
|
||||
teardown: function () {
|
||||
sense.tests = {};
|
||||
}
|
||||
});
|
|
@ -1,162 +1,150 @@
|
|||
var global = window;
|
||||
define([
|
||||
'_',
|
||||
'curl'
|
||||
], function (_, curl) {
|
||||
'use strict';
|
||||
|
||||
module("CURL", {
|
||||
setup: function () {
|
||||
if (!global.sense)
|
||||
global.sense = {};
|
||||
var sense = global.sense;
|
||||
sense.tests = {};
|
||||
},
|
||||
module("CURL");
|
||||
|
||||
teardown: function () {
|
||||
sense.tests = {};
|
||||
}
|
||||
});
|
||||
var notCURLS = [
|
||||
'sldhfsljfhs',
|
||||
's;kdjfsldkfj curl -XDELETE ""',
|
||||
'{ "hello": 1 }'
|
||||
];
|
||||
|
||||
var notCURLS = [
|
||||
'sldhfsljfhs',
|
||||
's;kdjfsldkfj curl -XDELETE ""',
|
||||
'{ "hello": 1 }'
|
||||
];
|
||||
|
||||
var CURLS = [
|
||||
{
|
||||
var CURLS = [
|
||||
{
|
||||
"curl": "curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{ \
|
||||
\"user\" : \"kimchy\", \
|
||||
\"post_date\" : \"2009-11-15T14:12:12\",\
|
||||
\"message\" : \"trying out Elastic Search\"\
|
||||
}'",
|
||||
\"user\" : \"kimchy\", \
|
||||
\"post_date\" : \"2009-11-15T14:12:12\",\
|
||||
\"message\" : \"trying out Elastic Search\"\
|
||||
}'",
|
||||
"ret": {
|
||||
"server": "http://localhost:9200",
|
||||
"method": "PUT",
|
||||
"url": "/twitter/tweet/1",
|
||||
"data": "{ \
|
||||
\"user\" : \"kimchy\", \
|
||||
\"post_date\" : \"2009-11-15T14:12:12\",\
|
||||
\"message\" : \"trying out Elastic Search\"\
|
||||
}"
|
||||
"server": "http://localhost:9200",
|
||||
"method": "PUT",
|
||||
"url": "/twitter/tweet/1",
|
||||
"data": "{ \
|
||||
\"user\" : \"kimchy\", \
|
||||
\"post_date\" : \"2009-11-15T14:12:12\",\
|
||||
\"message\" : \"trying out Elastic Search\"\
|
||||
}"
|
||||
}
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
"curl": "curl -XGET \"localhost/twitter/tweet/1?version=2\" -d '{ \
|
||||
\"message\" : \"elasticsearch now has versioning support, double cool!\"\
|
||||
}'",
|
||||
\"message\" : \"elasticsearch now has versioning support, double cool!\"\
|
||||
}'",
|
||||
"ret": {
|
||||
"server": "http://localhost",
|
||||
"method": "GET",
|
||||
"url": "/twitter/tweet/1?version=2",
|
||||
"data": "{ \
|
||||
\"message\" : \"elasticsearch now has versioning support, double cool!\"\
|
||||
}"
|
||||
"server": "http://localhost",
|
||||
"method": "GET",
|
||||
"url": "/twitter/tweet/1?version=2",
|
||||
"data": "{ \
|
||||
\"message\" : \"elasticsearch now has versioning support, double cool!\"\
|
||||
}"
|
||||
}
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
"curl": "curl -XPOST https://localhost/twitter/tweet/1?version=2 -d '{ \n\
|
||||
\"message\" : \"elasticsearch now has versioning support, double cool!\"\n\
|
||||
}'",
|
||||
\"message\" : \"elasticsearch now has versioning support, double cool!\"\n\
|
||||
}'",
|
||||
"ret": {
|
||||
"server": "https://localhost",
|
||||
"method": "POST",
|
||||
"url": "/twitter/tweet/1?version=2",
|
||||
"data": "{ \n\
|
||||
\"message\" : \"elasticsearch now has versioning support, double cool!\"\n\
|
||||
}"
|
||||
"server": "https://localhost",
|
||||
"method": "POST",
|
||||
"url": "/twitter/tweet/1?version=2",
|
||||
"data": "{ \n\
|
||||
\"message\" : \"elasticsearch now has versioning support, double cool!\"\n\
|
||||
}"
|
||||
}
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
"curl": "curl -XPOST https://localhost/twitter",
|
||||
"ret": {
|
||||
"server": "https://localhost",
|
||||
"method": "POST",
|
||||
"url": "/twitter",
|
||||
"data": ""
|
||||
"server": "https://localhost",
|
||||
"method": "POST",
|
||||
"url": "/twitter",
|
||||
"data": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
"curl": "curl -X POST https://localhost/twitter/",
|
||||
"ret": {
|
||||
"server": "https://localhost",
|
||||
"method": "POST",
|
||||
"url": "/twitter/",
|
||||
"data": ""
|
||||
"server": "https://localhost",
|
||||
"method": "POST",
|
||||
"url": "/twitter/",
|
||||
"data": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
"curl": "curl -s -XPOST localhost:9200/missing-test -d'\n\
|
||||
{ \n\
|
||||
{ \n\
|
||||
\"mappings\": {\n\
|
||||
}\n\
|
||||
}'",
|
||||
}'",
|
||||
"ret": {
|
||||
"server": "http://localhost:9200",
|
||||
"method": "POST",
|
||||
"url": "/missing-test",
|
||||
"data": "{ \n\
|
||||
"server": "http://localhost:9200",
|
||||
"method": "POST",
|
||||
"url": "/missing-test",
|
||||
"data": "{ \n\
|
||||
\"mappings\": {\n\
|
||||
}\n\
|
||||
}"
|
||||
}"
|
||||
}
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
"curl": "curl 'localhost:9200/missing-test/doc/_search?pretty' -d'\n\
|
||||
{\n\
|
||||
{\n\
|
||||
\"query\": {\n\
|
||||
},\n\
|
||||
}'",
|
||||
}'",
|
||||
"ret": {
|
||||
"server": "http://localhost:9200",
|
||||
"method": "",
|
||||
"url": "/missing-test/doc/_search?pretty",
|
||||
"data": "{\n\
|
||||
"server": "http://localhost:9200",
|
||||
"method": "",
|
||||
"url": "/missing-test/doc/_search?pretty",
|
||||
"data": "{\n\
|
||||
\"query\": {\n\
|
||||
},\n\
|
||||
}"
|
||||
}"
|
||||
}
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
"curl": 'curl localhost:9200/ -d"\n\
|
||||
{\n\
|
||||
{\n\
|
||||
\\"query\\": {\n\
|
||||
},\n\
|
||||
}"',
|
||||
}"',
|
||||
"ret": {
|
||||
"server": "http://localhost:9200",
|
||||
"method": "",
|
||||
"url": "/",
|
||||
"data": "{\n\
|
||||
"server": "http://localhost:9200",
|
||||
"method": "",
|
||||
"url": "/",
|
||||
"data": "{\n\
|
||||
\"query\": {\n\
|
||||
},\n\
|
||||
}"
|
||||
}"
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
function compareCURL(result, expected) {
|
||||
deepEqual(result.server, expected.server);
|
||||
deepEqual(result.method, expected.method);
|
||||
deepEqual(result.url, expected.url);
|
||||
deepEqual(result.data, expected.data);
|
||||
}
|
||||
|
||||
for (var i = 0; i < notCURLS.length; i++)
|
||||
|
||||
test("cURL Detection - broken strings " + i, function (c) {
|
||||
return function () {
|
||||
ok(!global.sense.curl.detectCURL(notCURLS[c]), "marked as curl while it wasn't:" + notCURLS[c]);
|
||||
}
|
||||
}(i)
|
||||
);
|
||||
|
||||
for (var i = 0; i < CURLS.length; i++)
|
||||
function compareCURL(result, expected) {
|
||||
deepEqual(result.server, expected.server);
|
||||
deepEqual(result.method, expected.method);
|
||||
deepEqual(result.url, expected.url);
|
||||
deepEqual(result.data, expected.data);
|
||||
}
|
||||
|
||||
|
||||
test("cURL Detection - correct strings " + i, function (c) {
|
||||
return function () {
|
||||
ok(global.sense.curl.detectCURL(CURLS[c].curl), "marked as not curl while it was:" + CURLS[c].curl);
|
||||
var r = global.sense.curl.parseCURL(CURLS[c].curl);
|
||||
compareCURL(r, CURLS[c].ret);
|
||||
}
|
||||
}(i)
|
||||
);
|
||||
_.each(notCURLS, function (notCURL, i) {
|
||||
test("cURL Detection - broken strings " + i, function () {
|
||||
ok(!curl.detectCURL(notCURL), "marked as curl while it wasn't:" + notCURL);
|
||||
});
|
||||
});
|
||||
|
||||
_.each(CURLS, function (fixture, i) {
|
||||
test("cURL Detection - correct strings " + i, function () {
|
||||
ok(curl.detectCURL(fixture.curl), "marked as not curl while it was:" + fixture.curl);
|
||||
var r = curl.parseCURL(fixture.curl);
|
||||
compareCURL(r, fixture.ret);
|
||||
});
|
||||
})
|
||||
|
||||
});
|
183
sense/tests/src/editor_tests.js
Normal file
|
@ -0,0 +1,183 @@
|
|||
define([
|
||||
'ace',
|
||||
'input',
|
||||
'jquery'
|
||||
], function (ace, input, $) {
|
||||
'use strict';
|
||||
|
||||
module("Editor", {
|
||||
setup: function () {
|
||||
input.$el.show();
|
||||
},
|
||||
teardown: function () {
|
||||
input.$el.hide();
|
||||
}
|
||||
});
|
||||
|
||||
var testCount = 0;
|
||||
|
||||
function utils_test(name, prefix, data, test) {
|
||||
var id = testCount++;
|
||||
if (data && typeof data != "string") data = JSON.stringify(data, null, 3);
|
||||
if (data) {
|
||||
if (prefix) data = prefix + "\n" + data;
|
||||
} else {
|
||||
data = prefix;
|
||||
}
|
||||
|
||||
asyncTest("Utils test " + id + " : " + name, function () {
|
||||
input.update(data, function () {
|
||||
test();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var simple_request = {
|
||||
prefix: 'POST _search',
|
||||
data: [
|
||||
'{',
|
||||
' "query": { "match_all": {} }',
|
||||
'}'
|
||||
].join('\n')
|
||||
};
|
||||
|
||||
var single_line_request =
|
||||
{ prefix: 'POST _search',
|
||||
data: '{ "query": { "match_all": {} } }'
|
||||
};
|
||||
|
||||
var get_request_no_data = {
|
||||
prefix: 'GET _stats'
|
||||
};
|
||||
|
||||
var multi_doc_request = {
|
||||
prefix: 'POST _bulk',
|
||||
data_as_array: [
|
||||
'{ "index": { "_index": "index", "_type":"type" } }',
|
||||
'{ "field": 1 }'
|
||||
]
|
||||
};
|
||||
multi_doc_request.data = multi_doc_request.data_as_array.join("\n");
|
||||
|
||||
|
||||
utils_test("simple request range", simple_request.prefix, simple_request.data, function () {
|
||||
input.getCurrentRequestRange(function (range) {
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
3, 1
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
utils_test("simple request data", simple_request.prefix, simple_request.data, function () {
|
||||
input.getCurrentRequest(function (request) {
|
||||
var expected = {
|
||||
method: "POST",
|
||||
url: "_search",
|
||||
data: [simple_request.data]
|
||||
};
|
||||
|
||||
deepEqual(request, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
utils_test("single line request range", single_line_request.prefix, single_line_request.data, function () {
|
||||
input.getCurrentRequestRange(function (range) {
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
1, 32
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
utils_test("single line request data", single_line_request.prefix, single_line_request.data, function () {
|
||||
input.getCurrentRequest(function (request) {
|
||||
var expected = {
|
||||
method: "POST",
|
||||
url: "_search",
|
||||
data: [single_line_request.data]
|
||||
};
|
||||
|
||||
deepEqual(request, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
utils_test("request with no data followed by a new line", get_request_no_data.prefix, "\n", function () {
|
||||
input.getCurrentRequestRange(function (range) {
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
0, 10
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
utils_test("request with no data followed by a new line (data)", get_request_no_data.prefix, "\n", function () {
|
||||
input.getCurrentRequest(function (request) {
|
||||
var expected = {
|
||||
method: "GET",
|
||||
url: "_stats",
|
||||
data: []
|
||||
};
|
||||
|
||||
deepEqual(request, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
utils_test("request with no data", get_request_no_data.prefix, get_request_no_data.data, function () {
|
||||
input.getCurrentRequestRange(function (range) {
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
0, 10
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
utils_test("request with no data (data)", get_request_no_data.prefix, get_request_no_data.data, function () {
|
||||
input.getCurrentRequest(function (range) {
|
||||
var expected = {
|
||||
method: "GET",
|
||||
url: "_stats",
|
||||
data: []
|
||||
};
|
||||
|
||||
deepEqual(range, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
utils_test("multi doc request range", multi_doc_request.prefix, multi_doc_request.data, function () {
|
||||
input.getCurrentRequestRange(function (range) {
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
2, 14
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
utils_test("multi doc request data", multi_doc_request.prefix, multi_doc_request.data, function () {
|
||||
input.getCurrentRequest(function (request) {
|
||||
var expected = {
|
||||
method: "POST",
|
||||
url: "_bulk",
|
||||
data: multi_doc_request.data_as_array
|
||||
};
|
||||
|
||||
deepEqual(request, expected);
|
||||
start();
|
||||
});
|
||||
});
|
||||
})
|
|
@ -1,103 +1,102 @@
|
|||
var global = window;
|
||||
define([
|
||||
'kb/index',
|
||||
'mappings'
|
||||
], function (kb, mappings) {
|
||||
'use strict';
|
||||
|
||||
module("Knowledge base", {
|
||||
setup: function () {
|
||||
var sense = global.sense;
|
||||
sense.mappings.clear();
|
||||
sense.tests = {};
|
||||
},
|
||||
|
||||
teardown: function () {
|
||||
sense.tests = {};
|
||||
}
|
||||
});
|
||||
module("Knowledge base", {
|
||||
setup: function () {
|
||||
mappings.clear();
|
||||
kb.clear();
|
||||
},
|
||||
teardown: function () {
|
||||
mappings.clear();
|
||||
kb.clear();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
test("Index mode filters", function () {
|
||||
global.sense.mappings.clear();
|
||||
global.sense.kb.clear();
|
||||
global.sense.kb.addEndpointDescription("_multi_indices", {
|
||||
test("Index mode filters", function () {
|
||||
kb.addEndpointDescription("_multi_indices", {
|
||||
indices_mode: "multi"
|
||||
});
|
||||
global.sense.kb.addEndpointDescription("_one_or_more_indices", {
|
||||
});
|
||||
kb.addEndpointDescription("_one_or_more_indices", {
|
||||
indices_mode: "required_multi"
|
||||
});
|
||||
global.sense.kb.addEndpointDescription("_single_index", {
|
||||
});
|
||||
kb.addEndpointDescription("_single_index", {
|
||||
match: "_single_index",
|
||||
endpoint_autocomplete: [
|
||||
"_single_index"
|
||||
"_single_index"
|
||||
],
|
||||
indices_mode: "single"
|
||||
});
|
||||
global.sense.kb.addEndpointDescription("_no_index", {
|
||||
});
|
||||
kb.addEndpointDescription("_no_index", {
|
||||
indices_mode: "none"
|
||||
});
|
||||
});
|
||||
|
||||
deepEqual(global.sense.kb.getEndpointAutocomplete([], [], null).sort(), ["_multi_indices", "_no_index" ]);
|
||||
deepEqual(global.sense.kb.getEndpointAutocomplete(["index"], [], null).sort(), ["_multi_indices", "_one_or_more_indices", "_single_index"]);
|
||||
deepEqual(global.sense.kb.getEndpointAutocomplete(["index1", "index2"], [], null).sort(), ["_multi_indices", "_one_or_more_indices"]);
|
||||
deepEqual(global.sense.kb.getEndpointAutocomplete(["index1", "index2"], ["type"], null).sort(), ["_multi_indices", "_one_or_more_indices"]);
|
||||
});
|
||||
deepEqual(kb.getEndpointAutocomplete([], [], null).sort(), ["_multi_indices", "_no_index" ]);
|
||||
deepEqual(kb.getEndpointAutocomplete(["index"], [], null).sort(), ["_multi_indices", "_one_or_more_indices", "_single_index"]);
|
||||
deepEqual(kb.getEndpointAutocomplete(["index1", "index2"], [], null).sort(), ["_multi_indices", "_one_or_more_indices"]);
|
||||
deepEqual(kb.getEndpointAutocomplete(["index1", "index2"], ["type"], null).sort(), ["_multi_indices", "_one_or_more_indices"]);
|
||||
});
|
||||
|
||||
test("Type mode filters", function () {
|
||||
global.sense.mappings.clear();
|
||||
global.sense.kb.clear();
|
||||
global.sense.kb.addEndpointDescription("_multi_types", {
|
||||
test("Type mode filters", function () {
|
||||
kb.addEndpointDescription("_multi_types", {
|
||||
indices_mode: "single",
|
||||
types_mode: "multi"
|
||||
});
|
||||
global.sense.kb.addEndpointDescription("_single_type", {
|
||||
});
|
||||
kb.addEndpointDescription("_single_type", {
|
||||
endpoint_autocomplete: [
|
||||
"_single_type"
|
||||
"_single_type"
|
||||
],
|
||||
indices_mode: "single",
|
||||
types_mode: "single"
|
||||
});
|
||||
global.sense.kb.addEndpointDescription("_no_types", {
|
||||
});
|
||||
kb.addEndpointDescription("_no_types", {
|
||||
indices_mode: "single",
|
||||
types_mode: "none"
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
deepEqual(global.sense.kb.getEndpointAutocomplete(["index"], [], null).sort(), ["_multi_types", "_no_types" ]);
|
||||
deepEqual(global.sense.kb.getEndpointAutocomplete(["index"], ["type"], null).sort(), ["_multi_types", "_single_type"]);
|
||||
deepEqual(global.sense.kb.getEndpointAutocomplete(["index"], ["type", "type1"], null).sort(), ["_multi_types"]);
|
||||
});
|
||||
deepEqual(kb.getEndpointAutocomplete(["index"], [], null).sort(), ["_multi_types", "_no_types" ]);
|
||||
deepEqual(kb.getEndpointAutocomplete(["index"], ["type"], null).sort(), ["_multi_types", "_single_type"]);
|
||||
deepEqual(kb.getEndpointAutocomplete(["index"], ["type", "type1"], null).sort(), ["_multi_types"]);
|
||||
});
|
||||
|
||||
test("Id mode filters", function () {
|
||||
global.sense.kb.clear();
|
||||
global.sense.kb.addEndpointDescription("_single_id", {
|
||||
test("Id mode filters", function () {
|
||||
kb.addEndpointDescription("_single_id", {
|
||||
indices_mode: "single",
|
||||
types_mode: "single",
|
||||
doc_id_mode: "required_single"
|
||||
});
|
||||
global.sense.kb.addEndpointDescription("_no_id", {
|
||||
});
|
||||
kb.addEndpointDescription("_no_id", {
|
||||
indices_mode: "single",
|
||||
types_mode: "single",
|
||||
doc_id_mode: "none"
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
deepEqual(global.sense.kb.getEndpointAutocomplete(["index"], ["type"], null).sort(), ["_no_id"].sort());
|
||||
deepEqual(global.sense.kb.getEndpointAutocomplete(["index"], ["type"], "123").sort(), ["_single_id"].sort());
|
||||
});
|
||||
deepEqual(kb.getEndpointAutocomplete(["index"], ["type"], null).sort(), ["_no_id"].sort());
|
||||
deepEqual(kb.getEndpointAutocomplete(["index"], ["type"], "123").sort(), ["_single_id"].sort());
|
||||
});
|
||||
|
||||
test("Get active scheme by doc id", function () {
|
||||
global.sense.kb.clear();
|
||||
global.sense.kb.addEndpointDescription("_single_id", {
|
||||
test("Get active scheme by doc id", function () {
|
||||
kb.addEndpointDescription("_single_id", {
|
||||
match: ".*",
|
||||
indices_mode: "single",
|
||||
types_mode: "single",
|
||||
doc_id_mode: "required_single"
|
||||
});
|
||||
global.sense.kb.addEndpointDescription("_no_id", {
|
||||
});
|
||||
kb.addEndpointDescription("_no_id", {
|
||||
match: ".*",
|
||||
indices_mode: "single",
|
||||
types_mode: "single",
|
||||
doc_id_mode: "none"
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
deepEqual(global.sense.kb.getEndpointDescriptionByPath("bla", ["index"], ["type"], null).doc_id_mode, "none");
|
||||
deepEqual(global.sense.kb.getEndpointDescriptionByPath("bla", ["index"], ["type"], "123").doc_id_mode, "required_single");
|
||||
});
|
||||
deepEqual(kb.getEndpointDescriptionByPath("bla", ["index"], ["type"], null).doc_id_mode, "none");
|
||||
deepEqual(kb.getEndpointDescriptionByPath("bla", ["index"], ["type"], "123").doc_id_mode, "required_single");
|
||||
});
|
||||
|
||||
});
|
|
@ -1,209 +1,202 @@
|
|||
var global = window;
|
||||
define([
|
||||
'mappings'
|
||||
], function (mappings) {
|
||||
'use strict';
|
||||
|
||||
module("Mappings", {
|
||||
setup: function () {
|
||||
if (!global.sense)
|
||||
global.sense = {};
|
||||
var sense = global.sense;
|
||||
sense.tests = {};
|
||||
},
|
||||
|
||||
teardown: function () {
|
||||
sense.tests = {};
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
test("Multi fields", function () {
|
||||
global.sense.mappings.loadMappings({
|
||||
"index": {
|
||||
"tweet": {
|
||||
"properties": {
|
||||
"first_name": {
|
||||
"type": "multi_field",
|
||||
"path": "just_name",
|
||||
"fields": {
|
||||
"first_name": {"type": "string", "index": "analyzed"},
|
||||
"any_name": {"type": "string", "index": "analyzed"}
|
||||
}
|
||||
},
|
||||
"last_name": {
|
||||
"type": "multi_field",
|
||||
"path": "just_name",
|
||||
"fields": {
|
||||
"last_name": {"type": "string", "index": "analyzed"},
|
||||
"any_name": {"type": "string", "index": "analyzed"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
});
|
||||
|
||||
deepEqual(global.sense.mappings.getFields("index").sort(), ["any_name", "first_name", "last_name" ]);
|
||||
});
|
||||
|
||||
test("Simple fields", function () {
|
||||
global.sense.mappings.loadMappings({
|
||||
"index": {
|
||||
"tweet": {
|
||||
"properties": {
|
||||
"str": {
|
||||
"type": "string"
|
||||
},
|
||||
"number": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
}}
|
||||
});
|
||||
|
||||
deepEqual(global.sense.mappings.getFields("index").sort(), ["number", "str" ]);
|
||||
});
|
||||
|
||||
|
||||
test("Nested fields", function () {
|
||||
global.sense.mappings.loadMappings({
|
||||
"index": {
|
||||
"tweet": {
|
||||
"properties": {
|
||||
"person": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"properties": {
|
||||
"first_name": {"type": "string"},
|
||||
"last_name": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"sid": {"type": "string", "index": "not_analyzed"}
|
||||
}
|
||||
},
|
||||
"message": {"type": "string"}
|
||||
}
|
||||
}
|
||||
}});
|
||||
|
||||
deepEqual(global.sense.mappings.getFields("index", ["tweet"]).sort(),
|
||||
["message", "person.name.first_name", "person.name.last_name", "person.sid" ]);
|
||||
});
|
||||
|
||||
test("Enabled fields", function () {
|
||||
global.sense.mappings.loadMappings({
|
||||
"index": {
|
||||
"tweet": {
|
||||
"properties": {
|
||||
"person": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "object",
|
||||
"enabled": false
|
||||
},
|
||||
"sid": {"type": "string", "index": "not_analyzed"}
|
||||
}
|
||||
},
|
||||
"message": {"type": "string"}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(global.sense.mappings.getFields("index", ["tweet"]).sort(),
|
||||
["message", "person.sid" ]);
|
||||
});
|
||||
|
||||
|
||||
test("Path tests", function () {
|
||||
global.sense.mappings.loadMappings({
|
||||
"index": {
|
||||
"person": {
|
||||
"properties": {
|
||||
"name1": {
|
||||
"type": "object",
|
||||
"path": "just_name",
|
||||
"properties": {
|
||||
"first1": {"type": "string"},
|
||||
"last1": {"type": "string", "index_name": "i_last_1"}
|
||||
}
|
||||
},
|
||||
"name2": {
|
||||
"type": "object",
|
||||
"path": "full",
|
||||
"properties": {
|
||||
"first2": {"type": "string"},
|
||||
"last2": {"type": "string", "index_name": "i_last_2"}
|
||||
test("Multi fields", function () {
|
||||
mappings.loadMappings({
|
||||
"index": {
|
||||
"tweet": {
|
||||
"properties": {
|
||||
"first_name": {
|
||||
"type": "multi_field",
|
||||
"path": "just_name",
|
||||
"fields": {
|
||||
"first_name": {"type": "string", "index": "analyzed"},
|
||||
"any_name": {"type": "string", "index": "analyzed"}
|
||||
}
|
||||
},
|
||||
"last_name": {
|
||||
"type": "multi_field",
|
||||
"path": "just_name",
|
||||
"fields": {
|
||||
"last_name": {"type": "string", "index": "analyzed"},
|
||||
"any_name": {"type": "string", "index": "analyzed"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields("index").sort(), ["any_name", "first_name", "last_name" ]);
|
||||
});
|
||||
|
||||
deepEqual(global.sense.mappings.getFields().sort(),
|
||||
["first1", "i_last_1", "name2.first2", "name2.i_last_2" ]);
|
||||
});
|
||||
|
||||
test("Use index_name tests", function () {
|
||||
global.sense.mappings.loadMappings({
|
||||
"index": {
|
||||
"person": {
|
||||
"properties": {
|
||||
"last1": {"type": "string", "index_name": "i_last_1"}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(global.sense.mappings.getFields().sort(),
|
||||
[ "i_last_1" ]);
|
||||
});
|
||||
|
||||
test("Aliases", function () {
|
||||
global.sense.mappings.loadAliases({
|
||||
"test_index1": {
|
||||
"aliases": {
|
||||
"alias1": {}
|
||||
}
|
||||
},
|
||||
"test_index2": {
|
||||
"aliases": {
|
||||
"alias2": {
|
||||
"filter": {
|
||||
"term": {
|
||||
"FIELD": "VALUE"
|
||||
test("Simple fields", function () {
|
||||
mappings.loadMappings({
|
||||
"index": {
|
||||
"tweet": {
|
||||
"properties": {
|
||||
"str": {
|
||||
"type": "string"
|
||||
},
|
||||
"number": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"alias1": {}
|
||||
}
|
||||
}
|
||||
});
|
||||
global.sense.mappings.loadMappings({
|
||||
"test_index1": {
|
||||
"type1": {
|
||||
"properties": {
|
||||
"last1": {"type": "string", "index_name": "i_last_1"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"test_index2": {
|
||||
"type2": {
|
||||
"properties": {
|
||||
"last1": {"type": "string", "index_name": "i_last_1"}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields("index").sort(), ["number", "str" ]);
|
||||
});
|
||||
|
||||
|
||||
test("Nested fields", function () {
|
||||
mappings.loadMappings({
|
||||
"index": {
|
||||
"tweet": {
|
||||
"properties": {
|
||||
"person": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"properties": {
|
||||
"first_name": {"type": "string"},
|
||||
"last_name": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"sid": {"type": "string", "index": "not_analyzed"}
|
||||
}
|
||||
},
|
||||
"message": {"type": "string"}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields("index", ["tweet"]).sort(),
|
||||
["message", "person.name.first_name", "person.name.last_name", "person.sid" ]);
|
||||
});
|
||||
|
||||
test("Enabled fields", function () {
|
||||
mappings.loadMappings({
|
||||
"index": {
|
||||
"tweet": {
|
||||
"properties": {
|
||||
"person": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "object",
|
||||
"enabled": false
|
||||
},
|
||||
"sid": {"type": "string", "index": "not_analyzed"}
|
||||
}
|
||||
},
|
||||
"message": {"type": "string"}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields("index", ["tweet"]).sort(),
|
||||
["message", "person.sid" ]);
|
||||
});
|
||||
|
||||
|
||||
test("Path tests", function () {
|
||||
mappings.loadMappings({
|
||||
"index": {
|
||||
"person": {
|
||||
"properties": {
|
||||
"name1": {
|
||||
"type": "object",
|
||||
"path": "just_name",
|
||||
"properties": {
|
||||
"first1": {"type": "string"},
|
||||
"last1": {"type": "string", "index_name": "i_last_1"}
|
||||
}
|
||||
},
|
||||
"name2": {
|
||||
"type": "object",
|
||||
"path": "full",
|
||||
"properties": {
|
||||
"first2": {"type": "string"},
|
||||
"last2": {"type": "string", "index_name": "i_last_2"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields().sort(),
|
||||
["first1", "i_last_1", "name2.first2", "name2.i_last_2" ]);
|
||||
});
|
||||
|
||||
test("Use index_name tests", function () {
|
||||
mappings.loadMappings({
|
||||
"index": {
|
||||
"person": {
|
||||
"properties": {
|
||||
"last1": {"type": "string", "index_name": "i_last_1"}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getFields().sort(),
|
||||
[ "i_last_1" ]);
|
||||
});
|
||||
|
||||
test("Aliases", function () {
|
||||
mappings.loadAliases({
|
||||
"test_index1": {
|
||||
"aliases": {
|
||||
"alias1": {}
|
||||
}
|
||||
},
|
||||
"test_index2": {
|
||||
"aliases": {
|
||||
"alias2": {
|
||||
"filter": {
|
||||
"term": {
|
||||
"FIELD": "VALUE"
|
||||
}
|
||||
}
|
||||
},
|
||||
"alias1": {}
|
||||
}
|
||||
}
|
||||
});
|
||||
mappings.loadMappings({
|
||||
"test_index1": {
|
||||
"type1": {
|
||||
"properties": {
|
||||
"last1": {"type": "string", "index_name": "i_last_1"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"test_index2": {
|
||||
"type2": {
|
||||
"properties": {
|
||||
"last1": {"type": "string", "index_name": "i_last_1"}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
deepEqual(mappings.getIndices().sort(),
|
||||
[ "_all", "alias1", "alias2", "test_index1", "test_index2" ]
|
||||
);
|
||||
deepEqual(mappings.getIndices(false).sort(),
|
||||
["test_index1", "test_index2" ]
|
||||
);
|
||||
deepEqual(mappings.expandAliases(["alias1", "test_index2"]).sort(),
|
||||
["test_index1", "test_index2" ]
|
||||
);
|
||||
deepEqual(mappings.expandAliases("alias2"), "test_index2");
|
||||
});
|
||||
|
||||
deepEqual(global.sense.mappings.getIndices().sort(),
|
||||
[ "_all", "alias1", "alias2", "test_index1", "test_index2" ]
|
||||
);
|
||||
deepEqual(global.sense.mappings.getIndices(false).sort(),
|
||||
["test_index1", "test_index2" ]
|
||||
);
|
||||
deepEqual(global.sense.mappings.expandAliases(["alias1", "test_index2"]).sort(),
|
||||
["test_index1", "test_index2" ]
|
||||
);
|
||||
deepEqual(global.sense.mappings.expandAliases("alias2"), "test_index2");
|
||||
});
|
||||
|
||||
|
|
|
@ -1,242 +1,232 @@
|
|||
var sense = window.sense;
|
||||
var utils = sense.utils;
|
||||
define([
|
||||
'ace',
|
||||
'input',
|
||||
'jquery'
|
||||
], function (ace, input, $) {
|
||||
'use strict';
|
||||
|
||||
module("Tokenization", {
|
||||
setup: function () {
|
||||
module("Tokenization", {
|
||||
setup: function () {
|
||||
input.$el.show();
|
||||
},
|
||||
teardown: function () {
|
||||
input.$el.hide();
|
||||
}
|
||||
});
|
||||
|
||||
sense.tests = {};
|
||||
sense.tests.editor_div = $('<div id="editor"></div>').appendTo($('body'));
|
||||
sense.tests.editor = ace.edit("editor");
|
||||
ace.require("ace/mode/sense");
|
||||
sense.tests.editor.getSession().setMode("ace/mode/sense");
|
||||
sense.tests.editor.getSession().setValue("hello");
|
||||
|
||||
},
|
||||
|
||||
teardown: function () {
|
||||
sense.tests.editor_div.remove();
|
||||
sense.tests = {};
|
||||
}
|
||||
});
|
||||
|
||||
function tokensAsList(editor) {
|
||||
var iter = new (ace.require("ace/token_iterator").TokenIterator)(editor.getSession(), 0, 0);
|
||||
var ret = [];
|
||||
var t = iter.getCurrentToken();
|
||||
if (utils.isEmptyToken(t)) t = utils.nextNonEmptyToken(iter);
|
||||
while (t) {
|
||||
function tokensAsList() {
|
||||
var iter = new (ace.require("ace/token_iterator").TokenIterator)(input.getSession(), 0, 0);
|
||||
var ret = [];
|
||||
var t = iter.getCurrentToken();
|
||||
if (input.parser.isEmptyToken(t)) t = input.parser.nextNonEmptyToken(iter);
|
||||
while (t) {
|
||||
ret.push({ value: t.value, type: t.type });
|
||||
t = utils.nextNonEmptyToken(iter);
|
||||
}
|
||||
t = input.parser.nextNonEmptyToken(iter);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
var testCount = 0;
|
||||
var testCount = 0;
|
||||
|
||||
function token_test(token_list, prefix, data) {
|
||||
if (data && typeof data != "string") data = JSON.stringify(data, null, 3);
|
||||
if (data) {
|
||||
function token_test(token_list, prefix, data) {
|
||||
if (data && typeof data != "string") data = JSON.stringify(data, null, 3);
|
||||
if (data) {
|
||||
if (prefix) data = prefix + "\n" + data;
|
||||
} else {
|
||||
} else {
|
||||
data = prefix;
|
||||
}
|
||||
}
|
||||
|
||||
QUnit.asyncTest("Token test " + testCount++ + " prefix: " + prefix, function () {
|
||||
var editor = sense.tests.editor;
|
||||
asyncTest("Token test " + testCount++ + " prefix: " + prefix, function () {
|
||||
input.update(data, function () {
|
||||
var tokens = tokensAsList();
|
||||
var normTokenList = [];
|
||||
for (var i = 0; i < token_list.length; i++) {
|
||||
normTokenList.push({ type: token_list[i++], value: token_list[i] });
|
||||
}
|
||||
|
||||
utils.updateEditorAndCallWhenUpdated(data, editor, function () {
|
||||
var tokens = tokensAsList(editor);
|
||||
var normTokenList = [];
|
||||
for (var i = 0; i < token_list.length; i++) {
|
||||
normTokenList.push({ type: token_list[i++], value: token_list[i] });
|
||||
}
|
||||
|
||||
deepEqual(tokens, normTokenList, "Doc:\n" + data);
|
||||
start();
|
||||
deepEqual(tokens, normTokenList, "Doc:\n" + data);
|
||||
start();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.endpoint", "_search" ],
|
||||
"GET _search"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.endpoint", "_search" ],
|
||||
"GET _search"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.endpoint", "_search" ],
|
||||
"GET /_search"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.endpoint", "_search" ],
|
||||
"GET /_search"
|
||||
);
|
||||
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.endpoint", "_cluster", "url.slash", "/", "url.part" , "nodes" ],
|
||||
"GET _cluster/nodes"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.endpoint", "_cluster", "url.slash", "/", "url.part" , "nodes" ],
|
||||
"GET _cluster/nodes"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.endpoint", "_cluster", "url.slash", "/", "url.part" , "nodes" ],
|
||||
"GET /_cluster/nodes"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.endpoint", "_cluster", "url.slash", "/", "url.part" , "nodes" ],
|
||||
"GET /_cluster/nodes"
|
||||
);
|
||||
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.endpoint", "_search" ],
|
||||
"GET index/_search"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.endpoint", "_search" ],
|
||||
"GET index/_search"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index" ],
|
||||
"GET index"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index" ],
|
||||
"GET index"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.type", "type" ],
|
||||
"GET index/type"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.type", "type" ],
|
||||
"GET index/type"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index", "url.slash", "/", "url.type", "type", "url.slash", "/" ],
|
||||
"GET /index/type/"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index", "url.slash", "/", "url.type", "type", "url.slash", "/" ],
|
||||
"GET /index/type/"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.type", "type", "url.slash", "/", "url.endpoint", "_search" ],
|
||||
"GET index/type/_search"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.type", "type", "url.slash", "/", "url.endpoint", "_search" ],
|
||||
"GET index/type/_search"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.type", "type", "url.slash", "/", "url.endpoint", "_search",
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.type", "type", "url.slash", "/", "url.endpoint", "_search",
|
||||
"url.questionmark", "?", "url.param", "value", "url.equal", "=", "url.value", "1"
|
||||
],
|
||||
"GET index/type/_search?value=1"
|
||||
);
|
||||
],
|
||||
"GET index/type/_search?value=1"
|
||||
);
|
||||
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.type", "type", "url.slash", "/", "url.id", "1" ],
|
||||
"GET index/type/1"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index", "url.slash", "/", "url.type", "type", "url.slash", "/", "url.id", "1" ],
|
||||
"GET index/type/1"
|
||||
);
|
||||
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index1", "url.comma", ",", "url.index", "index2", "url.slash", "/" ],
|
||||
"GET /index1,index2/"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index1", "url.comma", ",", "url.index", "index2", "url.slash", "/" ],
|
||||
"GET /index1,index2/"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index1", "url.comma", ",", "url.index", "index2", "url.slash", "/",
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index1", "url.comma", ",", "url.index", "index2", "url.slash", "/",
|
||||
"url.endpoint", "_search"],
|
||||
"GET /index1,index2/_search"
|
||||
);
|
||||
"GET /index1,index2/_search"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index1", "url.comma", ",", "url.index", "index2", "url.slash", "/",
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index1", "url.comma", ",", "url.index", "index2", "url.slash", "/",
|
||||
"url.endpoint", "_search"],
|
||||
"GET index1,index2/_search"
|
||||
);
|
||||
"GET index1,index2/_search"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index1", "url.comma", ",", "url.index", "index2" ],
|
||||
"GET /index1,index2"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index1", "url.comma", ",", "url.index", "index2" ],
|
||||
"GET /index1,index2"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index1", "url.comma", ",", "url.index", "index2" ],
|
||||
"GET index1,index2"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.index", "index1", "url.comma", ",", "url.index", "index2" ],
|
||||
"GET index1,index2"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index1", "url.comma", "," ],
|
||||
"GET /index1,"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "GET", "url.slash", "/", "url.index", "index1", "url.comma", "," ],
|
||||
"GET /index1,"
|
||||
);
|
||||
|
||||
|
||||
token_test(
|
||||
[ "method", "PUT", "url.slash", "/", "url.index", "index", "url.slash", "/" ],
|
||||
"PUT /index/"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "PUT", "url.slash", "/", "url.index", "index", "url.slash", "/" ],
|
||||
"PUT /index/"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "PUT", "url.slash", "/", "url.index", "index" ],
|
||||
"PUT /index"
|
||||
);
|
||||
token_test(
|
||||
[ "method", "PUT", "url.slash", "/", "url.index", "index" ],
|
||||
"PUT /index"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "PUT", "url.slash", "/", "url.index", "index1", "url.comma", ",", "url.index", "index2",
|
||||
token_test(
|
||||
[ "method", "PUT", "url.slash", "/", "url.index", "index1", "url.comma", ",", "url.index", "index2",
|
||||
"url.slash", "/", "url.type", "type1", "url.comma", ",", "url.type", "type2"],
|
||||
"PUT /index1,index2/type1,type2"
|
||||
);
|
||||
"PUT /index1,index2/type1,type2"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "PUT", "url.slash", "/", "url.index", "index1",
|
||||
token_test(
|
||||
[ "method", "PUT", "url.slash", "/", "url.index", "index1",
|
||||
"url.slash", "/", "url.type", "type1", "url.comma", ",", "url.type", "type2", "url.comma", ","],
|
||||
"PUT /index1/type1,type2,"
|
||||
);
|
||||
"PUT /index1/type1,type2,"
|
||||
);
|
||||
|
||||
token_test(
|
||||
[ "method", "PUT", "url.index", "index1", "url.comma", ",", "url.index", "index2",
|
||||
token_test(
|
||||
[ "method", "PUT", "url.index", "index1", "url.comma", ",", "url.index", "index2",
|
||||
"url.slash", "/", "url.type", "type1", "url.comma", ",", "url.type", "type2", "url.slash", "/",
|
||||
"url.id", "1234"],
|
||||
"PUT index1,index2/type1,type2/1234"
|
||||
);
|
||||
"PUT index1,index2/type1,type2/1234"
|
||||
);
|
||||
|
||||
|
||||
token_test(
|
||||
[ "method", "POST", "url.endpoint", "_search", "paren.lparen", "{", "variable", '"q"', "punctuation.colon", ":",
|
||||
token_test(
|
||||
[ "method", "POST", "url.endpoint", "_search", "paren.lparen", "{", "variable", '"q"', "punctuation.colon", ":",
|
||||
"paren.lparen", "{", "paren.rparen", "}", "paren.rparen", "}"
|
||||
],
|
||||
'POST _search\n' +
|
||||
],
|
||||
'POST _search\n' +
|
||||
'{\n' +
|
||||
' "q": {}\n' +
|
||||
' \n' +
|
||||
' "q": {}\n' +
|
||||
' \n' +
|
||||
'}'
|
||||
);
|
||||
);
|
||||
|
||||
function statesAsList(editor) {
|
||||
var ret = [];
|
||||
var session = editor.getSession();
|
||||
var maxLine = session.getLength();
|
||||
for (var row = 0; row < maxLine; row++) ret.push(session.getState(row));
|
||||
function statesAsList() {
|
||||
var ret = [];
|
||||
var session = input.getSession();
|
||||
var maxLine = session.getLength();
|
||||
for (var row = 0; row < maxLine; row++) ret.push(session.getState(row));
|
||||
|
||||
return ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
function states_test(states_list, prefix, data) {
|
||||
if (data && typeof data != "string") data = JSON.stringify(data, null, 3);
|
||||
if (data) {
|
||||
function states_test(states_list, prefix, data) {
|
||||
if (data && typeof data != "string") data = JSON.stringify(data, null, 3);
|
||||
if (data) {
|
||||
if (prefix) data = prefix + "\n" + data;
|
||||
} else {
|
||||
} else {
|
||||
data = prefix;
|
||||
}
|
||||
}
|
||||
|
||||
QUnit.asyncTest("States test " + testCount++ + " prefix: " + prefix, function () {
|
||||
var editor = global.sense.tests.editor;
|
||||
|
||||
utils.updateEditorAndCallWhenUpdated(data, editor, function () {
|
||||
var modes = statesAsList(editor);
|
||||
deepEqual(modes, states_list, "Doc:\n" + data);
|
||||
|
||||
start();
|
||||
asyncTest("States test " + testCount++ + " prefix: " + prefix, function () {
|
||||
input.update(data, function () {
|
||||
var modes = statesAsList();
|
||||
deepEqual(modes, states_list, "Doc:\n" + data);
|
||||
start();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function n(name) {
|
||||
return { name: name};
|
||||
}
|
||||
function nd(name, depth) {
|
||||
return { name: name, depth: depth };
|
||||
}
|
||||
function n(name) {
|
||||
return { name: name};
|
||||
}
|
||||
function nd(name, depth) {
|
||||
return { name: name, depth: depth };
|
||||
}
|
||||
|
||||
states_test(
|
||||
[n("start"), nd("json", 1), nd("json", 1), nd("start", 0) ],
|
||||
'POST _search\n' +
|
||||
states_test(
|
||||
[n("start"), nd("json", 1), nd("json", 1), nd("start", 0) ],
|
||||
'POST _search\n' +
|
||||
'{\n' +
|
||||
' "query": { "match_all": {} }\n' +
|
||||
' "query": { "match_all": {} }\n' +
|
||||
'}'
|
||||
);
|
||||
);
|
||||
})
|
|
@ -1,188 +0,0 @@
|
|||
var sense = window.sense;
|
||||
var utils = sense.utils;
|
||||
|
||||
module("Utils", {
|
||||
setup: function () {
|
||||
sense.tests = {};
|
||||
sense.tests.editor_div = $('<div id="editor"></div>').appendTo($('body'));
|
||||
sense.tests.editor = ace.edit("editor");
|
||||
ace.require("ace/mode/sense");
|
||||
sense.tests.editor.getSession().setMode("ace/mode/sense");
|
||||
sense.tests.editor.getSession().setValue("hello");
|
||||
|
||||
},
|
||||
|
||||
teardown: function () {
|
||||
sense.tests.editor_div.remove();
|
||||
sense.tests = {};
|
||||
}
|
||||
});
|
||||
|
||||
var testCount = 0;
|
||||
|
||||
function utils_test(name, prefix, data, test) {
|
||||
if (data && typeof data != "string") data = JSON.stringify(data, null, 3);
|
||||
if (data) {
|
||||
if (prefix) data = prefix + "\n" + data;
|
||||
} else {
|
||||
data = prefix;
|
||||
}
|
||||
|
||||
QUnit.asyncTest("Utils test " + testCount++ + ":" + name,
|
||||
function () {
|
||||
var editor = sense.tests.editor;
|
||||
utils.updateEditorAndCallWhenUpdated(data, editor, function () {
|
||||
test(editor);
|
||||
start();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
var simple_request =
|
||||
{ prefix: 'POST _search',
|
||||
data: '{\n' +
|
||||
' "query": { "match_all": {} }\n' +
|
||||
'}'
|
||||
};
|
||||
|
||||
var single_line_request =
|
||||
{ prefix: 'POST _search',
|
||||
data: '{ "query": { "match_all": {} } }'
|
||||
};
|
||||
|
||||
|
||||
utils_test("simple request range", simple_request.prefix, simple_request.data,
|
||||
function (editor) {
|
||||
var range = utils.getCurrentRequestRange(editor);
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
3, 1
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
}
|
||||
);
|
||||
|
||||
utils_test("single line request range", single_line_request.prefix, single_line_request.data,
|
||||
function (editor) {
|
||||
var range = utils.getCurrentRequestRange(editor);
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
1, 32
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
}
|
||||
);
|
||||
|
||||
utils_test("simple request data", simple_request.prefix, simple_request.data,
|
||||
function (editor) {
|
||||
var request = utils.getCurrentRequest(editor);
|
||||
var expected = {
|
||||
method: "POST",
|
||||
url: "_search",
|
||||
data: [simple_request.data]
|
||||
};
|
||||
|
||||
deepEqual(request, expected);
|
||||
}
|
||||
);
|
||||
|
||||
utils_test("single line request data", single_line_request.prefix, single_line_request.data,
|
||||
function (editor) {
|
||||
var request = utils.getCurrentRequest(editor);
|
||||
var expected = {
|
||||
method: "POST",
|
||||
url: "_search",
|
||||
data: [single_line_request.data]
|
||||
};
|
||||
|
||||
deepEqual(request, expected);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
var get_request_no_data =
|
||||
{ prefix: 'GET _stats'
|
||||
};
|
||||
|
||||
utils_test("request with no data followed by a new line", get_request_no_data.prefix, "\n",
|
||||
function (editor) {
|
||||
var range = utils.getCurrentRequestRange(editor);
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
0, 10
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
}
|
||||
);
|
||||
|
||||
utils_test("request with no data followed by a new line (data)", get_request_no_data.prefix, "\n",
|
||||
function (editor) {
|
||||
var range = utils.getCurrentRequest(editor);
|
||||
var expected = {
|
||||
method: "GET",
|
||||
url: "_stats",
|
||||
data: []
|
||||
};
|
||||
|
||||
deepEqual(range, expected);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
utils_test("request with no data", get_request_no_data.prefix, get_request_no_data.data,
|
||||
function (editor) {
|
||||
var range = utils.getCurrentRequestRange(editor);
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
0, 10
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
}
|
||||
);
|
||||
|
||||
utils_test("request with no data (data)", get_request_no_data.prefix, get_request_no_data.data,
|
||||
function (editor) {
|
||||
var range = utils.getCurrentRequest(editor);
|
||||
var expected = {
|
||||
method: "GET",
|
||||
url: "_stats",
|
||||
data: []
|
||||
};
|
||||
|
||||
deepEqual(range, expected);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
var multi_doc_request =
|
||||
{ prefix: 'POST _bulk',
|
||||
data_as_array: ['{ "index": { "_index": "index", "_type":"type" } }',
|
||||
'{ "field": 1 }'
|
||||
]
|
||||
};
|
||||
multi_doc_request.data = multi_doc_request.data_as_array.join("\n");
|
||||
|
||||
utils_test("multi doc request range", multi_doc_request.prefix, multi_doc_request.data,
|
||||
function (editor) {
|
||||
var range = utils.getCurrentRequestRange(editor);
|
||||
var expected = new (ace.require("ace/range").Range)(
|
||||
0, 0,
|
||||
2, 14
|
||||
);
|
||||
deepEqual(range, expected);
|
||||
}
|
||||
);
|
||||
|
||||
utils_test("multi doc request data", multi_doc_request.prefix, multi_doc_request.data,
|
||||
function (editor) {
|
||||
var request = utils.getCurrentRequest(editor);
|
||||
var expected = {
|
||||
method: "POST",
|
||||
url: "_bulk",
|
||||
data: multi_doc_request.data_as_array
|
||||
};
|
||||
|
||||
deepEqual(request, expected);
|
||||
}
|
||||
);
|
2232
sense/vendor/ace/worker-json.js
vendored
Normal file
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
2280
sense/vendor/bootstrap/js/bootstrap.js
vendored
Normal file
Before Width: | Height: | Size: 197 KiB After Width: | Height: | Size: 197 KiB |
9472
sense/vendor/jquery/jquery-1.8.3.js
vendored
Normal file
7157
sense/vendor/lodash.js
vendored
Normal file
2363
sense/vendor/moment.js
vendored
Normal file
410
sense/vendor/require/almond.js
vendored
Normal file
|
@ -0,0 +1,410 @@
|
|||
/**
|
||||
* almond 0.2.6 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved.
|
||||
* Available via the MIT or new BSD license.
|
||||
* see: http://github.com/jrburke/almond for details
|
||||
*/
|
||||
//Going sloppy to avoid 'use strict' string cost, but strict practices should
|
||||
//be followed.
|
||||
/*jslint sloppy: true */
|
||||
/*global setTimeout: false */
|
||||
|
||||
var requirejs, require, define;
|
||||
(function (undef) {
|
||||
var main, req, makeMap, handlers,
|
||||
defined = {},
|
||||
waiting = {},
|
||||
config = {},
|
||||
defining = {},
|
||||
hasOwn = Object.prototype.hasOwnProperty,
|
||||
aps = [].slice;
|
||||
|
||||
function hasProp(obj, prop) {
|
||||
return hasOwn.call(obj, prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a relative module name, like ./something, normalize it to
|
||||
* a real name that can be mapped to a path.
|
||||
* @param {String} name the relative name
|
||||
* @param {String} baseName a real name that the name arg is relative
|
||||
* to.
|
||||
* @returns {String} normalized name
|
||||
*/
|
||||
function normalize(name, baseName) {
|
||||
var nameParts, nameSegment, mapValue, foundMap,
|
||||
foundI, foundStarMap, starI, i, j, part,
|
||||
baseParts = baseName && baseName.split("/"),
|
||||
map = config.map,
|
||||
starMap = (map && map['*']) || {};
|
||||
|
||||
//Adjust any relative paths.
|
||||
if (name && name.charAt(0) === ".") {
|
||||
//If have a base name, try to normalize against it,
|
||||
//otherwise, assume it is a top-level require that will
|
||||
//be relative to baseUrl in the end.
|
||||
if (baseName) {
|
||||
//Convert baseName to array, and lop off the last part,
|
||||
//so that . matches that "directory" and not name of the baseName's
|
||||
//module. For instance, baseName of "one/two/three", maps to
|
||||
//"one/two/three.js", but we want the directory, "one/two" for
|
||||
//this normalization.
|
||||
baseParts = baseParts.slice(0, baseParts.length - 1);
|
||||
|
||||
name = baseParts.concat(name.split("/"));
|
||||
|
||||
//start trimDots
|
||||
for (i = 0; i < name.length; i += 1) {
|
||||
part = name[i];
|
||||
if (part === ".") {
|
||||
name.splice(i, 1);
|
||||
i -= 1;
|
||||
} else if (part === "..") {
|
||||
if (i === 1 && (name[2] === '..' || name[0] === '..')) {
|
||||
//End of the line. Keep at least one non-dot
|
||||
//path segment at the front so it can be mapped
|
||||
//correctly to disk. Otherwise, there is likely
|
||||
//no path mapping for a path starting with '..'.
|
||||
//This can still fail, but catches the most reasonable
|
||||
//uses of ..
|
||||
break;
|
||||
} else if (i > 0) {
|
||||
name.splice(i - 1, 2);
|
||||
i -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
//end trimDots
|
||||
|
||||
name = name.join("/");
|
||||
} else if (name.indexOf('./') === 0) {
|
||||
// No baseName, so this is ID is resolved relative
|
||||
// to baseUrl, pull off the leading dot.
|
||||
name = name.substring(2);
|
||||
}
|
||||
}
|
||||
|
||||
//Apply map config if available.
|
||||
if ((baseParts || starMap) && map) {
|
||||
nameParts = name.split('/');
|
||||
|
||||
for (i = nameParts.length; i > 0; i -= 1) {
|
||||
nameSegment = nameParts.slice(0, i).join("/");
|
||||
|
||||
if (baseParts) {
|
||||
//Find the longest baseName segment match in the config.
|
||||
//So, do joins on the biggest to smallest lengths of baseParts.
|
||||
for (j = baseParts.length; j > 0; j -= 1) {
|
||||
mapValue = map[baseParts.slice(0, j).join('/')];
|
||||
|
||||
//baseName segment has config, find if it has one for
|
||||
//this name.
|
||||
if (mapValue) {
|
||||
mapValue = mapValue[nameSegment];
|
||||
if (mapValue) {
|
||||
//Match, update name to the new value.
|
||||
foundMap = mapValue;
|
||||
foundI = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (foundMap) {
|
||||
break;
|
||||
}
|
||||
|
||||
//Check for a star map match, but just hold on to it,
|
||||
//if there is a shorter segment match later in a matching
|
||||
//config, then favor over this star map.
|
||||
if (!foundStarMap && starMap && starMap[nameSegment]) {
|
||||
foundStarMap = starMap[nameSegment];
|
||||
starI = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundMap && foundStarMap) {
|
||||
foundMap = foundStarMap;
|
||||
foundI = starI;
|
||||
}
|
||||
|
||||
if (foundMap) {
|
||||
nameParts.splice(0, foundI, foundMap);
|
||||
name = nameParts.join('/');
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
function makeRequire(relName, forceSync) {
|
||||
return function () {
|
||||
//A version of a require function that passes a moduleName
|
||||
//value for items that may need to
|
||||
//look up paths relative to the moduleName
|
||||
return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync]));
|
||||
};
|
||||
}
|
||||
|
||||
function makeNormalize(relName) {
|
||||
return function (name) {
|
||||
return normalize(name, relName);
|
||||
};
|
||||
}
|
||||
|
||||
function makeLoad(depName) {
|
||||
return function (value) {
|
||||
defined[depName] = value;
|
||||
};
|
||||
}
|
||||
|
||||
function callDep(name) {
|
||||
if (hasProp(waiting, name)) {
|
||||
var args = waiting[name];
|
||||
delete waiting[name];
|
||||
defining[name] = true;
|
||||
main.apply(undef, args);
|
||||
}
|
||||
|
||||
if (!hasProp(defined, name) && !hasProp(defining, name)) {
|
||||
throw new Error('No ' + name);
|
||||
}
|
||||
return defined[name];
|
||||
}
|
||||
|
||||
//Turns a plugin!resource to [plugin, resource]
|
||||
//with the plugin being undefined if the name
|
||||
//did not have a plugin prefix.
|
||||
function splitPrefix(name) {
|
||||
var prefix,
|
||||
index = name ? name.indexOf('!') : -1;
|
||||
if (index > -1) {
|
||||
prefix = name.substring(0, index);
|
||||
name = name.substring(index + 1, name.length);
|
||||
}
|
||||
return [prefix, name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a name map, normalizing the name, and using a plugin
|
||||
* for normalization if necessary. Grabs a ref to plugin
|
||||
* too, as an optimization.
|
||||
*/
|
||||
makeMap = function (name, relName) {
|
||||
var plugin,
|
||||
parts = splitPrefix(name),
|
||||
prefix = parts[0];
|
||||
|
||||
name = parts[1];
|
||||
|
||||
if (prefix) {
|
||||
prefix = normalize(prefix, relName);
|
||||
plugin = callDep(prefix);
|
||||
}
|
||||
|
||||
//Normalize according
|
||||
if (prefix) {
|
||||
if (plugin && plugin.normalize) {
|
||||
name = plugin.normalize(name, makeNormalize(relName));
|
||||
} else {
|
||||
name = normalize(name, relName);
|
||||
}
|
||||
} else {
|
||||
name = normalize(name, relName);
|
||||
parts = splitPrefix(name);
|
||||
prefix = parts[0];
|
||||
name = parts[1];
|
||||
if (prefix) {
|
||||
plugin = callDep(prefix);
|
||||
}
|
||||
}
|
||||
|
||||
//Using ridiculous property names for space reasons
|
||||
return {
|
||||
f: prefix ? prefix + '!' + name : name, //fullName
|
||||
n: name,
|
||||
pr: prefix,
|
||||
p: plugin
|
||||
};
|
||||
};
|
||||
|
||||
function makeConfig(name) {
|
||||
return function () {
|
||||
return (config && config.config && config.config[name]) || {};
|
||||
};
|
||||
}
|
||||
|
||||
handlers = {
|
||||
require: function (name) {
|
||||
return makeRequire(name);
|
||||
},
|
||||
exports: function (name) {
|
||||
var e = defined[name];
|
||||
if (typeof e !== 'undefined') {
|
||||
return e;
|
||||
} else {
|
||||
return (defined[name] = {});
|
||||
}
|
||||
},
|
||||
module: function (name) {
|
||||
return {
|
||||
id: name,
|
||||
uri: '',
|
||||
exports: defined[name],
|
||||
config: makeConfig(name)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
main = function (name, deps, callback, relName) {
|
||||
var cjsModule, depName, ret, map, i,
|
||||
args = [],
|
||||
usingExports;
|
||||
|
||||
//Use name if no relName
|
||||
relName = relName || name;
|
||||
|
||||
//Call the callback to define the module, if necessary.
|
||||
if (typeof callback === 'function') {
|
||||
|
||||
//Pull out the defined dependencies and pass the ordered
|
||||
//values to the callback.
|
||||
//Default to [require, exports, module] if no deps
|
||||
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
|
||||
for (i = 0; i < deps.length; i += 1) {
|
||||
map = makeMap(deps[i], relName);
|
||||
depName = map.f;
|
||||
|
||||
//Fast path CommonJS standard dependencies.
|
||||
if (depName === "require") {
|
||||
args[i] = handlers.require(name);
|
||||
} else if (depName === "exports") {
|
||||
//CommonJS module spec 1.1
|
||||
args[i] = handlers.exports(name);
|
||||
usingExports = true;
|
||||
} else if (depName === "module") {
|
||||
//CommonJS module spec 1.1
|
||||
cjsModule = args[i] = handlers.module(name);
|
||||
} else if (hasProp(defined, depName) ||
|
||||
hasProp(waiting, depName) ||
|
||||
hasProp(defining, depName)) {
|
||||
args[i] = callDep(depName);
|
||||
} else if (map.p) {
|
||||
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
|
||||
args[i] = defined[depName];
|
||||
} else {
|
||||
throw new Error(name + ' missing ' + depName);
|
||||
}
|
||||
}
|
||||
|
||||
ret = callback.apply(defined[name], args);
|
||||
|
||||
if (name) {
|
||||
//If setting exports via "module" is in play,
|
||||
//favor that over return value and exports. After that,
|
||||
//favor a non-undefined return value over exports use.
|
||||
if (cjsModule && cjsModule.exports !== undef &&
|
||||
cjsModule.exports !== defined[name]) {
|
||||
defined[name] = cjsModule.exports;
|
||||
} else if (ret !== undef || !usingExports) {
|
||||
//Use the return value from the function.
|
||||
defined[name] = ret;
|
||||
}
|
||||
}
|
||||
} else if (name) {
|
||||
//May just be an object definition for the module. Only
|
||||
//worry about defining if have a module name.
|
||||
defined[name] = callback;
|
||||
}
|
||||
};
|
||||
|
||||
requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
|
||||
if (typeof deps === "string") {
|
||||
if (handlers[deps]) {
|
||||
//callback in this case is really relName
|
||||
return handlers[deps](callback);
|
||||
}
|
||||
//Just return the module wanted. In this scenario, the
|
||||
//deps arg is the module name, and second arg (if passed)
|
||||
//is just the relName.
|
||||
//Normalize module name, if it contains . or ..
|
||||
return callDep(makeMap(deps, callback).f);
|
||||
} else if (!deps.splice) {
|
||||
//deps is a config object, not an array.
|
||||
config = deps;
|
||||
if (callback.splice) {
|
||||
//callback is an array, which means it is a dependency list.
|
||||
//Adjust args if there are dependencies
|
||||
deps = callback;
|
||||
callback = relName;
|
||||
relName = null;
|
||||
} else {
|
||||
deps = undef;
|
||||
}
|
||||
}
|
||||
|
||||
//Support require(['a'])
|
||||
callback = callback || function () {};
|
||||
|
||||
//If relName is a function, it is an errback handler,
|
||||
//so remove it.
|
||||
if (typeof relName === 'function') {
|
||||
relName = forceSync;
|
||||
forceSync = alt;
|
||||
}
|
||||
|
||||
//Simulate async callback;
|
||||
if (forceSync) {
|
||||
main(undef, deps, callback, relName);
|
||||
} else {
|
||||
//Using a non-zero value because of concern for what old browsers
|
||||
//do, and latest browsers "upgrade" to 4 if lower value is used:
|
||||
//http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
|
||||
//If want a value immediately, use require('id') instead -- something
|
||||
//that works in almond on the global level, but not guaranteed and
|
||||
//unlikely to work in other AMD implementations.
|
||||
setTimeout(function () {
|
||||
main(undef, deps, callback, relName);
|
||||
}, 4);
|
||||
}
|
||||
|
||||
return req;
|
||||
};
|
||||
|
||||
/**
|
||||
* Just drops the config on the floor, but returns req in case
|
||||
* the config return value is used.
|
||||
*/
|
||||
req.config = function (cfg) {
|
||||
config = cfg;
|
||||
if (config.deps) {
|
||||
req(config.deps, config.callback);
|
||||
}
|
||||
return req;
|
||||
};
|
||||
|
||||
/**
|
||||
* Expose module registry for debugging and tooling
|
||||
*/
|
||||
requirejs._defined = defined;
|
||||
|
||||
define = function (name, deps, callback) {
|
||||
|
||||
//This module may not have dependencies
|
||||
if (!deps.splice) {
|
||||
//deps is not an array, so probably means
|
||||
//an object literal or factory function for
|
||||
//the value. Adjust args.
|
||||
callback = deps;
|
||||
deps = [];
|
||||
}
|
||||
|
||||
if (!hasProp(defined, name) && !hasProp(waiting, name)) {
|
||||
waiting[name] = [name, deps, callback];
|
||||
}
|
||||
};
|
||||
|
||||
define.amd = {
|
||||
jQuery: true
|
||||
};
|
||||
}());
|
10
sense/vendor/require/css/LICENSE
vendored
Executable file
|
@ -0,0 +1,10 @@
|
|||
MIT License
|
||||
-----------
|
||||
|
||||
Copyright (C) 2013 Guy Bedford
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
203
sense/vendor/require/css/README.md
vendored
Executable file
|
@ -0,0 +1,203 @@
|
|||
require-css
|
||||
===========
|
||||
|
||||
RequireJS CSS requiring and optimization, with almond support.
|
||||
|
||||
Useful for writing modular CSS dependencies alongside scripts. For an example of widget rendering see [ZestJS](http://zestjs.org).
|
||||
|
||||
For LESS inclusion, use [require-less](https://github.com/guybedford/require-less), which behaves and builds the css exactly like this module apart from the preprocessing step.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
Allows the construction of scripts that can require CSS, using the simple RequireJS syntax:
|
||||
|
||||
```javascript
|
||||
define(['css!styles/main'], function() {
|
||||
//code that requires the stylesheet: styles/main.css
|
||||
});
|
||||
```
|
||||
|
||||
Fully compatible in IE 6+, Chrome 3+, Firefox 3.5+, Opera 10+, iOS.
|
||||
|
||||
* **CSS builds** When run as part of a build with the RequireJS optimizer, `css!` dependencies are automatically inlined into the built layer within the JavaScript, fully compatible with layering. CSS injection is performed as soon as the layer is loaded.
|
||||
* **Option to build separate layer CSS files** A `separateCSS` build parameter allows for built layers to output their css files separately, instead of inline with the JavaScript, for manual inclusion.
|
||||
* **CSS compression** CSS redundancy compression is supported through the external library, [csso](https://github.com/css/csso).
|
||||
|
||||
Installation and Setup
|
||||
----------------------
|
||||
|
||||
Download the require-css folder manually or use Bower:
|
||||
|
||||
```bash
|
||||
bower install require-css
|
||||
```
|
||||
|
||||
To allow the direct `css!` usage, add the following [map configuration](http://requirejs.org/docs/api.html#config-map) in RequireJS:
|
||||
|
||||
```javascript
|
||||
map: {
|
||||
'*': {
|
||||
'css': 'require-css/css' // or whatever the path to require-css is
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Use Cases and Benefits
|
||||
----------------------
|
||||
|
||||
### Motivation
|
||||
|
||||
The use case for RequireCSS came out of a need to manage templates and their CSS together.
|
||||
The idea being that a CSS require can be a dependency of the code that dynamically renders a template.
|
||||
When writing a large dynamic application, with templates being rendered on the client-side, it can be beneficial to inject the CSS as templates are required instead
|
||||
of dumping all the CSS together separately. The added benefit of this is then being able to build the CSS naturally with the RequireJS optimizer,
|
||||
which also supports [separate build layers](http://requirejs.org/docs/1.0/docs/faq-optimization.html#priority) as needed.
|
||||
|
||||
### Script-inlined CSS Benefits
|
||||
|
||||
By default, during the build CSS is compressed and inlined as a string within the layer that injects the CSS when run.
|
||||
|
||||
If the layer is included as a `<script>` tag, only one browser request is needed instead of many separate CSS requests with `<link>` tags.
|
||||
|
||||
Even better than including a layer as a `<script>` tag is to include the layer dynamically with a non-blocking require.
|
||||
Then the page can be displayed while the layer is still loading asynchronously in the background.
|
||||
In this case, the CSS that goes with a template being dynamically rendered is loaded with that same script asynchronously.
|
||||
No longer does it need to sit in a `<link>` tag that blocks the page display unnecessarily.
|
||||
|
||||
Modular CSS
|
||||
-----------
|
||||
|
||||
RequireCSS implies a CSS modularisation where styles can be scoped directly to the render code that they are bundled with.
|
||||
|
||||
Just like JS requires, the order of CSS injection can't be guaranteed. The idea here is that whenever there are style overrides, they should
|
||||
be based on using a more specific selector with an extra id or class at the base, and not assuming a CSS load order. Reset and global styles are a repeated dependency of all
|
||||
modular styles that build on top of them.
|
||||
|
||||
Optimizer Configuration
|
||||
-----------------------
|
||||
|
||||
### Basic Usage
|
||||
|
||||
Optimizer configuration:
|
||||
|
||||
```javascript
|
||||
{
|
||||
modules: [
|
||||
{
|
||||
name: 'mymodule',
|
||||
exclude: ['css/normalize']
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
If the contents of 'mymodule' are:
|
||||
|
||||
```javascript
|
||||
define(['css!style', 'css!page'], function(css) {
|
||||
//...
|
||||
});
|
||||
```
|
||||
|
||||
Then the optimizer output would be:
|
||||
|
||||
-mymodule.js containing:
|
||||
style.css and page.css which will be dynamically injected
|
||||
|
||||
The `css/normalize` exclude is needed due to [r.js issue #289](https://github.com/jrburke/r.js/issues/289)
|
||||
|
||||
### Separate File Output
|
||||
|
||||
To output the CSS to a separate file, use the configuration:
|
||||
|
||||
```javascript
|
||||
{
|
||||
separateCSS: true,
|
||||
modules: [
|
||||
{
|
||||
name: 'mymodule'
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
This will then output all the css to the file `mymodule.css`. This configuration can also be placed on the module object itself for layer-specific settings.
|
||||
|
||||
Optimization is fully compatible with exclude and include.
|
||||
|
||||
### siteRoot Configuration
|
||||
|
||||
When building the CSS, all URIs are renormalized relative to the site root.
|
||||
|
||||
It assumed that the siteRoot matches the build directory in this case.
|
||||
|
||||
If this is different, then specify the server path of the siteRoot relative to the baseURL in the configuration.
|
||||
|
||||
For example, if the site root is `www` and we are building the directory `www/lib`, we would use the configuration:
|
||||
|
||||
```javascript
|
||||
{
|
||||
appDir: 'lib',
|
||||
dir: 'lib-built',
|
||||
siteRoot: '../',
|
||||
modules: [
|
||||
{
|
||||
name: 'mymodule'
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### Disabling the Build
|
||||
|
||||
To disable any CSS build entirely, use the configuration option `buildCSS`:
|
||||
|
||||
```javascript
|
||||
{
|
||||
buildCSS: false,
|
||||
modules: [
|
||||
{
|
||||
name: 'mymodule'
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
CSS requires will then be left in the source "as is".
|
||||
|
||||
CSS Compression
|
||||
---------------
|
||||
|
||||
CSS compression is supported with [csso](https://github.com/css/csso).
|
||||
|
||||
To enable the CSS compression, install csso with npm:
|
||||
|
||||
```
|
||||
npm install csso -g
|
||||
```
|
||||
|
||||
The build log will display the compression results.
|
||||
|
||||
When running the r.js optimizer through NodeJS, sometimes the global module isn't found. In this case install csso as a local node module so it can be found.
|
||||
|
||||
|
||||
Injection methods
|
||||
-----------------
|
||||
|
||||
When loading a CSS file or external CSS file, a `<link>` tag is used. Cross-browser support comes through a number of careful browser conditions for this.
|
||||
|
||||
If CSS resources such as images are important to be loaded first, these can be added to the require through a loader plugin that can act as a preloader such as [image](https://github.com/millermedeiros/requirejs-plugins) or [font](https://github.com/millermedeiros/requirejs-plugins). Then a require can be written of the form:
|
||||
|
||||
```javascript
|
||||
require(['css!my-css', 'image!preload-background-image.jpg', 'font!google,families:[Tangerine]']);
|
||||
```
|
||||
|
||||
License
|
||||
---
|
||||
|
||||
MIT
|
||||
|
||||
|
||||
[](https://bitdeli.com/free "Bitdeli Badge")
|
||||
|
174
sense/vendor/require/css/css-builder.js
vendored
Executable file
|
@ -0,0 +1,174 @@
|
|||
define(['require', './normalize'], function(req, normalize) {
|
||||
var cssAPI = {};
|
||||
|
||||
var isWindows = !!process.platform.match(/^win/);
|
||||
|
||||
function compress(css) {
|
||||
if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) {
|
||||
try {
|
||||
var csso = require.nodeRequire('csso');
|
||||
}
|
||||
catch(e) {
|
||||
console.log('Compression module not installed. Use "npm install csso -g" to enable.');
|
||||
return css;
|
||||
}
|
||||
var csslen = css.length;
|
||||
try {
|
||||
css = csso.justDoIt(css);
|
||||
}
|
||||
catch(e) {
|
||||
console.log('Compression failed due to a CSS syntax error.');
|
||||
return css;
|
||||
}
|
||||
console.log('Compressed CSS output to ' + Math.round(css.length / csslen * 100) + '%.');
|
||||
return css;
|
||||
}
|
||||
console.log('Compression not supported outside of nodejs environments.');
|
||||
return css;
|
||||
}
|
||||
|
||||
//load file code - stolen from text plugin
|
||||
function loadFile(path) {
|
||||
if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) {
|
||||
var fs = require.nodeRequire('fs');
|
||||
var file = fs.readFileSync(path, 'utf8');
|
||||
if (file.indexOf('\uFEFF') === 0)
|
||||
return file.substring(1);
|
||||
return file;
|
||||
}
|
||||
else {
|
||||
var file = new java.io.File(path),
|
||||
lineSeparator = java.lang.System.getProperty("line.separator"),
|
||||
input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(file), 'utf-8')),
|
||||
stringBuffer, line;
|
||||
try {
|
||||
stringBuffer = new java.lang.StringBuffer();
|
||||
line = input.readLine();
|
||||
if (line && line.length() && line.charAt(0) === 0xfeff)
|
||||
line = line.substring(1);
|
||||
stringBuffer.append(line);
|
||||
while ((line = input.readLine()) !== null) {
|
||||
stringBuffer.append(lineSeparator).append(line);
|
||||
}
|
||||
return String(stringBuffer.toString());
|
||||
}
|
||||
finally {
|
||||
input.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function saveFile(path, data) {
|
||||
if (typeof process !== "undefined" && process.versions && !!process.versions.node && require.nodeRequire) {
|
||||
var fs = require.nodeRequire('fs');
|
||||
fs.writeFileSync(path, data, 'utf8');
|
||||
}
|
||||
else {
|
||||
var content = new java.lang.String(data);
|
||||
var output = new java.io.BufferedWriter(new java.io.OutputStreamWriter(new java.io.FileOutputStream(path), 'utf-8'));
|
||||
|
||||
try {
|
||||
output.write(content, 0, content.length());
|
||||
output.flush();
|
||||
}
|
||||
finally {
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//when adding to the link buffer, paths are normalised to the baseUrl
|
||||
//when removing from the link buffer, paths are normalised to the output file path
|
||||
function escape(content) {
|
||||
return content.replace(/(["'\\])/g, '\\$1')
|
||||
.replace(/[\f]/g, "\\f")
|
||||
.replace(/[\b]/g, "\\b")
|
||||
.replace(/[\n]/g, "\\n")
|
||||
.replace(/[\t]/g, "\\t")
|
||||
.replace(/[\r]/g, "\\r");
|
||||
}
|
||||
|
||||
// NB add @media query support for media imports
|
||||
var importRegEx = /@import\s*(url)?\s*(('([^']*)'|"([^"]*)")|\(('([^']*)'|"([^"]*)"|([^\)]*))\))\s*;?/g;
|
||||
var absUrlRegEx = /^([^\:\/]+:\/)?\//;
|
||||
|
||||
|
||||
var siteRoot;
|
||||
|
||||
var baseParts = req.toUrl('base_url').split('/');
|
||||
baseParts[baseParts.length - 1] = '';
|
||||
var baseUrl = baseParts.join('/');
|
||||
|
||||
var curModule = 0;
|
||||
var config;
|
||||
|
||||
var layerBuffer = [];
|
||||
var cssBuffer = {};
|
||||
|
||||
cssAPI.load = function(name, req, load, _config) {
|
||||
|
||||
//store config
|
||||
config = config || _config;
|
||||
|
||||
if (!siteRoot) {
|
||||
siteRoot = path.resolve(config.dir || path.dirname(config.out), config.siteRoot || '.') + '/';
|
||||
if (isWindows)
|
||||
siteRoot = siteRoot.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
//external URLS don't get added (just like JS requires)
|
||||
if (name.match(absUrlRegEx))
|
||||
return load();
|
||||
|
||||
var fileUrl = req.toUrl(name + '.css');
|
||||
|
||||
//add to the buffer
|
||||
cssBuffer[name] = normalize(loadFile(fileUrl), isWindows ? fileUrl.replace(/\\/g, '/') : fileUrl, siteRoot);
|
||||
|
||||
load();
|
||||
}
|
||||
|
||||
cssAPI.normalize = function(name, normalize) {
|
||||
if (name.substr(name.length - 4, 4) == '.css')
|
||||
name = name.substr(0, name.length - 4);
|
||||
return normalize(name);
|
||||
}
|
||||
|
||||
cssAPI.write = function(pluginName, moduleName, write, parse) {
|
||||
//external URLS don't get added (just like JS requires)
|
||||
if (moduleName.match(absUrlRegEx))
|
||||
return;
|
||||
|
||||
layerBuffer.push(cssBuffer[moduleName]);
|
||||
|
||||
if (config.buildCSS != false)
|
||||
write.asModule(pluginName + '!' + moduleName, 'define(function(){})');
|
||||
}
|
||||
|
||||
cssAPI.onLayerEnd = function(write, data) {
|
||||
//calculate layer css
|
||||
var css = layerBuffer.join('');
|
||||
|
||||
if (config.separateCSS) {
|
||||
console.log('Writing CSS! file: ' + data.name + '\n');
|
||||
|
||||
var outPath = config.appDir ? config.baseUrl + data.name + '.css' : config.out.replace(/(\.js)?$/, '.css');
|
||||
|
||||
saveFile(outPath, compress(css));
|
||||
}
|
||||
else if (config.buildCSS != false) {
|
||||
if (css == '')
|
||||
return;
|
||||
write(
|
||||
"(function(c){var d=document,a='appendChild',i='styleSheet',s=d.createElement('style');s.type='text/css';d.getElementsByTagName('head')[0][a](s);s[i]?s[i].cssText=c:s[a](d.createTextNode(c));})\n"
|
||||
+ "('" + escape(compress(css)) + "');\n"
|
||||
);
|
||||
}
|
||||
|
||||
//clear layer buffer for next layer
|
||||
layerBuffer = [];
|
||||
}
|
||||
|
||||
return cssAPI;
|
||||
});
|