Browse Source

Merge branch 'module/stock' into dev

module/document
Stephan Richter 2 weeks ago
parent
commit
19451c705f
  1. 30
      frontend/src/routes/stock/Index.svelte
  2. 2
      stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

30
frontend/src/routes/stock/Index.svelte

@ -34,12 +34,16 @@
}); });
if (res.ok){ if (res.ok){
yikes(); yikes();
for (var owner of top_level){ unlistLocation(loc);
if (owner.locations && dropNestedLocation(owner.locations,loc)) break;
}
} else error(res); } else error(res);
} }
function unlistLocation(loc){
for (var owner of top_level){
if (owner.locations && dropNestedLocation(owner.locations,loc)) break;
}
}
function drag_item(item){ function drag_item(item){
draggedLocation = null; draggedLocation = null;
draggedItem = item; draggedItem = item;
@ -72,11 +76,7 @@
if (res.ok){ if (res.ok){
yikes(); yikes();
location = new_loc; location = new_loc;
if (!draggedItem){ if (!draggedItem) unlistLocation(draggedLocation);
for (var owner of top_level){
if (owner.locations && dropNestedLocation(owner.locations,draggedLocation)) break;
}
}
draggedItem = null; draggedItem = null;
draggedLocation = null; draggedLocation = null;
} else { } else {
@ -124,6 +124,18 @@
loadProperties(); loadProperties();
} }
function moveToTop(loc){
if (patchLocation(location,'parent_location_id',0)){
loc.parent_location_id = 0;
for (var owner of top_level){
if (owner.locations && dropNestedLocation(owner.locations,loc)) {
owner.locations.push(loc);
break;
};
}
}
}
async function patchLocation(location,field,newValue){ async function patchLocation(location,field,newValue){
const data = {}; const data = {};
data[field] = newValue; data[field] = newValue;
@ -172,7 +184,7 @@
<LineEditor editable={true} bind:value={location.name} type="span" onSet={newName => patchLocation(location,'name',newName)} /> <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> <button class="symbol" title={t('delete_object',{object:t('location')})} onclick={e => deleteLocation(location)}></button>
{#if location.parent_location_id} {#if location.parent_location_id}
<button class="symbol" title={t('move_to_top')} onclick={e => patchLocation(location,'parent_location_id',0)}></button> <button class="symbol" title={t('move_to_top')} onclick={e => moveToTop(location)}></button>
{/if} {/if}
</h3> </h3>
<MarkdownEditor editable={true} value={location.description} type="div" onSet={newDesc => patchLocation(location,'description',newDesc)} /> <MarkdownEditor editable={true} value={location.description} type="div" onSet={newDesc => patchLocation(location,'description',newDesc)} />

2
stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

@ -250,9 +250,11 @@ public class StockModule extends BaseHandler implements StockService {
if (json.has(PARENT_LOCATION_ID) && json.get(PARENT_LOCATION_ID) instanceof Number parentId){ if (json.has(PARENT_LOCATION_ID) && json.get(PARENT_LOCATION_ID) instanceof Number parentId){
if (parentId.longValue() != 0L) { if (parentId.longValue() != 0L) {
var target = stockDb.loadLocation(parentId.longValue()); var target = stockDb.loadLocation(parentId.longValue());
if (target.id() == location.id()) throw forbidden("Location must not be it`s own parent!");
var targetOwner = target.owner().resolve(); var targetOwner = target.owner().resolve();
if (!assigned(targetOwner, user)) throw forbidden("You are not allowed to edit \"{0}\"!", target.name()); if (!assigned(targetOwner, user)) throw forbidden("You are not allowed to edit \"{0}\"!", target.name());
if (!targetOwner.equals(owner)) throw unprocessable("You may not move locations from one owner ({0}) to another ({1})", owner, targetOwner); if (!targetOwner.equals(owner)) throw unprocessable("You may not move locations from one owner ({0}) to another ({1})", owner, targetOwner);
LOG.log(WARNING,"Not checking, if location is moved to on of its own children!");
} }
} }

Loading…
Cancel
Save