improved history for cars
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>de.srsoftware</groupId>
|
<groupId>de.srsoftware</groupId>
|
||||||
<artifactId>web4rail</artifactId>
|
<artifactId>web4rail</artifactId>
|
||||||
<version>1.4.26</version>
|
<version>1.4.27</version>
|
||||||
<name>Web4Rail</name>
|
<name>Web4Rail</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Java Model Railway Control</description>
|
<description>Java Model Railway Control</description>
|
||||||
|
|||||||
@@ -435,3 +435,7 @@ svg.Block text{
|
|||||||
.Switch.on rect.enabled{
|
.Switch.on rect.enabled{
|
||||||
fill: forestgreen;
|
fill: forestgreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#history table td:nth-child(2) {
|
||||||
|
padding-left: 30px;
|
||||||
|
}
|
||||||
|
|||||||
@@ -531,7 +531,7 @@ public abstract class BaseClass implements Constants{
|
|||||||
new Button(t("Apply"),customForm).addTo(customForm).addTo(customFields);
|
new Button(t("Apply"),customForm).addTo(customForm).addTo(customFields);
|
||||||
customFields.addTo(win);
|
customFields.addTo(win);
|
||||||
|
|
||||||
Fieldset history = new Fieldset(t("History"));
|
Fieldset history = new Fieldset(t("History")).id("history");
|
||||||
|
|
||||||
Form form = new Form("add-history-entry");
|
Form form = new Form("add-history-entry");
|
||||||
new Input(REALM, REALM_HISTORY).hideIn(form);
|
new Input(REALM, REALM_HISTORY).hideIn(form);
|
||||||
@@ -542,8 +542,11 @@ public abstract class BaseClass implements Constants{
|
|||||||
form.addTo(history);
|
form.addTo(history);
|
||||||
|
|
||||||
table = new Table();
|
table = new Table();
|
||||||
table.addHead(t("Date/Time"),t("Event"));
|
table.addHead(t("Date/Time"),t("Event"),t("Actions"));
|
||||||
for (LogEntry entry : History.getFor(this)) table.addRow(new SimpleDateFormat("YYYY-dd-MM HH:mm").format(entry.date()),entry.getText());
|
for (LogEntry entry : History.getFor(this)) table.addRow(
|
||||||
|
new SimpleDateFormat("YYYY-dd-MM HH:mm").format(entry.date()),
|
||||||
|
entry.getText(),
|
||||||
|
button(t("delete"),Map.of(REALM,REALM_HISTORY,ACTION,ACTION_DROP,TIME,""+entry.getTime())));
|
||||||
table.addTo(history).addTo(win);
|
table.addTo(history).addTo(win);
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
|
|||||||
@@ -53,14 +53,14 @@ public interface Constants {
|
|||||||
public static final String REALM_PLAN = "plan";
|
public static final String REALM_PLAN = "plan";
|
||||||
public static final String REALM_TRAIN = "train";
|
public static final String REALM_TRAIN = "train";
|
||||||
|
|
||||||
public static final String ASSIGN = "assign";
|
public static final String ASSIGN = "assign";
|
||||||
public static final String BLOCK = "block";
|
public static final String BLOCK = "block";
|
||||||
public static final String COL = ": ";
|
public static final String COL = ": ";
|
||||||
public static final String CONTACT = "contact";
|
public static final String CONTACT = "contact";
|
||||||
public static final String CONTEXT = "context";
|
public static final String CONTEXT = "context";
|
||||||
public static final String DEFAULT_SPEED_UNIT = "km/h";
|
public static final String DEFAULT_SPEED_UNIT = "km/h";
|
||||||
public static final String DEFAULT_LENGTH_UNIT = "mm";
|
public static final String DEFAULT_LENGTH_UNIT = "mm";
|
||||||
public static final String DESTINATION = "destination";
|
public static final String DESTINATION = "destination";
|
||||||
public static final String DISABLED = "disabled";
|
public static final String DISABLED = "disabled";
|
||||||
public static final String DIRECTION = "direction";
|
public static final String DIRECTION = "direction";
|
||||||
public static final String GITHUB_URL = "https://github.com/srsoftware-de/Web4Rail";
|
public static final String GITHUB_URL = "https://github.com/srsoftware-de/Web4Rail";
|
||||||
@@ -76,6 +76,7 @@ public interface Constants {
|
|||||||
public static final String RESERVED = "reserved";
|
public static final String RESERVED = "reserved";
|
||||||
public static final String ROUTE = "route";
|
public static final String ROUTE = "route";
|
||||||
public static final String STATE = "state";
|
public static final String STATE = "state";
|
||||||
|
public static final String TIME = "time";
|
||||||
public static final String TURNOUT = "turnout";
|
public static final String TURNOUT = "turnout";
|
||||||
public static final String TYPE = "type";
|
public static final String TYPE = "type";
|
||||||
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
public static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ public class History {
|
|||||||
public String getText() {
|
public String getText() {
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return date()+": "+text;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static LogEntry assign(LogEntry logEntry, BaseClass object) {
|
public static LogEntry assign(LogEntry logEntry, BaseClass object) {
|
||||||
@@ -47,21 +52,39 @@ public class History {
|
|||||||
return logEntry;
|
return logEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void dropEntry(BaseClass object,long time) {
|
||||||
|
Vector<LogEntry> list = log.get(object.id());
|
||||||
|
if (list == null) return;
|
||||||
|
for (int i=list.size(); i>0; i--) {
|
||||||
|
LogEntry entry = list.get(i-1);
|
||||||
|
if (entry.getTime() == time) list.remove(i-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Vector<LogEntry> getFor(BaseClass object){
|
public static Vector<LogEntry> getFor(BaseClass object){
|
||||||
Vector<LogEntry> list = log.get(object.id());
|
Vector<LogEntry> list = log.get(object.id());
|
||||||
return list != null ? list : new Vector<>();
|
return list != null ? list : new Vector<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object action(HashMap<String, String> params) {
|
public static Object action(HashMap<String, String> params) {
|
||||||
|
BaseClass object = BaseClass.get(Id.from(params));
|
||||||
switch (params.get(Constants.ACTION)) {
|
switch (params.get(Constants.ACTION)) {
|
||||||
case Constants.ACTION_ADD:
|
case Constants.ACTION_ADD:
|
||||||
BaseClass object = BaseClass.get(Id.from(params));
|
|
||||||
return object != null ? object.addLogEntry(params.get(Constants.NOTES)) : BaseClass.t("Unknown object!");
|
return object != null ? object.addLogEntry(params.get(Constants.NOTES)) : BaseClass.t("Unknown object!");
|
||||||
|
case Constants.ACTION_DROP:
|
||||||
|
if (BaseClass.isNull(object)) return BaseClass.t("Trying to delete log entry without specifing object!");
|
||||||
|
String err = null;
|
||||||
|
try {
|
||||||
|
long time = Long.parseLong(params.get(Constants.TIME));
|
||||||
|
dropEntry(object,time);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
err = BaseClass.t("Was not able to delete history entry!");
|
||||||
|
}
|
||||||
|
return object.properties(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return BaseClass.t("Unknown action: {}",params.get(Constants.ACTION));
|
String message = BaseClass.t("Unknown action: {}",params.get(Constants.ACTION));
|
||||||
|
return (BaseClass.isNull(object)) ? message : object.properties(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save(String filename) {
|
public static void save(String filename) {
|
||||||
|
|||||||
@@ -104,6 +104,11 @@ public class Car extends BaseClass implements Comparable<Car>{
|
|||||||
return t("Unknown action: {}",params.get(ACTION));
|
return t("Unknown action: {}",params.get(ACTION));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Window addLogEntry(String text) {
|
||||||
|
return super.addLogEntry(distance(distanceCounter)+": "+text);
|
||||||
|
}
|
||||||
|
|
||||||
public Object addTask(MaintnanceTask newTask) {
|
public Object addTask(MaintnanceTask newTask) {
|
||||||
if (isSet(newTask)) {
|
if (isSet(newTask)) {
|
||||||
tasks.add(newTask);
|
tasks.add(newTask);
|
||||||
|
|||||||
Reference in New Issue
Block a user