working on referenceable locations
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
let loc_data = $derived.by(loadLocation);
|
||||
let item = $state(null);
|
||||
let location = $state(null);
|
||||
let draggedItem = $state(null)
|
||||
let draggedLocation = $state(null)
|
||||
let draggedItem = $state(null);
|
||||
let draggedLocation = $state(null);
|
||||
let { item_id, location_id, owner, owner_id } = $props();
|
||||
|
||||
$effect(() => {
|
||||
// This effect runs whenever `location` changes
|
||||
@@ -35,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);
|
||||
@@ -69,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;
|
||||
@@ -87,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();
|
||||
@@ -98,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 = {}
|
||||
@@ -113,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();
|
||||
@@ -122,6 +131,7 @@
|
||||
|
||||
function load(){
|
||||
loadUserLocations();
|
||||
loadPath();
|
||||
loadProperties();
|
||||
}
|
||||
|
||||
@@ -141,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;
|
||||
@@ -179,6 +185,12 @@
|
||||
</script>
|
||||
|
||||
<h2>{t('Stock')}</h2>
|
||||
<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}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user