Merge branch 'feature/stock_clone_item' into dev
This commit is contained in:
@@ -1,11 +1,39 @@
|
||||
<script>
|
||||
import { api, post } from '../../urls.svelte';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { api, eventStream, post } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
|
||||
let { items, selected = $bindable(null), location = null, drag_start = item => console.log({dragging:item}) } = $props();
|
||||
let eventSource = null;
|
||||
let newItem = $state({name:null, code: null});
|
||||
|
||||
function handleCreateEvent(evt){
|
||||
let json = JSON.parse(evt.data);
|
||||
if (json.item.location.id == location.id){
|
||||
items = [...items,json.item];
|
||||
selected = json.item;
|
||||
}
|
||||
}
|
||||
|
||||
function handleEvent(evt,method){
|
||||
console.log(evt,method);
|
||||
}
|
||||
|
||||
function handleDeleteEvent(evt){
|
||||
handleEvent(evt,'delete');
|
||||
}
|
||||
|
||||
function handleUpdateEvent(evt){
|
||||
handleEvent(evt,'update');
|
||||
}
|
||||
|
||||
function load(){
|
||||
try {
|
||||
eventSource = eventStream(handleCreateEvent,handleUpdateEvent,handleDeleteEvent);
|
||||
} catch (ignored) {}
|
||||
}
|
||||
|
||||
async function saveNewItem(){
|
||||
newItem.location = location;
|
||||
const url = api('stock/item');
|
||||
@@ -17,6 +45,12 @@
|
||||
items = [...items, it];
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
if (eventSource) eventSource.close();
|
||||
});
|
||||
onMount(load);
|
||||
|
||||
</script>
|
||||
<table>
|
||||
<thead>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import LineEditor from '../../Components/LineEditor.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { api } from '../../urls.svelte';
|
||||
import { api, patch, post } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { t } from '../../translations.svelte';
|
||||
|
||||
@@ -15,6 +15,15 @@
|
||||
}
|
||||
});
|
||||
|
||||
async function doClone(ev){
|
||||
let url = api('stock/clone');
|
||||
let res = await post(url,{id:item.id});
|
||||
if (res.ok){
|
||||
let json = await res.json();
|
||||
yikes(res);
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
function byName(a,b){
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
@@ -30,11 +39,7 @@
|
||||
},
|
||||
add_prop : add_prop
|
||||
}
|
||||
const res = await fetch(url,{
|
||||
credentials:'include',
|
||||
method:'POST',
|
||||
body:JSON.stringify(data)
|
||||
});
|
||||
const res = await post(url,data);
|
||||
if (res.ok){
|
||||
const prop = await res.json();
|
||||
const id = prop.id;
|
||||
@@ -45,18 +50,14 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
async function patch(key,newVal){
|
||||
async function update(key,newVal){
|
||||
const url = api('stock');
|
||||
const data = {
|
||||
id : item.id,
|
||||
owner : item.owner,
|
||||
};
|
||||
data[key] = newVal;
|
||||
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;
|
||||
@@ -67,13 +68,19 @@
|
||||
</script>
|
||||
|
||||
{#if item}
|
||||
<LineEditor type="h3" editable={true} value={item.name} onSet={v => patch('name',v)} />
|
||||
Code: <LineEditor type="span" editable={true} value={item.code} onSet={v => patch('code',v)} />
|
||||
<LineEditor type="h3" editable={true} value={item.name} onSet={v => update('name',v)} />
|
||||
<button class="clone symbol" title={t('clone')} onclick={doClone}></button>
|
||||
<div>
|
||||
{@html item.description.rendered}
|
||||
</div>
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{t('Code')}:</td>
|
||||
<td>
|
||||
<LineEditor type="span" editable={true} value={item.code} onSet={v => update('code',v)} />
|
||||
</td>
|
||||
</tr>
|
||||
{#each item.properties.toSorted(byName) as prop}
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
Reference in New Issue
Block a user