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