implemented persistence of plans
This commit is contained in:
@@ -69,7 +69,7 @@ function savePlan(ev){
|
||||
$.ajax({
|
||||
url : PLAN,
|
||||
method : POST,
|
||||
data : {action:'save',name:'default'},
|
||||
data : {action:'save',name:'default'}, // todo: ask for name
|
||||
success: function(resp){ addMessage(resp);}
|
||||
});
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
Actions : Aktionen
|
||||
Added {} : {} hinzugefügt
|
||||
Add tile : Kachel hinzufügen
|
||||
Plan saved as "{}". : Plan als „{}“ gespeichert.
|
||||
Save plan : Plan speichern
|
||||
Unknown action\: {} : Unbekannte Aktion: {}
|
||||
@@ -5,6 +5,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
@@ -38,10 +39,11 @@ public class Application {
|
||||
private static final String PORT = "port";
|
||||
private static final Charset UTF8 = StandardCharsets.UTF_8;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
Configuration config = new Configuration(Configuration.dir("Web4Rail")+"/app.config");
|
||||
LOG.debug("Config: {}",config);
|
||||
plan = new Plan();
|
||||
plan = Plan.load("default.plan");
|
||||
/*plan = new Plan();
|
||||
plan.set(0, 0, new StraightH());
|
||||
plan.set(1, 0, new DiagSW());
|
||||
plan.set(1, 1, new StraightV());
|
||||
@@ -51,7 +53,7 @@ public class Application {
|
||||
plan.set(3, 1, new TurnoutSE());
|
||||
plan.set(3, 0, new TurnoutSW());
|
||||
plan.set(2, 0, new EndE());
|
||||
plan.set(4, 1, new EndW());
|
||||
plan.set(4, 1, new EndW());*/
|
||||
InetSocketAddress addr = new InetSocketAddress(config.getOrAdd(PORT, 8080));
|
||||
HttpServer server = HttpServer.create(addr, 0);
|
||||
server.createContext("/plan", client -> sendPlan(client));
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package de.srsoftware.web4rail;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -39,6 +41,15 @@ public class Plan {
|
||||
|
||||
private HashMap<Integer,HashMap<Integer,Tile>> tiles = new HashMap<Integer,HashMap<Integer,Tile>>();
|
||||
|
||||
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")));
|
||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||
}
|
||||
|
||||
private Tile addTile(String clazz, String xs, String ys) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
int x = Integer.parseInt(xs);
|
||||
int y = Integer.parseInt(ys);
|
||||
@@ -67,6 +78,19 @@ public class Plan {
|
||||
}
|
||||
return page.append(menu()).append(messages());
|
||||
}
|
||||
|
||||
public static Plan load(String filename) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
|
||||
Plan result = new Plan();
|
||||
File file = new File(filename);
|
||||
BufferedReader br = new BufferedReader(new FileReader(file));
|
||||
while (br.ready()) {
|
||||
String line = br.readLine().trim();
|
||||
String[] parts = line.split(":");
|
||||
result.addTile(parts[2].trim(), parts[0].trim(), parts[1].trim());
|
||||
}
|
||||
br.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
private Tag messages() {
|
||||
return new Tag("div").id("messages").content("");
|
||||
@@ -81,15 +105,6 @@ public class Plan {
|
||||
return menu;
|
||||
}
|
||||
|
||||
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")));
|
||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||
}
|
||||
|
||||
public String process(HashMap<String, String> params) {
|
||||
try {
|
||||
String action = params.get(ACTION);
|
||||
@@ -123,7 +138,7 @@ public class Plan {
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
return "saving "+name;
|
||||
return t("Plan saved as \"{}\".",file);
|
||||
}
|
||||
|
||||
public Tile set(int x,int y,Tile tile) {
|
||||
@@ -160,4 +175,6 @@ public class Plan {
|
||||
tiles.append(new Eraser().html());
|
||||
return new Tag("div").clazz("list").content(tiles.toString()).addTo(tileMenu);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user