@geode/opengeodeweb-front 11.0.1-rc.1 → 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.
@@ -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, allowedObjectsList) {
43
+ function resolveAllowedObjectsPerFile(filenames, responses) {
58
44
  return filenames.map((filename, index) => {
59
- const objectMap = allowedObjectsList[index] ?? {};
45
+ const response = responses[index];
60
46
  return {
61
47
  filename,
62
- candidates: sortCandidates(objectMap),
63
- selectedGeodeObject: selectGeodeObject(objectMap)
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 type, each file is checked with its own type (unused for time series)
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 request_file_plan(filename: string): Promise<FilePlan> {
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 Promise.resolve({
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 params = { geode_object_type: geodeObjectTypes[filename] ?? "", filename };
118
- return backStore.request({ schema, params });
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 type, files that cannot be loaded are left out
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, 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
- async function fetchAllowedObjectsList(): Promise<AllowedObjectMap[]> {
56
- const promiseArray = filenames.map((filename): Promise<{ allowed_objects: AllowedObjectMap }> => {
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
- const responses = await Promise.all(promiseArray);
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
- ): string | undefined {
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, string][] {
125
- return loadable.flatMap((file): [string, string][] => {
126
- if (file.selectedGeodeObject === undefined) {
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.selectedGeodeObject]];
122
+ return [[file.filename, file.selectedGeodeObjects]];
130
123
  });
131
124
  }
132
125
 
133
- // Tries to settle the pending files without the per file panel. Returns true when it did
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
- const selected = showCommonGeodeObjects(pendingFilenames.value, pendingAllowedObjects);
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(allowedObjectsList: readonly AllowedObjectMap[]): boolean {
157
- const files = resolveAllowedObjectsPerFile(filenames, allowedObjectsList);
158
- const loadable = files.filter((file) => file.candidates.length > 0);
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.selectedGeodeObject === undefined);
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.candidates.length === 0)
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 allowedGeodeObjectsList = await fetchAllowedObjectsList();
184
- showPerFile.value = resolvePerFile(allowedGeodeObjectsList);
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="(type, filename) in resolvedTypes" :key="filename" align="center">
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">{{ type }}</v-chip>
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geode/opengeodeweb-front",
3
- "version": "11.0.1-rc.1",
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": {
@@ -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
- const selectedGeodeObject = selectGeodeObject(mergedAllowedObjects);
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
- readonly selectedGeodeObject: string | undefined;
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 type; files are no longer required to share one
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
- allowedObjectsList: readonly AllowedObjectMap[],
93
+ responses: readonly AllowedObjectsResponse[],
133
94
  ): FileAllowedObjects[] {
134
95
  return filenames.map((filename, index) => {
135
- const objectMap = allowedObjectsList[index] ?? {};
96
+ const response = responses[index];
136
97
  return {
137
98
  filename,
138
- candidates: sortCandidates(objectMap),
139
- selectedGeodeObject: selectGeodeObject(objectMap),
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 };