Skip to content

Commit

Permalink
fix: Groups are displayed and ordered correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Apr 11, 2017
1 parent 926d420 commit 54e03c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cli/cms/editor/handlebars/printBlock.js
Expand Up @@ -11,7 +11,7 @@ export default function printBlock (ctx, root) {
if(ctx[0].block != null && ctx[0].block !== '') {
res += `<div class="form-group" data-precontrib-templates="${ctx[0].precontribTemplate}">
<label class="title">
${(ctx[0].groupdesc != null) ? ctx[0].groupdesc : ctx[0].block}
${(ctx[0].group != null) ? ctx[0].group : ctx[0].block}
</label>
<div class='single-block well well-sm'>`
Array.prototype.forEach.call(ctx, (item) => {
Expand Down
11 changes: 8 additions & 3 deletions src/server/controllers/editor.js
Expand Up @@ -2,6 +2,7 @@ import {Promise} from 'bluebird'
import path from 'path'

import {
coreUtils,
cmsData,
cmsEditor,
abeEngine,
Expand Down Expand Up @@ -196,12 +197,12 @@ export function orderByGroup(form) {
var index = 0

Array.prototype.forEach.call(form.item, (item) => {
if(item.group != null) {
if(item.group != null && (item.block === '' || item.block == null)) {
if(typeof groups[item.group] === 'undefined' || groups[item.group] === null){
groupIndex[item.group] = index
groups[item.group] = []
}
item.order = -1

groups[item.group].push(item)
}
else noGroup.push(item)
Expand All @@ -210,6 +211,10 @@ export function orderByGroup(form) {

for(var prop in groups){
var group = groups[prop]
group.sort(coreUtils.sort.predicatBy('order'))
Array.prototype.forEach.call(group, (elt, index) => {
group[index].order = group[0].order
})
group[0].firstgroup = 1
group[group.length - 1].lastgroup = 1
noGroup = noGroup.splice(0, groupIndex[group[0].group]).concat(group).concat(noGroup)
Expand Down Expand Up @@ -246,7 +251,7 @@ function orderBlock(util) {
var arKeys = Object.keys(formBlockTab).sort((a,b) => {
if(parseFloat(formBlockTab[a][0].order) < parseFloat(formBlockTab[b][0].order)) {
return -1
}else if(parseFloat(formBlockTab[a][0].order) > parseFloat(formBlockTab[b][0].order)) {
} else if(parseFloat(formBlockTab[a][0].order) > parseFloat(formBlockTab[b][0].order)) {
return 1
}
return 0
Expand Down
9 changes: 8 additions & 1 deletion src/server/views/partials/engine.html
Expand Up @@ -37,7 +37,14 @@
</div>
{{else}}
{{#each this}}
{{#if this.0.firstgroup}}<div class='single-block well well-sm'>{{/if}}
{{#if this.0.firstgroup}}
{{#if this.0.group}}
<label class="title">
{{this.0.group}}
</label>
{{/if}}
<div class='single-block well well-sm'>
{{/if}}
<div class="{{cleanTab @key}}">
{{{printBlock this @root}}}
</div>
Expand Down

0 comments on commit 54e03c0

Please sign in to comment.