add entities per page dropdown

This commit is contained in:
Manuel Gugger 2022-07-26 22:34:33 +02:00
parent 130a2b4098
commit 38792b0fb5
3 changed files with 107 additions and 73 deletions

View File

@ -1,25 +1,31 @@
{% extends "base.html" %}
{% block content %}
<form method="post">
{% for model_field in view_model.fields -%}
{% if model_field.select_list != "" %}
<select name="{{ model_field.field_name }}">
{% if model_field.is_option %}
<option value="" selected></option>
{% else %}
<option value="" selected disabled>Select</option>
{% endif %}
{% for select_list_item in select_lists[model_field.field_name] -%}
<option value="{{ select_list_item[0] }}">{{ select_list_item[1] }}</option>
<article>
<form method="post">
{% for model_field in view_model.fields -%}
<label for="{{ model_field.field_name }}">
{{ model_field.field_name }}
{% if model_field.select_list != "" %}
<select name="{{ model_field.field_name }}">
{% if model_field.is_option %}
<option value="" selected></option>
{% else %}
<option value="" selected disabled>Select</option>
{% endif %}
{% for select_list_item in select_lists[model_field.field_name] -%}
<option value="{{ select_list_item[0] }}">{{ select_list_item[1] }}</option>
{%- endfor %}
</select>
{% else %}
<input type="{{ model_field.html_input_type }}" name="{{ model_field.field_name }}"
placeholder="{{ model_field.field_name }}" aria-label="{{ model_field.field_name }}">
<!-- required="" -->
{% endif %}
</label>
{%- endfor %}
</select>
{% else %}
<input type="{{ model_field.html_input_type }}" name="{{ model_field.field_name }}"
placeholder="{{ model_field.field_name }}" aria-label="{{ model_field.field_name }}"><!-- required="" -->
{% endif %}
{%- endfor %}
<button type="submit">Save</button>
<a href="{{ list_link }}" role="button" class="secondary">Cancel</a>
</form>
<button type="submit">Save</button>
<a href="{{ list_link }}" role="button" class="secondary">Cancel</a>
</form>
</article>
{% endblock content %}

View File

@ -1,24 +1,33 @@
{% extends "base.html" %}
{% block content %}
<form method="post">
<div>
{% for model_field in view_model.fields -%}
{% if model_field.select_list != "" %}
<select name="{{ model_field.field_name }}">
{% if model_field.is_option %}
<option value=""></option>
<article>
<form method="post">
<div>
{% for model_field in view_model.fields -%}
<label for="{{ model_field.field_name }}">
{{ model_field.field_name }}
{% if model_field.select_list != "" %}
<select name="{{ model_field.field_name }}">
{% if model_field.is_option %}
<option value=""></option>
{% endif %}
{% for select_list_item in select_lists[model_field.field_name] -%}
<option {% if select_list_item[0]==model.values | get(key=model_field.field_name) %} selected {%
endif %} value="{{ select_list_item[0] }}">{{ select_list_item[1] }}</option>
{%- endfor %}
</select>
</label>
{% else %}
<input type="{{ model_field.html_input_type }}" value="{{ model.values | get(key=model_field.field_name) }}"
name="{{ model_field.field_name }}" placeholder="{{ model_field.field_name }}"
aria-label="{{ model_field.field_name }}"><!-- required="" -->
{% endif %}
{% for select_list_item in select_lists[model_field.field_name] -%}
<option {% if select_list_item[0] == model.values | get(key=model_field.field_name) %} selected {% endif %} value="{{ select_list_item[0] }}">{{ select_list_item[1] }}</option>
</label>
{%- endfor %}
</select>
{% else %}
<input type="{{ model_field.html_input_type }}" value="{{ model.values | get(key=model_field.field_name) }}" name="{{ model_field.field_name }}" placeholder="{{ model_field.field_name }}" aria-label="{{ model_field.field_name }}"><!-- required="" -->
{% endif %}
{%- endfor %}
<button type="submit">Save</button>
<a href="{{ list_link }}" role="button" class="secondary">Cancel</a>
</div>
</form>
<button type="submit">Save</button>
<a href="{{ list_link }}" role="button" class="secondary">Cancel</a>
</div>
</form>
</article>
{% endblock content %}

View File

@ -1,45 +1,64 @@
{% extends "base.html" %}
{% block content %}
<a href="create" role="button">&#43;</a>
<table role="grid">
<thead>
<tr>
<th>{{ view_model.primary_key }}</th>
{% for model_field in view_model.fields -%}
<th>{{ model_field.field_name }}</th>
<article>
<div class="grid">
<div>
<a href="create" role="button">&#43;</a>
</div>
</div>
<table role="grid">
<thead>
<tr>
<th>{{ view_model.primary_key }}</th>
{% for model_field in view_model.fields -%}
<th>{{ model_field.field_name }}</th>
{%- endfor %}
<th>
<!-- Edit Action -->
<!-- Delete Action -->
</th>
</tr>
</thead>
<tbody hx-confirm="Are you sure?" hx-target="closest tr" hx-swap="outerHTML">
{% for entity in entities -%}
<tr>
<td>{{ entity.primary_key }}</td>
{% for model_field in view_model.fields -%}
<td>{{ entity.values | get(key=model_field.field_name) }}</td>
{%- endfor %}
<td>
<a href="edit/{{ entity.primary_key }}">&#9998;</a>
<a href="#" hx-post="delete/{{ entity.primary_key }}">&#128465;</a>
</td>
</tr>
{%- endfor %}
<th>
<!-- Edit Action -->
<!-- Delete Action -->
</th>
</tr>
</thead>
<tbody hx-confirm="Are you sure?" hx-target="closest tr" hx-swap="outerHTML">
{% for entity in entities -%}
<tr>
<td>{{ entity.primary_key }}</td>
{% for model_field in view_model.fields -%}
<td>{{ entity.values | get(key=model_field.field_name) }}</td>
{%- endfor %}
<td>
<a href="edit/{{ entity.primary_key }}">&#9998;</a>
<a href="#" hx-post="delete/{{ entity.primary_key }}">&#128465;</a>
</td>
</tr>
{%- endfor %}
</tbody>
<tfoot>
<tr>
<td colspan="{{ num_pages + 2 }}">
<div>
</tbody>
<tfoot>
<tr>
<td colspan="{{ view_model.fields | length + 2 }}">
<a href="?page={{ page - 1 }}&entities_per_page={{ entities_per_page }}">&laquo;</a>
{% for i in range(end=num_pages) %}
<a href="?page={{ i + 1 }}&entities_per_page={{ entities_per_page }}">{{ i + 1 }}</a>
{%- endfor %}
<a href="?page={{ page + 1 }}&entities_per_page={{ entities_per_page }}">&raquo;</a>
</td>
</tr>
</tfoot>
</table>
</td>
</tr>
</tfoot>
</table>
<div class="grid">
<div>
<form>
<label for="entities_per_page">Entities per Page
<select name="entities_per_page" onchange="this.form.submit()">
{% for a in [10,20,50,100,] %}
<option {% if entities_per_page == a %}selected{% endif %} value="{{ a }}">{{ a }}</option>
{% endfor %}
</select>
</label>
</form>
</div>
</div>
</article>
{% endblock content %}