-<style>
-
-.warning {
- background-color: navajowhite;
-}
-
-.bad {
- background-color: orangered;
- color: white;
-}
-
-.events {
- margin: 0.8em;
- margin-bottom: 1.5em;
- padding: 2px;
- border-spacing: 2em 0;
-}
-
-.events h3 {
- display: inline-block;
- margin-top: 1ex;
- margin-right: 0.7em;
-}
-
-.events-box {
- border: 1px solid black;
- padding: 0.5em;
- display: inline-block;
- vertical-align: top;
-}
-
-.events-box h4 {
- margin: 0.5ex;
-}
-.events-box .btnline {
- text-align: left;
-}
-.events-box input {
- padding: 1.5ex;
- margin: 0.5ex;
-}
-</style>
-
{###############}
{# Graphs etc. #}
{###############}
{##########}
{# Events #}
{##########}
- <br />
- <form>
- {%- macro event_box(title, events, warn_days=999, bad_days=9999) -%}
- {# Calculate maximum timestamp of all relevant events #}
- {%- set when = last_events.items() | selectattr(0, 'in', events) | map(attribute=1) | max -%}
- {%- set days = when | days | default(0) -%}
- <div class="events-box{% if days >= bad_days %} bad {% elif days >= warn_days %} warning{% endif %}">
- <h4>{{title | capitalize}}</h4>
- {#- The first item in the list is used as button label, last item in the overview -#}
- {%- set verb = {
- "COFFEE_MACHINE_CLEANED": ["cleaned"],
- "COFFEE_PACK_OPENED": ["opened"],
- "LAST_COFFEE_PACK_OPENED": ["last opened"],
- "MILK_CONTAINER_CLEANED": ["cleaned (water)", "cleaned"],
- "MILK_CONTAINER_CLEANED_WITH_TABLET": ["cleaned (tablet)"],
- }
- -%}
- {% if name -%} {# User logged in - show action buttons #}
- {%- for event in events %}
- <div class="btnline">
- <input type="button" value="{{ verb[event]|first }}"
- onclick="addEvent('{{ event }}', '{{ verb[events[0]]|last }} the {{ title }}')" />
- ({{ last_events[event] | humanize(max_interval="days") if event in last_events else "never" }})
- </div>
- {%- endfor -%}
- {%- else -%} {# Nobody logged in - show overview with summary times #}
- {%- if when -%}
- {{ verb[events[0]]|last }} {{ when | humanize(max_interval="days") }}
- {%- else -%}
- never {{ verb[events[0]]|last }}
- {%- endif -%}
- {%- endif %}
- </div>
- {%- endmacro %}
- <div class="events">
- <h3>{{ ("Record<br />event" if name else "Events") | safe }}:</h3>
- {{ event_box('coffee machine', ['COFFEE_MACHINE_CLEANED'] ) }}
- {{ event_box('milk container', ['MILK_CONTAINER_CLEANED', 'MILK_CONTAINER_CLEANED_WITH_TABLET'], warn_days=4, bad_days=7) }}
-
- {{ event_box('coffee pack', ['COFFEE_PACK_OPENED'] ) }}
- </div>
- </form>
+
+{% include "events.html" %}
{##################################}
{# User name and chip idnetifiers #}