prepared route search
This commit is contained in:
@@ -125,11 +125,12 @@ function moveTile(x,y){
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function savePlan(ev){
|
function runAction(ev){
|
||||||
|
console.log("runAction: ",ev.target.id);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : PLAN,
|
url : PLAN,
|
||||||
method : POST,
|
method : POST,
|
||||||
data : {action:'save',name:'default'}, // TODO: ask for name
|
data : {action:ev.target.id,file:'default'}, // TODO: ask for name
|
||||||
success: function(resp){ addMessage(resp);}
|
success: function(resp){ addMessage(resp);}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
@@ -141,6 +142,6 @@ window.onload = function () {
|
|||||||
$('.menu > div').click(closeMenu);
|
$('.menu > div').click(closeMenu);
|
||||||
$('.menu .addtile .list svg').click(enableAdding);
|
$('.menu .addtile .list svg').click(enableAdding);
|
||||||
$('.menu .move .list div').click(enableMove);
|
$('.menu .move .list div').click(enableMove);
|
||||||
$(BODY).click(bodyClick);
|
$('.menu .actions .list > div').click(runAction);
|
||||||
$('#save').click(savePlan);
|
$(BODY).click(bodyClick);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
@@ -17,6 +18,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import de.keawe.tools.translations.Translation;
|
import de.keawe.tools.translations.Translation;
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.tiles.Block;
|
||||||
import de.srsoftware.web4rail.tiles.BlockH;
|
import de.srsoftware.web4rail.tiles.BlockH;
|
||||||
import de.srsoftware.web4rail.tiles.BlockV;
|
import de.srsoftware.web4rail.tiles.BlockV;
|
||||||
import de.srsoftware.web4rail.tiles.CrossH;
|
import de.srsoftware.web4rail.tiles.CrossH;
|
||||||
@@ -46,27 +48,30 @@ import de.srsoftware.web4rail.tiles.TurnoutWS;
|
|||||||
public class Plan {
|
public class Plan {
|
||||||
private static final String ACTION = "action";
|
private static final String ACTION = "action";
|
||||||
private static final String ACTION_ADD = "add";
|
private static final String ACTION_ADD = "add";
|
||||||
|
private static final String ACTION_ANALYZE = "analyze";
|
||||||
|
private static final String ACTION_MOVE = "move";
|
||||||
|
private static final String ACTION_PROPS = "openProps";
|
||||||
private static final String ACTION_SAVE = "save";
|
private static final String ACTION_SAVE = "save";
|
||||||
|
private static final String ACTION_UPDATE = "update";
|
||||||
private static final String TILE = "tile";
|
private static final String TILE = "tile";
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(Plan.class);
|
private static final Logger LOG = LoggerFactory.getLogger(Plan.class);
|
||||||
private static final String X = "x";
|
private static final String X = "x";
|
||||||
private static final String Y = "y";
|
private static final String Y = "y";
|
||||||
private static final String NAME = "name";
|
private static final String FILE = "file";
|
||||||
private static final String ACTION_PROPS = "openProps";
|
|
||||||
private static final String ACTION_MOVE = "move";
|
|
||||||
private static final String DIRECTION = "direction";
|
private static final String DIRECTION = "direction";
|
||||||
private static final String EAST = "east";
|
private static final String EAST = "east";
|
||||||
private static final String WEST = "west";
|
private static final String WEST = "west";
|
||||||
private static final String SOUTH = "south";
|
private static final String SOUTH = "south";
|
||||||
private static final String NORTH = "north";
|
private static final String NORTH = "north";
|
||||||
private static final String ACTION_UPDATE = "update";
|
|
||||||
|
|
||||||
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
||||||
|
private HashSet<Block> blocks = new HashSet<Block>();
|
||||||
|
|
||||||
private Tag actionMenu() throws IOException {
|
private Tag actionMenu() throws IOException {
|
||||||
Tag tileMenu = new Tag("div").clazz("actions").content(t("Actions"));
|
Tag tileMenu = new Tag("div").clazz("actions").content(t("Actions"));
|
||||||
StringBuffer tiles = new StringBuffer();
|
StringBuffer tiles = new StringBuffer();
|
||||||
tiles.append(new Tag("div").id("save").content(t("Save plan")));
|
tiles.append(new Tag("div").id("save").content(t("Save plan")));
|
||||||
|
tiles.append(new Tag("div").id("analyze").content(t("Analyze plan")));
|
||||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,11 +83,17 @@ public class Plan {
|
|||||||
clazz = tc.getName().replace(".Tile", "."+clazz);
|
clazz = tc.getName().replace(".Tile", "."+clazz);
|
||||||
Tile tile = (Tile) tc.getClassLoader().loadClass(clazz).getDeclaredConstructor().newInstance();
|
Tile tile = (Tile) tc.getClassLoader().loadClass(clazz).getDeclaredConstructor().newInstance();
|
||||||
if (configJson != null) tile.configure(new JSONObject(configJson));
|
if (configJson != null) tile.configure(new JSONObject(configJson));
|
||||||
set(x, y, tile);
|
set(x, y, tile);
|
||||||
|
|
||||||
return tile;
|
return tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String analyze() {
|
||||||
|
for (Block block : blocks) {
|
||||||
|
LOG.debug("searching routes from {}",block);
|
||||||
|
}
|
||||||
|
return "analyze() not implemented, yet!";
|
||||||
|
}
|
||||||
|
|
||||||
public Tile get(int x, int y) {
|
public Tile get(int x, int y) {
|
||||||
HashMap<Integer, Tile> column = tiles.get(x);
|
HashMap<Integer, Tile> column = tiles.get(x);
|
||||||
return column == null ? null : column.get(y);
|
return column == null ? null : column.get(y);
|
||||||
@@ -195,12 +206,14 @@ public class Plan {
|
|||||||
case ACTION_ADD:
|
case ACTION_ADD:
|
||||||
Tile tile = addTile(params.get(TILE),params.get(X),params.get(Y),null);
|
Tile tile = addTile(params.get(TILE),params.get(X),params.get(Y),null);
|
||||||
return t("Added {}",tile.getClass().getSimpleName());
|
return t("Added {}",tile.getClass().getSimpleName());
|
||||||
|
case ACTION_ANALYZE:
|
||||||
|
return analyze();
|
||||||
case ACTION_MOVE:
|
case ACTION_MOVE:
|
||||||
return moveTile(params.get(DIRECTION),params.get(X),params.get(Y));
|
return moveTile(params.get(DIRECTION),params.get(X),params.get(Y));
|
||||||
case ACTION_PROPS:
|
case ACTION_PROPS:
|
||||||
return propMenu(params.get(X),params.get(Y));
|
return propMenu(params.get(X),params.get(Y));
|
||||||
case ACTION_SAVE:
|
case ACTION_SAVE:
|
||||||
return saveTo(params.get(NAME));
|
return saveTo(params.get(FILE));
|
||||||
case ACTION_UPDATE:
|
case ACTION_UPDATE:
|
||||||
return update(params);
|
return update(params);
|
||||||
default:
|
default:
|
||||||
@@ -262,10 +275,12 @@ public class Plan {
|
|||||||
tiles.put(x, column);
|
tiles.put(x, column);
|
||||||
}
|
}
|
||||||
old = column.remove(y);
|
old = column.remove(y);
|
||||||
|
if (old instanceof Block) blocks.remove((Block)old);
|
||||||
if (tile != null && !(tile instanceof Eraser)) {
|
if (tile != null && !(tile instanceof Eraser)) {
|
||||||
column.put(y,tile.position(x, y));
|
column.put(y,tile.position(x, y));
|
||||||
for (int i=1; i<tile.len(); i++) set(x+i,y,new Shadow(tile));
|
for (int i=1; i<tile.len(); i++) set(x+i,y,new Shadow(tile));
|
||||||
for (int i=1; i<tile.height(); i++) set(x,y+i,new Shadow(tile));
|
for (int i=1; i<tile.height(); i++) set(x,y+i,new Shadow(tile));
|
||||||
|
if (tile instanceof Block) blocks.add((Block)tile);
|
||||||
}
|
}
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|||||||
5
src/main/java/de/srsoftware/web4rail/Route.java
Normal file
5
src/main/java/de/srsoftware/web4rail/Route.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package de.srsoftware.web4rail;
|
||||||
|
|
||||||
|
public class Route {
|
||||||
|
|
||||||
|
}
|
||||||
10
src/main/java/de/srsoftware/web4rail/tiles/Block.java
Normal file
10
src/main/java/de/srsoftware/web4rail/tiles/Block.java
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package de.srsoftware.web4rail.tiles;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.srsoftware.web4rail.Route;
|
||||||
|
import de.srsoftware.web4rail.tiles.StretchableTile;
|
||||||
|
|
||||||
|
public abstract class Block extends StretchableTile{
|
||||||
|
public abstract Set<Route> routes();
|
||||||
|
}
|
||||||
@@ -3,12 +3,14 @@ package de.srsoftware.web4rail.tiles;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.Route;
|
||||||
|
|
||||||
public class BlockH extends StraightH{
|
public class BlockH extends Block{
|
||||||
private static final String NAME = "name";
|
private static final String NAME = "name";
|
||||||
Contact north,center,south;
|
Contact north,center,south;
|
||||||
private String name = "Block";
|
private String name = "Block";
|
||||||
@@ -26,6 +28,10 @@ public class BlockH extends StraightH{
|
|||||||
if (config.has(NAME)) name = config.getString(NAME);
|
if (config.has(NAME)) name = config.getString(NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int len() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag propForm() {
|
public Tag propForm() {
|
||||||
@@ -38,6 +44,11 @@ public class BlockH extends StraightH{
|
|||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Route> routes() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||||
if (replacements == null) replacements = new HashMap<String, Object>();
|
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||||
@@ -45,6 +56,11 @@ public class BlockH extends StraightH{
|
|||||||
return super.tag(replacements);
|
return super.tag(replacements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) {
|
public Tile update(HashMap<String, String> params) {
|
||||||
super.update(params);
|
super.update(params);
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ package de.srsoftware.web4rail.tiles;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import de.srsoftware.tools.Tag;
|
import de.srsoftware.tools.Tag;
|
||||||
|
import de.srsoftware.web4rail.Route;
|
||||||
|
|
||||||
public class BlockV extends StraightV{
|
public class BlockV extends Block{
|
||||||
private static final String NAME = "name";
|
private static final String NAME = "name";
|
||||||
Contact west,center,east;
|
Contact west,center,east;
|
||||||
private String name = "Block";
|
private String name = "Block";
|
||||||
@@ -26,6 +28,10 @@ public class BlockV extends StraightV{
|
|||||||
if (config.has(NAME)) name = config.getString(NAME);
|
if (config.has(NAME)) name = config.getString(NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int height() {
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag propForm() {
|
public Tag propForm() {
|
||||||
@@ -38,6 +44,11 @@ public class BlockV extends StraightV{
|
|||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Route> routes() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||||
if (replacements == null) replacements = new HashMap<String, Object>();
|
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||||
@@ -45,6 +56,11 @@ public class BlockV extends StraightV{
|
|||||||
return super.tag(replacements);
|
return super.tag(replacements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tile update(HashMap<String, String> params) {
|
public Tile update(HashMap<String, String> params) {
|
||||||
super.update(params);
|
super.update(params);
|
||||||
|
|||||||
Reference in New Issue
Block a user