@geode/opengeodeweb-front 11.0.0 → 11.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.build/shared/utils/response_handlers/load.js +5 -19
- package/app/components/MissingFilesSelector.vue +21 -12
- package/app/components/ObjectSelector.vue +33 -35
- package/app/stores/treeview.ts +17 -19
- package/internal/database/database.ts +42 -5
- package/package.json +4 -4
- package/shared/utils/response_handlers/load.ts +17 -56
|
@@ -7,19 +7,6 @@ function getObject(objectMap, key) {
|
|
|
7
7
|
if (!object) throw new Error(`Unknown geode object key: ${key}`);
|
|
8
8
|
return object;
|
|
9
9
|
}
|
|
10
|
-
function selectGeodeObject(objectMap) {
|
|
11
|
-
const objectKeys = Object.keys(objectMap);
|
|
12
|
-
if (objectKeys.length === 0) return;
|
|
13
|
-
const [firstKey] = objectKeys;
|
|
14
|
-
if (objectKeys.length === 1 && firstKey !== void 0 && getObject(objectMap, firstKey).is_loadable > 0) return firstKey;
|
|
15
|
-
const highestLoadScore = Math.max(...objectKeys.map((key) => getObject(objectMap, key).is_loadable));
|
|
16
|
-
if (highestLoadScore <= 0) return;
|
|
17
|
-
const bestScoreObjects = objectKeys.filter((key) => getObject(objectMap, key).is_loadable === highestLoadScore);
|
|
18
|
-
if (bestScoreObjects.length === 1) return bestScoreObjects[0];
|
|
19
|
-
const highestPriority = Math.max(...bestScoreObjects.map((key) => getObject(objectMap, key).object_priority ?? -Infinity));
|
|
20
|
-
const bestPriorityObjects = bestScoreObjects.filter((key) => getObject(objectMap, key).object_priority === highestPriority);
|
|
21
|
-
if (highestPriority !== -Infinity && bestPriorityObjects.length === 1) return bestPriorityObjects[0];
|
|
22
|
-
}
|
|
23
10
|
function intersectAllowedObjects(allowedObjectsList) {
|
|
24
11
|
const allKeys = [...new Set(allowedObjectsList.flatMap((object) => Object.keys(object)))];
|
|
25
12
|
const commonKeys = allKeys.filter((key) => allowedObjectsList.every((object) => key in object));
|
|
@@ -42,8 +29,7 @@ function resolveAllowedObjects(filenames, allowedObjectsList) {
|
|
|
42
29
|
const { commonKeys, allKeys, mergedAllowedObjects } = intersectAllowedObjects(allowedObjectsList);
|
|
43
30
|
return {
|
|
44
31
|
mergedAllowedObjects,
|
|
45
|
-
multipleFilesNoCommon: filenames.length > 1 && allKeys.length > 0 && commonKeys.length === 0
|
|
46
|
-
selectedGeodeObject: selectGeodeObject(mergedAllowedObjects)
|
|
32
|
+
multipleFilesNoCommon: filenames.length > 1 && allKeys.length > 0 && commonKeys.length === 0
|
|
47
33
|
};
|
|
48
34
|
}
|
|
49
35
|
function sortCandidates(objectMap) {
|
|
@@ -54,13 +40,13 @@ function sortCandidates(objectMap) {
|
|
|
54
40
|
return (objectB.object_priority ?? -Infinity) - (objectA.object_priority ?? -Infinity);
|
|
55
41
|
});
|
|
56
42
|
}
|
|
57
|
-
function resolveAllowedObjectsPerFile(filenames,
|
|
43
|
+
function resolveAllowedObjectsPerFile(filenames, responses) {
|
|
58
44
|
return filenames.map((filename, index) => {
|
|
59
|
-
const
|
|
45
|
+
const response = responses[index];
|
|
60
46
|
return {
|
|
61
47
|
filename,
|
|
62
|
-
candidates: sortCandidates(
|
|
63
|
-
|
|
48
|
+
candidates: sortCandidates(response?.allowed_objects ?? {}),
|
|
49
|
+
selectedGeodeObjects: [...response?.objects_to_load ?? []]
|
|
64
50
|
};
|
|
65
51
|
});
|
|
66
52
|
}
|
|
@@ -35,8 +35,8 @@ const emit = defineEmits<Emits>();
|
|
|
35
35
|
|
|
36
36
|
interface Props {
|
|
37
37
|
multiple: boolean;
|
|
38
|
-
// Filename -> geode object
|
|
39
|
-
geodeObjectTypes?: Record<string, GeodeObjectType>;
|
|
38
|
+
// Filename -> geode object types, each file is checked with each of its types (unused for time series)
|
|
39
|
+
geodeObjectTypes?: Record<string, GeodeObjectType[]>;
|
|
40
40
|
filenames: string[];
|
|
41
41
|
files?: UploadFile[];
|
|
42
42
|
timeSeries?: boolean;
|
|
@@ -76,6 +76,7 @@ const can_skip = computed(
|
|
|
76
76
|
() => missing_by_file.value.length > 0 && files_without_mandatory.value.length > 0,
|
|
77
77
|
);
|
|
78
78
|
const toggle_loading = useToggle(loading);
|
|
79
|
+
const backStore = useBackStore();
|
|
79
80
|
const uploading = ref<boolean>(false);
|
|
80
81
|
|
|
81
82
|
function files_uploaded_event(value: UploadFile[]): void {
|
|
@@ -102,20 +103,29 @@ function reset_missing_state(): void {
|
|
|
102
103
|
missing_by_file.value = [];
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
function
|
|
106
|
+
function request_type_plan(
|
|
107
|
+
filename: string,
|
|
108
|
+
geode_object_type: GeodeObjectType,
|
|
109
|
+
): Promise<FilePlan> {
|
|
110
|
+
const params = { geode_object_type, filename };
|
|
111
|
+
return backStore.request({ schema, params });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// A file holding several contents is checked once per type, the missing files are merged
|
|
115
|
+
async function request_file_plan(filename: string): Promise<FilePlan> {
|
|
106
116
|
if (isCsvFile(filename)) {
|
|
107
|
-
return
|
|
108
|
-
has_missing_files: false,
|
|
109
|
-
mandatory_files: [],
|
|
110
|
-
additional_files: [],
|
|
111
|
-
});
|
|
117
|
+
return { has_missing_files: false, mandatory_files: [], additional_files: [] };
|
|
112
118
|
}
|
|
113
|
-
const backStore = useBackStore();
|
|
114
119
|
if (timeSeries) {
|
|
115
120
|
return backStore.request({ schema: time_series_schema, params: { filename } });
|
|
116
121
|
}
|
|
117
|
-
const
|
|
118
|
-
|
|
122
|
+
const types = geodeObjectTypes[filename] ?? [];
|
|
123
|
+
const plans = await Promise.all(types.map((type) => request_type_plan(filename, type)));
|
|
124
|
+
return {
|
|
125
|
+
has_missing_files: plans.some((plan) => plan.has_missing_files),
|
|
126
|
+
mandatory_files: [...new Set(plans.flatMap((plan) => plan.mandatory_files))],
|
|
127
|
+
additional_files: [...new Set(plans.flatMap((plan) => plan.additional_files))],
|
|
128
|
+
};
|
|
119
129
|
}
|
|
120
130
|
|
|
121
131
|
function collect_file_plans(values: FilePlan[]): void {
|
|
@@ -186,7 +196,6 @@ async function upload_missing_from(
|
|
|
186
196
|
useFeedbackStore().add_warning(`The selected folder does not contain: ${expected.join(", ")}`);
|
|
187
197
|
return;
|
|
188
198
|
}
|
|
189
|
-
const backStore = useBackStore();
|
|
190
199
|
await Promise.all(found.map((file) => backStore.upload(file)));
|
|
191
200
|
emit("update_values", { additional_files: [...uploaded, ...found] });
|
|
192
201
|
await missing_files();
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import {
|
|
3
|
+
type AllowedObjectMap,
|
|
4
|
+
type AllowedObjectsResponse,
|
|
3
5
|
type FileAllowedObjects,
|
|
4
6
|
resolveAllowedObjects,
|
|
5
7
|
resolveAllowedObjectsPerFile,
|
|
@@ -10,13 +12,6 @@ import { geode_objects } from "@ogw_front/assets/geode_objects";
|
|
|
10
12
|
import schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
|
|
11
13
|
import { useBackStore } from "@ogw_front/stores/back";
|
|
12
14
|
|
|
13
|
-
// Mirrors the (unexported) shape produced by shared/utils/response_handlers/load.ts.
|
|
14
|
-
interface AllowedObject {
|
|
15
|
-
is_loadable: number;
|
|
16
|
-
object_priority?: number;
|
|
17
|
-
}
|
|
18
|
-
type AllowedObjectMap = Record<string, AllowedObject>;
|
|
19
|
-
|
|
20
15
|
const schema = schemas.opengeodeweb_back.allowed_objects;
|
|
21
16
|
|
|
22
17
|
interface PendingGroup {
|
|
@@ -26,8 +21,8 @@ interface PendingGroup {
|
|
|
26
21
|
}
|
|
27
22
|
|
|
28
23
|
const emit = defineEmits<{
|
|
29
|
-
// Filename -> geode object
|
|
30
|
-
update_values: [value: { geode_object_types: Record<string, GeodeObjectType> }];
|
|
24
|
+
// Filename -> geode object types (one per content of the file), files that cannot be loaded are left out
|
|
25
|
+
update_values: [value: { geode_object_types: Record<string, GeodeObjectType[]> }];
|
|
31
26
|
increment_step: [];
|
|
32
27
|
}>();
|
|
33
28
|
|
|
@@ -44,7 +39,7 @@ const allowedGeodeObjects = ref<AllowedObjectMap>({});
|
|
|
44
39
|
const toggleLoading = useToggle(loading);
|
|
45
40
|
const multipleFilesNoCommon = ref<boolean>(false);
|
|
46
41
|
// Types already known, files left to choose for, and files that cannot be loaded
|
|
47
|
-
const resolvedTypes = ref<Record<string,
|
|
42
|
+
const resolvedTypes = ref<Record<string, GeodeObjectType[]>>({});
|
|
48
43
|
const pendingFilenames = ref<string[]>([]);
|
|
49
44
|
const pendingGroups = ref<PendingGroup[]>([]);
|
|
50
45
|
const skippedFiles = ref<string[]>([]);
|
|
@@ -52,16 +47,15 @@ const showPerFile = ref<boolean>(false);
|
|
|
52
47
|
// Every file got its type without the user, nothing to display
|
|
53
48
|
const autoResolved = ref<boolean>(false);
|
|
54
49
|
|
|
55
|
-
|
|
56
|
-
const promiseArray = filenames.map((filename): Promise<
|
|
50
|
+
function fetchAllowedObjectsList(): Promise<AllowedObjectsResponse[]> {
|
|
51
|
+
const promiseArray = filenames.map((filename): Promise<AllowedObjectsResponse> => {
|
|
57
52
|
const params = { filename };
|
|
58
53
|
return backStore.request({ schema, params });
|
|
59
54
|
});
|
|
60
|
-
|
|
61
|
-
return responses.map((response) => response.allowed_objects);
|
|
55
|
+
return Promise.all(promiseArray);
|
|
62
56
|
}
|
|
63
57
|
|
|
64
|
-
function emitGeodeObjectTypes(geode_object_types: Record<string, GeodeObjectType>): void {
|
|
58
|
+
function emitGeodeObjectTypes(geode_object_types: Record<string, GeodeObjectType[]>): void {
|
|
65
59
|
emit("update_values", { geode_object_types });
|
|
66
60
|
emit("increment_step");
|
|
67
61
|
}
|
|
@@ -70,13 +64,13 @@ function setGeodeObject(geode_object_type: GeodeObjectType | undefined): void {
|
|
|
70
64
|
if (!geode_object_type) {
|
|
71
65
|
return;
|
|
72
66
|
}
|
|
73
|
-
const chosen = pendingFilenames.value.map((filename) => [filename, geode_object_type]);
|
|
67
|
+
const chosen = pendingFilenames.value.map((filename) => [filename, [geode_object_type]]);
|
|
74
68
|
emitGeodeObjectTypes({ ...resolvedTypes.value, ...Object.fromEntries(chosen) });
|
|
75
69
|
}
|
|
76
70
|
|
|
77
71
|
function confirmPerFile(): void {
|
|
78
72
|
const chosen = pendingGroups.value.flatMap((group) =>
|
|
79
|
-
group.filenames.map((filename) => [filename, group.selected]),
|
|
73
|
+
group.filenames.map((filename) => [filename, [group.selected]]),
|
|
80
74
|
);
|
|
81
75
|
emitGeodeObjectTypes({ ...resolvedTypes.value, ...Object.fromEntries(chosen) });
|
|
82
76
|
}
|
|
@@ -114,23 +108,22 @@ function geodeObjectImage(key: string): string | undefined {
|
|
|
114
108
|
function showCommonGeodeObjects(
|
|
115
109
|
pendingNames: readonly string[],
|
|
116
110
|
allowedObjectsList: readonly AllowedObjectMap[],
|
|
117
|
-
):
|
|
111
|
+
): void {
|
|
118
112
|
const resolved = resolveAllowedObjects(pendingNames, allowedObjectsList);
|
|
119
113
|
allowedGeodeObjects.value = resolved.mergedAllowedObjects;
|
|
120
114
|
multipleFilesNoCommon.value = resolved.multipleFilesNoCommon;
|
|
121
|
-
return resolved.selectedGeodeObject;
|
|
122
115
|
}
|
|
123
116
|
|
|
124
|
-
function toResolvedEntries(loadable: readonly FileAllowedObjects[]): [string,
|
|
125
|
-
return loadable.flatMap((file): [string,
|
|
126
|
-
if (file.
|
|
117
|
+
function toResolvedEntries(loadable: readonly FileAllowedObjects[]): [string, GeodeObjectType[]][] {
|
|
118
|
+
return loadable.flatMap((file): [string, GeodeObjectType[]][] => {
|
|
119
|
+
if (file.selectedGeodeObjects.length === 0) {
|
|
127
120
|
return [];
|
|
128
121
|
}
|
|
129
|
-
return [[file.filename, file.
|
|
122
|
+
return [[file.filename, file.selectedGeodeObjects]];
|
|
130
123
|
});
|
|
131
124
|
}
|
|
132
125
|
|
|
133
|
-
//
|
|
126
|
+
// Emits when nothing is pending, else shows the common choice cards. Returns true when the per file panel is not needed
|
|
134
127
|
function resolveWithoutPanel(
|
|
135
128
|
pending: readonly FileAllowedObjects[],
|
|
136
129
|
allowedObjectsList: readonly AllowedObjectMap[],
|
|
@@ -144,28 +137,31 @@ function resolveWithoutPanel(
|
|
|
144
137
|
(file) => allowedObjectsList[filenames.indexOf(file.filename)] ?? {},
|
|
145
138
|
);
|
|
146
139
|
// Pending files sharing a loadable type: one choice for all of them
|
|
147
|
-
|
|
140
|
+
// The backend could not decide for these files: the user always chooses, never the front
|
|
141
|
+
showCommonGeodeObjects(pendingFilenames.value, pendingAllowedObjects);
|
|
148
142
|
if (Object.values(allowedGeodeObjects.value).some((object) => object.is_loadable > 0)) {
|
|
149
|
-
setGeodeObject(selected);
|
|
150
143
|
return true;
|
|
151
144
|
}
|
|
152
145
|
return false;
|
|
153
146
|
}
|
|
154
147
|
|
|
155
148
|
// Each file gets its own type. Returns true when the per file panel is needed, i.e. the files cannot be handled by a single choice
|
|
156
|
-
function resolvePerFile(
|
|
157
|
-
const files = resolveAllowedObjectsPerFile(filenames,
|
|
158
|
-
const
|
|
149
|
+
function resolvePerFile(responses: readonly AllowedObjectsResponse[]): boolean {
|
|
150
|
+
const files = resolveAllowedObjectsPerFile(filenames, responses);
|
|
151
|
+
const allowedObjectsList = responses.map((response) => response.allowed_objects);
|
|
152
|
+
const loadable = files.filter(
|
|
153
|
+
(file) => file.candidates.length > 0 || file.selectedGeodeObjects.length > 0,
|
|
154
|
+
);
|
|
159
155
|
if (loadable.length === 0) {
|
|
160
156
|
// Nothing can be loaded: show why with the common types
|
|
161
157
|
showCommonGeodeObjects(filenames, allowedObjectsList);
|
|
162
158
|
return false;
|
|
163
159
|
}
|
|
164
|
-
const pending = loadable.filter((file) => file.
|
|
160
|
+
const pending = loadable.filter((file) => file.selectedGeodeObjects.length === 0);
|
|
165
161
|
resolvedTypes.value = Object.fromEntries(toResolvedEntries(loadable));
|
|
166
162
|
pendingFilenames.value = pending.map((file) => file.filename);
|
|
167
163
|
skippedFiles.value = files
|
|
168
|
-
.filter((file) => file
|
|
164
|
+
.filter((file) => !loadable.includes(file))
|
|
169
165
|
.map((file) => file.filename);
|
|
170
166
|
if (skippedFiles.value.length === 0 && resolveWithoutPanel(pending, allowedObjectsList)) {
|
|
171
167
|
return false;
|
|
@@ -180,8 +176,8 @@ async function getAllowedGeodeObjects(): Promise<void> {
|
|
|
180
176
|
multipleFilesNoCommon.value = false;
|
|
181
177
|
showPerFile.value = false;
|
|
182
178
|
|
|
183
|
-
const
|
|
184
|
-
showPerFile.value = resolvePerFile(
|
|
179
|
+
const responses = await fetchAllowedObjectsList();
|
|
180
|
+
showPerFile.value = resolvePerFile(responses);
|
|
185
181
|
toggleLoading();
|
|
186
182
|
}
|
|
187
183
|
// oxlint-disable-next-line no-top-level-await
|
|
@@ -207,9 +203,11 @@ await getAllowedGeodeObjects();
|
|
|
207
203
|
/>
|
|
208
204
|
</v-col>
|
|
209
205
|
</v-row>
|
|
210
|
-
<v-row v-for="(
|
|
206
|
+
<v-row v-for="(types, filename) in resolvedTypes" :key="filename" align="center">
|
|
211
207
|
<v-chip class="ma-1" size="small">{{ filename }}</v-chip>
|
|
212
|
-
<v-chip class="ma-1" size="small" variant="tonal">
|
|
208
|
+
<v-chip v-for="type in types" :key="type" class="ma-1" size="small" variant="tonal">
|
|
209
|
+
{{ type }}
|
|
210
|
+
</v-chip>
|
|
213
211
|
</v-row>
|
|
214
212
|
<v-row v-if="skippedFiles.length" align="center">
|
|
215
213
|
<v-icon color="warning" icon="mdi-file-alert-outline" class="ma-1" />
|
package/app/stores/treeview.ts
CHANGED
|
@@ -13,10 +13,9 @@ import type {
|
|
|
13
13
|
ViewerType,
|
|
14
14
|
ViewerTyped,
|
|
15
15
|
} from "@ogw_front/types/identifiers";
|
|
16
|
-
import type { Table } from "dexie";
|
|
17
16
|
import type { TreeGroup, TreeNode } from "@ogw_front/types/tree";
|
|
18
17
|
import { ref, watch } from "vue";
|
|
19
|
-
import {
|
|
18
|
+
import { getTable } from "@ogw_internal/database/database";
|
|
20
19
|
|
|
21
20
|
const PANEL_WIDTH = 300;
|
|
22
21
|
|
|
@@ -90,12 +89,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
|
|
|
90
89
|
const pendingSelectionIds = ref<string[]>([]);
|
|
91
90
|
const rowHeights = ref<number[]>([]);
|
|
92
91
|
|
|
93
|
-
|
|
94
|
-
type DatabaseTables = Record<string, unknown>;
|
|
95
|
-
// oxlint-disable-next-line no-unsafe-type-assertion -- database's table map is dynamically typed at runtime; see comment above.
|
|
96
|
-
const typedDatabase = database as unknown as DatabaseTables;
|
|
97
|
-
// oxlint-disable-next-line no-unsafe-type-assertion -- database's table map is dynamically typed at runtime; see comment above.
|
|
98
|
-
const treeview_config_db = typedDatabase.treeview_config as Table<TreeviewConfigRecord, string>;
|
|
92
|
+
const treeview_config_db = getTable<TreeviewConfigRecord>("treeview_config");
|
|
99
93
|
|
|
100
94
|
async function loadConfig(): Promise<void> {
|
|
101
95
|
try {
|
|
@@ -116,7 +110,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
|
|
|
116
110
|
rowHeights.value = config.rowHeights;
|
|
117
111
|
}
|
|
118
112
|
} catch (error) {
|
|
119
|
-
consola.error("Failed to load treeview config:", error);
|
|
113
|
+
consola.error("Failed to load treeview config:", String(error));
|
|
120
114
|
}
|
|
121
115
|
}
|
|
122
116
|
// oxlint-disable-next-line typescript/no-floating-promises -- loadConfig catches its own errors internally.
|
|
@@ -124,7 +118,7 @@ export const useTreeviewStore = defineStore("treeview", () => {
|
|
|
124
118
|
|
|
125
119
|
watch(
|
|
126
120
|
[opened_views, panelWidth, additionalPanelWidth, selection, rowHeights],
|
|
127
|
-
() => {
|
|
121
|
+
async () => {
|
|
128
122
|
// oxlint-disable-next-line unicorn/prefer-structured-clone, no-unsafe-type-assertion -- JSON round-trip of a known-shape ref; result matches the source type.
|
|
129
123
|
const clean_opened_views = JSON.parse(JSON.stringify(opened_views.value)) as OpenedView[];
|
|
130
124
|
// oxlint-disable-next-line unicorn/prefer-structured-clone, no-unsafe-type-assertion -- JSON round-trip of a known-shape ref; result matches the source type.
|
|
@@ -132,15 +126,19 @@ export const useTreeviewStore = defineStore("treeview", () => {
|
|
|
132
126
|
// oxlint-disable-next-line unicorn/prefer-structured-clone, no-unsafe-type-assertion -- JSON round-trip of a known-shape ref; result matches the source type.
|
|
133
127
|
const clean_rowHeights = JSON.parse(JSON.stringify(rowHeights.value)) as number[];
|
|
134
128
|
|
|
135
|
-
//
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
129
|
+
// Best-effort persistence: a failure is logged, not thrown.
|
|
130
|
+
try {
|
|
131
|
+
await treeview_config_db.put({
|
|
132
|
+
id: "main",
|
|
133
|
+
opened_views: clean_opened_views,
|
|
134
|
+
panelWidth: panelWidth.value,
|
|
135
|
+
additionalPanelWidth: additionalPanelWidth.value,
|
|
136
|
+
selectionIds: clean_selectionIds,
|
|
137
|
+
rowHeights: clean_rowHeights,
|
|
138
|
+
});
|
|
139
|
+
} catch (error) {
|
|
140
|
+
consola.error("Failed to save treeview config:", String(error));
|
|
141
|
+
}
|
|
144
142
|
},
|
|
145
143
|
{ deep: true },
|
|
146
144
|
);
|
|
@@ -94,27 +94,64 @@ await initialDatabase.clear();
|
|
|
94
94
|
// The set of tables is assembled dynamically at runtime (Database.addTable/addTables add stores on the fly), so fully modelling this with Dexie's row generics isn't worth it here: the proxy target is typed loosely as "any table name maps to a Dexie Table of loosely-typed rows".
|
|
95
95
|
type DatabaseTables = Record<string, Table<Record<string, unknown>, string>>;
|
|
96
96
|
|
|
97
|
+
// Database.addTables closes the current instance and opens a new one, so a table taken from an instance must not be kept: a store keeping it would query a closed database.
|
|
98
|
+
// A live table resolves the table of the current instance at each access instead.
|
|
99
|
+
function currentInstance(): Dexie {
|
|
100
|
+
// Set at module load time below; always defined by the time the database is used.
|
|
101
|
+
if (!databaseContainer.instance) {
|
|
102
|
+
throw new Error("The database is not open");
|
|
103
|
+
}
|
|
104
|
+
return databaseContainer.instance;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function liveTable<TRow>(tableName: string): Table<TRow, string> {
|
|
108
|
+
const handler: ProxyHandler<object> = {
|
|
109
|
+
get(_target, prop: string | symbol): unknown {
|
|
110
|
+
const table = currentInstance().table(tableName);
|
|
111
|
+
const value: unknown = Reflect.get(table, prop, table);
|
|
112
|
+
if (typeof value === "function") {
|
|
113
|
+
// oxlint-disable-next-line no-unsafe-return
|
|
114
|
+
return value.bind(table);
|
|
115
|
+
}
|
|
116
|
+
return value;
|
|
117
|
+
},
|
|
118
|
+
// Dexie checks that the tables given to a transaction are instances of its Table.
|
|
119
|
+
getPrototypeOf(): object | null {
|
|
120
|
+
return Reflect.getPrototypeOf(currentInstance().table(tableName));
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
// oxlint-disable-next-line no-unsafe-type-assertion -- the proxy forwards every access to a Dexie Table.
|
|
124
|
+
return new Proxy({}, handler) as Table<TRow, string>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isTableName(instance: Dexie, prop: string | symbol): prop is string {
|
|
128
|
+
return typeof prop === "string" && instance.tables.some((table) => table.name === prop);
|
|
129
|
+
}
|
|
130
|
+
|
|
97
131
|
const database = new Proxy<DatabaseTables>(
|
|
98
132
|
{},
|
|
99
133
|
{
|
|
100
134
|
get(_target, prop: string | symbol): unknown {
|
|
135
|
+
const dexie = currentInstance();
|
|
136
|
+
if (isTableName(dexie, prop)) {
|
|
137
|
+
return liveTable(prop);
|
|
138
|
+
}
|
|
101
139
|
// The instance is a Dexie subclass whose tables are only known dynamically at runtime.
|
|
102
140
|
// oxlint-disable-next-line no-unsafe-type-assertion
|
|
103
|
-
const instance =
|
|
141
|
+
const instance = dexie as unknown as Record<string | symbol, unknown>;
|
|
104
142
|
const value = instance[prop];
|
|
105
143
|
if (typeof value === "function") {
|
|
106
144
|
// oxlint-disable-next-line no-unsafe-return
|
|
107
|
-
return value.bind(
|
|
145
|
+
return value.bind(dexie);
|
|
108
146
|
}
|
|
109
147
|
return value;
|
|
110
148
|
},
|
|
111
149
|
},
|
|
112
150
|
);
|
|
113
151
|
|
|
114
|
-
//
|
|
152
|
+
// Callers cast to the row type they know a given table holds.
|
|
115
153
|
function getTable<TRow>(tableName: string): Table<TRow, string> {
|
|
116
|
-
|
|
117
|
-
return database[tableName] as unknown as Table<TRow, string>;
|
|
154
|
+
return liveTable<TRow>(tableName);
|
|
118
155
|
}
|
|
119
156
|
|
|
120
157
|
export { Database, database, getTable };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geode/opengeodeweb-front",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.1.0-rc.1",
|
|
4
4
|
"description": "OpenSource Vue/Nuxt/Pinia/Vuetify framework for web applications",
|
|
5
5
|
"homepage": "https://github.com/Geode-solutions/OpenGeodeWeb-Front",
|
|
6
6
|
"bugs": {
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"prepublishOnly": "npm run build"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@geode/cloud-api": "
|
|
68
|
-
"@geode/opengeodeweb-back": "
|
|
69
|
-
"@geode/opengeodeweb-viewer": "
|
|
67
|
+
"@geode/cloud-api": "next",
|
|
68
|
+
"@geode/opengeodeweb-back": "next",
|
|
69
|
+
"@geode/opengeodeweb-viewer": "next",
|
|
70
70
|
"@kitware/vtk.js": "33.3.0",
|
|
71
71
|
"@mdi/font": "7.4.47",
|
|
72
72
|
"@msgpack/msgpack": "2.8.0",
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
interface AllowedObject {
|
|
2
2
|
readonly is_loadable: number;
|
|
3
3
|
readonly object_priority?: number;
|
|
4
|
+
readonly loadable_family?: string;
|
|
4
5
|
}
|
|
5
6
|
type AllowedObjectMap = Record<string, AllowedObject>;
|
|
7
|
+
// Mirrors the allowed_objects route response
|
|
8
|
+
interface AllowedObjectsResponse {
|
|
9
|
+
readonly allowed_objects: AllowedObjectMap;
|
|
10
|
+
// One type per content of the file, empty when the user has to choose
|
|
11
|
+
readonly objects_to_load: readonly string[];
|
|
12
|
+
}
|
|
6
13
|
|
|
7
14
|
function getFileExtension(filename: string): string {
|
|
8
15
|
return filename.slice(filename.lastIndexOf(".") + 1);
|
|
@@ -16,47 +23,6 @@ function getObject(objectMap: AllowedObjectMap, key: string): AllowedObject {
|
|
|
16
23
|
return object;
|
|
17
24
|
}
|
|
18
25
|
|
|
19
|
-
function selectGeodeObject(objectMap: AllowedObjectMap): string | undefined {
|
|
20
|
-
const objectKeys = Object.keys(objectMap);
|
|
21
|
-
if (objectKeys.length === 0) {
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
const [firstKey] = objectKeys;
|
|
25
|
-
if (
|
|
26
|
-
objectKeys.length === 1 &&
|
|
27
|
-
firstKey !== undefined &&
|
|
28
|
-
getObject(objectMap, firstKey).is_loadable > 0
|
|
29
|
-
) {
|
|
30
|
-
return firstKey;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const highestLoadScore = Math.max(
|
|
34
|
-
...objectKeys.map((key) => getObject(objectMap, key).is_loadable),
|
|
35
|
-
);
|
|
36
|
-
if (highestLoadScore <= 0) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const bestScoreObjects = objectKeys.filter(
|
|
41
|
-
(key) => getObject(objectMap, key).is_loadable === highestLoadScore,
|
|
42
|
-
);
|
|
43
|
-
if (bestScoreObjects.length === 1) {
|
|
44
|
-
return bestScoreObjects[0];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const highestPriority = Math.max(
|
|
48
|
-
...bestScoreObjects.map((key) => getObject(objectMap, key).object_priority ?? -Infinity),
|
|
49
|
-
);
|
|
50
|
-
const bestPriorityObjects = bestScoreObjects.filter(
|
|
51
|
-
(key) => getObject(objectMap, key).object_priority === highestPriority,
|
|
52
|
-
);
|
|
53
|
-
if (highestPriority !== -Infinity && bestPriorityObjects.length === 1) {
|
|
54
|
-
return bestPriorityObjects[0];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return undefined;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
26
|
function intersectAllowedObjects(allowedObjectsList: readonly AllowedObjectMap[]): {
|
|
61
27
|
commonKeys: string[];
|
|
62
28
|
allKeys: string[];
|
|
@@ -90,27 +56,22 @@ function resolveAllowedObjects(
|
|
|
90
56
|
): {
|
|
91
57
|
mergedAllowedObjects: AllowedObjectMap;
|
|
92
58
|
multipleFilesNoCommon: boolean;
|
|
93
|
-
selectedGeodeObject: string | undefined;
|
|
94
59
|
} {
|
|
95
60
|
const { commonKeys, allKeys, mergedAllowedObjects } = intersectAllowedObjects(allowedObjectsList);
|
|
96
61
|
|
|
97
62
|
const multipleFilesNoCommon =
|
|
98
63
|
filenames.length > 1 && allKeys.length > 0 && commonKeys.length === 0;
|
|
99
64
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
mergedAllowedObjects,
|
|
104
|
-
multipleFilesNoCommon,
|
|
105
|
-
selectedGeodeObject,
|
|
106
|
-
};
|
|
65
|
+
// No automatic pick here: the backend is the only one selecting types, the user chooses
|
|
66
|
+
return { mergedAllowedObjects, multipleFilesNoCommon };
|
|
107
67
|
}
|
|
108
68
|
|
|
109
69
|
interface FileAllowedObjects {
|
|
110
70
|
readonly filename: string;
|
|
111
71
|
// Loadable types only, sorted by best is_loadable then best object_priority
|
|
112
72
|
readonly candidates: string[];
|
|
113
|
-
|
|
73
|
+
// Types the backend selected to load every content of the file, empty when the user has to choose
|
|
74
|
+
readonly selectedGeodeObjects: string[];
|
|
114
75
|
}
|
|
115
76
|
|
|
116
77
|
function sortCandidates(objectMap: AllowedObjectMap): string[] {
|
|
@@ -126,20 +87,20 @@ function sortCandidates(objectMap: AllowedObjectMap): string[] {
|
|
|
126
87
|
});
|
|
127
88
|
}
|
|
128
89
|
|
|
129
|
-
// Each file gets its own geode object
|
|
90
|
+
// Each file gets its own geode object types; files are no longer required to share one
|
|
130
91
|
function resolveAllowedObjectsPerFile(
|
|
131
92
|
filenames: readonly string[],
|
|
132
|
-
|
|
93
|
+
responses: readonly AllowedObjectsResponse[],
|
|
133
94
|
): FileAllowedObjects[] {
|
|
134
95
|
return filenames.map((filename, index) => {
|
|
135
|
-
const
|
|
96
|
+
const response = responses[index];
|
|
136
97
|
return {
|
|
137
98
|
filename,
|
|
138
|
-
candidates: sortCandidates(
|
|
139
|
-
|
|
99
|
+
candidates: sortCandidates(response?.allowed_objects ?? {}),
|
|
100
|
+
selectedGeodeObjects: [...(response?.objects_to_load ?? [])],
|
|
140
101
|
};
|
|
141
102
|
});
|
|
142
103
|
}
|
|
143
104
|
|
|
144
105
|
export { resolveAllowedObjects, resolveAllowedObjectsPerFile, getFileExtension };
|
|
145
|
-
export type { FileAllowedObjects };
|
|
106
|
+
export type { AllowedObjectMap, AllowedObjectsResponse, FileAllowedObjects };
|