mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Infrastructure and changes to the Query Tool for realtime preference handling. Refs #3294
Highlights of this patch include: - Changes will affect SQL Editors in Create dialog boxes, SQL tab of the main screen, Query tool, History entries in the query tool, Query tool opened in New Tab/Window - All the components of SQL editor will refer to single source of preferences which is cached in the Browser object. All other redundant ajax get preference calls are removed. - SQL editor will not refer template JS variables anymore, once all the references are removed the template variables will also be removed. - Code refactoring wherever possible. - Covered JS test cases wherever possible.
This commit is contained in:
committed by
Dave Page
parent
82d77c4608
commit
bdb7e3fde2
@@ -8,6 +8,7 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
import $ from 'jquery';
|
||||
import gettext from 'sources/gettext';
|
||||
|
||||
const PERIOD_KEY = 190,
|
||||
FWD_SLASH_KEY = 191,
|
||||
@@ -49,6 +50,52 @@ function isCtrlAltBoth(event) {
|
||||
return event.ctrlKey && event.altKey && !event.shiftKey;
|
||||
}
|
||||
|
||||
/* Returns the key of shortcut */
|
||||
function shortcut_key(shortcut) {
|
||||
let key = '';
|
||||
if(shortcut['key'] && shortcut['key']['char']) {
|
||||
key = shortcut['key']['char'].toUpperCase();
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
/* Converts shortcut object to title representation
|
||||
* Shortcut object is browser.get_preference().value
|
||||
*/
|
||||
function shortcut_title(title, shortcut) {
|
||||
let text_representation = '';
|
||||
|
||||
if (typeof shortcut === 'undefined' || shortcut === null) {
|
||||
return text_representation;
|
||||
}
|
||||
if(shortcut['alt']) {
|
||||
text_representation = gettext('Alt') + '+';
|
||||
}
|
||||
if(shortcut['shift']) {
|
||||
text_representation += gettext('Shift') + '+';
|
||||
}
|
||||
if(shortcut['control']) {
|
||||
text_representation += gettext('Ctrl') + '+';
|
||||
}
|
||||
text_representation += shortcut_key(shortcut);
|
||||
|
||||
return gettext('%(title)s (%(text_representation)s)',{
|
||||
'title': title,
|
||||
'text_representation': text_representation,
|
||||
});
|
||||
}
|
||||
|
||||
/* Returns the key char of shortcut
|
||||
* shortcut object is browser.get_preference().value
|
||||
*/
|
||||
function shortcut_accesskey_title(title, shortcut) {
|
||||
return gettext('%(title)s (accesskey + %(key)s)',{
|
||||
'title': title,
|
||||
'key': shortcut_key(shortcut),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function _stopEventPropagation(event) {
|
||||
event.cancelBubble = true;
|
||||
event.preventDefault();
|
||||
@@ -124,19 +171,19 @@ function getInnerPanel($el, direction) {
|
||||
|
||||
/* Query tool: Keyboard Shortcuts handling */
|
||||
function keyboardShortcutsQueryTool(
|
||||
sqlEditorController, keyboardShortcutConfig, queryToolActions, event
|
||||
sqlEditorController, queryToolActions, event
|
||||
) {
|
||||
if (sqlEditorController.isQueryRunning()) {
|
||||
return;
|
||||
}
|
||||
let keyCode = event.which || event.keyCode, panel_id;
|
||||
let executeKeys = keyboardShortcutConfig['execute'];
|
||||
let explainKeys = keyboardShortcutConfig['explain'];
|
||||
let explainAnalyzeKeys = keyboardShortcutConfig['explain_analyze'];
|
||||
let downloadCsvKeys = keyboardShortcutConfig['download_csv'];
|
||||
let nextPanelKeys = keyboardShortcutConfig['move_next'];
|
||||
let previousPanelKeys = keyboardShortcutConfig['move_previous'];
|
||||
let toggleCaseKeys = keyboardShortcutConfig['toggle_case'];
|
||||
let executeKeys = sqlEditorController.preferences.execute_query;
|
||||
let explainKeys = sqlEditorController.preferences.explain_query;
|
||||
let explainAnalyzeKeys = sqlEditorController.preferences.explain_analyze_query;
|
||||
let downloadCsvKeys = sqlEditorController.preferences.download_csv;
|
||||
let nextPanelKeys = sqlEditorController.preferences.move_next;
|
||||
let previousPanelKeys = sqlEditorController.preferences.move_previous;
|
||||
let toggleCaseKeys = sqlEditorController.preferences.toggle_case;
|
||||
|
||||
if (this.validateShortcutKeys(executeKeys, event)) {
|
||||
this._stopEventPropagation(event);
|
||||
@@ -245,4 +292,7 @@ module.exports = {
|
||||
isAltShiftBoth: isAltShiftBoth,
|
||||
isCtrlShiftBoth: isCtrlShiftBoth,
|
||||
isCtrlAltBoth: isCtrlAltBoth,
|
||||
shortcut_key : shortcut_key,
|
||||
shortcut_title : shortcut_title,
|
||||
shortcut_accesskey_title : shortcut_accesskey_title,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user