{# Plugin Configuration Partial - Server-side rendered form #} {# This template is loaded via HTMX when a plugin tab is clicked #} {# ===== MACROS FOR FORM FIELD GENERATION ===== #} {# Render a single form field based on schema type #} {% macro render_field(key, prop, value, prefix='', plugin_id='') %} {% set full_key = (prefix ~ '.' ~ key) if prefix else key %} {% set field_id = (plugin_id ~ '-' ~ full_key)|replace('.', '-')|replace('_', '-') %} {% set label = prop.title if prop.title else key|replace('_', ' ')|title %} {% set description = prop.description if prop.description else '' %} {% set field_type = prop.type if prop.type is string else (prop.type[0] if prop.type is iterable else 'string') %} {# Handle nested objects recursively #} {% if field_type == 'object' and prop.properties %} {{ render_nested_section(key, prop, value, prefix, plugin_id) }} {% else %}
{% if description %}

{{ description }}

{% endif %} {# Boolean checkbox #} {% if field_type == 'boolean' %} {# Enum dropdown #} {% elif prop.enum %} {# Number input #} {% elif field_type in ['number', 'integer'] %} {# Array - check for file upload widget first (to avoid breaking static-image plugin), then checkbox-group, then array of objects #} {% elif field_type == 'array' %} {% set x_widget = prop.get('x-widget') or prop.get('x_widget') %} {% if x_widget == 'file-upload' %} {# File upload widget for arrays #} {% set upload_config = prop.get('x-upload-config') or {} %} {% set max_files = upload_config.get('max_files', 10) %} {% set allowed_types = upload_config.get('allowed_types', ['image/png', 'image/jpeg', 'image/bmp', 'image/gif']) %} {% set max_size_mb = upload_config.get('max_size_mb', 5) %} {% set plugin_id_from_config = upload_config.get('plugin_id', plugin_id) %} {% set array_value = value if value is not none and value is iterable and value is not string else (prop.default if prop.default is defined and prop.default is iterable and prop.default is not string else []) %}

Drag and drop images here or click to browse

Max {{ max_files }} files, {{ max_size_mb }}MB each (PNG, JPG, GIF, BMP)

Remember to save configuration after upload

{% for img in array_value %} {% set img_id = img.get('id', loop.index0) %} {% set img_schedule = img.get('schedule', {}) %} {% set has_schedule = img_schedule.get('enabled', false) and img_schedule.get('mode') and img_schedule.get('mode') != 'always' %}
{{ img.get('filename', '') }}

{{ img.get('original_filename') or img.get('filename', 'Image') }}

{% if img.get('size') %}{{ (img.get('size') / 1024)|round }} KB{% endif %} {% if img.get('uploaded_at') %} • {{ img.get('uploaded_at') }}{% endif %}

{% if has_schedule %}

Scheduled

{% endif %}
{% endfor %}
{% elif x_widget == 'checkbox-group' %} {# Checkbox group widget for multi-select arrays with enum items #} {% set array_value = value if value is not none and value is iterable and value is not string else (prop.default if prop.default is defined and prop.default is iterable and prop.default is not string else []) %} {% set items_schema = prop.get('items') or {} %} {% set enum_items = items_schema.get('enum') or [] %} {% set x_options = prop.get('x-options') or {} %} {% set labels = x_options.get('labels') or {} %}
{% for option in enum_items %} {% set is_checked = option in array_value %} {% set option_label = labels.get(option, option|replace('_', ' ')|title) %} {% set checkbox_id = (field_id ~ '_' ~ option)|replace('.', '_')|replace(' ', '_') %} {% endfor %}
{# Hidden input to store selected values as JSON array (like array-of-objects pattern) #} {# Sentinel hidden input with bracket notation to allow clearing array to [] when all unchecked #} {# This ensures the field is always submitted, even when all checkboxes are unchecked #} {% else %} {# Check for custom-feeds widget first #} {% set items_schema = prop.get('items') or {} %} {% if x_widget == 'custom-feeds' %} {# Custom feeds table interface - widget-specific implementation #} {# Validate that required fields exist in schema #} {% set item_properties = items_schema.get('properties', {}) %} {% if not (item_properties.get('name') and item_properties.get('url')) %} {# Fallback to generic if schema doesn't match expected structure #}

Custom feeds widget requires 'name' and 'url' properties in items schema.

{% else %} {% set max_items = prop.get('maxItems', 50) %} {% set array_value = value if value is not none and value is iterable and value is not string else (prop.default if prop.default is defined and prop.default is iterable and prop.default is not string else []) %}
{% for item in array_value %} {% set item_index = loop.index0 %} {% endfor %}
Name URL Logo Enabled Actions
{% set logo_value = item.get('logo') or {} %} {% set logo_path = logo_value.get('path', '') %}
{% if logo_path %} Logo {% else %} No logo {% endif %}
{% endif %} {% else %} {# Generic array-of-objects would go here if needed in the future #} {# For now, fall back to regular array input (comma-separated) #} {# Regular array input (comma-separated) #} {% set array_value = value if value is not none else (prop.default if prop.default is defined else []) %}

Separate multiple values with commas

{% endif %} {% endif %} {# Text input (default) #} {% else %} {% endif %}
{% endif %} {% endmacro %} {# Render a nested/collapsible section for object types #} {% macro render_nested_section(key, prop, value, prefix='', plugin_id='') %} {% set full_key = (prefix ~ '.' ~ key) if prefix else key %} {% set section_id = (plugin_id ~ '-section-' ~ full_key)|replace('.', '-')|replace('_', '-') %} {% set label = prop.title if prop.title else key|replace('_', ' ')|title %} {% set description = prop.description if prop.description else '' %} {% set nested_value = value if value else {} %}
{% endmacro %} {# ===== MAIN TEMPLATE ===== #}

{{ plugin.name or plugin.id }}

{{ plugin.description or 'Plugin configuration' }}

{# Plugin Information Panel #}

Plugin Information

Name
{{ plugin.name or plugin.id }}
Author
{{ plugin.author or 'Unknown' }}
{% if plugin.version %}
Version
{{ plugin.version }}
{% endif %} {% if plugin.last_commit %}
Commit
{{ plugin.last_commit[:7] if plugin.last_commit|length > 7 else plugin.last_commit }} {% if plugin.branch %} ({{ plugin.branch }}) {% endif %}
{% endif %} {% if plugin.category %}
Category
{{ plugin.category }}
{% endif %} {% if plugin.tags %}
Tags
{% for tag in plugin.tags %} {{ tag }} {% endfor %}
{% endif %}
{# On-Demand Controls #}
On-Demand Controls
{% if not plugin.enabled %}

Plugin is disabled, but on-demand will temporarily enable it.

{% endif %}
{# Configuration Form Panel #}

Configuration

{% if schema and schema.properties %} {# Use property order if defined, otherwise use natural order #} {# Skip 'enabled' field - it's handled by the header toggle #} {% set property_order = schema['x-propertyOrder'] if 'x-propertyOrder' in schema else schema.properties.keys()|list %} {% for key in property_order %} {% if key in schema.properties and key != 'enabled' %} {% set prop = schema.properties[key] %} {% set value = config[key] if key in config else none %} {{ render_field(key, prop, value, '', plugin.id) }} {% endif %} {% endfor %} {% else %} {# No schema - render simple form from config #} {% if config %} {% for key, value in config.items() %} {% if key not in ['enabled'] %}
{% if value is sameas true or value is sameas false %} {% elif value is number %} {% else %} {% endif %}
{% endif %} {% endfor %} {% else %}

No configuration options available for this plugin.

{% endif %} {% endif %}
{# Web UI Actions (if any) #} {% if web_ui_actions %}

Plugin Actions

{% if web_ui_actions[0].section_description %}

{{ web_ui_actions[0].section_description }}

{% endif %}
{% for action in web_ui_actions %} {% set action_id = "action-" ~ action.id ~ "-" ~ loop.index0 %} {% set status_id = "action-status-" ~ action.id ~ "-" ~ loop.index0 %} {% set bg_color = action.color or 'blue' %} {% if bg_color == 'green' %} {% set bg_class = 'bg-green-50' %} {% set border_class = 'border-green-200' %} {% set text_class = 'text-green-900' %} {% set text_light_class = 'text-green-700' %} {% set btn_class = 'bg-green-600 hover:bg-green-700' %} {% elif bg_color == 'red' %} {% set bg_class = 'bg-red-50' %} {% set border_class = 'border-red-200' %} {% set text_class = 'text-red-900' %} {% set text_light_class = 'text-red-700' %} {% set btn_class = 'bg-red-600 hover:bg-red-700' %} {% elif bg_color == 'yellow' %} {% set bg_class = 'bg-yellow-50' %} {% set border_class = 'border-yellow-200' %} {% set text_class = 'text-yellow-900' %} {% set text_light_class = 'text-yellow-700' %} {% set btn_class = 'bg-yellow-600 hover:bg-yellow-700' %} {% elif bg_color == 'purple' %} {% set bg_class = 'bg-purple-50' %} {% set border_class = 'border-purple-200' %} {% set text_class = 'text-purple-900' %} {% set text_light_class = 'text-purple-700' %} {% set btn_class = 'bg-purple-600 hover:bg-purple-700' %} {% else %} {% set bg_class = 'bg-blue-50' %} {% set border_class = 'border-blue-200' %} {% set text_class = 'text-blue-900' %} {% set text_light_class = 'text-blue-700' %} {% set btn_class = 'bg-blue-600 hover:bg-blue-700' %} {% endif %}

{% if action.icon %}{% endif %}{{ action.title or action.id }}

{{ action.description or '' }}

{% endfor %}
{% endif %} {# Action Buttons #}