Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions applications/default/extensions/layout/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ layout.type = function(types, callback) {
region: {
title: 'Region',
type: 'boolean'
},
alwaysRender: {
title: 'Always Render',
type: 'boolean'
}
}
};
Expand Down Expand Up @@ -125,6 +129,10 @@ layout.type = function(types, callback) {
region: {
title: 'Region',
type: 'boolean'
},
alwaysRender: {
title: 'Always Render',
type: 'boolean'
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div ng-if="column.region" ng-include="'/templates/region.html'" ng-controller="RegionController"></div>
<div ng-if="column.region && !column.empty" ng-include="'/templates/region.html'" ng-controller="RegionController"></div>
<!-- Rows -->
<div ng-repeat="row in column.rows | orderBy:'weight'" ng-controller="RowController" ng-include="getTemplate()" class="row-{{row.name}} row-fluid"></div>
<div ng-repeat="row in column.rows | orderBy:'weight'" ng-if="!row.empty" ng-controller="RowController" ng-include="getTemplate()" class="row-{{row.name}} row-fluid"></div>
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<!-- Rows -->
<div ng-repeat="row in layout.rows | orderBy:'weight'" ng-controller="RowController" ng-include="row.template || '/templates/row.html'" class="row-{{row.name}} row-fluid"></div>
<div ng-repeat="row in layout.rows | orderBy:'weight'" ng-if="!row.empty" ng-controller="RowController" ng-include="row.template || '/templates/row.html'" class="row-{{row.name}} row-fluid"></div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div ng-class="row.classes" class="container">
<div ng-if="row.region" ng-include="'/templates/region.html'" ng-controller="RegionController"></div>
<div ng-if="row.region && !row.empty" ng-include="'/templates/region.html'" ng-controller="RegionController"></div>
<!-- Columns -->
<div ng-repeat="column in row.columns | orderBy:'weight'" ng-controller="ColumnController" ng-include="getTemplate()" ng-class="column.classes" class="column-{{column.name}} col-md-{{column.width}}"></div>
<div ng-repeat="column in row.columns | orderBy:'weight'" ng-if="!column.empty" ng-controller="ColumnController" ng-include="getTemplate()" ng-class="column.classes" class="column-{{column.name}} col-md-{{column.width}}"></div>
</div>
51 changes: 49 additions & 2 deletions applications/default/extensions/panel/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,19 +234,24 @@ panel.contextReactionType = function(reactionTypes, callback) {
}
},
react: function(request, response, regionPanels, callback) {

// Get panel type.
var Panel = self.application.type('panel');

// Initialize panels container if not initialized yet.
response.payload.panels = response.payload.panels || {};

// Add all panels to response payload.
async.each(Object.keys(regionPanels), function(regionName, next) {

// Initialize panels container if not initialized yet.
response.payload.panels[regionName] = response.payload.panels[regionName] || [];
var panels = regionPanels[regionName];

// A context can set several panels for a region.
async.each(panels, function(regionPanel, next) {
// Load the panel.
var Panel = self.application.type('panel');

// Load the panel.
Panel.load(regionPanel.name, function(err, panel) {
if (err) {
return callback(err);
Expand Down Expand Up @@ -274,3 +279,45 @@ panel.contextReactionType = function(reactionTypes, callback) {

callback(null, newReactionTypes);
};

/**
* The response() hook.
*/
panel.response = function (payload, request, response, callback) {

var layout = payload.data && payload.data.layout;
var panels = payload.data && payload.data.panels;

if (layout && panels) {

/**
* Recursively verifies if a row/column is empty.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good place to use async.detect() or some other asynchronous utility from async library.

Could you justify there would be no impact in performance by doing those blocking loops? Specially since this will run in all page requests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although async does not help if recursiveness (or am I wrong?), indeed it could be used in the children iteration and would in fact improve performance for a bit. Anyway, I don't think there would be any issue on performance because of this loop, as it is really not probable to have a deep layout structure and as the forEach code is run natively and inside that resides a quite simple validation. I would run some tests, though, but I'm sure they would result in nothing to worry about.

It is good to note that the "heavy part" is only runned when receiving actual layout & panels data on payload - which as I've tested does not correspond to many request situations.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's do that this way for now, and review after we have some benchmarks.

*/
function findContent(region, childType) {

// Consider empty by default, unless when region is told to always be
// rendered.
region.empty = region.alwaysRender ? false : true;

// Check if region has content.
if (region.empty && region.region == true) {
region.empty = !Boolean(panels[region.name] && panels[region.name].length);
}

// Iterate recursively
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a period on this comment.

if (region[childType] && region[childType].length) {
region[childType].forEach(function (childRegion) {
var childEmpty = findContent(childRegion, childType == 'rows' ? 'columns' : 'rows');
region.empty = !region.empty ? region.empty : childEmpty;
});
}

return region.empty;
}

// As a layout contains rows, it behaves much like a column itself.
findContent(layout, 'rows');
}

callback();
};