[Extendible][Dashboard] Allow to show the dashboard of their choice for

the selected node in the browser tree.
This commit is contained in:
Ashesh Vashi 2017-03-20 19:17:42 +05:30
parent c9e04fec8d
commit 72128df75c

View File

@ -55,53 +55,40 @@ function(r, $, pgAdmin, _, Backbone) {
// Handle treeview clicks // Handle treeview clicks
object_selected: function(item, itemData, node) { object_selected: function(item, itemData, node) {
var treeHierarchy = node.getTreeNodeHierarchy(item) if (itemData && itemData._type) {
if (itemData && itemData._type) var treeHierarchy = node.getTreeNodeHierarchy(item),
{ url = '{{ url_for('dashboard.index') }}',
switch(itemData._type) { sid = -1, did = -1, b = pgAdmin.Browser,
case ('server-group'): m = b && b.Nodes[itemData._type];
url = '{{ url_for('dashboard.index') }}';
break;
case ('server'): if (m && m.dashboard) {
case ('coll-database'): if (_.isFunction(m.dashboard)) {
case ('coll-role'): url = m.dashboard.apply(
case ('role'): item, itemData, node, treeHierarchy
case ('coll-tablespace'): );
case ('tablespace'): } else {
url = '{{ url_for('dashboard.index') }}' url = m.dashboard;
+ treeHierarchy.server._id;
break;
default:
url = '{{ url_for('dashboard.index') }}'
+ treeHierarchy.server._id
if ('database' in treeHierarchy) {
url += '/' + treeHierarchy.database._id;
} }
break; } else {
if ('database' in treeHierarchy) {
sid = treeHierarchy.server._id;
did = treeHierarchy.database._id;
url += sid + '/' + did;
} else if ('server' in treeHierarchy) {
sid = treeHierarchy.server._id;
url += sid;
} }
} }
var dashboardPanel = pgBrowser.panels['dashboard'].panel; var dashboardPanel = pgBrowser.panels['dashboard'].panel;
if (dashboardPanel) { if (dashboardPanel) {
var div = dashboardPanel.layout().scene().find('.pg-panel-content'); var div = dashboardPanel.layout().scene().find(
'.pg-panel-content'
);
if (div) { if (div) {
// Avoid unnecessary reloads // Avoid unnecessary reloads
if (_.isUndefined(treeHierarchy.server) || _.isUndefined(treeHierarchy.server._id)) if (url != $(dashboardPanel).data('dashboard_url')) {
sid = -1
else
sid = treeHierarchy.server._id
if (_.isUndefined(treeHierarchy.database) || _.isUndefined(treeHierarchy.database._id))
did = -1
else
did = treeHierarchy.database._id
if (sid != $(dashboardPanel).data('sid') ||
did != $(dashboardPanel).data('did')) {
// Clear out everything so any existing timers die off // Clear out everything so any existing timers die off
$(div).empty(); $(div).empty();
@ -120,8 +107,8 @@ function(r, $, pgAdmin, _, Backbone) {
}); });
// Cache the current IDs for next time // Cache the current IDs for next time
$(dashboardPanel).data('sid', sid) $(dashboardPanel).data('dashboard_url', url);
$(dashboardPanel).data('did', did) }
} }
} }
} }