diff --git a/webui/assets/main.js b/webui/assets/main.js
index 4e17db19a..78ed7470c 100644
--- a/webui/assets/main.js
+++ b/webui/assets/main.js
@@ -116,42 +116,90 @@ class REPL {
process_query(query) {
var xhr = new XMLHttpRequest();
+ var url, data, request, command_name;
var e = document.getElementById("index-dropdown");
var indexname = e.options[e.selectedIndex].text;
- xhr.open('POST', '/index/' + indexname + '/query');
+ var repl = this;
+ if (query.startsWith(":")) {
+ var parsed_query = parse_query(query, indexname);
+ if (Object.keys(parsed_query).length === 0) {
+ repl.create_single_output({
+ "input": query,
+ "output": "invalid query",
+ "status": 400,
+ "indexname": indexname,
+ });
+ return;
+ } else {
+ // set selectedIndex from dropdown list
+ if (parsed_query.command === "use") {
+ for (var i = 0; i < e.options.length; i++) {
+ if (e.options[i].text === parsed_query.command_name) {
+ e.selectedIndex = i;
+ break;
+ }
+ }
+ return;
+ }
+ url = parsed_query.url;
+ data = parsed_query.data;
+ request = parsed_query.request;
+ command_name = parsed_query.command_name;
+ }
+ }
+ else {
+ url = '/index/' + indexname + '/query'
+ request = "POST"
+ data = query
+ }
+ xhr.open(request, url);
xhr.setRequestHeader('Content-Type', 'application/text');
- var repl = this
var start_time = new Date().getTime();
- xhr.send(query)
- xhr.onload = function() {
- var end_time = new Date().getTime()
+ xhr.onload = function () {
+ var end_time = new Date().getTime();
repl.result_number++
- repl.createSingleOutput({
- "input": query,
- "output": xhr.responseText,
- "indexname": indexname,
- "querytime_ms": end_time - start_time,
- })
- }
+ repl.create_single_output({
+ "input": query,
+ "output": xhr.responseText,
+ "status": xhr.status,
+ "indexname": indexname,
+ "querytime_ms": end_time - start_time,
+ });
+ };
+ xhr.send(data);
+ // Remove index from dropdown with delete index command
+ if (request === 'DELETE' && url === '/index/' + command_name){
+ for (var i = 0; i < e.options.length; i++) {
+ if (e.options[i].text === command_name) {
+ e.remove(i);
+ break;
+ }
+ }
+ }
}
- createSingleOutput(res) {
- var node = document.createElement("div");
- node.classList.add('output');
- var output_string = res['output']
- var output_json = JSON.parse(output_string)
- var result_class = "result-output"
- var getting_started_errors = [
- 'index not found',
- 'frame not found',
- ]
-
- if("error" in output_json) {
- result_class = "result-error"
- if(getting_started_errors.indexOf(output_json['error']) >= 0) {
- output_string += `
+ create_single_output(res) {
+ var node = document.createElement("div");
+ node.classList.add('output');
+ var output_string = res['output']
+ var result_class = "result-output"
+ var getting_started_errors = [
+ 'index not found',
+ 'frame not found',
+ ]
+ var output_json;
+ if (isJSON(output_string)) {
+ output_json = JSON.parse(output_string)
+ }
+ // handle output formatting
+ if (res["status"] != 200) {
+ result_class = "result-error";
+ if (output_json) {
+ if ("error" in output_json) {
+ if (getting_started_errors.indexOf(output_json['error']) >= 0) {
+ output_string += `
Just getting started? Try this:
$ curl -XPOST "http://127.0.0.1:10101/index/test" -d '{"options": {"columnLabel": "col"}}' # create index "test"
@@ -159,8 +207,10 @@ class REPL {
# Select "test" in the index dropdown above
SetBit(row=0, col=0, frame=foo) # Use PQL to set a bit
`
+ }
+ }
+ }
}
- }
var markup =`
@@ -184,7 +234,9 @@ class REPL {