Skip to content
Snippets Groups Projects
Verified Commit 90283706 authored by Nik | Klampfradler's avatar Nik | Klampfradler Committed by Tom Teichler
Browse files

Add preliminary UI for check-ins

parent 7daada65
No related branches found
No related tags found
1 merge request!48Revert "Update pyproject"
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
Check in Check in
</v-btn> </v-btn>
</v-form> </v-form>
<v-card class="mx-auto">
<v-alert v-for="(checkIn, i) in checkIns" :key="i" :color="checkIn.color">
{{ checkIn.message }}
</v-alert>
</v-card>
</template> </template>
<script> <script>
...@@ -24,12 +29,16 @@ ...@@ -24,12 +29,16 @@
export default { export default {
data () { data () {
return { return {
comment: "" comment: "",
status: {
"color": "blue-grey",
"message": "Scan not started",
},
checkIns: new Array(),
} }
}, },
methods: { methods: {
checkIn (personId) { checkIn (data, statusObject) {
this.$apollo.mutate({ this.$apollo.mutate({
mutation: gql`mutation ($eventSlug:String!, $personId:Int!, $comment:String!, $lat:Int, $lon:Int) { mutation: gql`mutation ($eventSlug:String!, $personId:Int!, $comment:String!, $lat:Int, $lon:Int) {
checkpointCheckIn(eventSlug:$eventSlug, personId:$personId, comment:$comment, lat:$lat, lon:$lon){ checkpointCheckIn(eventSlug:$eventSlug, personId:$personId, comment:$comment, lat:$lat, lon:$lon){
...@@ -40,37 +49,54 @@ ...@@ -40,37 +49,54 @@
}`, }`,
variables: { variables: {
"eventSlug": this.$route.params.slug, "eventSlug": this.$route.params.slug,
"personId": personId, "personId": data.id,
"comment": this.comment "comment": this.comment
} }
}).then((data) => { }).then((data) => {
console.log(data) statusObject.message = `Checked in ${data.user.username}`;
statusObject.color = "green";
}).catch((error) => { }).catch((error) => {
alert(error) statusObject.message = `Error checking in ${data.user.username}`;
statusObject.color = "red";
}) })
}, },
startScan() { startScan() {
try { try {
const ndef = new NDEFReader(); const ndef = new NDEFReader();
ndef.scan().then(() => { ndef.scan().then(() => {
ndef.addEventListener("readingerror", () => { ndef.addEventListener("readingerror", (err) => {
// FIXME use semantic colors/types
this.status.color = "red";
this.status.message = err;
}); });
ndef.addEventListener("reading", (e) => { ndef.addEventListener("reading", (e) => {
const message = e.message; const message = e.message;
const checkInStatus = {
"color": "blue-grey",
"message": "Decoding...",
};
this.checkIns.unshift(checkInStatus);
for (const record of message.records) { for (const record of message.records) {
if (record.recordType !== "url") { if (record.recordType !== "url") {
checkInStatus.message = "Found non-URL";
continue; continue;
} }
const decoder = new TextDecoder(); const decoder = new TextDecoder();
const url = decoder.decode(record.data); const url = decoder.decode(record.data);
// FIXME use configured base URL here // FIXME use configured base URL here
if (!url.startsWith("https://ticdesk.teckids.org/o/")) { if (!url.startsWith("https://ticdesk.teckids.org/o/")) {
continue; checkInStatus.message = "Found invalid URL";
checkInStatus.color = "red";
break;
} }
fetch(url).then((res) => res.json()).then((data) => { fetch(url).then((res) => res.json()).then((data) => {
this.checkIn(data.id); checkInStatus.message = `Checking in ${data.user.username}...`;
}).catch((error) => alert(error)); checkInStatus.color = "orange";
this.checkIn(data, checkInStatus);
}).catch((error) => {
checkInStatus.message = "Error retrieving or decoding data";
checkInStatus.color = "red";
};
} }
}); });
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment