diff --git a/frontend/src/routes/stock/Index.svelte b/frontend/src/routes/stock/Index.svelte index a63990c..43078ec 100644 --- a/frontend/src/routes/stock/Index.svelte +++ b/frontend/src/routes/stock/Index.svelte @@ -10,10 +10,10 @@ import Notes from '../notes/RelatedNotes.svelte'; import Tags from '../tags/TagList.svelte'; - let loc_data = $derived.by(loadLocation); let item = $state(null); let location = $state(null); + let draggedItem = $state(null) $effect(() => { // This effect runs whenever `location` changes @@ -22,6 +22,19 @@ let properties = $state(null); let top_level = $state(null); + async function move_dragged_to(new_loc){ + const data = { item : draggedItem, target: new_loc }; + const url = api('stock/move_item'); + const res = await fetch(url,{ + credentials : 'include', + method : 'PATCH', + body : JSON.stringify(data) + }); + if (res.ok){ + yikes(); + } else error(res); + } + async function loadLocation(){ if (!location) return null; const url = api(`stock/location/${location.id}`) @@ -76,7 +89,7 @@ {#each top_level as realm,idx}

{realm.name}

{#if realm.locations} - + {/if} {/each} {/if} @@ -88,7 +101,7 @@ {#if location}

{location.name}

{/if} - a.code.localeCompare(b.code))} bind:selected={item} /> + a.code.localeCompare(b.code))} bind:selected={item} drag_start={item => draggedItem = item} />
diff --git a/frontend/src/routes/stock/ItemList.svelte b/frontend/src/routes/stock/ItemList.svelte index be9010f..308a27e 100644 --- a/frontend/src/routes/stock/ItemList.svelte +++ b/frontend/src/routes/stock/ItemList.svelte @@ -1,7 +1,7 @@ @@ -13,7 +13,7 @@ {#each items as item} - selected = item}> + selected = item} ondragstart={e => drag_start(item)} draggable="true"> diff --git a/frontend/src/routes/stock/Locations.svelte b/frontend/src/routes/stock/Locations.svelte index a2d1435..8588c38 100644 --- a/frontend/src/routes/stock/Locations.svelte +++ b/frontend/src/routes/stock/Locations.svelte @@ -5,10 +5,22 @@ import LineEditor from '../../Components/LineEditor.svelte'; - let { locations, parent = null, selected = $bindable(null) } = $props(); + let { locations, move_dragged_to = new_loc => {}, selected = $bindable(null) } = $props(); let show_location_form = $state(false); let new_location_name = $state(null); + let highlight = $state(null); + + function drag_over(ev,location){ + ev.stopPropagation(); + ev.preventDefault(); + location.highlight = true; + return false; + } + + function flat(x){ + return JSON.parse(JSON.stringify(x)); + } async function toggleChildren(ev, location){ ev.preventDefault(); @@ -35,8 +47,6 @@ name: new_location_name, parent: parent.user ? {user:parent.user} : {company:parent.company} } - - console.log(data); } function show_loc_form(ev){ @@ -47,6 +57,12 @@ } + +
  • {#if show_location_form} @@ -61,10 +77,14 @@
  • {#each locations as location} -
  • toggleChildren(e, location)} class={location.locations?'expanded':'collapsed'}> - {location.name} +
  • toggleChildren(e, location)} + class="{location.locations?'expanded':'collapsed'} {location.highlight?'highlight':null}" + ondragover={e => drag_over(e,location)} + ondrop={e => move_dragged_to(location)} + ondragleave={e => delete location.highlight}> + {location.name} {#if location.locations} - + {/if}
  • {/each} diff --git a/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java b/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java index 5c2894f..0d52660 100644 --- a/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java +++ b/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java @@ -136,7 +136,7 @@ public class StockModule extends BaseHandler implements StockService { var result = new ArrayList(); var userLocations = stockDb.listUserLocations(user); result.add(Map.of( - USER, user.id(), + OWNER, Map.of(USER, user.id()), NAME,user.name(), LOCATIONS,userLocations.stream().map(DbLocation::toMap).toList()));
{item.id} {item.code} {item.name}