diff --git a/client/package-lock.json b/client/package-lock.json
index 652b72fc..9992f461 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -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",
diff --git a/client/package.json b/client/package.json
index 3ecc0653..99fca5e1 100644
--- a/client/package.json
+++ b/client/package.json
@@ -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",
diff --git a/client/src/components/modules/SnapshotCreated.vue b/client/src/components/modules/SnapshotCreated.vue
index 65779a9b..3b73543f 100644
--- a/client/src/components/modules/SnapshotCreated.vue
+++ b/client/src/components/modules/SnapshotCreated.vue
@@ -9,7 +9,7 @@
{{ snapshot.title }}
- 30.11.2020 - 17:31 - Simone Gerber
+ {{ created }} - {{ snapshot.creator.firstName }} {{ snapshot.creator.lastName }}
@@ -26,6 +26,7 @@
@@ -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;
}
}
diff --git a/client/src/graphql/gql/moduleSnapshots.gql b/client/src/graphql/gql/moduleSnapshots.gql
index 0646f5fe..9ce5d249 100644
--- a/client/src/graphql/gql/moduleSnapshots.gql
+++ b/client/src/graphql/gql/moduleSnapshots.gql
@@ -9,6 +9,7 @@ query ModuleSnapshotsQuery($slug: String!) {
snapshots {
id
title
+ created
}
}
}
diff --git a/client/src/graphql/gql/mutations/createSnapshot.gql b/client/src/graphql/gql/mutations/createSnapshot.gql
index 0d64b711..2b88a88a 100644
--- a/client/src/graphql/gql/mutations/createSnapshot.gql
+++ b/client/src/graphql/gql/mutations/createSnapshot.gql
@@ -3,6 +3,12 @@ mutation CreateSnapshot($input: CreateSnapshotInput!) {
snapshot {
id
title
+ created
+ creator {
+ username
+ firstName
+ lastName
+ }
}
success
}
diff --git a/client/src/helpers/date-format.js b/client/src/helpers/date-format.js
new file mode 100644
index 00000000..e3dcbbf1
--- /dev/null
+++ b/client/src/helpers/date-format.js
@@ -0,0 +1,5 @@
+import dayjs from 'dayjs';
+
+const dateformat = date => dayjs(date).format('DD.MM.YYYY - HH:mm');
+
+export default dateformat;
diff --git a/server/books/migrations/0027_auto_20210429_1444.py b/server/books/migrations/0027_auto_20210429_1444.py
new file mode 100644
index 00000000..dd1cac57
--- /dev/null
+++ b/server/books/migrations/0027_auto_20210429_1444.py
@@ -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),
+ ),
+ ]
diff --git a/server/books/models/snapshot.py b/server/books/models/snapshot.py
index d88227f3..6c328a96 100644
--- a/server/books/models/snapshot.py
+++ b/server/books/models/snapshot.py
@@ -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):
diff --git a/server/books/tests/test_create_snapshot.py b/server/books/tests/test_create_snapshot.py
index 2a73aa0e..c2942682 100644
--- a/server/books/tests/test_create_snapshot.py
+++ b/server/books/tests/test_create_snapshot.py
@@ -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'])