Add node for notes

This commit is contained in:
Ramon Wenger 2019-10-12 08:51:28 +02:00
parent 67cfc4b572
commit 62460d58ab
8 changed files with 25 additions and 85 deletions

View File

@ -57,7 +57,7 @@
computed: {
bookmarked() {
return this.bookmarks.indexOf(this.component.id) > -1;
return !!this.bookmarks.find(bookmark => bookmark.uuid === this.component.id);
}
},
@ -68,12 +68,12 @@
contentBlock: this.parent
});
},
bookmarkContent(id, bookmarked) {
bookmarkContent(uuid, bookmarked) {
this.$apollo.mutate({
mutation: UPDATE_CONTENT_BOOKMARK,
variables: {
input: {
id,
uuid,
contentBlock: this.parent,
bookmarked
}

View File

@ -6,7 +6,13 @@ fragment ContentBlockParts on ContentBlockNode {
contents
userCreated
mine
bookmarks
bookmarks {
uuid
note {
id
text
}
}
hiddenFor {
edges {
node {

View File

@ -1,21 +0,0 @@
# Generated by Django 2.0.6 on 2019-10-07 14:53
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='bookmarks',
field=models.ManyToManyField(related_name='bookmarked_content_blocks', through='notes.ContentBlockBookmark', to=settings.AUTH_USER_MODEL),
),
]

View File

@ -6,6 +6,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 ContentBlockBookmark
from notes.schema import ContentBlockBookmarkNode
from rooms.models import ModuleRoomSlug
from ..models import Book, Topic, Module, Chapter, ContentBlock
@ -25,7 +26,7 @@ def process_module_room_slug_block(content):
class ContentBlockNode(DjangoObjectType):
mine = graphene.Boolean()
bookmarks = graphene.List(graphene.String)
bookmarks = graphene.List(ContentBlockBookmarkNode)
class Meta:
model = ContentBlock
@ -57,10 +58,10 @@ class ContentBlockNode(DjangoObjectType):
return self.contents
def resolve_bookmarks(self, info, **kwargs):
return [bookmark.id for bookmark in ContentBlockBookmark.objects.filter(
return ContentBlockBookmark.objects.filter(
user=info.context.user,
content_block=self
)]
)
class ChapterNode(DjangoObjectType):

View File

@ -1,29 +0,0 @@
# Generated by Django 2.0.6 on 2019-10-07 14:53
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='ContentBlockBookmark',
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,
},
),
]

View File

@ -1,26 +0,0 @@
# Generated by Django 2.0.6 on 2019-10-09 09:19
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('notes', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Note',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.TextField()),
],
),
migrations.AddField(
model_name='contentblockbookmark',
name='note',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.SET_NULL, to='notes.Note'),
),
]

View File

@ -10,7 +10,7 @@ class Note(models.Model):
class Bookmark(models.Model):
id = models.UUIDField(primary_key=True)
uuid = models.UUIDField(unique=True)
user = models.ForeignKey(User, on_delete=models.CASCADE)
note = models.OneToOneField(Note, null=True, on_delete=models.SET_NULL)

View File

@ -2,7 +2,7 @@ import graphene
from graphene import relay
from graphene_django import DjangoObjectType
from notes.models import Note
from notes.models import Note, ContentBlockBookmark
class NoteNode(DjangoObjectType):
@ -14,3 +14,12 @@ class NoteNode(DjangoObjectType):
def resolve_pk(self, *args, **kwargs):
return self.id
class ContentBlockBookmarkNode(DjangoObjectType):
# note = graphene.
uuid = graphene.UUID()
note = graphene.Field(NoteNode)
class Meta:
model = ContentBlockBookmark