public inbox for [email protected]help / color / mirror / Atom feed
[pgAdmin][RM5519]: Unable to close tab after disconnecting server. 4+ messages / 3 participants [nested] [flat]
* [pgAdmin][RM5519]: Unable to close tab after disconnecting server. @ 2021-03-31 14:08 Pradip Parkale <[email protected]> 0 siblings, 1 reply; 4+ messages in thread From: Pradip Parkale @ 2021-03-31 14:08 UTC (permalink / raw) To: pgadmin-hackers Hi Hackers, Please find the attached patch for #5519. Updated the existing confirmation message and also added a new confirmation dialog before closing the query tool if the server is disconnected. -- Thanks & Regards, Pradip Parkale Software Engineer | EnterpriseDB Corporation Attachments: [application/octet-stream] RM5519.patch (5.2K, 3-RM5519.patch) download | inline diff: diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 37cc89c50..de3864be5 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -119,6 +119,7 @@ class SqlEditorModule(PgAdminModule): 'sqleditor.get_new_connection_data', 'sqleditor.get_new_connection_database', 'sqleditor.get_new_connection_user', + 'sqleditor._check_server_connection_status', 'sqleditor.get_new_connection_role', 'sqleditor.connect_server', 'sqleditor.connect_server_with_user', @@ -1479,6 +1480,49 @@ def get_filter_data(trans_id): return FilterDialog.get(status, error_msg, conn, trans_obj, session_ob) [email protected]( + '/get_server_connection/<int:sgid>/<int:sid>', + methods=["GET"], endpoint='_check_server_connection_status' +) +@login_required +def _check_server_connection_status(sgid, sid=None): + """ + This function returns the server connection details + """ + try: + driver = get_driver(PG_DEFAULT_DRIVER) + from pgadmin.browser.server_groups.servers import \ + server_icon_and_background + server = Server.query.filter_by( + id=sid).first() + + manager = driver.connection_manager(server.id) + conn = manager.connection() + connected = conn.connected() + + msg = "Success" + return make_json_response( + data={ + 'status': True, + 'msg': msg, + 'result': { + 'server': connected + } + } + ) + + except Exception: + return make_json_response( + data={ + 'status': False, + 'msg': ERROR_FETCHING_DATA, + 'result': { + 'server': False + } + } + ) + + @blueprint.route( '/new_connection_dialog/<int:sgid>/<int:sid>', methods=["GET"], endpoint='get_new_connection_data' diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index b87051bf7..cf2b0eec4 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -4809,7 +4809,7 @@ define('tools.querytool', [ else if (!ignore_unsaved_query && self.is_query_tool && self.is_query_changed && self.preferences.prompt_save_query_changes) { - msg = gettext('The text has changed. Do you want to save changes?'); + msg = gettext('The query text has changed. Do you want to save changes?'); self.unsaved_changes_user_confirmation(msg, false); } // If a transaction is currently ongoing else if (self.preferences.prompt_commit_transaction @@ -4938,14 +4938,44 @@ define('tools.querytool', [ break; case 1: // Don't Save self.close_on_save = false; - if(this.is_unsaved_data) - self.ignore_on_close.unsaved_data = true; - else - self.ignore_on_close.unsaved_query = true; - // Go back to check for any other needed confirmations before closing - if (!self.check_needed_confirmations_before_closing_panel()){ - closeEvent.cancel = true; - } + $.ajax({ + url: url_for('sqleditor._check_server_connection_status', { + 'sid': self.url_params.sid, + 'sgid': self.url_params.sgid, + }), + headers: { + 'Cache-Control' : 'no-cache', + }, + }).done(function (res) { + let response = res.data.result.server; + if(response){ + closeEvent.cancel = true; + if(this.is_unsaved_data) + self.ignore_on_close.unsaved_data = true; + else + self.ignore_on_close.unsaved_query = true; + // Go back to check for any other needed confirmations before closing + if (!self.check_needed_confirmations_before_closing_panel()){ + closeEvent.cancel = true; + } + }else{ + alertify.confirm( + gettext('Warning'), + gettext('Current trasaction is not commited because server is disconnected.'), + function() { + // Close the query tool if server is disconnected. + setTimeout(() => { self.close(); }, 200); + }, + function() { + return true; + } + ).set('labels', { + ok: gettext('Ok') + }); + } + }).fail(function() { + /* failure should be ignored */ + }); break; case 2: //Save self.close_on_save = true; ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [pgAdmin][RM5519]: Unable to close tab after disconnecting server. @ 2021-03-31 14:23 Dave Page <[email protected]> parent: Pradip Parkale <[email protected]> 0 siblings, 1 reply; 4+ messages in thread From: Dave Page @ 2021-03-31 14:23 UTC (permalink / raw) To: Pradip Parkale <[email protected]>; +Cc: pgadmin-hackers Thanks Pradip. Before this is committed, let's change this: gettext('Current trasaction is not commited because server is disconnected.'), to: gettext('The current transaction has been rolled back because the server was disconnected.'), On Wed, Mar 31, 2021 at 3:09 PM Pradip Parkale < [email protected]> wrote: > Hi Hackers, > Please find the attached patch for #5519. Updated the existing > confirmation message and also added a new confirmation dialog before > closing the query tool if the server is disconnected. > > -- > Thanks & Regards, > Pradip Parkale > Software Engineer | EnterpriseDB Corporation > -- Dave Page Blog: http://pgsnake.blogspot.com Twitter: @pgsnake EDB: http://www.enterprisedb.com ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [pgAdmin][RM5519]: Unable to close tab after disconnecting server. @ 2021-04-01 06:10 Pradip Parkale <[email protected]> parent: Dave Page <[email protected]> 0 siblings, 1 reply; 4+ messages in thread From: Pradip Parkale @ 2021-04-01 06:10 UTC (permalink / raw) To: Dave Page <[email protected]>; +Cc: pgadmin-hackers Hi Hackers, Please find the updated patch with the change mentioned by Dave. On Wed, Mar 31, 2021 at 7:53 PM Dave Page <[email protected]> wrote: > Thanks Pradip. > > Before this is committed, let's change this: > > gettext('Current trasaction is not commited because server is > disconnected.'), > > to: > > gettext('The current transaction has been rolled back because the server > was disconnected.'), > > On Wed, Mar 31, 2021 at 3:09 PM Pradip Parkale < > [email protected]> wrote: > >> Hi Hackers, >> Please find the attached patch for #5519. Updated the existing >> confirmation message and also added a new confirmation dialog before >> closing the query tool if the server is disconnected. >> >> -- >> Thanks & Regards, >> Pradip Parkale >> Software Engineer | EnterpriseDB Corporation >> > > > -- > Dave Page > Blog: http://pgsnake.blogspot.com > Twitter: @pgsnake > > EDB: http://www.enterprisedb.com > > -- Thanks & Regards, Pradip Parkale Software Engineer | EnterpriseDB Corporation Attachments: [application/octet-stream] RM5519_v1.patch (5.2K, 3-RM5519_v1.patch) download | inline diff: diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 37cc89c50..de3864be5 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -119,6 +119,7 @@ class SqlEditorModule(PgAdminModule): 'sqleditor.get_new_connection_data', 'sqleditor.get_new_connection_database', 'sqleditor.get_new_connection_user', + 'sqleditor._check_server_connection_status', 'sqleditor.get_new_connection_role', 'sqleditor.connect_server', 'sqleditor.connect_server_with_user', @@ -1479,6 +1480,49 @@ def get_filter_data(trans_id): return FilterDialog.get(status, error_msg, conn, trans_obj, session_ob) [email protected]( + '/get_server_connection/<int:sgid>/<int:sid>', + methods=["GET"], endpoint='_check_server_connection_status' +) +@login_required +def _check_server_connection_status(sgid, sid=None): + """ + This function returns the server connection details + """ + try: + driver = get_driver(PG_DEFAULT_DRIVER) + from pgadmin.browser.server_groups.servers import \ + server_icon_and_background + server = Server.query.filter_by( + id=sid).first() + + manager = driver.connection_manager(server.id) + conn = manager.connection() + connected = conn.connected() + + msg = "Success" + return make_json_response( + data={ + 'status': True, + 'msg': msg, + 'result': { + 'server': connected + } + } + ) + + except Exception: + return make_json_response( + data={ + 'status': False, + 'msg': ERROR_FETCHING_DATA, + 'result': { + 'server': False + } + } + ) + + @blueprint.route( '/new_connection_dialog/<int:sgid>/<int:sid>', methods=["GET"], endpoint='get_new_connection_data' diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index b87051bf7..b2a964538 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -4809,7 +4809,7 @@ define('tools.querytool', [ else if (!ignore_unsaved_query && self.is_query_tool && self.is_query_changed && self.preferences.prompt_save_query_changes) { - msg = gettext('The text has changed. Do you want to save changes?'); + msg = gettext('The query text has changed. Do you want to save changes?'); self.unsaved_changes_user_confirmation(msg, false); } // If a transaction is currently ongoing else if (self.preferences.prompt_commit_transaction @@ -4938,14 +4938,44 @@ define('tools.querytool', [ break; case 1: // Don't Save self.close_on_save = false; - if(this.is_unsaved_data) - self.ignore_on_close.unsaved_data = true; - else - self.ignore_on_close.unsaved_query = true; - // Go back to check for any other needed confirmations before closing - if (!self.check_needed_confirmations_before_closing_panel()){ - closeEvent.cancel = true; - } + $.ajax({ + url: url_for('sqleditor._check_server_connection_status', { + 'sid': self.url_params.sid, + 'sgid': self.url_params.sgid, + }), + headers: { + 'Cache-Control' : 'no-cache', + }, + }).done(function (res) { + let response = res.data.result.server; + if(response){ + closeEvent.cancel = true; + if(this.is_unsaved_data) + self.ignore_on_close.unsaved_data = true; + else + self.ignore_on_close.unsaved_query = true; + // Go back to check for any other needed confirmations before closing + if (!self.check_needed_confirmations_before_closing_panel()){ + closeEvent.cancel = true; + } + }else{ + alertify.confirm( + gettext('Warning'), + gettext('The current transaction has been rolled back because the server was disconnected'), + function() { + // Close the query tool if server is disconnected. + setTimeout(() => { self.close(); }, 200); + }, + function() { + return true; + } + ).set('labels', { + ok: gettext('Ok') + }); + } + }).fail(function() { + /* failure should be ignored */ + }); break; case 2: //Save self.close_on_save = true; ^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [pgAdmin][RM5519]: Unable to close tab after disconnecting server. @ 2021-04-01 06:44 Akshay Joshi <[email protected]> parent: Pradip Parkale <[email protected]> 0 siblings, 0 replies; 4+ messages in thread From: Akshay Joshi @ 2021-04-01 06:44 UTC (permalink / raw) To: Pradip Parkale <[email protected]>; +Cc: Dave Page <[email protected]>; pgadmin-hackers Thanks, patch applied. On Thu, Apr 1, 2021 at 11:40 AM Pradip Parkale < [email protected]> wrote: > Hi Hackers, > > Please find the updated patch with the change mentioned by Dave. > > On Wed, Mar 31, 2021 at 7:53 PM Dave Page <[email protected]> wrote: > >> Thanks Pradip. >> >> Before this is committed, let's change this: >> >> gettext('Current trasaction is not commited because server is >> disconnected.'), >> >> to: >> >> gettext('The current transaction has been rolled back because the server >> was disconnected.'), >> >> On Wed, Mar 31, 2021 at 3:09 PM Pradip Parkale < >> [email protected]> wrote: >> >>> Hi Hackers, >>> Please find the attached patch for #5519. Updated the existing >>> confirmation message and also added a new confirmation dialog before >>> closing the query tool if the server is disconnected. >>> >>> -- >>> Thanks & Regards, >>> Pradip Parkale >>> Software Engineer | EnterpriseDB Corporation >>> >> >> >> -- >> Dave Page >> Blog: http://pgsnake.blogspot.com >> Twitter: @pgsnake >> >> EDB: http://www.enterprisedb.com >> >> > > -- > Thanks & Regards, > Pradip Parkale > Software Engineer | EnterpriseDB Corporation > -- *Thanks & Regards* *Akshay Joshi* *pgAdmin Hacker | Principal Software Architect* *EDB Postgres <http://edbpostgres.com>* *Mobile: +91 976-788-8246* ^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-04-01 06:44 UTC | newest] Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-03-31 14:08 [pgAdmin][RM5519]: Unable to close tab after disconnecting server. Pradip Parkale <[email protected]> 2021-03-31 14:23 ` Dave Page <[email protected]> 2021-04-01 06:10 ` Pradip Parkale <[email protected]> 2021-04-01 06:44 ` Akshay Joshi <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox