Skip to content

Commit d74d438

Browse files
committed
Improve opening collections
1 parent ed07683 commit d74d438

2 files changed

Lines changed: 54 additions & 42 deletions

File tree

frontend/src/App.vue

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const hasError = globalStatus.hasError;
2626
const hasWarning = globalStatus.hasWarning;
2727
2828
const isServerLess = import.meta.env.VITE_SERVERLESS;
29-
const selectedFile = ref(null)
3029
const serverFileList = ref([])
3130
const statusesList = ref([])
3231
const collectionSettings = ref({})
@@ -65,36 +64,39 @@ onMounted(async () => {
6564
}
6665
})
6766
68-
const handleRemoteFileSelected = async (file) => {
67+
const openFile = async (file, connection_type) => {
6968
if (!file)
7069
return;
7170
72-
selectedFile.value = file;
7371
isOpened = true;
7472
await router.replace('/')
75-
appTitle.pushTitle(file)
73+
let ret = null
7674
77-
const ret = await service.openRemoteFile(file);
78-
collectionSettings.value = ret.collectionSettings;
79-
statusesList.value = ret.statusesList;
75+
if (connection_type === 'remote') {
76+
appTitle.pushTitle(file)
8077
81-
coinListViewRef.value.onOpenFile()
82-
}
78+
ret = await service.openRemoteFile(file);
79+
}
80+
else if (connection_type === 'local') {
81+
appTitle.pushTitle(file.name)
8382
84-
const handleFileUpload = async (file) => {
85-
if (!file)
86-
return;
83+
ret = await service.openLocalFile(file);
84+
}
8785
88-
selectedFile.value = file;
89-
isOpened = true;
90-
await router.replace('/')
91-
appTitle.pushTitle(file.name)
86+
if (ret) {
87+
collectionSettings.value = ret.collectionSettings;
88+
statusesList.value = ret.statusesList;
9289
93-
const ret = await service.openLocalFile(file);
94-
collectionSettings.value = ret.collectionSettings;
95-
statusesList.value = ret.statusesList;
90+
coinListViewRef.value.onOpenFile()
91+
}
92+
}
9693
97-
coinListViewRef.value.onOpenFile()
94+
const handleRemoteFileSelected = async (file) => {
95+
await openFile(file, 'remote')
96+
}
97+
98+
const handleFileUpload = async (file) => {
99+
await openFile(file, 'local')
98100
}
99101
</script>
100102

frontend/src/composables/useService.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,29 @@ export function useService(passwordDialogRef) {
164164
}
165165

166166
const versionValid = await checkDbVersion(collectionSettings);
167-
if (versionValid) {
167+
if (!versionValid) {
168+
return null;
169+
}
170+
else {
168171
const passwordValid = await checkDbPassword(collectionSettings)
169-
if (passwordValid) {
170-
await globalStatus.startLoading('Load collection');
171-
172-
try {
173-
const responseFilters = await api.get('/api/filters', {params: {f: file}})
174-
statusesList = responseFilters.data
175-
}
176-
catch (err) {
177-
globalStatus.error.value = err
178-
}
179-
finally {
180-
await globalStatus.finishLoading();
181-
}
172+
if (!passwordValid) {
173+
return null;
182174
}
183175
}
184176

177+
await globalStatus.startLoading('Load collection');
178+
179+
try {
180+
const responseFilters = await api.get('/api/filters', {params: {f: file}})
181+
statusesList = responseFilters.data
182+
}
183+
catch (err) {
184+
globalStatus.error.value = err
185+
}
186+
finally {
187+
await globalStatus.finishLoading();
188+
}
189+
185190
return {collectionSettings, statusesList};
186191
}
187192

@@ -215,6 +220,17 @@ export function useService(passwordDialogRef) {
215220
}
216221
})
217222

223+
const versionValid = await checkDbVersion(collectionSettings);
224+
if (!versionValid) {
225+
return null;
226+
}
227+
else {
228+
const passwordValid = await checkDbPassword(collectionSettings)
229+
if (!passwordValid) {
230+
return null;
231+
}
232+
}
233+
218234
const field_sql = `SELECT id, title FROM fields WHERE id IN (${Object.keys(fieldIds)})`
219235
const fieldsDb = await executeQuery(field_sql)
220236

@@ -223,14 +239,8 @@ export function useService(passwordDialogRef) {
223239
collectionSettings.fields[field] = elem[1]
224240
})
225241

226-
const versionValid = await checkDbVersion(collectionSettings);
227-
if (versionValid) {
228-
const passwordValid = await checkDbPassword(collectionSettings)
229-
if (passwordValid) {
230-
const sql_statuses = 'SELECT DISTINCT status FROM coins';
231-
statusesList = (await executeQuery(sql_statuses)).flat()
232-
}
233-
}
242+
const sql_statuses = 'SELECT DISTINCT status FROM coins';
243+
statusesList = (await executeQuery(sql_statuses)).flat()
234244

235245
return {collectionSettings, statusesList};
236246
}

0 commit comments

Comments
 (0)