public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][RM3849] Ask to save unsaved query changes stopped working
Date: Mon, 21 Jan 2019 13:24:18 +0530
Message-ID: <CAM9w-_m7Z8tj4VFySfyqj1F+ZEAgd4dnYTjTND4jY8YQEwXovQ@mail.gmail.com> (raw)

Hi Hackers,

Attached is the patch to throw alert warning when user reloads or closes
the browser.

Kindly review.

-- 
Thanks and Regards,
Aditya Toshniwal
Software Engineer | EnterpriseDB Software Solutions | Pune
"Don't Complain about Heat, Plant a tree"


Attachments:

  [application/octet-stream] RM3849.patch (5.0K, 3-RM3849.patch)
  download | inline diff:
diff --git a/web/config.py b/web/config.py
index 5184b323..f81ee4bf 100644
--- a/web/config.py
+++ b/web/config.py
@@ -409,6 +409,12 @@ SUPPORT_SSH_TUNNEL = True
 # Set to False to disable password saving.
 ALLOW_SAVE_TUNNEL_PASSWORD = False
 
+
+##########################################################################
+# Disable alert message when pgAdmin is reloaded or browser is closed
+##########################################################################
+DISABLE_BEFOREUNLOAD_MESSAGE = False
+
 ##########################################################################
 # Local config settings
 ##########################################################################
diff --git a/web/pgadmin/__init__.py b/web/pgadmin/__init__.py
index 1649b2bc..2a96810a 100644
--- a/web/pgadmin/__init__.py
+++ b/web/pgadmin/__init__.py
@@ -190,6 +190,16 @@ def create_app(app_name=None):
         # change operation so we will open the same password change page again.
         config.SECURITY_POST_CHANGE_VIEW = 'browser.change_password'
 
+    # While running test cases,
+    # Set SQLITE_PATH to TEST_SQLITE_PATH
+    # Disable browser reload warning
+    if (
+        'PGADMIN_TESTING_MODE' in os.environ and
+        os.environ['PGADMIN_TESTING_MODE'] == '1'
+    ):
+        config.SQLITE_PATH = config.TEST_SQLITE_PATH
+        config.DISABLE_BEFOREUNLOAD_MESSAGE = True
+
     """Create the Flask application, startup logging and dynamically load
     additional modules (blueprints) that are found in this directory."""
     app = PgAdmin(__name__, static_url_path='/static')
@@ -214,13 +224,6 @@ def create_app(app_name=None):
     logger = logging.getLogger('werkzeug')
     logger.setLevel(logging.INFO)
 
-    # Set SQLITE_PATH to TEST_SQLITE_PATH while running test cases
-    if (
-        'PGADMIN_TESTING_MODE' in os.environ and
-        os.environ['PGADMIN_TESTING_MODE'] == '1'
-    ):
-        config.SQLITE_PATH = config.TEST_SQLITE_PATH
-
     # Ensure the various working directories exist
     from pgadmin.setup import create_app_data_directory, db_upgrade
     create_app_data_directory(config)
diff --git a/web/pgadmin/browser/__init__.py b/web/pgadmin/browser/__init__.py
index b77514e6..f34e5455 100644
--- a/web/pgadmin/browser/__init__.py
+++ b/web/pgadmin/browser/__init__.py
@@ -621,7 +621,8 @@ def utils():
             editor_indent_with_tabs=editor_indent_with_tabs,
             app_name=config.APP_NAME,
             pg_libpq_version=pg_libpq_version,
-            support_ssh_tunnel=config.SUPPORT_SSH_TUNNEL
+            support_ssh_tunnel=config.SUPPORT_SSH_TUNNEL,
+            disable_beforeunload_message=config.DISABLE_BEFOREUNLOAD_MESSAGE,
         ),
         200, {'Content-Type': 'application/x-javascript'})
 
diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js
index cc2ea056..0dc7b5c1 100644
--- a/web/pgadmin/browser/static/js/browser.js
+++ b/web/pgadmin/browser/static/js/browser.js
@@ -1991,10 +1991,17 @@ define('pgadmin.browser', [
     pgAdmin.Browser.editor_shortcut_keys.Tab = 'insertSoftTab';
   }
 
-  $(window).on('beforeunload', function() {
+  $(window).on('beforeunload', function(e) {
     let pref = pgBrowser.get_preference('browser', 'browser_tree_state_save_interval');
     if (!_.isUndefined(pref) && pref.value !== -1)
       pgAdmin.Browser.browserTreeState.save_state();
+
+    if(!pgBrowser.utils.disable_beforeunload_message) {
+      /* This message will not be displayed in Chrome, Firefox, Safari as they have disabled it*/
+      let msg = S(gettext('Are you sure you want to close the %s browser?')).sprintf(pgBrowser.utils.app_name).value();
+      e.originalEvent.returnValue = msg;
+      return msg;
+    }
   });
 
   return pgAdmin.Browser;
diff --git a/web/pgadmin/browser/templates/browser/js/utils.js b/web/pgadmin/browser/templates/browser/js/utils.js
index eac96b14..298c1354 100644
--- a/web/pgadmin/browser/templates/browser/js/utils.js
+++ b/web/pgadmin/browser/templates/browser/js/utils.js
@@ -36,7 +36,7 @@ define('pgadmin.browser.utils',
     app_name: '{{ app_name }}',
     pg_libpq_version: {{pg_libpq_version|e}},
     support_ssh_tunnel: '{{ support_ssh_tunnel }}' == 'True',
-
+    disable_beforeunload_message: '{{disable_beforeunload_message}}' == 'True',
     counter: {total: 0, loaded: 0},
     registerScripts: function (ctx) {
       // There are some scripts which needed to be loaded immediately,
diff --git a/web/setup.py b/web/setup.py
index 194c1e35..b43bd5c1 100644
--- a/web/setup.py
+++ b/web/setup.py
@@ -397,9 +397,14 @@ if __name__ == '__main__':
     args, extra = parser.parse_known_args()
 
     config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION
+
+    # While running test cases,
+    # Set SQLITE_PATH to TEST_SQLITE_PATH
+    # Disable browser reload warning
     if "PGADMIN_TESTING_MODE" in os.environ and \
             os.environ["PGADMIN_TESTING_MODE"] == "1":
         config.SQLITE_PATH = config.TEST_SQLITE_PATH
+        config.DISABLE_BEFOREUNLOAD_MESSAGE = True
 
     # What to do?
     if args.dump_servers is not None:


view thread (11+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][RM3849] Ask to save unsaved query changes stopped working
  In-Reply-To: <CAM9w-_m7Z8tj4VFySfyqj1F+ZEAgd4dnYTjTND4jY8YQEwXovQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox