From 008359ad3a38f246755111b257bed4deb8f1bf04 Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Mon, 13 Aug 2018 13:47:07 +0100 Subject: [PATCH] Ensure that refreshing a node also updates the Property list. Fixes #3461 --- docs/en_US/release_notes_3_3.rst | 1 + web/pgadmin/browser/static/js/browser.js | 2 + web/pgadmin/browser/static/js/node.js | 40 +++++-------------- web/pgadmin/misc/depends/static/js/depends.js | 34 ++++++++++++++++ web/pgadmin/misc/sql/static/js/sql.js | 25 ++++++++++++ .../misc/statistics/static/js/statistics.js | 31 ++++++++++++++ 6 files changed, 103 insertions(+), 30 deletions(-) diff --git a/docs/en_US/release_notes_3_3.rst b/docs/en_US/release_notes_3_3.rst index 0ed01af25..a421f4eeb 100644 --- a/docs/en_US/release_notes_3_3.rst +++ b/docs/en_US/release_notes_3_3.rst @@ -16,4 +16,5 @@ Bug fixes ********* | `Bug #3407 `_ - Fix keyboard shortcuts layout in the preferences panel. +| `Bug #3461 `_ - Ensure that refreshing a node also updates the Property list. | `Bug #3528 `_ - Handle connection errors properly in the query tool. diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js index decbd98d0..0f975f88f 100644 --- a/web/pgadmin/browser/static/js/browser.js +++ b/web/pgadmin/browser/static/js/browser.js @@ -1494,6 +1494,8 @@ define('pgadmin.browser', [ isOpen, idx = -1; + this.Events.trigger('pgadmin-browser:tree:refreshing', _i, d, n); + if (!n) { _i = null; ctx.i = null; diff --git a/web/pgadmin/browser/static/js/node.js b/web/pgadmin/browser/static/js/node.js index bef03ae50..24bf30649 100644 --- a/web/pgadmin/browser/static/js/node.js +++ b/web/pgadmin/browser/static/js/node.js @@ -903,34 +903,6 @@ define('pgadmin.browser.node', [ // is active). this.showProperties(item, d, b.panels['properties'].panel); } - if ('sql' in b.panels && - b.panels['sql'] && - b.panels['sql'].panel && - b.panels['sql'].panel.isVisible()) { - // TODO:: Show reverse engineered query for this object (when 'sql' - // tab is active.) - } - if ('statistics' in b.panels && - b.panels['statistics'] && - b.panels['statistics'].panel && - b.panels['statistics'].panel.isVisible()) { - // TODO:: Show statistics for this object (when the 'statistics' - // tab is active.) - } - if ('dependencies' in b.panels && - b.panels['dependencies'] && - b.panels['dependencies'].panel && - b.panels['dependencies'].panel.isVisible()) { - // TODO:: Show dependencies for this object (when the - // 'dependencies' tab is active.) - } - if ('dependents' in b.panels && - b.panels['dependents'] && - b.panels['dependents'].panel && - b.panels['dependents'].panel.isVisible()) { - // TODO:: Show dependents for this object (when the 'dependents' - // tab is active.) - } } return true; @@ -974,9 +946,17 @@ define('pgadmin.browser.node', [ } }, refresh: function(cmd, _item) { + var self = this, + t = pgBrowser.tree, + data = _item && t.itemData(_item); + + $(pgBrowser.panels['properties'].panel).removeData('node-prop'); pgBrowser.Events.trigger( - 'pgadmin:browser:tree:refresh', _item || pgBrowser.tree.selected() - ); + 'pgadmin:browser:tree:refresh', _item || pgBrowser.tree.selected(), { + success: function() { + self.callbacks.selected.apply(self, [_item, data, pgBrowser]); + }, + }); }, }, /********************************************************************** diff --git a/web/pgadmin/misc/depends/static/js/depends.js b/web/pgadmin/misc/depends/static/js/depends.js index 9078e562a..278b33ec0 100644 --- a/web/pgadmin/misc/depends/static/js/depends.js +++ b/web/pgadmin/misc/depends/static/js/depends.js @@ -152,6 +152,7 @@ define('misc.depends', [ // If Dependencies panel exists and is focused then we need to listen the browser tree selection events. if ((dependenciesPanels[0].isVisible()) || dependenciesPanels.length != 1) { pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependencies); + pgBrowser.Events.on('pgadmin-browser:tree:refreshing', this.refreshDependencies, this); } }.bind(this) ); @@ -161,6 +162,7 @@ define('misc.depends', [ // If Dependencies panel exists and is focused then we need to listen the browser tree selection events. if ((dependenciesPanels[0].isVisible()) || dependenciesPanels.length != 1) { pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependencies); + pgBrowser.Events.on('pgadmin-browser:tree:refreshing', this.refreshDependencies, this); } } @@ -174,6 +176,7 @@ define('misc.depends', [ // If Dependents panel exists and is focused then we need to listen the browser tree selection events. if ((dependentsPanels[0].isVisible()) || dependentsPanels.length != 1) { pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependents); + pgBrowser.Events.on('pgadmin-browser:tree:refreshing', this.refreshDependents, this); } }.bind(this) ); @@ -183,6 +186,7 @@ define('misc.depends', [ // If Dependents panel exists and is focused then we need to listen the browser tree selection events. if ((dependentsPanels[0].isVisible()) || dependentsPanels.length != 1) { pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependents); + pgBrowser.Events.on('pgadmin-browser:tree:refreshing', this.refreshDependents, this); } } }, @@ -297,6 +301,19 @@ define('misc.depends', [ $msgContainer.text(msg); } }, + refreshDependents: function(item, data, node) { + var that = this, + cache_flag = { + node_type: data._type, + url: node.generate_url(item, 'dependent', data, true), + }; + + if (_.isEqual($(that.dependentsPanels[0]).data('node-prop'), cache_flag)) { + // Reset the current item selection + $(that.dependentsPanels[0]).data('node-prop', ''); + that.showDependents(item, data, node); + } + }, showDependents: function(item, data, node) { /** * We can't start fetching the Dependents immediately, it is possible the user @@ -333,10 +350,25 @@ define('misc.depends', [ // We will start listening the tree selection event. pgBrowser.Events.on('pgadmin-browser:tree:selected', pgBrowser.ShowNodeDepends.showDependents); + pgBrowser.Events.on('pgadmin-browser:tree:refreshing', pgBrowser.ShowNodeDepends.refreshDependents, this); } else { // We don't need to listen the tree item selection event. pgBrowser.Events.off('pgadmin-browser:tree:selected', pgBrowser.ShowNodeDepends.showDependents); + pgBrowser.Events.off('pgadmin-browser:tree:refreshing', pgBrowser.ShowNodeDepends.refreshDependents, this); + } + }, + refreshDependencies: function(item, data, node) { + var that = this, + cache_flag = { + node_type: data._type, + url: node.generate_url(item, 'dependency', data, true), + }; + + if (_.isEqual($(that.dependenciesPanels[0]).data('node-prop'), cache_flag)) { + // Reset the current item selection + $(that.dependenciesPanels[0]).data('node-prop', ''); + that.showDependencies(item, data, node); } }, showDependencies: function(item, data, node) { @@ -377,9 +409,11 @@ define('misc.depends', [ // We will start listening the tree selection event. pgBrowser.Events.on('pgadmin-browser:tree:selected', pgBrowser.ShowNodeDepends.showDependencies); + pgBrowser.Events.on('pgadmin-browser:tree:refreshing', pgBrowser.ShowNodeDepends.refreshDependencies, this); } else { // We don't need to listen the tree item selection event. pgBrowser.Events.off('pgadmin-browser:tree:selected', pgBrowser.ShowNodeDepends.showDependencies); + pgBrowser.Events.off('pgadmin-browser:tree:refreshing', pgBrowser.ShowNodeDepends.refreshDependencies, this); } }, }); diff --git a/web/pgadmin/misc/sql/static/js/sql.js b/web/pgadmin/misc/sql/static/js/sql.js index 27c7ae552..b067bc1e6 100644 --- a/web/pgadmin/misc/sql/static/js/sql.js +++ b/web/pgadmin/misc/sql/static/js/sql.js @@ -48,15 +48,34 @@ define('misc.sql', [ pgBrowser.Events.on( 'pgadmin-browser:tree:selected', this.showSQL ); + pgBrowser.Events.on( + 'pgadmin-browser:tree:refreshing', this.refreshSQL, this + ); } }.bind(this) ); } else { if ((sqlPanels[0].isVisible()) || sqlPanels.length != 1) { pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showSQL); + pgBrowser.Events.on( + 'pgadmin-browser:tree:refreshing', this.refreshSQL, this + ); } } }, + refreshSQL: function(item, data, node) { + var that = this, + cache_flag = { + node_type: data._type, + url: node.generate_url(item, 'sql', data, true), + }; + + if (_.isEqual($(that.sqlPanels[0]).data('node-prop'), cache_flag)) { + // Reset the current item selection + $(that.sqlPanels[0]).data('node-prop', ''); + that.showSQL(item, data, node); + } + }, showSQL: function(item, data, node) { /** * We can't start fetching the SQL immediately, it is possible - the user @@ -149,9 +168,15 @@ define('misc.sql', [ // We will start listening the tree selection event. pgBrowser.Events.on('pgadmin-browser:tree:selected', pgBrowser.ShowNodeSQL.showSQL); + pgBrowser.Events.on( + 'pgadmin-browser:tree:refreshing', pgBrowser.ShowNodeSQL.refreshSQL, this + ); } else { // We don't need to listen the tree item selection event. pgBrowser.Events.off('pgadmin-browser:tree:selected', pgBrowser.ShowNodeSQL.showSQL); + pgBrowser.Events.off( + 'pgadmin-browser:tree:refreshing', pgBrowser.ShowNodeSQL.refreshSQL, this + ); } }, }); diff --git a/web/pgadmin/misc/statistics/static/js/statistics.js b/web/pgadmin/misc/statistics/static/js/statistics.js index 8a74bf189..4e69788a1 100644 --- a/web/pgadmin/misc/statistics/static/js/statistics.js +++ b/web/pgadmin/misc/statistics/static/js/statistics.js @@ -164,6 +164,9 @@ define('misc.statistics', [ pgBrowser.Events.on( 'pgadmin-browser:tree:selected', this.showStatistics ); + pgBrowser.Events.on( + 'pgadmin-browser:tree:refreshing', this.refreshStatistics, this + ); } }.bind(this) ); @@ -173,12 +176,18 @@ define('misc.statistics', [ pgBrowser.Events.on( 'pgadmin-browser:tree:selected', this.showStatistics ); + pgBrowser.Events.on( + 'pgadmin-browser:tree:refreshing', this.refreshStatistics, this + ); } } if (self.panel.length > 0 && self.panel[0].isVisible()) { pgBrowser.Events.on( 'pgadmin-browser:tree:selected', this.showStatistics ); + pgBrowser.Events.on( + 'pgadmin-browser:tree:refreshing', this.refreshStatistics, this + ); } }, @@ -300,7 +309,19 @@ define('misc.statistics', [ $msgContainer.text(msg); } }, + refreshStatistics: function(item, data, node) { + var that = this, + cache_flag = { + node_type: data._type, + url: node.generate_url(item, 'stats', data, true), + }; + if (_.isEqual($(that.panel[0]).data('node-prop'), cache_flag)) { + // Reset the current item selection + $(that.panel[0]).data('node-prop', ''); + that.showStatistics(item, data, node); + } + }, showStatistics: function(item, data, node) { var self = this; if (!node) { @@ -395,12 +416,22 @@ define('misc.statistics', [ 'pgadmin-browser:tree:selected', pgBrowser.NodeStatistics.showStatistics ); + pgBrowser.Events.on( + 'pgadmin-browser:tree:refreshing', + pgBrowser.NodeStatistics.refreshStatistics, + this + ); } else { // We don't need to listen the tree item selection event. pgBrowser.Events.off( 'pgadmin-browser:tree:selected', pgBrowser.NodeStatistics.showStatistics ); + pgBrowser.Events.off( + 'pgadmin-browser:tree:refreshing', + pgBrowser.NodeStatistics.refreshStatistics, + this + ); } }, });