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. 8
      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 @@
return a.name.localeCompare(b.name); return a.name.localeCompare(b.name);
} }
async function onclick(){ async function onsubmit(ev){
ev.preventDefault();
ev.stopPropagation();
const url = api('stock/property'); const url = api('stock/property');
const data = { const data = {
item : { item : {
@ -40,6 +42,7 @@
item.properties.push(prop); item.properties.push(prop);
yikes(); yikes();
} else error(res); } else error(res);
return false;
} }
async function patch(key,newVal){ async function patch(key,newVal){
@ -95,13 +98,15 @@ Code: <LineEditor type="span" editable={true} value={item.code} onSet={v => patc
{/if} {/if}
</td> </td>
<td> <td>
<form {onsubmit}>
<input type="text" placeholder="value" bind:value={add_prop.value} /> <input type="text" placeholder="value" bind:value={add_prop.value} />
{#if !add_prop.existing_prop_id} {#if !add_prop.existing_prop_id}
<input type="text" placeholder="unit" bind:value={add_prop.new_prop.unit} /> <input type="text" placeholder="unit" bind:value={add_prop.new_prop.unit} />
{:else} {:else}
{properties.filter(p => p.id == add_prop.existing_prop_id)[0].unit} {properties.filter(p => p.id == add_prop.existing_prop_id)[0].unit}
{/if} {/if}
<button {onclick}>{t('save')}</button> <button>{t('save')}</button>
</form>
</td> </td>
</tr> </tr>
</tbody> </tbody>

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

@ -51,14 +51,18 @@ public class SqliteDb extends BaseDb implements StockDb {
} }
@Override @Override
public Property addProperty(long ownerId, long itemId, long existingPropId, Object value) { public Property setProperty(long ownerId, long itemId, long existingPropId, Object value) {
try { try {
Property prop = null; Property prop = null;
var rs = select(ALL).from(TABLE_PROPERTIES).where(ID,equal(existingPropId)).exec(db); var rs = select(ALL).from(TABLE_PROPERTIES).where(ID,equal(existingPropId)).exec(db);
if (rs.next()) prop = Property.of(rs); if (rs.next()) prop = Property.of(rs);
rs.close(); rs.close();
if (prop == null) throw databaseException("Failed to add new property to item {0}",itemId); 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); return prop.value(value);
} catch (SQLException e) { } catch (SQLException e) {
throw databaseException("Failed to add new property to item {0}",itemId); 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.*;
import java.util.Collection; import java.util.Collection;
public interface StockDb { 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); Property addNewProperty(long ownerId, long itemId, String name, Object value, String unit);
Collection<Location> listChildLocations(long parentId); Collection<Location> listChildLocations(long parentId);
Collection<Location> listCompanyLocations(Company company); Collection<Location> listCompanyLocations(Company company);
@ -14,6 +13,6 @@ public interface StockDb {
Collection<Property> listProperties(); Collection<Property> listProperties();
Collection<Location> listUserLocations(UmbrellaUser userId); Collection<Location> listUserLocations(UmbrellaUser userId);
Item loadItem(Mappable owner, long itemId); Item loadItem(Mappable owner, long itemId);
Item save(Item item); 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 {
Property property = null; Property property = null;
if (propData.get("existing_prop_id") instanceof Number existingPropId && existingPropId.longValue() != 0L){ 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 { } 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 (!(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!"); if (!(newProp.get(NAME) instanceof String name) || name.isBlank()) throw unprocessable("data.add_prop.new_prop does not contain name!");

Loading…
Cancel
Save