From 4025e24c8a5bcb7a791aa41a898bc256e42ffbae Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Thu, 3 May 2018 23:43:32 +0200 Subject: [PATCH 01/17] Added default poles option Poles describe certain platforms at stations. --- MMM-RNV.js | 1 + 1 file changed, 1 insertion(+) diff --git a/MMM-RNV.js b/MMM-RNV.js index 5da7379..0332203 100644 --- a/MMM-RNV.js +++ b/MMM-RNV.js @@ -24,6 +24,7 @@ Module.register('MMM-RNV',{ apiBase: 'http://rnv.the-agent-factory.de:8080/easygo2/api', requestURL: '/regions/rnv/modules/stationmonitor/element', stationID: '', + poles: '', iconTable: { "KOM": "fa fa-bus", From 12cdd54c64d56417ca9354d3cde28c24a94ed670 Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Thu, 3 May 2018 23:45:11 +0200 Subject: [PATCH 02/17] Added poles to API URL when defined in config --- node_helper.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/node_helper.js b/node_helper.js index 0ecf4ea..35db4ea 100644 --- a/node_helper.js +++ b/node_helper.js @@ -23,7 +23,10 @@ module.exports = NodeHelper.create({ var currentDate = moment().format('YYYY-MM-DD+hh:mm:ss'); var myUrl = this.config.apiBase + this.config.requestURL + '?hafasID=' + this.config.stationID + '&time=' + currentDate; - + if(this.config.poles != '') { + myUrl += '&poles=' + this.config.poles; + } + request({ url: myUrl, method: 'GET', From be5251e480dc56f15ac1caa161cb02d445379e5d Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 4 May 2018 00:12:07 +0200 Subject: [PATCH 03/17] Changed name of poles. --- MMM-RNV.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MMM-RNV.js b/MMM-RNV.js index 0332203..7bb5079 100644 --- a/MMM-RNV.js +++ b/MMM-RNV.js @@ -24,7 +24,7 @@ Module.register('MMM-RNV',{ apiBase: 'http://rnv.the-agent-factory.de:8080/easygo2/api', requestURL: '/regions/rnv/modules/stationmonitor/element', stationID: '', - poles: '', + poleIDs: '', iconTable: { "KOM": "fa fa-bus", From a47f5eec4112373690f1d9a65c56d091fd1e1c0a Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 4 May 2018 00:12:45 +0200 Subject: [PATCH 04/17] Changed name of poles. --- node_helper.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node_helper.js b/node_helper.js index 35db4ea..605c4b0 100644 --- a/node_helper.js +++ b/node_helper.js @@ -23,8 +23,8 @@ module.exports = NodeHelper.create({ var currentDate = moment().format('YYYY-MM-DD+hh:mm:ss'); var myUrl = this.config.apiBase + this.config.requestURL + '?hafasID=' + this.config.stationID + '&time=' + currentDate; - if(this.config.poles != '') { - myUrl += '&poles=' + this.config.poles; + if(this.config.poleIDs != '') { + myUrl += '&poles=' + this.config.poleIDs; } request({ From f5ca4e0dd5c8a3f45b7dfcf2f48a9c24d64958d5 Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 4 May 2018 00:14:20 +0200 Subject: [PATCH 05/17] Added Config options overview --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5d5153b..571ce9e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ It monitors a given station in the RNV traffic network and shows the 10 upcoming Open a terminal session, navigate to your MagicMirror's `modules` folder and execute `git clone https://github.com/yawnsde/MMM-RNV.git`, a new folder called MMM-RNV will be created. Activate the module by adding it to the config.js file as shown below. Of course the position is up to you and the header is optional/customizable. -To find the id of your station take a look here: https://opendata.rnv-online.de/sites/default/files/Haltestellen_16.xml ## Using the module ````javascript @@ -22,4 +21,15 @@ modules: [ stationID: 'ENTER YOUR STATION ID HERE', } }, + ] ```` + +## Configuration options + +The following properties can be configured: + +| Option | Type | Description | Format | +| --- | --- | --- | --- | +| `apiKey` | String | Your personal API Key | 'abcdefghi123456' | +| `stationID` | String | The ID of your station. To find the ID of your station take a look here: https://opendata.rnv-online.de/sites/default/files/Haltestellen_16.xml | '1234' | +| `poleIDs` | String | The platform your transport leaves from. This can influence the direciton shown. Get the different poles by executing `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stations/detail?stationId=<stationID>`. To get the connections leaving from this pole, fire `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stationmonitor/element?hafasID=<stationID>&time=null&poles=<poleIDs>`| '1', for multiple poles: '1;5,6' | From 5cb95f7aaf806d0a340bcc2b18a97355394fed0c Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 4 May 2018 00:14:58 +0200 Subject: [PATCH 06/17] Fixed typo. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 571ce9e..f96063a 100644 --- a/README.md +++ b/README.md @@ -32,4 +32,4 @@ The following properties can be configured: | --- | --- | --- | --- | | `apiKey` | String | Your personal API Key | 'abcdefghi123456' | | `stationID` | String | The ID of your station. To find the ID of your station take a look here: https://opendata.rnv-online.de/sites/default/files/Haltestellen_16.xml | '1234' | -| `poleIDs` | String | The platform your transport leaves from. This can influence the direciton shown. Get the different poles by executing `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stations/detail?stationId=<stationID>`. To get the connections leaving from this pole, fire `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stationmonitor/element?hafasID=<stationID>&time=null&poles=<poleIDs>`| '1', for multiple poles: '1;5,6' | +| `poleIDs` | String | The platform your transport leaves from. This can influence the direciton shown. Get the different poles by executing `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stations/detail?stationId=<stationID>`. To get the connections leaving from this pole, fire `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stationmonitor/element?hafasID=<stationID>&time=null&poles=<poleIDs>`| '1', for multiple poles: '1;5;6' | From b6eea5c29fed1f24b06494abb23cd14c11a6761c Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 4 May 2018 00:38:07 +0200 Subject: [PATCH 07/17] Added walkingTimeOffset walkingTimeOffset is the time one need to reach the stop. --- MMM-RNV.js | 1 + 1 file changed, 1 insertion(+) diff --git a/MMM-RNV.js b/MMM-RNV.js index 7bb5079..a20f7fc 100644 --- a/MMM-RNV.js +++ b/MMM-RNV.js @@ -25,6 +25,7 @@ Module.register('MMM-RNV',{ requestURL: '/regions/rnv/modules/stationmonitor/element', stationID: '', poleIDs: '', + walkingTimeOffset: 0, iconTable: { "KOM": "fa fa-bus", From 6844b96618fc70f1cc13fd4a14ffe7a57f0d8a97 Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 4 May 2018 00:40:36 +0200 Subject: [PATCH 08/17] Added walkingTimeOffset, fixed formatting error - hh: Hours (12 hour time) HH: Hours (24 hour time) - added walkingTimeOffset it takes to reach stop --- node_helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_helper.js b/node_helper.js index 605c4b0..b289c7e 100644 --- a/node_helper.js +++ b/node_helper.js @@ -21,7 +21,7 @@ module.exports = NodeHelper.create({ getData: function() { var self = this; - var currentDate = moment().format('YYYY-MM-DD+hh:mm:ss'); + var currentDate = moment().add(this.config.walkingTimeOffset, 'm').format('YYYY-MM-DD+HH:mm:ss'); var myUrl = this.config.apiBase + this.config.requestURL + '?hafasID=' + this.config.stationID + '&time=' + currentDate; if(this.config.poleIDs != '') { myUrl += '&poles=' + this.config.poleIDs; From 68d45f11e9a1feb356a4b74e01b9b339c6aa9572 Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 4 May 2018 00:42:36 +0200 Subject: [PATCH 09/17] Added walkingTimeOffset config description --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f96063a..95ab16b 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,4 @@ The following properties can be configured: | `apiKey` | String | Your personal API Key | 'abcdefghi123456' | | `stationID` | String | The ID of your station. To find the ID of your station take a look here: https://opendata.rnv-online.de/sites/default/files/Haltestellen_16.xml | '1234' | | `poleIDs` | String | The platform your transport leaves from. This can influence the direciton shown. Get the different poles by executing `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stations/detail?stationId=<stationID>`. To get the connections leaving from this pole, fire `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stationmonitor/element?hafasID=<stationID>&time=null&poles=<poleIDs>`| '1', for multiple poles: '1;5;6' | +| `walkingTimeOffset` | int | Time it takes you to reach your station in minutes. | 0 | From c05e55b290dc139185206b118eb3e3f76d1b0ef6 Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Sat, 5 May 2018 11:21:31 +0200 Subject: [PATCH 10/17] Added walkingTimeOffset to departure processing --- MMM-RNV.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/MMM-RNV.js b/MMM-RNV.js index a20f7fc..441c44b 100644 --- a/MMM-RNV.js +++ b/MMM-RNV.js @@ -152,19 +152,30 @@ Module.register('MMM-RNV',{ for (var i in data.listOfDepartures) { var t = data.listOfDepartures[i]; - if ((t.time).indexOf(' ') > 0) { // time contains a date because it is not today - t.time = (t.time).substring((t.time).indexOf(' ')+1, (t.time).length); + var delay = 0; // delay of the trasportation + var departure = 0; // departure time of the transportation + var now = moment(); + + if((t.time).indexOf('+') > 0) { // if connection has a delay + delay = (t.time).substring((t.time).indexOf('+') + 1, (t.time).length); // parse delay + t.time = (t.time).substring(0, (t.time).indexOf('+')); // cut off the delay + } + + departure = moment(t.time, ["HH:mm", "DD.MM.YYYY HH:mm"]); + if(moment.duration(departure.add(delay, 'm').diff(now)).as('minutes') <= this.config.walkingTimeOffset) { + continue; // skip this entry if transport is not reachable in time: (departure + delay - now) <= walkingTimeOffset) } + this.departures.push({ - time: (t.time).substring(0,5), - delay: (((t.time).indexOf('+') > 0) ? (t.time).substring(6,(t.time).length) : 0), + time: departure.format('HH:mm'), + delay: delay, lineLabel: t.lineLabel, direction: t.direction, status: t.status, statusNote: t.statusNote, transportation: t.transportation, }); - + } return; From e0e27a87715dc90985fda2210e6313c4b44c7626 Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Sat, 5 May 2018 11:28:49 +0200 Subject: [PATCH 11/17] fixed typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95ab16b..be57eec 100644 --- a/README.md +++ b/README.md @@ -32,5 +32,5 @@ The following properties can be configured: | --- | --- | --- | --- | | `apiKey` | String | Your personal API Key | 'abcdefghi123456' | | `stationID` | String | The ID of your station. To find the ID of your station take a look here: https://opendata.rnv-online.de/sites/default/files/Haltestellen_16.xml | '1234' | -| `poleIDs` | String | The platform your transport leaves from. This can influence the direciton shown. Get the different poles by executing `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stations/detail?stationId=<stationID>`. To get the connections leaving from this pole, fire `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stationmonitor/element?hafasID=<stationID>&time=null&poles=<poleIDs>`| '1', for multiple poles: '1;5;6' | +| `poleIDs` | String | The platform your transport leaves from. This can influence the direction shown. Get the different poles by executing `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stations/detail?stationId=<stationID>`. To get the connections leaving from this pole, fire `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stationmonitor/element?hafasID=<stationID>&time=null&poles=<poleIDs>`| '1', for multiple poles: '1;5;6' | | `walkingTimeOffset` | int | Time it takes you to reach your station in minutes. | 0 | From 17f8152392e6db8b1f35553da01461589ede4336 Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Sat, 5 May 2018 11:56:45 +0200 Subject: [PATCH 12/17] fixed bug where delay is added to departure time --- MMM-RNV.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MMM-RNV.js b/MMM-RNV.js index 441c44b..7e61977 100644 --- a/MMM-RNV.js +++ b/MMM-RNV.js @@ -156,13 +156,14 @@ Module.register('MMM-RNV',{ var departure = 0; // departure time of the transportation var now = moment(); - if((t.time).indexOf('+') > 0) { // if connection has a delay + if((t.time).includes('+')) { // if connection has a delay (could be 0 as well) delay = (t.time).substring((t.time).indexOf('+') + 1, (t.time).length); // parse delay t.time = (t.time).substring(0, (t.time).indexOf('+')); // cut off the delay } departure = moment(t.time, ["HH:mm", "DD.MM.YYYY HH:mm"]); - if(moment.duration(departure.add(delay, 'm').diff(now)).as('minutes') <= this.config.walkingTimeOffset) { + d1 = departure.clone(); // workaround because if-condition changes var departure (adds the delay) for unknown reason + if(moment.duration(d1.add(delay, 'm').diff(now)).as('minutes') <= this.config.walkingTimeOffset) { continue; // skip this entry if transport is not reachable in time: (departure + delay - now) <= walkingTimeOffset) } From eeb0d473757fce13186e662b7a5a75fea29d6701 Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Sat, 5 May 2018 12:11:13 +0200 Subject: [PATCH 13/17] added new parameter numberOfShownDepartures --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index be57eec..8571458 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,4 @@ The following properties can be configured: | `stationID` | String | The ID of your station. To find the ID of your station take a look here: https://opendata.rnv-online.de/sites/default/files/Haltestellen_16.xml | '1234' | | `poleIDs` | String | The platform your transport leaves from. This can influence the direction shown. Get the different poles by executing `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stations/detail?stationId=<stationID>`. To get the connections leaving from this pole, fire `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stationmonitor/element?hafasID=<stationID>&time=null&poles=<poleIDs>`| '1', for multiple poles: '1;5;6' | | `walkingTimeOffset` | int | Time it takes you to reach your station in minutes. | 0 | +| `numberOfShownDepartures` | int | Number of shown departures. Has to be between 1 and 10. | 10 | From 0bf01efbeed964c11988399ceddc92e60aa4567b Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Sat, 5 May 2018 12:13:25 +0200 Subject: [PATCH 14/17] Added choice of how many departures to show --- MMM-RNV.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MMM-RNV.js b/MMM-RNV.js index 7e61977..5acc25a 100644 --- a/MMM-RNV.js +++ b/MMM-RNV.js @@ -26,6 +26,7 @@ Module.register('MMM-RNV',{ stationID: '', poleIDs: '', walkingTimeOffset: 0, + numberOfShownDepartures: 10, iconTable: { "KOM": "fa fa-bus", @@ -149,8 +150,12 @@ Module.register('MMM-RNV',{ this.departures = []; this.ticker = data.ticker; + var iterations = 0; for (var i in data.listOfDepartures) { + if(iterations == this.config.numberOfShownDepartures && this.config.numberOfShownDepartures > 0 && this.config.numberOfShownDepartures <= 10 ){ + break; + } var t = data.listOfDepartures[i]; var delay = 0; // delay of the trasportation var departure = 0; // departure time of the transportation @@ -176,7 +181,8 @@ Module.register('MMM-RNV',{ statusNote: t.statusNote, transportation: t.transportation, }); - + + iterations++; } return; From d3cc74651c71da5046e44c5cf92ae85ea662453d Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 11 May 2018 17:23:46 +0200 Subject: [PATCH 15/17] Added showZeroDelay documentation. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 8571458..522e2af 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,4 @@ The following properties can be configured: | `poleIDs` | String | The platform your transport leaves from. This can influence the direction shown. Get the different poles by executing `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stations/detail?stationId=<stationID>`. To get the connections leaving from this pole, fire `curl -H "RNV_API_TOKEN:<apiKey>" http://rnv.the-agent-factory.de:8080/easygo2/api/regions/rnv/modules/stationmonitor/element?hafasID=<stationID>&time=null&poles=<poleIDs>`| '1', for multiple poles: '1;5;6' | | `walkingTimeOffset` | int | Time it takes you to reach your station in minutes. | 0 | | `numberOfShownDepartures` | int | Number of shown departures. Has to be between 1 and 10. | 10 | +| `showZeroDelay` | bool | Shows delay for any connection which has already started even if 0. | false | From 91c7a5ec8ad3e21874c69decaa4d60764b08c412 Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 11 May 2018 17:24:34 +0200 Subject: [PATCH 16/17] Added nodelay css class. --- MMM-RNV.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/MMM-RNV.css b/MMM-RNV.css index e756b2b..ade7d75 100644 --- a/MMM-RNV.css +++ b/MMM-RNV.css @@ -2,6 +2,10 @@ color: #FF0000; } +.nodelay{ + color: #11aa41; +} + .rnvheader { text-align: left; } From 852faca069cb0036fb0b8ca37b7138f55ed56a1f Mon Sep 17 00:00:00 2001 From: gunrunner20 <38960053+gunrunner20@users.noreply.github.com> Date: Fri, 11 May 2018 17:26:13 +0200 Subject: [PATCH 17/17] Added function to display 0 delay when connection has already started. --- MMM-RNV.js | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/MMM-RNV.js b/MMM-RNV.js index 5acc25a..132a529 100644 --- a/MMM-RNV.js +++ b/MMM-RNV.js @@ -8,7 +8,7 @@ */ Module.register('MMM-RNV',{ - + defaults: { apiKey: "", units: config.units, @@ -21,24 +21,25 @@ Module.register('MMM-RNV',{ initialLoadDelay: 0, // 0 seconds delay retryDelay: 2500, - apiBase: 'http://rnv.the-agent-factory.de:8080/easygo2/api', + apiBase: 'http://rnv.the-agent-factory.de:8080/easygo2/api', requestURL: '/regions/rnv/modules/stationmonitor/element', stationID: '', poleIDs: '', walkingTimeOffset: 0, numberOfShownDepartures: 10, - + showZeroDelay: false, + iconTable: { "KOM": "fa fa-bus", "STRAB": "fa fa-subway" }, }, - + // Define required scripts. getScripts: function() { return ["moment.js", "font-awesome.css"]; }, - + getStyles: function() { return ['MMM-RNV.css']; }, @@ -68,18 +69,18 @@ Module.register('MMM-RNV',{ wrapper.innerHTML = this.translate('LOADING'); wrapper.className = "dimmed light small"; return wrapper; - } - + } + if (!this.departures.length) { wrapper.innerHTML = "No data"; wrapper.className = "dimmed light small"; return wrapper; } - + var table = document.createElement("table"); table.id = "rnvtable"; table.className = "small thin light"; - + var row = document.createElement("tr"); var timeHeader = document.createElement("th"); @@ -94,22 +95,28 @@ Module.register('MMM-RNV',{ var destinationHeader = document.createElement("th"); destinationHeader.innerHTML = "Fahrtrichtung"; destinationHeader.className = "rnvheader"; - row.appendChild(destinationHeader); + row.appendChild(destinationHeader); table.appendChild(row); - + for (var i in this.departures) { var currentDeparture = this.departures[i]; var row = document.createElement("tr"); table.appendChild(row); - + var cellDeparture = document.createElement("td"); cellDeparture.innerHTML = currentDeparture.time; cellDeparture.className = "timeinfo"; + if (currentDeparture.delay > 0) { var spanDelay = document.createElement("span"); spanDelay.innerHTML = ' +' + currentDeparture.delay; spanDelay.className = "small delay"; cellDeparture.appendChild(spanDelay); + } else if(currentDeparture.connectionIsLive && this.config.showZeroDelay) { + var spanDelay = document.createElement("span"); + spanDelay.innerHTML = ' +' + currentDeparture.delay; + spanDelay.className = "small nodelay"; + cellDeparture.appendChild(spanDelay); } row.appendChild(cellDeparture); @@ -119,19 +126,19 @@ Module.register('MMM-RNV',{ symbolTransportation.className = this.config.iconTable[currentDeparture.transportation]; cellTransport.appendChild(symbolTransportation); row.appendChild(cellTransport); - + var cellLine = document.createElement("td"); cellLine.innerHTML = currentDeparture.lineLabel; cellLine.className = "lineinfo"; row.appendChild(cellLine); - + var cellDirection = document.createElement("td"); cellDirection.innerHTML = currentDeparture.direction; cellDirection.className = "destinationinfo"; - row.appendChild(cellDirection); + row.appendChild(cellDirection); } wrapper.appendChild(table); - + if (this.ticker) { var marqueeTicker = document.createElement("marquee"); marqueeTicker.innerHTML = this.ticker; @@ -147,7 +154,7 @@ Module.register('MMM-RNV',{ if (!data.listOfDepartures) { return; } - + this.departures = []; this.ticker = data.ticker; var iterations = 0; @@ -159,9 +166,11 @@ Module.register('MMM-RNV',{ var t = data.listOfDepartures[i]; var delay = 0; // delay of the trasportation var departure = 0; // departure time of the transportation + var connectionIsLive = false; var now = moment(); - if((t.time).includes('+')) { // if connection has a delay (could be 0 as well) + if((t.time).includes('+')) { // if connection already started (showing delay, could be 0 as well) + connectionIsLive = true; delay = (t.time).substring((t.time).indexOf('+') + 1, (t.time).length); // parse delay t.time = (t.time).substring(0, (t.time).indexOf('+')); // cut off the delay } @@ -180,14 +189,15 @@ Module.register('MMM-RNV',{ status: t.status, statusNote: t.statusNote, transportation: t.transportation, + connectionIsLive: connectionIsLive, }); - + iterations++; } - + return; }, - + socketNotificationReceived: function(notification, payload) { if (notification === "STARTED") { this.updateDom(); @@ -197,6 +207,6 @@ Module.register('MMM-RNV',{ this.processDepartures(JSON.parse(payload)); this.updateDom(); } - } + } });