Add snapshot creator and created date
This commit is contained in:
parent
08ddd58132
commit
cde5e8d964
|
|
@ -8336,6 +8336,11 @@
|
|||
"integrity": "sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI=",
|
||||
"dev": true
|
||||
},
|
||||
"dayjs": {
|
||||
"version": "1.10.4",
|
||||
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.10.4.tgz",
|
||||
"integrity": "sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw=="
|
||||
},
|
||||
"de-indent": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz",
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@
|
|||
"chalk": "^2.0.1",
|
||||
"copy-webpack-plugin": "^4.0.1",
|
||||
"css-loader": "^0.28.0",
|
||||
"dayjs": "^1.10.4",
|
||||
"debounce": "^1.2.0",
|
||||
"eslint": "^4.15.0",
|
||||
"eslint-config-standard": "^10.2.1",
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<div class="snapshot-created__content">
|
||||
<div class="snapshot-created__entry">
|
||||
<span class="snapshot-created__title">{{ snapshot.title }}</span>
|
||||
<span class="snapshot-created__meta">30.11.2020 - 17:31 - Simone Gerber</span>
|
||||
<span class="snapshot-created__meta">{{ created }} - {{ snapshot.creator.firstName }} {{ snapshot.creator.lastName }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div slot="footer">
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
<script>
|
||||
import Modal from '@/components/Modal';
|
||||
import {SNAPSHOT_LIST} from '@/router/module.names';
|
||||
import dateformat from '@/helpers/date-format';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
|
|
@ -43,6 +44,9 @@
|
|||
computed: {
|
||||
snapshot() {
|
||||
return this.$modal.state.payload.snapshot;
|
||||
},
|
||||
created() {
|
||||
return dateformat(this.snapshot.created);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -3,16 +3,28 @@
|
|||
<span
|
||||
class="snapshot-list-item__title"
|
||||
v-html="snapshot.title"/>
|
||||
<span
|
||||
class="snapshot-list-item__date"
|
||||
v-html="created" />
|
||||
<a class="snapshot-list-item__link">Mit Team teilen</a>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import dateformat from '@/helpers/date-format';
|
||||
|
||||
export default {
|
||||
props: {
|
||||
snapshot: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
created() {
|
||||
return dateformat(this.snapshot.created);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
@ -21,8 +33,22 @@
|
|||
@import '~styles/helpers';
|
||||
|
||||
.snapshot-list-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
|
||||
&__title {
|
||||
@include heading-4;
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
&__date {
|
||||
@include regular-text;
|
||||
}
|
||||
|
||||
&__link {
|
||||
@include default-link;
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ query ModuleSnapshotsQuery($slug: String!) {
|
|||
snapshots {
|
||||
id
|
||||
title
|
||||
created
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,12 @@ mutation CreateSnapshot($input: CreateSnapshotInput!) {
|
|||
snapshot {
|
||||
id
|
||||
title
|
||||
created
|
||||
creator {
|
||||
username
|
||||
firstName
|
||||
lastName
|
||||
}
|
||||
}
|
||||
success
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
import dayjs from 'dayjs';
|
||||
|
||||
const dateformat = date => dayjs(date).format('DD.MM.YYYY - HH:mm');
|
||||
|
||||
export default dateformat;
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
# Generated by Django 2.2.20 on 2021-04-29 14:44
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('books', '0026_auto_20210427_1814'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='snapshot',
|
||||
name='created',
|
||||
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='snapshot',
|
||||
name='creator',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
from django.db.models import Q
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ class ChapterSnapshot(models.Model):
|
|||
|
||||
class SnapshotManager(models.Manager):
|
||||
def create_snapshot(self, module, school_class, user, *args, **kwargs):
|
||||
snapshot = self.create(module=module, *args, **kwargs)
|
||||
snapshot = self.create(module=module, creator=user, *args, **kwargs)
|
||||
chapters_with_hidden_properties = Chapter.get_by_parent(module).filter(
|
||||
Q(description_hidden_for=school_class)
|
||||
| Q(title_hidden_for=school_class)
|
||||
|
|
@ -71,6 +72,9 @@ class Snapshot(models.Model):
|
|||
'books.ContentBlock',
|
||||
related_name='hidden_for_snapshots'
|
||||
)
|
||||
created = models.DateTimeField(auto_now_add=True)
|
||||
creator = models.ForeignKey(get_user_model(), on_delete=models.SET_NULL, null=True)
|
||||
|
||||
objects = SnapshotManager()
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
|||
|
|
@ -51,6 +51,10 @@ mutation CreateSnapshot($input: CreateSnapshotInput!) {
|
|||
createSnapshot(input: $input) {
|
||||
snapshot {
|
||||
id
|
||||
created
|
||||
creator {
|
||||
username
|
||||
}
|
||||
chapters {
|
||||
edges {
|
||||
node {
|
||||
|
|
@ -92,8 +96,9 @@ class CreateSnapshotTestCase(TestCase):
|
|||
def setUp(self):
|
||||
create_users()
|
||||
# teacher will create snapshot
|
||||
self.slug = 'some-module'
|
||||
self.teacher = User.objects.get(username='teacher')
|
||||
self.module = ModuleFactory(slug='some-module')
|
||||
self.module = ModuleFactory(slug=self.slug)
|
||||
self.skillbox_class = SchoolClass.objects.get(name='skillbox')
|
||||
|
||||
# module M has a chapter
|
||||
|
|
@ -158,13 +163,17 @@ class CreateSnapshotTestCase(TestCase):
|
|||
def test_create_snapshot(self):
|
||||
result = self.client.execute(CREATE_SNAPSHOT_MUTATION, variables={
|
||||
'input': {
|
||||
'module': to_global_id('ContentBlockNode', self.module.pk),
|
||||
'module': self.slug,
|
||||
'selectedClass': to_global_id('SchoolClassNode', self.skillbox_class.pk),
|
||||
}
|
||||
})
|
||||
self.assertIsNone(result.get('errors'))
|
||||
snapshot = result.get('data').get('createSnapshot').get('snapshot')
|
||||
chapter = snapshot.get('chapters').get('edges')[0]['node']
|
||||
|
||||
self.assertIsNotNone(snapshot.get('created'))
|
||||
self.assertEqual(snapshot.get('creator').get('username'), self.teacher.username)
|
||||
|
||||
self.assertTrue(chapter['titleHidden'])
|
||||
self.assertFalse(chapter['descriptionHidden'])
|
||||
_, chapter_id = from_global_id(chapter['id'])
|
||||
|
|
|
|||
Loading…
Reference in New Issue