221 lines
11 KiB
HTML
221 lines
11 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(nav.locale, nav.tr("td-could-not-add-column"), message) %}{% endcall %}{% endif -%}
|
|
{%- if let Some(message) = page.status %}{% call panel_toast::success(nav.tr("td-staged"), message) %}{% endcall %}{% endif -%}
|
|
{%- if let Some(message) = page.error %}{% call panel_dialog::error(nav.locale, nav.tr("td-could-not-add-column"), message) %}{% endcall %}{% endif -%}
|
|
{% endif %}
|
|
|
|
<div class="form-grid">
|
|
<label>{% if page.columns.show_link_target() %}{{ nav.tr("td-link-alias") }}{% else %}{{ nav.tr("td-column-name") }}{% endif %}
|
|
<input name="column_name_input" value="{{ page.columns.name_input }}" placeholder="issued_on">
|
|
{% if page.columns.show_link_target() %}<small>{{ nav.tr("td-link-alias-hint") }}</small>{% endif %}
|
|
</label>
|
|
<label>{{ nav.tr("td-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="">{{ nav.tr("td-choose-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" %}{{ nav.tr("td-fk-link") }}{% else %}{{ column_type }}{% endif %}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</label>
|
|
|
|
{% if page.columns.show_temporal_type() %}
|
|
<label>{{ nav.tr("td-temporal-type") }}
|
|
<select name="temporal_type_input">
|
|
<option value="">{{ nav.tr("td-choose-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>{{ nav.tr("td-gtin-type") }}
|
|
<select name="gtin_type_input">
|
|
<option value="">{{ nav.tr("td-choose-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>{{ nav.tr("td-precision") }}
|
|
<input name="decimal_precision_input" value="{{ page.columns.decimal_precision_input }}"
|
|
inputmode="numeric" placeholder="12">
|
|
<small>{{ nav.tr("td-precision-hint") }}</small>
|
|
</label>
|
|
<label>{{ nav.tr("td-scale") }}
|
|
<input name="decimal_scale_input" value="{{ page.columns.decimal_scale_input }}"
|
|
inputmode="numeric" placeholder="3">
|
|
<small>{{ nav.tr("td-scale-hint") }}</small>
|
|
</label>
|
|
{% endif %}
|
|
|
|
{% if page.columns.show_link_target() %}
|
|
<label>{{ nav.tr("td-referenced-table") }}
|
|
<select name="link_table_input">
|
|
<option value="">{{ nav.tr("td-choose-table") }}</option>
|
|
{% if !page.global_link_target_tables().is_empty() %}
|
|
<optgroup label="{{ nav.tr("td-group-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="{{ nav.tr("td-group-user") }}">
|
|
{% 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="{{ nav.tr("td-group-system") }}">
|
|
{% 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>{{ nav.tr("td-no-eligible-tables") }}</small>{% endif %}
|
|
</label>
|
|
{% endif %}
|
|
|
|
{% if page.columns.show_money_options() %}
|
|
<label>{{ nav.tr("td-currency") }}
|
|
<input name="column_currency_input" value="{{ page.columns.currency_input }}" list="currency-codes"
|
|
maxlength="3" placeholder="EUR">
|
|
</label>
|
|
<label>{{ nav.tr("td-rounding") }}
|
|
<select name="column_rounding_input">
|
|
<option value="none" {% if page.columns.rounding_input != "half-up" %}selected{% endif %}>{{ nav.tr("td-rounding-none") }}</option>
|
|
<option value="half-up" {% if page.columns.rounding_input == "half-up" %}selected{% endif %}>{{ nav.tr("td-rounding-half-up") }}</option>
|
|
</select>
|
|
</label>
|
|
{% endif %}
|
|
|
|
{#
|
|
A link is left out rather than defaulted to "no": the server builds an
|
|
index for every foreign key as it adds the column, and refuses a request
|
|
that asks for one on top.
|
|
#}
|
|
{% if page.columns.show_indexing() %}
|
|
<label>{{ nav.tr("td-indexing") }}
|
|
<select name="column_indexing_input">
|
|
<option value="no" {% if page.columns.indexing_input != "yes" %}selected{% endif %}>{{ nav.tr("common-no") }}</option>
|
|
<option value="yes" {% if page.columns.indexing_input == "yes" %}selected{% endif %}>{{ nav.tr("common-yes") }}</option>
|
|
</select>
|
|
</label>
|
|
{% else if page.columns.pending_is_auto_indexed() %}
|
|
<div class="field-note">
|
|
<span class="field-label">{{ nav.tr("td-indexing") }}</span>
|
|
<p class="hint">{{ nav.tr("td-indexed-automatically") }}</p>
|
|
</div>
|
|
{% endif %}
|
|
<label>{{ nav.tr("td-required") }}
|
|
<select name="column_required_input">
|
|
<option value="no" {% if page.columns.required_input != "yes" %}selected{% endif %}>{{ nav.tr("common-no") }}</option>
|
|
<option value="yes" {% if page.columns.required_input == "yes" %}selected{% endif %}>{{ nav.tr("common-yes") }}</option>
|
|
</select>
|
|
<small>{{ nav.tr("td-required-hint") }}</small>
|
|
</label>
|
|
{% if page.columns.show_quantity_ledger() %}
|
|
<label>{{ nav.tr("td-quantity-ledger") }}
|
|
<select name="column_quantity_ledger_input">
|
|
<option value="no" {% if page.columns.quantity_ledger_input != "yes" %}selected{% endif %}>{{ nav.tr("common-no") }}</option>
|
|
<option value="yes" {% if page.columns.quantity_ledger_input == "yes" %}selected{% endif %}>{{ nav.tr("common-yes") }}</option>
|
|
</select>
|
|
<small>{{ nav.tr_args("td-ql-only", [("types", page.columns.quantity_ledger_types())]) }}</small>
|
|
</label>
|
|
{% else %}
|
|
<p class="hint">{{ nav.tr("td-shared-no-quantity-ledger") }}</p>
|
|
{% endif %}
|
|
</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"}'>{{ nav.tr("td-stage-column") }}</button>
|
|
|
|
{% if page.columns.added.is_empty() %}
|
|
<p class="hint">{{ nav.tr("td-no-staged-columns") }} <em>{{ nav.tr("td-stage-column") }}</em>.</p>
|
|
{% else %}
|
|
<table class="builder-table">
|
|
<thead><tr><th>{{ nav.tr("td-col-name") }}</th><th>{{ nav.tr("td-col-type") }}</th><th>{{ nav.tr("td-col-indexed") }}</th><th>{{ nav.tr("td-col-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 if column.is_indexed() %}
|
|
<span class="tag">{{ nav.tr("td-indexed-automatically-tag") }}</span>
|
|
{% else %}
|
|
<span class="hint">—</span>
|
|
{% endif %}
|
|
</td>
|
|
<td>
|
|
{% if column.required %}<span class="tag">{{ nav.tr("column-flag-required") }}</span>{% endif %}
|
|
{% if column.quantity_ledger %}<span class="tag">{{ nav.tr("column-flag-quantity-ledger") }}</span>{% endif %}
|
|
{% if !column.currency.is_empty() %}<span class="tag">{{ column.currency }}, {{ column.money_mode.display_label(nav.locale) }}</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 }}"}'>{{ nav.tr("common-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_required" value="{% if column.required %}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">{{ nav.tr_count("td-add-columns-button", "count", page.columns.added.len() as i64) }}</button>
|
|
</div>
|