implemented removing ot routes
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.7</version>
|
<version>0.7.8</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>
|
||||||
|
|||||||
@@ -121,6 +121,7 @@ function moveTile(x,y){
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openRoute(id){
|
function openRoute(id){
|
||||||
|
console.log("openRoute("+id+")");
|
||||||
request({realm:'route',action:PROPS,id:id});
|
request({realm:'route',action:PROPS,id:id});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -381,10 +381,6 @@ public class Plan implements Constants{
|
|||||||
return controlUnit.queue(command);
|
return controlUnit.queue(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Route route(int routeId) {
|
|
||||||
return routes.get(routeId);
|
|
||||||
}
|
|
||||||
|
|
||||||
Route registerRoute(Route route) {
|
Route registerRoute(Route route) {
|
||||||
for (Tile tile: route.path()) tile.add(route);
|
for (Tile tile: route.path()) tile.add(route);
|
||||||
routes.put(route.id(), route);
|
routes.put(route.id(), route);
|
||||||
@@ -398,11 +394,24 @@ public class Plan implements Constants{
|
|||||||
for (int i=1; i<tile.height(); i++) remove_intern(tile.x, tile.y+i); // remove shadow tiles
|
for (int i=1; i<tile.height(); i++) remove_intern(tile.x, tile.y+i); // remove shadow tiles
|
||||||
if (tile != null) stream("remove "+tile.id());
|
if (tile != null) stream("remove "+tile.id());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remove(Route route) {
|
||||||
|
for (Tile tile : route.path()) tile.remove(route);
|
||||||
|
for (Train train : Train.list()) {
|
||||||
|
if (train.route == route) train.route = null;
|
||||||
|
}
|
||||||
|
routes.remove(route.id());
|
||||||
|
stream(t("Removed {}.",route));
|
||||||
|
}
|
||||||
|
|
||||||
private void remove_intern(int x, int y) {
|
private void remove_intern(int x, int y) {
|
||||||
LOG.debug("removed {} from tile list",tiles.remove(Tile.id(x, y)));
|
LOG.debug("removed {} from tile list",tiles.remove(Tile.id(x, y)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Route route(int routeId) {
|
||||||
|
return routes.get(routeId);
|
||||||
|
}
|
||||||
|
|
||||||
Object routeAction(HashMap<String, String> params) throws IOException {
|
Object routeAction(HashMap<String, String> params) throws IOException {
|
||||||
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));
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ public class Route implements Constants{
|
|||||||
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 ACTION_ID = "action_id";
|
private static final String ACTION_ID = "action_id";
|
||||||
|
private static final String TILE = Tile.class.getSimpleName();
|
||||||
|
|
||||||
private Tag actionTypeForm(Contact contact) {
|
private Tag actionTypeForm(Contact contact) {
|
||||||
String formId ="add-action-to-contact-"+contact.id();
|
String formId ="add-action-to-contact-"+contact.id();
|
||||||
@@ -291,10 +292,15 @@ public class Route implements Constants{
|
|||||||
public Vector<Contact> contacts() {
|
public Vector<Contact> contacts() {
|
||||||
return new Vector<>(contacts);
|
return new Vector<>(contacts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object dropAction(HashMap<String, String> params) {
|
public Object dropAction(HashMap<String, String> params) {
|
||||||
String actionId = params.get(ACTION_ID);
|
String actionId = params.get(ACTION_ID);
|
||||||
if (actionId == null) return t("No action id passed to request!");
|
if (actionId == null) {
|
||||||
|
plan.remove(this); // if id of an action is given: delete the action from the route. otherwise: delete the route
|
||||||
|
String tileId = params.get(TILE);
|
||||||
|
Tile tile = plan.get(tileId,false);
|
||||||
|
return tile.propMenu();
|
||||||
|
}
|
||||||
String contactId = params.get(CONTACT);
|
String contactId = params.get(CONTACT);
|
||||||
Tile tag = plan.get(contactId, false);
|
Tile tag = plan.get(contactId, false);
|
||||||
if (!(tag instanceof Contact)) return t("No contact id passed to request!");
|
if (!(tag instanceof Contact)) return t("No contact id passed to request!");
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ public class Button extends Tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Button(String text, Map<String, Object> props) {
|
public Button(String text, Map<String, Object> props) {
|
||||||
super("button");
|
this(text,"request("+(new JSONObject(props).toString().replace("\"", "'"))+")");
|
||||||
attr("onclick","request("+(new JSONObject(props).toString().replace("\"", "'"))+")").content(text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,15 +214,21 @@ public abstract class Tile implements Constants{
|
|||||||
|
|
||||||
if (!routes.isEmpty()) {
|
if (!routes.isEmpty()) {
|
||||||
new Tag("h4").content(t("Routes using this tile:")).addTo(window);
|
new Tag("h4").content(t("Routes using this tile:")).addTo(window);
|
||||||
Tag routeList = new Tag("ul");
|
Tag routeList = new Tag("ol");
|
||||||
for (Route route : routes) {
|
for (Route route : routes) {
|
||||||
new Tag("li").clazz("link").attr("onclick","openRoute('"+route.id()+"')").content(route.name()).addTo(routeList);
|
Tag li = new Tag("span").attr("onclick","openRoute('"+route.id()+"')").content(route.name()+NBSP).addTo(new Tag("li").clazz("link"));
|
||||||
|
Map<String, Object> params = Map.of(REALM,REALM_ROUTE,ID,route.id(),ACTION,ACTION_DROP,Tile.class.getSimpleName(),id());
|
||||||
|
new Button(t("delete route"),params).addTo(li);
|
||||||
|
li.addTo(routeList);
|
||||||
}
|
}
|
||||||
routeList.addTo(window);
|
routeList.addTo(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remove(Route route) {
|
||||||
|
routes.remove(route);
|
||||||
|
}
|
||||||
|
|
||||||
private static String replace(String line, Entry<String, Object> replacement) {
|
private static String replace(String line, Entry<String, Object> replacement) {
|
||||||
String key = replacement.getKey();
|
String key = replacement.getKey();
|
||||||
@@ -365,19 +371,4 @@ public abstract class Tile implements Constants{
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (clazz == null) throw new NullPointerException(TILE+" must not be null!");
|
|
||||||
Class<Tile> tc = Tile.class;
|
|
||||||
clazz = tc.getName().replace(".Tile", "."+clazz);
|
|
||||||
Tile tile = (Tile) tc.getClassLoader().loadClass(clazz).getDeclaredConstructor().newInstance();
|
|
||||||
if (tile instanceof Eraser) {
|
|
||||||
Tile erased = get(x,y,true);
|
|
||||||
remove(erased);
|
|
||||||
return erased == null ? null : t("Removed {}.",erased);
|
|
||||||
}
|
|
||||||
if (configJson != null) tile.configure(new JSONObject(configJson));
|
|
||||||
set(x, y, tile);
|
|
||||||
return t("Added {}",tile.getClass().getSimpleName());
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user