- implemented tags on trains and cars
- added condition TrainHasTag
This commit is contained in:
@@ -70,6 +70,10 @@ public abstract class Condition implements Constants {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
JSONObject json = new JSONObject().put(TYPE, getClass().getSimpleName());
|
||||
if (inverted) json.put(INVERTED, true);
|
||||
@@ -88,6 +92,10 @@ public abstract class Condition implements Constants {
|
||||
return new Tag(tagClass).clazz("link").attr("onclick","request("+json+")").content(toString());
|
||||
}
|
||||
|
||||
private static List<Class<? extends Condition>> list() {
|
||||
return List.of(TrainHasTag.class,TrainSelect.class,TrainLength.class);
|
||||
}
|
||||
|
||||
public Tag propForm(HashMap<String, String> params) {
|
||||
Form form = new Form("condition-props-"+id);
|
||||
new Input(REALM,REALM_CONDITION).hideIn(form);
|
||||
@@ -118,10 +126,6 @@ public abstract class Condition implements Constants {
|
||||
return select.addTo(new Label(t("Action type:")+NBSP));
|
||||
}
|
||||
|
||||
private static List<Class<? extends Condition>> list() {
|
||||
return List.of(TrainSelect.class,TrainLength.class);
|
||||
}
|
||||
|
||||
public static String t(String text, Object...fills) {
|
||||
return Translation.get(Application.class, text, fills);
|
||||
}
|
||||
@@ -135,8 +139,4 @@ public abstract class Condition implements Constants {
|
||||
inverted = "on".equals(params.get(INVERTED));
|
||||
return t("updated {}.",this);
|
||||
}
|
||||
|
||||
public int id() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package de.srsoftware.web4rail.conditions;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.srsoftware.tools.Tag;
|
||||
import de.srsoftware.web4rail.actions.Action.Context;
|
||||
import de.srsoftware.web4rail.tags.Input;
|
||||
import de.srsoftware.web4rail.tags.Label;
|
||||
|
||||
public class TrainHasTag extends Condition {
|
||||
|
||||
private static final String TAG = "tag";
|
||||
private String tag = null;
|
||||
|
||||
@Override
|
||||
public boolean fulfilledBy(Context context) {
|
||||
if (tag == null) return true;
|
||||
return context.train.tags().contains(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
return super.json().put(TAG, tag);
|
||||
}
|
||||
|
||||
public static TrainHasTag load(JSONObject json) {
|
||||
TrainHasTag tl = new TrainHasTag();
|
||||
if (json.has(TAG)) tl.tag = json.getString(TAG);
|
||||
return tl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tag propForm(HashMap<String, String> params) {
|
||||
return new Input(TAG, tag == null ? "" : tag).addTo(new Label(t("Tag:")+NBSP)).addTo(super.propForm(params));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (tag == null) return t("[Click to setup tag]");
|
||||
return t(inverted ? "train does not have tag \"{}\"" : "train has tag \"{}\"",tag) ;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object update(HashMap<String, String> params) {
|
||||
tag = params.get(TAG);
|
||||
return super.update(params);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user