Make bookmarks work with content list blocks

This commit is contained in:
Ramon Wenger 2019-10-22 14:28:37 +02:00
parent d061116585
commit 9b2db99d0b
3 changed files with 22 additions and 11 deletions

View File

@ -21,7 +21,8 @@
<content-component v-for="component in contentBlocksWithContentLists.contents" <content-component v-for="component in contentBlocksWithContentLists.contents"
:key="component.id" :key="component.id"
:component="component" :component="component"
:parent="contentBlock.id" :root="root"
:parent="contentBlock"
:bookmarks="contentBlock.bookmarks" :bookmarks="contentBlock.bookmarks"
:notes="contentBlock.notes" :notes="contentBlock.notes"
> >
@ -151,6 +152,10 @@
}, },
hidden() { hidden() {
return isHidden(this.contentBlock, this.schoolClass); return isHidden(this.contentBlock, this.schoolClass);
},
root() {
// we need the root content block id, not the generated content block if inside a content list block
return this.contentBlock.root ? this.contentBlock.root : this.contentBlock.id;
} }
}, },

View File

@ -1,6 +1,7 @@
<template> <template>
<div class="content-component" :class="{'content-component--bookmarked': bookmarked}"> <div class="content-component" :class="{'content-component--bookmarked': bookmarked}">
<bookmark-actions <bookmark-actions
v-if="component.type !== 'content_list' && component.type !== 'basic_knowledge'"
@add-note="addNote(component.id)" @add-note="addNote(component.id)"
@edit-note="editNote" @edit-note="editNote"
@bookmark="bookmarkContent(component.id, !bookmarked)" @bookmark="bookmarkContent(component.id, !bookmarked)"
@ -8,7 +9,9 @@
:note="note"></bookmark-actions> :note="note"></bookmark-actions>
<component <component
:is="component.type" :is="component.type"
v-bind="component"> v-bind="component"
:parent="parent"
>
</component> </component>
</div> </div>
</template> </template>
@ -35,7 +38,7 @@
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql'; import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
export default { export default {
props: ['component', 'parent', 'bookmarks', 'notes'], props: ['component', 'parent', 'bookmarks', 'notes', 'root'],
components: { components: {
'text_block': TextBlock, 'text_block': TextBlock,
@ -59,11 +62,9 @@
computed: { computed: {
bookmarked() { bookmarked() {
// fixme: make indented sub-contents work
return this.bookmarks && !!this.bookmarks.find(bookmark => bookmark.uuid === this.component.id); return this.bookmarks && !!this.bookmarks.find(bookmark => bookmark.uuid === this.component.id);
}, },
note() { note() {
// fixme: make indented sub-contents work
const bookmark = this.bookmarks && this.bookmarks.find(bookmark => bookmark.uuid === this.component.id); const bookmark = this.bookmarks && this.bookmarks.find(bookmark => bookmark.uuid === this.component.id);
return bookmark && bookmark.note; return bookmark && bookmark.note;
} }
@ -73,7 +74,7 @@
addNote(id) { addNote(id) {
this.$store.dispatch('addNote', { this.$store.dispatch('addNote', {
content: id, content: id,
contentBlock: this.parent contentBlock: this.root
}); });
}, },
editNote() { editNote() {
@ -85,7 +86,7 @@
variables: { variables: {
input: { input: {
uuid, uuid,
contentBlock: this.parent, contentBlock: this.root,
bookmarked bookmarked
} }
}, },

View File

@ -6,7 +6,10 @@
:key="contentBlock.id" :key="contentBlock.id"
v-for="(contentBlock, index) in contentBlocks"> v-for="(contentBlock, index) in contentBlocks">
<p class="content-list__numbering">{{alphaIndex(index)}})</p> <p class="content-list__numbering">{{alphaIndex(index)}})</p>
<content-block :contentBlock="contentBlock"></content-block> <content-block
:contentBlock="contentBlock"
:parent="parent"
></content-block>
</li> </li>
</ol> </ol>
</div> </div>
@ -35,11 +38,13 @@
computed: { computed: {
contentBlocks() { contentBlocks() {
// fixme: make indented sub-contents work
return this.contents.map(contentBlock => { return this.contents.map(contentBlock => {
return Object.assign({}, contentBlock, { return Object.assign({}, contentBlock, {
contents: [...contentBlock.value], contents: [...contentBlock.value],
indent: true indent: true,
bookmarks: this.parent.bookmarks,
notes: this.parent.notes,
root: this.parent.id
}) })
}); });
} }
@ -58,7 +63,7 @@
&__item { &__item {
list-style: none; list-style: none;
position: relative; position: relative;
padding: 0 2*15px; padding: 0 0 0 2*15px;
} }
&__numbering { &__numbering {