Add document block

This commit is contained in:
Ramon Wenger 2018-09-12 15:05:36 +02:00
parent 23f282b358
commit 639fa7665c
9 changed files with 67 additions and 5 deletions

View File

@ -28,6 +28,7 @@
import ImageBlock from '@/components/content-blocks/ImageBlock'; import ImageBlock from '@/components/content-blocks/ImageBlock';
import VideoBlock from '@/components/content-blocks/VideoBlock'; import VideoBlock from '@/components/content-blocks/VideoBlock';
import LinkBlock from '@/components/content-blocks/LinkBlock'; import LinkBlock from '@/components/content-blocks/LinkBlock';
import DocumentBlock from '@/components/content-blocks/DocumentBlock';
import StudentEntry from '@/components/content-blocks/StudentEntry'; import StudentEntry from '@/components/content-blocks/StudentEntry';
import AddContentBlockButton from '@/components/AddContentBlockButton'; import AddContentBlockButton from '@/components/AddContentBlockButton';
import EyeIcon from '@/components/icons/EyeIcon'; import EyeIcon from '@/components/icons/EyeIcon';
@ -42,6 +43,7 @@
'image_block': ImageBlock, 'image_block': ImageBlock,
'video_block': VideoBlock, 'video_block': VideoBlock,
'link_block': LinkBlock, 'link_block': LinkBlock,
'document_block': DocumentBlock,
Task, Task,
AddContentBlockButton, AddContentBlockButton,
EyeIcon EyeIcon

View File

@ -15,6 +15,7 @@
v-on:link-change-url="changeLinkUrl" v-on:link-change-url="changeLinkUrl"
v-on:link-change-text="changeLinkText" v-on:link-change-text="changeLinkText"
v-on:text-change-value="changeTextValue" v-on:text-change-value="changeTextValue"
v-on:document-change-url="changeDocumentUrl"
v-on:video-change-url="changeVideoUrl"> v-on:video-change-url="changeVideoUrl">
</component> </component>
<a class="new-content-block-wizard__remove" v-on:click="removeElement(index)"> <a class="new-content-block-wizard__remove" v-on:click="removeElement(index)">
@ -78,7 +79,7 @@
return 'text-form'; return 'text-form';
case 'exercise': case 'exercise':
return 'exercise-form'; return 'exercise-form';
case 'document': case 'document_block':
return 'document-form'; return 'document-form';
} }
return 'content-block-element-chooser-widget' return 'content-block-element-chooser-widget'
@ -98,6 +99,9 @@
changeVideoUrl(value, index) { changeVideoUrl(value, index) {
this._updateProperty(value, index, 'url') this._updateProperty(value, index, 'url')
}, },
changeDocumentUrl(value, index) {
this._updateProperty(value, index, 'url')
},
changeTextValue(value, index) { changeTextValue(value, index) {
this._updateProperty(value, index, 'text') this._updateProperty(value, index, 'text')
}, },
@ -134,6 +138,12 @@
url: '' url: ''
}; };
break; break;
case 'document_block':
el = {
...el,
url: ''
};
break;
} }
this.elements.splice(index, 1, el); this.elements.splice(index, 1, el);

View File

@ -0,0 +1,36 @@
<template>
<div class="document-block">
<document-icon class="document-block__icon"></document-icon>
<a :href="value.url" class="document-block__link" target="_blank">{{value.url}}</a>
</div>
</template>
<script>
import DocumentIcon from '@/components/icons/DocumentIcon';
export default {
props: ['value'],
components: {
DocumentIcon
}
}
</script>
<style scoped lang="scss">
.document-block {
margin-bottom: 30px;
display: grid;
grid-template-columns: 50px 1fr;
align-items: center;
&__icon {
width: 30px;
height: 30px;
}
&__link {
text-decoration: underline;
}
}
</style>

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="link-block"> <div class="link-block">
<link-icon class="link-block__icon"></link-icon> <link-icon class="link-block__icon"></link-icon>
<a :href="value.url" class="link-block__link">{{value.text}}</a> <a :href="value.url" class="link-block__link" target="_blank">{{value.text}}</a>
</div> </div>
</template> </template>

View File

@ -20,7 +20,7 @@
<speech-bubble-icon class="content-block-element-chooser-widget__link-icon"></speech-bubble-icon> <speech-bubble-icon class="content-block-element-chooser-widget__link-icon"></speech-bubble-icon>
<div class="content-block-element-chooser-widget__link-title">Aufgabe&nbsp;& Ergebnis</div> <div class="content-block-element-chooser-widget__link-title">Aufgabe&nbsp;& Ergebnis</div>
</div> </div>
<div class="content-block-element-chooser-widget__link" v-on:click="$emit('change-type', index, 'document')"> <div class="content-block-element-chooser-widget__link" v-on:click="$emit('change-type', index, 'document_block')">
<document-icon class="content-block-element-chooser-widget__link-icon"></document-icon> <document-icon class="content-block-element-chooser-widget__link-icon"></document-icon>
<div class="content-block-element-chooser-widget__link-title">Dokument</div> <div class="content-block-element-chooser-widget__link-title">Dokument</div>
</div> </div>

View File

@ -8,6 +8,7 @@
</p> </p>
<input class="document-form__document-link skillbox-input" <input class="document-form__document-link skillbox-input"
:value="url" v-on:input="$emit('document-change-url', $event.target.value, index)"
placeholder="URL einfügen..."> placeholder="URL einfügen...">
</div> </div>
@ -17,6 +18,8 @@
import InfoIcon from '@/components/icons/InfoIcon'; import InfoIcon from '@/components/icons/InfoIcon';
export default { export default {
props: ['url', 'index'],
components: { components: {
InfoIcon InfoIcon
} }

View File

@ -36,6 +36,10 @@ class VideoBlock(blocks.StructBlock):
url = blocks.URLBlock() url = blocks.URLBlock()
# 'document_block'
class DocumentBlock(blocks.StructBlock):
url = blocks.URLBlock()
# 'text_block' 'task' 'basic_knowledge' 'student_entry' 'image_block' # 'text_block' 'task' 'basic_knowledge' 'student_entry' 'image_block'
# #
# url = blocks.URLBlock() # url = blocks.URLBlock()

View File

@ -5,7 +5,7 @@ from wagtail.admin.edit_handlers import FieldPanel, TabbedInterface, ObjectList,
from wagtail.core.fields import StreamField from wagtail.core.fields import StreamField
from wagtail.images.blocks import ImageChooserBlock from wagtail.images.blocks import ImageChooserBlock
from book.blocks import TextBlock, BasicKnowledgeBlock, StudentEntryBlock, LinkBlock, VideoBlock from book.blocks import TextBlock, BasicKnowledgeBlock, StudentEntryBlock, LinkBlock, VideoBlock, DocumentBlock
from core.wagtail_utils import StrictHierarchyPage from core.wagtail_utils import StrictHierarchyPage
from user.models import UserGroup from user.models import UserGroup
@ -37,6 +37,7 @@ class ContentBlock(StrictHierarchyPage):
('link_block', LinkBlock(icon='link')), ('link_block', LinkBlock(icon='link')),
('task', TextBlock(icon='tick')), ('task', TextBlock(icon='tick')),
('video_block', VideoBlock(icon='media')), ('video_block', VideoBlock(icon='media')),
('document_block', DocumentBlock(icon='doc-full')),
], null=True, blank=True) ], null=True, blank=True)
type = models.CharField( type = models.CharField(

View File

@ -13,6 +13,7 @@ from book.schema.queries import ContentBlockNode
def handle_content_blocks(content_data): def handle_content_blocks(content_data):
new_contents = [] new_contents = []
for content in content_data: for content in content_data:
# todo: add all the content blocks # todo: add all the content blocks
# todo: sanitize user inputs! # todo: sanitize user inputs!
@ -43,7 +44,12 @@ def handle_content_blocks(content_data):
'url': bleach.clean(content['url']) 'url': bleach.clean(content['url'])
}}) }})
elif content['type'] == 'document_block': elif content['type'] == 'document_block':
pass new_contents.append({
'type': 'document_block',
'value': {
'url': bleach.clean(content['url'])
}})
return new_contents return new_contents