Compare commits

..

5 Commits

Author SHA1 Message Date
1e29aa8583 fixed frontend path
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-02-11 14:48:01 +01:00
214a4c00f5 finished loading item by db id
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-02-11 14:32:41 +01:00
12ed6d47ec working on loading item by id 2026-02-11 13:41:45 +01:00
76651b1e46 bugfix: still had problems with the menu entry urls
All checks were successful
Build Docker Image / Docker-Build (push) Successful in 2m32s
Build Docker Image / Clean-Registry (push) Successful in 3s
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-02-09 16:11:23 +01:00
cb21560f7c bugfix: menu code did not properly handle module paths on non-top-level pages
All checks were successful
Build Docker Image / Docker-Build (push) Successful in 2m33s
Build Docker Image / Clean-Registry (push) Successful in 3s
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
2026-02-09 16:03:31 +01:00
5 changed files with 51 additions and 6 deletions

View File

@@ -103,7 +103,8 @@
<Route path="/search" component={Search} />
<Route path="/stock" component={Stock} />
<Route path="/stock/location/:location_id" component={Stock} />
<Route path="/stock/:owner/:owner_id/item/:item_id" component={Stock} />
<Route path="/stock/:item_id/view" component={Stock} />
<Route path="/stock/:owner/:owner_id/item/:owner_number" component={Stock} />
<Route path="/tags" component={TagList} />
<Route path="/tags/use/:tag" component={TagUses} />
<Route path="/task" component={TaskList} />

View File

@@ -59,7 +59,7 @@ onMount(fetchModules);
</form>
<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>
<a href={module.module.includes('://') ? module.module : '/'+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>

View File

@@ -1,5 +1,6 @@
<script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api, drop, get, patch } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
@@ -17,8 +18,9 @@
let location = $state(null);
let draggedItem = $state(null)
let draggedLocation = $state(null)
let { item_id, location_id, owner, owner_id } = $props();
let { item_id, location_id, owner, owner_id, owner_number } = $props();
let skip_location = false; // disable effect on setting location within loadItem()
let router = useTinyRouter();
$effect(() => {
// This effect runs whenever `location` changes
@@ -98,8 +100,8 @@
}
async function loadItem(){
if (!item_id) return;
const url = api(`stock/${owner}/${owner_id}/item/${item_id}`);
if (!owner_number) return;
const url = api(`stock/${owner}/${owner_id}/item/${owner_number}`);
const res = await get(url);
if (res.ok){
yikes();
@@ -116,7 +118,7 @@
}
}
for (let i of json.items){
if (i.owner_number == +item_id) item = i;
if (i.owner_number == +owner_number) item = i;
}
} else {
error(res);
@@ -170,12 +172,27 @@
}
async function load(){
await preload();
await loadUserLocations();
await loadPath();
await loadProperties();
await loadItem();
}
async function preload(){
if (item_id) {
let url = api(`stock/item/${item_id}`);
const res = await get(url);
if (res.ok){
const json = await res.json();
owner = json.owner.type;
owner_id = json.owner.id;
owner_number = json.owner_number;
location_id = json.location.id;
}
}
}
function moveToTop(loc){
if (patchLocation(location,'parent_location_id',0)){
loc.parent_location_id = 0;

View File

@@ -74,6 +74,15 @@ Code: <LineEditor type="span" editable={true} value={item.code} onSet={v => patc
</div>
<table>
<tbody>
<tr>
<td>
{t('ID')}
</td>
<td>
{item.id}
</td>
</tr>
{#each item.properties.toSorted(byName) as prop}
<tr>
<td>

View File

@@ -27,6 +27,7 @@ import de.srsoftware.umbrella.core.api.Owner;
import de.srsoftware.umbrella.core.api.StockService;
import de.srsoftware.umbrella.core.constants.Field;
import de.srsoftware.umbrella.core.constants.Path;
import de.srsoftware.umbrella.core.constants.Text;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.*;
import de.srsoftware.umbrella.core.model.Location;
@@ -113,6 +114,7 @@ public class StockModule extends BaseHandler implements StockService {
yield super.doGet(path,ex);
}
}
case Path.ITEM -> getItemById(user.get(),path,ex);
case Path.LOCATION -> {
try {
var location = Location.of(Long.parseLong(path.pop()));
@@ -155,6 +157,22 @@ public class StockModule extends BaseHandler implements StockService {
}
}
private boolean getItemById(UmbrellaUser user, de.srsoftware.tools.Path path, HttpExchange ex) throws IOException {
var head = path.pop();
if (head == null) throw missingField(Field.ID);
try {
var itemId = Long.parseLong(head);
var item = stockDb.loadItem(itemId);
var owner = item.location().resolve().owner().resolve();
boolean allowed = owner instanceof UmbrellaUser u && user.equals(u);
allowed = allowed || owner instanceof Company c && companyService().membership(c.id(),user.id());
if (!allowed) throw forbidden("You are not allowed to access item {id}",ID,itemId);
return sendContent(ex,item);
} catch (NumberFormatException e) {
throw invalidField(Field.ID, Text.NUMBER);
}
}
@Override
public boolean doPatch(de.srsoftware.tools.Path path, HttpExchange ex) throws IOException {
addCors(ex);