added display for stock items to TagUses
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
37
frontend/src/routes/stock/display.svelte
Normal file
37
frontend/src/routes/stock/display.svelte
Normal file
@@ -0,0 +1,37 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { useTinyRouter } from 'svelte-tiny-router';
|
||||
|
||||
import { api, get } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
|
||||
let {module, id} = $props();
|
||||
let item = $state(null);
|
||||
let router = useTinyRouter();
|
||||
|
||||
function onclick(e){
|
||||
e.preventDefault();
|
||||
var target = e.target;
|
||||
while (target && !target.href) target=target.parentNode;
|
||||
let href = target.getAttribute('href');
|
||||
if (href) router.navigate(href);
|
||||
return false;
|
||||
}
|
||||
|
||||
async function loadItem(){
|
||||
let url = api(`stock/item/${id}`);
|
||||
let res = await get(url);
|
||||
if (res.ok) {
|
||||
yikes();
|
||||
item = await res.json();
|
||||
} else error();
|
||||
}
|
||||
|
||||
|
||||
onMount(loadItem);
|
||||
</script>
|
||||
|
||||
{#if item}
|
||||
<a href="/stock/{id}/view" {onclick} >({item.code}) {item.name}</a>
|
||||
{/if}
|
||||
@@ -6,6 +6,8 @@
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte.js';
|
||||
|
||||
import ItemDisplay from '../stock/display.svelte';
|
||||
|
||||
let { module, id } = $props();
|
||||
let object = $state(null);
|
||||
let router = useTinyRouter();
|
||||
@@ -44,7 +46,9 @@
|
||||
{:else if module=='wiki'}
|
||||
<span onclick={go}>{object.title}</span>
|
||||
{:else if module=='document'}
|
||||
<span onclick={go}>{t(object.type)} ${object.number} (${object.customer.name.split('\n')[0]})</span>
|
||||
<span onclick={go}>{t('type_'+object.type)} {object.number} ({object.customer.name.split('\n')[0]})</span>
|
||||
{:else if module=='stock'}
|
||||
<ItemDisplay {module} {id} />
|
||||
{:else}
|
||||
<span class="error">No display defined in Reference.svelte for entities of type {module}.</span>
|
||||
{/if}
|
||||
|
||||
@@ -12,6 +12,12 @@
|
||||
let router = useTinyRouter();
|
||||
let uses = $state(null);
|
||||
|
||||
function headline(module){
|
||||
if (module == 'stock') return t(module);
|
||||
if (module.endsWith('s')) return t(`${module}s`);
|
||||
return t(module);
|
||||
}
|
||||
|
||||
async function loadUses(){
|
||||
const url = api(`tags/uses/${tag}`);
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
@@ -36,7 +42,7 @@
|
||||
</legend>
|
||||
{#if uses}
|
||||
{#each Object.entries(uses) as [module,ids]}
|
||||
<h2>{t(module.endsWith('s') ? module : `${module}s`)}</h2>
|
||||
<h2>{headline(module)}</h2>
|
||||
<ul>
|
||||
{#each ids as id}
|
||||
<li><Reference {module} {id} /></li>
|
||||
|
||||
Reference in New Issue
Block a user