diff --git a/docs/en_US/images/preferences_browser_display.png b/docs/en_US/images/preferences_browser_display.png index c1e562ae6..bae979821 100644 Binary files a/docs/en_US/images/preferences_browser_display.png and b/docs/en_US/images/preferences_browser_display.png differ diff --git a/docs/en_US/preferences.rst b/docs/en_US/preferences.rst index e547f299c..5bb187b94 100644 --- a/docs/en_US/preferences.rst +++ b/docs/en_US/preferences.rst @@ -18,6 +18,12 @@ Use preferences found in the *Browser* node of the tree control to personalize y Use the fields on the *Display* panel to specify general display preferences: +* When the *Auto-expand sole children* switch is set to *True*, child nodes will be automatically expanded if a treeview node is expanded and has only a single child. + +* Use the *Browser tree state saving interval* field to set the treeview state saving interval. A value of *-1* will disable the treeview state saving functionality. + +* When the *Confirm on close or refresh* switch is set to *True*, pgAdmin will attempt to catch browser close or refresh events and prompt before allowing them to continue. + * When the *Show system objects?* switch is set to *True*, the client will display system objects such as system schemas (for example, *pg_temp*) or system columns (for example, *xmin* or *ctid*) in the tree control. * When the *Enable browser tree animation?* switch is set to *True*, the client will display the animated tree control otherwise it will be unanimated. diff --git a/web/pgadmin/browser/register_browser_preferences.py b/web/pgadmin/browser/register_browser_preferences.py index c7ea81264..c4d86c663 100644 --- a/web/pgadmin/browser/register_browser_preferences.py +++ b/web/pgadmin/browser/register_browser_preferences.py @@ -48,6 +48,16 @@ def register_browser_preferences(self): ) ) + self.preference.register( + 'display', 'auto_expand_sole_children', + gettext("Auto-expand sole children"), 'boolean', True, + category_label=gettext('Display'), + help_str=gettext( + 'If a treeview node is expanded and has only a single ' + 'child, automatically expand the child node as well.' + ) + ) + self.table_row_count_threshold = self.preference.register( 'properties', 'table_row_count_threshold', gettext("Count rows if estimated less than"), 'integer', 2000, diff --git a/web/pgadmin/browser/static/js/node.js b/web/pgadmin/browser/static/js/node.js index 696f8f530..1b03fc252 100644 --- a/web/pgadmin/browser/static/js/node.js +++ b/web/pgadmin/browser/static/js/node.js @@ -999,8 +999,17 @@ define('pgadmin.browser.node', [ }); }, opened: function(item) { + let tree = pgBrowser.tree, + auto_expand = pgBrowser.get_preference('browser', 'auto_expand_sole_children'); + pgBrowser.Events.trigger('pgadmin:browser:tree:update-tree-state', item); + + if (auto_expand && auto_expand.value == true && tree.children(item).length == 1) { + // Automatically expand the child node, if a treeview node has only a single child. + tree.open(tree.first(item)); + } + }, closed: function(item) { pgBrowser.Events.trigger('pgadmin:browser:tree:remove-from-tree-state', diff --git a/web/pgadmin/settings/__init__.py b/web/pgadmin/settings/__init__.py index 930a2d312..6187dcaa1 100644 --- a/web/pgadmin/settings/__init__.py +++ b/web/pgadmin/settings/__init__.py @@ -55,7 +55,8 @@ class SettingsModule(PgAdminModule): """ return [ 'settings.store', 'settings.store_bulk', 'settings.reset_layout', - 'settings.save_tree_state', 'settings.get_tree_state' + 'settings.save_tree_state', 'settings.get_tree_state', + 'settings.reset_tree_state' ] @@ -150,6 +151,24 @@ def reset_layout(): return make_json_response(result=request.form) +@blueprint.route("/reset_tree_state", methods=['DELETE'], endpoint='reset_tree_state') +@login_required +def reset_tree_state(): + """Reset the saved tree state.""" + + data = Setting.query.filter_by(user_id=current_user.id, setting='browser_tree_state').first() + try: + if data is not None: + db.session.delete(data) + db.session.commit() + except Exception as e: + return make_json_response( + status=410, success=0, errormsg=str(e) + ) + + return success_return() + + @blueprint.route("/save_tree_state/", endpoint="save_tree_state", methods=['POST']) @login_required diff --git a/web/pgadmin/static/js/tree/pgadmin_tree_save_state.js b/web/pgadmin/static/js/tree/pgadmin_tree_save_state.js index f835b9f96..597877783 100644 --- a/web/pgadmin/static/js/tree/pgadmin_tree_save_state.js +++ b/web/pgadmin/static/js/tree/pgadmin_tree_save_state.js @@ -69,7 +69,27 @@ _.extend(pgBrowser.browserTreeState, { this.remove_from_cache, this); pgBrowser.Events.on('pgadmin:browser:tree:update-tree-state', this.update_cache, this); + } else { + $.ajax({ + url: url_for('settings.reset_tree_state'), + type: 'DELETE', + }) + .fail(function(jqx) { + var msg = jqx.responseText; + /* Error from the server */ + if (jqx.status == 417 || jqx.status == 410 || jqx.status == 500) { + try { + var data = JSON.parse(jqx.responseText); + msg = data.errormsg; + } catch (e) { + console.warn(e.stack || e); + } + } + console.warn( + gettext('Error resetting the tree saved state."'), msg); + }); } + }, save_state: function() {