Browse Source

accomplished direct linking of items

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/stock
Stephan Richter 5 days ago
parent
commit
57a18b5957
  1. 40
      frontend/src/routes/stock/Index.svelte
  2. 3
      stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

40
frontend/src/routes/stock/Index.svelte

@ -18,17 +18,22 @@
let draggedItem = $state(null) let draggedItem = $state(null)
let draggedLocation = $state(null) let draggedLocation = $state(null)
let { item_id, location_id, owner, owner_id } = $props(); let { item_id, location_id, owner, owner_id } = $props();
let skip_location = false; // disable effect on setting location within loadItem()
$effect(() => { $effect(() => {
// This effect runs whenever `location` changes // This effect runs whenever `location` changes
if (location !== null) { if (!skip_location && location !== null) {
item = null; item = null;
setLocationUrl(); setLocationUrl();
} }
}); });
$effect(() => { $effect(() => {
if (item !== null) setItemUrl(); // This effect runs whenever `item` changes
if (item !== null) {
setItemUrl();
skip_location = false;
}
}); });
let properties = $state(null); let properties = $state(null);
let top_level = $state(null); let top_level = $state(null);
@ -96,6 +101,27 @@
if (!item_id) return; if (!item_id) return;
const url = api(`stock/${owner}/${owner_id}/item/${item_id}`); const url = api(`stock/${owner}/${owner_id}/item/${item_id}`);
const res = await get(url); const res = await get(url);
if (res.ok){
yikes();
const json = await res.json();
const path = json.path;
for (let owner of top_level){
for (let loc of owner.locations){
if (loc.id == path.id) {
loc.locations = path.locations;
skip_location = true;
location = json.location;
break;
}
}
}
for (let i of json.items){
if (i.owner_number == +item_id) item = i;
}
} else {
error(res);
return null;
}
} }
async function loadPath(){ async function loadPath(){
@ -146,9 +172,9 @@
async function load(){ async function load(){
await loadUserLocations(); await loadUserLocations();
loadItem(); await loadPath();
loadPath(); await loadProperties();
loadProperties(); await loadItem();
} }
function moveToTop(loc){ function moveToTop(loc){
@ -240,7 +266,7 @@
<div class="properties"> <div class="properties">
<ItemProps {item} {properties} /> <ItemProps {item} {properties} />
</div> </div>
{#if item} {#if item && data && data.users}
<div class="tags"> <div class="tags">
<span>{t('tags')}</span> <span>{t('tags')}</span>
<Tags module="stock" id={item.id} user_list={data.users} /> <Tags module="stock" id={item.id} user_list={data.users} />
@ -255,6 +281,6 @@
<div> <div>
<pre> <pre>
{JSON.stringify({owner,owner_id,item_id},null,2)} {JSON.stringify({item_id,location},null,2)}
</pre> </pre>
</div> </div>

3
stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

@ -181,8 +181,7 @@ public class StockModule extends BaseHandler implements StockService {
try { try {
var itemId = Long.parseLong(path.pop()); var itemId = Long.parseLong(path.pop());
var item = stockDb.loadItem(owner.dbCode(),itemId); var item = stockDb.loadItem(owner.dbCode(),itemId);
stockDb.loadProperties(item); yield getLocationEntities(item.location(),ex);
yield sendContent(ex,item);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
yield super.doGet(path,ex); yield super.doGet(path,ex);
} }

Loading…
Cancel
Save