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:
Christian Cueni 2019-09-05 08:14:26 +00:00 committed by Ramon Wenger
commit c38c8ce9eb
2 changed files with 28 additions and 16 deletions

View File

@ -122,7 +122,7 @@
},
contentBlocksWithContentLists() {
/*
collects all conent_list_items in content_lists:
collects all content_list_items in content_lists:
{
text_block,
content_list_item: [contents...],
@ -146,18 +146,21 @@
}
*/
let contentList = [];
let startingIndex = 0;
let newContent = this.contentBlock.contents.reduce((newContents, content, index) => {
// collect content_list_items
if (content.type === 'content_list_item') {
contentList = [...contentList, content]
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 {
// handle all other items and reset current content_list if necessary
if (contentList.length !== 0) {
newContents = [...newContents, ...this.createContentListOrBlocks(contentList), content];
newContents = [...newContents, ...this.createContentListOrBlocks(contentList, startingIndex), content];
startingIndex = this.updateStartingIndex(startingIndex, contentList);
contentList = [];
return newContents;
} else {
@ -165,9 +168,8 @@
}
}
}, []);
return Object.assign({}, this.contentBlock, {
contents: newContent
contents: this.removeSingleContentListItem(newContent, startingIndex)
});
},
schoolClass() {
@ -209,18 +211,29 @@
}
});
},
createContentListOrBlocks(contentList) {
// if list contains only one item, return blocks
if (contentList.length === 1) {
return contentList[0].value;
}
createContentListOrBlocks(contentList, startingIndex) {
return [{
type: 'content_list',
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() {
return {

View File

@ -1,7 +1,7 @@
<template>
<div class="content-list-block__container">
<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">
<content-block :contentBlock="contentBlock"></content-block>
</li>
@ -15,7 +15,7 @@
// import ContentBlock from '@/components/ContentBlock';
export default {
props: ['contents', 'parent'],
props: ['contents', 'parent', 'startingIndex'],
name: 'content-block-list',
components: {
@ -43,7 +43,6 @@
.content-list-wrapper {
.content-list {
/* https://stackoverflow.com/questions/1632005/ordered-list-html-lower-alpha-with-right-parentheses */
counter-reset: list;
&__item {
list-style: none;