WIP: Added QueryResult ui type

This commit is contained in:
Jose Gonzalez 2020-10-08 13:47:26 +02:00
parent 63ed443b98
commit 3b14453d1e
8 changed files with 28706 additions and 8 deletions

View File

@ -14,7 +14,7 @@
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2019 Artica Soluciones Tecnologicas
* Copyright (c) 2005-2020 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -6124,3 +6124,105 @@ function ui_print_message_dialog($title, $text, $id='', $img='', $text_button=''
echo '</div>';
echo '</div>';
}
/**
* Build a Query-Result editor structure
*
* @param string $name Name of the structure
*
* @return null
*/
function ui_query_result_editor($name='default')
{
$editorSubContainer = html_print_div(
[
'id' => $name.'_editor_title',
'content' => '<p>'.__('Query').'</p>',
],
true
);
$editorSubContainer .= html_print_div(
[
'id' => $name.'_editor',
'class' => 'query_result_editor',
],
true
);
$editorSubContainer .= html_print_div(
[
'class' => 'action-buttons edit-button',
'content' => html_print_submit_button(
__('Execute query'),
'execute_query',
false,
'class="sub next"',
true
),
],
true
);
$editorContainer = html_print_div(
[
'id' => $name.'_editor_container',
'class' => 'query_result_editor_container',
'content' => $editorSubContainer,
],
true
);
$viewSubContainer = html_print_div(
[
'id' => $name.'_view_title',
'content' => '<p>'.__('Results').'</p>',
],
true
);
$viewSubContainer .= html_print_div(
[
'id' => $name.'_view',
'class' => 'query_result_view',
],
true
);
$viewSubContainer .= html_print_div(
[
'class' => 'action-buttons',
'content' => '',
],
true
);
$viewContainer = html_print_div(
[
'id' => $name.'_view_container',
'class' => 'query_result_view_container',
'content' => $viewSubContainer,
],
true
);
html_print_div(
[
'id' => 'query_result_container',
'class' => 'databox',
'content' => $editorContainer.$viewContainer,
]
);
// This is needed for Javascript
html_print_div(
[
'id' => 'pandora_full_url',
'hidden' => true,
'content' => ui_get_full_url(false, false, false, false),
]
);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,396 @@
ace.define(
"ace/mode/json_highlight_rules",
[
"require",
"exports",
"module",
"ace/lib/oop",
"ace/mode/text_highlight_rules"
],
function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextHighlightRules = require("./text_highlight_rules")
.TextHighlightRules;
var JsonHighlightRules = function() {
this.$rules = {
start: [
{
token: "variable", // single line
regex: '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]\\s*(?=:)'
},
{
token: "string", // single line
regex: '"',
next: "string"
},
{
token: "constant.numeric", // hex
regex: "0[xX][0-9a-fA-F]+\\b"
},
{
token: "constant.numeric", // float
regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
},
{
token: "constant.language.boolean",
regex: "(?:true|false)\\b"
},
{
token: "text", // single quoted strings are not allowed
regex: "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
},
{
token: "comment", // comments are not allowed, but who cares?
regex: "\\/\\/.*$"
},
{
token: "comment.start", // comments are not allowed, but who cares?
regex: "\\/\\*",
next: "comment"
},
{
token: "paren.lparen",
regex: "[[({]"
},
{
token: "paren.rparen",
regex: "[\\])}]"
},
{
token: "text",
regex: "\\s+"
}
],
string: [
{
token: "constant.language.escape",
regex: /\\(?:x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|["\\\/bfnrt])/
},
{
token: "string",
regex: '"|$',
next: "start"
},
{
defaultToken: "string"
}
],
comment: [
{
token: "comment.end", // comments are not allowed, but who cares?
regex: "\\*\\/",
next: "start"
},
{
defaultToken: "comment"
}
]
};
};
oop.inherits(JsonHighlightRules, TextHighlightRules);
exports.JsonHighlightRules = JsonHighlightRules;
}
);
ace.define(
"ace/mode/matching_brace_outdent",
["require", "exports", "module", "ace/range"],
function(require, exports, module) {
"use strict";
var Range = require("../range").Range;
var MatchingBraceOutdent = function() {};
(function() {
this.checkOutdent = function(line, input) {
if (!/^\s+$/.test(line)) return false;
return /^\s*\}/.test(input);
};
this.autoOutdent = function(doc, row) {
var line = doc.getLine(row);
var match = line.match(/^(\s*\})/);
if (!match) return 0;
var column = match[1].length;
var openBracePos = doc.findMatchingBracket({
row: row,
column: column
});
if (!openBracePos || openBracePos.row == row) return 0;
var indent = this.$getIndent(doc.getLine(openBracePos.row));
doc.replace(new Range(row, 0, row, column - 1), indent);
};
this.$getIndent = function(line) {
return line.match(/^\s*/)[0];
};
}.call(MatchingBraceOutdent.prototype));
exports.MatchingBraceOutdent = MatchingBraceOutdent;
}
);
ace.define(
"ace/mode/folding/cstyle",
[
"require",
"exports",
"module",
"ace/lib/oop",
"ace/range",
"ace/mode/folding/fold_mode"
],
function(require, exports, module) {
"use strict";
var oop = require("../../lib/oop");
var Range = require("../../range").Range;
var BaseFoldMode = require("./fold_mode").FoldMode;
var FoldMode = (exports.FoldMode = function(commentRegex) {
if (commentRegex) {
this.foldingStartMarker = new RegExp(
this.foldingStartMarker.source.replace(
/\|[^|]*?$/,
"|" + commentRegex.start
)
);
this.foldingStopMarker = new RegExp(
this.foldingStopMarker.source.replace(
/\|[^|]*?$/,
"|" + commentRegex.end
)
);
}
});
oop.inherits(FoldMode, BaseFoldMode);
(function() {
this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
this._getFoldWidgetBase = this.getFoldWidget;
this.getFoldWidget = function(session, foldStyle, row) {
var line = session.getLine(row);
if (this.singleLineBlockCommentRe.test(line)) {
if (
!this.startRegionRe.test(line) &&
!this.tripleStarBlockCommentRe.test(line)
)
return "";
}
var fw = this._getFoldWidgetBase(session, foldStyle, row);
if (!fw && this.startRegionRe.test(line)) return "start"; // lineCommentRegionStart
return fw;
};
this.getFoldWidgetRange = function(
session,
foldStyle,
row,
forceMultiline
) {
var line = session.getLine(row);
if (this.startRegionRe.test(line))
return this.getCommentRegionBlock(session, line, row);
var match = line.match(this.foldingStartMarker);
if (match) {
var i = match.index;
if (match[1])
return this.openingBracketBlock(session, match[1], row, i);
var range = session.getCommentFoldRange(row, i + match[0].length, 1);
if (range && !range.isMultiLine()) {
if (forceMultiline) {
range = this.getSectionRange(session, row);
} else if (foldStyle != "all") range = null;
}
return range;
}
if (foldStyle === "markbegin") return;
var match = line.match(this.foldingStopMarker);
if (match) {
var i = match.index + match[0].length;
if (match[1])
return this.closingBracketBlock(session, match[1], row, i);
return session.getCommentFoldRange(row, i, -1);
}
};
this.getSectionRange = function(session, row) {
var line = session.getLine(row);
var startIndent = line.search(/\S/);
var startRow = row;
var startColumn = line.length;
row = row + 1;
var endRow = row;
var maxRow = session.getLength();
while (++row < maxRow) {
line = session.getLine(row);
var indent = line.search(/\S/);
if (indent === -1) continue;
if (startIndent > indent) break;
var subRange = this.getFoldWidgetRange(session, "all", row);
if (subRange) {
if (subRange.start.row <= startRow) {
break;
} else if (subRange.isMultiLine()) {
row = subRange.end.row;
} else if (startIndent == indent) {
break;
}
}
endRow = row;
}
return new Range(
startRow,
startColumn,
endRow,
session.getLine(endRow).length
);
};
this.getCommentRegionBlock = function(session, line, row) {
var startColumn = line.search(/\s*$/);
var maxRow = session.getLength();
var startRow = row;
var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
var depth = 1;
while (++row < maxRow) {
line = session.getLine(row);
var m = re.exec(line);
if (!m) continue;
if (m[1]) depth--;
else depth++;
if (!depth) break;
}
var endRow = row;
if (endRow > startRow) {
return new Range(startRow, startColumn, endRow, line.length);
}
};
}.call(FoldMode.prototype));
}
);
ace.define(
"ace/mode/json",
[
"require",
"exports",
"module",
"ace/lib/oop",
"ace/mode/text",
"ace/mode/json_highlight_rules",
"ace/mode/matching_brace_outdent",
"ace/mode/behaviour/cstyle",
"ace/mode/folding/cstyle",
"ace/worker/worker_client"
],
function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var HighlightRules = require("./json_highlight_rules").JsonHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent")
.MatchingBraceOutdent;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var WorkerClient = require("../worker/worker_client").WorkerClient;
var Mode = function() {
this.HighlightRules = HighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = new CstyleBehaviour();
this.foldingRules = new CStyleFoldMode();
};
oop.inherits(Mode, TextMode);
(function() {
this.lineCommentStart = "//";
this.blockComment = { start: "/*", end: "*/" };
this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);
if (state == "start") {
var match = line.match(/^.*[\{\(\[]\s*$/);
if (match) {
indent += tab;
}
}
return indent;
};
this.checkOutdent = function(state, line, input) {
return this.$outdent.checkOutdent(line, input);
};
this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};
this.createWorker = function(session) {
var worker = new WorkerClient(
["ace"],
"ace/mode/json_worker",
"JsonWorker"
);
worker.attachToDocument(session.getDocument());
worker.on("annotate", function(e) {
session.setAnnotations(e.data);
});
worker.on("terminate", function() {
session.clearAnnotations();
});
return worker;
};
this.$id = "ace/mode/json";
}.call(Mode.prototype));
exports.Mode = Mode;
}
);
(function() {
ace.require(["ace/mode/json"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();

View File

@ -0,0 +1,154 @@
.ace-tm .ace_gutter {
background: #f0f0f0;
color: #333;
}
.ace-tm .ace_print-margin {
width: 1px;
background: #e8e8e8;
}
.ace-tm .ace_fold {
background-color: #6b72e6;
}
.ace-tm {
background-color: #ffffff;
color: black;
}
.ace-tm .ace_cursor {
color: black;
}
.ace-tm .ace_invisible {
color: rgb(191, 191, 191);
}
.ace-tm .ace_storage,
.ace-tm .ace_keyword {
color: blue;
}
.ace-tm .ace_constant {
color: rgb(197, 6, 11);
}
.ace-tm .ace_constant.ace_buildin {
color: rgb(88, 72, 246);
}
.ace-tm .ace_constant.ace_language {
color: rgb(88, 92, 246);
}
.ace-tm .ace_constant.ace_library {
color: rgb(6, 150, 14);
}
.ace-tm .ace_invalid {
background-color: rgba(255, 0, 0, 0.1);
color: red;
}
.ace-tm .ace_support.ace_function {
color: rgb(60, 76, 114);
}
.ace-tm .ace_support.ace_constant {
color: rgb(6, 150, 14);
}
.ace-tm .ace_support.ace_type,
.ace-tm .ace_support.ace_class {
color: rgb(109, 121, 222);
}
.ace-tm .ace_keyword.ace_operator {
color: rgb(104, 118, 135);
}
.ace-tm .ace_string {
color: rgb(3, 106, 7);
}
.ace-tm .ace_comment {
color: rgb(76, 136, 107);
}
.ace-tm .ace_comment.ace_doc {
color: rgb(0, 102, 255);
}
.ace-tm .ace_comment.ace_doc.ace_tag {
color: rgb(128, 159, 191);
}
.ace-tm .ace_constant.ace_numeric {
color: rgb(0, 0, 205);
}
.ace-tm .ace_variable {
color: rgb(49, 132, 149);
}
.ace-tm .ace_xml-pe {
color: rgb(104, 104, 91);
}
.ace-tm .ace_entity.ace_name.ace_function {
color: #0000a2;
}
.ace-tm .ace_heading {
color: rgb(12, 7, 255);
}
.ace-tm .ace_list {
color: rgb(185, 6, 144);
}
.ace-tm .ace_meta.ace_tag {
color: rgb(0, 22, 142);
}
.ace-tm .ace_string.ace_regex {
color: rgb(255, 0, 0);
}
.ace-tm .ace_marker-layer .ace_selection {
background: rgb(181, 213, 255);
}
.ace-tm.ace_multiselect .ace_selection.ace_start {
box-shadow: 0 0 3px 0px white;
}
.ace-tm .ace_marker-layer .ace_step {
background: rgb(252, 255, 0);
}
.ace-tm .ace_marker-layer .ace_stack {
background: rgb(164, 229, 101);
}
.ace-tm .ace_marker-layer .ace_bracket {
margin: -1px 0 0 -1px;
border: 1px solid rgb(192, 192, 192);
}
.ace-tm .ace_marker-layer .ace_active-line {
background: rgba(0, 0, 0, 0.07);
}
.ace-tm .ace_gutter-active-line {
background-color: #dcdcdc;
}
.ace-tm .ace_marker-layer .ace_selected-word {
background: rgb(250, 250, 255);
border: 1px solid rgb(200, 200, 250);
}
.ace-tm .ace_indent-guide {
background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==")
right repeat-y;
}

View File

@ -0,0 +1,41 @@
/* ***** BEGIN LICENSE BLOCK *****
* Distributed under the BSD license:
*
* Copyright (c) 2010, Ajax.org B.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Ajax.org B.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ***** END LICENSE BLOCK ***** */
define(function(require, exports, module) {
"use strict";
exports.isDark = false;
exports.cssClass = "ace-tm";
exports.cssText = require("../requirejs/text!./textmate.css");
exports.$id = "ace/theme/textmate";
var dom = require("../lib/dom");
dom.importCssString(exports.cssText, exports.cssClass);
});

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,69 @@
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("");
let selectText = editor.getSelectedText();
if (selectText === "") {
let allText = editor.getValue();
if (allText === "") {
return;
}
allText = allText.split("\n").join("");
allText = allText.concat("\n");
var text = allText.match("(GET|PUT|POST)(.*?)({.*?}.*?)?(GET|POST|PUT|\n)");
} else {
selectText = selectText.split("\n").join("");
selectText = selectText.concat("\n");
var text = selectText.match("(GET|PUT|POST)(.*?)({.*?}.*?)?(\n)");
}
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"
);
});

View File

@ -1,19 +1,19 @@
#elasticsearch_container {
#query_result_container {
display: flex;
}
.elasticsearch_editor_container {
.query_result_editor_container {
width: 30%;
}
.elasticsearch_editor_container p {
.query_result_editor_container p {
padding-left: 40px;
font-size: medium;
margin-top: 5px;
margin-bottom: 5px;
}
.elasticsearch_editor {
.query_result_editor {
width: 100%;
height: 65em;
border-top: 1px solid #e2e2e2;
@ -24,19 +24,19 @@
border-radius: 4px;
}
.elasticsearch_view_container {
.query_result_view_container {
width: 70%;
margin-left: 30px;
}
.elasticsearch_view_container p {
.query_result_view_container p {
padding-left: 40px;
font-size: medium;
margin-top: 5px;
margin-bottom: 5px;
}
.elasticsearch_view {
.query_result_view {
min-height: 65em;
border-top: 1px solid #e2e2e2;
border-left: 1px solid #e2e2e2;