Skip to content

Commit 9ee282c

Browse files
committed
load snapshot backend data view into vue, switch from slugh_hash to string id (fixes graphql)
1 parent ef30ac2 commit 9ee282c

File tree

5 files changed

+46
-18
lines changed

5 files changed

+46
-18
lines changed

django/gsmap/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ class SnapshotAdmin(admin.ModelAdmin):
1313
)
1414
fieldsets = (
1515
(_('Meta'), {
16-
'fields': ('created', 'slug_hash', 'archived', 'deleted')
16+
'fields': ('created', 'id', 'archived', 'deleted')
1717
}),
1818
(_('Main'), {
1919
'fields':
2020
('data', 'screenshot', 'municipality', 'predecessor', 'user'),
2121
}),
2222
)
23-
list_display = ('created', 'slug_hash')
23+
list_display = ('id', 'created')
2424

2525

2626
admin.site.register(Municipality, MunicipalityAdmin)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 3.0.3 on 2020-02-19 08:16
2+
3+
from django.db import migrations, models
4+
import gsmap.models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('gsmap', '0005_auto_20200218_1558'),
11+
]
12+
13+
operations = [
14+
migrations.RemoveField(
15+
model_name='snapshot',
16+
name='slug_hash',
17+
),
18+
migrations.AlterField(
19+
model_name='snapshot',
20+
name='id',
21+
field=models.CharField(default=gsmap.models.create_slug_hash, max_length=8, primary_key=True, serialize=False, unique=True),
22+
),
23+
]

django/gsmap/models.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ def create_slug_hash():
6262

6363
class Snapshot(models.Model):
6464
created = models.DateTimeField(auto_now_add=True)
65-
slug_hash = models.CharField(max_length=8,
66-
unique=True,
67-
default=create_slug_hash)
65+
id = models.CharField(
66+
max_length=8, unique=True, primary_key=True,
67+
default=create_slug_hash
68+
)
6869
archived = models.BooleanField(default=False)
6970
deleted = models.BooleanField(default=False)
7071
data = pg_fields.JSONField(default=dict)
@@ -80,4 +81,4 @@ class Snapshot(models.Model):
8081
user = models.ForeignKey(User, on_delete=models.CASCADE)
8182

8283
def __str__(self):
83-
return self.slug_hash
84+
return self.id

django/gsmap/schema.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,18 @@ def resolve_thumbnail(self, info, size):
4646
size=size
4747
)
4848

49+
4950
class SnapshotNode(DjangoObjectType):
5051
class Meta:
5152
model = Snapshot
52-
fields = ['slug_hash', 'data', 'screenshot']
53-
filter_fields = {
54-
'slug_hash': ['exact']
55-
}
53+
fields = ['data', 'screenshot']
54+
filter_fields = ['created']
5655
interfaces = [graphene.relay.Node]
5756

5857
data = generic.GenericScalar(source='data')
5958
screenshot = graphene.Field(ImageNode)
59+
pk = graphene.String(source='id')
60+
6061

6162
class Query(object):
6263
municipality = graphene.relay.Node.Field(MunicipalityNode)

vue/src/views/Snapshot.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,27 @@ export default {
3232
},
3333
3434
methods: {
35-
async getSnapshot(val) {
35+
async getSnapshot(hash) {
3636
const result = await this.$apollo.query({
37-
query: gql`query snapshot(slugHash$: String!){
38-
snapshot(ID: $slugHash) {
39-
node {
40-
id
41-
}
37+
query: gql`query getsnapshot($hash: ID!){
38+
snapshot(id: $hash) {
39+
id
40+
pk
41+
data
4242
}
4343
}`,
4444
variables: {
45-
slugHash: val
45+
hash: btoa(`SnapshotNode:${hash}`)
4646
}
4747
});
4848
return result;
4949
}
5050
},
5151
52-
mounted() {
52+
async created() {
53+
const hash = this.$route.params.hash;
54+
const result = await this.getSnapshot(hash);
55+
console.log(result);
5356
}
5457
};
5558
</script>

0 commit comments

Comments
 (0)