@geode/opengeodeweb-front 12.1.0 → 12.2.0-rc.2

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.
Files changed (57) hide show
  1. package/.build/server/utils/microservices_process.js +1 -1
  2. package/.build/tests/browser/helpers/crs.js +136 -0
  3. package/.build/tests/browser/helpers/crs_flows.js +60 -0
  4. package/.build/tests/browser/helpers/crs_shortlist.js +13 -0
  5. package/.build/tests/browser/helpers/crs_test_data.js +40 -0
  6. package/.build/tests/browser/suites/crs.js +142 -0
  7. package/.build/tests/browser/suites/crs_harmonize.js +63 -0
  8. package/.build/tests/browser/suites/crs_shortlist.js +31 -0
  9. package/.build/tests/browser/suites/index.js +6 -0
  10. package/app/app.config.ts +4 -0
  11. package/app/components/CrsAlign.vue +207 -0
  12. package/app/components/CrsDialog.vue +400 -0
  13. package/app/components/CrsDialogHost.vue +66 -0
  14. package/app/components/CrsSelector.vue +100 -3
  15. package/app/components/PickButton.vue +43 -0
  16. package/app/components/ProjectCrsDialog.vue +109 -0
  17. package/app/components/ToolPanel.vue +5 -2
  18. package/app/components/Viewer/CrsOverlays.vue +29 -0
  19. package/app/components/Viewer/Ui.vue +3 -2
  20. package/app/composables/crs.ts +197 -0
  21. package/app/composables/crs_align.ts +206 -0
  22. package/app/composables/crs_assign.ts +102 -0
  23. package/app/composables/crs_link.ts +22 -0
  24. package/app/composables/crs_shortlist.ts +63 -0
  25. package/app/composables/project_crs.ts +197 -0
  26. package/app/composables/user_setting.ts +140 -0
  27. package/app/plugins/activity_connections.client.ts +9 -0
  28. package/app/stores/activity.ts +130 -0
  29. package/app/stores/back.ts +7 -2
  30. package/app/stores/basemap.ts +19 -2
  31. package/app/stores/cloud.ts +1 -1
  32. package/app/stores/crs.ts +11 -106
  33. package/app/stores/crs_helpers/geographic_list.ts +44 -0
  34. package/app/stores/crs_helpers/project_crs.ts +60 -0
  35. package/app/stores/crs_helpers/requests.ts +60 -0
  36. package/app/utils/activity_connections.ts +36 -0
  37. package/app/utils/activity_params.ts +40 -0
  38. package/app/utils/crs.ts +17 -1
  39. package/app/utils/import_item.ts +87 -0
  40. package/app/utils/import_workflow.ts +36 -94
  41. package/app/utils/log.ts +4 -1
  42. package/app/utils/reload_object.ts +26 -0
  43. package/internal/utils/api_fetch.ts +13 -2
  44. package/internal/utils/track_request.ts +74 -0
  45. package/internal/utils/upload_file.ts +73 -39
  46. package/internal/utils/viewer_call.ts +49 -39
  47. package/package.json +5 -5
  48. package/server/utils/microservices_process.ts +4 -1
  49. package/tests/browser/data/test_lambert93_no_crs.og_pts3d +0 -0
  50. package/tests/browser/data/test_utm31n.og_pts3d +0 -0
  51. package/tests/browser/helpers/crs.ts +250 -0
  52. package/tests/browser/helpers/crs_flows.ts +115 -0
  53. package/tests/browser/helpers/crs_shortlist.ts +27 -0
  54. package/tests/browser/helpers/crs_test_data.ts +34 -0
  55. package/tests/browser/suites/crs.ts +228 -0
  56. package/tests/browser/suites/crs_harmonize.ts +96 -0
  57. package/tests/browser/suites/crs_shortlist.ts +37 -0
@@ -0,0 +1,140 @@
1
+ import type { Ref, ShallowRef } from "vue";
2
+ import { useLocalStorage } from "@vueuse/core";
3
+ import type { z } from "zod";
4
+
5
+ interface DesktopSettingsAPI {
6
+ app_settings: unknown;
7
+ app_settings_write: (settings: Record<string, unknown>) => Promise<unknown>;
8
+ }
9
+
10
+ // A setting of the user (theme, favorite CRS...), declared once next to the feature that uses it.
11
+ // Its value is replaced, never changed in place: `favorites.value = [...favorites.value, entry]`
12
+ interface UserSettingDefinition<Value> {
13
+ // Its key in the desktop settings.json
14
+ key: string;
15
+ // Checks the stored value on read, strictly: an invalid one gives the fallback. A setting whose type
16
+ // Changes takes a new key: the old value is left as is, never converted
17
+ schema: z.ZodType<Value>;
18
+ // A JSON value: copied for each use, compared when the setting is declared again
19
+ fallback: Value;
20
+ // Its key in the browser local storage
21
+ browserKey: string;
22
+ // The value shared by every caller on the desktop, with the settings API it is saved through
23
+ desktop?: { api: DesktopSettingsAPI; setting: ShallowRef<Value> };
24
+ }
25
+
26
+ // The browser key and fallback of each declared setting, as JSON
27
+ const declared = new Map<string, string>();
28
+
29
+ // Declares a setting, at module level. Declaring it again the same way (hot reload, tests) is fine;
30
+ // Declaring it differently is an error: two features would overwrite each other's value.
31
+ function defineUserSetting<Value>(options: {
32
+ key: string;
33
+ schema: z.ZodType<Value>;
34
+ fallback: Value;
35
+ browserKey?: string;
36
+ }): UserSettingDefinition<Value> {
37
+ const definition: UserSettingDefinition<Value> = {
38
+ ...options,
39
+ browserKey: options.browserKey ?? `ogw-${options.key}`,
40
+ };
41
+ const signature = JSON.stringify([definition.browserKey, definition.fallback]);
42
+ const existing = declared.get(definition.key);
43
+ if (existing !== undefined && existing !== signature) {
44
+ throw new Error(`User setting "${definition.key}" is already defined differently`);
45
+ }
46
+ declared.set(definition.key, signature);
47
+ return definition;
48
+ }
49
+
50
+ function hasDesktopSettingsAPI(
51
+ value: typeof globalThis,
52
+ ): value is typeof globalThis & { electronAPI: DesktopSettingsAPI } {
53
+ return (
54
+ "electronAPI" in value &&
55
+ typeof value.electronAPI === "object" &&
56
+ value.electronAPI !== null &&
57
+ "app_settings" in value.electronAPI &&
58
+ "app_settings_write" in value.electronAPI
59
+ );
60
+ }
61
+
62
+ // The stored value when the setting's schema accepts it, a copy of the fallback otherwise
63
+ function validated<Value>(definition: UserSettingDefinition<Value>, value: unknown): Value {
64
+ const result = definition.schema.safeParse(value);
65
+ if (result.success) {
66
+ return result.data;
67
+ }
68
+ return structuredClone(definition.fallback);
69
+ }
70
+
71
+ // Every value is stored as JSON. A value that is not JSON is a string stored raw by a previous version
72
+ // (the Vease color theme was stored as `dark`)
73
+ function parseStored(raw: string): unknown {
74
+ try {
75
+ return JSON.parse(raw);
76
+ } catch {
77
+ return raw;
78
+ }
79
+ }
80
+
81
+ function browserSetting<Value>(definition: UserSettingDefinition<Value>): Ref<Value> {
82
+ return useLocalStorage<Value>(definition.browserKey, structuredClone(definition.fallback), {
83
+ shallow: true,
84
+ serializer: {
85
+ read: (raw: string): Value => validated(definition, parseStored(raw)),
86
+ write: (value: Value): string => JSON.stringify(value),
87
+ },
88
+ });
89
+ }
90
+
91
+ // A copy without Vue proxies: toRaw only unwraps the outer one, not the elements a filter or a spread returns
92
+ function toPlain(value: unknown): unknown {
93
+ const raw: unknown = toRaw(value);
94
+ if (Array.isArray(raw)) {
95
+ return raw.map((item: unknown) => toPlain(item));
96
+ }
97
+ if (typeof raw === "object" && raw !== null) {
98
+ return Object.fromEntries(
99
+ Object.entries(raw).map(([entryKey, entryValue]) => [entryKey, toPlain(entryValue)]),
100
+ );
101
+ }
102
+ return raw;
103
+ }
104
+
105
+ function desktopSetting<Value>(
106
+ api: DesktopSettingsAPI,
107
+ definition: UserSettingDefinition<Value>,
108
+ ): Ref<Value> {
109
+ if (definition.desktop?.api === api) {
110
+ return definition.desktop.setting;
111
+ }
112
+ let saved: unknown = undefined;
113
+ if (typeof api.app_settings === "object" && api.app_settings !== null) {
114
+ saved = Reflect.get(api.app_settings, definition.key);
115
+ }
116
+ const setting = shallowRef(validated(definition, saved));
117
+ // Detached: the first caller's unmount must not stop the saving
118
+ effectScope(true).run(() => {
119
+ watch(setting, (value) => {
120
+ // Electron cannot send the Vue proxies a new value may hold, at any depth
121
+ void api.app_settings_write({ [definition.key]: toPlain(value) });
122
+ });
123
+ });
124
+ definition.desktop = { api, setting };
125
+ return setting;
126
+ }
127
+
128
+ // The value of a setting, shared by every caller. The desktop app clears its browser storage on every launch:
129
+ // There the settings live in its settings.json, read before the page renders and written on every change.
130
+ // The browser keeps them in its local storage.
131
+ function useUserSetting<Value>(definition: UserSettingDefinition<Value>): Ref<Value> {
132
+ const globalScope = globalThis;
133
+ if (!hasDesktopSettingsAPI(globalScope)) {
134
+ return browserSetting(definition);
135
+ }
136
+ return desktopSetting(globalScope.electronAPI, definition);
137
+ }
138
+
139
+ export type { UserSettingDefinition };
140
+ export { defineUserSetting, useUserSetting };
@@ -0,0 +1,9 @@
1
+ import { watchMicroserviceConnections } from "@ogw_front/utils/activity_connections";
2
+
3
+ export default defineNuxtPlugin({
4
+ name: "activity-connections",
5
+ dependsOn: ["pinia"],
6
+ setup() {
7
+ watchMicroserviceConnections();
8
+ },
9
+ });
@@ -0,0 +1,130 @@
1
+ import { summarizeParams } from "@ogw_front/utils/activity_params";
2
+
3
+ // Read-only journal of what the app is doing: microservice requests, server events, connection changes
4
+ const MAX_ENTRIES = 500;
5
+
6
+ type ActivityEntryKind = "http" | "ws" | "upload" | "event" | "connection";
7
+ type ActivityEntryStatus = "running" | "success" | "error" | "timeout" | "info";
8
+ type ActivityOutcome = { status: "success" } | { status: "error" | "timeout"; error: string };
9
+
10
+ interface ActivityEntry {
11
+ id: number;
12
+ source: string;
13
+ kind: ActivityEntryKind;
14
+ route: string;
15
+ status: ActivityEntryStatus;
16
+ started_at: number;
17
+ label?: string;
18
+ params?: string;
19
+ duration_ms?: number;
20
+ error?: string;
21
+ }
22
+
23
+ interface ActivityEntryInput {
24
+ source: string;
25
+ kind: ActivityEntryKind;
26
+ route: string;
27
+ label?: string;
28
+ params?: unknown;
29
+ }
30
+
31
+ interface ActivityLogInput extends ActivityEntryInput {
32
+ status: ActivityEntryStatus;
33
+ started_at?: number;
34
+ duration_ms?: number;
35
+ error?: string;
36
+ }
37
+
38
+ // An error or a timeout: what the activity panel counts and shows in red
39
+ function isFailure(status: ActivityEntryStatus): boolean {
40
+ return status === "error" || status === "timeout";
41
+ }
42
+
43
+ function createEntry(id: number, input: ActivityLogInput): ActivityEntry {
44
+ const { params, started_at, ...fields } = input;
45
+ const summary = summarizeParams(params);
46
+ return {
47
+ ...fields,
48
+ id,
49
+ started_at: started_at ?? Date.now(),
50
+ ...(summary !== undefined && { params: summary }),
51
+ };
52
+ }
53
+
54
+ // The errors not seen yet, counted in one place whether logged at once or failed later
55
+ function useUnseenErrors(): {
56
+ unseen_errors: Ref<number>;
57
+ countFailure: (status: ActivityEntryStatus) => void;
58
+ mark_errors_seen: () => void;
59
+ } {
60
+ const unseen_errors = ref(0);
61
+ function countFailure(status: ActivityEntryStatus): void {
62
+ if (isFailure(status)) {
63
+ unseen_errors.value += 1;
64
+ }
65
+ }
66
+ function mark_errors_seen(): void {
67
+ unseen_errors.value = 0;
68
+ }
69
+ return { unseen_errors, countFailure, mark_errors_seen };
70
+ }
71
+
72
+ const useActivityStore = defineStore("activity", () => {
73
+ const entries = ref<ActivityEntry[]>([]);
74
+ const { unseen_errors, countFailure, mark_errors_seen } = useUnseenErrors();
75
+ let next_id = 0;
76
+
77
+ const running = computed(() => entries.value.filter((entry) => entry.status === "running"));
78
+ const error_count = computed(
79
+ () => entries.value.filter((entry) => isFailure(entry.status)).length,
80
+ );
81
+
82
+ function log(input: ActivityLogInput): ActivityEntry {
83
+ next_id += 1;
84
+ const entry = createEntry(next_id, input);
85
+ entries.value.push(entry);
86
+ if (entries.value.length > MAX_ENTRIES) {
87
+ entries.value.splice(0, entries.value.length - MAX_ENTRIES);
88
+ }
89
+ countFailure(entry.status);
90
+ return entry;
91
+ }
92
+
93
+ function start_request(input: ActivityEntryInput): number {
94
+ return log({ ...input, status: "running" }).id;
95
+ }
96
+
97
+ function finish_request(entryId: number, outcome: ActivityOutcome): void {
98
+ const entry = entries.value.find((candidate) => candidate.id === entryId);
99
+ if (entry === undefined) {
100
+ return;
101
+ }
102
+ entry.duration_ms = Date.now() - entry.started_at;
103
+ entry.status = outcome.status;
104
+ if (outcome.status !== "success") {
105
+ entry.error = outcome.error;
106
+ }
107
+ countFailure(outcome.status);
108
+ }
109
+
110
+ // Empties the view only: running requests stay, they will still finish
111
+ function clear(): void {
112
+ entries.value = entries.value.filter((entry) => entry.status === "running");
113
+ mark_errors_seen();
114
+ }
115
+
116
+ return {
117
+ entries,
118
+ unseen_errors,
119
+ running,
120
+ error_count,
121
+ start_request,
122
+ finish_request,
123
+ log,
124
+ clear,
125
+ mark_errors_seen,
126
+ };
127
+ });
128
+
129
+ export { MAX_ENTRIES, isFailure, useActivityStore };
130
+ export type { ActivityEntry, ActivityEntryKind, ActivityEntryStatus, ActivityOutcome };
@@ -63,7 +63,7 @@ export const useBackStore = defineStore("back", {
63
63
  const feedbackStore = useFeedbackStore();
64
64
  const schema = back_schemas.opengeodeweb_back.ping;
65
65
  const result = await this.request(
66
- { schema },
66
+ { schema, log_success: false },
67
67
  {
68
68
  request_error_function: () => {
69
69
  feedbackStore.$patch({ server_error: true });
@@ -108,7 +108,11 @@ export const useBackStore = defineStore("back", {
108
108
  await Promise.resolve();
109
109
  },
110
110
  async request<Schema extends JsonRpcSchema>(
111
- { schema, params }: { schema: Schema; params?: ParamsOf<Schema> },
111
+ {
112
+ schema,
113
+ params,
114
+ log_success,
115
+ }: { schema: Schema; params?: ParamsOf<Schema>; log_success?: boolean },
112
116
  callbacks: RequestHandlers<ResponseOf<Schema>> = {},
113
117
  ): Promise<ResponseOf<Schema>> {
114
118
  const rpc_schema: JsonRpcSchema = schema;
@@ -122,6 +126,7 @@ export const useBackStore = defineStore("back", {
122
126
  schema: rpc_schema as JsonRpcSchema & { methods: string[] },
123
127
  params: params ?? {},
124
128
  headers: {},
129
+ ...(log_success !== undefined && { log_success }),
125
130
  },
126
131
  {
127
132
  ...callbacks,
@@ -6,11 +6,28 @@ import { useGeoreferenced } from "./basemap_helpers/georeferenced.js";
6
6
 
7
7
  const REBUILD_DELAY_MILLISECONDS = 500;
8
8
 
9
+ // Apps opt in with `ogwFront.basemap` in their app.config.ts: without it, no map is built or offered
10
+ function readBasemapOption(appConfig: ReturnType<typeof useAppConfig>): boolean {
11
+ // The resolved type holds the layer's literal default (false): widen it to the config input type
12
+ const ogwFront: { basemap?: boolean } | undefined = appConfig.ogwFront;
13
+ return ogwFront?.basemap === true;
14
+ }
15
+
9
16
  export const useBasemapStore = defineStore("basemap", () => {
10
- const { available, georeferencedIds, dataBounds, dataKey } = useGeoreferenced();
17
+ const appConfig = useAppConfig();
18
+ const enabled = computed(() => readBasemapOption(appConfig));
19
+ const georeferenced = useGeoreferenced();
20
+ const { georeferencedIds, dataBounds, dataKey } = georeferenced;
21
+ const available = computed(() => enabled.value && georeferenced.available.value);
11
22
  const layers = useBasemapLayers(georeferencedIds);
12
23
  const { shown, maps, opacities, crop, layersParams, applyLayers, applyBasemap } = layers;
13
- const { basemapId, grid, attribution, rebuild, reset } = useBasemapBuilds(layers, dataBounds);
24
+ const builds = useBasemapBuilds(layers, dataBounds);
25
+ const { basemapId, grid, attribution, reset } = builds;
26
+ async function rebuild(): Promise<void> {
27
+ if (enabled.value) {
28
+ await builds.rebuild();
29
+ }
30
+ }
14
31
  const settings = useBasemapSettings(layers, basemapId, rebuild);
15
32
  const { setMaps, setOpacity, setCrop, exportStores, importStores } = settings;
16
33
 
@@ -74,7 +74,7 @@ export const useCloudStore = defineStore("cloud", {
74
74
  backStore.stop_request();
75
75
  },
76
76
  },
77
- { schema: back_schemas.opengeodeweb_back.ping },
77
+ { schema: back_schemas.opengeodeweb_back.ping, log_success: false },
78
78
  );
79
79
  } catch (error) {
80
80
  useFeedbackStore().$patch({ server_error: true });
package/app/stores/crs.ts CHANGED
@@ -1,110 +1,22 @@
1
- import { oldestCrs, sameCrs } from "@ogw_front/utils/crs";
2
1
  import type { CRS } from "@geode/opengeodeweb-back/schema_types";
3
- import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
4
- import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";
5
- import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
6
- import { useBackStore } from "@ogw_front/stores/back";
2
+ import { oldestCrs } from "@ogw_front/utils/crs";
3
+ import { useCrsRequests } from "./crs_helpers/requests.js";
7
4
  import { useDataStore } from "@ogw_front/stores/data";
5
+ import { useGeographicList } from "./crs_helpers/geographic_list.js";
6
+ import { useProjectCrsState } from "./crs_helpers/project_crs.js";
8
7
 
9
8
  // Session cache of the available CRS, the project CRS, and the channel the shared components use to ask the host app for a CRS edit
10
- // oxlint-disable-next-line max-lines-per-function, max-statements
11
9
  export const useCrsStore = defineStore("crs", () => {
12
- const backStore = useBackStore();
13
- // OpenGeode geosciences lists the same geographic CRS for 2D and 3D data: one list for all types
14
- let geographicListPromise: Promise<CRS[]> | undefined = undefined;
15
- const crsEditEnabled = ref(false);
16
- const crsEditRequest = ref<string | undefined>(undefined);
17
- const dataStore = useDataStore();
18
- const crsItems = dataStore.refCrsItems();
19
- const projectCrs = ref<CRS | undefined>(undefined);
20
- const projectCrsEditRequest = ref(false);
21
-
22
- // The project follows its data: once every georeferenced data is in one CRS, it is the project
23
- // CRS. Data already mixed before any project CRS: the oldest one is the reference
24
- watch(
25
- () => {
26
- const georeferenced = crsItems.value.filter((item) => item.crs !== undefined);
27
- const [first] = georeferenced;
28
- if (first === undefined) {
29
- return undefined;
30
- }
31
- if (georeferenced.every((item) => sameCrs(item.crs, first.crs))) {
32
- return first.crs;
33
- }
34
- return projectCrs.value ?? oldestCrs(georeferenced);
35
- },
36
- (reference) => {
37
- if (reference !== undefined && !sameCrs(reference, projectCrs.value)) {
38
- projectCrs.value = reference;
39
- }
40
- },
41
- { immediate: true },
42
- );
43
-
44
- // Data without CRS are listed too (value undefined): they could not follow the project
45
- const mismatchedCrs = computed(() => {
46
- const project = projectCrs.value;
47
- const mismatched = new Map<string, CRS | undefined>();
48
- for (const item of crsItems.value) {
49
- if (project !== undefined && !sameCrs(item.crs, project)) {
50
- mismatched.set(item.data_id, item.crs);
51
- }
52
- }
53
- return mismatched;
54
- });
55
-
56
- async function fetchGeographicList(geodeObjectType: GeodeObjectType): Promise<CRS[]> {
57
- try {
58
- const response = await backStore.request({
59
- schema: back_schemas.opengeodeweb_back.crs.geographic_list,
60
- params: { geode_object_type: geodeObjectType },
61
- });
62
- if (response?.crs_list !== undefined) {
63
- return response.crs_list;
64
- }
65
- } catch {
66
- // The back store already reports the error to the user
67
- }
68
- // A failed request is not cached: the next call retries
69
- geographicListPromise = undefined;
70
- return [];
71
- }
72
-
73
- async function geographicList(geodeObjectType: GeodeObjectType): Promise<CRS[]> {
74
- // The promise is cached, so dialogs opened together share a single request.
75
- // The back still checks each CRS against the list of the data dimension
76
- geographicListPromise ??= fetchGeographicList(geodeObjectType);
77
- const list = await geographicListPromise;
78
- return list;
79
- }
80
-
81
- function enableCrsEdit(): void {
82
- crsEditEnabled.value = true;
83
- }
84
-
85
- function requestCrsEdit(dataId: DataId): void {
86
- crsEditRequest.value = dataId;
87
- }
88
-
89
- function clearCrsEditRequest(): void {
90
- crsEditRequest.value = undefined;
91
- }
92
-
93
- function setProjectCrs(crs: CRS): void {
94
- projectCrs.value = crs;
95
- }
96
-
97
- function requestProjectCrsEdit(): void {
98
- projectCrsEditRequest.value = true;
99
- }
100
-
101
- function clearProjectCrsEditRequest(): void {
102
- projectCrsEditRequest.value = false;
103
- }
10
+ const crsItems = useDataStore().refCrsItems();
11
+ const { geographicList } = useGeographicList();
12
+ const { projectCrs, mismatchedCrs, setProjectCrs } = useProjectCrsState(crsItems);
13
+ // Edit and alignment requests, returned as they are
14
+ const requests = useCrsRequests();
104
15
 
105
16
  // A new project: its data set the project CRS again
106
17
  function reset(): void {
107
18
  projectCrs.value = undefined;
19
+ requests.closeCrsAlign();
108
20
  }
109
21
 
110
22
  function exportStores(): { projectCrs?: CRS } {
@@ -119,17 +31,10 @@ export const useCrsStore = defineStore("crs", () => {
119
31
  return {
120
32
  crsItems,
121
33
  geographicList,
122
- crsEditEnabled,
123
- enableCrsEdit,
124
- crsEditRequest,
125
- requestCrsEdit,
126
- clearCrsEditRequest,
127
34
  projectCrs,
128
35
  mismatchedCrs,
129
36
  setProjectCrs,
130
- projectCrsEditRequest,
131
- requestProjectCrsEdit,
132
- clearProjectCrsEditRequest,
37
+ ...requests,
133
38
  reset,
134
39
  exportStores,
135
40
  importStores,
@@ -0,0 +1,44 @@
1
+ import type { CRS } from "@geode/opengeodeweb-back/schema_types";
2
+ import type { GeodeObjectType } from "@geode/opengeodeweb-microservice/data_types";
3
+ import back_schemas from "@geode/opengeodeweb-back/opengeodeweb_back_typed_schemas.js";
4
+ import { useBackStore } from "@ogw_front/stores/back";
5
+
6
+ interface GeographicList {
7
+ geographicList: (geodeObjectType: GeodeObjectType) => Promise<CRS[]>;
8
+ }
9
+
10
+ // Session cache of the available CRS
11
+ function useGeographicList(): GeographicList {
12
+ const backStore = useBackStore();
13
+ // OpenGeode geosciences lists the same geographic CRS for 2D and 3D data: one list for all types
14
+ let geographicListPromise: Promise<CRS[]> | undefined = undefined;
15
+
16
+ async function fetchGeographicList(geodeObjectType: GeodeObjectType): Promise<CRS[]> {
17
+ try {
18
+ const response = await backStore.request({
19
+ schema: back_schemas.opengeodeweb_back.crs.geographic_list,
20
+ params: { geode_object_type: geodeObjectType },
21
+ });
22
+ if (response?.crs_list !== undefined) {
23
+ return response.crs_list;
24
+ }
25
+ } catch {
26
+ // The back store already reports the error to the user
27
+ }
28
+ // A failed request is not cached: the next call retries
29
+ geographicListPromise = undefined;
30
+ return [];
31
+ }
32
+
33
+ async function geographicList(geodeObjectType: GeodeObjectType): Promise<CRS[]> {
34
+ // The promise is cached, so dialogs opened together share a single request.
35
+ // The back still checks each CRS against the list of the data dimension
36
+ geographicListPromise ??= fetchGeographicList(geodeObjectType);
37
+ const list = await geographicListPromise;
38
+ return list;
39
+ }
40
+
41
+ return { geographicList };
42
+ }
43
+
44
+ export { useGeographicList };
@@ -0,0 +1,60 @@
1
+ import type { ComputedRef, Ref } from "vue";
2
+ import { oldestCrs, sameCrs } from "@ogw_front/utils/crs";
3
+ import type { CRS } from "@geode/opengeodeweb-back/schema_types";
4
+ import type { CrsItem } from "@ogw_front/stores/data";
5
+
6
+ interface ProjectCrsState {
7
+ projectCrs: Ref<CRS | undefined>;
8
+ mismatchedCrs: ComputedRef<Map<string, CRS | undefined>>;
9
+ setProjectCrs: (crs: CRS) => void;
10
+ }
11
+
12
+ // The CRS every data of the project should be in, given the data CRS
13
+ function referenceCrs(crsItems: CrsItem[], projectCrs: CRS | undefined): CRS | undefined {
14
+ const georeferenced = crsItems.filter((item) => item.crs !== undefined);
15
+ const [first] = georeferenced;
16
+ if (first === undefined) {
17
+ return undefined;
18
+ }
19
+ if (georeferenced.every((item) => sameCrs(item.crs, first.crs))) {
20
+ return first.crs;
21
+ }
22
+ return projectCrs ?? oldestCrs(georeferenced);
23
+ }
24
+
25
+ // The project CRS and the data out of it
26
+ function useProjectCrsState(crsItems: Ref<CrsItem[]>): ProjectCrsState {
27
+ const projectCrs = ref<CRS | undefined>(undefined);
28
+
29
+ // The project follows its data: once every georeferenced data is in one CRS, it is the project
30
+ // CRS. Data already mixed before any project CRS: the oldest one is the reference
31
+ watch(
32
+ () => referenceCrs(crsItems.value, projectCrs.value),
33
+ (reference) => {
34
+ if (reference !== undefined && !sameCrs(reference, projectCrs.value)) {
35
+ projectCrs.value = reference;
36
+ }
37
+ },
38
+ { immediate: true },
39
+ );
40
+
41
+ // Data without CRS are listed too (value undefined): they could not follow the project
42
+ const mismatchedCrs = computed(() => {
43
+ const project = projectCrs.value;
44
+ const mismatched = new Map<string, CRS | undefined>();
45
+ for (const item of crsItems.value) {
46
+ if (project !== undefined && !sameCrs(item.crs, project)) {
47
+ mismatched.set(item.data_id, item.crs);
48
+ }
49
+ }
50
+ return mismatched;
51
+ });
52
+
53
+ function setProjectCrs(crs: CRS): void {
54
+ projectCrs.value = crs;
55
+ }
56
+
57
+ return { projectCrs, mismatchedCrs, setProjectCrs };
58
+ }
59
+
60
+ export { useProjectCrsState };
@@ -0,0 +1,60 @@
1
+ import type { DataId } from "@geode/opengeodeweb-microservice/schema_types";
2
+ import type { DataItem } from "@ogw_front/stores/data";
3
+ import type { Ref } from "vue";
4
+
5
+ interface CrsRequests {
6
+ crsEditEnabled: Ref<boolean>;
7
+ enableCrsEdit: () => void;
8
+ crsEditRequest: Ref<string | undefined>;
9
+ requestCrsEdit: (dataId: DataId) => void;
10
+ clearCrsEditRequest: () => void;
11
+ projectCrsEditRequest: Ref<boolean>;
12
+ requestProjectCrsEdit: () => void;
13
+ clearProjectCrsEditRequest: () => void;
14
+ showCrsAlign: Ref<boolean>;
15
+ crsAlignItem: Ref<DataItem | undefined>;
16
+ openCrsAlign: (item: DataItem) => void;
17
+ closeCrsAlign: () => void;
18
+ }
19
+
20
+ // The channel the shared components use to ask the host app for a CRS edit or an alignment
21
+ function useCrsRequests(): CrsRequests {
22
+ const crsEditEnabled = ref(false);
23
+ const crsEditRequest = ref<string | undefined>(undefined);
24
+ const projectCrsEditRequest = ref(false);
25
+ const showCrsAlign = ref(false);
26
+ const crsAlignItem = ref<DataItem | undefined>(undefined);
27
+
28
+ return {
29
+ crsEditEnabled,
30
+ enableCrsEdit: (): void => {
31
+ crsEditEnabled.value = true;
32
+ },
33
+ crsEditRequest,
34
+ requestCrsEdit: (dataId: DataId): void => {
35
+ crsEditRequest.value = dataId;
36
+ },
37
+ clearCrsEditRequest: (): void => {
38
+ crsEditRequest.value = undefined;
39
+ },
40
+ projectCrsEditRequest,
41
+ requestProjectCrsEdit: (): void => {
42
+ projectCrsEditRequest.value = true;
43
+ },
44
+ clearProjectCrsEditRequest: (): void => {
45
+ projectCrsEditRequest.value = false;
46
+ },
47
+ showCrsAlign,
48
+ crsAlignItem,
49
+ openCrsAlign: (item: DataItem): void => {
50
+ crsAlignItem.value = item;
51
+ showCrsAlign.value = true;
52
+ },
53
+ closeCrsAlign: (): void => {
54
+ showCrsAlign.value = false;
55
+ crsAlignItem.value = undefined;
56
+ },
57
+ };
58
+ }
59
+
60
+ export { useCrsRequests };