Browse Source

implemented removing ot routes

lookup-tables
Stephan Richter 5 years ago
parent
commit
6cb318a37d
  1. 2
      pom.xml
  2. 1
      resources/js/plan.js
  3. 17
      src/main/java/de/srsoftware/web4rail/Plan.java
  4. 10
      src/main/java/de/srsoftware/web4rail/Route.java
  5. 3
      src/main/java/de/srsoftware/web4rail/tags/Button.java
  6. 29
      src/main/java/de/srsoftware/web4rail/tiles/Tile.java

2
pom.xml

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.srsoftware</groupId>
<artifactId>web4rail</artifactId>
<version>0.7.7</version>
<version>0.7.8</version>
<name>Web4Rail</name>
<packaging>jar</packaging>
<description>Java Model Railway Control</description>

1
resources/js/plan.js

@ -121,6 +121,7 @@ function moveTile(x,y){ @@ -121,6 +121,7 @@ function moveTile(x,y){
}
function openRoute(id){
console.log("openRoute("+id+")");
request({realm:'route',action:PROPS,id:id});
return false;
}

17
src/main/java/de/srsoftware/web4rail/Plan.java

@ -381,10 +381,6 @@ public class Plan implements Constants{ @@ -381,10 +381,6 @@ public class Plan implements Constants{
return controlUnit.queue(command);
}
public Route route(int routeId) {
return routes.get(routeId);
}
Route registerRoute(Route route) {
for (Tile tile: route.path()) tile.add(route);
routes.put(route.id(), route);
@ -398,11 +394,24 @@ public class Plan implements Constants{ @@ -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
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) {
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 {
Route route = route(Integer.parseInt(params.get(ID)));
if (route == null) return t("Unknown route: {}",params.get(ID));

10
src/main/java/de/srsoftware/web4rail/Route.java

@ -70,6 +70,7 @@ public class Route implements Constants{ @@ -70,6 +70,7 @@ public class Route implements Constants{
private static final String TRIGGER = "trigger";
private static final String ACTIONS = "actions";
private static final String ACTION_ID = "action_id";
private static final String TILE = Tile.class.getSimpleName();
private Tag actionTypeForm(Contact contact) {
String formId ="add-action-to-contact-"+contact.id();
@ -291,10 +292,15 @@ public class Route implements Constants{ @@ -291,10 +292,15 @@ public class Route implements Constants{
public Vector<Contact> 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!");
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);
Tile tag = plan.get(contactId, false);
if (!(tag instanceof Contact)) return t("No contact id passed to request!");

3
src/main/java/de/srsoftware/web4rail/tags/Button.java

@ -23,7 +23,6 @@ public class Button extends Tag { @@ -23,7 +23,6 @@ public class Button extends Tag {
}
public Button(String text, Map<String, Object> props) {
super("button");
attr("onclick","request("+(new JSONObject(props).toString().replace("\"", "'"))+")").content(text);
this(text,"request("+(new JSONObject(props).toString().replace("\"", "'"))+")");
}
}

29
src/main/java/de/srsoftware/web4rail/tiles/Tile.java

@ -214,15 +214,21 @@ public abstract class Tile implements Constants{ @@ -214,15 +214,21 @@ public abstract class Tile implements Constants{
if (!routes.isEmpty()) {
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) {
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);
}
}
return window;
}
public void remove(Route route) {
routes.remove(route);
}
private static String replace(String line, Entry<String, Object> replacement) {
String key = replacement.getKey();
@ -365,19 +371,4 @@ public abstract class Tile implements Constants{ @@ -365,19 +371,4 @@ public abstract class Tile implements Constants{
}
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());
}*/
}

Loading…
Cancel
Save