Skip to content

Commit 3c7bccb

Browse files
committed
Show coins list
1 parent f1a9f2d commit 3c7bccb

2 files changed

Lines changed: 62 additions & 4 deletions

File tree

frontend/src/App.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import FileUploader from './components/FileUploader.vue'
55
import CoinList from "@/components/CoinList.vue";
66
77
const selectedFile = ref(null)
8+
const coinsList = ref([])
89
910
const db = ref(null);
1011
const status = ref('');
@@ -38,11 +39,16 @@ const handleFileUpload = async (file) => {
3839
// Load database
3940
db.value = new SQL.Database(uint8Array);
4041
41-
const result = db.value.exec(`SELECT COUNT(*) FROM coins`);
42-
console.log(`Coins in database: ${result[0].values[0][0]}`);
43-
4442
status.value = `Database loaded successfully: ${file.name} (${(file.size / 1024 / 1024).toFixed(2)} MB)`;
4543
44+
const coins = db.value.exec(`
45+
SELECT coins.id, images.image, title, status, subjectshort, value, unit, year, mintmark, series, country
46+
FROM coins LEFT OUTER JOIN images on images.id = coins.image
47+
`);
48+
coinsList.value = coins.length > 0
49+
? coins[0].values
50+
: [];
51+
4652
selectedFile.value = file;
4753
} catch (err) {
4854
console.error('Error loading database:', err);
@@ -65,7 +71,7 @@ const handleFileUpload = async (file) => {
6571
<p>Your file not will be uploaded to the internet. You can disable internet connection.</p>
6672
</div>
6773
<div v-else class="file-view">
68-
<CoinList :file_name="selectedFile.name" />
74+
<CoinList :file_name="selectedFile.name" :coins_list="coinsList" />
6975
</div>
7076
<div v-if="status" class="status">{{ status }}</div>
7177
</main>

frontend/src/components/CoinList.vue

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,63 @@ defineProps({
66
type: String,
77
required: true,
88
},
9+
coins_list: {
10+
type: Array,
11+
required: true,
12+
},
913
});
14+
15+
function arrayBufferToBase64( buffer ) {
16+
let binary = '';
17+
const bytes = new Uint8Array( buffer );
18+
const len = bytes.byteLength;
19+
for (let i = 0; i < len; i++) {
20+
binary += String.fromCharCode( bytes[ i ] );
21+
}
22+
// return window.btoa( binary );
23+
const base64String = window.btoa( binary );
24+
return `data:image/png;base64,${base64String}`;
25+
}
26+
27+
function generateDescription( coin_data ) {
28+
let desc = [];
29+
if (coin_data[4])
30+
desc.push(coin_data[4]);
31+
if (coin_data[5] || coin_data[6])
32+
desc.push(coin_data[5] + ' ' + coin_data[6]);
33+
if (coin_data[10])
34+
desc.push(coin_data[10]);
35+
if (coin_data[7]) {
36+
desc.push(coin_data[7]);
37+
}
38+
if (coin_data[8])
39+
desc.push(coin_data[8]);
40+
if (coin_data[9])
41+
desc.push(coin_data[9]);
42+
43+
return desc;
44+
}
1045
</script>
1146

1247
<template>
1348
<h2 class="file-name">{{ file_name }}</h2>
49+
50+
<div>
51+
<table>
52+
<tr v-for="coin_data in coins_list">
53+
<td class="image" :data-id="coin_data[0]"><img :src="arrayBufferToBase64(coin_data[1])"></td>
54+
<td class="data">
55+
<div class="title">
56+
{{ coin_data[2] }}&nbsp;
57+
</div>
58+
<div class="description">
59+
{{ generateDescription(coin_data).join(', ') }}&nbsp;
60+
</div>
61+
</td>
62+
<td>{{ coin_data[3] }}</td>
63+
</tr>
64+
</table>
65+
</div>
1466
</template>
1567

1668
<style scoped>

0 commit comments

Comments
 (0)