Add last visited module to user
This commit is contained in:
parent
b86b1eea37
commit
10b35a5a3e
|
|
@ -7,6 +7,10 @@ fragment UserParts on UserNode {
|
||||||
firstName
|
firstName
|
||||||
lastName
|
lastName
|
||||||
avatar
|
avatar
|
||||||
|
lastModule {
|
||||||
|
id
|
||||||
|
slug
|
||||||
|
}
|
||||||
schoolClasses {
|
schoolClasses {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
class="start-sections__section"
|
class="start-sections__section"
|
||||||
title="Inhalte"
|
title="Inhalte"
|
||||||
subtitle="Neues Wissen erwerben"
|
subtitle="Neues Wissen erwerben"
|
||||||
link-text="Alle Inhalte anzeigen"
|
:link-text="moduleText"
|
||||||
route="/book/topic/geld-und-kauf"
|
:route="moduleRoute"
|
||||||
>
|
>
|
||||||
<contents-illustration></contents-illustration>
|
<contents-illustration></contents-illustration>
|
||||||
</section-block>
|
</section-block>
|
||||||
|
|
@ -53,6 +53,8 @@
|
||||||
import PortfolioIllustration from '@/components/illustrations/PortfolioIllustration';
|
import PortfolioIllustration from '@/components/illustrations/PortfolioIllustration';
|
||||||
import RoomsIllustration from '@/components/illustrations/RoomsIllustration';
|
import RoomsIllustration from '@/components/illustrations/RoomsIllustration';
|
||||||
|
|
||||||
|
import {meQuery} from '@/graphql/queries';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
SectionBlock,
|
SectionBlock,
|
||||||
|
|
@ -62,7 +64,24 @@
|
||||||
RoomsIllustration
|
RoomsIllustration
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {},
|
computed: {
|
||||||
|
moduleRoute() {
|
||||||
|
if (this.me.lastModule && this.me.lastModule.slug) {
|
||||||
|
return `/module/${this.me.lastModule.slug}`;
|
||||||
|
}
|
||||||
|
return '/book/topic/geld-und-kauf';
|
||||||
|
},
|
||||||
|
moduleText() {
|
||||||
|
if (this.me.lastModule && this.me.lastModule.slug) {
|
||||||
|
return 'Aktuelles Modul anzeigen';
|
||||||
|
}
|
||||||
|
return 'Alle Inhalte anzeigen'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
apollo: {
|
||||||
|
me: meQuery
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 2.0.6 on 2019-03-01 09:54
|
||||||
|
|
||||||
|
import assignments.models
|
||||||
|
from django.db import migrations
|
||||||
|
import wagtail.core.blocks
|
||||||
|
import wagtail.core.fields
|
||||||
|
import wagtail.images.blocks
|
||||||
|
import wagtail.snippets.blocks
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('books', '0007_auto_20190205_1529'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='contentblock',
|
||||||
|
name='contents',
|
||||||
|
field=wagtail.core.fields.StreamField([('text_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock())])), ('basic_knowledge', wagtail.core.blocks.StructBlock([('description', wagtail.core.blocks.RichTextBlock()), ('basic_knowledge', wagtail.core.blocks.PageChooserBlock(required=True, target_model=['basicknowledge.BasicKnowledge']))])), ('assignment', wagtail.core.blocks.StructBlock([('assignment_id', wagtail.snippets.blocks.SnippetChooserBlock(assignments.models.Assignment))])), ('image_block', wagtail.images.blocks.ImageChooserBlock()), ('image_url_block', wagtail.core.blocks.StructBlock([('title', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('link_block', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.TextBlock()), ('url', wagtail.core.blocks.URLBlock())])), ('solution', wagtail.core.blocks.StructBlock([('text', wagtail.core.blocks.RichTextBlock())], icon='tick')), ('video_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('document_block', wagtail.core.blocks.StructBlock([('url', wagtail.core.blocks.URLBlock())])), ('infogram_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock()), ('title', wagtail.core.blocks.TextBlock())])), ('genially_block', wagtail.core.blocks.StructBlock([('id', wagtail.core.blocks.TextBlock())]))], blank=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -199,12 +199,21 @@ class BookQuery(object):
|
||||||
def resolve_module(self, info, **kwargs):
|
def resolve_module(self, info, **kwargs):
|
||||||
slug = kwargs.get('slug')
|
slug = kwargs.get('slug')
|
||||||
id = kwargs.get('id')
|
id = kwargs.get('id')
|
||||||
|
# save last visited module in user
|
||||||
|
user = info.context.user
|
||||||
|
module = None
|
||||||
|
|
||||||
if id is not None:
|
if id is not None:
|
||||||
return get_object(Module, id)
|
module = get_object(Module, id)
|
||||||
if slug is not None:
|
|
||||||
return Module.objects.get(slug=slug)
|
elif slug is not None:
|
||||||
return None
|
module = Module.objects.get(slug=slug)
|
||||||
|
|
||||||
|
if module is not None:
|
||||||
|
user.last_module = module
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
return module
|
||||||
|
|
||||||
def resolve_topic(self, info, **kwargs):
|
def resolve_topic(self, info, **kwargs):
|
||||||
slug = kwargs.get('slug')
|
slug = kwargs.get('slug')
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Generated by Django 2.0.6 on 2019-03-01 09:54
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('books', '0008_auto_20190301_0954'),
|
||||||
|
('users', '0002_auto_20181017_1340'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='user',
|
||||||
|
name='last_module',
|
||||||
|
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='books.Module'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -11,6 +11,8 @@ DEFAULT_SCHOOL_ID = 1
|
||||||
|
|
||||||
|
|
||||||
class User(AbstractUser):
|
class User(AbstractUser):
|
||||||
|
last_module = models.ForeignKey('books.Module', related_name='+', on_delete=models.SET_NULL, null=True)
|
||||||
|
|
||||||
def get_role_permissions(self):
|
def get_role_permissions(self):
|
||||||
perms = set()
|
perms = set()
|
||||||
for role in Role.objects.get_roles_for_user(self):
|
for role in Role.objects.get_roles_for_user(self):
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class UserNode(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
filter_fields = ['username', 'email']
|
filter_fields = ['username', 'email']
|
||||||
only_fields = ['username', 'email', 'first_name', 'last_name', 'school_classes', ]
|
only_fields = ['username', 'email', 'first_name', 'last_name', 'school_classes', 'last_module']
|
||||||
interfaces = (relay.Node,)
|
interfaces = (relay.Node,)
|
||||||
|
|
||||||
def resolve_pk(self, info, **kwargs):
|
def resolve_pk(self, info, **kwargs):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue