From a1a75e9b3f69e6693e9cc6a8878e857ce3bbb01c Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Mon, 15 Oct 2018 13:59:48 +0200 Subject: [PATCH 1/6] rename types of Contentblocks, change box appearance --- client/src/components/ContentBlock.vue | 17 +++++---- client/src/components/content-blocks/Task.vue | 2 +- client/src/styles/_mixins.scss | 12 ++++++ server/books/factories.py | 2 +- .../migrations/0003_auto_20181015_0915.py | 18 +++++++++ server/books/models/contentblock.py | 18 ++++----- server/core/management/commands/dummy_data.py | 38 +++++++++---------- 7 files changed, 70 insertions(+), 37 deletions(-) create mode 100644 server/books/migrations/0003_auto_20181015_0915.py diff --git a/client/src/components/ContentBlock.vue b/client/src/components/ContentBlock.vue index 3f8aaa7f..9a8624da 100644 --- a/client/src/components/ContentBlock.vue +++ b/client/src/components/ContentBlock.vue @@ -136,6 +136,7 @@ diff --git a/client/src/styles/_mixins.scss b/client/src/styles/_mixins.scss index a6e5d917..8d7e202c 100644 --- a/client/src/styles/_mixins.scss +++ b/client/src/styles/_mixins.scss @@ -32,3 +32,15 @@ } } + +@mixin content-box($main-color) { + background-color: rgba($main-color, 0.15); + padding: 15px; + align-items: start; + border-radius: $default-border-radius; + + /deep/ .button { + border-color: $main-color; + background-color: $color-white; + } +} diff --git a/server/books/factories.py b/server/books/factories.py index c13fb548..f647e856 100644 --- a/server/books/factories.py +++ b/server/books/factories.py @@ -93,7 +93,7 @@ class ContentBlockFactory(BasePageFactory): class Meta: model = ContentBlock - type = factory.LazyAttribute(lambda x: random.choice(['plain', 'yellow', 'green', 'blue'])) + type = factory.LazyAttribute(lambda x: random.choice(['normal', 'base_communication', 'task', 'base_society'])) contents = wagtail_factories.StreamFieldFactory({ 'text_block': TextBlockFactory, diff --git a/server/books/migrations/0003_auto_20181015_0915.py b/server/books/migrations/0003_auto_20181015_0915.py new file mode 100644 index 00000000..4d0646c1 --- /dev/null +++ b/server/books/migrations/0003_auto_20181015_0915.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.6 on 2018-10-15 09:15 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('books', '0002_auto_20181010_0825'), + ] + + operations = [ + migrations.AlterField( + model_name='contentblock', + name='type', + field=models.CharField(choices=[('normal', 'Normal'), ('base_communication', 'Basiswissen Sprache & Kommunikation'), ('task', 'Aufgabe'), ('base_society', 'Basiswissen Gesellschaft')], default='normal', max_length=100), + ), + ] diff --git a/server/books/models/contentblock.py b/server/books/models/contentblock.py index 34c5cb47..34b2204d 100644 --- a/server/books/models/contentblock.py +++ b/server/books/models/contentblock.py @@ -19,16 +19,16 @@ class ContentBlock(StrictHierarchyPage): verbose_name = 'Inhaltsblock' verbose_name_plural = 'Inhaltsblöcke' - PLAIN = 'plain' - YELLOW = 'yellow' - GREEN = 'green' - BLUE = 'blue' + NORMAL = 'normal' + BASE_COMMUNICATION = 'base_communication' + TASK = 'task' + BASE_SOCIETY = 'base_society' TYPE_CHOICES = ( - (PLAIN, 'Normal'), - (YELLOW, 'Gelb'), - (GREEN, 'Grün'), - (BLUE, 'Blau'), + (NORMAL, 'Normal'), + (BASE_COMMUNICATION, 'Basiswissen Sprache & Kommunikation'), + (TASK, 'Aufgabe'), + (BASE_SOCIETY, 'Basiswissen Gesellschaft'), ) hidden_for = models.ManyToManyField(SchoolClass, related_name='hidden_content_blocks') @@ -50,7 +50,7 @@ class ContentBlock(StrictHierarchyPage): type = models.CharField( max_length=100, choices=TYPE_CHOICES, - default=PLAIN + default=NORMAL ) content_panels = [ diff --git a/server/core/management/commands/dummy_data.py b/server/core/management/commands/dummy_data.py index 95d573e5..e75b0a34 100644 --- a/server/core/management/commands/dummy_data.py +++ b/server/core/management/commands/dummy_data.py @@ -83,7 +83,7 @@ data = [ 'title': '1.1 Lehrbeginn', 'content_blocks': [ { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 1', 'contents': [ { @@ -102,7 +102,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 2', 'contents': [ { @@ -139,7 +139,7 @@ data = [ ] }, { - 'type': 'yellow', + 'type': 'base_communication', 'title': 'Das Interview', 'contents': [ { @@ -151,7 +151,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 3', 'contents': [ { @@ -175,7 +175,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 4', 'contents': [ { @@ -199,7 +199,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'normal', 'title': 'Tipp', 'contents': [ { @@ -216,7 +216,7 @@ data = [ 'title': '1.2 Die drei Lernorte', 'content_blocks': [ { - 'type': 'blue', + 'type': 'base_society', 'title': 'Das Berufsbildungssystem', 'contents': [ { @@ -246,7 +246,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 5', 'contents': [ { @@ -271,7 +271,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 6', 'contents': [ { @@ -283,7 +283,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 7', 'contents': [ { @@ -325,7 +325,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 8', 'contents': [ { @@ -381,7 +381,7 @@ data = [ 'title': '2.1 Eine Welt ohne Geld?', 'content_blocks': [ { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 1', 'contents': [ { @@ -433,7 +433,7 @@ data = [ 'title': '2.2 Geld regiert die Welt', 'content_blocks': [ { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 2', 'contents': [ { @@ -493,7 +493,7 @@ data = [ 'title': '2.3 Funktionen der Geschäftsbanken', 'content_blocks': [ { - 'type': 'yellow', + 'type': 'base_communication', 'title': 'Basiswissen: Notizen', 'contents': [ { @@ -505,7 +505,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 3', 'contents': [ { @@ -535,7 +535,7 @@ data = [ 'title': '2.4 Geld aufbewahren', 'content_blocks': [ { - 'type': 'yellow', + 'type': 'base_communication', 'title': 'Basiswissen: Geldanlage', 'contents': [ { @@ -547,7 +547,7 @@ data = [ ] }, { - 'type': 'yellow', + 'type': 'base_communication', 'title': 'Basiswissen: Anlageformen', 'contents': [ { @@ -559,7 +559,7 @@ data = [ ] }, { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 4', 'contents': [ { @@ -608,7 +608,7 @@ data = [ 'title': '2.5 Geldinstitute im Vergleich', 'content_blocks': [ { - 'type': 'plain', + 'type': 'task', 'title': 'Auftrag 5', 'contents': [ { From 3547a30228b06a4abc984bc690cf60128f3ec485 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 16 Oct 2018 07:29:41 +0200 Subject: [PATCH 2/6] allow user to set block type --- .../content-block-form/ContentsForm.vue | 17 ++++++++++++++--- .../EditContentBlockWizard.vue | 3 ++- .../NewContentBlockWizard.vue | 3 ++- .../content-blocks/assignment/Assignment.vue | 3 --- .../graphql/gql/mutations/addContentBlock.gql | 1 + ...81015_0915.py => 0003_auto_20181015_1202.py} | 4 ++-- server/books/schema/mutations/contentblock.py | 14 +++++++++++--- server/books/schema/mutations/utils.py | 8 ++++++++ server/books/schema/queries.py | 1 + 9 files changed, 41 insertions(+), 13 deletions(-) rename server/books/migrations/{0003_auto_20181015_0915.py => 0003_auto_20181015_1202.py} (83%) diff --git a/client/src/components/content-block-form/ContentsForm.vue b/client/src/components/content-block-form/ContentsForm.vue index c6b29123..9acb063e 100644 --- a/client/src/components/content-block-form/ContentsForm.vue +++ b/client/src/components/content-block-form/ContentsForm.vue @@ -5,7 +5,11 @@ :placeholder="titlePlaceholder" :value="localContentBlock.title" :error="error"> - + @@ -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; } } } diff --git a/client/src/components/content-block-form/EditContentBlockWizard.vue b/client/src/components/content-block-form/EditContentBlockWizard.vue index b7dbcaa0..705994bd 100644 --- a/client/src/components/content-block-form/EditContentBlockWizard.vue +++ b/client/src/components/content-block-form/EditContentBlockWizard.vue @@ -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 } diff --git a/client/src/components/content-block-form/NewContentBlockWizard.vue b/client/src/components/content-block-form/NewContentBlockWizard.vue index cda054b3..fe7bfb7f 100644 --- a/client/src/components/content-block-form/NewContentBlockWizard.vue +++ b/client/src/components/content-block-form/NewContentBlockWizard.vue @@ -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 diff --git a/client/src/components/content-blocks/assignment/Assignment.vue b/client/src/components/content-blocks/assignment/Assignment.vue index 486d5559..dbeebb96 100644 --- a/client/src/components/content-blocks/assignment/Assignment.vue +++ b/client/src/components/content-blocks/assignment/Assignment.vue @@ -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); diff --git a/client/src/graphql/gql/mutations/addContentBlock.gql b/client/src/graphql/gql/mutations/addContentBlock.gql index 03fef5c1..f6359991 100644 --- a/client/src/graphql/gql/mutations/addContentBlock.gql +++ b/client/src/graphql/gql/mutations/addContentBlock.gql @@ -5,6 +5,7 @@ mutation AddContentBlock($input: AddContentBlockInput!) { title slug contents + type } errors clientMutationId diff --git a/server/books/migrations/0003_auto_20181015_0915.py b/server/books/migrations/0003_auto_20181015_1202.py similarity index 83% rename from server/books/migrations/0003_auto_20181015_0915.py rename to server/books/migrations/0003_auto_20181015_1202.py index 4d0646c1..1508dd27 100644 --- a/server/books/migrations/0003_auto_20181015_0915.py +++ b/server/books/migrations/0003_auto_20181015_1202.py @@ -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 = [ diff --git a/server/books/schema/mutations/contentblock.py b/server/books/schema/mutations/contentblock.py index ec18717c..abe81677 100644 --- a/server/books/schema/mutations/contentblock.py +++ b/server/books/schema/mutations/contentblock.py @@ -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 diff --git a/server/books/schema/mutations/utils.py b/server/books/schema/mutations/utils.py index 4775fb35..812f5302 100644 --- a/server/books/schema/mutations/utils.py +++ b/server/books/schema/mutations/utils.py @@ -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 diff --git a/server/books/schema/queries.py b/server/books/schema/queries.py index 146fe0e8..b2a1b385 100644 --- a/server/books/schema/queries.py +++ b/server/books/schema/queries.py @@ -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) From 0db89c116d3fb6bd86ee532ee92828bb796f7a94 Mon Sep 17 00:00:00 2001 From: Christian Cueni Date: Tue, 16 Oct 2018 15:28:18 +0200 Subject: [PATCH 3/6] style checkbox, refactor task assignment --- client/src/components/content-block-form/ContentsForm.vue | 6 +++++- .../content-block-form/EditContentBlockWizard.vue | 3 ++- .../content-block-form/NewContentBlockWizard.vue | 4 ++-- client/src/graphql/gql/mutations/addContentBlock.gql | 8 +++----- client/src/graphql/gql/mutations/mutateContentBlock.gql | 1 + client/src/helpers/content-block.js | 3 +++ 6 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 client/src/helpers/content-block.js diff --git a/client/src/components/content-block-form/ContentsForm.vue b/client/src/components/content-block-form/ContentsForm.vue index 9acb063e..a864489e 100644 --- a/client/src/components/content-block-form/ContentsForm.vue +++ b/client/src/components/content-block-form/ContentsForm.vue @@ -9,6 +9,7 @@ :item="localContentBlock" :label="'Aufgabe'" @input="setContentBlockType" + class="contents-form__task" > diff --git a/client/src/components/content-block-form/EditContentBlockWizard.vue b/client/src/components/content-block-form/EditContentBlockWizard.vue index 705994bd..7b13dff3 100644 --- a/client/src/components/content-block-form/EditContentBlockWizard.vue +++ b/client/src/components/content-block-form/EditContentBlockWizard.vue @@ -14,6 +14,7 @@ import EDIT_CONTENT_BLOCK_MUTATION from '@/graphql/gql/mutations/mutateContentBlock.gql'; import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql'; import CONTENT_BLOCK_QUERY from '@/graphql/gql/contentBlockQuery.gql'; + import { setUserBlockType } from '@/helpers/content-block' export default { components: { @@ -33,7 +34,7 @@ contentBlock: { title: contentBlock.title, contents: contentBlock.contents.filter(value => Object.keys(value).length > 0), - type: contentBlock.isAssignment ? 'TASK' : 'NORMAL' + type: setUserBlockType(contentBlock.isAssignment) }, id: contentBlock.id } diff --git a/client/src/components/content-block-form/NewContentBlockWizard.vue b/client/src/components/content-block-form/NewContentBlockWizard.vue index fe7bfb7f..ad482278 100644 --- a/client/src/components/content-block-form/NewContentBlockWizard.vue +++ b/client/src/components/content-block-form/NewContentBlockWizard.vue @@ -8,11 +8,11 @@