Don't continually poll for graph data on the dashboard if the server is disconnected. Fixes #1165

This commit is contained in:
Khushboo Vashi 2017-07-14 12:42:29 +01:00 committed by Dave Page
parent de06e63334
commit da67963094

View File

@ -22,10 +22,14 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
// Bind the Dashboard object with the 'object_selected' function
var selected = this.object_selected.bind(this);
var disconnected = this.object_disconnected.bind(this);
// Listen for selection of any of object
pgBrowser.Events.on('pgadmin-browser:tree:selected', selected);
// Listen for server disconnected event
pgBrowser.Events.on('pgadmin:server:disconnect', disconnected);
// Load the default welcome dashboard
url = '{{ url_for('dashboard.index') }}';
@ -55,6 +59,11 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
}
},
// Handle Server Disconnect
object_disconnected: function(obj) {
this.object_selected(obj.item, obj.data, pgBrowser.Nodes[obj.data._type]);
},
// Handle treeview clicks
object_selected: function(item, itemData, node) {
if (itemData && itemData._type && dashboardVisible) {
@ -89,8 +98,10 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
);
if (div) {
if (itemData.connected || _.isUndefined(itemData.connected)) {
// Avoid unnecessary reloads
if (url != $(dashboardPanel).data('dashboard_url')) {
if (url != $(dashboardPanel).data('dashboard_url') ||
(url == $(dashboardPanel).data('dashboard_url') && $(dashboardPanel).data('server_status') == false )) {
// Clear out everything so any existing timers die off
$(div).empty();
@ -107,10 +118,20 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
);
}
});
$(dashboardPanel).data('server_status', true);
}
}
else {
$(div).empty();
$(div).html(
'<div class="alert alert-info pg-panel-message" role="alert">' + gettext('Please connect to the selected server to view the dashboard.') + '</div>'
);
$(dashboardPanel).data('server_status', false);
}
// Cache the current IDs for next time
$(dashboardPanel).data('dashboard_url', url);
}
}
}
}