mirror of https://gitee.com/bigwinds/arangodb
added query result checks in query editor
This commit is contained in:
parent
5c6aa6fbe8
commit
8d1e818d79
|
@ -105,11 +105,12 @@
|
|||
<span class="action"><i class="fa fa-close" element="outputEditor<%= counter %>" style="display: none"></i></span>
|
||||
</div>
|
||||
<div class="pull-right">
|
||||
<% if (type === 'Query') { %>
|
||||
<span class="switchAce" counter="<%=counter%>" style="display: none">Result</span>
|
||||
<% } else { %>
|
||||
<span class="switchAce" counter="<%=counter%>">AQL</span>
|
||||
<% } %>
|
||||
<div class="switchAce" counter="<%=counter%>">
|
||||
<span id="json-switch" val="JSON" counter="<%=counter%>">JSON</span>
|
||||
<span id="table-switch" val="Table" counter="<%=counter%>" style="display: none">Table</span>
|
||||
<span id="graph-switch" val="Graph" counter="<%=counter%>" style="display: none">Graph</span>
|
||||
<span id="aql-switch" val="AQL" counter="<%=counter%>">AQL</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="outputEditor<%= counter %>" style="opacity: 0.5"></div>
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
'click #explainQuery': 'explainQuery',
|
||||
'click #clearQuery': 'clearQuery',
|
||||
'click .outputEditorWrapper #downloadQueryResult': 'downloadQueryResult',
|
||||
'click .outputEditorWrapper .switchAce': 'switchAce',
|
||||
'click .outputEditorWrapper .switchAce span': 'switchAce',
|
||||
'click .outputEditorWrapper .fa-close': 'closeResult',
|
||||
'click #toggleQueries1': 'toggleQueries',
|
||||
'click #toggleQueries2': 'toggleQueries',
|
||||
|
@ -353,15 +353,50 @@
|
|||
},
|
||||
|
||||
switchAce: function (e) {
|
||||
// check if button is disabled
|
||||
var count = $(e.currentTarget).attr('counter');
|
||||
var elem = e.currentTarget;
|
||||
|
||||
if ($(e.currentTarget).text() === 'Result') {
|
||||
$(e.currentTarget).text('AQL');
|
||||
} else {
|
||||
$(e.currentTarget).text('Result');
|
||||
if ($(elem).hasClass('disabled')) {
|
||||
return;
|
||||
}
|
||||
$('#outputEditor' + count).toggle();
|
||||
$('#sentWrapper' + count).toggle();
|
||||
|
||||
_.each($(elem).parent().children(), function (child) {
|
||||
$(child).removeClass('active');
|
||||
});
|
||||
|
||||
var string = $(elem).attr('val');
|
||||
$(elem).addClass('active');
|
||||
$(elem).text(string.charAt(0).toUpperCase() + string.slice(1));
|
||||
|
||||
// refactor this
|
||||
if (string === 'JSON') {
|
||||
$('#outputEditor' + count).show();
|
||||
|
||||
$('#sentWrapper' + count).hide();
|
||||
$('#outputGraph' + count).hide();
|
||||
$('#outputTable' + count).hide();
|
||||
} else if (string === 'AQL') {
|
||||
$('#sentWrapper' + count).show();
|
||||
|
||||
$('#outputEditor' + count).hide();
|
||||
$('#outputGraph' + count).hide();
|
||||
$('#outputTable' + count).hide();
|
||||
} else if (string === 'Table') {
|
||||
$('#outputTable' + count).show();
|
||||
|
||||
$('#outputGraph' + count).hide();
|
||||
$('#outputEditor' + count).hide();
|
||||
$('#sentWrapper' + count).hide();
|
||||
} else if (string === 'Graph') {
|
||||
$('#outputGraph' + count).show();
|
||||
|
||||
$('#outputTable' + count).hide();
|
||||
$('#outputEditor' + count).hide();
|
||||
$('#sentWrapper' + count).hide();
|
||||
}
|
||||
|
||||
// deselect editors
|
||||
this.deselect(ace.edit('outputEditor' + count));
|
||||
this.deselect(ace.edit('sentQueryEditor' + count));
|
||||
this.deselect(ace.edit('sentBindParamEditor' + count));
|
||||
|
@ -1437,6 +1472,23 @@
|
|||
warningsFunc(data);
|
||||
window.progressView.hide();
|
||||
|
||||
var result = self.analyseQuery(data.result);
|
||||
console.log('Using ' + result.defaultType + ' as data format.');
|
||||
if (result.defaultType === 'table') {
|
||||
$('#outputEditorWrapper' + counter).append('<div id="outputTable' + counter + '"></div>');
|
||||
$('#outputTable' + counter).show();
|
||||
|
||||
$('#outputEditor' + counter).hide();
|
||||
} else if (result.defaultType === 'graph') {
|
||||
$('#outputEditorWrapper' + counter).append('<div id="outputGraph' + counter + '"></div>');
|
||||
$('#outputGraph' + counter).show();
|
||||
|
||||
$('#outputEditor' + counter).hide();
|
||||
}
|
||||
|
||||
// add active class to choosen display method
|
||||
$('#' + result.defaultType + '-switch').addClass('active').css('display', 'inline');
|
||||
|
||||
var appendSpan = function (value, icon, css) {
|
||||
if (!css) {
|
||||
css = '';
|
||||
|
@ -1555,6 +1607,108 @@
|
|||
checkQueryStatus();
|
||||
},
|
||||
|
||||
analyseQuery: function (result) {
|
||||
var toReturn = {
|
||||
defaultType: null,
|
||||
original: result,
|
||||
modified: null
|
||||
};
|
||||
|
||||
var found = false;
|
||||
|
||||
// check if result could be displayed as graph
|
||||
// case a) result has keys named vertices and edges
|
||||
if (result[0].vertices && result[0].edges) {
|
||||
var hitsa = 0;
|
||||
var totala = 0;
|
||||
|
||||
_.each(result, function (obj) {
|
||||
if (obj.edges) {
|
||||
totala += obj.edges.length;
|
||||
|
||||
_.each(obj.edges, function (edge) {
|
||||
if (edge._from && edge._to) {
|
||||
hitsa++;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var percentagea = hitsa / totala * 100;
|
||||
|
||||
if (percentagea >= 95) {
|
||||
found = true;
|
||||
toReturn.defaultType = 'graph';
|
||||
}
|
||||
} else {
|
||||
// case b) 95% have _from and _to attribute
|
||||
var hitsb = 0;
|
||||
var totalb = result.length;
|
||||
|
||||
_.each(result, function (obj) {
|
||||
if (obj._from && obj._to) {
|
||||
hitsb++;
|
||||
}
|
||||
});
|
||||
|
||||
var percentageb = hitsb / totalb * 100;
|
||||
|
||||
if (percentageb >= 95) {
|
||||
found = true;
|
||||
toReturn.defaultType = 'graph';
|
||||
// then display as graph
|
||||
}
|
||||
}
|
||||
|
||||
// check if result could be displayed as table
|
||||
if (!found) {
|
||||
var maxAttributeCount = 0;
|
||||
var length;
|
||||
var attributes = {};
|
||||
|
||||
_.each(result, function (obj) {
|
||||
length = _.keys(obj).length;
|
||||
|
||||
if (length > maxAttributeCount) {
|
||||
maxAttributeCount = length;
|
||||
}
|
||||
|
||||
_.each(obj, function (value, key) {
|
||||
if (attributes[key]) {
|
||||
attributes[key] = attributes[key] + 1;
|
||||
} else {
|
||||
attributes[key] = 1;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var rate;
|
||||
var check = true;
|
||||
|
||||
_.each(attributes, function (val, key) {
|
||||
rate = (val / result.length) * 100;
|
||||
|
||||
if (check !== false) {
|
||||
if (rate <= 95) {
|
||||
check = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (check) {
|
||||
found = true;
|
||||
toReturn.defaultType = 'table';
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
// if all check fails, then just display as json
|
||||
toReturn.defaultType = 'json';
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
},
|
||||
|
||||
markPositionError: function (text, pos) {
|
||||
var row;
|
||||
|
||||
|
|
|
@ -365,6 +365,18 @@
|
|||
right: -24px;
|
||||
top: 45px;
|
||||
z-index: 10;
|
||||
|
||||
span {
|
||||
top: 0;
|
||||
|
||||
&.active {
|
||||
color: $c-positive;
|
||||
}
|
||||
|
||||
&.disabled {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ace_editor {
|
||||
|
|
Loading…
Reference in New Issue