refactor login page, change routes to token-based, add service classes
This commit is contained in:
10
src/routes/(token-based)/+layout.server.ts
Normal file
10
src/routes/(token-based)/+layout.server.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { type ServerLoadEvent } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from '../anmeldung/$types';
|
||||
|
||||
export const load: PageServerLoad = (event: ServerLoadEvent) => {
|
||||
if (event.locals.user) {
|
||||
return {
|
||||
user: event.locals.user
|
||||
};
|
||||
}
|
||||
};
|
||||
16
src/routes/(token-based)/+layout.svelte
Normal file
16
src/routes/(token-based)/+layout.svelte
Normal file
@@ -0,0 +1,16 @@
|
||||
<script lang="ts">
|
||||
import Footer from '$lib/components/Footer.svelte';
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
|
||||
export let data;
|
||||
</script>
|
||||
|
||||
<div class="h-screen v-screen flex flex-col">
|
||||
<Header {data} />
|
||||
|
||||
<div class="mt-10 flex-grow items-center justify-center">
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
<Footer {data} />
|
||||
</div>
|
||||
103
src/routes/(token-based)/list/+page.svelte
Normal file
103
src/routes/(token-based)/list/+page.svelte
Normal file
@@ -0,0 +1,103 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import Trash from '$lib/icons/Trash.svelte';
|
||||
import Folder from '$lib/icons/Folder.svelte';
|
||||
|
||||
/**
|
||||
* @type any[]
|
||||
*/
|
||||
let list: any[] = [];
|
||||
//$: list;
|
||||
|
||||
onMount(async () => {
|
||||
const response = await fetch('/api/list');
|
||||
const stream = await response.body;
|
||||
if (!stream) return;
|
||||
|
||||
const reader = stream.getReader();
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) return;
|
||||
|
||||
const objs = new TextDecoder()
|
||||
.decode(value)
|
||||
.split('\n')
|
||||
.filter((i) => i.length > 0)
|
||||
.map((i) => JSON.parse(i));
|
||||
|
||||
list = list.concat(objs);
|
||||
}
|
||||
});
|
||||
|
||||
async function delete_item(ev: Event) {
|
||||
let delete_item = window.confirm('Bist du sicher?');
|
||||
|
||||
if (delete_item) {
|
||||
const target = ev.currentTarget as HTMLElement | null;
|
||||
if (!target) return;
|
||||
let filename = target.id.split('del__')[1];
|
||||
|
||||
// delete request
|
||||
// --------------
|
||||
|
||||
let url = `/api/list/${filename}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url, { method: 'DELETE' });
|
||||
if (response.status == 204) {
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.log(error.message);
|
||||
} else {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="-z-10 bg-white">
|
||||
<div class="flex flex-col items-center justify-center w-full">
|
||||
<h1 class="text-xl">Liste der Vorgänge</h1>
|
||||
</div>
|
||||
<div class="mx-auto flex justify-center max-w-7xl h-full">
|
||||
<ul role="list" class="divide-y divide-gray-100">
|
||||
{#each list as item}
|
||||
<li>
|
||||
<a href="/list/{item.name}" class="flex justify-between gap-x-6 py-5">
|
||||
<div class="flex gap-x-4">
|
||||
<!-- Ordner -->
|
||||
<Folder />
|
||||
<div class="min-w-0 flex-auto">
|
||||
<span class="text-sm font-semibold leading-6 text-gray-900">{item.name}</span>
|
||||
<!-- Delete button -->
|
||||
<button
|
||||
style="padding: 2px"
|
||||
id="del__{item.name}"
|
||||
on:click|preventDefault={delete_item}
|
||||
aria-label="Vorgang {item.name} löschen"
|
||||
>
|
||||
<Trash />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden sm:flex sm:flex-col sm:items-end">
|
||||
<p class="text-sm leading-6 text-gray-900">Vorgang</p>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
ul {
|
||||
min-width: 24rem;
|
||||
}
|
||||
</style>
|
||||
314
src/routes/(token-based)/list/[vorgang]/+page.svelte
Normal file
314
src/routes/(token-based)/list/[vorgang]/+page.svelte
Normal file
@@ -0,0 +1,314 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import shortenFileSize from '$lib/helper/shortenFileSize';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
import timeElapsed from '$lib/helper/timeElapsed';
|
||||
|
||||
import Alert from '$lib/components/Alert.svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import Modal from '$lib/components/Modal/Modal.svelte';
|
||||
import ModalTitle from '$lib/components/Modal/ModalTitle.svelte';
|
||||
import ModalContent from '$lib/components/Modal/ModalContent.svelte';
|
||||
import ModalFooter from '$lib/components/Modal/ModalFooter.svelte';
|
||||
import Cube from '$lib/icons/Cube.svelte';
|
||||
import Edit from '$lib/icons/Edit.svelte';
|
||||
import Trash from '$lib/icons/Trash.svelte';
|
||||
|
||||
/** export let data; */
|
||||
/** @type {import('./$types').PageData} */
|
||||
export let data;
|
||||
|
||||
interface ListItem {
|
||||
name: string;
|
||||
size: number;
|
||||
lastModified: string | number | Date;
|
||||
show_button?: boolean;
|
||||
// add other properties as needed
|
||||
}
|
||||
|
||||
let list: ListItem[] = [];
|
||||
$: list;
|
||||
|
||||
let open = false;
|
||||
$: open;
|
||||
let inProgress = false;
|
||||
$: inProgress;
|
||||
let err = false;
|
||||
$: err;
|
||||
|
||||
let rename_input;
|
||||
$: rename_input;
|
||||
|
||||
onMount(async () => {
|
||||
const response = await fetch('/api/list/' + $page.params.vorgang);
|
||||
const stream = response.body;
|
||||
if (!stream) return;
|
||||
|
||||
const reader = stream.getReader();
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) return;
|
||||
|
||||
const objs = new TextDecoder()
|
||||
.decode(value)
|
||||
.split('\n')
|
||||
.filter((i) => i.length > 0)
|
||||
.map((i) => JSON.parse(i));
|
||||
|
||||
list = list.concat(objs);
|
||||
|
||||
list = list.map((item) => {
|
||||
item.show_button = true;
|
||||
return item;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function uploadSuccessful() {
|
||||
open = false;
|
||||
}
|
||||
|
||||
function defocus_element(i: number) {
|
||||
let item = list[i];
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute('contenteditable', 'false');
|
||||
text_field.textContent = item.name;
|
||||
}
|
||||
|
||||
// reshow button
|
||||
list[i].show_button = true;
|
||||
return;
|
||||
}
|
||||
|
||||
async function handle_input(ev: KeyboardEvent, i: number) {
|
||||
let item = list[i];
|
||||
if (ev.key == 'Escape') {
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute('contenteditable', 'false');
|
||||
text_field.textContent = item.name;
|
||||
}
|
||||
|
||||
// reshow button
|
||||
item.show_button = true;
|
||||
return;
|
||||
}
|
||||
if (ev.key == 'Enter') {
|
||||
let name_field = ev.currentTarget as HTMLElement | null;
|
||||
let new_name = name_field
|
||||
? name_field.textContent || (name_field as any).innerText || ''
|
||||
: '';
|
||||
|
||||
if (new_name == '') {
|
||||
alert('Bitte einen gültigen Namen eingeben.');
|
||||
ev.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// actual upload
|
||||
// -------------
|
||||
|
||||
// to prevent from item being selected
|
||||
ev.preventDefault();
|
||||
|
||||
// construct PUT URL
|
||||
const url = $page.url;
|
||||
console.log(url);
|
||||
|
||||
let data_obj: { new_name: string; old_name: string } = { new_name: '', old_name: '' };
|
||||
data_obj['new_name'] = new_name;
|
||||
data_obj['old_name'] =
|
||||
ev.currentTarget && (ev.currentTarget as HTMLElement).id
|
||||
? (ev.currentTarget as HTMLElement).id.split('__')[1]
|
||||
: '';
|
||||
|
||||
open = true;
|
||||
inProgress = true;
|
||||
|
||||
const response = await fetch(url, { method: 'PUT', body: JSON.stringify(data_obj) });
|
||||
|
||||
inProgress = false;
|
||||
|
||||
if (!response.ok) {
|
||||
err = true;
|
||||
if (response.status == 400) {
|
||||
let json_res = await response.json();
|
||||
return;
|
||||
}
|
||||
throw new Error(`Fehlgeschlagen: ${response.status}`);
|
||||
} else {
|
||||
uploadSuccessful();
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
// --- upload finished ---
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="-z-10 bg-white">
|
||||
<div class="flex flex-col items-center justify-center w-full">
|
||||
<h1 class="text-xl">Vorgang {$page.params.vorgang}</h1>
|
||||
</div>
|
||||
<div class="mx-auto flex justify-center max-w-7xl h-full">
|
||||
<ul class="divide-y divide-gray-100">
|
||||
{#each list as item, i}
|
||||
<li>
|
||||
<a
|
||||
href="/view/{$page.params.vorgang}/{item.name}"
|
||||
class=" flex justify-between gap-x-6 py-5"
|
||||
aria-label="zum 3D-modell"
|
||||
>
|
||||
<div class=" flex gap-x-4">
|
||||
<Cube />
|
||||
<button on:click="{() => console.log('test')}">test</button>
|
||||
<div class="min-w-0 flex-auto">
|
||||
{#if data?.user?.admin}
|
||||
<span
|
||||
id="label__{item.name}"
|
||||
class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
|
||||
contenteditable={!item.show_button}
|
||||
role="textbox"
|
||||
tabindex="0"
|
||||
aria-label="Dateiname bearbeiten"
|
||||
on:focusout={() => {
|
||||
defocus_element(i);
|
||||
}}
|
||||
on:keydown|stopPropagation={// event needed to identify ID
|
||||
// TO-DO: check if event is needed or if index is sufficient
|
||||
async (ev) => {
|
||||
handle_input(ev, i);
|
||||
}}>{item.name}</span
|
||||
>
|
||||
|
||||
<!--<input
|
||||
class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
|
||||
type="text"
|
||||
name=""
|
||||
on:keydown|stopPropagation={// event needed to identify ID
|
||||
// TO-DO: check if event is needed or if index is sufficient
|
||||
async (ev) => {
|
||||
handle_input(ev, i);
|
||||
}}
|
||||
bind:value={item.name}
|
||||
id="label__{item.name}"
|
||||
/>-->
|
||||
<!-- disabled={item.show_button} -->
|
||||
<!-- https://iconduck.com/icons/192863/edit-rename -->
|
||||
|
||||
{#if item.show_button}
|
||||
<button
|
||||
style="padding: 2px"
|
||||
id="edit__{item.name}"
|
||||
aria-label="Datei umbenennen"
|
||||
on:click|preventDefault={(ev) => {
|
||||
let text_field_id = `label__${item.name}`;
|
||||
|
||||
let text_field = document.getElementById(text_field_id);
|
||||
if (text_field) {
|
||||
text_field.setAttribute('contenteditable', 'true');
|
||||
text_field.focus();
|
||||
text_field.textContent = '';
|
||||
}
|
||||
|
||||
// hide button
|
||||
item.show_button = false;
|
||||
}}
|
||||
>
|
||||
<Edit />
|
||||
</button>
|
||||
{/if}
|
||||
<button
|
||||
style="padding: 2px"
|
||||
id="del__{item.name}"
|
||||
on:click|preventDefault={async (ev) => {
|
||||
let delete_item = window.confirm('Bist du sicher?');
|
||||
|
||||
if (delete_item) {
|
||||
// bucket: tatort, name: <vorgang>/item-name
|
||||
let vorgang = $page.params.vorgang;
|
||||
let filename = '';
|
||||
if (ev && ev.currentTarget && (ev.currentTarget as HTMLElement).id) {
|
||||
filename = (ev.currentTarget as HTMLElement).id.split('del__')[1];
|
||||
}
|
||||
|
||||
// delete request
|
||||
// --------------
|
||||
|
||||
let url = new URL($page.url);
|
||||
url.pathname += `/${filename}`;
|
||||
|
||||
console.log(`--- ${vorgang} + ${filename} + ${url}`);
|
||||
try {
|
||||
const response = await fetch(url, { method: 'DELETE' });
|
||||
if (response.status == 204) {
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 500);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.log(error.message);
|
||||
} else {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
aria-label="Datei löschen"
|
||||
>
|
||||
<Trash />
|
||||
</button>
|
||||
{:else}
|
||||
<span class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
|
||||
>{item.name}</span
|
||||
>
|
||||
{/if}
|
||||
<p class="mt-1 truncate text-xs leading-5 text-gray-500">
|
||||
{shortenFileSize(item.size)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden sm:flex sm:flex-col sm:items-end">
|
||||
<p class="text-sm leading-6 text-gray-900">3D Tatort</p>
|
||||
<p class="mt-1 text-xs leading-5 text-gray-500">
|
||||
Zuletzt geändert <time datetime="2023-01-23T13:23Z"
|
||||
>{timeElapsed(new Date(item.lastModified))}</time
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<Modal {open}
|
||||
><ModalTitle>Umbenennen</ModalTitle><ModalContent>
|
||||
{#if inProgress}
|
||||
<p class="py-2 mb-1">Vorgang läuft...</p>
|
||||
{/if}
|
||||
{#if err}
|
||||
<Alert class="w-full" type="error">Fehler beim Umbenennen</Alert>
|
||||
{/if}
|
||||
</ModalContent>
|
||||
<ModalFooter><Button disabled={inProgress} on:click={uploadSuccessful}>Ok</Button></ModalFooter>
|
||||
</Modal>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
ul {
|
||||
min-width: 24rem;
|
||||
}
|
||||
</style>
|
||||
35
src/routes/(token-based)/list/[vorgang]/+server.ts
Normal file
35
src/routes/(token-based)/list/[vorgang]/+server.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { client } from '$lib/minio';
|
||||
import { json } from '@sveltejs/kit';
|
||||
|
||||
|
||||
// rename operation
|
||||
export async function PUT({ request }: {request: Request}) {
|
||||
const data = await request.json();
|
||||
|
||||
|
||||
// Vorgang
|
||||
const vorgang = request.url.split('/').at(-1);
|
||||
|
||||
// prepare copy, incl. check if new name exists already
|
||||
const old_name = data["old_name"];
|
||||
const src_full_path = `/tatort/${vorgang}/${old_name}`;
|
||||
const new_name = `${vorgang}/${data["new_name"]}`;
|
||||
|
||||
try {
|
||||
await client.statObject('tatort', new_name);
|
||||
return json({ msg: 'Die Datei existiert bereits.' }, { status: 400 });
|
||||
} catch (error) {
|
||||
// continue operation
|
||||
console.log(error, 'continue operation');
|
||||
}
|
||||
|
||||
// actual copy operation
|
||||
await client.copyObject('tatort', new_name, src_full_path)
|
||||
|
||||
// delete
|
||||
await client.removeObject('tatort', `${vorgang}/${old_name}`)
|
||||
|
||||
// return success or failure
|
||||
|
||||
return json({ success: 'success' }, { status: 200 });
|
||||
};
|
||||
11
src/routes/(token-based)/list/[vorgang]/[tatort]/+server.ts
Normal file
11
src/routes/(token-based)/list/[vorgang]/[tatort]/+server.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { client } from '$lib/minio';
|
||||
|
||||
export async function DELETE({ request }: { request: Request }) {
|
||||
const url_fragments = request.url.split('/');
|
||||
const item = url_fragments.at(-1);
|
||||
const vorgang = url_fragments.at(-2);
|
||||
|
||||
await client.removeObject('tatort', `${vorgang}/${item}`);
|
||||
|
||||
return new Response(null, { status: 204 });
|
||||
}
|
||||
6
src/routes/(token-based)/view/+page.server.ts
Normal file
6
src/routes/(token-based)/view/+page.server.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { getVorgangByCaseNumber } from '$lib/server/vorgangService';
|
||||
|
||||
/** @type {import('./$types').Actions} */
|
||||
export const actions = {
|
||||
default: async ({request}: {request: Request}) => getVorgangByCaseNumber(request)
|
||||
}
|
||||
82
src/routes/(token-based)/view/+page.svelte
Normal file
82
src/routes/(token-based)/view/+page.svelte
Normal file
@@ -0,0 +1,82 @@
|
||||
<script lang="ts">
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
import Exclamation from '$lib/icons/Exclamation.svelte';
|
||||
|
||||
export let form;
|
||||
</script>
|
||||
|
||||
<div class="mx-auto max-w-2xl">
|
||||
<div class="flex flex-col items-center justify-center w-full">
|
||||
<h1 class="text-xl">Vorgang ansehen</h1>
|
||||
</div>
|
||||
|
||||
<form method="POST">
|
||||
<div class="space-y-12">
|
||||
<div class="border-b border-gray-900/10 pb-12">
|
||||
<!-- <h2 class="text-base font-semibold leading-7 text-gray-900">Profile</h2> -->
|
||||
<p class="mt-8 text-sm leading-6 text-gray-600">
|
||||
Anhand der Vorgangsnummer werden Sie zu den Dateien des Vorgangs weitergeleitet und können
|
||||
sich den Vorgang dann ansehen.
|
||||
</p>
|
||||
|
||||
<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-8">
|
||||
<div>
|
||||
<label for="caseNumber" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
><span class="flex"
|
||||
>{#if form?.error?.caseNumber}
|
||||
<span class="inline-block mr-1"><Exclamation /></span>
|
||||
{/if} Vorgangs-Nr.</span
|
||||
></label
|
||||
>
|
||||
<div class="mt-2 w-full">
|
||||
<div
|
||||
class="flex w-full rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
|
||||
>
|
||||
<input
|
||||
value={form?.caseNumber ?? ''}
|
||||
type="text"
|
||||
name="caseNumber"
|
||||
id="caseNumber"
|
||||
class="block w-full flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if form?.error?.caseNumber}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{form.error.caseNumber}</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="token" class="block text-sm font-medium leading-6 text-gray-900"
|
||||
><span class="flex"> Zugangscode</span></label
|
||||
>
|
||||
<div class="mt-2 w-full">
|
||||
<div
|
||||
class="flex w-full rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
|
||||
>
|
||||
<input
|
||||
value={false || ''}
|
||||
placeholder="optional"
|
||||
type="text"
|
||||
name="token"
|
||||
id="token"
|
||||
class="block w-full flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{#if form?.error?.token}
|
||||
<p class="block text-sm leading-6 text-red-900 mt-2">{form.error.token}</p>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-6 flex items-center justify-end gap-x-6">
|
||||
<Button
|
||||
type="submit"
|
||||
class="rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>Weiter</Button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,9 @@
|
||||
import { client } from '$lib/minio';
|
||||
import type { PageServerLoad } from './$types';
|
||||
|
||||
/** @type {import('./$types').PageServerLoad} */
|
||||
export const load: PageServerLoad = async ({ params }) => {
|
||||
const { vorgang, tatort } = params;
|
||||
const url = await client.presignedUrl('GET', 'tatort', `${vorgang}/${tatort}`);
|
||||
return { url };
|
||||
}
|
||||
205
src/routes/(token-based)/view/[vorgang]/[tatort]/+page.svelte
Normal file
205
src/routes/(token-based)/view/[vorgang]/[tatort]/+page.svelte
Normal file
@@ -0,0 +1,205 @@
|
||||
<script lang="ts">
|
||||
import Panel from '$lib/components/Panel.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import Button from '$lib/components/Button.svelte';
|
||||
|
||||
export let data;
|
||||
|
||||
onMount(() => {
|
||||
import('@google/model-viewer');
|
||||
});
|
||||
|
||||
let progress = 0;
|
||||
let hideProgressScreen = false;
|
||||
|
||||
let cameraOrbit = '0deg 0deg 100%';
|
||||
let cameraTarget = '0m 0m 0m';
|
||||
let fieldOfView = '10deg';
|
||||
|
||||
let cameraAzimuth = 0;
|
||||
let cameraPolar = 0;
|
||||
|
||||
let cameraZoom = 100;
|
||||
let xRotation = 0;
|
||||
let yRotation = 0;
|
||||
let zRotation = 0;
|
||||
|
||||
let modelViewer;
|
||||
|
||||
$: style = `width: ${progress}%`;
|
||||
|
||||
const onProgress = ({ detail }) => {
|
||||
progress = Math.ceil(detail.totalProgress * 100.0);
|
||||
if (progress == 100) {
|
||||
setTimeout(() => {
|
||||
hideProgressScreen = true;
|
||||
}, 250);
|
||||
} else hideProgressScreen = false;
|
||||
}
|
||||
|
||||
function onResetView() {
|
||||
cameraAzimuth = 0;
|
||||
cameraPolar = 0;
|
||||
cameraZoom = 100;
|
||||
|
||||
modelViewer.cameraOrbit = cameraOrbit;
|
||||
modelViewer.cameraTarget = cameraTarget;
|
||||
modelViewer.fieldOfView = fieldOfView;
|
||||
cameraAzimuth = 0;
|
||||
cameraPolar = 0;
|
||||
cameraZoom = 100;
|
||||
fieldOfView = '10deg';
|
||||
}
|
||||
|
||||
function updateCameraOrbit(azimuth: number, polar: number, zoom: number) {
|
||||
cameraAzimuth = azimuth;
|
||||
cameraPolar = polar;
|
||||
cameraZoom = zoom;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="h-full model w-full bg-neutral-200 p-4 transition-all delay-250">
|
||||
<!-- xr-environment -->
|
||||
<model-viewer
|
||||
ar
|
||||
shadow-intensity="1"
|
||||
src={data.url}
|
||||
bind:this={modelViewer}
|
||||
touch-action="pan-y"
|
||||
field-of-view={fieldOfView}
|
||||
min-field-of-view="1deg"
|
||||
max-field-of-view="10deg"
|
||||
camera-controls
|
||||
orientation={`${xRotation}deg ${yRotation}deg ${zRotation}deg`}
|
||||
camera-target="0m 0m 0m"
|
||||
camera-orbit={`${cameraAzimuth}deg ${cameraPolar}deg ${cameraZoom}%`}
|
||||
on:progress={onProgress}
|
||||
>
|
||||
<!--Buttons zum Steuern-->
|
||||
<div
|
||||
class=" p-4 flex z-10 absolute bottom-0"
|
||||
class:opacity-0={!hideProgressScreen}
|
||||
class:hidden={!hideProgressScreen}
|
||||
>
|
||||
<button slot="ar-button" id="ar-button"> 👋 Activate AR </button>
|
||||
|
||||
<div id="ar-prompt">AR-Prompt</div>
|
||||
|
||||
<button id="ar-failure"> AR is not tracking! </button>
|
||||
<div class="flex flex-col bg-white/50">
|
||||
<button
|
||||
on:click={() => {
|
||||
console.log(modelViewer.ar, modelViewer.getAttribute('ar-status'));
|
||||
}}>Test</button
|
||||
>
|
||||
|
||||
<!--3 Buttons-->
|
||||
<div class="p-2">
|
||||
<Button
|
||||
on:click={() => {
|
||||
updateCameraOrbit(0, 0, cameraZoom);
|
||||
}}
|
||||
type="button"
|
||||
variant="white"
|
||||
align="left"
|
||||
class="relative cursor-default justify-start py-2 pl-3 pr-10 text-left "
|
||||
>
|
||||
Draufsicht
|
||||
</Button>
|
||||
<Button
|
||||
on:click={() => {
|
||||
onResetView();
|
||||
}}
|
||||
type="button"
|
||||
variant="white"
|
||||
align="left"
|
||||
class="relative cursor-default justify-start py-2 pl-3 pr-10 text-left"
|
||||
>
|
||||
Werte zurücksetzen
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
on:click={() => {
|
||||
updateCameraOrbit(0, 90, cameraZoom);
|
||||
}}
|
||||
type="button"
|
||||
variant="white"
|
||||
align="left"
|
||||
class="relative cursor-default justify-start py-2 pl-3 pr-10 text-left"
|
||||
>
|
||||
Frontansicht
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<!--Horizontal-->
|
||||
<div class="p-2">
|
||||
<label for="cazimuth">Horizontal drehen (Azimut):</label>
|
||||
<input id="cazimuth" type="range" min="0" max="360" bind:value={cameraAzimuth} />
|
||||
</div>
|
||||
<!--Vertikal-->
|
||||
<div class="p-2">
|
||||
<label class=" mb-2" for="polarSlider">Vertikal drehen (Polar):</label>
|
||||
<input id="polarSlider" type="range" min="0" max="90" bind:value={cameraPolar} />
|
||||
</div>
|
||||
<!--Zoom/Distanz-->
|
||||
<div class="p-2">
|
||||
<label for="cZoom">Abstand (zoom):</label>
|
||||
<input id="cZoom" type="range" min="0" max="100" bind:value={cameraZoom} />
|
||||
</div>
|
||||
</div>
|
||||
<!--Rotationen-->
|
||||
<div class="flex flex-col ml-2 p-4 bg-white/50">
|
||||
Modell rotieren lassen:
|
||||
<br />
|
||||
Modell auf dem Kopf? -> y auf 270°
|
||||
<div class="p-2">
|
||||
<label class="" for="polarSlider">Rotation X:</label>
|
||||
<input id="polarSlider" type="range" min="0" max="360" bind:value={xRotation} />
|
||||
</div>
|
||||
<div class="p-2">
|
||||
<label class="" for="polarSlider">Rotation Y:</label>
|
||||
<input id="polarSlider" type="range" min="0" max="360" bind:value={yRotation} />
|
||||
</div>
|
||||
<div class="p-2">
|
||||
<label class="" for="polarSlider">Rotation Z:</label>
|
||||
<input id="polarSlider" type="range" min="0" max="360" bind:value={zRotation} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!--Loading-->
|
||||
<div
|
||||
slot="progress-bar"
|
||||
class="flex items-center justify-center h-5/6 w-full transition-all delay-250"
|
||||
class:opacity-0={hideProgressScreen}
|
||||
class:hidden={hideProgressScreen}
|
||||
>
|
||||
<Panel class="w-72 bg-gray-50 flex items-center flex-col"
|
||||
><p class="mb-5">Loading {progress}%</p>
|
||||
<div class="h-1 w-full bg-neutral-200 dark:bg-neutral-600">
|
||||
<div class="h-1 bg-blue-500" {style}></div>
|
||||
</div></Panel
|
||||
>
|
||||
</div>
|
||||
</model-viewer>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
model-viewer {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* .vertical-slider {
|
||||
writing-mode: bt-lr; /* Schreibt von unten nach oben (Vertikale Darstellung)
|
||||
transform: rotate(270deg); /* Slider um 270° drehen
|
||||
height: 200px;
|
||||
} */
|
||||
|
||||
.model {
|
||||
height: calc(100%-84px);
|
||||
}
|
||||
|
||||
/* .active-border {
|
||||
border: 2px blue solid;
|
||||
} */
|
||||
</style>
|
||||
Reference in New Issue
Block a user