allow user to set block type
This commit is contained in:
parent
a1a75e9b3f
commit
3547a30228
|
|
@ -5,7 +5,11 @@
|
||||||
:placeholder="titlePlaceholder"
|
:placeholder="titlePlaceholder"
|
||||||
:value="localContentBlock.title"
|
:value="localContentBlock.title"
|
||||||
:error="error"></modal-input>
|
:error="error"></modal-input>
|
||||||
|
<checkbox :checked="localContentBlock.isAssignment"
|
||||||
|
:item="localContentBlock"
|
||||||
|
:label="'Aufgabe'"
|
||||||
|
@input="setContentBlockType"
|
||||||
|
></checkbox>
|
||||||
<modal-input v-if="blockType === 'RoomEntry'"
|
<modal-input v-if="blockType === 'RoomEntry'"
|
||||||
placeholder="Untertitel für Raumeintrag erfassen"
|
placeholder="Untertitel für Raumeintrag erfassen"
|
||||||
v-model="localContentBlock.subtitle"></modal-input>
|
v-model="localContentBlock.subtitle"></modal-input>
|
||||||
|
|
@ -68,6 +72,7 @@
|
||||||
import AssignmentForm from '@/components/content-forms/AssignmentForm';
|
import AssignmentForm from '@/components/content-forms/AssignmentForm';
|
||||||
import TextForm from '@/components/content-forms/TextForm';
|
import TextForm from '@/components/content-forms/TextForm';
|
||||||
import TrashIcon from '@/components/icons/TrashIcon';
|
import TrashIcon from '@/components/icons/TrashIcon';
|
||||||
|
import Checkbox from '@/components/Checkbox';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
|
@ -89,17 +94,20 @@
|
||||||
DocumentForm,
|
DocumentForm,
|
||||||
AssignmentForm,
|
AssignmentForm,
|
||||||
TextForm,
|
TextForm,
|
||||||
TrashIcon
|
TrashIcon,
|
||||||
|
Checkbox
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
console.log(this.contentBlock)
|
||||||
return {
|
return {
|
||||||
error: false,
|
error: false,
|
||||||
localContentBlock: Object.assign({}, {
|
localContentBlock: Object.assign({}, {
|
||||||
title: this.contentBlock.title,
|
title: this.contentBlock.title,
|
||||||
contents: [...this.contentBlock.contents],
|
contents: [...this.contentBlock.contents],
|
||||||
id: this.contentBlock.id || undefined,
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
this.$emit('save', this.localContentBlock);
|
this.$emit('save', this.localContentBlock);
|
||||||
|
},
|
||||||
|
setContentBlockType(checked, localContentBlock) {
|
||||||
|
this.localContentBlock.isAssignment = checked;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@
|
||||||
input: {
|
input: {
|
||||||
contentBlock: {
|
contentBlock: {
|
||||||
title: contentBlock.title,
|
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
|
id: contentBlock.id
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,8 @@
|
||||||
input: {
|
input: {
|
||||||
contentBlock: {
|
contentBlock: {
|
||||||
title: contentBlock.title,
|
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,
|
after: this.$store.state.contentBlockPosition.after,
|
||||||
parent: this.$store.state.contentBlockPosition.parent
|
parent: this.$store.state.contentBlockPosition.parent
|
||||||
|
|
|
||||||
|
|
@ -177,9 +177,6 @@
|
||||||
|
|
||||||
.assignment {
|
.assignment {
|
||||||
margin-bottom: 2em;
|
margin-bottom: 2em;
|
||||||
padding: 20px;
|
|
||||||
border-radius: $default-border-radius;
|
|
||||||
background-color: $color-brand-light;
|
|
||||||
|
|
||||||
&__title {
|
&__title {
|
||||||
font-size: toRem(17px);
|
font-size: toRem(17px);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ mutation AddContentBlock($input: AddContentBlockInput!) {
|
||||||
title
|
title
|
||||||
slug
|
slug
|
||||||
contents
|
contents
|
||||||
|
type
|
||||||
}
|
}
|
||||||
errors
|
errors
|
||||||
clientMutationId
|
clientMutationId
|
||||||
|
|
|
||||||
|
|
@ -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
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
@ -6,7 +6,7 @@ from django.db import migrations, models
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('books', '0002_auto_20181010_0825'),
|
('books', '0002_auto_20181011_1345'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from django.core.exceptions import ValidationError
|
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.models import ContentBlock, Chapter, SchoolClass
|
||||||
from books.schema.inputs import ContentBlockInput
|
from books.schema.inputs import ContentBlockInput
|
||||||
from books.schema.queries import ContentBlockNode
|
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):
|
class MutateContentBlock(relay.ClientIDMutation):
|
||||||
|
|
@ -29,9 +32,10 @@ class MutateContentBlock(relay.ClientIDMutation):
|
||||||
title = content_block_data.get('title', None)
|
title = content_block_data.get('title', None)
|
||||||
contents = content_block_data.get('contents', None)
|
contents = content_block_data.get('contents', None)
|
||||||
visibility_list = content_block_data.get('visibility', 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)
|
content_block = get_object(ContentBlock, id_param)
|
||||||
|
logger.info(content_block_data)
|
||||||
if visibility_list is not None:
|
if visibility_list is not None:
|
||||||
for v in visibility_list:
|
for v in visibility_list:
|
||||||
school_class = get_object(SchoolClass, v.school_class_id)
|
school_class = get_object(SchoolClass, v.school_class_id)
|
||||||
|
|
@ -46,6 +50,8 @@ class MutateContentBlock(relay.ClientIDMutation):
|
||||||
if contents is not None:
|
if contents is not None:
|
||||||
content_block.contents = json.dumps([handle_content_block(c, info.context) for c in contents])
|
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()
|
content_block.save()
|
||||||
|
|
||||||
return cls(content_block=content_block)
|
return cls(content_block=content_block)
|
||||||
|
|
@ -74,8 +80,10 @@ class AddContentBlock(relay.ClientIDMutation):
|
||||||
|
|
||||||
title = content_block_data.get('title')
|
title = content_block_data.get('title')
|
||||||
contents = content_block_data.get('contents')
|
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:
|
if parent is not None:
|
||||||
parent_chapter = get_object(Chapter, parent).specific
|
parent_chapter = get_object(Chapter, parent).specific
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import bleach
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from assignments.models import Assignment
|
from assignments.models import Assignment
|
||||||
|
from books.models import ContentBlock
|
||||||
|
|
||||||
|
|
||||||
def newlines_to_paragraphs(text):
|
def newlines_to_paragraphs(text):
|
||||||
|
|
@ -83,3 +84,10 @@ def handle_content_block(content, context, allowed_blocks=ALLOWED_BLOCKS):
|
||||||
}}
|
}}
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def set_user_defined_block_type(block_type):
|
||||||
|
if block_type == ContentBlock.TASK.upper():
|
||||||
|
return ContentBlock.TASK
|
||||||
|
else:
|
||||||
|
return ContentBlock.NORMAL
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ class ContentBlockNode(DjangoObjectType):
|
||||||
def resolve_mine(self, info, **kwargs):
|
def resolve_mine(self, info, **kwargs):
|
||||||
return self.owner is not None and self.owner.pk == info.context.user.pk
|
return self.owner is not None and self.owner.pk == info.context.user.pk
|
||||||
|
|
||||||
|
|
||||||
class ChapterNode(DjangoObjectType):
|
class ChapterNode(DjangoObjectType):
|
||||||
content_blocks = DjangoFilterConnectionField(ContentBlockNode)
|
content_blocks = DjangoFilterConnectionField(ContentBlockNode)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue