implemented remval and re-ordering of route 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.7.1</version>
|
<version>0.7.2</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>
|
||||||
|
|||||||
@@ -411,6 +411,8 @@ public class Plan implements Constants{
|
|||||||
return route.addActionForm(params);
|
return route.addActionForm(params);
|
||||||
case ACTION_DROP:
|
case ACTION_DROP:
|
||||||
return route.dropAction(params);
|
return route.dropAction(params);
|
||||||
|
case ACTION_MOVE:
|
||||||
|
return route.moveAction(params);
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return route.properties();
|
return route.properties();
|
||||||
case ACTION_UPDATE:
|
case ACTION_UPDATE:
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class Route implements Constants{
|
|||||||
new Input(ACTION,ACTION_ADD_ACTION).hideIn(typeForm);
|
new Input(ACTION,ACTION_ADD_ACTION).hideIn(typeForm);
|
||||||
new Input(CONTACT,contact.id()).hideIn(typeForm);
|
new Input(CONTACT,contact.id()).hideIn(typeForm);
|
||||||
Select select = new Select(TYPE);
|
Select select = new Select(TYPE);
|
||||||
List<Class<? extends Action>> classes = List.of(SpeedReduction.class);
|
List<Class<? extends Action>> classes = List.of(SpeedReduction.class,SetSignalsToStop.class,FinishRoute.class);
|
||||||
for (Class<? extends Action> clazz : classes) select.addOption(clazz.getSimpleName());
|
for (Class<? extends Action> clazz : classes) select.addOption(clazz.getSimpleName());
|
||||||
select.addTo(new Label("Action type:")).addTo(typeForm);
|
select.addTo(new Label("Action type:")).addTo(typeForm);
|
||||||
return new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(typeForm);
|
return new Button(t("Create action"),"return submitForm('"+formId+"');").addTo(typeForm);
|
||||||
@@ -116,24 +116,6 @@ public class Route implements Constants{
|
|||||||
actions.add(action);
|
actions.add(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object dropAction(HashMap<String, String> params) {
|
|
||||||
String action_id = params.get(ACTION_ID);
|
|
||||||
if (action_id == null) return t("No action id passed to request!");
|
|
||||||
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;
|
|
||||||
Vector<Action> actions = triggers.get(contact.trigger());
|
|
||||||
|
|
||||||
for (int i=0; i<actions.size(); i++) {
|
|
||||||
if (actions.elementAt(i).toString().equals(action_id)) {
|
|
||||||
actions.remove(i);
|
|
||||||
return t("removed {} from contact {}.",action_id,contactId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return t("No action \"{}\" assigned with {}!",action_id,contact);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object addActionForm(HashMap<String, String> params) {
|
public Object addActionForm(HashMap<String, String> params) {
|
||||||
String contactId = params.get(CONTACT);
|
String contactId = params.get(CONTACT);
|
||||||
Tile tag = plan.get(contactId, false);
|
Tile tag = plan.get(contactId, false);
|
||||||
@@ -146,8 +128,16 @@ public class Route implements Constants{
|
|||||||
String type = params.get(TYPE);
|
String type = params.get(TYPE);
|
||||||
if (type == null) return (actionTypeForm(contact).addTo(win));
|
if (type == null) return (actionTypeForm(contact).addTo(win));
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
case "FinishRoute":
|
||||||
|
addAction(contact.trigger(),new FinishRoute(id()));
|
||||||
|
plan.stream("Action added!");
|
||||||
|
return properties();
|
||||||
case "SpeedReduction":
|
case "SpeedReduction":
|
||||||
return SpeedReduction.propForm(params,this,contact);
|
return SpeedReduction.propForm(params,this,contact);
|
||||||
|
case "SetSignalsToStop":
|
||||||
|
addAction(contact.trigger(),new SetSignalsToStop(id()));
|
||||||
|
plan.stream("Action added!");
|
||||||
|
return properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
@@ -183,14 +173,19 @@ public class Route implements Constants{
|
|||||||
Vector<Action> actions = triggers.get(c.trigger());
|
Vector<Action> actions = triggers.get(c.trigger());
|
||||||
if (actions != null && !actions.isEmpty()) {
|
if (actions != null && !actions.isEmpty()) {
|
||||||
Tag ul = new Tag("ul");
|
Tag ul = new Tag("ul");
|
||||||
|
boolean first = true;
|
||||||
for (Action action : actions) {
|
for (Action action : actions) {
|
||||||
Tag act = new Tag("li").content(action.toString());
|
|
||||||
new Button("↑").addTo(act);
|
|
||||||
new Button("↓").addTo(act);
|
|
||||||
json.put(ACTION, ACTION_DROP);
|
|
||||||
json.put(ACTION_ID, action.toString());
|
json.put(ACTION_ID, action.toString());
|
||||||
|
|
||||||
|
Tag act = new Tag("li").content(action.toString());
|
||||||
|
if (!first) {
|
||||||
|
json.put(ACTION, ACTION_MOVE);
|
||||||
|
new Button("↑",json).addTo(act);
|
||||||
|
}
|
||||||
|
json.put(ACTION, ACTION_DROP);
|
||||||
new Button("-",json).addTo(act);
|
new Button("-",json).addTo(act);
|
||||||
act.addTo(ul);
|
act.addTo(ul);
|
||||||
|
first = false;
|
||||||
}
|
}
|
||||||
ul.addTo(link);
|
ul.addTo(link);
|
||||||
}
|
}
|
||||||
@@ -282,6 +277,26 @@ public class Route implements Constants{
|
|||||||
return new Vector<>(contacts);
|
return new Vector<>(contacts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object dropAction(HashMap<String, String> params) {
|
||||||
|
String actionId = params.get(ACTION_ID);
|
||||||
|
if (actionId == null) return t("No action id passed to request!");
|
||||||
|
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;
|
||||||
|
Vector<Action> actions = triggers.get(contact.trigger());
|
||||||
|
|
||||||
|
for (int i=0; i<actions.size(); i++) {
|
||||||
|
if (actions.elementAt(i).toString().equals(actionId)) {
|
||||||
|
actions.remove(i);
|
||||||
|
plan.stream(t("removed {}.",actionId));
|
||||||
|
return properties();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plan.stream(t("No action \"{}\" assigned with {}!",actionId,contact));
|
||||||
|
return properties();
|
||||||
|
}
|
||||||
|
|
||||||
public void finish() throws IOException {
|
public void finish() throws IOException {
|
||||||
startBlock.train(null);
|
startBlock.train(null);
|
||||||
train.route = null;
|
train.route = null;
|
||||||
@@ -437,6 +452,26 @@ public class Route implements Constants{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object moveAction(HashMap<String, String> params) {
|
||||||
|
String action_id = params.get(ACTION_ID);
|
||||||
|
if (action_id == null) return t("No action id passed to request!");
|
||||||
|
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;
|
||||||
|
Vector<Action> actions = triggers.get(contact.trigger());
|
||||||
|
|
||||||
|
for (int i=1; i<actions.size(); i++) {
|
||||||
|
if (actions.elementAt(i).toString().equals(action_id)) {
|
||||||
|
Action action = actions.remove(i);
|
||||||
|
actions.insertElementAt(action, i-1);
|
||||||
|
return properties();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
plan.stream(t("No action \"{}\" assigned with {}!",action_id,contact));
|
||||||
|
return properties();
|
||||||
|
}
|
||||||
|
|
||||||
public List<Route> multiply(int size) {
|
public List<Route> multiply(int size) {
|
||||||
Vector<Route> routes = new Vector<Route>();
|
Vector<Route> routes = new Vector<Route>();
|
||||||
for (int i=0; i<size; i++) routes.add(i==0 ? this : this.clone());
|
for (int i=0; i<size; i++) routes.add(i==0 ? this : this.clone());
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class SpeedReduction extends RouteAction implements Constants{
|
|||||||
if (error == null) {
|
if (error == null) {
|
||||||
route.addAction(contact.trigger(),new SpeedReduction(route.id(), s));
|
route.addAction(contact.trigger(),new SpeedReduction(route.id(), s));
|
||||||
contact.plan().stream("Action added!");
|
contact.plan().stream("Action added!");
|
||||||
return null;
|
return route.properties();
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
error = t("Not a valid number!");
|
error = t("Not a valid number!");
|
||||||
|
|||||||
Reference in New Issue
Block a user