Browse Source

preparing to delete locations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/document
Stephan Richter 2 weeks ago
parent
commit
59e6a7001d
  1. 10
      core/src/main/java/de/srsoftware/umbrella/core/model/DbLocation.java
  2. 21
      core/src/main/java/de/srsoftware/umbrella/core/model/Location.java
  3. 2
      frontend/src/routes/stock/Index.svelte
  4. 5
      frontend/src/routes/stock/Locations.svelte
  5. 20
      stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java
  6. 13
      stock/src/main/java/de/srsoftware/umbrella/stock/StockDb.java

10
core/src/main/java/de/srsoftware/umbrella/core/model/DbLocation.java

@ -50,11 +50,11 @@ public class DbLocation extends Location { @@ -50,11 +50,11 @@ public class DbLocation extends Location {
@Override
public Map<String, Object> toMap() {
return Map.of(
OWNER,owner.toMap(),
ID,id(),
NAME,name,
DESCRIPTION,description);
var map = super.toMap();
map.put(OWNER,owner.toMap());
map.put(NAME,name);
map.put(DESCRIPTION,description);
return map;
}
@Override

21
core/src/main/java/de/srsoftware/umbrella/core/model/Location.java

@ -9,16 +9,27 @@ import static java.text.MessageFormat.format; @@ -9,16 +9,27 @@ import static java.text.MessageFormat.format;
import de.srsoftware.tools.Mappable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
public class Location implements Mappable {
private final long id;
private long id;
public Location(long id){
this.id = id;
}
public long id(){
return id;
}
public <T extends Location> T id(long newValue){
id = newValue;
//noinspection unchecked
return (T) this;
}
public static Location of(ResultSet rs) throws SQLException {
return new Location(rs.getLong(LOCATION_ID));
}
@ -31,13 +42,11 @@ public class Location implements Mappable { @@ -31,13 +42,11 @@ public class Location implements Mappable {
return stockService().loadLocation(id());
}
public long id(){
return id;
}
@Override
public Map<String, Object> toMap() {
return Map.of(ID,id);
var map = new HashMap<String,Object>();
map.put(ID,id);
return map;
}
@Override

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

@ -102,7 +102,7 @@ @@ -102,7 +102,7 @@
{:then data}
<div class="items">
{#if location}
<h3>{location.name}</h3>
<h3>{location.name} <button class="symbol" title={t('delete_object',{object:t('location')})} onclick={e => deleteLocation(location)}></button></h3>
{/if}
<ItemList items={data?.items.sort((a,b) => a.code.localeCompare(b.code))} bind:selected={item} drag_start={item => draggedItem = item} />
</div>

5
frontend/src/routes/stock/Locations.svelte

@ -52,9 +52,11 @@ @@ -52,9 +52,11 @@
});
if (res.ok){
yikes;
const saved = await res.json();
locations.push(saved);
return true;
} else {
error(ok);
error(res);
return false;
}
}
@ -67,7 +69,6 @@ @@ -67,7 +69,6 @@
name: new_location_name,
parent: parent
}
console.log(JSON.parse(JSON.stringify(data)));
}
function show_loc_form(ev){

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

@ -276,6 +276,26 @@ public class SqliteDb extends BaseDb implements StockDb { @@ -276,6 +276,26 @@ public class SqliteDb extends BaseDb implements StockDb {
db.prepareStatement(format("ALTER TABLE {0} RENAME TO {1}","locations_temp",TABLE_LOCATIONS)).execute();
}
@Override
public Location save(DbLocation location) {
if (location.id() == 0) { // new location
try {
var rs = insertInto(TABLE_LOCATIONS,OWNER,PARENT_LOCATION_ID,NAME,DESCRIPTION)
.values(location.owner().dbCode(),location.parent(),location.name(),null)
.execute(db).getGeneratedKeys();
long id = 0;
if (rs.next()) id = rs.getLong(1);
rs.close();
if (id == 0) throw databaseException("Failed to save new location ({0})",location.name());
return location.id(id);
} catch (SQLException e){
throw databaseException("Failed to save new location ({0})",location.name());
}
} else {
throw databaseException("Updating locations not implemented");
}
}
@Override
public Item save(Item item) {
if (item.id() == 0){ // TODO

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

@ -6,14 +6,15 @@ import de.srsoftware.umbrella.core.model.Location; @@ -6,14 +6,15 @@ import de.srsoftware.umbrella.core.model.Location;
import java.util.Collection;
public interface StockDb {
Property addNewProperty(long itemId, String name, Object value, String unit);
Property addNewProperty(long itemId, String name, Object value, String unit);
Collection<DbLocation> listChildLocations(long parentId);
Collection<DbLocation> listCompanyLocations(Company company);
Collection<Item> listItemsAt(Location location);
Collection<Property> listProperties();
Collection<Item> listItemsAt(Location location);
Collection<Property> listProperties();
Collection<DbLocation> listUserLocations(UmbrellaUser userId);
Item loadItem(long id);
Item loadItem(long id);
DbLocation loadLocation(long locationId);
Item save(Item item);
Property setProperty(long itemId, long existingPropId, Object value);
Location save(DbLocation location);
Item save(Item item);
Property setProperty(long itemId, long existingPropId, Object value);
}

Loading…
Cancel
Save