2017-08-21 15:27:29 +01:00
|
|
|
import $ from 'jquery';
|
|
|
|
|
|
|
|
|
|
let queryToolActions = {
|
|
|
|
|
_verbose: function () {
|
2018-02-09 11:54:42 +00:00
|
|
|
return !$('.explain-verbose').hasClass('visibility-hidden');
|
2017-08-21 15:27:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_costsEnabled: function () {
|
2018-02-09 11:54:42 +00:00
|
|
|
return !$('.explain-costs').hasClass('visibility-hidden');
|
2017-08-21 15:27:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_buffers: function () {
|
2018-02-09 11:54:42 +00:00
|
|
|
return !$('.explain-buffers').hasClass('visibility-hidden');
|
2017-08-21 15:27:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_timing: function () {
|
2018-02-09 11:54:42 +00:00
|
|
|
return !$('.explain-timing').hasClass('visibility-hidden');
|
2017-08-21 15:27:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_clearMessageTab: function () {
|
|
|
|
|
$('.sql-editor-message').html('');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
executeQuery: function (sqlEditorController) {
|
|
|
|
|
if(sqlEditorController.is_query_tool) {
|
|
|
|
|
this._clearMessageTab();
|
|
|
|
|
sqlEditorController.execute();
|
|
|
|
|
} else {
|
|
|
|
|
sqlEditorController.execute_data_query();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
explainAnalyze: function (sqlEditorController) {
|
|
|
|
|
let costEnabled = this._costsEnabled();
|
|
|
|
|
let verbose = this._verbose();
|
|
|
|
|
let buffers = this._buffers();
|
|
|
|
|
let timing = this._timing();
|
2018-02-09 11:54:42 +00:00
|
|
|
const explainObject = {
|
|
|
|
|
format: 'json',
|
|
|
|
|
analyze: true,
|
|
|
|
|
verbose: verbose,
|
|
|
|
|
costs: costEnabled,
|
|
|
|
|
buffers: buffers,
|
|
|
|
|
timing: timing,
|
|
|
|
|
summary: false,
|
|
|
|
|
};
|
2018-01-03 15:19:56 +00:00
|
|
|
this._clearMessageTab();
|
2018-02-09 11:54:42 +00:00
|
|
|
sqlEditorController.execute(explainObject);
|
2017-08-21 15:27:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
explain: function (sqlEditorController) {
|
|
|
|
|
let costEnabled = this._costsEnabled();
|
|
|
|
|
let verbose = this._verbose();
|
|
|
|
|
|
2018-02-09 11:54:42 +00:00
|
|
|
// let explainQuery = `EXPLAIN (FORMAT JSON, ANALYZE OFF, VERBOSE ${verbose}, COSTS ${costEnabled}, BUFFERS OFF, TIMING OFF) `;
|
|
|
|
|
const explainObject = {
|
|
|
|
|
format: 'json',
|
|
|
|
|
analyze: false,
|
|
|
|
|
verbose: verbose,
|
|
|
|
|
costs: costEnabled,
|
|
|
|
|
buffers: false,
|
|
|
|
|
timing: false,
|
|
|
|
|
summary: false,
|
|
|
|
|
};
|
2018-01-03 15:19:56 +00:00
|
|
|
this._clearMessageTab();
|
2018-02-09 11:54:42 +00:00
|
|
|
sqlEditorController.execute(explainObject);
|
2017-08-21 15:27:29 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
download: function (sqlEditorController) {
|
|
|
|
|
let sqlQuery = sqlEditorController.gridView.query_tool_obj.getSelection();
|
|
|
|
|
|
|
|
|
|
if (!sqlQuery) {
|
|
|
|
|
sqlQuery = sqlEditorController.gridView.query_tool_obj.getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!sqlQuery) return;
|
|
|
|
|
|
|
|
|
|
let filename = 'data-' + new Date().getTime() + '.csv';
|
|
|
|
|
|
|
|
|
|
if (!sqlEditorController.is_query_tool) {
|
|
|
|
|
filename = sqlEditorController.table_name + '.csv';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sqlEditorController.trigger_csv_download(sqlQuery, filename);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
commentBlockCode: function (sqlEditorController) {
|
|
|
|
|
let codeMirrorObj = sqlEditorController.gridView.query_tool_obj;
|
|
|
|
|
|
|
|
|
|
if (!codeMirrorObj.getValue()) return;
|
|
|
|
|
|
|
|
|
|
codeMirrorObj.toggleComment(codeMirrorObj.getCursor(true), codeMirrorObj.getCursor(false));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
commentLineCode: function (sqlEditorController) {
|
|
|
|
|
let codeMirrorObj = sqlEditorController.gridView.query_tool_obj;
|
|
|
|
|
|
|
|
|
|
if (!codeMirrorObj.getValue()) return;
|
|
|
|
|
|
|
|
|
|
codeMirrorObj.lineComment(codeMirrorObj.getCursor(true),
|
|
|
|
|
codeMirrorObj.getCursor(false),
|
|
|
|
|
{lineComment: '--'}
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
uncommentLineCode: function (sqlEditorController) {
|
|
|
|
|
let codeMirrorObj = sqlEditorController.gridView.query_tool_obj;
|
|
|
|
|
|
|
|
|
|
if (!codeMirrorObj.getValue()) return;
|
|
|
|
|
|
|
|
|
|
codeMirrorObj.uncomment(codeMirrorObj.getCursor(true),
|
|
|
|
|
codeMirrorObj.getCursor(false),
|
|
|
|
|
{lineComment: '--'}
|
|
|
|
|
);
|
|
|
|
|
},
|
2018-02-02 14:28:37 +01:00
|
|
|
|
2018-02-27 14:32:03 +00:00
|
|
|
focusOut: function () {
|
2018-02-02 14:28:37 +01:00
|
|
|
document.activeElement.blur();
|
|
|
|
|
window.top.document.activeElement.blur();
|
|
|
|
|
},
|
2018-02-27 14:32:03 +00:00
|
|
|
|
2018-06-15 10:18:56 +01:00
|
|
|
toggleCaseOfSelectedText: function (sqlEditorController) {
|
|
|
|
|
let codeMirrorObj = sqlEditorController.gridView.query_tool_obj;
|
|
|
|
|
let selectedText = codeMirrorObj.getSelection();
|
|
|
|
|
|
|
|
|
|
if (!selectedText) return;
|
|
|
|
|
|
|
|
|
|
if (selectedText === selectedText.toUpperCase()) {
|
|
|
|
|
codeMirrorObj.replaceSelection(selectedText.toLowerCase());
|
|
|
|
|
} else {
|
|
|
|
|
codeMirrorObj.replaceSelection(selectedText.toUpperCase());
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-08-21 15:27:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = queryToolActions;
|