Merge branch 'module/stock' into dev
This commit is contained in:
@@ -76,7 +76,7 @@
|
|||||||
{#each top_level as realm,idx}
|
{#each top_level as realm,idx}
|
||||||
<h3>{realm.name}</h3>
|
<h3>{realm.name}</h3>
|
||||||
{#if realm.locations}
|
{#if realm.locations}
|
||||||
<Locations locations={realm.locations} bind:selected={location} />
|
<Locations locations={realm.locations} parent={realm} bind:selected={location} />
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -3,7 +3,12 @@
|
|||||||
import { error, yikes } from '../../warn.svelte';
|
import { error, yikes } from '../../warn.svelte';
|
||||||
import { t } from '../../translations.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){
|
async function toggleChildren(ev, location){
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
@@ -21,20 +26,47 @@
|
|||||||
}
|
}
|
||||||
return false;
|
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>
|
</script>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<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')})}
|
<span class="symbol"></span> {t('add_object',{object:t('location')})}
|
||||||
</a>
|
</a>
|
||||||
|
{/if}
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
{#each locations as location}
|
{#each locations as location}
|
||||||
<li onclick={e => toggleChildren(e, location)} class={location.locations?'expanded':'collapsed'}>
|
<li onclick={e => toggleChildren(e, location)} class={location.locations?'expanded':'collapsed'}>
|
||||||
{location.name}
|
{location.name}
|
||||||
{#if location.locations}
|
{#if location.locations}
|
||||||
<svelte:self locations={location.locations} bind:selected />
|
<svelte:self locations={location.locations} parent={location} bind:selected />
|
||||||
{/if}
|
{/if}
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
<!-- <pre>{JSON.stringify(parent,null,2)}</pre> -->
|
||||||
@@ -136,7 +136,7 @@ public class StockModule extends BaseHandler implements StockService {
|
|||||||
var result = new ArrayList<Object>();
|
var result = new ArrayList<Object>();
|
||||||
var userLocations = stockDb.listUserLocations(user);
|
var userLocations = stockDb.listUserLocations(user);
|
||||||
result.add(Map.of(
|
result.add(Map.of(
|
||||||
ID, user.id(),
|
USER, user.id(),
|
||||||
NAME,user.name(),
|
NAME,user.name(),
|
||||||
LOCATIONS,userLocations.stream().map(DbLocation::toMap).toList()));
|
LOCATIONS,userLocations.stream().map(DbLocation::toMap).toList()));
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ public class StockModule extends BaseHandler implements StockService {
|
|||||||
companies.values().stream().sorted(comparing(a -> a.name().toLowerCase())).forEach(company -> {
|
companies.values().stream().sorted(comparing(a -> a.name().toLowerCase())).forEach(company -> {
|
||||||
var locations = stockDb.listCompanyLocations(company);
|
var locations = stockDb.listCompanyLocations(company);
|
||||||
result.add(Map.of(
|
result.add(Map.of(
|
||||||
ID, company.id(),
|
COMPANY, company.id(),
|
||||||
NAME,company.name(),
|
NAME,company.name(),
|
||||||
LOCATIONS,locations.stream().sorted(comparing(a -> a.name().toLowerCase())).map(DbLocation::toMap).toList()));
|
LOCATIONS,locations.stream().sorted(comparing(a -> a.name().toLowerCase())).map(DbLocation::toMap).toList()));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user