Merged in feature/content-list-numbering (pull request #33)
Feature/content list numbering Approved-by: Ramon Wenger <ramon.wenger@iterativ.ch>
This commit is contained in:
commit
c38c8ce9eb
|
|
@ -122,7 +122,7 @@
|
||||||
},
|
},
|
||||||
contentBlocksWithContentLists() {
|
contentBlocksWithContentLists() {
|
||||||
/*
|
/*
|
||||||
collects all conent_list_items in content_lists:
|
collects all content_list_items in content_lists:
|
||||||
{
|
{
|
||||||
text_block,
|
text_block,
|
||||||
content_list_item: [contents...],
|
content_list_item: [contents...],
|
||||||
|
|
@ -146,18 +146,21 @@
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
let contentList = [];
|
let contentList = [];
|
||||||
|
let startingIndex = 0;
|
||||||
let newContent = this.contentBlock.contents.reduce((newContents, content, index) => {
|
let newContent = this.contentBlock.contents.reduce((newContents, content, index) => {
|
||||||
// collect content_list_items
|
// collect content_list_items
|
||||||
if (content.type === 'content_list_item') {
|
if (content.type === 'content_list_item') {
|
||||||
contentList = [...contentList, content]
|
contentList = [...contentList, content]
|
||||||
if (index === this.contentBlock.contents.length - 1) { // content is last element of contents array
|
if (index === this.contentBlock.contents.length - 1) { // content is last element of contents array
|
||||||
return [...newContents, ...this.createContentListOrBlocks(contentList)];
|
startingIndex = this.updateStartingIndex(startingIndex, contentList);
|
||||||
|
return [...newContents, ...this.createContentListOrBlocks(contentList, startingIndex)];
|
||||||
}
|
}
|
||||||
return newContents
|
return newContents;
|
||||||
} else {
|
} else {
|
||||||
// handle all other items and reset current content_list if necessary
|
// handle all other items and reset current content_list if necessary
|
||||||
if (contentList.length !== 0) {
|
if (contentList.length !== 0) {
|
||||||
newContents = [...newContents, ...this.createContentListOrBlocks(contentList), content];
|
newContents = [...newContents, ...this.createContentListOrBlocks(contentList, startingIndex), content];
|
||||||
|
startingIndex = this.updateStartingIndex(startingIndex, contentList);
|
||||||
contentList = [];
|
contentList = [];
|
||||||
return newContents;
|
return newContents;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -165,9 +168,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return Object.assign({}, this.contentBlock, {
|
return Object.assign({}, this.contentBlock, {
|
||||||
contents: newContent
|
contents: this.removeSingleContentListItem(newContent, startingIndex)
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
schoolClass() {
|
schoolClass() {
|
||||||
|
|
@ -209,18 +211,29 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createContentListOrBlocks(contentList) {
|
createContentListOrBlocks(contentList, startingIndex) {
|
||||||
// if list contains only one item, return blocks
|
|
||||||
if (contentList.length === 1) {
|
|
||||||
return contentList[0].value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
type: 'content_list',
|
type: 'content_list',
|
||||||
contents: contentList,
|
contents: contentList,
|
||||||
id: contentList[0].id
|
id: contentList[0].id,
|
||||||
|
startingIndex
|
||||||
}];
|
}];
|
||||||
},
|
},
|
||||||
|
updateStartingIndex(startingIndex, contentList) {
|
||||||
|
return contentList.length > 1 ? startingIndex + contentList.length : startingIndex;
|
||||||
|
},
|
||||||
|
removeSingleContentListItem(content, index) {
|
||||||
|
// just handle the case where we have one contentlistItem ( no index like "a)"" will be shown)
|
||||||
|
if (index > 0) {
|
||||||
|
return content;
|
||||||
|
};
|
||||||
|
|
||||||
|
let contentListIndex = content.findIndex(contentItem => contentItem.type === 'content_list');
|
||||||
|
if (contentListIndex < 0) {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
return [...content.slice(0, contentListIndex), ...content[contentListIndex].contents[0].value, ...content.slice(contentListIndex + 1)];
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="content-list-block__container">
|
<div class="content-list-block__container">
|
||||||
<div class="content-list-wrapper">
|
<div class="content-list-wrapper">
|
||||||
<ol class="content-list">
|
<ol class="content-list" :style="`counter-reset: list ${startingIndex}`">
|
||||||
<li class="content-list__item contentlist-item" :key="contentBlock.id" v-for="contentBlock in contentBlocks">
|
<li class="content-list__item contentlist-item" :key="contentBlock.id" v-for="contentBlock in contentBlocks">
|
||||||
<content-block :contentBlock="contentBlock"></content-block>
|
<content-block :contentBlock="contentBlock"></content-block>
|
||||||
</li>
|
</li>
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
// import ContentBlock from '@/components/ContentBlock';
|
// import ContentBlock from '@/components/ContentBlock';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['contents', 'parent'],
|
props: ['contents', 'parent', 'startingIndex'],
|
||||||
name: 'content-block-list',
|
name: 'content-block-list',
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
|
|
@ -43,7 +43,6 @@
|
||||||
.content-list-wrapper {
|
.content-list-wrapper {
|
||||||
.content-list {
|
.content-list {
|
||||||
/* https://stackoverflow.com/questions/1632005/ordered-list-html-lower-alpha-with-right-parentheses */
|
/* https://stackoverflow.com/questions/1632005/ordered-list-html-lower-alpha-with-right-parentheses */
|
||||||
counter-reset: list;
|
|
||||||
|
|
||||||
&__item {
|
&__item {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue