Browse Source

implemented moving of locations

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
module/document
Stephan Richter 2 weeks ago
parent
commit
eafa7a5b5f
  1. 17
      core/src/main/java/de/srsoftware/umbrella/core/model/DbLocation.java
  2. 8
      frontend/src/routes/stock/Index.svelte
  3. 14
      stock/src/main/java/de/srsoftware/umbrella/stock/SqliteDb.java
  4. 2
      stock/src/main/java/de/srsoftware/umbrella/stock/StockModule.java

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

@ -6,7 +6,9 @@ import static de.srsoftware.umbrella.core.Constants.*; @@ -6,7 +6,9 @@ import static de.srsoftware.umbrella.core.Constants.*;
import de.srsoftware.umbrella.core.api.Owner;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class DbLocation extends Location {
private Owner owner;
@ -14,6 +16,7 @@ public class DbLocation extends Location { @@ -14,6 +16,7 @@ public class DbLocation extends Location {
private String name;
private String description;
private String relation; // when added to an item, this field describes the type of the relation
private Set<String> dirtyFields = new HashSet<>();
public DbLocation(long id, Owner owner, Long parentLocationId, String name, String description){
super(id);
@ -23,10 +26,23 @@ public class DbLocation extends Location { @@ -23,10 +26,23 @@ public class DbLocation extends Location {
this.description = description;
}
public DbLocation clear(){
dirtyFields.clear();
return this;
}
public String description() {
return description;
}
public boolean isDirty() {
return !dirtyFields.isEmpty();
}
public boolean isDirty(String field){
return dirtyFields.contains(field);
}
public String name() {
return name;
}
@ -45,6 +61,7 @@ public class DbLocation extends Location { @@ -45,6 +61,7 @@ public class DbLocation extends Location {
public DbLocation parent(DbLocation newParent) {
parentLocationId = newParent.id();
dirtyFields.add(PARENT_LOCATION_ID);
return this;
}

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

@ -60,7 +60,6 @@ @@ -60,7 +60,6 @@
}
async function move_dragged_to(new_loc){
console.log({move_dragged_to:JSON.parse(JSON.stringify(new_loc))});
const data = draggedItem ? { item : draggedItem.id, target: new_loc.id } : { location : draggedLocation.id, target: new_loc.id }
const url = api(draggedItem ? 'stock/move_item' : 'stock/move_location');
const res = await fetch(url,{
@ -71,6 +70,13 @@ @@ -71,6 +70,13 @@
if (res.ok){
yikes();
location = new_loc;
if (!draggedItem){
for (var owner of top_level){
if (owner.locations && dropNestedLocation(owner.locations,draggedLocation)) break;
}
}
draggedItem = null;
draggedLocation = null;
} else {
error(res);
}

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

@ -292,7 +292,7 @@ public class SqliteDb extends BaseDb implements StockDb { @@ -292,7 +292,7 @@ public class SqliteDb extends BaseDb implements StockDb {
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)
.values(location.owner().dbCode(),location.parent(),location.name(),location.description())
.execute(db).getGeneratedKeys();
long id = 0;
if (rs.next()) id = rs.getLong(1);
@ -303,7 +303,17 @@ public class SqliteDb extends BaseDb implements StockDb { @@ -303,7 +303,17 @@ public class SqliteDb extends BaseDb implements StockDb {
throw databaseException("Failed to save new location ({0})",location.name());
}
} else {
throw databaseException("Updating locations not implemented");
try {
update(TABLE_LOCATIONS)
.set(OWNER, PARENT_LOCATION_ID, NAME, DESCRIPTION)
.where(ID,equal(location.id()))
.prepare(db)
.apply(location.owner().dbCode(), location.parent(), location.name(), location.description())
.close();
return location.clear();
} catch (SQLException e){
throw databaseException("Updating location \"{0}\" not implemented",location.name());
}
}
}

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

@ -242,7 +242,7 @@ public class StockModule extends BaseHandler implements StockService { @@ -242,7 +242,7 @@ public class StockModule extends BaseHandler implements StockService {
var owner = location.owner().resolve();
if (!assigned(owner,user)) throw forbidden("You are not allowed to alter the location of \"{0}\"!",location.name());
var target = stockDb.loadLocation(locationId.longValue());
var target = stockDb.loadLocation(destLocationId.longValue());
var locOwner = target.resolve().owner().resolve();
if (!assigned(locOwner,user)) throw forbidden("You are not allowed to modify \"{0}\"!",target.name());

Loading…
Cancel
Save