mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Refactor keyboard shortcut functions in the query tool. Fix some incorrect keycodes and update docs.
Initial work by Sarah & Violet @ Pivotal, with additional tweaks by Murtuza @ EDB.
This commit is contained in:
@@ -2,10 +2,9 @@ const F5_KEY = 116,
|
||||
F7_KEY = 118,
|
||||
F8_KEY = 119,
|
||||
PERIOD_KEY = 190,
|
||||
FWD_SLASH_KEY = 191,
|
||||
IS_CMD_KEY = window.navigator.platform.search('Mac') != -1;
|
||||
FWD_SLASH_KEY = 191;
|
||||
|
||||
function keyboardShortcuts(sqlEditorController, event) {
|
||||
function keyboardShortcuts(sqlEditorController, queryToolActions, event) {
|
||||
if (sqlEditorController.isQueryRunning()) {
|
||||
return;
|
||||
}
|
||||
@@ -14,28 +13,28 @@ function keyboardShortcuts(sqlEditorController, event) {
|
||||
|
||||
if (keyCode === F5_KEY) {
|
||||
event.preventDefault();
|
||||
sqlEditorController.executeQuery();
|
||||
queryToolActions.executeQuery(sqlEditorController);
|
||||
} else if (event.shiftKey && keyCode === F7_KEY) {
|
||||
_stopEventPropagation();
|
||||
sqlEditorController.explainAnalyze(event);
|
||||
queryToolActions.explainAnalyze(sqlEditorController);
|
||||
} else if (keyCode === F7_KEY) {
|
||||
_stopEventPropagation();
|
||||
sqlEditorController.explain(event);
|
||||
queryToolActions.explain(sqlEditorController);
|
||||
} else if (keyCode === F8_KEY) {
|
||||
event.preventDefault();
|
||||
sqlEditorController.download();
|
||||
} else if (((IS_CMD_KEY && event.metaKey) || (!IS_CMD_KEY && event.ctrlKey)) &&
|
||||
event.shiftKey && keyCode === FWD_SLASH_KEY) {
|
||||
queryToolActions.download(sqlEditorController);
|
||||
} else if (((this.isMac() && event.metaKey) || (!this.isMac() && event.ctrlKey)) &&
|
||||
event.shiftKey && keyCode === FWD_SLASH_KEY) {
|
||||
_stopEventPropagation();
|
||||
sqlEditorController.commentLineCode();
|
||||
} else if (((IS_CMD_KEY && event.metaKey) || (!IS_CMD_KEY && event.ctrlKey)) &&
|
||||
event.shiftKey && keyCode === PERIOD_KEY) {
|
||||
queryToolActions.commentBlockCode(sqlEditorController);
|
||||
} else if (((this.isMac() && event.metaKey) || (!this.isMac() && event.ctrlKey)) &&
|
||||
keyCode === FWD_SLASH_KEY) {
|
||||
_stopEventPropagation();
|
||||
sqlEditorController.uncommentLineCode();
|
||||
} else if (((IS_CMD_KEY && event.metaKey) || (!IS_CMD_KEY && event.ctrlKey)) &&
|
||||
keyCode === FWD_SLASH_KEY) {
|
||||
queryToolActions.commentLineCode(sqlEditorController);
|
||||
} else if (((this.isMac() && event.metaKey) || (!this.isMac() && event.ctrlKey)) &&
|
||||
keyCode === PERIOD_KEY) {
|
||||
_stopEventPropagation();
|
||||
sqlEditorController.commentBlockCode();
|
||||
queryToolActions.uncommentLineCode(sqlEditorController);
|
||||
}
|
||||
|
||||
function _stopEventPropagation() {
|
||||
@@ -46,6 +45,11 @@ function keyboardShortcuts(sqlEditorController, event) {
|
||||
}
|
||||
}
|
||||
|
||||
function isMac() {
|
||||
return window.navigator.platform.search('Mac') != -1;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
processEvent: keyboardShortcuts,
|
||||
isMac: isMac,
|
||||
};
|
||||
|
||||
99
web/pgadmin/static/js/sqleditor/query_tool_actions.js
Normal file
99
web/pgadmin/static/js/sqleditor/query_tool_actions.js
Normal file
@@ -0,0 +1,99 @@
|
||||
import $ from 'jquery';
|
||||
|
||||
let queryToolActions = {
|
||||
_verbose: function () {
|
||||
return $('.explain-verbose').hasClass('visibility-hidden') ? 'OFF' : 'ON';
|
||||
},
|
||||
|
||||
_costsEnabled: function () {
|
||||
return $('.explain-costs').hasClass('visibility-hidden') ? 'OFF' : 'ON';
|
||||
},
|
||||
|
||||
_buffers: function () {
|
||||
return $('.explain-buffers').hasClass('visibility-hidden') ? 'OFF' : 'ON';
|
||||
},
|
||||
|
||||
_timing: function () {
|
||||
return $('.explain-timing').hasClass('visibility-hidden') ? 'OFF' : 'ON';
|
||||
},
|
||||
|
||||
_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();
|
||||
let explainAnalyzeQuery = `EXPLAIN (FORMAT JSON, ANALYZE ON, VERBOSE ${verbose}, COSTS ${costEnabled}, BUFFERS ${buffers}, TIMING ${timing}) `;
|
||||
sqlEditorController.execute(explainAnalyzeQuery);
|
||||
},
|
||||
|
||||
explain: function (sqlEditorController) {
|
||||
let costEnabled = this._costsEnabled();
|
||||
let verbose = this._verbose();
|
||||
|
||||
let explainQuery = `EXPLAIN (FORMAT JSON, ANALYZE OFF, VERBOSE ${verbose}, COSTS ${costEnabled}, BUFFERS OFF, TIMING OFF) `;
|
||||
sqlEditorController.execute(explainQuery);
|
||||
},
|
||||
|
||||
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: '--'}
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = queryToolActions;
|
||||
Reference in New Issue
Block a user