Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidebar collapsable #58

Merged
merged 25 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a7ba8e0
material list update
Amanbh997 Jan 9, 2024
d23f96b
Update MaterialMappingCard.vue
fabianlinkflink Jan 24, 2024
3aa77a3
Merge remote-tracking branch 'origin/material-list-branch' into Mater…
fabianlinkflink Jan 26, 2024
980f394
Merge Table view
fabianlinkflink Jan 26, 2024
4871d37
Assemblies update
fabianlinkflink Jan 29, 2024
96b762b
Material Modal layout
fabianlinkflink Jan 29, 2024
37ffa77
Material store creation
fabianlinkflink Jan 29, 2024
a49b39c
Test material list
fabianlinkflink Jan 29, 2024
76cd7c6
Router update
fabianlinkflink Jan 29, 2024
e22ecc5
Mapping UI update
fabianlinkflink Jan 29, 2024
9cbb6d1
Assembly support added
fabianlinkflink Jan 29, 2024
29b22ca
Small ui fixes
fabianlinkflink Jan 30, 2024
c0bed37
Material store for assemblies and filtering
fabianlinkflink Jan 30, 2024
e417e8c
Refactored components + search
fabianlinkflink Jan 30, 2024
a774e10
Merge branch 'main' into Material-Mapping
fabianlinkflink Feb 15, 2024
727694f
ReEnabling from Viewer
fabianlinkflink Feb 17, 2024
30c9776
Model update
fabianlinkflink Feb 17, 2024
037b06d
Material Viewer interaction added
fabianlinkflink Feb 17, 2024
252ce1f
ColorMode Viewer
fabianlinkflink Feb 18, 2024
43af300
Update materialList.json
fabianlinkflink Apr 3, 2024
7082d2d
Material Filtering added
fabianlinkflink Apr 3, 2024
364e56e
Material sorting updated
fabianlinkflink Apr 4, 2024
b0e421c
Collapsable sidebar
fabianlinkflink Apr 5, 2024
eaefed7
Update SpeckleViewer.vue
fabianlinkflink Apr 11, 2024
3b04d4c
Merge branch 'main' into Sidebar-collapse
fabianlinkflink Apr 11, 2024
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
65 changes: 57 additions & 8 deletions src/components/ModelViewer/SpeckleViewer.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
<template>
<div class="relative inset-y-16 w-2/3 h-[calc(100vh-4rem)] bg-gray-100">
<!-- TODO: This is supposed to fade in and out when resizing the viewer. Not working correct currently -->
<TransitionRoot as="template" :show="fadeOut">
<TransitionChild
as="template"
enter="ease-in-out duration-500"
enter-from="opacity-0"
enter-to="opacity-100"
leave="ease-in-out duration-500"
leave-from="opacity-100"
leave-to="opacity-0"
>
<div
class="fixed w-full h-full bg-gray-500 bg-opacity-75 transition-opacity z-30"
/>
</TransitionChild>
</TransitionRoot>
<div
class="relative inset-y-16 w-full h-[calc(100vh-4rem)] bg-gray-100 overflow-auto"
id="renderParent"
>
<div class="absolute text-sm select-none left-4">
<h3
class="font-semibold leading-5 text-gray-400 border-b border-gray-300 pb-2"
Expand All @@ -23,7 +42,10 @@
<FilterSelector />
</div>
-->
<div class="flex h-full w-full bg-gray-50 -z-10" id="renderer" />
<div
class="flex h-full w-full bg-gray-50 -z-10"
id="renderer"
/>

<ViewerControls />
<DetailBar />
Expand All @@ -37,11 +59,16 @@
ViewerEvent,
type SelectionEvent
} from '@speckle/viewer'

import { useSpeckleStore } from '@/stores/speckle'
import { onMounted, watch, onBeforeUnmount } from 'vue'
import { useProjectStore, useNavigationStore } from '@/stores/main'
import { onMounted, watch, onBeforeUnmount, ref, render } from 'vue'
import { useProjectStore } from '@/stores/main'
import { storeToRefs } from 'pinia'

import {
TransitionChild,
TransitionRoot,
} from '@headlessui/vue'
import ViewerControls from '@/components/ModelViewer/ViewerControls.vue'
import DetailBar from '@/components/DetailBar/DetailBar.vue'

Expand All @@ -51,10 +78,11 @@

const projectStore = useProjectStore()
const { selectedObjects } = storeToRefs(projectStore)
const navStore = useNavigationStore()

const serverUrl = import.meta.env.VITE_APP_SERVER_URL
const token = import.meta.env.VITE_SPECKLE_TOKEN
const resizeObserver = ref(null)
const fadeOut = ref(false)

const handleEscKey = (e) => {
if (e.key.toLowerCase() === 'escape') {
Expand All @@ -64,6 +92,21 @@
}
}

//This is to resize it properly when just div changes size as when expanding sidebar
const handleResize = (entries : ResizeObserverEntry[]) => {
for (let entry of entries) {
//fadeOut.value = true

const { width, height } = entry.contentRect
viewer.resize()
//Update aspect ratio manually
viewer.cameraHandler.activeCam.camera.aspect = width / height
viewer.cameraHandler.activeCam.camera.updateProjectionMatrix()

//fadeOut.value = false
}
}

/**
/ Renable select all if needed, see no need for it now.
const handleSelectAll = (e) => {
Expand All @@ -76,11 +119,11 @@
*/

onMounted(async () => {
const renderParent = document.getElementById('renderParent') as HTMLElement
const container = document.getElementById('renderer') as HTMLElement
window.addEventListener('keydown', handleEscKey)
//window.addEventListener('keydown', handleSelectAll)

const container = document.getElementById('renderer') as HTMLElement

viewer = new Viewer(container, DefaultViewerParams)
await viewer.init()

Expand Down Expand Up @@ -154,10 +197,15 @@
}
*/

resizeObserver.value = new ResizeObserver(handleResize)
resizeObserver.value.observe(renderParent)

// Resize the viewer when the window is resized.
/*
window.onresize = function () {
viewer.resize()
}
*/

const speckleStore = useSpeckleStore()
speckleStore.setViewerInstance(viewer)
Expand All @@ -169,7 +217,8 @@
})

onBeforeUnmount(() => {
window.removeEventListener('keydown', handleEscKey);
window.removeEventListener('keydown', handleEscKey)
resizeObserver.value.disconnect()
})

watch(
Expand Down
69 changes: 63 additions & 6 deletions src/components/Sidebar/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,88 @@
<NewGroupModal />
<MaterialMappingModal />
<!-- End of modal area -->

<div class="relative mt-16 z-40 flex h-[calc(100vh-4rem)] w-1/3 flex-col">
<button
v-if="!sideBarShow"
@click="toggleSideBar"
class="absolute top-1/2 pt-16 left-2 transform -translate-y-1/2 mr-2 z-50"
>
<ChevronRightIcon class="w-6 h-6 opacity-50" />
</button>
<TransitionRoot as="template" :show="sideBarShow">
<div
class="flex grow h-[calc(100vh-12rem)] flex-col gap-y-5 overflow-y-auto border-r border-gray-200 bg-white px-6 pt-4"
class="relative mt-16 z-40 flex h-[calc(100vh-4rem)] w-1/2 flex-col"
>
<GroupList />
<TransitionChild
as="template"
enter="transform transition ease-in-out duration-500 sm:duration-700"
enter-from="-translate-x-full"
enter-to="translate-x-0"
leave="transform transition ease-in-out duration-500 sm:duration-700"
leave-from="translate-x-0"
leave-to="-translate-x-full"
>
<div
class="flex grow h-[calc(100vh-12rem)] flex-col gap-y-5 overflow-y-auto border-r border-gray-200 bg-white px-6 pt-4"
>
<button
v-if="sideBarShow"
@click="toggleSideBar"
class="absolute top-1/2 -right-8 transform -translate-y-1/2 mr-2 opacity-50"
>
<ChevronLeftIcon class="w-6 h-6" />
</button>
<GroupList />
</div>
</TransitionChild>
</div>
</div>
</TransitionRoot>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import {
TransitionChild,
TransitionRoot
} from '@headlessui/vue'

import {
ChevronRightIcon,
ChevronLeftIcon
} from '@heroicons/vue/24/solid'

import { useNavigationStore } from '@/stores/main'
import { useSpeckleStore } from '@/stores/speckle'

import GroupList from '@/components/Sidebar/GroupList.vue'
import NewGroupModal from '@/components/Sidebar/NewGroupModal.vue'
import MaterialMappingModal from '@/components/Mapping/MaterialMappingModal.vue'

import { storeToRefs } from 'pinia'

export default defineComponent({
name: 'SideBar',
components: {
GroupList,
NewGroupModal,
MaterialMappingModal,
TransitionChild,
TransitionRoot,
ChevronLeftIcon,
ChevronRightIcon
},
setup() {
return {}
const navStore = useNavigationStore()
const { sideBarShow } = storeToRefs(navStore)

const toggleSideBar = () => {
navStore.toggleSideBar()
}


return {
sideBarShow,
toggleSideBar
}
}

})
Expand Down
8 changes: 8 additions & 0 deletions src/stores/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ export const useNavigationStore = defineStore({
mappingModalOpen: false,
loading: false,
groupColorMode: false,
sideBarShow: true,
}
},
actions: {
Expand Down Expand Up @@ -445,6 +446,13 @@ export const useNavigationStore = defineStore({
*/
toggleColorMode() {
this.groupColorMode = !this.groupColorMode
},

/**
* Toggle sidebar on the app
*/
toggleSideBar() {
this.sideBarShow = !this.sideBarShow
}

},
Expand Down
32 changes: 3 additions & 29 deletions src/views/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
<div class="flex">
<NavbarComponent />
<Sidebar />
<SpeckleStats
:visible="statsVisible"
:names="statNames"
:vals="statValues"
/>
<Suspense>
<SpeckleViewer />
</Suspense>
Expand All @@ -17,8 +12,6 @@
<script lang="ts">
import Sidebar from '@/components/Sidebar/Sidebar.vue'
import Slideover from '@/components/SlideOver/Sliderover.vue'
import type { ViewerStats } from '@/models/speckle'
import SpeckleStats from '@/components/ModelViewer/SpeckleStats.vue'
import SpeckleViewer from '@/components/ModelViewer/SpeckleViewer.vue'
import NavbarComponent from '@/components/Navbar.vue'
import { useMaterialStore } from '@/stores/material'
Expand All @@ -31,7 +24,6 @@
name: 'DashboardView',
components: {
NavbarComponent,
SpeckleStats,
SpeckleViewer,
Sidebar,
Slideover,
Expand Down Expand Up @@ -60,30 +52,12 @@
required: false
}
},
setup(props) {
const materialStore = useMaterialStore()
setup() {
//Load materials from the store on startup
const materialStore = useMaterialStore()
materialStore.materialsFromJson()
let statNames: Array<string>
let statValues: Array<object>

if (props.statsVisible) {
// If props are not provided, use these defaults, otherwise deconstuct the given stats object.
const stats = (props.stats as ViewerStats)
? props.stats
: { names: null, vals: null }

statNames = stats.names ? stats.names : ['Elements', ' Stream']
statValues = stats.vals ? stats.vals : [18, ""]
} else {
statNames = []
statValues = []
}

return {
statNames,
statValues
}
return {}
}
}
</script>
Loading