preparing adding of actions
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>0.6.12</version>
|
<version>0.6.13</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>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
public interface Constants {
|
public interface Constants {
|
||||||
public static final String ACTION = "action";
|
public static final String ACTION = "action";
|
||||||
public static final String ACTION_ADD = "add";
|
public static final String ACTION_ADD = "add";
|
||||||
|
public static final String ACTION_ADD_ACTION = "add_action";
|
||||||
public static final String ACTION_ANALYZE = "analyze";
|
public static final String ACTION_ANALYZE = "analyze";
|
||||||
public static final String ACTION_AUTO = "auto";
|
public static final String ACTION_AUTO = "auto";
|
||||||
public static final String ACTION_CLICK = "click";
|
public static final String ACTION_CLICK = "click";
|
||||||
|
|||||||
@@ -407,6 +407,8 @@ public class Plan implements Constants{
|
|||||||
Route route = route(Integer.parseInt(params.get(ID)));
|
Route route = route(Integer.parseInt(params.get(ID)));
|
||||||
if (route == null) return t("Unknown route: {}",params.get(ID));
|
if (route == null) return t("Unknown route: {}",params.get(ID));
|
||||||
switch (params.get(ACTION)) {
|
switch (params.get(ACTION)) {
|
||||||
|
case ACTION_ADD_ACTION:
|
||||||
|
return route.addActionForm(params);
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return route.properties();
|
return route.properties();
|
||||||
case ACTION_UPDATE:
|
case ACTION_UPDATE:
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import de.srsoftware.web4rail.actions.FinishRoute;
|
|||||||
import de.srsoftware.web4rail.actions.SetSignalsToStop;
|
import de.srsoftware.web4rail.actions.SetSignalsToStop;
|
||||||
import de.srsoftware.web4rail.actions.SpeedReduction;
|
import de.srsoftware.web4rail.actions.SpeedReduction;
|
||||||
import de.srsoftware.web4rail.moving.Train;
|
import de.srsoftware.web4rail.moving.Train;
|
||||||
|
import de.srsoftware.web4rail.tags.Button;
|
||||||
import de.srsoftware.web4rail.tags.Form;
|
import de.srsoftware.web4rail.tags.Form;
|
||||||
import de.srsoftware.web4rail.tags.Input;
|
import de.srsoftware.web4rail.tags.Input;
|
||||||
import de.srsoftware.web4rail.tiles.Block;
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
@@ -55,12 +56,15 @@ public class Route implements Constants{
|
|||||||
public Train train;
|
public Train train;
|
||||||
private Block startBlock = null,endBlock;
|
private Block startBlock = null,endBlock;
|
||||||
private static final String START_DIRECTION = "direction_start";
|
private static final String START_DIRECTION = "direction_start";
|
||||||
public Direction startDirection;
|
|
||||||
private static final String END_DIRECTION = "direction_end";
|
private static final String END_DIRECTION = "direction_end";
|
||||||
|
|
||||||
|
public Direction startDirection;
|
||||||
|
private Direction endDirection;
|
||||||
|
private Plan plan;
|
||||||
|
|
||||||
private static final String TRIGGER = "trigger";
|
private static final String TRIGGER = "trigger";
|
||||||
private static final String ACTIONS = "actions";
|
private static final String ACTIONS = "actions";
|
||||||
private static final String ID = "id";
|
private static final String CONTACT = "contact";
|
||||||
private Direction endDirection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route wurde von Zug betreten
|
* Route wurde von Zug betreten
|
||||||
@@ -96,6 +100,75 @@ public class Route implements Constants{
|
|||||||
actions.add(action);
|
actions.add(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object addActionForm(HashMap<String, String> params) {
|
||||||
|
String contactId = params.get(CONTACT);
|
||||||
|
Tile tag = plan.get(contactId, false);
|
||||||
|
if (!(tag instanceof Contact)) return t("No contact id passed to request!");
|
||||||
|
Contact contact = (Contact) tag;
|
||||||
|
Window win = new Window("add-action-form", t("Add action to contact on route"));
|
||||||
|
new Tag("div").content("Route: "+this).addTo(win);
|
||||||
|
new Tag("div").content("Contact: "+contact).addTo(win);
|
||||||
|
return win;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addBasicPropertiesTo(Window win) {
|
||||||
|
new Tag("h4").content(t("Origin and destination")).addTo(win);
|
||||||
|
Tag list = new Tag("ul");
|
||||||
|
Plan.addLink(startBlock, t("Origin: {} to {}",startBlock.name,startDirection), list);
|
||||||
|
Plan.addLink(endBlock, t("Destination: {} from {}",endBlock.name,endDirection), list);
|
||||||
|
list.addTo(win);
|
||||||
|
|
||||||
|
if (!signals.isEmpty()) {
|
||||||
|
new Tag("h4").content(t("Signals")).addTo(win);
|
||||||
|
list = new Tag("ul");
|
||||||
|
for (Signal s : signals) Plan.addLink(s,s.toString(),list);
|
||||||
|
list.addTo(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addContactsTo(Window win) {
|
||||||
|
if (!contacts.isEmpty()) {
|
||||||
|
new Tag("h4").content(t("Contacts and actions")).addTo(win);
|
||||||
|
Tag list = new Tag("ul");
|
||||||
|
for (Contact c : contacts) {
|
||||||
|
Tag link = Plan.addLink(c,c.toString(),list);
|
||||||
|
JSONObject json = new JSONObject(Map.of(
|
||||||
|
REALM,REALM_ROUTE,
|
||||||
|
ID,id,
|
||||||
|
ACTION,ACTION_ADD_ACTION,
|
||||||
|
CONTACT,c.id()));
|
||||||
|
new Button(t("add action"),json).addTo(link);
|
||||||
|
Vector<Action> actions = triggers.get(c.trigger());
|
||||||
|
if (actions != null && !actions.isEmpty()) {
|
||||||
|
Tag ul = new Tag("ul");
|
||||||
|
for (Action action : actions) {
|
||||||
|
Tag act = new Tag("li").content(action.toString());
|
||||||
|
new Button("↑").addTo(act);
|
||||||
|
new Button("↓").addTo(act);
|
||||||
|
new Button("-").addTo(act);
|
||||||
|
act.addTo(ul);
|
||||||
|
}
|
||||||
|
ul.addTo(link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.addTo(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addFormTo(Window win) {
|
||||||
|
Form form = new Form();
|
||||||
|
new Input(ACTION, ACTION_UPDATE).hideIn(form);
|
||||||
|
new Input(REALM,REALM_ROUTE).hideIn(form);
|
||||||
|
new Input(ID,id()).hideIn(form);
|
||||||
|
|
||||||
|
Tag label = new Tag("label").content(t("name:"));
|
||||||
|
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name()).addTo(label);
|
||||||
|
label.addTo(form);
|
||||||
|
|
||||||
|
new Tag("button").attr("type", "submit").content(t("save")).addTo(form);
|
||||||
|
form.addTo(win);
|
||||||
|
}
|
||||||
|
|
||||||
void addSignal(Signal signal) {
|
void addSignal(Signal signal) {
|
||||||
signals.add(signal);
|
signals.add(signal);
|
||||||
}
|
}
|
||||||
@@ -104,6 +177,18 @@ public class Route implements Constants{
|
|||||||
turnouts.put(t, s);
|
turnouts.put(t, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addTurnoutsTo(Window win) {
|
||||||
|
if (!turnouts.isEmpty()) {
|
||||||
|
new Tag("h4").content(t("Turnouts")).addTo(win);
|
||||||
|
Tag list = new Tag("ul");
|
||||||
|
for (Entry<Turnout, State> entry : turnouts.entrySet()) {
|
||||||
|
Turnout turnout = entry.getKey();
|
||||||
|
Plan.addLink(turnout, turnout+": "+entry.getValue(), list);
|
||||||
|
}
|
||||||
|
list.addTo(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected Route clone() {
|
protected Route clone() {
|
||||||
Route clone = new Route();
|
Route clone = new Route();
|
||||||
clone.startBlock = startBlock;
|
clone.startBlock = startBlock;
|
||||||
@@ -233,6 +318,7 @@ public class Route implements Constants{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Route load(JSONObject json,Plan plan) {
|
private Route load(JSONObject json,Plan plan) {
|
||||||
|
this.plan = plan;
|
||||||
if (json.has(ID)) id = json.getInt(ID);
|
if (json.has(ID)) id = json.getInt(ID);
|
||||||
JSONArray pathIds = json.getJSONArray(PATH);
|
JSONArray pathIds = json.getJSONArray(PATH);
|
||||||
startDirection = Direction.valueOf(json.getString(START_DIRECTION));
|
startDirection = Direction.valueOf(json.getString(START_DIRECTION));
|
||||||
@@ -336,66 +422,14 @@ public class Route implements Constants{
|
|||||||
|
|
||||||
public Window properties() {
|
public Window properties() {
|
||||||
Window win = new Window("route-properties",t("Properties of {}",this));
|
Window win = new Window("route-properties",t("Properties of {}",this));
|
||||||
|
addFormTo(win);
|
||||||
new Tag("h4").content(t("Origin and destination")).addTo(win);
|
addBasicPropertiesTo(win);
|
||||||
Tag list = new Tag("ul");
|
addTurnoutsTo(win);
|
||||||
Plan.addLink(startBlock, t("Origin: {} to {}",startBlock.name,startDirection), list);
|
addContactsTo(win);
|
||||||
Plan.addLink(endBlock, t("Destination: {} from {}",endBlock.name,endDirection), list);
|
|
||||||
list.addTo(win);
|
|
||||||
|
|
||||||
|
|
||||||
if (!signals.isEmpty()) {
|
|
||||||
new Tag("h4").content(t("Signals")).addTo(win);
|
|
||||||
list = new Tag("ul");
|
|
||||||
for (Signal s : signals) Plan.addLink(s,s.toString(),list);
|
|
||||||
list.addTo(win);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!contacts.isEmpty()) {
|
|
||||||
new Tag("h4").content(t("Contacts and actions")).addTo(win);
|
|
||||||
list = new Tag("ul");
|
|
||||||
for (Contact c : contacts) {
|
|
||||||
Tag link = Plan.addLink(c,c.toString(),list);
|
|
||||||
Vector<Action> actions = triggers.get(c.trigger());
|
|
||||||
if (actions != null && !actions.isEmpty()) {
|
|
||||||
Tag ul = new Tag("ul");
|
|
||||||
for (Action action : actions) new Tag("li").content(action.toString()).addTo(ul);
|
|
||||||
ul.addTo(link);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
list.addTo(win);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!turnouts.isEmpty()) {
|
|
||||||
new Tag("h4").content(t("Turnouts")).addTo(win);
|
|
||||||
list = new Tag("ul");
|
|
||||||
for (Entry<Turnout, State> entry : turnouts.entrySet()) {
|
|
||||||
Turnout turnout = entry.getKey();
|
|
||||||
Plan.addLink(turnout, turnout+": "+entry.getValue(), list);
|
|
||||||
}
|
|
||||||
list.addTo(win);
|
|
||||||
}
|
|
||||||
|
|
||||||
Tag form = propForm();
|
|
||||||
new Tag("button").attr("type", "submit").content(t("save")).addTo(form);
|
|
||||||
form.addTo(win);
|
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag propForm() {
|
|
||||||
Form form = new Form();
|
|
||||||
new Input(ACTION, ACTION_UPDATE).hideIn(form);
|
|
||||||
new Input(REALM,REALM_ROUTE).hideIn(form);
|
|
||||||
new Input(ID,id()).hideIn(form);
|
|
||||||
|
|
||||||
Tag label = new Tag("label").content(t("name:"));
|
|
||||||
new Tag("input").attr("type", "text").attr(NAME,"name").attr("value", name()).addTo(label);
|
|
||||||
label.addTo(form);
|
|
||||||
|
|
||||||
return form;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void saveAll(Collection<Route> routes, String filename) throws IOException {
|
public static void saveAll(Collection<Route> routes, String filename) throws IOException {
|
||||||
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
BufferedWriter file = new BufferedWriter(new FileWriter(filename));
|
||||||
for (Route route : routes) file.write(route.json()+"\n");
|
for (Route route : routes) file.write(route.json()+"\n");
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.srsoftware.web4rail.tags;
|
package de.srsoftware.web4rail.tags;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
|
|
||||||
public class Button extends Tag {
|
public class Button extends Tag {
|
||||||
@@ -16,5 +18,9 @@ public class Button extends Tag {
|
|||||||
super("button");
|
super("button");
|
||||||
attr("onclick",action).content(text);
|
attr("onclick",action).content(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Button(String text,JSONObject json) {
|
||||||
|
super("button");
|
||||||
|
attr("onclick","request("+(json.toString().replace("\"", "'"))+")").content(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user