From 117782a3379f0e8a1ae981ff35b964526491c735 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 13 Aug 2019 15:28:53 +0200 Subject: [PATCH 1/2] Add continuos numbering for content lists --- client/src/components/ContentBlock.vue | 41 +++++++++++++------ .../content-blocks/ContentListBlock.vue | 5 +-- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/client/src/components/ContentBlock.vue b/client/src/components/ContentBlock.vue index cbd5d9a8..7bd658af 100644 --- a/client/src/components/ContentBlock.vue +++ b/client/src/components/ContentBlock.vue @@ -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,10 @@ } } }, []); - + let some = this.removeSingleContentListItem(newContent, startingIndex); + console.log(some) return Object.assign({}, this.contentBlock, { - contents: newContent + contents: some }); }, schoolClass() { @@ -209,18 +213,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 { diff --git a/client/src/components/content-blocks/ContentListBlock.vue b/client/src/components/content-blocks/ContentListBlock.vue index 663e02dd..bd865cf5 100644 --- a/client/src/components/content-blocks/ContentListBlock.vue +++ b/client/src/components/content-blocks/ContentListBlock.vue @@ -1,7 +1,7 @@