{# 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. #} {# The info button after a title, when the schema has a "help" (a longer text than the description). It sits outside the label (a click never toggles a box) and carries its text in data attributes: help.js shows it in one popup. Not an id: rows are renumbered and forms swapped in and out. #} {% macro help_button(f) -%} {%- if f.help %}{% endif -%} {%- endmacro %} {# On a field's wrapper: what reset.js goes back to ("Reset to "), when the field can be reset #} {% macro reset_data(f) -%} {%- if f.can_reset %} data-default="{{ f.default_json }}" data-default-text="{{ f.default_text }}"{% endif -%} {%- endmacro %} {% macro label(f, with_for=true) -%}
{{ f.title }}{{ help_button(f) }}

{{ 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 %} {# A switch with a "copy_value": a "Shared as" row after it, shown while it is on, with the text and a copy button (copy_value.js) #} {% macro toggle(f) -%}
{{ label(f) }}
{%- if f.copy_value %}
Shared as{{ f.copy_text }}
{%- endif %} {%- 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, add_label) -%} {% set container = "array-container-" ~ f.key %}
{{ label(f, false) }}
{{ cards }}
{%- endmacro %} {% macro accordion(f, inner) -%}
{{ f.title }}{{ help_button(f) }}
{% if f.description %}

{{ f.description }}

{% endif %}{{ inner }}
{%- endmacro %} {# The readout is the number and its unit ("100 %"), or the min_label at the minimum ("Auto") #} {% macro slider(f) -%}
{{ label(f) }}
{{ f.slider_text(f.stored_value) }}
{%- endmacro %} {% macro number(f) -%}
{{ label(f) }} {%- if f.unit %}
{{ f.unit }}
{%- else %}{% endif %}
{%- 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) }} {%- if f.suggestions %}{% for name in f.suggestions %}{% endif %}
{%- 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 %}