Skip to content

Commit ed07683

Browse files
committed
Apply Status filter
1 parent 35c844e commit ed07683

4 files changed

Lines changed: 66 additions & 30 deletions

File tree

backend/app.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,22 @@ def filelist():
3636

3737

3838
@app.get("/api/coins")
39-
def coins(f):
39+
def coins(f, status_filter=None):
4040
file = f
4141
con = sqlite_connect(file)
4242
cur = con.cursor()
4343

44-
res = cur.execute("""
44+
sql = """
4545
SELECT coins.id, images.image, title, status, subjectshort, value, unit, year, mintmark, series, country
4646
FROM coins LEFT OUTER JOIN images ON images.id = coins.image
47-
""")
47+
"""
48+
49+
params = []
50+
if status_filter:
51+
sql += " WHERE status = ?"
52+
params.append(status_filter)
53+
54+
res = cur.execute(sql, params)
4855
data = res.fetchall()
4956
con.close()
5057

frontend/src/App.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const hasWarning = globalStatus.hasWarning;
2828
const isServerLess = import.meta.env.VITE_SERVERLESS;
2929
const selectedFile = ref(null)
3030
const serverFileList = ref([])
31-
const coinsList = ref([])
3231
const statusesList = ref([])
3332
const collectionSettings = ref({})
3433
let isOpened = false;
@@ -70,14 +69,12 @@ const handleRemoteFileSelected = async (file) => {
7069
if (!file)
7170
return;
7271
73-
coinsList.value = [];
7472
selectedFile.value = file;
7573
isOpened = true;
7674
await router.replace('/')
7775
appTitle.pushTitle(file)
7876
7977
const ret = await service.openRemoteFile(file);
80-
coinsList.value = ret.coinsList;
8178
collectionSettings.value = ret.collectionSettings;
8279
statusesList.value = ret.statusesList;
8380
@@ -88,14 +85,12 @@ const handleFileUpload = async (file) => {
8885
if (!file)
8986
return;
9087
91-
coinsList.value = [];
9288
selectedFile.value = file;
9389
isOpened = true;
9490
await router.replace('/')
9591
appTitle.pushTitle(file.name)
9692
9793
const ret = await service.openLocalFile(file);
98-
coinsList.value = ret.coinsList;
9994
collectionSettings.value = ret.collectionSettings;
10095
statusesList.value = ret.statusesList;
10196
@@ -150,7 +145,7 @@ const handleFileUpload = async (file) => {
150145
:file_list="serverFileList" :onFileSelected="handleRemoteFileSelected" />
151146
<KeepAlive>
152147
<CoinListView v-if="route.name === 'home' && isOpened"
153-
:coins_list="coinsList" :settings="collectionSettings" :statuses_list="statusesList"
148+
:settings="collectionSettings" :statuses_list="statusesList"
154149
ref="coinListViewRef" />
155150
</KeepAlive>
156151
<CoinView v-if="route.name === 'coin' && isOpened"

frontend/src/components/CoinListView.vue

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ const router = useRouter()
1111
const service = useService();
1212
1313
const images = ref([])
14+
const coinsList = ref([])
1415
1516
const props = defineProps({
16-
coins_list: {
17-
type: Array,
18-
required: true,
19-
},
2017
settings: {
2118
type: Object,
2219
required: true,
@@ -32,8 +29,11 @@ onMounted(async () => {
3229
onUnmounted(async () => {
3330
})
3431
35-
const onOpenFile = () => {
36-
images.value = new Array(props.coins_list.length).fill('')
32+
const onOpenFile = async () => {
33+
images.value = []
34+
coinsList.value = []
35+
coinsList.value = await service.loadCoins()
36+
images.value = new Array(coinsList.value.length).fill('')
3737
}
3838
3939
defineExpose({
@@ -59,6 +59,10 @@ function generateDescription( coin_data ) {
5959
return desc;
6060
}
6161
62+
const onStatusFilterChange = async (val) => {
63+
coinsList.value = await service.loadCoins(val);
64+
}
65+
6266
const loadImage = async (index, coinId) => {
6367
images.value[index] = await service.loadImage(coinId, imagePresentation.value);
6468
}
@@ -70,12 +74,14 @@ const loadImage = async (index, coinId) => {
7074
:label="settings.fields['status']"
7175
:items="statuses_list"
7276
:item-title="item => settings.statuses[item]"
77+
@update:modelValue="onStatusFilterChange"
78+
return-object
7379
></v-select>
7480
</v-container>
7581
<v-container class="pa-0 ma-0">
7682
<v-list lines="two">
7783
<v-list-item
78-
v-for="(coin, index) in coins_list"
84+
v-for="(coin, index) in coinsList"
7985
:key="coin[0]"
8086
:subtitle="generateDescription(coin).join(', ')"
8187
:title="coin[2]"

frontend/src/composables/useService.js

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ export function useService(passwordDialogRef) {
136136
connection_type = 'remote';
137137
connected_file = file;
138138

139-
let coinsList = [];
140139
let collectionSettings = await initSettings();
141140
let statusesList = [];
142141
let settingsDb = {};
@@ -171,9 +170,6 @@ export function useService(passwordDialogRef) {
171170
await globalStatus.startLoading('Load collection');
172171

173172
try {
174-
const responseCoins = await api.get('/api/coins', {params: {f: file}})
175-
coinsList = responseCoins.data
176-
177173
const responseFilters = await api.get('/api/filters', {params: {f: file}})
178174
statusesList = responseFilters.data
179175
}
@@ -186,13 +182,12 @@ export function useService(passwordDialogRef) {
186182
}
187183
}
188184

189-
return {collectionSettings, coinsList, statusesList};
185+
return {collectionSettings, statusesList};
190186
}
191187

192188
const openLocalFile = async (file) => {
193189
connection_type = 'local';
194190

195-
let coinsList = [];
196191
let statusesList = [];
197192
let collectionSettings = await initSettings()
198193

@@ -232,18 +227,50 @@ export function useService(passwordDialogRef) {
232227
if (versionValid) {
233228
const passwordValid = await checkDbPassword(collectionSettings)
234229
if (passwordValid) {
235-
const sql = `
236-
SELECT coins.id, images.image, title, status, subjectshort, value, unit, year, mintmark, series, country
237-
FROM coins LEFT OUTER JOIN images ON images.id = coins.image
238-
`
239-
coinsList = await executeQuery(sql)
240-
241230
const sql_statuses = 'SELECT DISTINCT status FROM coins';
242-
statusesList = (await executeQuery(sql_statuses))[0]
231+
statusesList = (await executeQuery(sql_statuses)).flat()
243232
}
244233
}
245234

246-
return {collectionSettings, coinsList, statusesList};
235+
return {collectionSettings, statusesList};
236+
}
237+
238+
const loadCoins = async (statusFilter=null) => {
239+
if (connection_type === 'local')
240+
return loadCoinsLocal(statusFilter);
241+
else if (connection_type === 'remote')
242+
return loadCoinsRemote(statusFilter, connected_file);
243+
}
244+
245+
const loadCoinsRemote = async (statusFilter, file) => {
246+
let coinsList = [];
247+
248+
try {
249+
const responseCoins = await api.get('/api/coins', {params: {f: file, status_filter: statusFilter}})
250+
coinsList = responseCoins.data
251+
}
252+
catch (err) {
253+
globalStatus.error.value = err
254+
}
255+
256+
return coinsList;
257+
}
258+
259+
const loadCoinsLocal = async (statusFilter) => {
260+
let coinsList = [];
261+
262+
let sql = `
263+
SELECT coins.id, images.image, title, status, subjectshort, value, unit, year, mintmark, series, country
264+
FROM coins LEFT OUTER JOIN images ON images.id = coins.image
265+
`
266+
let params = [];
267+
if (statusFilter) {
268+
sql += ' WHERE status = ?';
269+
params.push(statusFilter);
270+
}
271+
coinsList = await executeQuery(sql, params)
272+
273+
return coinsList;
247274
}
248275

249276
const loadImage = async (coinId, type) => {
@@ -421,6 +448,7 @@ export function useService(passwordDialogRef) {
421448
getServerFileList,
422449
openRemoteFile,
423450
openLocalFile,
451+
loadCoins,
424452
loadImage,
425453
getDetails,
426454
getPhotos,

0 commit comments

Comments
 (0)