mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
[Extendible][Dashboard] Allow to show the dashboard of their choice for
the selected node in the browser tree.
This commit is contained in:
parent
c9e04fec8d
commit
72128df75c
@ -55,73 +55,60 @@ 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;
|
} else {
|
||||||
|
if ('database' in treeHierarchy) {
|
||||||
default:
|
sid = treeHierarchy.server._id;
|
||||||
url = '{{ url_for('dashboard.index') }}'
|
did = treeHierarchy.database._id;
|
||||||
+ treeHierarchy.server._id
|
url += sid + '/' + did;
|
||||||
if ('database' in treeHierarchy) {
|
} else if ('server' in treeHierarchy) {
|
||||||
url += '/' + treeHierarchy.database._id;
|
sid = treeHierarchy.server._id;
|
||||||
}
|
url += sid;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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
|
// Clear out everything so any existing timers die off
|
||||||
else
|
$(div).empty();
|
||||||
sid = treeHierarchy.server._id
|
|
||||||
|
|
||||||
if (_.isUndefined(treeHierarchy.database) || _.isUndefined(treeHierarchy.database._id))
|
$.ajax({
|
||||||
did = -1
|
url: url,
|
||||||
else
|
type: "GET",
|
||||||
did = treeHierarchy.database._id
|
dataType: "html",
|
||||||
|
success: function (data) {
|
||||||
|
$(div).html(data);
|
||||||
|
},
|
||||||
|
error: function (xhr, status) {
|
||||||
|
$(div).html(
|
||||||
|
'<div class="alert alert-danger pg-panel-message" role="alert">{{ gettext('An error occurred whilst loading the dashboard.') }}</div>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (sid != $(dashboardPanel).data('sid') ||
|
// Cache the current IDs for next time
|
||||||
did != $(dashboardPanel).data('did')) {
|
$(dashboardPanel).data('dashboard_url', url);
|
||||||
|
}
|
||||||
// Clear out everything so any existing timers die off
|
|
||||||
$(div).empty();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
url: url,
|
|
||||||
type: "GET",
|
|
||||||
dataType: "html",
|
|
||||||
success: function (data) {
|
|
||||||
$(div).html(data);
|
|
||||||
},
|
|
||||||
error: function (xhr, status) {
|
|
||||||
$(div).html(
|
|
||||||
'<div class="alert alert-danger pg-panel-message" role="alert">{{ gettext('An error occurred whilst loading the dashboard.') }}</div>'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Cache the current IDs for next time
|
|
||||||
$(dashboardPanel).data('sid', sid)
|
|
||||||
$(dashboardPanel).data('did', did)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user