pandorafms/pandora_console/include/javascript/elasticsearch_queryResult.js

71 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-10-08 13:47:26 +02:00
var editor = ace.edit("elasticsearch_editor");
editor.setValue(`GET _search \n{\n "query": {\n "match_all": {}\n }\n}`);
editor.clearSelection();
var view = ace.edit("elasticsearch_view");
view.setTheme("ace/theme/textmate");
view.session.setMode("ace/mode/json");
view.renderer.setShowGutter(false);
view.setReadOnly(true);
view.setShowPrintMargin(false);
$("#submit-execute_query").click(function() {
view.setValue("");
2022-02-07 13:48:25 +01:00
let text;
2020-10-08 13:47:26 +02:00
let selectText = editor.getSelectedText();
if (selectText === "") {
let allText = editor.getValue();
if (allText === "") {
return;
}
allText = allText.split("\n").join("");
allText = allText.concat("\n");
2022-02-07 13:48:25 +01:00
text = allText.match("(GET|PUT|POST)(.*?)({.*?}.*?)?(GET|POST|PUT|\n)");
2020-10-08 13:47:26 +02:00
} else {
selectText = selectText.split("\n").join("");
selectText = selectText.concat("\n");
2022-02-07 13:48:25 +01:00
text = selectText.match("(GET|PUT|POST)(.*?)({.*?}.*?)?(\n)");
2020-10-08 13:47:26 +02:00
}
if (
text === null ||
text === undefined ||
text[2] === "" ||
text[2] === undefined
) {
view.setValue(`Syntax error`);
view.clearSelection();
return;
}
const head = text[1];
let index = text[2].trim();
if (index.match("^/") === null) {
index = `/${index}`;
}
let json = text[3];
if (json !== "" && json !== undefined) {
json = json.match("^{.*}")[0];
}
jQuery.post(
$("#pandora_full_url").text() + "ajax.php",
{
page: "enterprise/include/ajax/log_viewer.ajax",
elasticsearch_curl: 1,
head: head,
index: index,
json: json
},
function(data) {
view.setValue(data);
view.clearSelection();
forced_title_callback();
},
"html"
);
});