Merge remote-tracking branch 'origin/module/stock' into module/stock

This commit is contained in:
2025-11-03 20:19:35 +01:00
6 changed files with 86 additions and 63 deletions

View File

@@ -1,6 +1,6 @@
<script>
import { onMount } from 'svelte';
import { api } from '../../urls.svelte';
import { api, drop, get, patch } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
@@ -17,7 +17,7 @@
let location = $state(null);
let draggedItem = $state(null)
let draggedLocation = $state(null)
let { location_id } = $props();
let { item_id, location_id, owner, owner_id } = $props();
$effect(() => {
// This effect runs whenever `location` changes
@@ -36,10 +36,7 @@
async function deleteLocation(loc){
if (!confirm(t('confirm_delete',{element:loc.name}))) return;
const url = api(`stock/location/${loc.id}`);
const res = await fetch(url,{
credentials: 'include',
method: 'DELETE',
});
const res = await drop(url);
if (res.ok){
yikes();
unlistLocation(loc);
@@ -70,11 +67,7 @@
async function move_dragged_to(new_loc){
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',
body : JSON.stringify(data)
});
const res = await patch(url,data);
if (res.ok){
yikes();
location = new_loc;
@@ -88,8 +81,8 @@
async function loadLocation(){
if (!location) return null;
const url = api(`stock/location/${location.id}`)
const res = await fetch(url,{credentials:'include'});
const url = api(`stock/location/${location.id}`);
const res = await get(url);
if (res.ok){
yikes();
return res.json();
@@ -99,9 +92,24 @@
}
}
async function loadPath(){
if (!location_id) return;
const url = api(`stock/location/${location_id}`);
const res = await get(url);
if (res.ok){
yikes();
var path = res.json();
} else {
error(res);
return null;
}
}
async function loadProperties(){
const url = api('stock/properties')
const res = await fetch(url,{credentials:'include'});
const res = await get(url);
if (res.ok){
var json = await res.json();
var dict = {}
@@ -114,7 +122,7 @@
async function loadUserLocations(){
const url = api('stock/locations/of_user')
const res = await fetch(url,{credentials:'include'});
const res = await get(url);
if (res.ok){
top_level = await res.json();
yikes();
@@ -123,7 +131,7 @@
function load(){
loadUserLocations();
unfoldPath();
loadPath();
loadProperties();
}
@@ -143,11 +151,7 @@
const data = {};
data[field] = newValue;
const url = api(`stock/location/${location.id}`);
const res = await fetch(url,{
credentials: 'include',
method:'PATCH',
body:JSON.stringify(data)
});
const res = await patch(url,data);
if (res.ok){
yikes();
return true;
@@ -169,12 +173,6 @@
window.history.replaceState(window.history.state, '', url);
}
// tries to unfold the path to a certain location, if a locationId is supplied via URL
function unfoldPath(){
if (!locationId) return;
// TODO
}
function unlistLocation(loc){
for (var owner of top_level){
if (owner.locations && dropNestedLocation(owner.locations,loc)) break;
@@ -185,9 +183,12 @@
</script>
<h2>{t('Stock')}</h2>
{#if location_id}
{location_id}
{/if}
<span class="warn">
{#if location_id}location id: {location_id}{/if}
{#if owner}owner type: {owner},{/if}
{#if owner_id}owner id: {owner_id},{/if}
{#if item_id}item id: {item_id}{/if}
</span>
<div class="grid3">
<div class="locations">
{#if top_level}

View File

@@ -1,5 +1,5 @@
<script>
import { api } from '../../urls.svelte';
import { api, get } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
@@ -41,7 +41,7 @@
delete location.locations;
} else {
const url = api(`stock/locations/below/${location.id}`);
const res = await fetch(url,{credentials:'include'});
const res = await get(url);
if (res.ok){
yikes();
location.locations = await res.json();
@@ -67,11 +67,7 @@
parent: parent
}
const url = api('stock/location');
const res = await fetch(url,{
credentials: 'include',
method: 'POST',
body: JSON.stringify(data)
});
const res = await post(url,data);
if (res.ok){
yikes;
const saved = await res.json();