Files
komp_ac/web/templates/pages/admin/table_definition/column_panel.html
2026-08-12 23:40:14 +02:00

194 lines
9.1 KiB
HTML

{#
The append-columns panel —
crate::pages::admin::table_definition::ui::ColumnPanelFragment, and what
workspace.html embeds inside #column-form.
Staging a column writes nothing, so these buttons swap this panel alone.
Saving is the form's own submit, which swaps the whole workspace. The field
names are the ones crate::schema::ColumnForm declares — the same set the
Add-table builder posts, decoded by the same code.
#}
{#
Staging swaps this panel and nothing else, so a refused column has nowhere
else to be reported. When the workspace embeds the panel it reports the
outcome at the top instead, and this block stays out of the way.
#}
{% import "ui/alert.html" as panel_alert %}
{% import "ui/dialog.html" as panel_dialog %}
{% import "ui/toast.html" as panel_toast %}
{% if standalone_column_panel %}
{%- if let Some(message) = page.error %}{% call panel_alert::error("Could not add the column", message) %}{% endcall %}{% endif -%}
{%- if let Some(message) = page.status %}{% call panel_toast::success("Staged", message) %}{% endcall %}{% endif -%}
{%- if let Some(message) = page.error %}{% call panel_dialog::error("Could not add the column", message) %}{% endcall %}{% endif -%}
{% endif %}
<div class="form-grid">
<label>{% if page.columns.show_link_target() %}Link alias{% else %}Column name{% endif %}
<input name="column_name_input" value="{{ page.columns.name_input }}" placeholder="issued_on">
{% if page.columns.show_link_target() %}<small>The alias is the column name used to distinguish this relationship.</small>{% endif %}
</label>
<label>Column type
<select name="column_type_input"
hx-post="/admin/tables/columns/builder{{ page.selection.query() }}"
hx-trigger="change" hx-include="#column-form"
hx-target="#column-panel" hx-swap="innerHTML"
hx-vals='{"action": "refresh"}'>
<option value="">Choose a type</option>
{% for column_type in column_types %}
<option value="{{ column_type }}" {% if page.columns.type_input == *column_type %}selected{% endif %}>{% if *column_type == "link" %}FKlink{% else %}{{ column_type }}{% endif %}</option>
{% endfor %}
</select>
</label>
{% if page.columns.show_temporal_type() %}
<label>Temporal type
<select name="temporal_type_input">
<option value="">Choose a temporal type</option>
{% for temporal_type in temporal_types %}
<option value="{{ temporal_type }}" {% if page.columns.temporal_type_input == *temporal_type %}selected{% endif %}>{{ temporal_type }}</option>
{% endfor %}
</select>
</label>
{% endif %}
{% if page.columns.show_gtin_type() %}
<label>GTIN type
<select name="gtin_type_input">
<option value="">Choose a GTIN length</option>
{% for gtin_type in gtin_types %}
<option value="{{ gtin_type }}" {% if page.columns.gtin_type_input == *gtin_type %}selected{% endif %}>GTIN-{{ gtin_type }}</option>
{% endfor %}
</select>
</label>
{% endif %}
{% if page.columns.show_decimal_arguments() %}
<label>Precision
<input name="decimal_precision_input" value="{{ page.columns.decimal_precision_input }}"
inputmode="numeric" placeholder="12">
<small>Total digits stored, at least 1.</small>
</label>
<label>Scale
<input name="decimal_scale_input" value="{{ page.columns.decimal_scale_input }}"
inputmode="numeric" placeholder="3">
<small>Digits after the point, no more than the precision.</small>
</label>
{% endif %}
{% if page.columns.show_link_target() %}
<label>Referenced table
<select name="link_table_input">
<option value="">Choose a table</option>
{% if !page.global_link_target_tables().is_empty() %}
<optgroup label="Global">
{% for table in page.global_link_target_tables() %}
<option value="{{ table }}" {% if page.columns.link_table_input == *table %}selected{% endif %}>{{ table }}</option>
{% endfor %}
</optgroup>
{% endif %}
{% if !page.user_link_target_tables().is_empty() %}
<optgroup label="User-created">
{% for table in page.user_link_target_tables() %}
<option value="{{ table }}" {% if page.columns.link_table_input == *table %}selected{% endif %}>{{ table }}</option>
{% endfor %}
</optgroup>
{% endif %}
{% if !page.system_link_target_tables().is_empty() %}
<optgroup label="System-created">
{% for table in page.system_link_target_tables() %}
<option value="{{ table }}" {% if page.columns.link_table_input == *table %}selected{% endif %}>{{ table }}</option>
{% endfor %}
</optgroup>
{% endif %}
</select>
{% if page.global_link_target_tables().is_empty() && page.user_link_target_tables().is_empty() && page.system_link_target_tables().is_empty() %}<small>No eligible tables exist in this scope.</small>{% endif %}
</label>
{% endif %}
{% if page.columns.show_money_options() %}
<label>Currency
<input name="column_currency_input" value="{{ page.columns.currency_input }}" list="currency-codes"
maxlength="3" placeholder="EUR">
</label>
<label>Rounding
<select name="column_rounding_input">
<option value="none" {% if page.columns.rounding_input != "half-up" %}selected{% endif %}>none</option>
<option value="half-up" {% if page.columns.rounding_input == "half-up" %}selected{% endif %}>half-up</option>
</select>
</label>
{% endif %}
<label>Indexing
<select name="column_indexing_input">
<option value="no" {% if page.columns.indexing_input != "yes" %}selected{% endif %}>no</option>
<option value="yes" {% if page.columns.indexing_input == "yes" %}selected{% endif %}>yes</option>
</select>
</label>
<label>Quantity ledger
<select name="column_quantity_ledger_input">
<option value="no" {% if page.columns.quantity_ledger_input != "yes" %}selected{% endif %}>no</option>
<option value="yes" {% if page.columns.quantity_ledger_input == "yes" %}selected{% endif %}>yes</option>
</select>
<small>{{ page.columns.quantity_ledger_types() }} only.</small>
</label>
</div>
<button type="button" class="secondary"
hx-post="/admin/tables/columns/builder{{ page.selection.query() }}"
hx-include="#column-form" hx-target="#column-panel" hx-swap="innerHTML"
hx-vals='{"action": "add-column"}'>Stage column</button>
{% if page.columns.added.is_empty() %}
<p class="hint">No columns staged yet. Describe one above and press <em>Stage column</em>.</p>
{% else %}
<table class="builder-table">
<thead><tr><th>Name</th><th>Type</th><th>Indexed</th><th>Options</th><th></th></tr></thead>
<tbody>
{% for column in page.columns.added %}
<tr>
<td><code>{{ column.name }}</code></td>
<td>{{ column.data_type }}</td>
<td>
{# A compound column expands into schema-managed companions, so
there is no column of its own name to index. #}
{% if page.columns.is_indexable(*loop.index0) %}
<button type="button" class="toggle"
hx-post="/admin/tables/columns/builder{{ page.selection.query() }}"
hx-include="#column-form" hx-target="#column-panel" hx-swap="innerHTML"
hx-vals='{"action": "toggle-index", "index": "{{ loop.index0 }}"}'>
{% if column.indexed %}[x]{% else %}[ ]{% endif %}
</button>
{% else %}
<span class="hint"></span>
{% endif %}
</td>
<td>
{% if column.quantity_ledger %}<span class="tag">quantity ledger</span>{% endif %}
{% if !column.option_label().is_empty() %}<span class="tag">{{ column.option_label() }}</span>{% endif %}
</td>
<td>
<button type="button" class="danger"
hx-post="/admin/tables/columns/builder{{ page.selection.query() }}"
hx-include="#column-form" hx-target="#column-panel" hx-swap="innerHTML"
hx-vals='{"action": "remove-column", "index": "{{ loop.index0 }}"}'>Remove</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
{# The staged columns themselves: one set of fields per column, in order. #}
{% for column in page.columns.added %}
<input type="hidden" name="column_names" value="{{ column.name }}">
<input type="hidden" name="column_types" value="{{ column.data_type }}">
<input type="hidden" name="column_indexed" value="{% if column.indexed %}yes{% else %}no{% endif %}">
<input type="hidden" name="column_quantity_ledger" value="{% if column.quantity_ledger %}yes{% else %}no{% endif %}">
<input type="hidden" name="column_rounding" value="{{ column.money_mode.label() }}">
<input type="hidden" name="column_currencies" value="{{ column.currency }}">
{% endfor %}
<div class="form-actions">
<button type="submit">Add {{ page.columns.added.len() }} column(s) to the table</button>
</div>