Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/components/Viewer/TreeComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ watch(
<template #title="{ item }">
<span
class="treeview-item"
:class="{ 'inactive-item': item.is_active === false }"
@contextmenu.prevent.stop="emit('show-menu', { event: $event, itemId: item })"
>{{ item.title }}</span
>
Expand All @@ -68,6 +69,10 @@ watch(
max-width: 100%;
display: inline-block;
}
.inactive-item {
opacity: 0.5;
font-style: italic;
}

.transparent-treeview {
background-color: transparent;
Expand Down
2 changes: 2 additions & 0 deletions app/stores/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,209 +9,211 @@

const viewer_generic_schemas = viewer_schemas.opengeodeweb_viewer.generic;

export const useDataStore = defineStore("data", () => {
const viewerStore = useViewerStore();

function item(id) {
return database.data.get(id);
}

function refItem(id) {
return useObservable(
liveQuery(() => database.data.get(id)),
{ initialValue: {} },
);
}

function refAllItems() {
return useObservable(
liveQuery(() => database.data.toArray()),
{ initialValue: [] },
);
}

async function formatedMeshComponents(modelId) {
const items = await database.model_components.where({ id: modelId }).toArray();
const componentTitles = {
Corner: "Corners",
Line: "Lines",
Surface: "Surfaces",
Block: "Blocks",
};

const componentsByType = {};
for (const component_item of items) {
if (componentTitles[component_item.type]) {
if (!componentsByType[component_item.type]) {
componentsByType[component_item.type] = [];
}
componentsByType[component_item.type].push(component_item);
}
}

return Object.keys(componentTitles)
.filter((type) => componentsByType[type])
.map((type) => ({
id: type,
title: componentTitles[type],
children: componentsByType[type].map((meshComponent) => ({
id: meshComponent.geode_id,
title: meshComponent.name,
category: meshComponent.type,
is_active: meshComponent.is_active,
})),
}));
}

async function meshComponentType(modelId, geode_id) {
const component = await database.model_components.where({ id: modelId, geode_id }).first();
return component?.type;
}

async function registerObject(id) {
return await viewerStore.request(viewer_generic_schemas.register, { id });
}

async function deregisterObject(id) {
return await viewerStore.request(viewer_generic_schemas.deregister, { id });
}

function addItem(new_item) {
const itemData = {
id: new_item.id,
name: new_item.name || new_item.id,
viewer_type: new_item.viewer_type,
geode_object_type: new_item.geode_object_type,
visible: true,
created_at: new Date().toISOString(),
binary_light_viewable: new_item.binary_light_viewable,
};
return database.data.put(itemData);
}

function addComponents(new_item) {
const allComponents = [];
function addModelComponents(components) {
for (const component of components) {
allComponents.push({
id: new_item.id,
geode_id: component.geode_id,
type: component.type,
viewer_id: component.viewer_id,
name: component.name,
is_active: component.is_active,
});
}
}
addModelComponents(new_item.mesh_components);
addModelComponents(new_item.collection_components);
return database.model_components.bulkPut(allComponents);
}

function addComponentRelations(new_item) {
const relations = [];
function addModelComponentRelations(components, parent, type) {
for (const child of components) {
relations.push({
id: new_item.id,
parent,
child,
type,
});
}
}
for (const component of new_item.mesh_components) {
if (component.boundaries) {
addModelComponentRelations(component.boundaries, component.geode_id, "boundary");
}
if (component.internals) {
addModelComponentRelations(component.internals, component.geode_id, "internal");
}
}
for (const component of new_item.collection_components) {
if (component.items) {
addModelComponentRelations(component.items, component.geode_id, "collection");
}
}
return database.model_components_relation.bulkPut(relations);
}

async function deleteItem(id) {
await database.data.delete(id);
await deleteModelComponents(id);
}

async function updateItem(id, changes) {
await database.data.update(id, changes);
}

async function deleteModelComponents(modelId) {
await database.model_components.where({ id: modelId }).delete();
await database.model_components_relation.where({ id: modelId }).delete();
}

async function getMeshComponentGeodeIds(modelId, component_type) {
const components = await database.model_components
.where({ id: modelId, type: component_type })
.toArray();
return components.map((component) => component.geode_id);
}

async function getCornersGeodeIds(modelId) {
return await getMeshComponentGeodeIds(modelId, "Corner");
}

async function getLinesGeodeIds(modelId) {
return await getMeshComponentGeodeIds(modelId, "Line");
}

async function getSurfacesGeodeIds(modelId) {
return await getMeshComponentGeodeIds(modelId, "Surface");
}

async function getBlocksGeodeIds(modelId) {
return await getMeshComponentGeodeIds(modelId, "Block");
}

async function getMeshComponentsViewerIds(modelId, meshComponentGeodeIds) {
const components = await database.model_components
.where("[id+geode_id]")
.anyOf(meshComponentGeodeIds.map((geode_id) => [modelId, geode_id]))
.toArray();
return components.map((component) => component.viewer_id);
}

async function exportStores() {
const items = await database.data.toArray();
return { items };
}

async function importStores(_snapshot) {
await clear();
}

async function clear() {
await database.data.clear();
}

return {
refAllItems,
item,
refItem,
meshComponentType,
formatedMeshComponents,
registerObject,
deregisterObject,
addItem,
addComponents,
addComponentRelations,
deleteItem,
updateItem,
getCornersGeodeIds,
getLinesGeodeIds,
getSurfacesGeodeIds,
getBlocksGeodeIds,
getMeshComponentsViewerIds,
exportStores,
importStores,
clear,
};
});

Check warning on line 219 in app/stores/data.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(max-statements)

function has too many statements (24). Maximum allowed is 20.

Check warning on line 219 in app/stores/data.js

View workflow job for this annotation

GitHub Actions / test / oxlint

eslint(max-lines-per-function)

The function has too many lines (183). Maximum allowed is 50.
Loading