Browse Source

implemented deletion of item properties

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/stock.v2
Stephan Richter 3 weeks ago
parent
commit
21c5a72349
  1. 9
      frontend/src/routes/stock/ItemProps.svelte
  2. 6
      stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java
  3. 3
      stock/src/main/java/de/srsoftware/umbrella/stock/StockDb.java
  4. 2
      stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

9
frontend/src/routes/stock/ItemProps.svelte

@ -19,7 +19,9 @@ @@ -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 @@ @@ -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 @@ -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>

6
stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java

@ -51,14 +51,18 @@ public class SqliteDb extends BaseDb implements StockDb { @@ -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);
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);

3
stock/src/main/java/de/srsoftware/umbrella/stock/StockDb.java

@ -6,7 +6,6 @@ import de.srsoftware.umbrella.core.model.*; @@ -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 { @@ -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);
}

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

@ -182,7 +182,7 @@ public class StockModule extends BaseHandler implements StockService { @@ -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!");

Loading…
Cancel
Save