Hi Dave, On Tue, Jun 27, 2017 at 8:08 PM, Dave Page <dp...@pgadmin.org> wrote:
> Hi > > I've had to revert this. Whilst it seems to work, after showing/hiding the > dashboard, I later find that when I completely reload the app, it fails, > leaving just the object menu present. I haven't come up with a concrete > case to reproduce it. In the console, I see: > > > wcDocker.min.js:38 Uncaught TypeError: Cannot read property '__save' of > null at e.save (wcDocker.min.js:38) at Object.save_current_layout ( > browser.js:340) at e.handleVisibility (panel.js:156) at e.__trigger ( > wcDocker.min.js:34) at e.trigger (wcDocker.min.js:38) at e.clear ( > wcDocker.min.js:38) at Object.init (browser.js:386) at (index):278 at > Object.execCb (require.min.js:29) at Z.check (require.min.js:18) > > I couldn't reproduce this issue. I have tried many things to reproduce it but not succeeded. I also switched server_mode but no luck. I think there should be any specific condition that fails this but have no clue. I have rebased this patch and attached. > On Tue, Jun 27, 2017 at 9:21 AM, Dave Page <dp...@pgadmin.org> wrote: > >> Thanks, patch applied. >> >> On Tue, Jun 27, 2017 at 2:58 AM, Khushboo Vashi < >> khushboo.va...@enterprisedb.com> wrote: >> >>> Hi, >>> >>> Please find the attached updated patch. >>> >>> Thanks, >>> Khushboo >>> >>> On Mon, Jun 26, 2017 at 5:08 PM, Dave Page <dp...@pgadmin.org> wrote: >>> >>>> Hi >>>> >>>> Looks good, except that when I close the dashboard panel, it continues >>>> to run the queries to update the graphs until I change the selected >>>> treeview node. Can we stop it immediately? >>>> >>>> Fixed >>> >>>> On Mon, Jun 26, 2017 at 1:56 AM, Khushboo Vashi >>>> <khushboo.va...@enterprisedb.com> wrote: >>>> > Hi, >>>> > >>>> > Please find the attached patch for the feature #2506: Allow the >>>> dashboard >>>> > panel to be closed. >>>> > >>>> > Thanks, >>>> > Khushboo >>>> >>>> >>>> >>>> -- >>>> Dave Page >>>> Blog: http://pgsnake.blogspot.com >>>> Twitter: @pgsnake >>>> >>>> EnterpriseDB UK: http://www.enterprisedb.com >>>> The Enterprise PostgreSQL Company >>>> >>> >>> >> >> >> -- >> Dave Page >> Blog: http://pgsnake.blogspot.com >> Twitter: @pgsnake >> >> EnterpriseDB UK: http://www.enterprisedb.com >> The Enterprise PostgreSQL Company >> > > > > -- > Dave Page > Blog: http://pgsnake.blogspot.com > Twitter: @pgsnake > > EnterpriseDB UK: http://www.enterprisedb.com > The Enterprise PostgreSQL Company >
diff --git a/web/pgadmin/browser/static/js/panel.js b/web/pgadmin/browser/static/js/panel.js index 71d2c68..ce21f0d 100644 --- a/web/pgadmin/browser/static/js/panel.js +++ b/web/pgadmin/browser/static/js/panel.js @@ -7,7 +7,8 @@ function(_, pgAdmin) { pgAdmin.Browser.Panel = function(options) { var defaults = [ 'name', 'title', 'width', 'height', 'showTitle', 'isCloseable', - 'isPrivate', 'content', 'icon', 'events', 'onCreate', 'elContainer' + 'isPrivate', 'content', 'icon', 'events', 'onCreate', 'elContainer', + 'canHide', 'limit' ]; _.extend(this, _.pick(options, defaults)); } @@ -25,12 +26,14 @@ function(_, pgAdmin) { panel: null, onCreate: null, elContainer: false, + limit: null, load: function(docker, title) { var that = this; if (!that.panel) { docker.registerPanelType(that.name, { title: that.title, isPrivate: that.isPrivate, + limit: that.limit, onCreate: function(myPanel) { $(myPanel).data('pgAdminName', that.name); myPanel.initSize(that.width, that.height); @@ -85,6 +88,14 @@ function(_, pgAdmin) { }); that.resizedContainer.apply(myPanel); } + + // Bind events only if they are configurable + if (that.canHide) { + _.each([wcDocker.EVENT.CLOSED, wcDocker.EVENT.VISIBILITY_CHANGED], + function(ev) { + myPanel.on(ev, that.handleVisibility.bind(myPanel, ev)); + }); + } } }); } @@ -134,7 +145,32 @@ function(_, pgAdmin) { 100 ); } + }, + handleVisibility: function(eventName) { + // Currently this function only works with dashboard panel but + // as per need it can be extended + if (this._type != 'dashboard') + return; + + if (eventName == 'panelClosed') { + pgBrowser.save_current_layout(pgBrowser); + pgAdmin.Dashboard.toggleVisibility(false); + } + else if (eventName == 'panelVisibilityChanged') { + if (pgBrowser.tree) { + pgBrowser.save_current_layout(pgBrowser); + var selectedNode = pgBrowser.tree.selected(); + // Discontinue this event after first time visible + this.off(wcDocker.EVENT.VISIBILITY_CHANGED); + if (!_.isUndefined(pgAdmin.Dashboard)) + pgAdmin.Dashboard.toggleVisibility(true); + // Explicitly trigger tree selected event when we add the tab. + pgBrowser.Events.trigger('pgadmin-browser:tree:selected', selectedNode, + pgBrowser.tree.itemData(selectedNode), pgBrowser.Node); + } + } } + }); return pgAdmin.Browser.Panel; diff --git a/web/pgadmin/browser/templates/browser/js/browser.js b/web/pgadmin/browser/templates/browser/js/browser.js index e587348..8a3a3b9 100644 --- a/web/pgadmin/browser/templates/browser/js/browser.js +++ b/web/pgadmin/browser/templates/browser/js/browser.js @@ -178,7 +178,9 @@ define( showTitle: {% if panel_item.showTitle %}true{% else %}false{% endif %}, isCloseable: {% if panel_item.isCloseable %}true{% else %}false{% endif %}, isPrivate: {% if panel_item.isPrivate %}true{% else %}false{% endif %}, - content: '{{ panel_item.content }}'{% if panel_item.events is not none %}, + content: '{{ panel_item.content }}', + canHide: {% if panel_item.canHide %}true{% else %}false{% endif %}{% if panel_item.limit is not none %}, + limit: {{ panel_item.limit }}{% endif %}{% if panel_item.events is not none %}, events: {{ panel_item.events }} {% endif %} }){% endif %}{% endfor %} }, @@ -365,15 +367,17 @@ define( // Listen to panel attach/detach event so that last layout will be remembered _.each(obj.panels, function(panel, name) { - panel.panel.on(wcDocker.EVENT.ATTACHED, function() { - obj.save_current_layout(obj); - }); - panel.panel.on(wcDocker.EVENT.DETACHED, function() { - obj.save_current_layout(obj); - }); - panel.panel.on(wcDocker.EVENT.MOVE_ENDED, function() { - obj.save_current_layout(obj); - }); + if (panel.panel) { + panel.panel.on(wcDocker.EVENT.ATTACHED, function() { + obj.save_current_layout(obj); + }); + panel.panel.on(wcDocker.EVENT.DETACHED, function() { + obj.save_current_layout(obj); + }); + panel.panel.on(wcDocker.EVENT.MOVE_ENDED, function() { + obj.save_current_layout(obj); + }); + } }); } diff --git a/web/pgadmin/dashboard/__init__.py b/web/pgadmin/dashboard/__init__.py index a95ba53..8f813d7 100644 --- a/web/pgadmin/dashboard/__init__.py +++ b/web/pgadmin/dashboard/__init__.py @@ -58,9 +58,11 @@ class DashboardModule(PgAdminModule): title=gettext('Dashboard'), icon='fa fa-tachometer', content='', - isCloseable=False, - isPrivate=True, - isIframe=False) + isCloseable=True, + isPrivate=False, + limit=1, + isIframe=False, + canHide=True) ] def register_preferences(self): diff --git a/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js b/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js index 35ed102..34a1ab7 100644 --- a/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js +++ b/web/pgadmin/dashboard/templates/dashboard/js/dashboard.js @@ -11,6 +11,8 @@ function(r, $, pgAdmin, _, Backbone, gettext) { if (pgAdmin.Dashboard) return; + var dashboardVisible = true; + pgAdmin.Dashboard = { init: function() { if (this.initialized) @@ -55,7 +57,7 @@ function(r, $, pgAdmin, _, Backbone, gettext) { // Handle treeview clicks object_selected: function(item, itemData, node) { - if (itemData && itemData._type) { + if (itemData && itemData._type && dashboardVisible) { var treeHierarchy = node.getTreeNodeHierarchy(item), url = '{{ url_for('dashboard.index') }}', sid = -1, did = -1, b = pgAdmin.Browser, @@ -124,6 +126,9 @@ function(r, $, pgAdmin, _, Backbone, gettext) { // { data: [[0, y0], [1, y1]...], label: 'Label 3', [options] } // ] + if (!dashboardVisible) + return; + y = 0; if (dataset.length == 0) { if (counter == true) @@ -862,6 +867,9 @@ function(r, $, pgAdmin, _, Backbone, gettext) { } }); + }, + toggleVisibility: function(flag) { + dashboardVisible = flag; } }; diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/js/datagrid.js b/web/pgadmin/tools/datagrid/templates/datagrid/js/datagrid.js index aa04c2f..bd90ffb 100644 --- a/web/pgadmin/tools/datagrid/templates/datagrid/js/datagrid.js +++ b/web/pgadmin/tools/datagrid/templates/datagrid/js/datagrid.js @@ -379,7 +379,7 @@ define([ newWin.document.title = grid_title; }); } else { - var dashboardPanel = pgBrowser.docker.findPanels('dashboard'); + var dashboardPanel = pgBrowser.docker.findPanels('properites'); var dataGridPanel = pgBrowser.docker.addPanel('frm_datagrid', wcDocker.DOCK.STACKED, dashboardPanel[0]); // Set panel title and icon @@ -495,7 +495,7 @@ define([ /* On successfully initialization find the dashboard panel, * create new panel and add it to the dashboard panel. */ - var dashboardPanel = pgBrowser.docker.findPanels('dashboard'); + var dashboardPanel = pgBrowser.docker.findPanels('properties'); var queryToolPanel = pgBrowser.docker.addPanel('frm_datagrid', wcDocker.DOCK.STACKED, dashboardPanel[0]); // Set panel title and icon diff --git a/web/pgadmin/tools/debugger/templates/debugger/js/debugger_ui.js b/web/pgadmin/tools/debugger/templates/debugger/js/debugger_ui.js index cfbba13..a692ae8 100644 --- a/web/pgadmin/tools/debugger/templates/debugger/js/debugger_ui.js +++ b/web/pgadmin/tools/debugger/templates/debugger/js/debugger_ui.js @@ -562,7 +562,7 @@ define([ }); // Create the debugger panel as per the data received from user input dialog. - var dashboardPanel = pgBrowser.docker.findPanels('dashboard'), + var dashboardPanel = pgBrowser.docker.findPanels('properties'), panel = pgBrowser.docker.addPanel( 'frm_debugger', wcDocker.DOCK.STACKED, dashboardPanel[0] ); diff --git a/web/pgadmin/utils/menu.py b/web/pgadmin/utils/menu.py index 66cb994..a426007 100644 --- a/web/pgadmin/utils/menu.py +++ b/web/pgadmin/utils/menu.py @@ -18,7 +18,7 @@ class MenuItem(object): class Panel(object): def __init__(self, name, title, content='', width=500, height=600, isIframe=True, showTitle=True, isCloseable=True, isPrivate=False, priority=None, - icon=None, data=None, events=None): + icon=None, data=None, events=None, limit=None, canHide=False): self.name = name self.title = title self.content = content @@ -31,6 +31,8 @@ class Panel(object): self.icon = icon self.data = data self.events = events + self.limit = limit + self.canHide = canHide if priority is None: global PRIORITY PRIORITY += 100