diff --git a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js index 2d84870..ca0c269 100644 --- a/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js +++ b/web/pgadmin/browser/server_groups/servers/templates/servers/servers.js @@ -237,6 +237,8 @@ function($, _, S, pgAdmin, pgBrowser, alertify) { pgBrowser.serverInfo = pgBrowser.serverInfo || {}; pgBrowser.serverInfo[data._id] = _.extend({}, data); + // Call added method of node.js + pgAdmin.Browser.Node.callbacks.added.apply(this, arguments); return true; }, /* Reload configuration */ diff --git a/web/pgadmin/browser/server_groups/templates/server_groups/server_groups.js b/web/pgadmin/browser/server_groups/templates/server_groups/server_groups.js index 4221280..316b1f7 100644 --- a/web/pgadmin/browser/server_groups/templates/server_groups/server_groups.js +++ b/web/pgadmin/browser/server_groups/templates/server_groups/server_groups.js @@ -10,6 +10,7 @@ function($, _, pgAdmin, Backbone) { label: '{{ _('Server Group') }}', width: '350px', height: '250px', + is_collection: true, Init: function() { /* Avoid multiple registration of menus */ if (this.initialized) diff --git a/web/pgadmin/browser/templates/browser/js/collection.js b/web/pgadmin/browser/templates/browser/js/collection.js index a6c1aab..12c80b7 100644 --- a/web/pgadmin/browser/templates/browser/js/collection.js +++ b/web/pgadmin/browser/templates/browser/js/collection.js @@ -50,6 +50,7 @@ function($, _, S, pgAdmin, Backbone, Alertify, Backform) { } }, hasId: false, + is_collection: true, // A collection will always have a collection of statistics, when the node // it represent will have some statistics. hasCollectiveStatistics: true, diff --git a/web/pgadmin/browser/templates/browser/js/node.js b/web/pgadmin/browser/templates/browser/js/node.js index 494240d..4cc8438 100644 --- a/web/pgadmin/browser/templates/browser/js/node.js +++ b/web/pgadmin/browser/templates/browser/js/node.js @@ -633,6 +633,27 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { this, [undefined, i] ); }, + added: function(item, data, browser) { + var b = browser || pgBrowser, + t = b.tree, + pItem = t.parent(item), + pData = pItem && t.itemData(pItem), + pNode = pData && pgBrowser.Nodes[pData._type]; + + // Check node is a collection or not. + if (pNode && pNode.is_collection) { + /* If 'collection_count' is not present in data + * it means tree node expanded first time, so we will + * kept collection count and label in data itself. + */ + if (!('collection_count' in pData)) { + pData.collection_count = 0; + pData._label = pData.label; + } + pData.collection_count++; + t.setLabel(pItem, {label: (pData._label + ' (' + pData.collection_count + ')')}); + } + }, // Callback called - when a node is selected in browser tree. selected: function(item, data, browser) { // Show the information about the selected node in the below panels, @@ -691,9 +712,34 @@ function($, _, S, pgAdmin, Menu, Backbone, Alertify, pgBrowser, Backform) { return true; }, removed: function(item) { - var self = this; + var self = this, + t = pgBrowser.tree, + pItem = t.parent(item), + pData = pItem && t.itemData(pItem), + pNode = pData && pgBrowser.Nodes[pData._type]; + + // Check node is a collection or not. + if (pNode && pNode.is_collection && + 'collection_count' in pData) + { + pData.collection_count--; + t.setLabel(pItem, {label: (pData._label + ' (' + pData.collection_count + ')')}); + } + setTimeout(function() { self.clear_cache.apply(self, item); }, 0); }, + unloaded: function(item) { + var self = this, + t = pgBrowser.tree, + data = item && t.itemData(item); + + // In case of unload remove the collection counter + if (self.is_collection && 'collection_count' in data) + { + delete data.collection_count; + t.setLabel(item, {label: data._label}); + } + }, refresh: function(n, i) { var self = this, t = pgBrowser.tree,