Files
pgadmin4/web/pgadmin/static/js/sqleditor/query_tool_actions.js
Aditya Toshniwal 0340b8fb28 Add EXPLAIN options for SETTINGS and SUMMARY. Fixes #4335
Prevent flickering of large tooltips on the Graphical EXPLAIN canvas. Fixes #4224
EXPLAIN options should be Query Tool instance-specific. Fixes #4395
2019-07-03 13:57:56 +01:00

162 lines
4.4 KiB
JavaScript

/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2019, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import $ from 'jquery';
let queryToolActions = {
_verbose: function () {
return !$('.explain-verbose').hasClass('visibility-hidden');
},
_costsEnabled: function () {
return !$('.explain-costs').hasClass('visibility-hidden');
},
_buffers: function () {
return !$('.explain-buffers').hasClass('visibility-hidden');
},
_timing: function () {
return !$('.explain-timing').hasClass('visibility-hidden');
},
_summary: function () {
return !$('.explain-summary').hasClass('visibility-hidden');
},
_settings: function () {
return !$('.explain-settings').hasClass('visibility-hidden');
},
_clearMessageTab: function () {
$('.sql-editor-message').html('');
},
executeQuery: function (sqlEditorController) {
if(sqlEditorController.is_query_tool) {
this._clearMessageTab();
sqlEditorController.execute();
} else {
this._clearMessageTab();
sqlEditorController.execute_data_query();
}
},
explainAnalyze: function (sqlEditorController) {
const explainObject = {
format: 'json',
analyze: true,
verbose: this._verbose(),
costs: this._costsEnabled(),
buffers: this._buffers(),
timing: this._timing(),
summary: this._summary(),
settings: this._settings(),
};
this._clearMessageTab();
sqlEditorController.execute(explainObject);
},
explain: function (sqlEditorController) {
// let explainQuery = `EXPLAIN (FORMAT JSON, ANALYZE OFF, VERBOSE ${verbose}, COSTS ${costEnabled}, BUFFERS OFF, TIMING OFF) `;
const explainObject = {
format: 'json',
analyze: false,
verbose: this._verbose(),
costs: this._costsEnabled(),
buffers: false,
timing: false,
summary: this._summary(),
settings: this._settings(),
};
this._clearMessageTab();
sqlEditorController.execute(explainObject);
},
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: '--'}
);
},
focusOut: function () {
document.activeElement.blur();
window.top.document.activeElement.blur();
},
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());
}
},
executeCommit: function (sqlEditorController) {
var self = this;
sqlEditorController.special_sql = 'COMMIT;';
self.executeQuery(sqlEditorController);
},
executeRollback: function (sqlEditorController) {
var self = this;
sqlEditorController.special_sql = 'ROLLBACK;';
self.executeQuery(sqlEditorController);
},
};
module.exports = queryToolActions;