ddstats-server/views/components/_utils.njk

56 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

2021-11-05 11:30:17 +01:00
{% macro fancyTime(inputSecs) %}
{% set seconds = inputSecs | round(0, "floor") %}
{% set hourSecs = seconds % 3600 %}
{% set hours = (seconds - hourSecs) / 3600 %}
{% set minSecs = (seconds - hours * 3600) % 60 %}
{% set mins = (seconds - hours * 3600 - minSecs) / 60 %}
{% set secsMillis = (inputSecs - hours * 3600 - mins * 60) | round(2) | float %}
{% set secs = secsMillis | round(0, "floor") %}
{% set millis = ((secsMillis - (secsMillis | round(0, "floor"))) * 100) | round(2) %}
{%- if hours -%}
{{- hours -}}:
{%- endif -%}
{%- if mins < 10 -%}
0{{- mins -}}:
{%- elif mins > 9 -%}
{{- mins -}}:
{%- endif -%}
{%- if secs < 10 -%}
0{{- secs -}}.
{%- elif secs > 9 -%}
{{- secs -}}.
{%- endif -%}
{%- if millis < 10 -%}
0{{- millis -}}
{%- elif millis > 9 -%}
{{- millis -}}
{%- endif -%}
2021-11-13 20:12:01 +01:00
{% endmacro %}
2021-11-13 21:28:28 +01:00
{% macro pageLink(pageNum, currentPage, queries) %}
{#
Yes! :D
I feel like I have brain damage...
#}
<a class="page {{ "current-page" if currentPage === pageNum }}" href="?{% for query, value in queries %}{{ query if query !== "page" }}{{ "=" if query !== "page" }}{{ value if query !== "page" }}{{ "&" if query !== "page" }}{% endfor %}page={{ pageNum }}">{{ pageNum }}</a>
{% endmacro %}
{% macro pager(pageNum, maxPage, queries) %}
{{ pageLink(1, pageNum, queries) }}
2021-11-13 20:12:01 +01:00
<p>{{ "..." if (pageNum - 2 > 1) }}</p>
{% for page in range(pageNum - 2, pageNum + 3) %}
{% if page > 1 and page < maxPage %}
2021-11-13 21:28:28 +01:00
{{ pageLink(page, pageNum, queries) }}
2021-11-13 20:12:01 +01:00
{% endif %}
{% endfor %}
<p>{{ "..." if (pageNum + 2 < maxPage) }}</p>
{% if maxPage > 1 %}
2021-11-13 21:28:28 +01:00
{{ pageLink(maxPage, pageNum, queries) }}
2021-11-13 20:12:01 +01:00
{% endif %}
2021-11-05 11:30:17 +01:00
{% endmacro %}