diff --git a/server/notes/inputs.py b/server/notes/inputs.py index a764392f..d1f1c72c 100644 --- a/server/notes/inputs.py +++ b/server/notes/inputs.py @@ -16,7 +16,7 @@ class UpdateNoteArgument(InputObjectType): class AddHighlightArgument(InputObjectType): - content_block = graphene.String(required=True) + page = graphene.String(required=True) content_index = graphene.Int(required=True) content_uuid = graphene.UUID(required=True) paragraph_index = graphene.Int(required=True) diff --git a/server/notes/models.py b/server/notes/models.py index 72b49d75..1a2e9825 100644 --- a/server/notes/models.py +++ b/server/notes/models.py @@ -1,8 +1,8 @@ from django.db import models # Create your models here. -from core.wagtail_utils import StrictHierarchyPage from users.models import User +from wagtail.models import Page class Note(models.Model): @@ -55,9 +55,7 @@ class InstrumentBookmark(Bookmark): class Highlight(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) - content_block = models.ForeignKey( - "books.ContentBlock", on_delete=models.CASCADE, related_name="highlights" - ) + page = models.ForeignKey(Page, on_delete=models.CASCADE, related_name="highlights") # see highlight.ts for comments content_index = models.IntegerField() content_uuid = models.UUIDField() diff --git a/server/notes/mutations.py b/server/notes/mutations.py index 02c92c28..8dc75134 100644 --- a/server/notes/mutations.py +++ b/server/notes/mutations.py @@ -285,7 +285,7 @@ class AddHighlight(relay.ClientIDMutation): if highlight is None: raise Exception("No highlight provided, should not happen") - content_block_id = highlight.get("content_block") + page_id = highlight.get("page") content_index = highlight.get("content_index") content_uuid = highlight.get("content_uuid") paragraph_index = highlight.get("paragraph_index") @@ -294,10 +294,16 @@ class AddHighlight(relay.ClientIDMutation): selection_length = highlight.get("selection_length") color = highlight.get("color") - content_block = get_object(ContentBlock, content_block_id) + page_type, page_id = from_global_id(page_id) + if page_type == "ContentBlockNode": + page = ContentBlock.objects.get(id=page_id) + elif page_type == "InstrumentNode": + page = BasicKnowledge.objects.get(id=page_id) + else: + raise Exception("wrong type") new_highlight = Highlight.objects.create( - content_block=content_block, + page=page, user=user, content_index=content_index, content_uuid=content_uuid, diff --git a/server/notes/schema.py b/server/notes/schema.py index eeba20bf..f5fb7ef1 100644 --- a/server/notes/schema.py +++ b/server/notes/schema.py @@ -1,14 +1,15 @@ import graphene +from basicknowledge.queries import InstrumentNode +from books.schema.nodes.content import ContentBlockNode from graphene import relay from graphene_django import DjangoObjectType - from notes.models import ( - Highlight, - Note, - ContentBlockBookmark, - ModuleBookmark, ChapterBookmark, + ContentBlockBookmark, + Highlight, InstrumentBookmark, + ModuleBookmark, + Note, ) @@ -64,7 +65,14 @@ class InstrumentBookmarkNode(DjangoObjectType): interfaces = (relay.Node,) +class HighlightableNode(graphene.Union): + class Meta: + types = (ContentBlockNode, InstrumentNode) + + class HighlightNode(DjangoObjectType): + page = graphene.Field(HighlightableNode) + class Meta: model = Highlight fields = "__all__" diff --git a/server/schema.graphql b/server/schema.graphql index a1dc5c6b..b6b4cd0e 100644 --- a/server/schema.graphql +++ b/server/schema.graphql @@ -599,6 +599,7 @@ type InstrumentNode implements Node { bookmarks: [InstrumentBookmarkNode] type: InstrumentTypeNode language: String + highlights: [HighlightNode] } type InstrumentTypeNode implements Node { @@ -622,7 +623,7 @@ type HighlightNode implements Node { """The ID of the object""" id: ID! user: PrivateUserNode! - contentBlock: ContentBlockNode! + page: HighlightableNode contentIndex: Int! contentUuid: UUID! paragraphIndex: Int! @@ -633,6 +634,8 @@ type HighlightNode implements Node { color: String! } +union HighlightableNode = ContentBlockNode | InstrumentNode + type SnapshotObjectiveGroupNode implements Node { """The ID of the object""" id: ID! @@ -1150,7 +1153,7 @@ input AddHighlightInput { } input AddHighlightArgument { - contentBlock: String! + page: String! contentIndex: Int! contentUuid: UUID! paragraphIndex: Int!