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({
|
||||
url : PLAN,
|
||||
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);}
|
||||
});
|
||||
return false;
|
||||
@@ -141,6 +142,6 @@ window.onload = function () {
|
||||
$('.menu > div').click(closeMenu);
|
||||
$('.menu .addtile .list svg').click(enableAdding);
|
||||
$('.menu .move .list div').click(enableMove);
|
||||
$('.menu .actions .list > div').click(runAction);
|
||||
$(BODY).click(bodyClick);
|
||||
$('#save').click(savePlan);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Vector;
|
||||
|
||||
@@ -17,6 +18,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.keawe.tools.translations.Translation;
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.tiles.Block;
|
||||
import de.srsoftware.web4rail.tiles.BlockH;
|
||||
import de.srsoftware.web4rail.tiles.BlockV;
|
||||
import de.srsoftware.web4rail.tiles.CrossH;
|
||||
@@ -46,27 +48,30 @@ import de.srsoftware.web4rail.tiles.TurnoutWS;
|
||||
public class Plan {
|
||||
private static final String ACTION = "action";
|
||||
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_UPDATE = "update";
|
||||
private static final String TILE = "tile";
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Plan.class);
|
||||
private static final String X = "x";
|
||||
private static final String Y = "y";
|
||||
private static final String NAME = "name";
|
||||
private static final String ACTION_PROPS = "openProps";
|
||||
private static final String ACTION_MOVE = "move";
|
||||
private static final String FILE = "file";
|
||||
private static final String DIRECTION = "direction";
|
||||
private static final String EAST = "east";
|
||||
private static final String WEST = "west";
|
||||
private static final String SOUTH = "south";
|
||||
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 HashSet<Block> blocks = new HashSet<Block>();
|
||||
|
||||
private Tag actionMenu() throws IOException {
|
||||
Tag tileMenu = new Tag("div").clazz("actions").content(t("Actions"));
|
||||
StringBuffer tiles = new StringBuffer();
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -79,10 +84,16 @@ public class Plan {
|
||||
Tile tile = (Tile) tc.getClassLoader().loadClass(clazz).getDeclaredConstructor().newInstance();
|
||||
if (configJson != null) tile.configure(new JSONObject(configJson));
|
||||
set(x, y, 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) {
|
||||
HashMap<Integer, Tile> column = tiles.get(x);
|
||||
return column == null ? null : column.get(y);
|
||||
@@ -195,12 +206,14 @@ public class Plan {
|
||||
case ACTION_ADD:
|
||||
Tile tile = addTile(params.get(TILE),params.get(X),params.get(Y),null);
|
||||
return t("Added {}",tile.getClass().getSimpleName());
|
||||
case ACTION_ANALYZE:
|
||||
return analyze();
|
||||
case ACTION_MOVE:
|
||||
return moveTile(params.get(DIRECTION),params.get(X),params.get(Y));
|
||||
case ACTION_PROPS:
|
||||
return propMenu(params.get(X),params.get(Y));
|
||||
case ACTION_SAVE:
|
||||
return saveTo(params.get(NAME));
|
||||
return saveTo(params.get(FILE));
|
||||
case ACTION_UPDATE:
|
||||
return update(params);
|
||||
default:
|
||||
@@ -262,10 +275,12 @@ public class Plan {
|
||||
tiles.put(x, column);
|
||||
}
|
||||
old = column.remove(y);
|
||||
if (old instanceof Block) blocks.remove((Block)old);
|
||||
if (tile != null && !(tile instanceof Eraser)) {
|
||||
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.height(); i++) set(x,y+i,new Shadow(tile));
|
||||
if (tile instanceof Block) blocks.add((Block)tile);
|
||||
}
|
||||
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.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
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";
|
||||
Contact north,center,south;
|
||||
private String name = "Block";
|
||||
@@ -26,6 +28,10 @@ public class BlockH extends StraightH{
|
||||
if (config.has(NAME)) name = config.getString(NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int len() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag propForm() {
|
||||
@@ -38,6 +44,11 @@ public class BlockH extends StraightH{
|
||||
return form;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Route> routes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||
@@ -45,6 +56,11 @@ public class BlockH extends StraightH{
|
||||
return super.tag(replacements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tile update(HashMap<String, String> params) {
|
||||
super.update(params);
|
||||
|
||||
@@ -3,12 +3,14 @@ package de.srsoftware.web4rail.tiles;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
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";
|
||||
Contact west,center,east;
|
||||
private String name = "Block";
|
||||
@@ -26,6 +28,10 @@ public class BlockV extends StraightV{
|
||||
if (config.has(NAME)) name = config.getString(NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int height() {
|
||||
return length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag propForm() {
|
||||
@@ -38,6 +44,11 @@ public class BlockV extends StraightV{
|
||||
return form;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Route> routes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag tag(Map<String, Object> replacements) throws IOException {
|
||||
if (replacements == null) replacements = new HashMap<String, Object>();
|
||||
@@ -45,6 +56,11 @@ public class BlockV extends StraightV{
|
||||
return super.tag(replacements);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()+"("+name+") @ ("+x+","+y+")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tile update(HashMap<String, String> params) {
|
||||
super.update(params);
|
||||
|
||||
Reference in New Issue
Block a user