-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e57df1f
commit f427bcc
Showing
7 changed files
with
148 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<template> | ||
<div> | ||
<h5>Default Files</h5> | ||
<ul class="list-group mb-3"> | ||
<li | ||
v-for="projects in projectList.items" | ||
:key="projects.title" | ||
class="list-group-item" | ||
> | ||
<a | ||
href="#" | ||
:data-fileurl="projects.remoteFileUrl" | ||
@click.prevent="loadRemoteFile" | ||
> | ||
{{ projects.title }} | ||
</a> | ||
</li> | ||
</ul> | ||
<div | ||
v-if="isLoading" | ||
class="d-flex align-items-center justify-content-start gap-3 mb-3" | ||
> | ||
<div class="spinner-border text-primary" role="status"> | ||
<span class="visually-hidden">Loading...</span> | ||
</div> | ||
<strong>{{ !progress ? 'Loading ...' : progress }}</strong> | ||
</div> | ||
</div> | ||
<div> | ||
<h5>Load File</h5> | ||
<LoadProject /> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ViewerProjectList } from 'composables/viewer'; | ||
import { Project } from '~/composables/project'; | ||
import { useProjectRefs, useProjectStore } from '~/composables/store/project'; | ||
import { useViewerStore } from '~/composables/store/viewer'; | ||
const isLoading = ref<boolean>(false); | ||
const progress = ref<string | null>(null); | ||
const { projectList } = defineProps<{ | ||
projectList: ViewerProjectList; | ||
}>(); | ||
const { loadProject, unloadProject } = useProjectStore(); | ||
const { toggleProjectMenu } = useViewerStore(); | ||
const { isLoaded } = useProjectRefs(); | ||
const loadRemoteFile = async ({ target }: MouseEvent) => { | ||
if (target && target instanceof HTMLAnchorElement) { | ||
const fileURL = target.dataset.fileurl; | ||
if (!fileURL) return; | ||
isLoading.value = true; | ||
const response = await fetch(fileURL); | ||
let result: Project; | ||
if (response.ok) { | ||
const reader = response.body!.getReader(); | ||
let received = 0; | ||
const chunks = []; | ||
while (true) { | ||
const { done, value } = await reader.read(); | ||
if (done) break; | ||
chunks.push(value); | ||
received += value.length; | ||
await nextTick(() => { | ||
const receivedMB = received / (1024 * 1024); | ||
const neat = Math.round(receivedMB * 100) / 100; | ||
progress.value = `Downloaded ${neat} Mb`; | ||
}); | ||
} | ||
const bodyBytes = new Uint8Array(received); | ||
let pos = 0; | ||
for (const chunk of chunks) { | ||
bodyBytes.set(chunk, pos); | ||
pos += chunk.length; | ||
} | ||
const bodyText = new TextDecoder('utf-8').decode(bodyBytes); | ||
result = JSON.parse(bodyText); | ||
} else { | ||
return; | ||
} | ||
if (isLoaded.value) { | ||
unloadProject(); | ||
} | ||
// Wait for the unloadProject to finish before loading the new project | ||
await nextTick(() => { | ||
loadProject(result, fileURL); | ||
toggleProjectMenu(false); | ||
isLoading.value = false; | ||
}); | ||
} | ||
}; | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
@import '~/assets/css/bootstrap/config'; | ||
</style> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<template> | ||
<ModalDialog :show="isProjectMenuVisible" @close="toggleProjectMenu(false)"> | ||
<template #header> | ||
<h5 class="m-0">Project Menu</h5> | ||
</template> | ||
<template #default> | ||
<div> | ||
<ProjectMenu :project-list="viewerProjectList" /> | ||
</div> | ||
</template> | ||
</ModalDialog> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import ProjectMenu from '~/components/viewer/ProjectMenu.vue'; | ||
import { useViewerRefs, useViewerStore } from '~/composables/store/viewer'; | ||
const { toggleProjectMenu, viewerProjectList } = useViewerStore(); | ||
const { isProjectMenuVisible } = useViewerRefs(); | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
@import '~/assets/css/bootstrap/config'; | ||
</style> |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters