{% extends "base.html" %} {% block title %}{{ t('design.editor_title') }}{% endblock %} {% block header %}
{{ t('design.title') }}

{% if is_new %} {{ t('design.new_report') }} {% else %} {{ code }} · {{ content.report_name }} {% endif %}

{% endblock %} {% block header_actions %}
{% if not is_new and draft %} {% if draft.status == 'DRAFT' %} {{ t('design.status_DRAFT') }} {% elif draft.status == 'PENDING' %} {{ t('design.status_PENDING') }} {% elif draft.status == 'APPROVED' %} {{ t('design.status_APPROVED') }} {% elif draft.status == 'REJECTED' %} {{ t('design.status_REJECTED') }} {% endif %} {% if auth and draft.author == auth.username and draft.status == 'PENDING' %}
{% endif %} {% if auth and ((auth.is_admin and draft.status != 'APPROVED') or (draft.author == auth.username and draft.status in ('DRAFT', 'REJECTED'))) %}
{% endif %} {% endif %} {{ t('design.back_to_list') }}
{% endblock %} {% block content %} {% if msg %} {% endif %} {% if not is_new and draft and draft.status == 'REJECTED' and draft.review_note %} {% endif %} {% if not is_new and draft and draft.test_summary %}

{{ t('design.last_test_title') }}

{% if draft.test_summary.ok %}
{{ t('design.test_passed_at', at=draft.test_summary.at, ms=draft.test_summary.duration_ms, count=draft.test_summary.row_count) }}
{% else %}
{{ t('design.test_failed_at', at=draft.test_summary.at, code=draft.test_summary.error_code, err=draft.test_summary.error) }}
{% endif %} {% if not is_tested and draft.status in ('DRAFT', 'REJECTED') %}
{{ t('design.test_needed_hint') }}
{% endif %}
{% endif %} {% if diff and auth and auth.is_admin and draft and draft.status == 'PENDING' %}

{{ t('design.review_panel') }}

{% if diff.fields %}

{{ t('design.fields_changed') }}

{% for fname, (old_v, new_v) in diff.fields.items() %} {% endfor %}
{{ t('design.field_name') }} {{ t('design.diff_live') }} {{ t('design.diff_proposed') }}
{{ fname }} {{ old_v if old_v is not none else '—' }} {{ new_v if new_v is not none else '—' }}
{% endif %} {% if diff.params.added or diff.params.removed or diff.params.changed %}
{{ t('design.params') }}: {% if diff.params.added %}+ {{ diff.params.added|join(', ') }}{% endif %} {% if diff.params.removed %}- {{ diff.params.removed|join(', ') }}{% endif %} {% if diff.params.changed %}~ {{ diff.params.changed|join(', ') }}{% endif %}
{% endif %} {% if diff.columns.added or diff.columns.removed or diff.columns.changed %}
{{ t('design.columns') }}: {% if diff.columns.added %}+ {{ diff.columns.added|join(', ') }}{% endif %} {% if diff.columns.removed %}- {{ diff.columns.removed|join(', ') }}{% endif %} {% if diff.columns.changed %}~ {{ diff.columns.changed|join(', ') }}{% endif %}
{% endif %}
{% for line in diff.query_diff %}{{ line }}{% else %}{{ t('design.no_diff') }}{% endfor %}

{{ t('design.approve') }}

{{ t('design.reject') }}

{% endif %} {% if test_result %}

{{ t('design.test_query') }}

{% if test_result.ok %}

{{ t('design.test_success') }}

{{ t('design.test_summary_text', count=test_result.row_count, ms=test_result.duration_ms) }}
{% if test_result.columns %}
{% for col in test_result.columns %} {% endfor %} {% for row in test_result.rows %} {% for val in row %} {% endfor %} {% else %} {% endfor %}
{{ col.name }} ({{ col.type }})
{{ val }}
{{ t('report.no_rows') }}
{% endif %} {% else %}

{{ t('design.test_failed') }}

{{ test_result.error_code }}: {{ test_result.error }}

{% endif %}
{% endif %} {% if errors %} {% endif %} {% if is_editor %}

{{ t('design.editor_title') }}

{% if not is_new and draft and draft.report_id is not none %} {% else %} {% endif %} {% if errors.report_code %}
{{ errors.report_code }}
{% endif %}
{% if errors.report_name %}
{{ errors.report_name }}
{% endif %}
{% if errors.group %}
{{ errors.group }}
{% endif %}
{% if errors.datasource %}
{{ errors.datasource }}
{% endif %}
{% if errors.query_text %}
{{ errors.query_text }}
{% endif %}

{{ t('design.params') }}

{% for p in content.params %} {% endfor %}
{{ t('design.is_active') }} {{ t('design.param_name') }} {{ t('design.label') }} {{ t('design.type') }} {{ t('design.input_kind') }} {{ t('design.is_required') }} {{ t('design.default_value') }} {{ t('design.options_query') }} {{ t('design.options_datasource') }} {{ t('design.advanced') }}
{% if errors['params.' ~ loop.index0 ~ '.param_name'] %}
{{ errors['params.' ~ loop.index0 ~ '.param_name'] }}
{% endif %}
{% if errors['params.' ~ loop.index0 ~ '.default_value'] %}
{{ errors['params.' ~ loop.index0 ~ '.default_value'] }}
{% endif %}
{% if errors['params.' ~ loop.index0 ~ '.advanced'] %}
{{ errors['params.' ~ loop.index0 ~ '.advanced'] }}
{% endif %}

{{ t('design.columns') }}

{% for c in content.columns %} {% endfor %}
{{ t('design.field_name') }} {{ t('design.label') }} {{ t('design.type') }} {{ t('design.display_format') }} {{ t('design.width_px') }} {{ t('design.align') }} {{ t('design.is_visible') }} {{ t('design.is_exported') }} {{ t('design.is_sortable') }} {{ t('design.is_filterable') }} {{ t('design.is_frozen') }} {{ t('design.footer_aggregate') }}
{% if errors['columns.' ~ loop.index0 ~ '.field_name'] %}
{{ errors['columns.' ~ loop.index0 ~ '.field_name'] }}
{% endif %}
{% if errors['columns.' ~ loop.index0 ~ '.display_format'] %}
{{ errors['columns.' ~ loop.index0 ~ '.display_format'] }}
{% endif %}
{% if not is_new %}

{{ t('design.test_params') }}

{% set active_params = [] %} {% for p in content.params %} {% if p.get('is_active', True) %} {% set _ = active_params.append(p) %} {% endif %} {% endfor %} {% if active_params %}
{% for p in active_params %}
{% if p.input_kind == 'multiselect' %} {{ t('design.test_param_multi_hint') }} {% endif %}
{% endfor %}
{% else %}

{{ t('design.no_test_params') }}

{% endif %}
{% endif %}
{% if is_new %} {% else %}
{% endif %}
{% if not is_new and draft %}
{% endif %} {% else %}

{{ t('design.report_name') }}

{{ t('design.readonly_hint') }}
{{ t('design.report_code') }}
{{ code }}
{{ t('design.report_name') }}
{{ content.report_name }}
{{ t('design.description') }}
{{ content.description or '—' }}
{{ t('design.group') }}
{{ content.group }}
{{ t('design.datasource') }}
{{ content.datasource }}
{{ t('design.cache_ttl') }}
{{ content.cache_ttl_seconds or 0 }}s

{{ t('design.query_text') }}

{{ content.query_text }}

{{ t('design.params') }}

{% for p in content.params %} {% else %} {% endfor %}
{{ t('design.param_name') }} {{ t('design.label') }} {{ t('design.type') }} {{ t('design.input_kind') }} {{ t('design.is_required') }} {{ t('design.default_value') }}
{{ p.param_name }} {{ p.label }} {{ p.data_type }} {{ p.input_kind }} {{ p.is_required }} {{ p.default_value or '—' }}
{{ t('design.no_params') }}

{{ t('design.columns') }}

{% for c in content.columns %} {% else %} {% endfor %}
{{ t('design.field_name') }} {{ t('design.label') }} {{ t('design.type') }} {{ t('design.display_format') }} {{ t('design.width_px') }} {{ t('design.align') }}
{{ c.field_name }} {{ c.label }} {{ c.data_type or '—' }} {{ c.display_format or '—' }} {{ c.width_px or '—' }} {{ c.align or '—' }}
{{ t('design.no_columns') }}
{% endif %} {% endblock %} {% block scripts %} {% endblock %}