improved car manager
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.1.3</version>
|
||||
<version>1.1.4</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -279,4 +279,11 @@ svg.disabled rect{
|
||||
|
||||
.cockpit .stop{
|
||||
min-width: 150px;
|
||||
}
|
||||
|
||||
fieldset.notes{
|
||||
min-width: 50%
|
||||
}
|
||||
fieldset.notes textarea{
|
||||
min-width: 100%;
|
||||
}
|
||||
@@ -100,6 +100,7 @@ new train : neuer Zug
|
||||
No : keine
|
||||
No free routes from {} : keine Route von {} frei
|
||||
NORTH : Norden
|
||||
{} now heading for {} : {} ist nun unterweg nach {}
|
||||
Occupied area\: : Belegte Abschnitte:
|
||||
Off : Aus
|
||||
On : An
|
||||
|
||||
@@ -56,6 +56,7 @@ public interface Constants {
|
||||
public static final String GITHUB_URL = "https://github.com/srsoftware-de/Web4Rail";
|
||||
public static final String ID = "id";
|
||||
public static final String NBSP = " ";
|
||||
public static final String NOTES = "notes";
|
||||
public static final String PORT = "port";
|
||||
public static final String TYPE = "type";
|
||||
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
|
||||
@@ -28,6 +28,7 @@ import de.srsoftware.web4rail.tags.Form;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
import de.srsoftware.web4rail.tags.Table;
|
||||
import de.srsoftware.web4rail.tags.TextArea;
|
||||
|
||||
public class Car extends BaseClass implements Comparable<Car>{
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(Car.class);
|
||||
@@ -47,6 +48,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
private Train train;
|
||||
protected Plan plan;
|
||||
protected int maxSpeed = 0;
|
||||
private String notes;
|
||||
|
||||
public Car(String name) {
|
||||
this(name,null);
|
||||
@@ -70,7 +72,9 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
|
||||
switch (params.get(ACTION)) {
|
||||
case ACTION_ADD:
|
||||
new Car(params.get(Car.NAME)).plan(plan);
|
||||
if (isSet(car)) {
|
||||
car.clone().plan(plan);
|
||||
} else new Car(params.get(Car.NAME)).plan(plan);
|
||||
return Car.manager();
|
||||
case ACTION_PROPS:
|
||||
return car == null ? Car.manager() : car.properties();
|
||||
@@ -81,6 +85,19 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
if (car instanceof Locomotive) return Locomotive.action(params,plan);
|
||||
return t("Unknown action: {}",params.get(ACTION));
|
||||
}
|
||||
|
||||
public Car clone() {
|
||||
Car clone = new Car(name);
|
||||
clone.maxSpeed = maxSpeed;
|
||||
clone.length = length;
|
||||
clone.tags = new HashSet<String>(tags);
|
||||
clone.notes = notes;
|
||||
return clone;
|
||||
}
|
||||
|
||||
private Button cloneButton() {
|
||||
return new Button(t("copy"),Map.of(REALM,REALM_CAR,ID,id(),ACTION,ACTION_ADD));
|
||||
}
|
||||
|
||||
public static Car get(Object id) {
|
||||
return isNull(id) ? null : cars.get(Integer.parseInt(""+id)); // try to get by id
|
||||
@@ -97,6 +114,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
json.put(NAME, name);
|
||||
json.put(LENGTH, length);
|
||||
if (maxSpeed != 0) json.put(MAX_SPEED, maxSpeed);
|
||||
if (isSet(notes) && !notes.isEmpty()) json.put(NOTES, notes);
|
||||
json.put(STOCK_ID, stockId);
|
||||
if (!tags.isEmpty()) json.put(TAGS, tags);
|
||||
return json;
|
||||
@@ -143,6 +161,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
if (json.has(ID)) id = json.getInt(ID);
|
||||
if (json.has(LENGTH)) length = json.getInt(LENGTH);
|
||||
if (json.has(MAX_SPEED)) maxSpeed = json.getInt(MAX_SPEED);
|
||||
if (json.has(NOTES)) notes = json.getString(NOTES);
|
||||
if (json.has(STOCK_ID)) stockId = json.getString(STOCK_ID);
|
||||
if (json.has(TAGS)) json.getJSONArray(TAGS).forEach(elem -> { tags.add(elem.toString()); });
|
||||
return this;
|
||||
@@ -153,8 +172,18 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
new Tag("h4").content(t("known cars")).addTo(win);
|
||||
new Tag("p").content(t("Click on a name to edit the entry.")).addTo(win);
|
||||
|
||||
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Max. Speed",speedUnit),t("Length"),t("Tags"));
|
||||
cars.values().stream().filter(car -> !(car instanceof Locomotive)).forEach(car -> table.addRow(car.stockId,car.maxSpeed == 0 ? "–":(car.maxSpeed+NBSP+speedUnit),car.link(),car.length,String.join(", ", car.tags())));
|
||||
Table table = new Table().addHead(t("Stock ID"),t("Name"),t("Max. Speed",speedUnit),t("Length"),t("Tags"),t("Actions"));
|
||||
cars.values()
|
||||
.stream()
|
||||
.filter(car -> !(car instanceof Locomotive))
|
||||
.forEach(car -> table.addRow(
|
||||
car.stockId,
|
||||
car.link(),
|
||||
car.maxSpeed == 0 ? "–":(car.maxSpeed+NBSP+speedUnit),
|
||||
car.length,
|
||||
String.join(", ", car.tags()),
|
||||
car.cloneButton()
|
||||
));
|
||||
table.addTo(win);
|
||||
|
||||
Form form = new Form("add-car-form");
|
||||
@@ -166,7 +195,7 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
fieldset.addTo(form).addTo(win);
|
||||
return win;
|
||||
}
|
||||
|
||||
|
||||
public int maxSpeed() {
|
||||
return maxSpeed;
|
||||
}
|
||||
@@ -196,6 +225,9 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
new Input(TAGS,String.join(", ", tags)).addTo(new Label(t("Tags")+NBSP)).addTo(fieldset);
|
||||
new Input(MAX_SPEED, maxSpeed).numeric().addTo(new Label(t("Maximum speed")+":"+NBSP)).content(NBSP+speedUnit).addTo(fieldset);
|
||||
fieldset.addTo(form);
|
||||
|
||||
fieldset = new Fieldset(t("Notes"));
|
||||
new TextArea(NOTES,notes).addTo(fieldset.clazz("notes")).addTo(form);
|
||||
return form;
|
||||
}
|
||||
|
||||
@@ -243,7 +275,8 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
}
|
||||
|
||||
public Car update(HashMap<String, String> params) {
|
||||
if (params.containsKey(NAME)) name = params.get(NAME);
|
||||
if (params.containsKey(NAME)) name = params.get(NAME).trim();
|
||||
if (params.containsKey(NOTES)) notes = params.get(NOTES).trim();
|
||||
if (params.containsKey(LENGTH)) length = Integer.parseInt(params.get(LENGTH));
|
||||
if (params.containsKey(MAX_SPEED)) maxSpeed = Integer.parseInt(params.get(MAX_SPEED));
|
||||
if (params.containsKey(STOCK_ID)) stockId = params.get(STOCK_ID);
|
||||
|
||||
29
src/main/java/de/srsoftware/web4rail/tags/TextArea.java
Normal file
29
src/main/java/de/srsoftware/web4rail/tags/TextArea.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package de.srsoftware.web4rail.tags;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
|
||||
public class TextArea extends Tag{
|
||||
|
||||
private static final long serialVersionUID = -330127933233033028L;
|
||||
public static final String NAME = "name";
|
||||
public static final String VALUE = "value";
|
||||
|
||||
public TextArea(String name) {
|
||||
this(name,"");
|
||||
}
|
||||
|
||||
public TextArea(String name, Object value) {
|
||||
super("textarea");
|
||||
attr("name", name);
|
||||
content(value == null?"":value.toString());
|
||||
}
|
||||
|
||||
public Tag hideIn(Tag form) {
|
||||
return this.attr("type", "hidden").addTo(form);
|
||||
}
|
||||
|
||||
public TextArea numeric() {
|
||||
attr("type","number");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user