preparing more general assignment function
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>de.srsoftware</groupId>
|
||||
<artifactId>web4rail</artifactId>
|
||||
<version>1.3.21</version>
|
||||
<version>1.3.22</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -13,7 +13,7 @@ var selected = null;
|
||||
var mode = null;
|
||||
var messageTimer = null;
|
||||
var messageOpacity = 0;
|
||||
var trainAwaitingDestination = null;
|
||||
var pendingAssignment = null;
|
||||
var lastTab = null;
|
||||
|
||||
function addClass(data){
|
||||
@@ -52,6 +52,13 @@ function arrangeTabs(){
|
||||
if (target != null) clickLegend({'data':lastTab,'target':target});
|
||||
}
|
||||
|
||||
function assign(context){
|
||||
pendingAssignment = context;
|
||||
closeWindows();
|
||||
$(PLAN).css('cursor','help');
|
||||
return false;
|
||||
}
|
||||
|
||||
function clickLegend(ev){
|
||||
lastTab = ev.data;
|
||||
$('.window > .tabs > legend').removeClass('front');
|
||||
@@ -64,9 +71,14 @@ function clickTile(x,y){
|
||||
var id = x+"-"+y;
|
||||
var tiles = $('#'+id);
|
||||
if (tiles.length > 0) {
|
||||
if (trainAwaitingDestination != null && tiles.hasClass("Block")) {
|
||||
request({realm:'train',id:trainAwaitingDestination,action:MOVE,destination:id});
|
||||
trainAwaitingDestination = null;
|
||||
if (pendingAssignment != null) {
|
||||
var key = pendingAssignment.assign;
|
||||
delete pendingAssignment.assign;
|
||||
console.log("assigning key:",key);
|
||||
pendingAssignment[key] = id;
|
||||
console.log("pA:",pendingAssignment);
|
||||
request(pendingAssignment);
|
||||
pendingAssignment = null;
|
||||
$(PLAN).css('cursor','');
|
||||
return false;
|
||||
}
|
||||
@@ -196,6 +208,7 @@ function remove(id){
|
||||
}
|
||||
|
||||
function request(data){
|
||||
console.log("request:",data);
|
||||
$.ajax({
|
||||
url : 'plan',
|
||||
method : POST,
|
||||
@@ -240,13 +253,6 @@ function runAction(ev){
|
||||
return false;
|
||||
}
|
||||
|
||||
function selectDest(trainId){
|
||||
trainAwaitingDestination = trainId;
|
||||
closeWindows();
|
||||
$(PLAN).css('cursor','help');
|
||||
return false;
|
||||
}
|
||||
|
||||
function stream(ev){
|
||||
var data = ev.data;
|
||||
console.log("received: ",data);
|
||||
|
||||
@@ -49,7 +49,7 @@ public interface Constants {
|
||||
public static final String REALM_PLAN = "plan";
|
||||
public static final String REALM_TRAIN = "train";
|
||||
|
||||
|
||||
public static final String ASSIGN = "assign";
|
||||
public static final String BLOCK = "block";
|
||||
public static final String COL = " ";
|
||||
public static final String CONTACT = "contact";
|
||||
|
||||
@@ -211,6 +211,8 @@ public class Route extends BaseClass {
|
||||
Route route = BaseClass.get(Id.from(params));
|
||||
if (isNull(route)) return t("Unknown route: {}",params.get(ID));
|
||||
switch (params.get(ACTION)) {
|
||||
case ACTION_AUTO:
|
||||
return route.simplyfyName().properties();
|
||||
case ACTION_DROP:
|
||||
route.remove();
|
||||
plan.stream(t("Removed {}.",route));
|
||||
@@ -823,7 +825,10 @@ public class Route extends BaseClass {
|
||||
preForm.add(conditions.list(t("Route will only be available, if all conditions are fulfilled.")));
|
||||
preForm.add(contactsAndActions());
|
||||
|
||||
formInputs.add(t("Name"),new Input(NAME, name()));
|
||||
Tag nameSpan = new Tag("span");
|
||||
new Input(NAME, name()).addTo(nameSpan);
|
||||
button(t("simplify name"), Map.of(ACTION,ACTION_AUTO,ROUTE,id().toString())).addTo(nameSpan);
|
||||
formInputs.add(t("Name"),nameSpan);
|
||||
Checkbox checkbox = new Checkbox(DISABLED, t("disabled"), disabled);
|
||||
if (disabled) checkbox.clazz("disabled");
|
||||
formInputs.add(t("State"),checkbox);
|
||||
@@ -935,9 +940,10 @@ public class Route extends BaseClass {
|
||||
return parts[0].trim()+"–"+parts[parts.length-1].trim();
|
||||
}
|
||||
|
||||
public void simplyfyName() {
|
||||
public Route simplyfyName() {
|
||||
String[] parts = name().split("-");
|
||||
if (parts.length>1) name(parts[0]+" - "+parts[parts.length-1]);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Route.State state(){
|
||||
|
||||
@@ -246,12 +246,8 @@ public class Car extends BaseClass implements Comparable<Car>{
|
||||
new Input(MAX_SPEED, maxSpeedForward).numeric().addTo(new Tag("p")).content(NBSP+speedUnit+NBSP+t("forward")).addTo(div);
|
||||
new Input(MAX_SPEED_REVERSE, maxSpeedReverse).numeric().addTo(new Tag("p")).content(NBSP+speedUnit+NBSP+t("backward")).addTo(div);
|
||||
formInputs.add(t("Maximum Speed"),div);
|
||||
|
||||
Fieldset fieldset = new Fieldset(t("Train"));
|
||||
if (train != null) train.link().addTo(fieldset);
|
||||
|
||||
postForm.add(fieldset);
|
||||
|
||||
if (train != null) formInputs.add(t("Train"), train.link());
|
||||
|
||||
return super.properties(preForm,formInputs,postForm);
|
||||
}
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
car.train(null);
|
||||
}
|
||||
if (cars.isEmpty()) {
|
||||
this.remove();
|
||||
remove();
|
||||
return t("Removed train \"{}\"",this);
|
||||
}
|
||||
return properties();
|
||||
@@ -582,7 +582,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
Tag dest = new Tag("li").content(t("Destination")+COL);
|
||||
if (isNull(destination)) {
|
||||
new Button(t("Select from plan"),"return selectDest("+id+");").addTo(dest);
|
||||
button(t("Select from plan"),Map.of(ACTION,ACTION_MOVE,ASSIGN,DESTINATION)).addTo(dest);
|
||||
} else {
|
||||
link("span",destination,Map.of(REALM,REALM_PLAN,ID,destination.id().toString(),ACTION,ACTION_CLICK)).addTo(dest);
|
||||
new Button(t("Drop"),Map.of(REALM,REALM_TRAIN,ID,id,ACTION,ACTION_MOVE,DESTINATION,"")).addTo(dest);
|
||||
@@ -637,6 +637,14 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
} else return t("autopilot not active.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseClass remove() {
|
||||
if (isSet(currentBlock)) currentBlock.removeChild(this);
|
||||
if (isSet(route)) route.removeChild(this);
|
||||
for (Tile t:trace) t.removeChild(this);
|
||||
return super.remove();
|
||||
}
|
||||
|
||||
private Window removeBrakeTimes() {
|
||||
List<Route> routes = BaseClass.listElements(Route.class);
|
||||
for (Route route: routes) route.dropBraketimes(brakeId(false),brakeId(true));
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.stream.Collectors;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.Constants;
|
||||
|
||||
public class Button extends Tag {
|
||||
|
||||
@@ -29,8 +30,12 @@ public class Button extends Tag {
|
||||
}
|
||||
|
||||
public Button(String text, Map<String, ? extends Object> props) {
|
||||
this(text,"request("+(new JSONObject(
|
||||
this(text,actionFrom(props)+"("+(new JSONObject(
|
||||
props.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey(), entry -> entry.getValue().toString()))
|
||||
).toString().replace("\"", "'"))+")");
|
||||
}
|
||||
|
||||
private static String actionFrom(Map<String, ? extends Object> props) {
|
||||
return props.containsKey(Constants.ASSIGN) ? Constants.ASSIGN : "request";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,8 +291,8 @@ public abstract class Block extends StretchableTile{
|
||||
if (json.has(PARKED_TRAINS)) {
|
||||
JSONArray ptids = json.getJSONArray(PARKED_TRAINS);
|
||||
for (Object id : ptids) {
|
||||
Id trainId = new Id(id.toString());
|
||||
parkedTrains.add(BaseClass.get(trainId));
|
||||
Train train = BaseClass.get(new Id(id.toString()));
|
||||
if (isSet(train)) parkedTrains.add(train);
|
||||
}
|
||||
}
|
||||
return super.load(json);
|
||||
@@ -302,7 +302,7 @@ public abstract class Block extends StretchableTile{
|
||||
Fieldset fieldset = new Fieldset(t("parked trains"));
|
||||
Tag list = new Tag("ul");
|
||||
for (Train t : parkedTrains) {
|
||||
t.link("li", t).addTo(list);
|
||||
if (isSet(t)) t.link("li", t).addTo(list);
|
||||
}
|
||||
list.addTo(fieldset);
|
||||
return fieldset;
|
||||
|
||||
Reference in New Issue
Block a user