implemented cloning of stock items. NEXT: update of GUI via message bus
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -6,7 +6,9 @@ public class Path {
|
||||
|
||||
public static final String ADD = "add";
|
||||
public static final String AVAILABLE = "available";
|
||||
|
||||
public static final String CSS = "css";
|
||||
public static final String CLONE = "clone";
|
||||
public static final String COMMON_TEMPLATES = "common_templates";
|
||||
public static final String COMPANY = "company";
|
||||
public static final String CONNECTED = "connected";
|
||||
|
||||
@@ -552,7 +552,7 @@ public class DocumentApi extends BaseHandler implements DocumentService {
|
||||
private boolean postToDocument(HttpExchange ex, de.srsoftware.tools.Path path, UmbrellaUser user, long docId) throws IOException, UmbrellaException {
|
||||
var head = path.pop();
|
||||
return switch (head){
|
||||
case CLONE -> postCloneDoc(docId,ex,user);
|
||||
case Path.CLONE -> postCloneDoc(docId,ex,user);
|
||||
case POSITION -> postDocumentPosition(docId,ex,user);
|
||||
case PATH_SEND -> sendDocument(ex,path,user,docId);
|
||||
case null, default -> super.doPost(path,ex);
|
||||
|
||||
@@ -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}>C</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>
|
||||
|
||||
@@ -27,6 +27,7 @@ import de.srsoftware.umbrella.core.api.Owner;
|
||||
import de.srsoftware.umbrella.core.api.StockService;
|
||||
import de.srsoftware.umbrella.core.constants.Field;
|
||||
import de.srsoftware.umbrella.core.constants.Path;
|
||||
import de.srsoftware.umbrella.core.constants.Text;
|
||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||
import de.srsoftware.umbrella.core.model.*;
|
||||
import de.srsoftware.umbrella.core.model.Location;
|
||||
@@ -190,6 +191,7 @@ public class StockModule extends BaseHandler implements StockService {
|
||||
if (user.isEmpty()) return unauthorized(ex);
|
||||
var head = path.pop();
|
||||
return switch (head) {
|
||||
case Path.CLONE -> postClone(user.get(),ex);
|
||||
case Path.ITEM -> postItem(user.get(), ex);
|
||||
case LIST -> postItemList(user.get(), path, ex);
|
||||
case Path.LOCATION -> postLocation(user.get(),ex);
|
||||
@@ -285,7 +287,7 @@ public class StockModule extends BaseHandler implements StockService {
|
||||
var json = json(ex);
|
||||
if (!(json.get(ID) instanceof Number id)) throw missingField(ID);
|
||||
json.remove(ID);
|
||||
|
||||
LOG.log(WARNING,"Missing permission check in StockModule.patchItem()!");
|
||||
var item = stockDb.loadItem(id.longValue());
|
||||
item.patch(json);
|
||||
return sendContent(ex,stockDb.save(item));
|
||||
@@ -336,6 +338,21 @@ public class StockModule extends BaseHandler implements StockService {
|
||||
return sendContent(ex,location);
|
||||
}
|
||||
|
||||
private boolean postClone(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
var json = json(ex);
|
||||
if (!json.has(ID))throw missingField(ID);
|
||||
if (!(json.get(ID) instanceof Number num)) throw invalidField(ID,Text.NUMBER);
|
||||
long itemId = num.longValue();
|
||||
var item = stockDb.loadItem(itemId);
|
||||
stockDb.loadProperties(item);
|
||||
var location = item.location().resolve();
|
||||
var owner = location.owner().resolve();
|
||||
if (!assigned(owner,user)) throw forbidden("You are not allowed to add items to \"{location}\"!", Text.LOCATION,location.name());
|
||||
var newItem = new Item(0,owner,0,location,item.code(),item.name(),item.description());
|
||||
for (var property : item.properties()) newItem.properties().add(property);
|
||||
return sendContent(ex,stockDb.save(newItem));
|
||||
}
|
||||
|
||||
private boolean postItem(UmbrellaUser user, HttpExchange ex) throws IOException {
|
||||
var json = json(ex);
|
||||
if (!json.has(NAME) || !(json.get(NAME) instanceof String name)) throw missingField(NAME);
|
||||
@@ -395,6 +412,7 @@ public class StockModule extends BaseHandler implements StockService {
|
||||
if (!(itemData.get(ID) instanceof Number itemId)) throw missingField(ID);
|
||||
if (!(json.get("add_prop") instanceof JSONObject propData)) throw missingField("add_prop");
|
||||
if (!propData.has(VALUE)) throw missingField(VALUE);
|
||||
LOG.log(WARNING,"Missing permission check in StockModule.postProperty()!");
|
||||
var value = propData.get(VALUE);
|
||||
if (value == null) throw missingField(VALUE);
|
||||
|
||||
|
||||
@@ -476,6 +476,16 @@ table{
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.properties{
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.properties .clone{
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 40px;
|
||||
}
|
||||
|
||||
.version > a{
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user