fewieden/MMM-NHL

View on GitHub
templates/MMM-NHL.njk

Summary

Maintainability
Test Coverage
{% if loading %}
    <div class="dimmed light">{{ "LOADING" | translate }}</div>
{% else %}
    <header>NHL {{ modes[season.mode] | translate }} {{ season.year }}</header>
    <table class="small table">
        <thead>
            <tr>
                <th><i class="fa fa-calendar"></i></th>
                <th colspan="{{ 1 + (1 if config.showNames else 0) + (1 if config.showLogos else 0) }}">
                    {{ "HOME" | translate }}
                </th>
                <th></th>
                <th colspan="{{ 1 + (1 if config.showNames else 0) + (1 if config.showLogos else 0) }}">
                    {{ "AWAY" | translate }}
                </th>
            </tr>
        </thead>
        <tbody>
            {% for index in range(rotateIndex, maxGames) %}
                <tr>
                    <td>
                        {% if games[index].status === "PRE" %}
                            {{ "PRE_GAME" | translate }}
                        {# TODO: Find out what the state postponed state is in the new API #}
                        {% elif games[index].status === "Postponed" %}
                            {{ "POSTPONED" | translate }}
                        {% elif games[index].status === "FUT" %}
                            {{ games[index] | formatStartDate }}
                        {% elif (games[index].status === "LIVE" or games[index].status === "CRIT") and games[index].live.period %}
                            {% if games[index].live.timeRemaining %}
                                <div class="live">{{ games[index].live.period | translate }}</div>
                                <div class="live">
                                    {{ "TIME_LEFT" | translate({TIME: games[index].live.timeRemaining}) }}
                                </div>
                            {% else %}
                                {{ games[index].live.period | translate }}
                            {% endif %}
                        {% else %}
                            {% if games[index].live.period === '3rd' %}
                                {{ "FINAL" | translate }}
                            {% else %}
                                {{ ("FINAL_" + games[index].live.periodType) | translate }}
                            {% endif %}
                        {% endif %}
                    </td>
                    {% if config.showNames %}
                        <td class="align-right">
                            {{ games[index].teams.home.short if games[index].teams.home.short else games[index].teams.home.name  }}
                        </td>
                    {% endif %}
                    {% if config.showLogos %}
                        <td>
                            <img class="icon {{ "no-color" if not config.colored }}"
                                 src="https://assets.nhle.com/logos/nhl/svg/{{games[index].teams.home.short}}_dark.svg"/>
                        </td>
                    {% endif %}
                    <td>{{ games[index].teams.home.score }}</td>
                    <td>:</td>
                    <td>{{ games[index].teams.away.score }}</td>
                    {% if config.showLogos %}
                        <td>
                            <img class="icon {{ "no-color" if not config.colored }}"
                                 src="https://assets.nhle.com/logos/nhl/svg/{{games[index].teams.away.short}}_dark.svg"/>
                        </td>
                    {% endif %}
                    {% if config.showNames %}
                        <td class="align-left">
                            {{ games[index].teams.away.short if games[index].teams.away.short else games[index].teams.away.name  }}
                        </td>
                    {% endif %}
                </tr>
            {% endfor %}
        </tbody>
    </table>
    {% if config.showPlayoffSeries and playoffSeries and playoffSeries.length > 0 %}
        <header style="margin-top: 10px">{{ "SERIES"  | translate }}</header>
        <table class="small table">
            <tbody>
                {% for series in playoffSeries %}
                    <tr>
                        {% if config.showNames %}
                            <td class="align-right">
                                {{ series.teams.home.short }}
                            </td>
                        {% endif %}
                        {% if config.showLogos %}
                            <td>
                                <img class="icon {{ "no-color" if not config.colored }}"
                                    src="https://assets.nhle.com/logos/nhl/svg/{{ series.teams.home.short }}_dark.svg"/>
                            </td>
                        {% endif %}
                        <td>{{ series.teams.home.score }}</td>
                        <td>:</td>
                        <td>{{ series.teams.away.score }}</td>
                        {% if config.showLogos %}
                            <td>
                                <img class="icon {{ "no-color" if not config.colored }}"
                                    src="https://assets.nhle.com/logos/nhl/svg/{{ series.teams.away.short }}_dark.svg"/>
                            </td>
                        {% endif %}
                        {% if config.showNames %}
                            <td class="align-left">
                                {{ series.teams.away.short }}
                            </td>
                        {% endif %}
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}
{% endif %}