implemented deletion of item properties
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -19,7 +19,9 @@
|
||||
return a.name.localeCompare(b.name);
|
||||
}
|
||||
|
||||
async function onclick(){
|
||||
async function onsubmit(ev){
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
const url = api('stock/property');
|
||||
const data = {
|
||||
item : {
|
||||
@@ -40,6 +42,7 @@
|
||||
item.properties.push(prop);
|
||||
yikes();
|
||||
} else error(res);
|
||||
return false;
|
||||
}
|
||||
|
||||
async function patch(key,newVal){
|
||||
@@ -95,13 +98,15 @@ Code: <LineEditor type="span" editable={true} value={item.code} onSet={v => patc
|
||||
{/if}
|
||||
</td>
|
||||
<td>
|
||||
<form {onsubmit}>
|
||||
<input type="text" placeholder="value" bind:value={add_prop.value} />
|
||||
{#if !add_prop.existing_prop_id}
|
||||
<input type="text" placeholder="unit" bind:value={add_prop.new_prop.unit} />
|
||||
{:else}
|
||||
{properties.filter(p => p.id == add_prop.existing_prop_id)[0].unit}
|
||||
{/if}
|
||||
<button {onclick}>{t('save')}</button>
|
||||
<button>{t('save')}</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@@ -51,14 +51,18 @@ public class SqliteDb extends BaseDb implements StockDb {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Property addProperty(long ownerId, long itemId, long existingPropId, Object value) {
|
||||
public Property setProperty(long ownerId, long itemId, long existingPropId, Object value) {
|
||||
try {
|
||||
Property prop = null;
|
||||
var rs = select(ALL).from(TABLE_PROPERTIES).where(ID,equal(existingPropId)).exec(db);
|
||||
if (rs.next()) prop = Property.of(rs);
|
||||
rs.close();
|
||||
if (prop == null) throw databaseException("Failed to add new property to item {0}",itemId);
|
||||
replaceInto(TABLE_ITEM_PROPERTIES,OWNER,ITEM_ID,PROPERTY_ID,VALUE).values(ownerId,itemId,existingPropId,value).execute(db);
|
||||
if ("".equals(value)){
|
||||
delete().from(TABLE_ITEM_PROPERTIES).where(OWNER,equal(ownerId)).where(ITEM_ID,equal(itemId)).where(PROPERTY_ID,equal(existingPropId)).execute(db);
|
||||
} else {
|
||||
replaceInto(TABLE_ITEM_PROPERTIES,OWNER,ITEM_ID,PROPERTY_ID,VALUE).values(ownerId,itemId,existingPropId,value).execute(db);
|
||||
}
|
||||
return prop.value(value);
|
||||
} catch (SQLException e) {
|
||||
throw databaseException("Failed to add new property to item {0}",itemId);
|
||||
|
||||
@@ -6,7 +6,6 @@ import de.srsoftware.umbrella.core.model.*;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface StockDb {
|
||||
Property addProperty(long ownerId, long itemId, long existingPropId, Object value);
|
||||
Property addNewProperty(long ownerId, long itemId, String name, Object value, String unit);
|
||||
Collection<Location> listChildLocations(long parentId);
|
||||
Collection<Location> listCompanyLocations(Company company);
|
||||
@@ -14,6 +13,6 @@ public interface StockDb {
|
||||
Collection<Property> listProperties();
|
||||
Collection<Location> listUserLocations(UmbrellaUser userId);
|
||||
Item loadItem(Mappable owner, long itemId);
|
||||
|
||||
Item save(Item item);
|
||||
Property setProperty(long ownerId, long itemId, long existingPropId, Object value);
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class StockModule extends BaseHandler implements StockService {
|
||||
|
||||
Property property = null;
|
||||
if (propData.get("existing_prop_id") instanceof Number existingPropId && existingPropId.longValue() != 0L){
|
||||
property = stockDb.addProperty(ownerId,itemId.longValue(),existingPropId.longValue(),value);
|
||||
property = stockDb.setProperty(ownerId,itemId.longValue(),existingPropId.longValue(),value);
|
||||
} else {
|
||||
if (!(propData.get("new_prop") instanceof JSONObject newProp)) throw unprocessable("data must contain either add_prop.existing_prop_id or add_prop.new_prop!");
|
||||
if (!(newProp.get(NAME) instanceof String name) || name.isBlank()) throw unprocessable("data.add_prop.new_prop does not contain name!");
|
||||
|
||||
Reference in New Issue
Block a user