mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Ensure that browser should warn before close or refresh. Fixes #3849
This commit is contained in:
parent
e27c2c421e
commit
fcfe0929d3
@ -26,6 +26,7 @@ Bug fixes
|
|||||||
| `Bug #3838 <https://redmine.postgresql.org/issues/3838>`_ - Proper SQL should be generated when creating/changing column with custom type argument.
|
| `Bug #3838 <https://redmine.postgresql.org/issues/3838>`_ - Proper SQL should be generated when creating/changing column with custom type argument.
|
||||||
| `Bug #3840 <https://redmine.postgresql.org/issues/3840>`_ - Ensure that file format combo box value should be retained when hidden files checkbox is toggled.
|
| `Bug #3840 <https://redmine.postgresql.org/issues/3840>`_ - Ensure that file format combo box value should be retained when hidden files checkbox is toggled.
|
||||||
| `Bug #3846 <https://redmine.postgresql.org/issues/3846>`_ - Proper SQL should be generated when create procedure with custom type arguments.
|
| `Bug #3846 <https://redmine.postgresql.org/issues/3846>`_ - Proper SQL should be generated when create procedure with custom type arguments.
|
||||||
|
| `Bug #3849 <https://redmine.postgresql.org/issues/3849>`_ - Ensure that browser should warn before close or refresh.
|
||||||
| `Bug #3853 <https://redmine.postgresql.org/issues/3853>`_ - Proper SQL should be generated when create domain of type interval with precision.
|
| `Bug #3853 <https://redmine.postgresql.org/issues/3853>`_ - Proper SQL should be generated when create domain of type interval with precision.
|
||||||
| `Bug #3858 <https://redmine.postgresql.org/issues/3858>`_ - Drop-down should be closed when click on any other toolbar button.
|
| `Bug #3858 <https://redmine.postgresql.org/issues/3858>`_ - Drop-down should be closed when click on any other toolbar button.
|
||||||
| `Bug #3862 <https://redmine.postgresql.org/issues/3862>`_ - Fixed keyboard navigation for dialog tabs.
|
| `Bug #3862 <https://redmine.postgresql.org/issues/3862>`_ - Fixed keyboard navigation for dialog tabs.
|
||||||
|
@ -38,6 +38,16 @@ def register_browser_preferences(self):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.preference.register(
|
||||||
|
'display', 'confirm_on_refresh_close',
|
||||||
|
gettext("Confirm on close or refresh ?"), 'boolean',
|
||||||
|
True, category_label=gettext('Display'),
|
||||||
|
help_str=gettext(
|
||||||
|
'Confirm closure or refresh of the browser or browser tab is '
|
||||||
|
'intended before proceeding.'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self.table_row_count_threshold = self.preference.register(
|
self.table_row_count_threshold = self.preference.register(
|
||||||
'properties', 'table_row_count_threshold',
|
'properties', 'table_row_count_threshold',
|
||||||
gettext("Count rows if estimated less than"), 'integer', 2000,
|
gettext("Count rows if estimated less than"), 'integer', 2000,
|
||||||
|
@ -1991,10 +1991,18 @@ define('pgadmin.browser', [
|
|||||||
pgAdmin.Browser.editor_shortcut_keys.Tab = 'insertSoftTab';
|
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');
|
let tree_save_interval = pgBrowser.get_preference('browser', 'browser_tree_state_save_interval'),
|
||||||
if (!_.isUndefined(pref) && pref.value !== -1)
|
confirm_on_refresh_close = pgBrowser.get_preference('browser', 'confirm_on_refresh_close');
|
||||||
|
if (!_.isUndefined(tree_save_interval) && tree_save_interval.value !== -1)
|
||||||
pgAdmin.Browser.browserTreeState.save_state();
|
pgAdmin.Browser.browserTreeState.save_state();
|
||||||
|
|
||||||
|
if(confirm_on_refresh_close.value) {
|
||||||
|
/* 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;
|
return pgAdmin.Browser;
|
||||||
|
@ -646,58 +646,77 @@ def get_db_server(sid):
|
|||||||
return connection
|
return connection
|
||||||
|
|
||||||
|
|
||||||
def set_preference(default_binary_path):
|
def configure_preferences(default_binary_path=None):
|
||||||
conn = sqlite3.connect(config.TEST_SQLITE_PATH)
|
conn = sqlite3.connect(config.TEST_SQLITE_PATH)
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
perf = Preferences.module('paths')
|
|
||||||
server_types = default_binary_path.keys()
|
|
||||||
|
|
||||||
|
if default_binary_path is not None:
|
||||||
|
paths_pref = Preferences.module('paths')
|
||||||
|
server_types = default_binary_path.keys()
|
||||||
for server in server_types:
|
for server in server_types:
|
||||||
path_pref = perf.preference('{0}_bin_dir'.format(server))
|
pref_bin_path = paths_pref.preference('{0}_bin_dir'.format(server))
|
||||||
user_pref = cur.execute(
|
user_pref = cur.execute(
|
||||||
'SELECT pid, uid FROM user_preferences '
|
'SELECT pid, uid FROM user_preferences '
|
||||||
'where pid=%s' % path_pref.pid
|
'where pid=%s' % pref_bin_path.pid
|
||||||
)
|
)
|
||||||
|
|
||||||
user_pref_data = user_pref.fetchone()
|
user_pref_data = user_pref.fetchone()
|
||||||
if user_pref_data:
|
if user_pref_data:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'UPDATE user_preferences SET value = ? WHERE pid = ?',
|
'UPDATE user_preferences SET value = ? WHERE pid = ?',
|
||||||
(default_binary_path[server], path_pref.pid)
|
(default_binary_path[server], pref_bin_path.pid)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
params = (path_pref.pid, 1, default_binary_path[server])
|
params = (pref_bin_path.pid, 1, default_binary_path[server])
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'INSERT INTO user_preferences(pid, uid, value)'
|
'INSERT INTO user_preferences(pid, uid, value)'
|
||||||
' VALUES (?,?,?)', params
|
' VALUES (?,?,?)', params
|
||||||
)
|
)
|
||||||
|
|
||||||
conn.commit()
|
browser_pref = Preferences.module('browser')
|
||||||
conn.close()
|
|
||||||
|
|
||||||
|
# Disable tree state save for tests
|
||||||
def disable_tree_state_save():
|
pref_tree_state_save_interval = \
|
||||||
conn = sqlite3.connect(config.TEST_SQLITE_PATH)
|
browser_pref.preference('browser_tree_state_save_interval')
|
||||||
cur = conn.cursor()
|
|
||||||
pref = Preferences.module('browser')\
|
|
||||||
.preference('browser_tree_state_save_interval')
|
|
||||||
|
|
||||||
user_pref = cur.execute(
|
user_pref = cur.execute(
|
||||||
'SELECT pid, uid FROM user_preferences '
|
'SELECT pid, uid FROM user_preferences '
|
||||||
'where pid=?', (pref.pid,)
|
'where pid=?', (pref_tree_state_save_interval.pid,)
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(user_pref.fetchall()) == 0:
|
if len(user_pref.fetchall()) == 0:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'INSERT INTO user_preferences(pid, uid, value)'
|
'INSERT INTO user_preferences(pid, uid, value)'
|
||||||
' VALUES (?,?,?)', (pref.pid, 1, -1)
|
' VALUES (?,?,?)', (pref_tree_state_save_interval.pid, 1, -1)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
'UPDATE user_preferences'
|
'UPDATE user_preferences'
|
||||||
' SET VALUE = ?'
|
' SET VALUE = ?'
|
||||||
' WHERE PID = ?', (-1, pref.pid)
|
' WHERE PID = ?', (-1, pref_tree_state_save_interval.pid)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Disable reload warning on browser
|
||||||
|
pref_confirm_on_refresh_close = \
|
||||||
|
browser_pref.preference('confirm_on_refresh_close')
|
||||||
|
|
||||||
|
user_pref = cur.execute(
|
||||||
|
'SELECT pid, uid FROM user_preferences '
|
||||||
|
'where pid=?', (pref_confirm_on_refresh_close.pid,)
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(user_pref.fetchall()) == 0:
|
||||||
|
cur.execute(
|
||||||
|
'INSERT INTO user_preferences(pid, uid, value)'
|
||||||
|
' VALUES (?,?,?)', (pref_confirm_on_refresh_close.pid, 1, 'False')
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
cur.execute(
|
||||||
|
'UPDATE user_preferences'
|
||||||
|
' SET VALUE = ?'
|
||||||
|
' WHERE PID = ?', ('False', pref_confirm_on_refresh_close.pid)
|
||||||
|
)
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
@ -415,12 +415,9 @@ if __name__ == '__main__':
|
|||||||
test_utils.drop_database(connection, test_db_name)
|
test_utils.drop_database(connection, test_db_name)
|
||||||
# Create database
|
# Create database
|
||||||
test_utils.create_database(server, test_db_name)
|
test_utils.create_database(server, test_db_name)
|
||||||
|
# Configure preferences for the test cases
|
||||||
if server['default_binary_paths'] is not None:
|
test_utils.configure_preferences(
|
||||||
test_utils.set_preference(server['default_binary_paths'])
|
default_binary_path=server['default_binary_paths'])
|
||||||
|
|
||||||
# Disable tree state saving
|
|
||||||
test_utils.disable_tree_state_save()
|
|
||||||
|
|
||||||
suite = get_suite(test_module_list,
|
suite = get_suite(test_module_list,
|
||||||
server,
|
server,
|
||||||
|
Loading…
Reference in New Issue
Block a user