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 authored and Dave Page committed 2019-02-14 09:18:08 +00:00
1 parent 438116c574
commit 17694ab467
6 files changed
+65 -1

No files matched your search

@@ -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,
+9
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',
+20 -1
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
@@ -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() {