allow user to set block type

This commit is contained in:
Christian Cueni 2018-10-16 07:29:41 +02:00
parent a1a75e9b3f
commit 3547a30228
9 changed files with 41 additions and 13 deletions

View File

@ -5,7 +5,11 @@
:placeholder="titlePlaceholder"
:value="localContentBlock.title"
:error="error"></modal-input>
<checkbox :checked="localContentBlock.isAssignment"
:item="localContentBlock"
:label="'Aufgabe'"
@input="setContentBlockType"
></checkbox>
<modal-input v-if="blockType === 'RoomEntry'"
placeholder="Untertitel für Raumeintrag erfassen"
v-model="localContentBlock.subtitle"></modal-input>
@ -68,6 +72,7 @@
import AssignmentForm from '@/components/content-forms/AssignmentForm';
import TextForm from '@/components/content-forms/TextForm';
import TrashIcon from '@/components/icons/TrashIcon';
import Checkbox from '@/components/Checkbox';
export default {
props: {
@ -89,17 +94,20 @@
DocumentForm,
AssignmentForm,
TextForm,
TrashIcon
TrashIcon,
Checkbox
},
data() {
console.log(this.contentBlock)
return {
error: false,
localContentBlock: Object.assign({}, {
title: this.contentBlock.title,
contents: [...this.contentBlock.contents],
id: this.contentBlock.id || undefined,
subtitle: this.contentBlock.subtitle
subtitle: this.contentBlock.subtitle,
isAssignment: this.contentBlock.type && this.contentBlock.type === 'TASK'
})
}
},
@ -229,6 +237,9 @@
return false;
}
this.$emit('save', this.localContentBlock);
},
setContentBlockType(checked, localContentBlock) {
this.localContentBlock.isAssignment = checked;
}
}
}

View File

@ -32,7 +32,8 @@
input: {
contentBlock: {
title: contentBlock.title,
contents: contentBlock.contents.filter(value => Object.keys(value).length > 0)
contents: contentBlock.contents.filter(value => Object.keys(value).length > 0),
type: contentBlock.isAssignment ? 'TASK' : 'NORMAL'
},
id: contentBlock.id
}

View File

@ -31,7 +31,8 @@
input: {
contentBlock: {
title: contentBlock.title,
contents: contentBlock.contents.filter(value => Object.keys(value).length > 0)
contents: contentBlock.contents.filter(value => Object.keys(value).length > 0),
type: contentBlock.isAssignment ? 'TASK' : 'NORMAL'
},
after: this.$store.state.contentBlockPosition.after,
parent: this.$store.state.contentBlockPosition.parent

View File

@ -177,9 +177,6 @@
.assignment {
margin-bottom: 2em;
padding: 20px;
border-radius: $default-border-radius;
background-color: $color-brand-light;
&__title {
font-size: toRem(17px);

View File

@ -5,6 +5,7 @@ mutation AddContentBlock($input: AddContentBlockInput!) {
title
slug
contents
type
}
errors
clientMutationId

View File

@ -1,4 +1,4 @@
# Generated by Django 2.0.6 on 2018-10-15 09:15
# Generated by Django 2.0.6 on 2018-10-15 12:02
from django.db import migrations, models
@ -6,7 +6,7 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('books', '0002_auto_20181010_0825'),
('books', '0002_auto_20181011_1345'),
]
operations = [

View File

@ -1,4 +1,5 @@
import json
import logging
import graphene
from django.core.exceptions import ValidationError
@ -9,7 +10,9 @@ from api.utils import get_object, get_errors
from books.models import ContentBlock, Chapter, SchoolClass
from books.schema.inputs import ContentBlockInput
from books.schema.queries import ContentBlockNode
from .utils import handle_content_block
from .utils import handle_content_block, set_user_defined_block_type
logger = logging.getLogger(__name__)
class MutateContentBlock(relay.ClientIDMutation):
@ -29,9 +32,10 @@ class MutateContentBlock(relay.ClientIDMutation):
title = content_block_data.get('title', None)
contents = content_block_data.get('contents', None)
visibility_list = content_block_data.get('visibility', None)
block_type = content_block_data.get('type', ContentBlock.NORMAL)
content_block = get_object(ContentBlock, id_param)
logger.info(content_block_data)
if visibility_list is not None:
for v in visibility_list:
school_class = get_object(SchoolClass, v.school_class_id)
@ -46,6 +50,8 @@ class MutateContentBlock(relay.ClientIDMutation):
if contents is not None:
content_block.contents = json.dumps([handle_content_block(c, info.context) for c in contents])
content_block.type = set_user_defined_block_type(block_type)
content_block.save()
return cls(content_block=content_block)
@ -74,8 +80,10 @@ class AddContentBlock(relay.ClientIDMutation):
title = content_block_data.get('title')
contents = content_block_data.get('contents')
block_type = content_block_data.get('type', ContentBlock.NORMAL)
new_content_block = ContentBlock(title=title, user_created=True, owner=context.user)
block_type = set_user_defined_block_type(block_type)
new_content_block = ContentBlock(title=title, user_created=True, owner=context.user, type=block_type)
if parent is not None:
parent_chapter = get_object(Chapter, parent).specific

View File

@ -12,6 +12,7 @@ import bleach
import re
from assignments.models import Assignment
from books.models import ContentBlock
def newlines_to_paragraphs(text):
@ -83,3 +84,10 @@ def handle_content_block(content, context, allowed_blocks=ALLOWED_BLOCKS):
}}
return None
def set_user_defined_block_type(block_type):
if block_type == ContentBlock.TASK.upper():
return ContentBlock.TASK
else:
return ContentBlock.NORMAL

View File

@ -22,6 +22,7 @@ class ContentBlockNode(DjangoObjectType):
def resolve_mine(self, info, **kwargs):
return self.owner is not None and self.owner.pk == info.context.user.pk
class ChapterNode(DjangoObjectType):
content_blocks = DjangoFilterConnectionField(ContentBlockNode)