finished loading item by db id

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-11 14:32:41 +01:00
parent 12ed6d47ec
commit 214a4c00f5

View File

@@ -1,5 +1,6 @@
<script> <script>
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api, drop, get, patch } from '../../urls.svelte'; import { api, drop, get, patch } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte'; import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte'; import { t } from '../../translations.svelte';
@@ -19,6 +20,7 @@
let draggedLocation = $state(null) let draggedLocation = $state(null)
let { item_id, location_id, owner, owner_id, owner_number } = $props(); let { item_id, location_id, owner, owner_id, owner_number } = $props();
let skip_location = false; // disable effect on setting location within loadItem() let skip_location = false; // disable effect on setting location within loadItem()
let router = useTinyRouter();
$effect(() => { $effect(() => {
// This effect runs whenever `location` changes // This effect runs whenever `location` changes
@@ -98,8 +100,8 @@
} }
async function loadItem(){ async function loadItem(){
if (!item_id && !owner_number) return; if (!owner_number) return;
const url = item_id ? api(`stock/item/${item_id}`) : api(`stock/${owner}/${owner_id}/item/${owner_number}`); const url = api(`stock/${owner}/${owner_id}/item/${owner_number}`);
const res = await get(url); const res = await get(url);
if (res.ok){ if (res.ok){
yikes(); yikes();
@@ -170,12 +172,27 @@
} }
async function load(){ async function load(){
await preload();
await loadUserLocations(); await loadUserLocations();
await loadPath(); await loadPath();
await loadProperties(); await loadProperties();
await loadItem(); 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){ function moveToTop(loc){
if (patchLocation(location,'parent_location_id',0)){ if (patchLocation(location,'parent_location_id',0)){
loc.parent_location_id = 0; loc.parent_location_id = 0;