mirror of https://gitee.com/bigwinds/arangodb
make number of results adjustable in AQL editor
This commit is contained in:
parent
500c270158
commit
d1b32bfcab
|
@ -163,6 +163,19 @@
|
||||||
z-index: 9999 !important;
|
z-index: 9999 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#querySize {
|
||||||
|
height: 20px !important;
|
||||||
|
line-height: 20px !important;
|
||||||
|
z-index: 9999 !important;
|
||||||
|
border-radius: 0 !important;
|
||||||
|
padding: 0 !important;
|
||||||
|
margin-bottom: 0;
|
||||||
|
border: 0 !important;
|
||||||
|
float: left !important;
|
||||||
|
margin-left: 50px;
|
||||||
|
margin-right: 0 !important;
|
||||||
|
}
|
||||||
|
|
||||||
.queryTH {
|
.queryTH {
|
||||||
width: 20% !important;
|
width: 20% !important;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
<span class="glyphicon glyphicon-cog queryTooltips" title="Edit custom queries" id="editAQL"/>
|
<span class="glyphicon glyphicon-cog queryTooltips" title="Edit custom queries" id="editAQL"/>
|
||||||
<span class="arangoicon arango-icon-disk queryTooltips" title="Save current query" id="addAQL"/>
|
<span class="arangoicon arango-icon-disk queryTooltips" title="Save current query" id="addAQL"/>
|
||||||
<span class="arangoicon arango-icon-remove queryTooltips" title="Clear" id="clearInput"/>
|
<span class="arangoicon arango-icon-remove queryTooltips" title="Clear" id="clearInput"/>
|
||||||
|
<select id="querySize"/>
|
||||||
<span class="arangoicon arango-icon-comment queryTooltips" title="Comment" id="commentText"/>
|
<span class="arangoicon arango-icon-comment queryTooltips" title="Comment" id="commentText"/>
|
||||||
<span class="arangoicon arango-icon-redo queryTooltips" title="Redo" id="redoText"/>
|
<span class="arangoicon arango-icon-redo queryTooltips" title="Redo" id="redoText"/>
|
||||||
<span class="arangoicon arango-icon-undo queryTooltips" title="Undo" id="undoText"/>
|
<span class="arangoicon arango-icon-undo queryTooltips" title="Undo" id="undoText"/>
|
||||||
|
|
|
@ -33,49 +33,51 @@ var queryView = Backbone.View.extend({
|
||||||
'keydown #new-query-name': 'listenKey',
|
'keydown #new-query-name': 'listenKey',
|
||||||
'change #queryModalSelect': 'updateEditSelect',
|
'change #queryModalSelect': 'updateEditSelect',
|
||||||
'change #querySelect': 'importSelected',
|
'change #querySelect': 'importSelected',
|
||||||
|
'change #querySize': 'changeSize',
|
||||||
'keypress #aqlEditor': 'aqlShortcuts'
|
'keypress #aqlEditor': 'aqlShortcuts'
|
||||||
},
|
},
|
||||||
|
|
||||||
listenKey: function (e) {
|
listenKey: function (e) {
|
||||||
if (e.keyCode === 13) {
|
if (e.keyCode === 13) {
|
||||||
this.saveAQL(e);
|
this.saveAQL(e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
clearOutput: function () {
|
clearOutput: function () {
|
||||||
var outputEditor = ace.edit("queryOutput");
|
var outputEditor = ace.edit("queryOutput");
|
||||||
outputEditor.setValue('');
|
outputEditor.setValue('');
|
||||||
},
|
},
|
||||||
|
|
||||||
clearInput: function () {
|
clearInput: function () {
|
||||||
var inputEditor = ace.edit("aqlEditor");
|
var inputEditor = ace.edit("aqlEditor");
|
||||||
inputEditor.setValue('');
|
inputEditor.setValue('');
|
||||||
},
|
},
|
||||||
|
|
||||||
smallOutput: function () {
|
smallOutput: function () {
|
||||||
var outputEditor = ace.edit("queryOutput");
|
var outputEditor = ace.edit("queryOutput");
|
||||||
outputEditor.getSession().foldAll();
|
outputEditor.getSession().foldAll();
|
||||||
},
|
},
|
||||||
|
|
||||||
bigOutput: function () {
|
bigOutput: function () {
|
||||||
var outputEditor = ace.edit("queryOutput");
|
var outputEditor = ace.edit("queryOutput");
|
||||||
outputEditor.getSession().unfold();
|
outputEditor.getSession().unfold();
|
||||||
},
|
},
|
||||||
|
|
||||||
aqlShortcuts: function (e) {
|
aqlShortcuts: function (e) {
|
||||||
if (e.ctrlKey && e.keyCode === 13) {
|
if (e.ctrlKey && e.keyCode === 13) {
|
||||||
this.submitQuery();
|
this.submitQuery();
|
||||||
}
|
}
|
||||||
else if (e.metaKey && !e.ctrlKey && e.keyCode === 13) {
|
else if (e.metaKey && ! e.ctrlKey && e.keyCode === 13) {
|
||||||
this.submitQuery();
|
this.submitQuery();
|
||||||
}
|
}
|
||||||
else if (e.ctrlKey && e.keyCode === 90) {
|
else if (e.ctrlKey && e.keyCode === 90) {
|
||||||
this.undoText();
|
// TODO: undo/redo seems to work even without this. check if can be removed
|
||||||
}
|
this.undoText();
|
||||||
else if (e.ctrlKey && e.shiftKey && e.keyCode === 90) {
|
}
|
||||||
this.redeText();
|
else if (e.ctrlKey && e.shiftKey && e.keyCode === 90) {
|
||||||
}
|
// TODO: undo/redo seems to work even without this. check if can be removed
|
||||||
|
this.redoText();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
queries: [
|
queries: [
|
||||||
|
@ -87,6 +89,20 @@ var queryView = Backbone.View.extend({
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
$(this.el).html(this.template.text);
|
$(this.el).html(this.template.text);
|
||||||
|
|
||||||
|
// fill select box with # of results
|
||||||
|
var querySize = 1000;
|
||||||
|
if (typeof Storage) {
|
||||||
|
if (localStorage.getItem("querySize") > 0) {
|
||||||
|
querySize = parseInt(localStorage.getItem("querySize"), 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var sizeBox = $('#querySize');
|
||||||
|
sizeBox.empty();
|
||||||
|
[ 100, 250, 500, 1000, 2500, 5000 ].forEach(function (value) {
|
||||||
|
sizeBox.append('<option value="' + value + '"' + (querySize === value ? ' selected' : '') + '>' + value + ' results</option>');
|
||||||
|
});
|
||||||
|
|
||||||
var outputEditor = ace.edit("queryOutput");
|
var outputEditor = ace.edit("queryOutput");
|
||||||
outputEditor.setReadOnly(true);
|
outputEditor.setReadOnly(true);
|
||||||
|
@ -97,59 +113,59 @@ var queryView = Backbone.View.extend({
|
||||||
var inputEditor = ace.edit("aqlEditor");
|
var inputEditor = ace.edit("aqlEditor");
|
||||||
inputEditor.getSession().setMode("ace/mode/aql");
|
inputEditor.getSession().setMode("ace/mode/aql");
|
||||||
inputEditor.getSession().selection.on('changeCursor', function (e) {
|
inputEditor.getSession().selection.on('changeCursor', function (e) {
|
||||||
var inputEditor = ace.edit("aqlEditor");
|
var inputEditor = ace.edit("aqlEditor");
|
||||||
var session = inputEditor.getSession();
|
var session = inputEditor.getSession();
|
||||||
var cursor = inputEditor.getCursorPosition();
|
var cursor = inputEditor.getCursorPosition();
|
||||||
var token = session.getTokenAt(cursor.row, cursor.column);
|
var token = session.getTokenAt(cursor.row, cursor.column);
|
||||||
if (token) {
|
if (token) {
|
||||||
if (token.type === "comment") {
|
if (token.type === "comment") {
|
||||||
$("#commentText")
|
$("#commentText")
|
||||||
.removeClass("arango-icon-comment")
|
.removeClass("arango-icon-comment")
|
||||||
.addClass("arango-icon-uncomment")
|
.addClass("arango-icon-uncomment")
|
||||||
.attr("data-original-title", "Uncomment");
|
.attr("data-original-title", "Uncomment");
|
||||||
} else {
|
} else {
|
||||||
$("#commentText")
|
$("#commentText")
|
||||||
.addClass("arango-icon-comment")
|
.addClass("arango-icon-comment")
|
||||||
.removeClass("arango-icon-uncomment")
|
.removeClass("arango-icon-uncomment")
|
||||||
.attr("data-original-title", "Comment");
|
.attr("data-original-title", "Comment");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#queryOutput').resizable({
|
$('#queryOutput').resizable({
|
||||||
handles: "s",
|
handles: "s",
|
||||||
ghost: true,
|
ghost: true,
|
||||||
stop: function () {
|
stop: function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var outputEditor = ace.edit("queryOutput");
|
var outputEditor = ace.edit("queryOutput");
|
||||||
outputEditor.resize();
|
outputEditor.resize();
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#aqlEditor').resizable({
|
$('#aqlEditor').resizable({
|
||||||
handles: "s",
|
handles: "s",
|
||||||
ghost: true,
|
ghost: true,
|
||||||
//helper: "resizable-helper",
|
//helper: "resizable-helper",
|
||||||
stop: function () {
|
stop: function () {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
var inputEditor = ace.edit("aqlEditor");
|
var inputEditor = ace.edit("aqlEditor");
|
||||||
inputEditor.resize();
|
inputEditor.resize();
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.queryTooltips').tooltip({
|
$('.queryTooltips').tooltip({
|
||||||
placement: "top"
|
placement: "top"
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#aqlEditor .ace_text-input').focus();
|
$('#aqlEditor .ace_text-input').focus();
|
||||||
$.gritter.removeAll();
|
$.gritter.removeAll();
|
||||||
|
|
||||||
if (typeof Storage) {
|
if (typeof Storage) {
|
||||||
var queryContent = localStorage.getItem("queryContent");
|
var queryContent = localStorage.getItem("queryContent");
|
||||||
var queryOutput = localStorage.getItem("queryOutput");
|
var queryOutput = localStorage.getItem("queryOutput");
|
||||||
inputEditor.setValue(queryContent);
|
inputEditor.setValue(queryContent);
|
||||||
outputEditor.setValue(queryOutput);
|
outputEditor.setValue(queryOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
var windowHeight = $(window).height() - 250;
|
var windowHeight = $(window).height() - 250;
|
||||||
|
@ -340,6 +356,11 @@ var queryView = Backbone.View.extend({
|
||||||
|
|
||||||
this.deselect(ace.edit("aqlEditor"));
|
this.deselect(ace.edit("aqlEditor"));
|
||||||
},
|
},
|
||||||
|
changeSize: function (e) {
|
||||||
|
if (Storage) {
|
||||||
|
localStorage.setItem("querySize", parseInt($('#' + e.currentTarget.id).val(), 10));
|
||||||
|
}
|
||||||
|
},
|
||||||
renderSelectboxes: function (modal) {
|
renderSelectboxes: function (modal) {
|
||||||
this.sortQueries();
|
this.sortQueries();
|
||||||
var selector = '';
|
var selector = '';
|
||||||
|
@ -446,8 +467,12 @@ var queryView = Backbone.View.extend({
|
||||||
},
|
},
|
||||||
submitQuery: function () {
|
submitQuery: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var sizeBox = $('#querySize');
|
||||||
var inputEditor = ace.edit("aqlEditor");
|
var inputEditor = ace.edit("aqlEditor");
|
||||||
var data = {query: inputEditor.getValue()};
|
var data = {
|
||||||
|
query: inputEditor.getValue(),
|
||||||
|
batchSize: parseInt(sizeBox.val(), 10)
|
||||||
|
};
|
||||||
var outputEditor = ace.edit("queryOutput");
|
var outputEditor = ace.edit("queryOutput");
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
|
@ -457,25 +482,25 @@ var queryView = Backbone.View.extend({
|
||||||
contentType: "application/json",
|
contentType: "application/json",
|
||||||
processData: false,
|
processData: false,
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
outputEditor.setValue(arangoHelper.FormatJSON(data.result));
|
outputEditor.setValue(arangoHelper.FormatJSON(data.result));
|
||||||
if (typeof Storage) {
|
if (typeof Storage) {
|
||||||
localStorage.setItem("queryContent", inputEditor.getValue());
|
localStorage.setItem("queryContent", inputEditor.getValue());
|
||||||
localStorage.setItem("queryOutput", outputEditor.getValue());
|
localStorage.setItem("queryOutput", outputEditor.getValue());
|
||||||
}
|
}
|
||||||
self.deselect(outputEditor);
|
self.deselect(outputEditor);
|
||||||
},
|
},
|
||||||
error: function (data) {
|
error: function (data) {
|
||||||
try {
|
try {
|
||||||
var temp = JSON.parse(data.responseText);
|
var temp = JSON.parse(data.responseText);
|
||||||
outputEditor.setValue('[' + temp.errorNum + '] ' + temp.errorMessage);
|
outputEditor.setValue('[' + temp.errorNum + '] ' + temp.errorMessage);
|
||||||
|
|
||||||
if (typeof Storage) {
|
if (typeof Storage) {
|
||||||
localStorage.setItem("queryContent", inputEditor.getValue());
|
localStorage.setItem("queryContent", inputEditor.getValue());
|
||||||
localStorage.setItem("queryOutput", outputEditor.getValue());
|
localStorage.setItem("queryOutput", outputEditor.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
outputEditor.setValue('ERROR');
|
outputEditor.setValue('ERROR');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue