diff --git a/client/src/graphql/gql/fragments/contentBlockParts.gql b/client/src/graphql/gql/fragments/contentBlockParts.gql index 229c87cc..ec389fc3 100644 --- a/client/src/graphql/gql/fragments/contentBlockParts.gql +++ b/client/src/graphql/gql/fragments/contentBlockParts.gql @@ -6,6 +6,7 @@ fragment ContentBlockParts on ContentBlockNode { contents userCreated mine + highlights hiddenFor { edges { node { diff --git a/server/books/migrations/0015_contentblock_highlights.py b/server/books/migrations/0015_contentblock_highlights.py new file mode 100644 index 00000000..c56d12bf --- /dev/null +++ b/server/books/migrations/0015_contentblock_highlights.py @@ -0,0 +1,21 @@ +# Generated by Django 2.0.6 on 2019-10-01 13:25 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('notes', '0001_initial'), + ('books', '0014_auto_20190912_1228'), + ] + + operations = [ + migrations.AddField( + model_name='contentblock', + name='highlights', + field=models.ManyToManyField(related_name='highlighted_content_blocks', through='notes.ContentBlockHighlight', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/server/books/models/contentblock.py b/server/books/models/contentblock.py index f8e1ca3f..5eafff98 100644 --- a/server/books/models/contentblock.py +++ b/server/books/models/contentblock.py @@ -10,8 +10,9 @@ from books.blocks import TextBlock, BasicKnowledgeBlock, LinkBlock, VideoBlock, ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock, ModuleRoomSlugBlock from books.utils import get_type_and_value from core.wagtail_utils import StrictHierarchyPage +from notes.models import Highlight, ContentBlockHighlight from surveys.models import Survey -from users.models import SchoolClass +from users.models import SchoolClass, User logger = logging.getLogger(__name__) @@ -33,10 +34,14 @@ class ContentBlock(StrictHierarchyPage): (BASE_SOCIETY, 'Instrument Gesellschaft'), ) + # blocks without owner are visible by default, need to be hidden for each class hidden_for = models.ManyToManyField(SchoolClass, related_name='hidden_content_blocks') + # blocks with owner are hidden by default, need to be shown for each class visible_for = models.ManyToManyField(SchoolClass, related_name='visible_content_blocks') user_created = models.BooleanField(default=False) + highlights = models.ManyToManyField(User, through=ContentBlockHighlight, related_name='highlighted_content_blocks') + content_blocks = [ ('text_block', TextBlock()), ('basic_knowledge', BasicKnowledgeBlock()), diff --git a/server/books/schema/queries.py b/server/books/schema/queries.py index c184e509..94881356 100644 --- a/server/books/schema/queries.py +++ b/server/books/schema/queries.py @@ -5,6 +5,7 @@ from graphene_django.filter import DjangoFilterConnectionField from api.utils import get_object from books.utils import are_solutions_enabled_for +from notes.models import ContentBlockHighlight from rooms.models import ModuleRoomSlug from ..models import Book, Topic, Module, Chapter, ContentBlock @@ -24,6 +25,7 @@ def process_module_room_slug_block(content): class ContentBlockNode(DjangoObjectType): mine = graphene.Boolean() + highlights = graphene.List(graphene.String) class Meta: model = ContentBlock @@ -54,6 +56,12 @@ class ContentBlockNode(DjangoObjectType): self.contents.stream_data = updated_stream_data return self.contents + def resolve_highlights(self, info, **kwargs): + return [highlight.id for highlight in ContentBlockHighlight.objects.filter( + user=info.context.user, + content_block=self + )] + class ChapterNode(DjangoObjectType): content_blocks = DjangoFilterConnectionField(ContentBlockNode) diff --git a/server/core/settings.py b/server/core/settings.py index 8437b685..9131a58a 100644 --- a/server/core/settings.py +++ b/server/core/settings.py @@ -54,6 +54,7 @@ INSTALLED_APPS = [ 'portfolio', 'statistics', 'surveys', + 'notes', 'wagtail.contrib.forms', 'wagtail.contrib.redirects', diff --git a/server/notes/__init__.py b/server/notes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/server/notes/admin.py b/server/notes/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/server/notes/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/server/notes/apps.py b/server/notes/apps.py new file mode 100644 index 00000000..b6155aca --- /dev/null +++ b/server/notes/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NotesConfig(AppConfig): + name = 'notes' diff --git a/server/notes/migrations/0001_initial.py b/server/notes/migrations/0001_initial.py new file mode 100644 index 00000000..83165dd3 --- /dev/null +++ b/server/notes/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 2.0.6 on 2019-10-01 13:25 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('books', '0014_auto_20190912_1228'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='ContentBlockHighlight', + fields=[ + ('id', models.UUIDField(primary_key=True, serialize=False)), + ('content_block', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='books.ContentBlock')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/server/notes/migrations/__init__.py b/server/notes/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/server/notes/models.py b/server/notes/models.py new file mode 100644 index 00000000..e01d9a25 --- /dev/null +++ b/server/notes/models.py @@ -0,0 +1,18 @@ +from django.db import models + +# Create your models here. +from core.wagtail_utils import StrictHierarchyPage +from users.models import User + + +# todo: change from Highlight to Bookmark / Note (tbd) +class Highlight(models.Model): + id = models.UUIDField(primary_key=True) + user = models.ForeignKey(User, on_delete=models.CASCADE) + + class Meta: + abstract = True + + +class ContentBlockHighlight(Highlight): + content_block = models.ForeignKey('books.ContentBlock', on_delete=models.CASCADE) diff --git a/server/notes/tests.py b/server/notes/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/server/notes/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/server/notes/views.py b/server/notes/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/server/notes/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here.