Some layout tweaks.

This commit is contained in:
Yaro Kasear 2025-10-09 10:25:23 -05:00
parent 3c07741500
commit 9181ba660f
5 changed files with 80 additions and 65 deletions

View file

@ -15,11 +15,19 @@ def _fields_for_model(model: str):
layout = [] layout = []
if model == "inventory": if model == "inventory":
fields = [] fields = [
"label",
"name",
"serial",
"barcode",
"model",
"condition",
"notes",
]
fields_spec = [ fields_spec = [
{"name": "label", "type": "display", "label": "", "row": "label", {"name": "label", "type": "display", "label": "", "row": "label",
"attrs": {"class": "display-6 mb-3"}, "wrap": {"class": "col"}}, "attrs": {"class": "display-6 mb-3"}, "wrap": {"class": "col"}},
{"name": "submit", "label": "", "row": "label", "type": "template", "template": "submit_button.html", {"name": "submit", "label": "", "row": "label", "type": "template", "template": "entry_buttons.html",
"wrap": {"class": "col-auto text-end me-2"}, "attrs": {"data-model": model}}, "wrap": {"class": "col-auto text-end me-2"}, "attrs": {"data-model": model}},
{"name": "name", "row": "names", "label": "Name", "wrap": {"class": "col-3"}, {"name": "name", "row": "names", "label": "Name", "wrap": {"class": "col-3"},
"attrs": {"class": "form-control"}, "label_attrs": {"class": "form-label"}}, "attrs": {"class": "form-control"}, "label_attrs": {"class": "form-label"}},
@ -70,11 +78,18 @@ def _fields_for_model(model: str):
] ]
elif model.lower() == 'user': elif model.lower() == 'user':
fields = [] fields = [
"label",
"first_name",
"last_name",
"title",
"active",
"staff"
]
fields_spec = [ fields_spec = [
{"name": "label", "row": "label", "label": "", "type": "display", {"name": "label", "row": "label", "label": "", "type": "display",
"attrs": {"class": "display-6 mb-3"}, "wrap": {"class": "col"}}, "attrs": {"class": "display-6 mb-3"}, "wrap": {"class": "col"}},
{"name": "submit", "label": "", "row": "label", "type": "template", "template": "submit_button.html", {"name": "submit", "label": "", "row": "label", "type": "template", "template": "entry_buttons.html",
"wrap": {"class": "col-auto text-end me-2"}, "attrs": {"data-model": model}}, "wrap": {"class": "col-auto text-end me-2"}, "attrs": {"data-model": model}},
{"name": "last_name", "label": "Last Name", "label_attrs": {"class": "form-label"}, {"name": "last_name", "label": "Last Name", "label_attrs": {"class": "form-label"},
"attrs": {"placeholder": "Doe", "class": "form-control"}, "row": "name", "wrap": {"class": "col-3"}}, "attrs": {"placeholder": "Doe", "class": "form-control"}, "row": "name", "wrap": {"class": "col-3"}},
@ -119,7 +134,7 @@ def _fields_for_model(model: str):
fields_spec = [ fields_spec = [
{"name": "id", "label": "", "type": "display", "label_spec": "Work Item #{id}", {"name": "id", "label": "", "type": "display", "label_spec": "Work Item #{id}",
"attrs": {"class": "display-6 mb-3"}, "row": "label", "wrap": {"class": "col"}}, "attrs": {"class": "display-6 mb-3"}, "row": "label", "wrap": {"class": "col"}},
{"name": "submit", "label": "", "row": "label", "type": "template", "template": "submit_button.html", {"name": "submit", "label": "", "row": "label", "type": "template", "template": "entry_buttons.html",
"wrap": {"class": "col-auto text-end me-2"}, "attrs": {"data-model": model}}, "wrap": {"class": "col-auto text-end me-2"}, "attrs": {"data-model": model}},
{"name": "contact", "row": "ownership", "wrap": {"class": "col"}, "label": "Contact", {"name": "contact", "row": "ownership", "wrap": {"class": "col"}, "label": "Contact",
"label_spec": "{label}", "attrs": {"class": "form-control"}, "label_attrs": {"class": "form-label"}}, "label_spec": "{label}", "attrs": {"class": "form-control"}, "label_attrs": {"class": "form-label"}},
@ -139,6 +154,7 @@ def _fields_for_model(model: str):
{"name": "ownership", "order": 10, "attrs": {"class": "row mb-2"}}, {"name": "ownership", "order": 10, "attrs": {"class": "row mb-2"}},
{"name": "timestamps", "order": 20, "attrs": {"class": "row d-flex align-items-center"}}, {"name": "timestamps", "order": 20, "attrs": {"class": "row d-flex align-items-center"}},
{"name": "updates", "order": 30, "attrs": {"class": "row"}}, {"name": "updates", "order": 30, "attrs": {"class": "row"}},
{"name": "buttons"},
] ]
return (fields, fields_spec, layout) return (fields, fields_spec, layout)

View file

@ -1,4 +1,4 @@
<div class="table-responsive mx-5" style="max-height: 80vh;"> <div class="table-responsive" style="max-height: 80vh;">
<table class="table table-info table-striped table-hover table-bordered border-tertiary text-nowrap overflow-x-auto mx-auto"> <table class="table table-info table-striped table-hover table-bordered border-tertiary text-nowrap overflow-x-auto mx-auto">
<thead> <thead>
<tr> <tr>

View file

@ -1,4 +1,8 @@
<button type="submit" class="btn btn-primary" id="submit">Save</button> <div class="btn-group">
<button type="submit" class="btn btn-primary" id="submit">Save</button>
<button type="button" class="btn btn-outline-primary" onclick="location.href='{{ url_for("entry.entry_new", model=(field['attrs']['data-model'])) }}'">New</button>
</div>
<script> <script>
window.newDrafts = window.newDrafts || []; window.newDrafts = window.newDrafts || [];
window.deletedIds = window.deletedIds || []; window.deletedIds = window.deletedIds || [];

View file

@ -5,52 +5,47 @@ Inventory Manager - {{ model|title }} Listing
{% endblock %} {% endblock %}
{% block main %} {% block main %}
<div class="container-fluid"> <div class="mx-5">
<h1 class="display-4 text-center mt-5">{{ model|title }} Listing</h1> <h1 class="display-4 text-center mt-2">{{ model|title }} Listing</h1>
<div class="btn-group"> <div class="btn-group">
<button type="button" class="btn btn-primary mb-3" <button type="button" class="btn btn-primary mb-3"
onclick="location.href='{{ url_for('entry.entry_new', model=model) }}'">New</button> onclick="location.href='{{ url_for('entry.entry_new', model=model) }}'">New</button>
</div> </div>
{{ table | safe }}
<nav class="d-flex justify-content-center my-2" aria-label="Pagination">
<ul class="pagination mb-0">
{# Prev #}
<li class="page-item {% if not pagination.has_prev %}disabled{% endif %}">
<a class="page-link" href="{{ pagination.prev_url if pagination.has_prev else '#' }}"
aria-label="Previous">Previous</a>
</li>
{# Numbered pages with ellipses #}
{% for item in pagination.nav %}
{% if item.type == 'page' %}
<li class="page-item {% if item.active %}active{% endif %}">
<a class="page-link" href="{{ item.url }}" {% if item.active %}aria-current="page" {% endif %}>{{ item.n }}</a>
</li>
{% elif item.type == 'ellipsis' %}
<li class="page-item disabled">
<a class="page-link" tabindex="-1" aria-disabled="true"></a>
</li>
{% endif %}
{% endfor %}
{# Next #}
<li class="page-item {% if not pagination.has_next %}disabled{% endif %}">
<a class="page-link" href="{{ pagination.next_url if pagination.has_next else '#' }}" aria-label="Next">Next</a>
</li>
</ul>
</nav>
</div> </div>
{{ table | safe }} <p class="text-center text-muted small mb-2">
<nav class="d-flex justify-content-center my-4" aria-label="Pagination">
<ul class="pagination mb-0">
{# Prev #}
<li class="page-item {% if not pagination.has_prev %}disabled{% endif %}">
<a class="page-link"
href="{{ pagination.prev_url if pagination.has_prev else '#' }}"
aria-label="Previous">Previous</a>
</li>
{# Numbered pages with ellipses #}
{% for item in pagination.nav %}
{% if item.type == 'page' %}
<li class="page-item {% if item.active %}active{% endif %}">
<a class="page-link"
href="{{ item.url }}"
{% if item.active %}aria-current="page"{% endif %}>{{ item.n }}</a>
</li>
{% elif item.type == 'ellipsis' %}
<li class="page-item disabled">
<a class="page-link" tabindex="-1" aria-disabled="true"></a>
</li>
{% endif %}
{% endfor %}
{# Next #}
<li class="page-item {% if not pagination.has_next %}disabled{% endif %}">
<a class="page-link"
href="{{ pagination.next_url if pagination.has_next else '#' }}"
aria-label="Next">Next</a>
</li>
</ul>
</nav>
<p class="text-center text-muted small mb-5">
Page {{ pagination.page }} of {{ pagination.pages }} · {{ pagination.total }} records Page {{ pagination.page }} of {{ pagination.pages }} · {{ pagination.total }} records
</p> </p>
{% endblock %} {% endblock %}

View file

@ -1,5 +1,19 @@
{% set items = (field.template_ctx.instance.updates or []) %} {% set items = (field.template_ctx.instance.updates or []) %}
<div class="mt-3">
<label class="form-label">Add update</label>
<textarea id="newUpdateInput" class="form-control auto-md" rows="3" placeholder="Write a new update..."></textarea>
<div class="mt-2 d-flex gap-2">
<button type="button" class="btn btn-primary btn-sm" onclick="addNewDraft()">Add</button>
<button type="button" class="btn btn-outline-secondary btn-sm" onclick="clearNewDraft()">Clear</button>
</div>
<div id="newDraftsList" class="mt-3 d-none">
<div class="fw-semibold mb-1">Pending new updates</div>
<ul class="list-group" id="newDraftsUl"></ul>
</div>
</div>
<ul class="list-group mt-3"> <ul class="list-group mt-3">
{% for n in items %} {% for n in items %}
<li class="list-group-item"> <li class="list-group-item">
@ -30,20 +44,6 @@
{% endfor %} {% endfor %}
</ul> </ul>
<div class="mt-3">
<label class="form-label">Add update</label>
<textarea id="newUpdateInput" class="form-control auto-md" rows="3" placeholder="Write a new update..."></textarea>
<div class="mt-2 d-flex gap-2">
<button type="button" class="btn btn-primary btn-sm" onclick="addNewDraft()">Add</button>
<button type="button" class="btn btn-outline-secondary btn-sm" onclick="clearNewDraft()">Clear</button>
</div>
<div id="newDraftsList" class="mt-3 d-none">
<div class="fw-semibold mb-1">Pending new updates</div>
<ul class="list-group" id="newDraftsUl"></ul>
</div>
</div>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@5/github-markdown.min.css"> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@5/github-markdown.min.css">
<style> <style>
textarea.auto-md { textarea.auto-md {