Updated the misc module javascripts to work with latest wcDocker.

This commit is contained in:
Neel Patel 2016-02-29 19:34:06 +05:30 committed by Ashesh Vashi
parent 18d767b107
commit 000c76871f
2 changed files with 79 additions and 21 deletions

View File

@ -25,26 +25,12 @@ define(
'showDependencies', 'dependenciesPanelVisibilityChanged', '__updateCollection' 'showDependencies', 'dependenciesPanelVisibilityChanged', '__updateCollection'
); );
// Find the panels to render the grid.
var dependenciesPanels = this.dependenciesPanels = pgBrowser.docker.findPanels('dependencies');
var dependentsPanels = this.dependentsPanels = pgBrowser.docker.findPanels('dependents');
// We will listened to the visibility change of the Dependencies and Dependents panel // We will listened to the visibility change of the Dependencies and Dependents panel
pgBrowser.Events.on('pgadmin-browser:panel-dependencies:' + wcDocker.EVENT.VISIBILITY_CHANGED, pgBrowser.Events.on('pgadmin-browser:panel-dependencies:' + wcDocker.EVENT.VISIBILITY_CHANGED,
this.dependenciesPanelVisibilityChanged); this.dependenciesPanelVisibilityChanged);
pgBrowser.Events.on('pgadmin-browser:panel-dependents:' + wcDocker.EVENT.VISIBILITY_CHANGED, pgBrowser.Events.on('pgadmin-browser:panel-dependents:' + wcDocker.EVENT.VISIBILITY_CHANGED,
this.dependentsPanelVisibilityChanged); this.dependentsPanelVisibilityChanged);
// If Dependencies panel exists and is focused then we need to listen the browser tree selection events.
if ((dependenciesPanels.length == 1 && dependenciesPanels[0].isVisible()) || dependenciesPanels.length != 1) {
pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependencies);
}
// If Dependents panel exists and is focused then we need to listen the browser tree selection events.
if ((dependentsPanels.length == 1 && dependentsPanels[0].isVisible()) || dependentsPanels.length != 1) {
pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showDependents);
}
// Defining Backbone Model for Dependencies and Dependents. // Defining Backbone Model for Dependencies and Dependents.
var Model = Backbone.Model.extend({ var Model = Backbone.Model.extend({
defaults: { defaults: {
@ -85,7 +71,7 @@ define(
* panel only once. * panel only once.
*/ */
var appendGridToPanel = function(collection, panel, is_dependent) { var appendGridToPanel = function(collection, panel, is_dependent) {
var $container = panel[0].layout().$table.find('.pg-panel-content'), var $container = panel[0].layout().scene().find('.pg-panel-content'),
$gridContainer = $container.find('.pg-panel-depends-container'), $gridContainer = $container.find('.pg-panel-depends-container'),
grid = new Backgrid.Grid({ grid = new Backgrid.Grid({
columns: [ columns: [
@ -127,16 +113,71 @@ define(
self.dependenciesGrid = grid; self.dependenciesGrid = grid;
$gridContainer.append(grid.render().el); $gridContainer.append(grid.render().el);
return true;
}; };
appendGridToPanel(this.dependentCollection, this.dependentsPanels, true); // We will listened to the visibility change of the Dependencies and Dependents panel
appendGridToPanel(this.dependenciesCollection, this.dependenciesPanels, false); pgBrowser.Events.on('pgadmin-browser:panel-dependencies:' + wcDocker.EVENT.VISIBILITY_CHANGED,
this.dependenciesPanelVisibilityChanged);
pgBrowser.Events.on('pgadmin-browser:panel-dependents:' + wcDocker.EVENT.VISIBILITY_CHANGED,
this.dependentsPanelVisibilityChanged);
// We will render the grid objects in the panel after some time, because -
// it is possible, it is not yet available.
// Find the panels to render the grid.
var dependenciesPanels = this.dependenciesPanels = pgBrowser.docker.findPanels('dependencies');
var dependentsPanels = this.dependentsPanels = pgBrowser.docker.findPanels('dependents');
if (dependenciesPanels.length == 0) {
pgBrowser.Events.on(
'pgadmin-browser:panel-dependencies:' + wcDocker.EVENT.INIT,
function() {
this.dependenciesPanels = pgBrowser.docker.findPanels('dependencies');
appendGridToPanel(this.dependenciesCollection, this.dependenciesPanels, false);
// 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);
}
}.bind(this)
);
} else {
appendGridToPanel(this.dependenciesCollection, this.dependenciesPanels, false);
// 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);
}
}
if (dependentsPanels.length == 0) {
pgBrowser.Events.on(
'pgadmin-browser:panel-dependents:' + wcDocker.EVENT.INIT,
function() {
this.dependentsPanels = pgBrowser.docker.findPanels('dependents');
appendGridToPanel(this.dependentCollection, this.dependentsPanels, true);
// 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);
}
}.bind(this)
);
} else {
appendGridToPanel(this.dependentCollection, this.dependentsPanels, true);
// 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);
}
}
}, },
// Fetch the actual data and update the collection // Fetch the actual data and update the collection
__updateCollection: function(collection, panel, url, messages, node) { __updateCollection: function(collection, panel, url, messages, node) {
var msg = messages[0], var msg = messages[0],
$container = panel[0].layout().$table.find('.pg-panel-content'), $container = panel[0].layout().scene().find('.pg-panel-content'),
$msgContainer = $container.find('.pg-panel-depends-message'), $msgContainer = $container.find('.pg-panel-depends-message'),
$gridContainer = $container.find('.pg-panel-depends-container'); $gridContainer = $container.find('.pg-panel-depends-container');

View File

@ -19,13 +19,30 @@ function(_, $, pgBrowser) {
var sqlPanels = pgBrowser.docker.findPanels('sql'); var sqlPanels = pgBrowser.docker.findPanels('sql');
// We will listend to the visibility change of the SQL panel // We will listend to the visibility change of the SQL panel
pgBrowser.Events.on('pgadmin-browser:panel-sql:' + wcDocker.EVENT.VISIBILITY_CHANGED, this.sqlPanelVisibilityChanged); pgBrowser.Events.on(
'pgadmin-browser:panel-sql:' + wcDocker.EVENT.VISIBILITY_CHANGED,
this.sqlPanelVisibilityChanged
);
// Hmm.. Did we find the SQL panel, and is it visible (openned)? // Hmm.. Did we find the SQL panel, and is it visible (openned)?
// If that is the case - we need to listen the browser tree selection // If that is the case - we need to listen the browser tree selection
// events. // events.
if ((sqlPanels.length == 1 && sqlPanels[0].isVisible()) || sqlPanels.length != 1) { if (sqlPanels.length == 0) {
pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showSQL); pgBrowser.Events.on(
'pgadmin-browser:panel-sql:' + wcDocker.EVENT.INIT,
function() {
if ((sqlPanels[0].isVisible()) || sqlPanels.length != 1) {
pgBrowser.Events.on(
'pgadmin-browser:tree:selected', this.showSQL
);
}
}.bind(this)
);
}
else {
if ((sqlPanels[0].isVisible()) || sqlPanels.length != 1) {
pgBrowser.Events.on('pgadmin-browser:tree:selected', this.showSQL);
}
} }
}, },
showSQL: function(item, data, node) { showSQL: function(item, data, node) {