Add Commit and Rollback buttons to the Query Tool. Fixes #2418

This commit is contained in:
Akshay Joshi
2019-02-22 14:28:05 +00:00
committed by Dave Page
parent 0766b17726
commit 38b034ec3c
19 changed files with 453 additions and 110 deletions

View File

@@ -218,7 +218,7 @@
tabindex="0" disabled >
<i class="fa fa-stop sql-icon-lg" aria-hidden="true"></i>
</button>
<button id="btn-flash" data-test-selector="execute-refresh-button" type="button" class="btn btn-sm btn-secondary" style="width: 40px;"
<button id="btn-flash" data-test-selector="execute-refresh-button" type="button" class="btn btn-sm btn-secondary" style="width: 32px;"
title=""
tabindex="0">
<i class="fa fa-bolt sql-icon-lg" aria-hidden="true"></i>
@@ -287,6 +287,19 @@
</li>
</ul>
</div>
<div class="btn-group mr-1" role="group" aria-label="">
<button id="btn-commit" type="button" class="btn btn-sm btn-secondary"
title=""
accesskey=""
tabindex="0" disabled>
<i class="icon-commit sql-icon-lg" aria-hidden="true"></i>
</button>
<button id="btn-rollback" type="button" class="btn btn-sm btn-secondary"
title=""
tabindex="0" disabled>
<i class="icon-rollback sql-icon-lg" aria-hidden="true"></i>
</button>
</div>
<div class="btn-group mr-1" role="group" aria-label="">
<button id="btn-clear-dropdown" type="button" class="btn btn-sm btn-secondary dropdown-toggle"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"

View File

@@ -584,6 +584,7 @@ def poll(trans_id):
result is not None and additional_messages:
result = additional_messages + result
transaction_status = conn.transaction_status()
return make_json_response(
data={
'status': status, 'result': result,
@@ -598,7 +599,8 @@ def poll(trans_id):
'types': types,
'client_primary_key': client_primary_key,
'has_oids': has_oids,
'oids': oids
'oids': oids,
'transaction_status': transaction_status,
},
encoding=conn.python_encoding
)

View File

@@ -297,6 +297,26 @@ input.editor-checkbox:focus {
background-image: url('../img/disconnect.svg');
}
.icon-commit, .icon-rollback {
display: inline-block;
align-content: center;
vertical-align: middle;
height: 18px;
width: 18px;
background-size: 22px !important;
background-repeat: no-repeat;
background-position-x: center;
background-position-y: center;
}
.icon-commit {
background-image: url('../img/commit.svg') !important;
}
.icon-rollback {
background-image: url('../img/rollback.svg') !important;
}
.ajs-body .warn-header {
font-size: 13px;
font-weight: bold;

View File

@@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><style>.cls-1{fill:#222222;}</style></defs><title>commit</title><path class="cls-1" d="M51.89,28.51a21.22,21.22,0,0,0-6.3-2.1,45.22,45.22,0,0,0-8.67-.78,45.12,45.12,0,0,0-8.66.78,21.22,21.22,0,0,0-6.3,2.1c-1.54.89-2.32,1.85-2.32,2.88v2.88c0,1,.78,2,2.32,2.88a20.92,20.92,0,0,0,6.3,2.11,46,46,0,0,0,8.66.77,46.07,46.07,0,0,0,8.67-.77,20.92,20.92,0,0,0,6.3-2.11q2.31-1.32,2.31-2.88V31.39Q54.2,29.85,51.89,28.51Z"/><path class="cls-1" d="M36.92,51.56a49.08,49.08,0,0,1-10-1,19.79,19.79,0,0,1-7.32-2.86v3.82c0,1,.78,2,2.32,2.88a20.92,20.92,0,0,0,6.3,2.11,46,46,0,0,0,8.66.77,46.07,46.07,0,0,0,8.67-.77,20.92,20.92,0,0,0,6.3-2.11q2.31-1.32,2.31-2.88V47.74a19.67,19.67,0,0,1-7.31,2.86A49.11,49.11,0,0,1,36.92,51.56Z"/><path class="cls-1" d="M36.92,42.92a49.08,49.08,0,0,1-10-1,19.79,19.79,0,0,1-7.32-2.86v3.82c0,1,.78,2,2.32,2.88a20.92,20.92,0,0,0,6.3,2.11,46,46,0,0,0,8.66.77,46.07,46.07,0,0,0,8.67-.77,20.92,20.92,0,0,0,6.3-2.11q2.31-1.32,2.31-2.88V39.1A19.67,19.67,0,0,1,46.89,42,49.11,49.11,0,0,1,36.92,42.92Z"/><path class="cls-1" d="M25.67,12.44a11.28,11.28,0,0,1,4.23.8,11.13,11.13,0,0,1,3.6,2.28l-3.08,3.1a1.29,1.29,0,0,0-.31,1.56,1.33,1.33,0,0,0,1.32.9H41.51a1.43,1.43,0,0,0,1-.43,1.4,1.4,0,0,0,.42-1V9.56a1.34,1.34,0,0,0-.9-1.33,1.28,1.28,0,0,0-1.55.31l-2.92,2.91a17.34,17.34,0,0,0-5.51-3.52A17,17,0,0,0,19,8.05a19.15,19.15,0,0,0-3,1.6h0c-.43.3-.85.61-1.25.94l-.4.34h0a16.91,16.91,0,0,0-4.49,6,.8.8,0,0,0,0,.53.65.65,0,0,0,.31.39L14,20a.82.82,0,0,0,.6.05.72.72,0,0,0,.42-.4,11.46,11.46,0,0,1,1.12-2.11h0l.39-.54.24-.3c.18-.22.37-.44.57-.65L17.4,16l.45-.44.09-.09c.16-.15.33-.29.5-.43l.27-.2.21-.16a11.84,11.84,0,0,1,2.29-1.28A11.12,11.12,0,0,1,25.67,12.44Z"/></svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><defs><style>.cls-1{fill:#222222;}</style></defs><title>rollback</title><path class="cls-1" d="M53.89,28.51a21.22,21.22,0,0,0-6.3-2.1,45.22,45.22,0,0,0-8.67-.78,45.12,45.12,0,0,0-8.66.78,21.22,21.22,0,0,0-6.3,2.1c-1.54.89-2.32,1.85-2.32,2.88v2.88c0,1,.78,2,2.32,2.88a20.92,20.92,0,0,0,6.3,2.11,46,46,0,0,0,8.66.77,46.07,46.07,0,0,0,8.67-.77,20.92,20.92,0,0,0,6.3-2.11q2.31-1.32,2.31-2.88V31.39Q56.2,29.85,53.89,28.51Z"/><path class="cls-1" d="M38.92,51.56a49.08,49.08,0,0,1-10-1,19.79,19.79,0,0,1-7.32-2.86v3.82c0,1,.78,2,2.32,2.88a20.92,20.92,0,0,0,6.3,2.11,46,46,0,0,0,8.66.77,46.07,46.07,0,0,0,8.67-.77,20.92,20.92,0,0,0,6.3-2.11q2.31-1.32,2.31-2.88V47.74a19.67,19.67,0,0,1-7.31,2.86A49.11,49.11,0,0,1,38.92,51.56Z"/><path class="cls-1" d="M38.92,42.92a49.08,49.08,0,0,1-10-1,19.79,19.79,0,0,1-7.32-2.86v3.82c0,1,.78,2,2.32,2.88a20.92,20.92,0,0,0,6.3,2.11,46,46,0,0,0,8.66.77,46.07,46.07,0,0,0,8.67-.77,20.92,20.92,0,0,0,6.3-2.11q2.31-1.32,2.31-2.88V39.1A19.67,19.67,0,0,1,48.89,42,49.11,49.11,0,0,1,38.92,42.92Z"/><path class="cls-1" d="M25.08,12.44a11.28,11.28,0,0,0-4.23.8,11.13,11.13,0,0,0-3.6,2.28l3.08,3.1a1.29,1.29,0,0,1,.31,1.56,1.33,1.33,0,0,1-1.32.9H9.24a1.43,1.43,0,0,1-1-.43,1.4,1.4,0,0,1-.42-1V9.56a1.34,1.34,0,0,1,.9-1.33,1.28,1.28,0,0,1,1.55.31l2.92,2.91a17.34,17.34,0,0,1,5.51-3.52,17,17,0,0,1,13.1.12,19.15,19.15,0,0,1,3,1.6h0c.43.3.85.61,1.25.94l.4.34h0a16.91,16.91,0,0,1,4.49,6,.8.8,0,0,1,0,.53.65.65,0,0,1-.31.39L36.8,20a.82.82,0,0,1-.6.05.72.72,0,0,1-.42-.4,11.46,11.46,0,0,0-1.12-2.11h0q-.19-.28-.39-.54l-.24-.3c-.18-.22-.37-.44-.57-.65L33.35,16l-.45-.44-.09-.09c-.16-.15-.33-.29-.5-.43l-.27-.2-.21-.16a11.84,11.84,0,0,0-2.29-1.28A11.12,11.12,0,0,0,25.08,12.44Z"/></svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -124,6 +124,8 @@ define('tools.querytool', [
// Indentation options
'click #btn-indent-code': 'on_indent_code',
'click #btn-unindent-code': 'on_unindent_code',
'click #btn-commit': 'on_commit_transaction',
'click #btn-rollback': 'on_rollback_transaction',
},
reflectPreferences: function() {
@@ -1782,6 +1784,15 @@ define('tools.querytool', [
}
}
},
// Callback function for the commit button click.
on_commit_transaction: function() {
queryToolActions.executeCommit(this.handler);
},
// Callback function for the rollback button click.
on_rollback_transaction: function() {
queryToolActions.executeRollback(this.handler);
},
});
/* Defining controller class for data grid, which actually
@@ -3411,6 +3422,15 @@ define('tools.querytool', [
}
},
// This function is used to enable/disable commit/rollback buttons
disable_transaction_buttons: function(disabled) {
this.is_transaction_buttons_disabled = disabled;
if (this.is_query_tool) {
$('#btn-commit').prop('disabled', disabled);
$('#btn-rollback').prop('disabled', disabled);
}
},
// This function will fetch the sql query from the text box
// and execute the query.
execute: function(explain_prefix, shouldReconnect=false) {
@@ -3420,14 +3440,18 @@ define('tools.querytool', [
self.has_more_rows = false;
self.fetching_rows = false;
/* If code is selected in the code mirror then execute
* the selected part else execute the complete code.
*/
var selected_code = self.gridView.query_tool_obj.getSelection();
if (selected_code.length > 0)
sql = selected_code;
else
sql = self.gridView.query_tool_obj.getValue();
if (!_.isUndefined(self.special_sql)) {
sql = self.special_sql;
} else {
/* If code is selected in the code mirror then execute
* the selected part else execute the complete code.
*/
var selected_code = self.gridView.query_tool_obj.getSelection();
if (selected_code.length > 0)
sql = selected_code;
else
sql = self.gridView.query_tool_obj.getValue();
}
const executeQuery = new ExecuteQuery.ExecuteQuery(this, pgAdmin.Browser.UserManagement);
executeQuery.execute(sql, explain_prefix, shouldReconnect);

View File

@@ -571,3 +571,39 @@ def RegisterQueryToolPreferences(self):
help_str=gettext('If set to True, Keywords will be displayed '
'in upper case for auto completion.')
)
self.preference.register(
'keyboard_shortcuts',
'commit_transaction',
gettext('Commit'),
'keyboardshortcut',
{
'alt': False,
'shift': True,
'control': True,
'key': {
'key_code': 77,
'char': 'm'
}
},
category_label=gettext('Keyboard shortcuts'),
fields=shortcut_fields
)
self.preference.register(
'keyboard_shortcuts',
'rollback_transaction',
gettext('Rollback'),
'keyboardshortcut',
{
'alt': False,
'shift': True,
'control': True,
'key': {
'key_code': 82,
'char': 'r'
}
},
category_label=gettext('Keyboard shortcuts'),
fields=shortcut_fields
)

View File

@@ -48,6 +48,7 @@ class StartRunningQuery:
can_edit = False
can_filter = False
notifies = None
trans_status = None
if transaction_object is not None and session_obj is not None:
# set fetched row count to 0 as we are executing query again.
transaction_object.update_fetched_row_cnt(0)
@@ -91,6 +92,7 @@ class StartRunningQuery:
# Get the notifies
notifies = conn.get_notifies()
trans_status = conn.transaction_status()
else:
status = False
result = gettext(
@@ -101,7 +103,8 @@ class StartRunningQuery:
'can_edit': can_edit, 'can_filter': can_filter,
'info_notifier_timeout':
self.blueprint_object.info_notifier_timeout.get(),
'notifies': notifies
'notifies': notifies,
'transaction_status': trans_status,
}
)

View File

@@ -118,7 +118,8 @@ class StartRunningQueryTest(BaseTestGenerator):
can_edit=False,
can_filter=False,
info_notifier_timeout=5,
notifies=None
notifies=None,
transaction_status=None
)
),
expect_internal_server_error_called_with=None,
@@ -278,7 +279,8 @@ class StartRunningQueryTest(BaseTestGenerator):
can_edit=True,
can_filter=True,
info_notifier_timeout=5,
notifies=None
notifies=None,
transaction_status=None
)
),
expect_internal_server_error_called_with=None,
@@ -322,7 +324,8 @@ class StartRunningQueryTest(BaseTestGenerator):
can_edit=True,
can_filter=True,
info_notifier_timeout=5,
notifies=None
notifies=None,
transaction_status=None
)
),
expect_internal_server_error_called_with=None,
@@ -366,7 +369,8 @@ class StartRunningQueryTest(BaseTestGenerator):
can_edit=True,
can_filter=True,
info_notifier_timeout=5,
notifies=None
notifies=None,
transaction_status=None
)
),
expect_internal_server_error_called_with=None,
@@ -411,7 +415,8 @@ class StartRunningQueryTest(BaseTestGenerator):
can_edit=True,
can_filter=True,
info_notifier_timeout=5,
notifies=None
notifies=None,
transaction_status=None
)
),
expect_internal_server_error_called_with=None,
@@ -517,9 +522,11 @@ class StartRunningQueryTest(BaseTestGenerator):
execute_async=MagicMock(),
execute_void=MagicMock(),
get_notifies=MagicMock(),
transaction_status=MagicMock(),
)
self.connection.connect.return_value = self.connection_connect_return
self.connection.get_notifies.return_value = None
self.connection.transaction_status.return_value = None
self.connection.execute_async.return_value = \
self.execute_async_return_value
if self.manager_connection_exception is None: