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 // Bind the Dashboard object with the 'object_selected' function
var selected = this.object_selected.bind(this); var selected = this.object_selected.bind(this);
var disconnected = this.object_disconnected.bind(this);
// Listen for selection of any of object // Listen for selection of any of object
pgBrowser.Events.on('pgadmin-browser:tree:selected', selected); 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 // Load the default welcome dashboard
url = '{{ url_for('dashboard.index') }}'; 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 // Handle treeview clicks
object_selected: function(item, itemData, node) { object_selected: function(item, itemData, node) {
if (itemData && itemData._type && dashboardVisible) { if (itemData && itemData._type && dashboardVisible) {
@ -89,28 +98,40 @@ function(r, $, pgAdmin, _, Backbone, gettext) {
); );
if (div) { if (div) {
// Avoid unnecessary reloads if (itemData.connected || _.isUndefined(itemData.connected)) {
if (url != $(dashboardPanel).data('dashboard_url')) { // Avoid unnecessary reloads
// Clear out everything so any existing timers die off if (url != $(dashboardPanel).data('dashboard_url') ||
$(div).empty(); (url == $(dashboardPanel).data('dashboard_url') && $(dashboardPanel).data('server_status') == false )) {
// Clear out everything so any existing timers die off
$(div).empty();
$.ajax({ $.ajax({
url: url, url: url,
type: "GET", type: "GET",
dataType: "html", dataType: "html",
success: function (data) { success: function (data) {
$(div).html(data); $(div).html(data);
}, },
error: function (xhr, status) { error: function (xhr, status) {
$(div).html( $(div).html(
'<div class="alert alert-danger pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>' '<div class="alert alert-danger pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>'
); );
} }
}); });
$(dashboardPanel).data('server_status', true);
}
// Cache the current IDs for next time
$(dashboardPanel).data('dashboard_url', url);
} }
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);
} }
} }
} }