preparing more general assignment function
This commit is contained in:
@@ -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