Add snapshot creator and created date
This commit is contained in:
parent
08ddd58132
commit
cde5e8d964
|
|
@ -8336,6 +8336,11 @@
|
||||||
"integrity": "sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI=",
|
"integrity": "sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI=",
|
||||||
"dev": true
|
"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": {
|
"de-indent": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz",
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@
|
||||||
"chalk": "^2.0.1",
|
"chalk": "^2.0.1",
|
||||||
"copy-webpack-plugin": "^4.0.1",
|
"copy-webpack-plugin": "^4.0.1",
|
||||||
"css-loader": "^0.28.0",
|
"css-loader": "^0.28.0",
|
||||||
|
"dayjs": "^1.10.4",
|
||||||
"debounce": "^1.2.0",
|
"debounce": "^1.2.0",
|
||||||
"eslint": "^4.15.0",
|
"eslint": "^4.15.0",
|
||||||
"eslint-config-standard": "^10.2.1",
|
"eslint-config-standard": "^10.2.1",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<div class="snapshot-created__content">
|
<div class="snapshot-created__content">
|
||||||
<div class="snapshot-created__entry">
|
<div class="snapshot-created__entry">
|
||||||
<span class="snapshot-created__title">{{ snapshot.title }}</span>
|
<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>
|
</div>
|
||||||
<div slot="footer">
|
<div slot="footer">
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
<script>
|
<script>
|
||||||
import Modal from '@/components/Modal';
|
import Modal from '@/components/Modal';
|
||||||
import {SNAPSHOT_LIST} from '@/router/module.names';
|
import {SNAPSHOT_LIST} from '@/router/module.names';
|
||||||
|
import dateformat from '@/helpers/date-format';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
|
@ -43,6 +44,9 @@
|
||||||
computed: {
|
computed: {
|
||||||
snapshot() {
|
snapshot() {
|
||||||
return this.$modal.state.payload.snapshot;
|
return this.$modal.state.payload.snapshot;
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
return dateformat(this.snapshot.created);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,28 @@
|
||||||
<span
|
<span
|
||||||
class="snapshot-list-item__title"
|
class="snapshot-list-item__title"
|
||||||
v-html="snapshot.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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import dateformat from '@/helpers/date-format';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
snapshot: {
|
snapshot: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({})
|
default: () => ({})
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
created() {
|
||||||
|
return dateformat(this.snapshot.created);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
@ -21,8 +33,22 @@
|
||||||
@import '~styles/helpers';
|
@import '~styles/helpers';
|
||||||
|
|
||||||
.snapshot-list-item {
|
.snapshot-list-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
|
||||||
&__title {
|
&__title {
|
||||||
@include heading-4;
|
@include heading-4;
|
||||||
|
width: 180px;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__date {
|
||||||
|
@include regular-text;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__link {
|
||||||
|
@include default-link;
|
||||||
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ query ModuleSnapshotsQuery($slug: String!) {
|
||||||
snapshots {
|
snapshots {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
|
created
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,12 @@ mutation CreateSnapshot($input: CreateSnapshotInput!) {
|
||||||
snapshot {
|
snapshot {
|
||||||
id
|
id
|
||||||
title
|
title
|
||||||
|
created
|
||||||
|
creator {
|
||||||
|
username
|
||||||
|
firstName
|
||||||
|
lastName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
success
|
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 import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
|
|
@ -25,7 +26,7 @@ class ChapterSnapshot(models.Model):
|
||||||
|
|
||||||
class SnapshotManager(models.Manager):
|
class SnapshotManager(models.Manager):
|
||||||
def create_snapshot(self, module, school_class, user, *args, **kwargs):
|
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(
|
chapters_with_hidden_properties = Chapter.get_by_parent(module).filter(
|
||||||
Q(description_hidden_for=school_class)
|
Q(description_hidden_for=school_class)
|
||||||
| Q(title_hidden_for=school_class)
|
| Q(title_hidden_for=school_class)
|
||||||
|
|
@ -71,6 +72,9 @@ class Snapshot(models.Model):
|
||||||
'books.ContentBlock',
|
'books.ContentBlock',
|
||||||
related_name='hidden_for_snapshots'
|
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()
|
objects = SnapshotManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,10 @@ mutation CreateSnapshot($input: CreateSnapshotInput!) {
|
||||||
createSnapshot(input: $input) {
|
createSnapshot(input: $input) {
|
||||||
snapshot {
|
snapshot {
|
||||||
id
|
id
|
||||||
|
created
|
||||||
|
creator {
|
||||||
|
username
|
||||||
|
}
|
||||||
chapters {
|
chapters {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
|
|
@ -92,8 +96,9 @@ class CreateSnapshotTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
create_users()
|
create_users()
|
||||||
# teacher will create snapshot
|
# teacher will create snapshot
|
||||||
|
self.slug = 'some-module'
|
||||||
self.teacher = User.objects.get(username='teacher')
|
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')
|
self.skillbox_class = SchoolClass.objects.get(name='skillbox')
|
||||||
|
|
||||||
# module M has a chapter
|
# module M has a chapter
|
||||||
|
|
@ -158,13 +163,17 @@ class CreateSnapshotTestCase(TestCase):
|
||||||
def test_create_snapshot(self):
|
def test_create_snapshot(self):
|
||||||
result = self.client.execute(CREATE_SNAPSHOT_MUTATION, variables={
|
result = self.client.execute(CREATE_SNAPSHOT_MUTATION, variables={
|
||||||
'input': {
|
'input': {
|
||||||
'module': to_global_id('ContentBlockNode', self.module.pk),
|
'module': self.slug,
|
||||||
'selectedClass': to_global_id('SchoolClassNode', self.skillbox_class.pk),
|
'selectedClass': to_global_id('SchoolClassNode', self.skillbox_class.pk),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
self.assertIsNone(result.get('errors'))
|
self.assertIsNone(result.get('errors'))
|
||||||
snapshot = result.get('data').get('createSnapshot').get('snapshot')
|
snapshot = result.get('data').get('createSnapshot').get('snapshot')
|
||||||
chapter = snapshot.get('chapters').get('edges')[0]['node']
|
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.assertTrue(chapter['titleHidden'])
|
||||||
self.assertFalse(chapter['descriptionHidden'])
|
self.assertFalse(chapter['descriptionHidden'])
|
||||||
_, chapter_id = from_global_id(chapter['id'])
|
_, chapter_id = from_global_id(chapter['id'])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue