Automatically expand child nodes as well as the selected node on the treeview if there is only one. Fixes #3559

This also ensure the browser state is cleared if the save interval is set to -1.
This commit is contained in:
Khushboo Vashi 2019-02-14 09:18:08 +00:00 committed by Dave Page
parent 438116c574
commit 17694ab467
6 changed files with 65 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

After

Width:  |  Height:  |  Size: 243 KiB

View File

@ -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.

View File

@ -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,

View File

@ -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',

View File

@ -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

View File

@ -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() {