diff --git a/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js b/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js index 34a1ab790..1bbe5a4d7 100644 --- a/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js +++ b/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js @@ -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,28 +98,40 @@ function(r, $, pgAdmin, _, Backbone, gettext) { ); if (div) { - // Avoid unnecessary reloads - if (url != $(dashboardPanel).data('dashboard_url')) { - // Clear out everything so any existing timers die off - $(div).empty(); + if (itemData.connected || _.isUndefined(itemData.connected)) { + // Avoid unnecessary reloads + 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(); - $.ajax({ - url: url, - type: "GET", - dataType: "html", - success: function (data) { - $(div).html(data); - }, - error: function (xhr, status) { - $(div).html( - '' - ); - } - }); + $.ajax({ + url: url, + type: "GET", + dataType: "html", + success: function (data) { + $(div).html(data); + }, + error: function (xhr, status) { + $(div).html( + '' + ); + } + }); + $(dashboardPanel).data('server_status', true); + } - // Cache the current IDs for next time - $(dashboardPanel).data('dashboard_url', url); } + else { + $(div).empty(); + $(div).html( + '' + ); + $(dashboardPanel).data('server_status', false); + } + // Cache the current IDs for next time + $(dashboardPanel).data('dashboard_url', url); + } } }