Skip to content

Commit 45d9604

Browse files
committed
Add coin info page
1 parent e4ea5ba commit 45d9604

5 files changed

Lines changed: 91 additions & 6 deletions

File tree

frontend/src/App.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script setup>
22
import {ref} from 'vue'
33
import {useRoute, useRouter} from 'vue-router'
4+
import {useSQLite} from "@/composables/useSQLite.js";
45
import FileUploaderView from '@/components/FileUploaderView.vue'
56
import CoinListView from "@/components/CoinListView.vue";
67
import AboutView from "@/components/AboutView.vue";
7-
import {useSQLite} from "@/composables/useSQLite.js";
8+
import CoinView from "@/components/CoinView.vue";
89
910
const {isLoading,
1011
error,
@@ -32,7 +33,11 @@ const handleFileUpload = async (file) => {
3233
isOpened = true;
3334
await router.replace('/')
3435
35-
coinsList.value = await executeQuery("")
36+
const sql = `
37+
SELECT coins.id, images.image, title, status, subjectshort, value, unit, year, mintmark, series, country
38+
FROM coins LEFT OUTER JOIN images ON images.id = coins.image
39+
`
40+
coinsList.value = await executeQuery(sql)
3641
}
3742
</script>
3843

@@ -76,6 +81,9 @@ const handleFileUpload = async (file) => {
7681
<div v-if="route.name === 'home' && isOpened">
7782
<CoinListView v-model:title="title" :file_name="selectedFile.name" :coins_list="coinsList" />
7883
</div>
84+
<div v-if="route.name === 'coin' && isOpened">
85+
<CoinView v-model:title="title" />
86+
</div>
7987
<div v-if="route.name === 'about'">
8088
<AboutView v-model:title="title" />
8189
</div>

frontend/src/components/CoinListView.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<script setup>
22
import {defineProps, onMounted, onUnmounted} from "vue";
3+
import {useRouter} from "vue-router";
4+
5+
const router = useRouter()
36
47
const props = defineProps({
58
title: String,
@@ -63,6 +66,7 @@ function generateDescription( coin_data ) {
6366
:key="coin[0]"
6467
:subtitle="generateDescription(coin).join(', ')"
6568
:title="coin[2]"
69+
@click="router.push('/coin/' + coin[0])"
6670
>
6771
<template v-slot:prepend>
6872
<v-img :src="arrayBufferToBase64(coin[1])" :width="100" />
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<script setup>
2+
import {defineProps, onMounted, onUnmounted, ref} from "vue";
3+
import {useRoute} from "vue-router";
4+
import {useSQLite} from "@/composables/useSQLite.js";
5+
6+
const route = useRoute()
7+
8+
const {isLoading,
9+
error,
10+
status,
11+
openDatabase,
12+
executeQuery} = useSQLite()
13+
14+
const props = defineProps({
15+
title: String,
16+
});
17+
18+
const emit = defineEmits(['update:title']);
19+
let oldTitle = null;
20+
const coinData = ref([])
21+
22+
const infoFields = ['coins.title', 'obverseimg.image', 'reverseimg.image',
23+
'status', 'region', 'country', 'period', 'ruler', 'value', 'unit', 'type',
24+
'series', 'subjectshort', 'issuedate', 'year', 'mintage', 'material',
25+
'mint', 'mintmark', 'features', 'subject', 'grade', 'paydate', 'payprice',
26+
'storage', 'condition', 'quantity'];
27+
function infoFieldIndex(field) {
28+
return infoFields.findIndex(element => element === field);
29+
}
30+
31+
onMounted(async () => {
32+
const id = route.params['id']
33+
const sql = `SELECT ${ infoFields.join(',') } FROM coins
34+
LEFT JOIN photos AS obverseimg ON coins.obverseimg = obverseimg.id
35+
LEFT JOIN photos AS reverseimg ON coins.reverseimg = reverseimg.id
36+
WHERE coins.id=?`
37+
const results = await executeQuery(sql, [id,])
38+
coinData.value = results[0]
39+
40+
oldTitle = props.title;
41+
emit('update:title', coinData.value[0]);
42+
})
43+
onUnmounted(async () => {
44+
emit('update:title', oldTitle);
45+
})
46+
47+
function arrayBufferToBase64( buffer ) {
48+
let binary = '';
49+
const bytes = new Uint8Array( buffer );
50+
const len = bytes.byteLength;
51+
for (let i = 0; i < len; i++) {
52+
binary += String.fromCharCode( bytes[ i ] );
53+
}
54+
const base64String = window.btoa( binary );
55+
return `data:image/png;base64,${base64String}`;
56+
}
57+
</script>
58+
59+
<template>
60+
<v-img :src="arrayBufferToBase64(coinData[infoFieldIndex('obverseimg.image')])" :width="200" />
61+
<v-img :src="arrayBufferToBase64(coinData[infoFieldIndex('reverseimg.image')])" :width="200" />
62+
{{ coinData[infoFieldIndex('status')] }}
63+
{{ coinData[infoFieldIndex('country')] }}
64+
{{ coinData[infoFieldIndex('type')] }}
65+
66+
{{ coinData[infoFieldIndex('features')] }}
67+
{{ coinData[infoFieldIndex('subject')] }}
68+
</template>
69+
70+
<style scoped>
71+
72+
</style>

frontend/src/composables/useSQLite.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,7 @@ export function useSQLite() {
8888
error.value = null
8989
status.value = 'Executing query...';
9090

91-
const result = db.exec(`
92-
SELECT coins.id, images.image, title, status, subjectshort, value, unit, year, mintmark, series, country
93-
FROM coins LEFT OUTER JOIN images on images.id = coins.image
94-
`);
91+
const result = db.exec(sql, params);
9592
console.log(result[0].values)
9693
const results = result.length > 0
9794
? result[0].values

frontend/src/router/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ const routes = [
55
path: '/',
66
name: 'home',
77
},
8+
{
9+
path: '/coin/:id',
10+
name: 'coin',
11+
},
812
{
913
path: '/open',
1014
name: 'open',

0 commit comments

Comments
 (0)