Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nil case for scheduled arrivals #8

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion MMM-CTA.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@
const diffInMilliseconds = new Date(arrivalTime) - now;
const diffInMinutes = Math.floor(diffInMilliseconds / 1000 / 60);

return diffInMinutes === 0 ? 'DUE' : diffInMinutes.toString();
if (diffInMinutes === 0) {
return 'DUE'

Check failure on line 99 in MMM-CTA.js

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
} else if (diffInMinutes === 1) {

Check failure on line 100 in MMM-CTA.js

View workflow job for this annotation

GitHub Actions / lint

Unnecessary 'else' after 'return'
return diffInMinutes.toString() + ' min'

Check failure on line 101 in MMM-CTA.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected string concatenation

Check failure on line 101 in MMM-CTA.js

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
} else {
return diffInMinutes.toString() + ' mins'

Check failure on line 103 in MMM-CTA.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected string concatenation

Check failure on line 103 in MMM-CTA.js

View workflow job for this annotation

GitHub Actions / lint

Missing semicolon
}
},
});
58 changes: 31 additions & 27 deletions templates/MMM-CTA.njk
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,43 @@
{% if routeIcons %}
<th class="align-left"></th>
{% endif %}
{% if stop.arrivals[0].arrival %}
<th class="align-left">
{{ "DIRECTION" | translate }}
</th>

<th class="align-left">
{{ "DIRECTION" | translate }}
</th>

<th class="align-right">
{{ "ARRIVAL" | translate }}
</th>
<th class="align-right">
{{ "ARRIVAL" | translate }}
</th>
{% endif %}
</tr>
</thead>

<tbody>
{% for arrival in stop.arrivals %}
<tr class="small">
{% if routeIcons %}
<td class="icon-col align-left {{ arrival.routeColor }}">
{% if stop.type === 'train' %}
<i class="fa fa-train fa-sm cta-mr-5"></i>
{% elif stop.type === 'bus' %}
<i class="fa fa-bus fa-sm cta-mr-5"></i>
{% endif %}
</td>
{% endif %}
{% if stop.arrivals[0].arrival %}
{% for arrival in stop.arrivals %}
<tr class="small">
{% if routeIcons %}
<td class="icon-col align-left {{ arrival.routeColor }}">
{% if stop.type === 'train' %}
<i class="fa fa-train fa-sm cta-mr-5"></i>
{% elif stop.type === 'bus' %}
<i class="fa fa-bus fa-sm cta-mr-5"></i>
{% endif %}
</td>
{% endif %}

<td class="align-left">
{{ arrival.direction }}
</td>
<td class="align-left">
{{ arrival.direction }}
</td>

<td class="bright align-right bold">
{{ arrival.arrival }}
</td>
</tr>
{% endfor %}
<td class="bright align-right">
{{ arrival.arrival }}
</td>
</tr>
{% endfor %}
{% else %}
<td class="small">No planned arrivals.</td>
{% endif %}
</tbody>
</table>
{% endfor %}
Expand Down
Loading