Refactor highlight model to use a generic page instead of a content
block
This commit is contained in:
parent
238be6cf4f
commit
b329427df8
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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__"
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
|
|||
Loading…
Reference in New Issue