From 38b034ec3c734090156ad97b10d555e752c7c3f7 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Fri, 22 Feb 2019 14:28:05 +0000 Subject: [PATCH] Add Commit and Rollback buttons to the Query Tool. Fixes #2418 --- docs/en_US/query_tool.rst | 206 ++++++++++-------- docs/en_US/release_notes_4_3.rst | 1 + web/pgadmin/static/js/keyboard_shortcuts.js | 14 ++ .../static/js/sqleditor/execute_query.js | 23 ++ .../static/js/sqleditor/query_tool_actions.js | 12 + .../js/sqleditor/query_tool_preferences.js | 8 + .../datagrid/templates/datagrid/index.html | 15 +- web/pgadmin/tools/sqleditor/__init__.py | 4 +- .../tools/sqleditor/static/css/sqleditor.css | 20 ++ .../tools/sqleditor/static/img/commit.svg | 1 + .../tools/sqleditor/static/img/rollback.svg | 1 + .../tools/sqleditor/static/js/sqleditor.js | 40 +++- .../sqleditor/utils/query_tool_preferences.py | 36 +++ .../sqleditor/utils/start_running_query.py | 5 +- .../utils/tests/test_start_running_query.py | 17 +- .../sqleditor/call_render_after_poll_spec.js | 1 + .../sqleditor/execute_query_spec.js | 41 ++++ .../sqleditor/keyboard_shortcuts_spec.js | 92 ++++++++ .../sqleditor/query_tool_actions_spec.js | 26 +++ 19 files changed, 453 insertions(+), 110 deletions(-) create mode 100644 web/pgadmin/tools/sqleditor/static/img/commit.svg create mode 100644 web/pgadmin/tools/sqleditor/static/img/rollback.svg diff --git a/docs/en_US/query_tool.rst b/docs/en_US/query_tool.rst index d0662701b..745f52458 100644 --- a/docs/en_US/query_tool.rst +++ b/docs/en_US/query_tool.rst @@ -49,99 +49,117 @@ icons may support functionality accessed via the :ref:`data editor `. Hover over an icon to display a tooltip that describes the icon's functionality: -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ -| Icon | Behavior | Shortcut | -+======================+===================================================================================================+=============+ -| *Open File* | Click the *Open File* icon to display a previously saved query in the SQL Editor. | | -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ -| *Save* | Click the *Save* icon to perform a quick-save of a previously saved query, or to access the | | -| | *Save* menu: | | -| | | | -| | * Select *Save* to save the selected content of the SQL Editor panel in a file. | | -| | | | -| | * Select *Save As* to open a new browser dialog and specify a new location to which to save the | | -| | selected content of the SQL Editor panel. | | -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ -| *Find* | Use the *Find* menu to search, replace, or navigate the code displayed in the SQL Editor: | | -| | | | -| | * Select *Find* to provide a search target, and search the SQL Editor contents. | Cmd+F | -| | | | -| | * Select *Find next* to locate the next occurrence of the search target. | Cmd+G | -| | | | -| | * Select *Find previous* to move to the last occurrence of the search target. | Cmd+Shift+G | -| | | | -| | * Select *Pesistent find* to identify all occurrences of the search target within the editor. | | -| | | | -| | * Select *Replace* to locate and replace (with prompting) individual occurrences of the target. | Cmd+Shift+F | -| | | | -| | * Select *Replace all* to locate and replace all occurrences of the target within the editor. | | -| | | | -| | * Select *Jump* to navigate to the next occurrence of the search target. | Alt+G | -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ -| *Copy* | Click the *Copy* icon to copy the content that is currently highlighted in the Data Output panel. | | -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ -| *Edit* | Use options on the *Edit* menu to access text editing tools; the options operate on the text | | -| | displayed in the SQL Editor panel: | | -| | | | -| | * Select *Indent Selection* to indent the currently selected text. | Tab | -| | | | -| | * Select *Unindent Selection* to remove indentation from the currently selected text. | Shift+Tab | -| | | | -| | * Select *Inline Comment Selection* to enclose any lines that contain the selection in | Cmd+/ | -| | SQL style comment notation. | | -| | | | -| | * Select *Inline Uncomment Selection* to remove SQL style comment notation from the | Cmd+. | -| | selected line. | | -| | | | -| | * Select *Block Comment* to enclose all lines that contain the selection in C style | Shift+Cmd+/ | -| | comment notation. This option acts as a toggle. | | -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ -| *Execute/Refresh* | Click the *Execute/Refresh* icon to either execute or refresh the query highlighted in the SQL | | -| | editor panel. Click the down arrow to access other execution options: | | -| | | | -| | * Select *Execute/Refresh* to invoke the SQL command and refresh the result set. | F5 | -| | | | -| | * Select *Explain* to view an explanation plan for the current query. The result of the | F7 | -| | EXPLAIN is displayed graphically on the *Explain* tab of the output panel, and in text | | -| | form on the *Data Output* tab. | | -| | | | -| | * Select *Explain analyze* to invoke an EXPLAIN ANALYZE command on the current query. | Shift+F7 | -| | | | -| | * Navigate through the *Explain Options* menu to select options for the EXPLAIN command: | | -| | | | -| | Select *Verbose* to display additional information regarding the query plan. | | -| | | | -| | Select *Costs* to include information on the estimated startup and total cost of each | | -| | plan node, as well as the estimated number of rows and the estimated width of each | | -| | row. | | -| | | | -| | Select *Buffers* to include information on buffer usage. | | -| | | | -| | Select *Timing* to include information about the startup time and the amount of time | | -| | spent in each node of the query. | | -| | | | -| | * Add a check next to *Auto-Rollback* to instruct the server to automatically roll back a | | -| | transaction if an error occurs during the transaction. | | -| | | | -| | * Add a check next to *Auto-Commit* to instruct the server to automatically commit each | | -| | transaction. Any changes made by the transaction will be visible to others, and | | -| | durable in the event of a crash. | | -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ -| *Stop* | Click the *Stop* icon to cancel the execution of the currently running query. | | -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ -| *Clear query window* | Use options on the *Clear* drop-down menu to erase display contents: | | -| | | | -| | * Select *Clear Query Window* to erase the content of the SQL Editor panel. | | -| | | | -| | | | -| | * Select *Explain analyze* to invoke an EXPLAIN ANALYZE command on the current query. | Shift+F7 | -| | | | -| | the SQL editor panel or the *History* tab. | | -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ -| *Download as CSV* | Click the *Download as CSV* icon to download the result set of the current query to a | F8 | -| | comma-separated list. You can specify the CSV settings through | | -| | *Preferences -> SQL Editor -> CSV output* dialogue. | | -+----------------------+---------------------------------------------------------------------------------------------------+-------------+ ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| Icon | Behavior | Shortcut | ++======================+===================================================================================================+================+ +| *Open File* | Click the *Open File* icon to display a previously saved query in the SQL Editor. | Accesskey + O | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Save* | Click the *Save* icon to perform a quick-save of a previously saved query, or to access the | Accesskey + S | +| | *Save* menu: | | +| | | | +| | * Select *Save* to save the selected content of the SQL Editor panel in a file. | | +| | | | +| | * Select *Save As* to open a new browser dialog and specify a new location to which to save the | | +| | selected content of the SQL Editor panel. | | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Find* | Use the *Find* menu to search, replace, or navigate the code displayed in the SQL Editor: | | +| | | | +| | * Select *Find* to provide a search target, and search the SQL Editor contents. | Cmd+F | +| | | | +| | * Select *Find next* to locate the next occurrence of the search target. | Cmd+G | +| | | | +| | * Select *Find previous* to move to the last occurrence of the search target. | Cmd+Shift+G | +| | | | +| | * Select *Pesistent find* to identify all occurrences of the search target within the editor. | | +| | | | +| | * Select *Replace* to locate and replace (with prompting) individual occurrences of the target. | Cmd+Shift+F | +| | | | +| | * Select *Replace all* to locate and replace all occurrences of the target within the editor. | | +| | | | +| | * Select *Jump* to navigate to the next occurrence of the search target. | Alt+G | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Copy* | Click the *Copy* icon to copy the content that is currently highlighted in the Data Output panel. | Accesskey + C | +| | when in View/Edit data mode. | | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Paste* | Click the *Paste* icon to paste a previously row into a new row when in View/Edit data mode. | Accesskey + P | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Delete* | Click the *Delete* icon to delete the selected rows when in View/Edit data mode. | Accesskey + D | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Edit* | Use options on the *Edit* menu to access text editing tools; the options operate on the text | | +| | displayed in the SQL Editor panel when in Query Tool mode: | | +| | | | +| | * Select *Indent Selection* to indent the currently selected text. | Tab | +| | | | +| | * Select *Unindent Selection* to remove indentation from the currently selected text. | Shift+Tab | +| | | | +| | * Select *Inline Comment Selection* to enclose any lines that contain the selection in | Cmd+/ | +| | SQL style comment notation. | | +| | | | +| | * Select *Inline Uncomment Selection* to remove SQL style comment notation from the | Cmd+. | +| | selected line. | | +| | | | +| | * Select *Block Comment* to enclose all lines that contain the selection in C style | Shift+Cmd+/ | +| | comment notation. This option acts as a toggle. | | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Filter* | Click the *Filter* icon to set filtering and sorting criteria for the data when in View/Edit data | Accesskey + F | +| | mode. Click the down arrow to access other filtering and sorting options: | | +| | | | +| | * Click *Sort/Filter* to open the sorting and filtering dialogue. | | +| | | | +| | * Click *Filter by Selection* to show only the rows containing the values in the selected cells. | | +| | | | +| | * Click *Exclude by Selection* to show only the rows that do not contain the values in the | | +| | selected cells. | | +| | | | +| | * Click *Remove Sort/Filter* to remove any previously selected sort or filtering options. | | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| Limit Selector | Select a value in the *Limit Selector* to limit the size of the dataset to a number of rows. | Accesskey + R | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Stop* | Click the *Stop* icon to cancel the execution of the currently running query. | Accesskey + Q | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Execute/Refresh* | Click the *Execute/Refresh* icon to either execute or refresh the query highlighted in the SQL | F5 | +| | editor panel. Click the down arrow to access other execution options: | | +| | | | +| | * Add a check next to *Auto-Rollback* to instruct the server to automatically roll back a | | +| | transaction if an error occurs during the transaction. | | +| | | | +| | * Add a check next to *Auto-Commit* to instruct the server to automatically commit each | | +| | transaction. Any changes made by the transaction will be visible to others, and | | +| | durable in the event of a crash. | | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Explain* | Click the *Explain* icon to view an explanation plan for the current query. The result of the | F7 | +| | EXPLAIN is displayed graphically on the *Explain* tab of the output panel, and in text | | +| | form on the *Data Output* tab. | | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Explain analyze* | Click the *Explain analyze* icon to invoke an EXPLAIN ANALYZE command on the current query. | Shift+F7 | +| | | | +| | Navigate through the *Explain Options* menu to select options for the EXPLAIN command: | | +| | | | +| | * Select *Verbose* to display additional information regarding the query plan. | | +| | | | +| | * Select *Costs* to include information on the estimated startup and total cost of each | | +| | plan node, as well as the estimated number of rows and the estimated width of each | | +| | row. | | +| | | | +| | * Select *Buffers* to include information on buffer usage. | | +| | | | +| | * Select *Timing* to include information about the startup time and the amount of time | | +| | spent in each node of the query. | | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Commit* | Click the *Commit* icon to commit the transaction. | Shift+CTRL+M | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Rollback* | Click the *Rollback* icon to rollback the transaction. | Shift+CTRL+R | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Clear* | Use options on the *Clear* drop-down menu to erase display contents: | Accesskey + L | +| | | | +| | * Select *Clear Query Window* to erase the content of the SQL Editor panel. | | +| | | | +| | * Select *Clear History* to erase the content of the *History* tab. | | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ +| *Download as CSV* | Click the *Download as CSV* icon to download the result set of the current query to a | F8 | +| | comma-separated list. You can specify the CSV settings through | | +| | *Preferences -> SQL Editor -> CSV output* dialogue. | | ++----------------------+---------------------------------------------------------------------------------------------------+----------------+ **The SQL Editor Panel** @@ -267,4 +285,4 @@ Use the *Connection status* feature to view the current connection and transaction status by clicking on the status icon in query tool: .. image:: images/query_tool_connection_status.png - :alt: Query tool connection and transaction statuses \ No newline at end of file + :alt: Query tool connection and transaction statuses diff --git a/docs/en_US/release_notes_4_3.rst b/docs/en_US/release_notes_4_3.rst index 8cecc998e..f9ec68ed5 100644 --- a/docs/en_US/release_notes_4_3.rst +++ b/docs/en_US/release_notes_4_3.rst @@ -11,6 +11,7 @@ Features | `Feature #1825 `_ - Install a script to start pgAdmin (pgadmin4) from the command line when installed from the Python wheel. | `Feature #2233 `_ - Add a "scratch pad" to the Query Tool to hold text snippets whilst editing. +| `Feature #2418 `_ - Add Commit and Rollback buttons to the Query Tool. | `Feature #3439 `_ - Allow X-FRAME-OPTIONS to be set for security. Default to SAMEORIGIN. | `Feature #3559 `_ - Automatically expand child nodes as well as the selected node on the treeview if there is only one. | `Feature #3886 `_ - Include multiple versions of the PG utilties in containers. diff --git a/web/pgadmin/static/js/keyboard_shortcuts.js b/web/pgadmin/static/js/keyboard_shortcuts.js index a5c8e1367..70aab912d 100644 --- a/web/pgadmin/static/js/keyboard_shortcuts.js +++ b/web/pgadmin/static/js/keyboard_shortcuts.js @@ -181,6 +181,8 @@ function keyboardShortcutsQueryTool( let nextPanelKeys = sqlEditorController.preferences.move_next; let previousPanelKeys = sqlEditorController.preferences.move_previous; let toggleCaseKeys = sqlEditorController.preferences.toggle_case; + let commitKeys = sqlEditorController.preferences.commit_transaction; + let rollbackKeys = sqlEditorController.preferences.rollback_transaction; if (this.validateShortcutKeys(executeKeys, event)) { this._stopEventPropagation(event); @@ -197,6 +199,18 @@ function keyboardShortcutsQueryTool( } else if (this.validateShortcutKeys(toggleCaseKeys, event)) { this._stopEventPropagation(event); queryToolActions.toggleCaseOfSelectedText(sqlEditorController); + } else if (this.validateShortcutKeys(commitKeys, event)) { + // If transaction buttons are disabled then no need to execute commit. + if (!sqlEditorController.is_transaction_buttons_disabled) { + this._stopEventPropagation(event); + queryToolActions.executeCommit(sqlEditorController); + } + } else if (this.validateShortcutKeys(rollbackKeys, event)) { + // If transaction buttons are disabled then no need to execute rollback. + if (!sqlEditorController.is_transaction_buttons_disabled) { + this._stopEventPropagation(event); + queryToolActions.executeRollback(sqlEditorController); + } } else if (( (this.isMac() && event.metaKey) || (!this.isMac() && event.ctrlKey) diff --git a/web/pgadmin/static/js/sqleditor/execute_query.js b/web/pgadmin/static/js/sqleditor/execute_query.js index 7ffc45049..8e2a1c4ef 100644 --- a/web/pgadmin/static/js/sqleditor/execute_query.js +++ b/web/pgadmin/static/js/sqleditor/execute_query.js @@ -81,6 +81,12 @@ class ExecuteQuery { } else { self.loadingScreen.hide(); self.enableSQLEditorButtons(); + // Enable/Disable commit and rollback button. + if (result.data.data.transaction_status == 2 || result.data.data.transaction_status == 3) { + self.enableTransactionButtons(); + } else { + self.disableTransactionButtons(); + } self.sqlServerObject.update_msg_history(false, httpMessageData.data.result); if ('notifies' in httpMessageData.data) self.sqlServerObject.update_notifications(httpMessageData.data.notifies); @@ -114,6 +120,13 @@ class ExecuteQuery { }) ).then( (httpMessage) => { + // Enable/Disable commit and rollback button. + if (httpMessage.data.data.transaction_status == 2 || httpMessage.data.data.transaction_status == 3) { + self.enableTransactionButtons(); + } else { + self.disableTransactionButtons(); + } + if (ExecuteQuery.isQueryFinished(httpMessage)) { self.loadingScreen.setMessage('Loading data from the database server and rendering...'); @@ -184,6 +197,7 @@ class ExecuteQuery { this.sqlServerObject.rows_affected = 0; this.sqlServerObject._init_polling_flags(); this.disableSQLEditorButtons(); + this.disableTransactionButtons(); } static prepareAnalyzeSql(sqlStatement, analyzeSql) { @@ -247,6 +261,15 @@ class ExecuteQuery { this.sqlServerObject.disable_tool_buttons(true); } + enableTransactionButtons() { + this.sqlServerObject.disable_transaction_buttons(false); + } + + disableTransactionButtons() { + this.sqlServerObject.special_sql = undefined; + this.sqlServerObject.disable_transaction_buttons(true); + } + static wasConnectionLostToPythonServer(httpResponse) { return _.isUndefined(httpResponse) || _.isUndefined(httpResponse.data); } diff --git a/web/pgadmin/static/js/sqleditor/query_tool_actions.js b/web/pgadmin/static/js/sqleditor/query_tool_actions.js index f82ed9d1b..7739e9b5a 100644 --- a/web/pgadmin/static/js/sqleditor/query_tool_actions.js +++ b/web/pgadmin/static/js/sqleditor/query_tool_actions.js @@ -141,6 +141,18 @@ let queryToolActions = { 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; diff --git a/web/pgadmin/static/js/sqleditor/query_tool_preferences.js b/web/pgadmin/static/js/sqleditor/query_tool_preferences.js index 5b639887a..daeefadd6 100644 --- a/web/pgadmin/static/js/sqleditor/query_tool_preferences.js +++ b/web/pgadmin/static/js/sqleditor/query_tool_preferences.js @@ -97,6 +97,14 @@ function updateUIPreferences(sqlEditor) { .attr('title', shortcut_title('Download as CSV',preferences.download_csv)); + $el.find('#btn-commit') + .attr('title', + shortcut_title('Commit',preferences.commit_transaction)); + + $el.find('#btn-rollback') + .attr('title', + shortcut_title('Rollback',preferences.rollback_transaction)); + /* Set Auto-commit and auto-rollback on query editor */ if (preferences.auto_commit) { $el.find('.auto-commit').removeClass('visibility-hidden'); diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/index.html b/web/pgadmin/tools/datagrid/templates/datagrid/index.html index 5dd0bdcd4..067cd7a26 100644 --- a/web/pgadmin/tools/datagrid/templates/datagrid/index.html +++ b/web/pgadmin/tools/datagrid/templates/datagrid/index.html @@ -218,7 +218,7 @@ tabindex="0" disabled > - + +