Browse Source

working on new location creation

module/document
Stephan Richter 3 weeks ago
parent
commit
2eb2bb25aa
  1. 2
      frontend/src/routes/stock/Index.svelte
  2. 40
      frontend/src/routes/stock/Locations.svelte
  3. 4
      stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

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

@ -76,7 +76,7 @@ @@ -76,7 +76,7 @@
{#each top_level as realm,idx}
<h3>{realm.name}</h3>
{#if realm.locations}
<Locations locations={realm.locations} bind:selected={location} />
<Locations locations={realm.locations} parent={realm} bind:selected={location} />
{/if}
{/each}
{/if}

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

@ -3,7 +3,12 @@ @@ -3,7 +3,12 @@
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
let { locations, selected = $bindable(null) } = $props();
import LineEditor from '../../Components/LineEditor.svelte';
let { locations, parent = null, selected = $bindable(null) } = $props();
let show_location_form = $state(false);
let new_location_name = $state(null);
async function toggleChildren(ev, location){
ev.preventDefault();
@ -21,20 +26,47 @@ @@ -21,20 +26,47 @@
}
return false;
}
function onsubmit(ev){
ev.preventDefault();
ev.stopPropagation();
const data = {
name: new_location_name,
parent: parent.user ? {user:parent.user} : {company:parent.company}
}
console.log(data);
}
function show_loc_form(ev){
ev.preventDefault();
ev.stopPropagation();
show_location_form = true;
return false;
}
</script>
<ul>
<li>
<a>
{#if show_location_form}
<form {onsubmit}>
<input type="text" placeholder={t('new_location_name')} bind:value={new_location_name} />
</form>
{:else}
<a onclick={show_loc_form}>
<span class="symbol"></span> {t('add_object',{object:t('location')})}
</a>
{/if}
</li>
{#each locations as location}
<li onclick={e => toggleChildren(e, location)} class={location.locations?'expanded':'collapsed'}>
{location.name}
{#if location.locations}
<svelte:self locations={location.locations} bind:selected />
<svelte:self locations={location.locations} parent={location} bind:selected />
{/if}
</li>
{/each}
</ul>
</ul>
<!-- <pre>{JSON.stringify(parent,null,2)}</pre> -->

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

@ -136,7 +136,7 @@ public class StockModule extends BaseHandler implements StockService { @@ -136,7 +136,7 @@ public class StockModule extends BaseHandler implements StockService {
var result = new ArrayList<Object>();
var userLocations = stockDb.listUserLocations(user);
result.add(Map.of(
ID, user.id(),
USER, user.id(),
NAME,user.name(),
LOCATIONS,userLocations.stream().map(DbLocation::toMap).toList()));
@ -144,7 +144,7 @@ public class StockModule extends BaseHandler implements StockService { @@ -144,7 +144,7 @@ public class StockModule extends BaseHandler implements StockService {
companies.values().stream().sorted(comparing(a -> a.name().toLowerCase())).forEach(company -> {
var locations = stockDb.listCompanyLocations(company);
result.add(Map.of(
ID, company.id(),
COMPANY, company.id(),
NAME,company.name(),
LOCATIONS,locations.stream().sorted(comparing(a -> a.name().toLowerCase())).map(DbLocation::toMap).toList()));

Loading…
Cancel
Save