improved message handling
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.5.35</version>
|
||||
<version>1.5.36</version>
|
||||
<name>Web4Rail</name>
|
||||
<packaging>jar</packaging>
|
||||
<description>Java Model Railway Control</description>
|
||||
|
||||
@@ -9,6 +9,7 @@ const POST = 'POST';
|
||||
const PROPS = 'props';
|
||||
const SQUARE = 30;
|
||||
const SVG = 'svg';
|
||||
const MSG_TIME = 5000;
|
||||
var selected = null;
|
||||
var mode = null;
|
||||
var messageTimer = null;
|
||||
@@ -41,11 +42,18 @@ function addClass(data){
|
||||
}
|
||||
|
||||
function addMessage(txt){
|
||||
let delay = MSG_TIME;
|
||||
if (txt.includes('⌛')){
|
||||
let parts = txt.split('⌛');
|
||||
delay = parseInt(parts[0]);
|
||||
txt = parts[1];
|
||||
}
|
||||
let mid = 'm'+Date.now();
|
||||
$('#messages').append($('<div/>').attr('id',mid).html(txt));
|
||||
setTimeout(function(){
|
||||
$('#'+mid).remove();
|
||||
},10000);
|
||||
},delay);
|
||||
if (delay != MSG_TIME) countDown(mid,delay/1000,txt);
|
||||
}
|
||||
|
||||
function addTile(x,y){
|
||||
@@ -86,11 +94,9 @@ function assign(context){
|
||||
}
|
||||
|
||||
function changeSpeed(inputId){
|
||||
console.log(inputId);
|
||||
let parts = inputId.split('_');
|
||||
let val = $('#'+inputId).val();
|
||||
let data = { realm : parts[0], id : parts[1], action : "setSpeed", speed : val};
|
||||
console.log(data);
|
||||
let caption = $('#'+inputId+'_caption');
|
||||
caption.text(caption.text().replace(/\d+/,val));
|
||||
request(data);
|
||||
@@ -114,9 +120,7 @@ function clickTile(x,y,shift){
|
||||
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','');
|
||||
@@ -155,6 +159,15 @@ function copyCv(ev){
|
||||
$('input[name=val]').val(td.innerText);
|
||||
}
|
||||
|
||||
function countDown(mid,time,msg){
|
||||
time = parseInt(time);
|
||||
$('#'+mid).html(msg.replace('%secs%',time));
|
||||
time = time -1;
|
||||
if (time>0) setTimeout(function(){
|
||||
countDown(mid,time,msg);
|
||||
},1000);
|
||||
}
|
||||
|
||||
function dropClass(data){
|
||||
var parts = data.split(" ");
|
||||
for (var i=1; i<parts.length; i++) $('#'+parts[0]).removeClass(parts[i]);
|
||||
@@ -235,7 +248,7 @@ function place(data){
|
||||
}
|
||||
|
||||
function planClick(ev){
|
||||
console.log('planClick:',ev);
|
||||
//console.log('planClick:',ev);
|
||||
var plan=$('#scroll').get(0);
|
||||
var x = Math.floor((plan.scrollLeft+ev.clientX)/SQUARE);
|
||||
var y = Math.floor((plan.scrollTop+ev.clientY)/SQUARE);
|
||||
@@ -253,7 +266,7 @@ function planClick(ev){
|
||||
}
|
||||
|
||||
function remember(lastClickedId){
|
||||
console.log("lastClickedId: "+lastClickedId)
|
||||
//console.log("lastClickedId: "+lastClickedId)
|
||||
var index = clickHistory.indexOf(lastClickedId);
|
||||
if (index > -1) clickHistory.splice(index, 1);
|
||||
clickHistory.unshift(lastClickedId);
|
||||
@@ -265,7 +278,7 @@ function remove(id){
|
||||
}
|
||||
|
||||
function request(data){
|
||||
console.log("request:",data);
|
||||
//console.log("request:",data);
|
||||
$.ajax({
|
||||
url : 'plan',
|
||||
method : POST,
|
||||
@@ -331,7 +344,7 @@ function stream(ev){
|
||||
}
|
||||
|
||||
function submitForm(formId){
|
||||
console.log("submitForm("+formId+")");
|
||||
//console.log("submitForm("+formId+")");
|
||||
return request($('#'+formId).serialize());
|
||||
}
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ Values : Werte
|
||||
WaitForContact : Auf Kontakt warten
|
||||
Wait for {}, then : auf {} warten, dann
|
||||
Wait {} ms, then : {} ms warten, dann
|
||||
{} waiting {} secs. : {} wartet {} Sekunden.
|
||||
{} waiting %secs% secs. : {} wartet %secs% Sekunden.
|
||||
Wait times : Wartezeiten
|
||||
Was not able to assign {} to {}! : Konnte {} nicht an {} zuweisen!
|
||||
Was not able to lock {} : Konnte {} nicht reservieren
|
||||
|
||||
@@ -374,7 +374,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
destination = Destination.from(destinationTag());
|
||||
LOG.debug("{}.destination() → {}",this,destination);
|
||||
if (isSet(destination)) shunting |= destination.shunting();
|
||||
}
|
||||
}
|
||||
return destination;
|
||||
}
|
||||
|
||||
@@ -499,7 +499,7 @@ public class Train extends BaseClass implements Comparable<Train> {
|
||||
|
||||
if (autopilot) {
|
||||
if (isNull(waitTime)) waitTime = 0;
|
||||
if (waitTime>0) plan.stream(t("{} waiting {} secs.",this,(int)(waitTime/1000)));
|
||||
if (waitTime>0) plan.stream(waitTime+"⌛"+t("{} waiting %secs% secs.",this));
|
||||
new DelayedExecution(waitTime,this) {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -242,7 +242,8 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
||||
PriorityQueue<Trail> trails = new PriorityQueue<>();
|
||||
|
||||
for (Route route : startBlock.leavingRoutes()) {
|
||||
int score = (route.endsAt(destination)) ? 100_000 : 0;
|
||||
boolean reachesDest = route.endsAt(destination);
|
||||
int score = reachesDest ? 100_000 : 0;
|
||||
|
||||
if (isSet(startDirection) && route.startDirection != startDirection) { // Route startet entgegen der aktuellen Fahrtrichtung des Zuges
|
||||
if (!train.pushPull) continue; // Zug kann nicht wenden
|
||||
@@ -254,13 +255,13 @@ public class RoutePrepper extends BaseClass implements Runnable{
|
||||
|
||||
if (!route.allowed(new Context(train).block(startBlock).direction(startDirection))) {
|
||||
LOG.debug(" - {} not allowed for {}", route, train);
|
||||
if (!route.endsAt(destination)) continue;
|
||||
if (!reachesDest) continue;
|
||||
LOG.debug(" …overridden by destination of train!", route, train);
|
||||
}
|
||||
|
||||
trails.add(new Trail().add(route,score));
|
||||
}
|
||||
|
||||
|
||||
return trails;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user