{# The admin's forms from a JSON schema: one macro per kind of field, forms.py picks it. Autoescaped: titles, descriptions, options and values come from a module's author. A value in a JS string goes through tojson, since the browser decodes HTML escapes before the JS runs. #} {% macro label(f, with_for=true) -%}
{{ f.title }}

{{ f.description }}

{%- endmacro %} {# The schema's rules as the browser's own checks (setting_rules.py checks them again on save, ARCHITECTURE #49); pattern_message is the tooltip the browser shows with a value of the wrong format #} {% macro rules(f) -%} {%- if f.required %} required{% endif -%} {%- if f.schema.minimum is number %} min="{{ f.schema.minimum }}"{% endif -%} {%- if f.schema.maximum is number %} max="{{ f.schema.maximum }}"{% endif -%} {%- if f.schema.minLength is number %} minlength="{{ f.schema.minLength }}"{% endif -%} {%- if f.schema.maxLength is number %} maxlength="{{ f.schema.maxLength }}"{% endif -%} {%- if f.schema.pattern is string %} pattern="{{ f.schema.pattern }}"{% if f.schema.pattern_message %} title="{{ f.schema.pattern_message }}"{% endif %}{% endif -%} {%- endmacro %} {# An enum option's name: the schema's enum_titles (or enumNames) beside its enum, else the value with _ as a space and its first letter in capitals ("open_meteo" → "Open meteo") #} {% macro option_title(prop, index) -%} {% set titles = prop.get("enum_titles") or prop.get("enumNames") %} {{- titles[index] if titles and index < titles|length else ((prop["enum"][index]|string).replace("_", " ")[:1]|upper) ~ (prop["enum"][index]|string).replace("_", " ")[1:] -}} {%- endmacro %} {% macro options(prop, current) -%} {%- for opt in prop["enum"] %} {%- endfor %} {%- endmacro %} {% macro toggle(f) -%}
{{ label(f) }}
{%- endmacro %} {% macro select(f) -%}
{{ label(f) }} {{ options(f.schema, f.stored_value) }}
{%- endmacro %} {# The boxes of a list of choices; the hidden empty value saves "none ticked" as []. Without ids when in a list item: moving the item renames ids (admin.js reindexArrayContainer), and the label holds its box. #} {% macro checkbox_list(f, with_ids=true) -%} {% set chosen = f.stored_value if f.stored_value is sequence and f.stored_value is not string and f.stored_value is not mapping else [] %}
{%- for opt in f.schema["items"]["enum"] %} {%- endfor %}
{%- endmacro %} {% macro checkboxes(f) -%}
{{ label(f, false) }} {{ checkbox_list(f) }}
{%- endmacro %} {% macro array(f, cards, item_title) -%} {% set container = "array-container-" ~ f.key %}
{{ label(f, false) }}
{{ cards }}
{%- endmacro %} {% macro accordion(f, inner) -%}
{{ f.title }}
{% if f.description %}

{{ f.description }}

{% endif %}{{ inner }}
{%- endmacro %} {% macro slider(f) -%}
{{ label(f) }}
{{ f.value }}
{%- endmacro %} {% macro number(f) -%}
{{ label(f) }}
{%- endmacro %} {# A colour: the design's swatches, or any CSS colour typed (a var() too) #} {% macro color(f) -%}
{{ label(f) }}
{%- for title, value, preview_hex_color in SWATCHES %} {%- endfor %}
{%- endmacro %} {% macro password(f) -%}
{{ label(f) }}
{%- endmacro %} {% macro textarea(f) -%}
{{ label(f) }} {{ f.value }}
{%- endmacro %} {% macro text(f) -%}
{{ label(f) }}
{%- endmacro %} {# "HH:MM" or blank, in the browser's own time picker (24h or 12h as the phone has it) #} {% macro time(f) -%}
{{ label(f) }}
{%- endmacro %} {# An address at home the module may reach (client.py lets the module host through to it). The schema's default is only a hint, never filled in: saving the form must not open an address the owner didn't type. #} {% macro lan_url(f) -%}
{{ label(f) }}

MirrorDash lets this module reach this address on your home network, and nothing else there.

{%- endmacro %} {# A Lucide icon's name, drawn beside it as it is typed; admin.js suggests the names of the page's Lucide. #} {% macro icon_input(f, size="") -%}
{%- endmacro %} {% macro icon(f) -%}
{{ label(f) }} {{ icon_input(f) }}
{%- endmacro %} {# Files the owner uploads (features/modules/files.py): admin.js lists them as thumbnails, shrinks an image on the phone before sending it, and says why when it can't (settings not saved yet, a kind of file this version doesn't take). Nothing of it goes into the form: the files live in the module's cache folder. #} {% macro files(f) -%}
{{ label(f, false) }} {%- if f.instance_id %}

Loading…

{%- else %}

Files can't sit in a list or a group of settings.

{%- endif %}
{%- endmacro %} {# A list or search setting (ARCHITECTURE #48): its choices come from the module (choices.js setUpChoiceFields), saved as [id] and [name]. A list is the browser's own {%- else %}