Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1611 #1612

Merged
merged 4 commits into from
May 2, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
30 changes: 18 additions & 12 deletions frontend/src/core/editor/page/views/editorComponentListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,36 @@ define(function(require) {
renderComponentList: function() {
Origin.trigger('editorComponentListView:removeSubviews');
// _.each(this.collection, function(componentType) {

this.collection.each(function(componentType) {
var properties = componentType.get('properties');
if (properties && properties.hasOwnProperty('._supportedLayout')) {
var supportedLayout = properties.hasOwnProperty('._supportedLayout').enum;
if (properties && properties.hasOwnProperty('_supportedLayout')) {
var supportedLayout = properties._supportedLayout.enum;
var availablePositions = {
Copy link
Member

Choose a reason for hiding this comment

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

@danielstorey I think availablePositions is also used to find positions that are not already occupied as set in setupFilters function. Assigning a new value to availablePositions here allows the user to insert two left (or right) positioned components.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok good point...so just need to combine both checks

Copy link
Member

Choose a reason for hiding this comment

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

👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Latest commit should do it!

left: true,
right: true,
full: true
};

// Prune the available positions
if (_.indexOf(supportedLayout, 'half-width') == -1) {
this.availablePositions.left = false;
this.availablePositions.right = false;
availablePositions.left = false;
availablePositions.right = false;
}

if (_.indexOf(supportedLayout, 'full-width') == -1) {
this.availablePositions.full = false;
availablePositions.full = false;
}
}

this.$('.editor-component-list-sidebar-list').append(new EditorComponentListItemView({
model: componentType,
availablePositions: this.availablePositions,
_parentId: this.model.get('_parentId'),
$parentElement: this.$parentElement,
parentView: this.parentView,
searchTerms: componentType.get('displayName').toLowerCase()
}).$el);
model: componentType,
availablePositions: availablePositions,
_parentId: this.model.get('_parentId'),
$parentElement: this.$parentElement,
parentView: this.parentView,
searchTerms: componentType.get('displayName').toLowerCase()
}).$el);
}, this);
},

Expand Down
48 changes: 30 additions & 18 deletions frontend/src/core/editor/page/views/editorComponentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(function(require){

this.on('contextMenu:component:edit', this.loadComponentEdit);
this.on('contextMenu:component:copy', this.onCopy);
this.on('contextMenu:component:copyID', this.onCopyID),
this.on('contextMenu:component:copyID', this.onCopyID);
this.on('contextMenu:component:cut', this.onCut);
this.on('contextMenu:component:delete', this.deleteComponentPrompt);
},
Expand Down Expand Up @@ -145,28 +145,40 @@ define(function(require){
},

evaluateLayout: function() {

var componentType = _.find(Origin.editor.data.componentTypes.models, function(type){
return type.get('component') == this.model.get('_component');
}, this);

var supportedLayout = componentType.get("properties")._supportedLayout;
var isFullWidthSupported = _.indexOf(supportedLayout.enum, "full-width") > -1;
var isHalfWidthSupported = _.indexOf(supportedLayout.enum, "half-width") > -1;

var movePositions = {
left: false,
right: false,
full: false
};

var siblings = this.model.getSiblings();
var showFull = !siblings.length;
var type = this.model.get('_layout');
switch (type) {
case 'left':
movePositions.right = true;
movePositions.full = showFull;
break;
case 'right':
movePositions.left = true;
movePositions.full = showFull;
break;
case 'full':
movePositions.left = true;
movePositions.right = true;
break
if (isHalfWidthSupported) {
var siblings = this.model.getSiblings();
var showFull = !siblings.length && isFullWidthSupported;
var type = this.model.get('_layout');

switch (type) {
case 'left':
movePositions.right = true;
movePositions.full = showFull;
break;
case 'right':
movePositions.left = true;
movePositions.full = showFull;
break;
case 'full':
movePositions.left = true;
movePositions.right = true;
break
}
}

this.model.set('_movePositions', movePositions);
Expand Down Expand Up @@ -262,4 +274,4 @@ define(function(require){

return EditorComponentView;

});
});