Browse Source

template work

featue/module_registry
Stephan Richter 3 months ago
parent
commit
8eef37eb1a
  1. 34
      frontend/src/routes/tags/Reference.svelte
  2. 1
      frontend/src/routes/tags/TagList.svelte
  3. 9
      frontend/src/routes/tags/TagUses.svelte

34
frontend/src/routes/tags/Reference.svelte

@ -1,21 +1,27 @@
<script> <script>
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js'; import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js'; import { t } from '../../translations.svelte.js';
let { module, id } = $props(); let { module, id } = $props();
let error = $state(null);
let object = $state(null);
let router = useTinyRouter();
let task = $state(null);
let task = $state(null); function go(){
let caption = $state(`${t(module)} ${id}`); router.navigate(`/${module}/${id}/view`);
}
async function loadDefault(){ async function loadDefault(){
const url = api(`${module}/${id}`); const url = api(`${module}/${id}`);
const resp = await fetch(url,{credentials:'include'}); const resp = await fetch(url,{credentials:'include'});
if (resp.ok){ if (resp.ok) {
var json = await resp.json(); object = await resp.json();
if (json.name) caption = json.name; } else {
if (json.type && json.number) caption = `${t(json.type)} ${json.number} (${json.customer.name.split('\n')[0]})` error = await resp.text();
} }
} }
@ -26,4 +32,18 @@
onMount(load); onMount(load);
</script> </script>
{caption} {#if error}
<span class="error">{error}</span>
{/if}
{#if object}
{#if module=='bookmark'}
<a href={object.url}>{object.url}</a>
<div>{@html object.comment.rendered}</div>
{:else if module=='task'}
<span onclick={go}>{object.name}</span>
{:else if module=='document'}
<span onclick={go}>{t(object.type)} ${object.number} (${object.customer.name.split('\n')[0]})</span>
{:else}
No display defined in Reference.svelte for entities of type {module}.
{/if}
{/if}

1
frontend/src/routes/tags/TagList.svelte

@ -21,6 +21,7 @@
// when creating elements, they don`t have an id, yet // when creating elements, they don`t have an id, yet
tags.push(newTag); tags.push(newTag);
tags = tags.sort(); tags = tags.sort();
newTag = '';
return; return;
} }
const url = api(`tags/${module}/${id}`); const url = api(`tags/${module}/${id}`);

9
frontend/src/routes/tags/TagUses.svelte

@ -1,15 +1,13 @@
<script> <script>
import {onMount} from 'svelte'; import {onMount} from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js'; import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js'; import { t } from '../../translations.svelte.js';
import Reference from './Reference.svelte'; import Reference from './Reference.svelte';
let { tag } = $props(); let { tag } = $props();
let error = $state(null); let error = $state(null);
let router = useTinyRouter();
let uses = $state(null); let uses = $state(null);
async function loadUses(){ async function loadUses(){
@ -23,9 +21,6 @@
} }
} }
function go(module,id){
router.navigate(`/${module}/${id}/view`);
}
onMount(loadUses); onMount(loadUses);
</script> </script>
@ -39,7 +34,7 @@
<h2>{t(module.endsWith('s') ? module : `${module}s`)}</h2> <h2>{t(module.endsWith('s') ? module : `${module}s`)}</h2>
<ul> <ul>
{#each ids as id} {#each ids as id}
<li onclick={() => go(module,id)}><Reference {module} {id} /></li> <li><Reference {module} {id} /></li>
{/each} {/each}
</ul> </ul>
{/each} {/each}

Loading…
Cancel
Save