From 8d40c8c9f1c55518d499955937b60e8834d7bc9d Mon Sep 17 00:00:00 2001 From: Stephan Richter Date: Thu, 16 Oct 2025 23:04:52 +0200 Subject: [PATCH] implemented tags for items Signed-off-by: Stephan Richter --- .../umbrella/core/model/DbLocation.java | 4 ++ frontend/src/routes/notes/RelatedNotes.svelte | 6 +-- frontend/src/routes/stock/Index.svelte | 50 ++++++++++++++++--- .../srsoftware/umbrella/stock/Constants.java | 5 +- .../umbrella/stock/StockModule.java | 17 +++++-- 5 files changed, 63 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/de/srsoftware/umbrella/core/model/DbLocation.java b/core/src/main/java/de/srsoftware/umbrella/core/model/DbLocation.java index 24d4d51..1b9874e 100644 --- a/core/src/main/java/de/srsoftware/umbrella/core/model/DbLocation.java +++ b/core/src/main/java/de/srsoftware/umbrella/core/model/DbLocation.java @@ -36,6 +36,10 @@ public class DbLocation extends Location { return new DbLocation(rs.getLong(ID), OwnerRef.of(rs), rs.getLong(PARENT_LOCATION_ID), rs.getString(NAME),rs.getString(DESCRIPTION)); } + public Owner owner(){ + return owner; + } + public Long parent(){ return parentLocationId; } diff --git a/frontend/src/routes/notes/RelatedNotes.svelte b/frontend/src/routes/notes/RelatedNotes.svelte index d5b1cec..7f205fe 100644 --- a/frontend/src/routes/notes/RelatedNotes.svelte +++ b/frontend/src/routes/notes/RelatedNotes.svelte @@ -38,8 +38,8 @@ router.navigate(`/${n.module}/${n.entity_id}/view`); } - async function load(){ - const url = api(`notes/${module}/${entity_id}`); + async function load(id){ + const url = api(`notes/${module}/${id}`); const resp = await fetch(url,{credentials:'include'}); if (resp.ok){ const data = await resp.json(); @@ -87,7 +87,7 @@ } } - onMount(load); + $effect(() => load(entity_id)); diff --git a/frontend/src/routes/stock/Index.svelte b/frontend/src/routes/stock/Index.svelte index f258c22..a68693d 100644 --- a/frontend/src/routes/stock/Index.svelte +++ b/frontend/src/routes/stock/Index.svelte @@ -8,15 +8,21 @@ import ItemList from './ItemList.svelte'; import ItemProps from './ItemProps.svelte'; import Notes from '../notes/RelatedNotes.svelte'; + import Tags from '../tags/TagList.svelte'; - let items = $derived.by(loadItems); + let loc_data = $derived.by(loadLocation); let item = $state(null); let location = $state(null); + + $effect(() => { + // This effect runs whenever `location` changes + if (location !== null) item = null; + }); let properties = $state(null); let top_level = $state(null); - async function loadItems(){ + async function loadLocation(){ if (!location) return null; const url = api(`stock/location/${location.id}`) const res = await fetch(url,{credentials:'include'}); @@ -59,6 +65,23 @@ onMount(load); + +

{t('Stock')}

@@ -71,20 +94,31 @@ {/each} {/if}
+ {#await loc_data} + loading… + {:then data}
- {#await items} - loading… - {:then data} {#if location}

{location.name}

{/if} - a.code.localeCompare(b.code))} bind:selected={item} /> - {/await} + a.code.localeCompare(b.code))} bind:selected={item} />
{#if item} - +
+ {t('tags')} + +
+
+ {t('notes')} + +
+ +
+        {JSON.stringify(data.users,null,2)}
+    
{/if} + {/await}
\ No newline at end of file diff --git a/stock/src/main/java/de/srsoftware/umbrella/stock/Constants.java b/stock/src/main/java/de/srsoftware/umbrella/stock/Constants.java index 035aca9..3360d90 100644 --- a/stock/src/main/java/de/srsoftware/umbrella/stock/Constants.java +++ b/stock/src/main/java/de/srsoftware/umbrella/stock/Constants.java @@ -5,11 +5,10 @@ public class Constants { private Constants(){} - public static final String BELOW = "below"; public static final String CONFIG_DATABASE = "umbrella.modules.stock.database"; public static final String ITEM_ID = "item_id"; - public static final String ITEMS_AT = "items_at"; + public static final String ITEMS = "items"; public static final String LOCATIONS = "locations"; public static final String OF_USER = "of_user"; public static final String PROPERTY_ID = "prop_id"; @@ -17,4 +16,4 @@ public class Constants { public static final String TABLE_ITEM_PROPERTIES = "item_props"; public static final String TABLE_LOCATIONS = "locations"; public static final String TABLE_PROPERTIES = "properties"; -} \ No newline at end of file +} 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 58c4668..364e4b7 100644 --- a/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java +++ b/stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java @@ -50,7 +50,7 @@ public class StockModule extends BaseHandler implements StockService { case LOCATION -> { try { var location = Location.of(Long.parseLong(path.pop())); - yield getItemsAtLocation(user.get(), location, ex); + yield getLocationEntities(location, ex); } catch (Exception e){ yield super.doGet(path,ex); } @@ -97,11 +97,18 @@ public class StockModule extends BaseHandler implements StockService { private boolean getChildLocations(UmbrellaUser user, long parentId, HttpExchange ex) throws IOException { LOG.log(WARNING,"No security check implemented for {0}.getChildLocations(user, parentId, ex)!",getClass().getSimpleName()); // TODO check, that user is allowed to request that location return sendContent(ex, stockDb.listChildLocations(parentId).stream().sorted(comparing(l -> l.name().toLowerCase())).map(DbLocation::toMap)); - } - private boolean getItemsAtLocation(UmbrellaUser user, Location location, HttpExchange ex) throws IOException { - return sendContent(ex, stockDb.listItemsAt(location).stream().map(Item::toMap).toList()); + private boolean getLocationEntities(Location location, HttpExchange ex) throws IOException { + var items = stockDb.listItemsAt(location).stream().map(Item::toMap).toList(); + var owner = location.resolve().owner(); + List userIds = switch (owner.type()){ + case COMPANY -> companyService().getMembers(owner.id()).stream().map(UmbrellaUser::id).toList(); + case USER -> List.of(owner.id()); + case null, default -> throw unprocessable("Unprocessable owner type: {0}",owner.type()); + }; + + return sendContent(ex,Map.of(ITEMS,items,USERS,userIds)); } private boolean getLocations(Path path, UmbrellaUser user, HttpExchange ex) throws IOException { @@ -209,4 +216,4 @@ public class StockModule extends BaseHandler implements StockService { public Collection redefineMe(long company_id) { return List.of(); } -} \ No newline at end of file +}