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):
|
class AddHighlightArgument(InputObjectType):
|
||||||
content_block = graphene.String(required=True)
|
page = graphene.String(required=True)
|
||||||
content_index = graphene.Int(required=True)
|
content_index = graphene.Int(required=True)
|
||||||
content_uuid = graphene.UUID(required=True)
|
content_uuid = graphene.UUID(required=True)
|
||||||
paragraph_index = graphene.Int(required=True)
|
paragraph_index = graphene.Int(required=True)
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
from core.wagtail_utils import StrictHierarchyPage
|
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
from wagtail.models import Page
|
||||||
|
|
||||||
|
|
||||||
class Note(models.Model):
|
class Note(models.Model):
|
||||||
|
|
@ -55,9 +55,7 @@ class InstrumentBookmark(Bookmark):
|
||||||
|
|
||||||
class Highlight(models.Model):
|
class Highlight(models.Model):
|
||||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||||
content_block = models.ForeignKey(
|
page = models.ForeignKey(Page, on_delete=models.CASCADE, related_name="highlights")
|
||||||
"books.ContentBlock", on_delete=models.CASCADE, related_name="highlights"
|
|
||||||
)
|
|
||||||
# see highlight.ts for comments
|
# see highlight.ts for comments
|
||||||
content_index = models.IntegerField()
|
content_index = models.IntegerField()
|
||||||
content_uuid = models.UUIDField()
|
content_uuid = models.UUIDField()
|
||||||
|
|
|
||||||
|
|
@ -285,7 +285,7 @@ class AddHighlight(relay.ClientIDMutation):
|
||||||
if highlight is None:
|
if highlight is None:
|
||||||
raise Exception("No highlight provided, should not happen")
|
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_index = highlight.get("content_index")
|
||||||
content_uuid = highlight.get("content_uuid")
|
content_uuid = highlight.get("content_uuid")
|
||||||
paragraph_index = highlight.get("paragraph_index")
|
paragraph_index = highlight.get("paragraph_index")
|
||||||
|
|
@ -294,10 +294,16 @@ class AddHighlight(relay.ClientIDMutation):
|
||||||
selection_length = highlight.get("selection_length")
|
selection_length = highlight.get("selection_length")
|
||||||
color = highlight.get("color")
|
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(
|
new_highlight = Highlight.objects.create(
|
||||||
content_block=content_block,
|
page=page,
|
||||||
user=user,
|
user=user,
|
||||||
content_index=content_index,
|
content_index=content_index,
|
||||||
content_uuid=content_uuid,
|
content_uuid=content_uuid,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
import graphene
|
import graphene
|
||||||
|
from basicknowledge.queries import InstrumentNode
|
||||||
|
from books.schema.nodes.content import ContentBlockNode
|
||||||
from graphene import relay
|
from graphene import relay
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
|
|
||||||
from notes.models import (
|
from notes.models import (
|
||||||
Highlight,
|
|
||||||
Note,
|
|
||||||
ContentBlockBookmark,
|
|
||||||
ModuleBookmark,
|
|
||||||
ChapterBookmark,
|
ChapterBookmark,
|
||||||
|
ContentBlockBookmark,
|
||||||
|
Highlight,
|
||||||
InstrumentBookmark,
|
InstrumentBookmark,
|
||||||
|
ModuleBookmark,
|
||||||
|
Note,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -64,7 +65,14 @@ class InstrumentBookmarkNode(DjangoObjectType):
|
||||||
interfaces = (relay.Node,)
|
interfaces = (relay.Node,)
|
||||||
|
|
||||||
|
|
||||||
|
class HighlightableNode(graphene.Union):
|
||||||
|
class Meta:
|
||||||
|
types = (ContentBlockNode, InstrumentNode)
|
||||||
|
|
||||||
|
|
||||||
class HighlightNode(DjangoObjectType):
|
class HighlightNode(DjangoObjectType):
|
||||||
|
page = graphene.Field(HighlightableNode)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Highlight
|
model = Highlight
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
|
|
||||||
|
|
@ -599,6 +599,7 @@ type InstrumentNode implements Node {
|
||||||
bookmarks: [InstrumentBookmarkNode]
|
bookmarks: [InstrumentBookmarkNode]
|
||||||
type: InstrumentTypeNode
|
type: InstrumentTypeNode
|
||||||
language: String
|
language: String
|
||||||
|
highlights: [HighlightNode]
|
||||||
}
|
}
|
||||||
|
|
||||||
type InstrumentTypeNode implements Node {
|
type InstrumentTypeNode implements Node {
|
||||||
|
|
@ -622,7 +623,7 @@ type HighlightNode implements Node {
|
||||||
"""The ID of the object"""
|
"""The ID of the object"""
|
||||||
id: ID!
|
id: ID!
|
||||||
user: PrivateUserNode!
|
user: PrivateUserNode!
|
||||||
contentBlock: ContentBlockNode!
|
page: HighlightableNode
|
||||||
contentIndex: Int!
|
contentIndex: Int!
|
||||||
contentUuid: UUID!
|
contentUuid: UUID!
|
||||||
paragraphIndex: Int!
|
paragraphIndex: Int!
|
||||||
|
|
@ -633,6 +634,8 @@ type HighlightNode implements Node {
|
||||||
color: String!
|
color: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
union HighlightableNode = ContentBlockNode | InstrumentNode
|
||||||
|
|
||||||
type SnapshotObjectiveGroupNode implements Node {
|
type SnapshotObjectiveGroupNode implements Node {
|
||||||
"""The ID of the object"""
|
"""The ID of the object"""
|
||||||
id: ID!
|
id: ID!
|
||||||
|
|
@ -1150,7 +1153,7 @@ input AddHighlightInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
input AddHighlightArgument {
|
input AddHighlightArgument {
|
||||||
contentBlock: String!
|
page: String!
|
||||||
contentIndex: Int!
|
contentIndex: Int!
|
||||||
contentUuid: UUID!
|
contentUuid: UUID!
|
||||||
paragraphIndex: Int!
|
paragraphIndex: Int!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue