Hi,

please find the attached updated patch.

Thanks,
Khushboo

On Mon, Jul 10, 2017 at 6:54 PM, Dave Page <dp...@pgadmin.org> wrote:

> Hi
>
> On Mon, Jul 10, 2017 at 2:14 PM, Khushboo Vashi <
> khushboo.va...@enterprisedb.com> wrote:
>
>> Hi,
>>
>> Please find the attached patch to fix the RM #1165 - Too many request to
>> update dashboard graphs when server is disconnected.
>>
>
> If I disconnect the server, it doesn't stop trying to get data until I
> refresh the browser by clicking on another node that causes it to reload.
>
> Fixed

> If I then click back on the server node, it doesn't redraw the dashboard
> and start displaying new data upon reconnect. I have to change nodes again
> before it will respond to the re-connection.
>
> Fixed

> Thanks.
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
diff --git a/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js b/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js
index 34a1ab7..1bbe5a4 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(
+                                            '<div class="alert alert-danger pg-panel-message" role="alert">' + gettext('An error occurred whilst loading the dashboard.') + '</div>'
+                                        );
+                                    }
+                                });
+                                $(dashboardPanel).data('server_status', true);
+                            }
 
-                            $.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('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);
+
                     }
                 }
             }

Reply via email to