{# 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 - check for widget first #} {% if field_type == 'object' %} {% set obj_widget = prop.get('x-widget') or prop.get('x_widget') %} {% if obj_widget == 'schedule-picker' %} {# Schedule picker widget - renders enable/mode/times UI #} {% set obj_value = value if value is not none else {} %}
{% if description %}

{{ description }}

{% endif %}
{% elif obj_widget == 'time-range' %} {# Time range widget - renders start/end time inputs #} {% set obj_value = value if value is not none else {} %}
{% if description %}

{{ description }}

{% endif %}
{% elif prop.properties %} {{ render_nested_section(key, prop, value, prefix, plugin_id) }} {% endif %} {% else %}
{% if description %}

{{ description }}

{% endif %} {# Boolean - check for widget first #} {% if field_type == 'boolean' %} {% set bool_widget = prop.get('x-widget') or prop.get('x_widget') %} {% if bool_widget == 'toggle-switch' %} {# Render toggle-switch widget #}
{% else %} {# Default checkbox - value="true" ensures checked sends "true" not "on" #} {% endif %} {# Enum dropdown #} {% elif prop.enum %} {# Number input - check for widget first #} {% elif field_type in ['number', 'integer'] %} {% set num_widget = prop.get('x-widget') or prop.get('x_widget') %} {% if num_widget in ['slider', 'number-input'] %} {# Render slider or number-input widget #}
{% else %} {# Default number input #} {% endif %} {# 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 #} {% elif x_widget == 'day-selector' %} {# Day selector widget for selecting days of the week #} {% 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 []) %}
{% 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 %} {% elif x_widget == 'array-table' %} {# Generic array-of-objects table widget - reads columns from schema #} {% set item_properties = items_schema.get('properties', {}) %} {% 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 []) %} {# Use x-columns if specified, otherwise auto-detect first 4 simple properties #} {% set x_columns = prop.get('x-columns') %} {% if x_columns %} {% set display_columns = x_columns %} {% else %} {% set display_columns = [] %} {% for col_name in item_properties.keys() %} {% set col_def = item_properties[col_name] %} {% if col_def.get('type') not in ['object', 'array'] and display_columns|length < 4 %} {% set _ = display_columns.append(col_name) %} {% endif %} {% endfor %} {% endif %}
{% for col_name in display_columns %} {% set col_def = item_properties.get(col_name, {}) %} {% set col_title = col_def.get('title', col_name|replace('_', ' ')|title) %} {% endfor %} {% for item in array_value %} {% set item_index = loop.index0 %} {% for col_name in display_columns %} {% set col_def = item_properties.get(col_name, {}) %} {% set col_type = col_def.get('type', 'string') %} {% set col_value = item.get(col_name, col_def.get('default', '')) %} {% endfor %} {% endfor %}
{{ col_title }}Actions
{% if col_type == 'boolean' %} {% elif col_type == 'integer' or col_type == 'number' %} {% else %} {% 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 %} {# String/default field - check for widgets #} {% else %} {% set str_widget = prop.get('x-widget') or prop.get('x_widget') %} {% set str_value = value if value is not none else (prop.default if prop.default is defined else '') %} {% if str_widget == 'file-upload' %} {# Single-file upload widget for string fields (e.g., credentials.json) #} {% set upload_config = prop.get('x-upload-config') or {} %} {% set upload_endpoint = upload_config.get('upload_endpoint', '') %} {% set target_filename = upload_config.get('target_filename', 'file.json') %} {% set max_size_mb = upload_config.get('max_size_mb', 1) %} {% set allowed_extensions = upload_config.get('allowed_extensions', ['.json']) %}

Click to upload {{ target_filename }}

Max {{ max_size_mb }}MB ({{ allowed_extensions|join(', ') }})

{% elif str_widget in ['text-input', 'textarea', 'select-dropdown', 'toggle-switch', 'radio-group', 'date-picker', 'slider', 'color-picker', 'email-input', 'url-input', 'password-input', 'font-selector'] %} {# Render widget container #}
{% else %} {# Default text input #} {% endif %} {% 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 #}