|
|
|
|
@ -4,9 +4,11 @@
@@ -4,9 +4,11 @@
|
|
|
|
|
import { error, yikes } from '../../warn.svelte'; |
|
|
|
|
import { t } from '../../translations.svelte'; |
|
|
|
|
|
|
|
|
|
import Locations from './Locations.svelte'; |
|
|
|
|
import ItemList from './ItemList.svelte'; |
|
|
|
|
import ItemProps from './ItemProps.svelte'; |
|
|
|
|
import LineEditor from '../../Components/LineEditor.svelte'; |
|
|
|
|
import Locations from './Locations.svelte'; |
|
|
|
|
import MarkdownEditor from '../../Components/MarkdownEditor.svelte'; |
|
|
|
|
import Notes from '../notes/RelatedNotes.svelte'; |
|
|
|
|
import Tags from '../tags/TagList.svelte'; |
|
|
|
|
|
|
|
|
|
@ -14,6 +16,7 @@
@@ -14,6 +16,7 @@
|
|
|
|
|
let item = $state(null); |
|
|
|
|
let location = $state(null); |
|
|
|
|
let draggedItem = $state(null) |
|
|
|
|
let draggedLocation = $state(null) |
|
|
|
|
|
|
|
|
|
$effect(() => { |
|
|
|
|
// This effect runs whenever `location` changes |
|
|
|
|
@ -37,6 +40,16 @@
@@ -37,6 +40,16 @@
|
|
|
|
|
} else error(res); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function drag_item(item){ |
|
|
|
|
draggedLocation = null; |
|
|
|
|
draggedItem = item; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function drag_location(loc){ |
|
|
|
|
draggedItem = null; |
|
|
|
|
draggedLocation = loc; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function dropNestedLocation(locations,loc){ |
|
|
|
|
for (let [idx,entry] of locations.entries()){ |
|
|
|
|
if (entry.id == loc.id){ |
|
|
|
|
@ -49,8 +62,8 @@
@@ -49,8 +62,8 @@
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function move_dragged_to(new_loc){ |
|
|
|
|
const data = { item : draggedItem.id, target: new_loc.id }; |
|
|
|
|
const url = api('stock/move_item'); |
|
|
|
|
const data = draggedItem ? { item : draggedItem.id, target: new_loc.id } : { parent_location_id: new_loc.id } |
|
|
|
|
const url = api(draggedItem ? 'stock/move_item' : `stock/location/${draggedLocation.id}`); |
|
|
|
|
const res = await fetch(url,{ |
|
|
|
|
credentials : 'include', |
|
|
|
|
method : 'PATCH', |
|
|
|
|
@ -59,6 +72,13 @@
@@ -59,6 +72,13 @@
|
|
|
|
|
if (res.ok){ |
|
|
|
|
yikes(); |
|
|
|
|
location = new_loc; |
|
|
|
|
if (!draggedItem){ |
|
|
|
|
for (var owner of top_level){ |
|
|
|
|
if (owner.locations && dropNestedLocation(owner.locations,draggedLocation)) break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
draggedItem = null; |
|
|
|
|
draggedLocation = null; |
|
|
|
|
} else { |
|
|
|
|
error(res); |
|
|
|
|
} |
|
|
|
|
@ -104,13 +124,28 @@
@@ -104,13 +124,28 @@
|
|
|
|
|
loadProperties(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function patchLocation(location,field,newValue){ |
|
|
|
|
const data = {}; |
|
|
|
|
data[field] = newValue; |
|
|
|
|
console.log(data); |
|
|
|
|
const url = api(`stock/location/${location.id}`); |
|
|
|
|
const res = await fetch(url,{ |
|
|
|
|
credentials: 'include', |
|
|
|
|
method:'PATCH', |
|
|
|
|
body:JSON.stringify(data) |
|
|
|
|
}); |
|
|
|
|
if (res.ok){ |
|
|
|
|
yikes(); |
|
|
|
|
return true; |
|
|
|
|
} else { |
|
|
|
|
error(res); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMount(load); |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<style> |
|
|
|
|
|
|
|
|
|
</style> |
|
|
|
|
|
|
|
|
|
<h2>{t('Stock')}</h2> |
|
|
|
|
<div class="grid3"> |
|
|
|
|
<div class="locations"> |
|
|
|
|
@ -118,7 +153,12 @@
@@ -118,7 +153,12 @@
|
|
|
|
|
{#each top_level as realm,idx} |
|
|
|
|
<h3>{realm.name}</h3> |
|
|
|
|
{#if realm.locations} |
|
|
|
|
<Locations locations={realm.locations} parent={realm.parent} bind:selected={location} {move_dragged_to} /> |
|
|
|
|
<Locations |
|
|
|
|
locations={realm.locations} |
|
|
|
|
parent={realm.parent} |
|
|
|
|
bind:selected={location} |
|
|
|
|
{move_dragged_to} |
|
|
|
|
drag_start={drag_location} /> |
|
|
|
|
{/if} |
|
|
|
|
{/each} |
|
|
|
|
{/if} |
|
|
|
|
@ -128,9 +168,16 @@
@@ -128,9 +168,16 @@
|
|
|
|
|
{:then data} |
|
|
|
|
<div class="items"> |
|
|
|
|
{#if location} |
|
|
|
|
<h3>{location.name} <button class="symbol" title={t('delete_object',{object:t('location')})} onclick={e => deleteLocation(location)}></button></h3> |
|
|
|
|
<h3> |
|
|
|
|
<LineEditor editable={true} bind:value={location.name} type="span" onSet={newName => patchLocation(location,'name',newName)} /> |
|
|
|
|
<button class="symbol" title={t('delete_object',{object:t('location')})} onclick={e => deleteLocation(location)}></button> |
|
|
|
|
{#if location.parent_location_id} |
|
|
|
|
<button class="symbol" title={t('move_to_top')} onclick={e => patchLocation(location,'parent_location_id',0)}></button> |
|
|
|
|
{/if} |
|
|
|
|
</h3> |
|
|
|
|
<MarkdownEditor editable={true} value={location.description} type="div" onSet={newDesc => patchLocation(location,'description',newDesc)} /> |
|
|
|
|
{/if} |
|
|
|
|
<ItemList items={data?.items.sort((a,b) => a.code.localeCompare(b.code))} bind:selected={item} drag_start={item => draggedItem = item} /> |
|
|
|
|
<ItemList items={data?.items.sort((a,b) => a.code.localeCompare(b.code))} bind:selected={item} drag_start={drag_item} /> |
|
|
|
|
</div> |
|
|
|
|
<div class="properties"> |
|
|
|
|
<ItemProps {item} {properties} /> |
|
|
|
|
|