implemented configurable menu, needs testing!

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-07 17:39:58 +01:00
parent e48bac4ce2
commit ece5a1ae85
6 changed files with 112 additions and 45 deletions

View File

@@ -2,32 +2,25 @@
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api, get } from '../urls.svelte.js';
import { logout, user } from '../user.svelte.js';
import { t } from '../translations.svelte.js';
import { api, get } from '../urls.svelte';
import { error } from '../warn.svelte';
import { logout, user } from '../user.svelte';
import { t } from '../translations.svelte';
import TimeRecorder from './TimeRecorder.svelte';
let key = $state(null);
const router = useTinyRouter();
const modules = $state([]);
let modules = $state(null);
let expand = $state(false);
async function fetchModules(){
let url = api('settings/menu');
const res = await get(url);
url = `${location.protocol}//${location.host.replace('5173','8080')}/legacy/user/modules`;
const resp = await get(url);
if (resp.ok){
const arr = await resp.json();
for (let entry of arr) {
let name = t('module.'+entry.module);
if (name) modules.push({name:name,url:entry.url});
}
if (res.ok){
modules = await res.json();
} else {
console.log('error');
error(res);
}
}
@@ -35,7 +28,11 @@ function onclick(e){
e.preventDefault();
expand = false;
let href = e.target.getAttribute('href');
if (href) router.navigate(href);
if (href) {
if (href.includes('://')) {
window.location.href = href;
} else router.navigate(href);
}
return false;
}
@@ -60,27 +57,13 @@ onMount(fetchModules);
<input type="text" bind:value={key} />
<button type="submit">{t('search')}</button>
</form>
<button class="symbol" onclick={e => expand = !expand}></button>
<a href="/user" {onclick} class="user">{t('users')}</a>
<a href="/company" {onclick} class="company">{t('companies')}</a>
<a href="/project" {onclick} class="project">{t('projects')}</a>
<a href="/task" {onclick} class="task">{t('tasks')}</a>
<a href="/tags" {onclick} class="tags">{t('tags')}</a>
<a href="/document" {onclick} class="doc">{t('documents')}</a>
<a href="/bookmark" {onclick} class="mark">{t('bookmarks')}</a>
<a href="/notes" {onclick} class="note">{t('notes')}</a>
<a href="/files" {onclick} class="file">{t('files')}</a>
<a href="/time" {onclick} class="time">{t('timetracking')}</a>
<a href="/wiki" {onclick} class="wiki">{t('wiki')}</a>
<a href="/contact" {onclick} class="contact">{t('contacts')}</a>
<a href="/stock" {onclick} class="stock">{t('stock')}</a>
<a href="/message" {onclick} class="message">{@html t('messages')}</a>
<button class="symbol" onclick={e => expand = !expand}> </button>
{#each modules as module,i}
<a href={module.module} {onclick} class={module.class}>{@html t(module.title)}</a>
{/each}
{#if user.id == 2}
<a href="https://svelte.dev/tutorial/svelte/state" target="_blank">{t('tutorial')}</a>
{/if}
{#each modules as module,i}
{#if module.name.trim()}<a href={module.url}>{module.name}</a>{/if}
{/each}
{#if user.name }
<a class="logout" onclick={logout}>{t('logout_user',{user:user.name})}</a>
{/if}