@geode/opengeodeweb-front 10.42.1-rc.2 → 10.43.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/app/components/Viewer/ObjectTree/Base/ComponentRelations.vue +57 -0
- package/app/components/Viewer/ObjectTree/Base/ItemLabel.vue +8 -1
- package/app/components/Viewer/ObjectTree/Views/ModelTree.vue +1 -0
- package/app/stores/data.ts +3 -0
- package/app/stores/data_helpers/collections.ts +1 -7
- package/app/stores/data_helpers/mesh.ts +2 -1
- package/app/stores/data_helpers/relations.ts +59 -0
- package/app/utils/string.ts +15 -1
- package/package.json +1 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { ComponentRelations } from "@ogw_front/stores/data_helpers/relations";
|
|
3
|
+
import type { FormattedComponent } from "@ogw_front/stores/data_helpers/mesh";
|
|
4
|
+
import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles";
|
|
5
|
+
import { pluralize } from "@ogw_front/utils/string";
|
|
6
|
+
import { useDataStore } from "@ogw_front/stores/data";
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
modelId: string;
|
|
10
|
+
componentId: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const { modelId, componentId } = defineProps<Props>();
|
|
14
|
+
|
|
15
|
+
const dataStore = useDataStore();
|
|
16
|
+
const relations = ref<ComponentRelations | undefined>(undefined);
|
|
17
|
+
|
|
18
|
+
watch(
|
|
19
|
+
() => [modelId, componentId] as const,
|
|
20
|
+
async ([newModelId, newComponentId]) => {
|
|
21
|
+
relations.value = await dataStore.getComponentRelations(newModelId, newComponentId);
|
|
22
|
+
},
|
|
23
|
+
{ immediate: true },
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
function summarize(components: readonly FormattedComponent[]): string {
|
|
27
|
+
const counts = new Map<string, number>();
|
|
28
|
+
for (const component of components) {
|
|
29
|
+
counts.set(component.category, (counts.get(component.category) ?? 0) + 1);
|
|
30
|
+
}
|
|
31
|
+
return MESH_COMPONENT_TYPES.filter((type) => counts.has(type))
|
|
32
|
+
.map((type) => {
|
|
33
|
+
const count = counts.get(type) ?? 0;
|
|
34
|
+
return `${count} ${count > 1 ? pluralize(type) : type}`;
|
|
35
|
+
})
|
|
36
|
+
.join(", ");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const rows = computed<{ label: string; summary: string; testId: string }[]>(() => {
|
|
40
|
+
if (!relations.value) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
return [
|
|
44
|
+
{ label: "Boundaries", summary: summarize(relations.value.boundaries), testId: "boundaries" },
|
|
45
|
+
{ label: "Internals", summary: summarize(relations.value.internals), testId: "internals" },
|
|
46
|
+
].filter((row) => row.summary !== "");
|
|
47
|
+
});
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<div v-if="rows.length > 0" class="d-flex flex-column ga-1">
|
|
52
|
+
<span v-for="row in rows" :key="row.label" class="text-caption d-flex align-center">
|
|
53
|
+
<strong class="text-white mr-1">{{ row.label }}:</strong>
|
|
54
|
+
<span :data-testid="`relations-${row.testId}`">{{ row.summary }}</span>
|
|
55
|
+
</span>
|
|
56
|
+
</div>
|
|
57
|
+
</template>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import ComponentRelations from "@ogw_front/components/Viewer/ObjectTree/Base/ComponentRelations.vue";
|
|
2
3
|
import type { DisplayItem } from "@ogw_front/composables/virtual_tree";
|
|
3
4
|
import { middleTruncate } from "@ogw_front/utils/string";
|
|
4
5
|
import { useClipboard } from "@vueuse/core";
|
|
@@ -11,9 +12,10 @@ const { copy } = useClipboard();
|
|
|
11
12
|
interface Props {
|
|
12
13
|
item: DisplayItem;
|
|
13
14
|
isLeaf?: boolean;
|
|
15
|
+
modelId?: string;
|
|
14
16
|
}
|
|
15
17
|
|
|
16
|
-
const { item, isLeaf } = defineProps<Props>();
|
|
18
|
+
const { item, isLeaf, modelId = "" } = defineProps<Props>();
|
|
17
19
|
|
|
18
20
|
interface Emits {
|
|
19
21
|
contextmenu: [event: MouseEvent];
|
|
@@ -131,6 +133,11 @@ async function copyToClipboard(text: string, label: string): Promise<void> {
|
|
|
131
133
|
<strong class="text-white mr-1">Status:</strong>
|
|
132
134
|
<i class="ml-1">{{ actualItem.is_active ? "Active" : "Inactive" }}</i>
|
|
133
135
|
</span>
|
|
136
|
+
<ComponentRelations
|
|
137
|
+
v-if="modelId && actualItem.geode_id"
|
|
138
|
+
:model-id="modelId"
|
|
139
|
+
:component-id="actualItem.geode_id"
|
|
140
|
+
/>
|
|
134
141
|
</div>
|
|
135
142
|
</v-tooltip>
|
|
136
143
|
</div>
|
|
@@ -248,6 +248,7 @@ function getLeafViewerIds(item: CollectionTreeItem): number[] {
|
|
|
248
248
|
<ObjectTreeItemLabel
|
|
249
249
|
:item="item as unknown as DisplayItem"
|
|
250
250
|
:is-leaf="isLeaf"
|
|
251
|
+
:model-id="id"
|
|
251
252
|
show-tooltip
|
|
252
253
|
class="text-body-1"
|
|
253
254
|
@contextmenu="showContextMenu($event, item as unknown as CollectionTreeItem)"
|
package/app/stores/data.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { type ModelComponentRecord, useDataMesh } from "./data_helpers/mesh.js";
|
|
|
9
9
|
import { database } from "@ogw_internal/database/database.js";
|
|
10
10
|
import { liveObservable } from "@ogw_front/utils/live_observable";
|
|
11
11
|
import { useDataCollections } from "./data_helpers/collections.js";
|
|
12
|
+
import { useDataRelations } from "./data_helpers/relations.js";
|
|
12
13
|
import { useViewerStore } from "@ogw_front/stores/viewer";
|
|
13
14
|
|
|
14
15
|
interface DataItem {
|
|
@@ -125,6 +126,7 @@ export const useDataStore = defineStore("data", () => {
|
|
|
125
126
|
formatedCollectionComponents,
|
|
126
127
|
refFormatedCollectionComponents,
|
|
127
128
|
} = useDataCollections();
|
|
129
|
+
const { getComponentRelations } = useDataRelations();
|
|
128
130
|
async function item(id: string): Promise<DataItem> {
|
|
129
131
|
const data_item = await data_db.get(id);
|
|
130
132
|
if (!data_item) {
|
|
@@ -395,6 +397,7 @@ export const useDataStore = defineStore("data", () => {
|
|
|
395
397
|
fetchAllCollectionComponents,
|
|
396
398
|
formatedCollectionComponents,
|
|
397
399
|
refFormatedCollectionComponents,
|
|
400
|
+
getComponentRelations,
|
|
398
401
|
};
|
|
399
402
|
});
|
|
400
403
|
|
|
@@ -3,6 +3,7 @@ import { MESH_COMPONENT_TYPES } from "@ogw_front/utils/default_styles";
|
|
|
3
3
|
import type { Ref } from "vue";
|
|
4
4
|
import { getTable } from "@ogw_internal/database/database.js";
|
|
5
5
|
import { liveObservable } from "@ogw_front/utils/live_observable";
|
|
6
|
+
import { pluralize } from "@ogw_front/utils/string";
|
|
6
7
|
import { useObservable } from "@vueuse/rxjs";
|
|
7
8
|
|
|
8
9
|
interface ModelComponentRelationRecord {
|
|
@@ -22,13 +23,6 @@ interface CollectionComponentGroup {
|
|
|
22
23
|
readonly children: readonly CollectionComponent[];
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
function pluralize(type: string): string {
|
|
26
|
-
if (type.endsWith("y")) {
|
|
27
|
-
return `${type.slice(0, -1)}ies`;
|
|
28
|
-
}
|
|
29
|
-
return `${type}s`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
26
|
// oxlint-disable-next-line eslint/max-lines-per-function
|
|
33
27
|
export function useDataCollections(): {
|
|
34
28
|
hasCollectionComponents: typeof hasCollectionComponents;
|
|
@@ -39,7 +39,7 @@ function toFormattedComponent(meshComponent: ModelComponentRecord): FormattedCom
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// oxlint-disable-next-line eslint/max-lines-per-function
|
|
42
|
-
|
|
42
|
+
function useDataMesh(): {
|
|
43
43
|
formatedMeshComponents: typeof formatedMeshComponents;
|
|
44
44
|
refFormatedMeshComponents: typeof refFormatedMeshComponents;
|
|
45
45
|
getMeshComponentsByType: typeof getMeshComponentsByType;
|
|
@@ -167,4 +167,5 @@ export function useDataMesh(): {
|
|
|
167
167
|
};
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
+
export { toFormattedComponent, useDataMesh };
|
|
170
171
|
export type { ModelComponentRecord, FormattedComponent, FormattedComponentGroup };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type FormattedComponent,
|
|
3
|
+
type ModelComponentRecord,
|
|
4
|
+
toFormattedComponent,
|
|
5
|
+
} from "./mesh.js";
|
|
6
|
+
import { Dexie } from "dexie";
|
|
7
|
+
import { getTable } from "@ogw_internal/database/database.js";
|
|
8
|
+
|
|
9
|
+
interface ModelComponentRelationRecord {
|
|
10
|
+
id: string;
|
|
11
|
+
parent: string;
|
|
12
|
+
child: string;
|
|
13
|
+
type: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface ComponentRelations {
|
|
17
|
+
readonly boundaries: readonly FormattedComponent[];
|
|
18
|
+
readonly internals: readonly FormattedComponent[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useDataRelations(): {
|
|
22
|
+
getComponentRelations: typeof getComponentRelations;
|
|
23
|
+
} {
|
|
24
|
+
const model_components_db = getTable<ModelComponentRecord>("model_components");
|
|
25
|
+
const model_components_relation_db = getTable<ModelComponentRelationRecord>(
|
|
26
|
+
"model_components_relation",
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
async function getRelatedComponents(
|
|
30
|
+
modelId: string,
|
|
31
|
+
relations: readonly ModelComponentRelationRecord[],
|
|
32
|
+
type: string,
|
|
33
|
+
): Promise<FormattedComponent[]> {
|
|
34
|
+
const keys = relations
|
|
35
|
+
.filter((relation) => relation.type === type)
|
|
36
|
+
.map((relation) => [modelId, relation.child]);
|
|
37
|
+
const components = await model_components_db.where("[id+geode_id]").anyOf(keys).toArray();
|
|
38
|
+
return components.map((component) => toFormattedComponent(component));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function getComponentRelations(
|
|
42
|
+
modelId: string,
|
|
43
|
+
componentId: string,
|
|
44
|
+
): Promise<ComponentRelations> {
|
|
45
|
+
const relations = await model_components_relation_db
|
|
46
|
+
.where("[id+parent+child]")
|
|
47
|
+
.between([modelId, componentId, Dexie.minKey], [modelId, componentId, Dexie.maxKey])
|
|
48
|
+
.toArray();
|
|
49
|
+
const [boundaries, internals] = await Promise.all([
|
|
50
|
+
getRelatedComponents(modelId, relations, "boundary"),
|
|
51
|
+
getRelatedComponents(modelId, relations, "internal"),
|
|
52
|
+
]);
|
|
53
|
+
return { boundaries, internals };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { getComponentRelations };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type { ComponentRelations };
|
package/app/utils/string.ts
CHANGED
|
@@ -10,7 +10,7 @@ const DEFAULT_END_CHARS = 6;
|
|
|
10
10
|
* @param {number} endChars - Number of characters to keep at the end.
|
|
11
11
|
* @returns {string} The truncated string.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
function middleTruncate(
|
|
14
14
|
text: string | undefined | null,
|
|
15
15
|
maxLength: number = DEFAULT_MAX_LENGTH,
|
|
16
16
|
startChars: number = DEFAULT_START_CHARS,
|
|
@@ -24,3 +24,17 @@ export function middleTruncate(
|
|
|
24
24
|
const end = text.slice(-endChars);
|
|
25
25
|
return `${start}...${end}`;
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Pluralizes an English noun.
|
|
30
|
+
* @param {string} word - The singular noun.
|
|
31
|
+
* @returns {string} The plural form.
|
|
32
|
+
*/
|
|
33
|
+
function pluralize(word: string): string {
|
|
34
|
+
if (word.endsWith("y")) {
|
|
35
|
+
return `${word.slice(0, -1)}ies`;
|
|
36
|
+
}
|
|
37
|
+
return `${word}s`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { middleTruncate, pluralize };
|
package/package.json
CHANGED