Tighten Recent Orders table layout and labels UI
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -55,6 +55,10 @@ class Order(models.Model):
|
||||
def custom_count(self):
|
||||
return sum(int(line['count']) for line in (self.custom_labels or []))
|
||||
|
||||
@property
|
||||
def box_weight(self):
|
||||
return self.canister_weight * self.canisters_per_box
|
||||
|
||||
def apply_weight(self):
|
||||
"""Derive canister/box counts from total_weight (create path)."""
|
||||
self.canister_count = math.ceil(self.total_weight / self.canister_weight)
|
||||
|
||||
@@ -513,15 +513,93 @@ input:focus, select:focus {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.table-wrap-capped {
|
||||
max-height: calc(100dvh - 10rem);
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
/* Keep td as table-cell so width:1% shrinks the column; flex lives inside. */
|
||||
.labels-cell {
|
||||
width: 1%;
|
||||
}
|
||||
|
||||
.label-counts {
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 0.35rem;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.label-counts > .count-stepper,
|
||||
.label-counts > .mono,
|
||||
.label-counts > [id^="custom-"],
|
||||
.label-counts .custom-label-list,
|
||||
.label-counts .custom-label-list .count-stepper,
|
||||
.label-counts .custom-label-list .mono {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.label-counts > [id^="custom-"]:empty {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.label-counts > [id^="custom-"],
|
||||
.label-counts .custom-label-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.label-counts .count-stepper {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(max-content, 1fr) 1.5rem 2.25rem 1.5rem;
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.label-counts .count-stepper .stepper-label {
|
||||
justify-self: start;
|
||||
margin-inline-start: 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.status-cell {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.status-cell .badge + .badge,
|
||||
.status-cell .badge + button.badge {
|
||||
margin-inline-start: 0.35rem;
|
||||
}
|
||||
|
||||
button.badge {
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
button.badge:hover {
|
||||
filter: brightness(0.92);
|
||||
}
|
||||
|
||||
.data-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
text-align: left;
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
.data-table th, .data-table td {
|
||||
padding: 0.85rem 1rem;
|
||||
border-bottom: 1px solid var(--border);
|
||||
text-align: start;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
@media (min-width: 1400px) {
|
||||
@@ -565,7 +643,7 @@ input:focus, select:focus {
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.badge-pending { background: rgba(245, 158, 11, 0.1); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
|
||||
.badge-pending { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }
|
||||
.badge-done { background: rgba(16, 185, 129, 0.1); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.2); }
|
||||
.badge-cancelled { background: rgba(239, 68, 68, 0.1); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }
|
||||
.badge-accent { background: var(--accent-soft); color: var(--brand-hover); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
|
||||
|
||||
@@ -32,6 +32,7 @@ const translations = {
|
||||
'boxes': 'Boxes',
|
||||
'canisters_unit': 'Canisters',
|
||||
'boxes_unit': 'Boxes',
|
||||
'labels': 'Labels',
|
||||
'custom': 'Custom',
|
||||
'custom_unit': 'Custom',
|
||||
'custom_labels': 'Custom Labels',
|
||||
@@ -41,6 +42,9 @@ const translations = {
|
||||
'pages_needed': 'Pages Needed',
|
||||
'total_pages': 'Pages',
|
||||
'status_pending': 'Pending',
|
||||
'status_done': 'Done',
|
||||
'status_printing': 'Printing',
|
||||
'status_cancelled': 'Cancelled',
|
||||
'add_to_queue': 'Add to Print Queue',
|
||||
'recent_orders': 'Recent Orders',
|
||||
'status': 'Status',
|
||||
@@ -87,6 +91,7 @@ const translations = {
|
||||
'boxes': 'تعداد کارتن',
|
||||
'canisters_unit': 'گالن',
|
||||
'boxes_unit': 'کارتن',
|
||||
'labels': 'برچسبها',
|
||||
'custom': 'سفارشی',
|
||||
'custom_unit': 'سفارشی',
|
||||
'custom_labels': 'برچسب سفارشی',
|
||||
@@ -96,6 +101,9 @@ const translations = {
|
||||
'pages_needed': 'تعداد صفحات',
|
||||
'total_pages': 'صفحات',
|
||||
'status_pending': 'در انتظار',
|
||||
'status_done': 'انجام شد',
|
||||
'status_printing': 'در حال چاپ',
|
||||
'status_cancelled': 'لغو شده',
|
||||
'add_to_queue': 'افزودن به صف چاپ',
|
||||
'recent_orders': 'سفارشات اخیر',
|
||||
'status': 'وضعیت',
|
||||
@@ -146,6 +154,15 @@ function applyLanguage(lang) {
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-i18n-title]').forEach(el => {
|
||||
const key = el.getAttribute('data-i18n-title');
|
||||
if (translations[lang][key]) el.title = translations[lang][key];
|
||||
});
|
||||
document.querySelectorAll('[data-i18n-aria]').forEach(el => {
|
||||
const key = el.getAttribute('data-i18n-aria');
|
||||
if (translations[lang][key]) el.setAttribute('aria-label', translations[lang][key]);
|
||||
});
|
||||
|
||||
// Button shows the language you can switch to
|
||||
const toggleBtn = document.getElementById('lang-label');
|
||||
if (toggleBtn) {
|
||||
@@ -218,12 +235,18 @@ async function adjustCount(id, field, delta) {
|
||||
}
|
||||
}
|
||||
|
||||
function formatWeight(w) {
|
||||
const n = Number(w);
|
||||
if (!Number.isFinite(n)) return String(w);
|
||||
return Number.isInteger(n) ? String(n) : String(parseFloat(n.toFixed(6)));
|
||||
}
|
||||
|
||||
function renderCustomLabels(id, labels, pending) {
|
||||
const cell = document.getElementById(`custom-${id}`);
|
||||
if (!cell) return;
|
||||
const lines = (labels || []).filter((line) => line && Number(line.count) > 0);
|
||||
if (!lines.length) {
|
||||
cell.textContent = '—';
|
||||
cell.replaceChildren();
|
||||
return;
|
||||
}
|
||||
const list = document.createElement('div');
|
||||
@@ -231,16 +254,17 @@ function renderCustomLabels(id, labels, pending) {
|
||||
lines.forEach((line, i) => {
|
||||
const weight = Number(line.weight);
|
||||
const count = Number(line.count);
|
||||
const weightLabel = formatWeight(weight);
|
||||
const row = document.createElement('div');
|
||||
if (!pending) {
|
||||
row.className = 'mono';
|
||||
row.textContent = `${weight} kg × ${count}`;
|
||||
row.textContent = `${weightLabel} kg × ${count}`;
|
||||
} else {
|
||||
row.className = 'count-stepper';
|
||||
row.dataset.weight = String(weight);
|
||||
const label = document.createElement('span');
|
||||
label.className = 'stepper-label';
|
||||
label.textContent = `${weight} kg`;
|
||||
label.textContent = `${weightLabel} kg`;
|
||||
const down = document.createElement('button');
|
||||
down.type = 'button';
|
||||
down.className = 'stepper-btn';
|
||||
|
||||
@@ -82,19 +82,16 @@
|
||||
<h2 class="card-title" data-i18n="recent_orders">Recent Orders</h2>
|
||||
<span class="card-badge badge-muted" id="order-count">{{ orders|length }}</span>
|
||||
</div>
|
||||
<div class="table-wrap">
|
||||
<div class="table-wrap table-wrap-capped">
|
||||
<table class="data-table" id="orders-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th data-i18n="product">Product</th>
|
||||
<th data-i18n="batch_number">Batch</th>
|
||||
<th data-i18n="canisters">Canisters</th>
|
||||
<th data-i18n="boxes">Boxes</th>
|
||||
<th data-i18n="custom">Custom</th>
|
||||
<th data-i18n="labels">Labels</th>
|
||||
<th data-i18n="total_pages">Pages</th>
|
||||
<th data-i18n="status">Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="orders-body">
|
||||
@@ -103,60 +100,63 @@
|
||||
<td class="mono">{{ o.id }}</td>
|
||||
<td>{{ o.product.code }}</td>
|
||||
<td class="mono">{{ o.batch_number }}</td>
|
||||
<td>
|
||||
{% if o.status == 'pending' %}
|
||||
<div class="count-stepper">
|
||||
<button type="button" class="stepper-btn" onclick="adjustCount({{ o.id }}, 'canister_count', -1)" aria-label="-">−</button>
|
||||
<span id="cc-{{ o.id }}">{{ o.canister_count }}</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCount({{ o.id }}, 'canister_count', 1)" aria-label="+">+</button>
|
||||
</div>
|
||||
{% else %}
|
||||
{{ o.canister_count }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if o.status == 'pending' %}
|
||||
<div class="count-stepper">
|
||||
<button type="button" class="stepper-btn" onclick="adjustCount({{ o.id }}, 'box_count', -1)" aria-label="-">−</button>
|
||||
<span id="bc-{{ o.id }}">{{ o.box_count }}</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCount({{ o.id }}, 'box_count', 1)" aria-label="+">+</button>
|
||||
</div>
|
||||
{% else %}
|
||||
{{ o.box_count }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td id="custom-{{ o.id }}">
|
||||
{% if o.custom_labels %}
|
||||
<div class="custom-label-list">
|
||||
<td class="labels-cell">
|
||||
<div class="label-counts">
|
||||
{% if o.status == 'pending' %}
|
||||
{% for line in o.custom_labels %}
|
||||
<div class="count-stepper" data-weight="{{ line.weight }}">
|
||||
<span class="stepper-label">{{ line.weight }} kg</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCustomCount({{ o.id }}, {{ forloop.counter0 }}, -1)" aria-label="-">−</button>
|
||||
<span class="cl-count">{{ line.count }}</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCustomCount({{ o.id }}, {{ forloop.counter0 }}, 1)" aria-label="+">+</button>
|
||||
<div class="count-stepper">
|
||||
<span class="stepper-label">{{ o.canister_weight|floatformat:-2 }} kg</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCount({{ o.id }}, 'canister_count', -1)" aria-label="-">−</button>
|
||||
<span id="cc-{{ o.id }}">{{ o.canister_count }}</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCount({{ o.id }}, 'canister_count', 1)" aria-label="+">+</button>
|
||||
</div>
|
||||
<div class="count-stepper">
|
||||
<span class="stepper-label">{{ o.box_weight|floatformat:-2 }} kg</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCount({{ o.id }}, 'box_count', -1)" aria-label="-">−</button>
|
||||
<span id="bc-{{ o.id }}">{{ o.box_count }}</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCount({{ o.id }}, 'box_count', 1)" aria-label="+">+</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% for line in o.custom_labels %}
|
||||
<div class="mono">{{ line.weight }} kg × {{ line.count }}</div>
|
||||
{% endfor %}
|
||||
<div class="mono">{{ o.canister_weight|floatformat:-2 }} kg × <span id="cc-{{ o.id }}">{{ o.canister_count }}</span></div>
|
||||
<div class="mono">{{ o.box_weight|floatformat:-2 }} kg × <span id="bc-{{ o.id }}">{{ o.box_count }}</span></div>
|
||||
{% endif %}
|
||||
<div id="custom-{{ o.id }}">
|
||||
{% if o.custom_labels %}
|
||||
<div class="custom-label-list">
|
||||
{% if o.status == 'pending' %}
|
||||
{% for line in o.custom_labels %}
|
||||
<div class="count-stepper" data-weight="{{ line.weight }}">
|
||||
<span class="stepper-label">{{ line.weight|floatformat:-2 }} kg</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCustomCount({{ o.id }}, {{ forloop.counter0 }}, -1)" aria-label="-">−</button>
|
||||
<span class="cl-count">{{ line.count }}</span>
|
||||
<button type="button" class="stepper-btn" onclick="adjustCustomCount({{ o.id }}, {{ forloop.counter0 }}, 1)" aria-label="+">+</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% for line in o.custom_labels %}
|
||||
<div class="mono">{{ line.weight|floatformat:-2 }} kg × {{ line.count }}</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
—
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="mono" id="pages-{{ o.id }}">{{ o.canister_pages|add:o.box_pages }}</td>
|
||||
<td><span class="badge badge-{{ o.status }}">{{ o.get_status_display }}</span></td>
|
||||
<td>
|
||||
<td class="status-cell">
|
||||
{% if o.status == 'pending' %}
|
||||
<button class="btn btn-ghost btn-sm btn-danger" onclick="deleteOrder({{ o.id }})" data-i18n="remove">Remove</button>
|
||||
<span class="badge badge-pending">⏳ <span data-i18n="status_pending">Pending</span></span>
|
||||
<button type="button" class="badge badge-pending" onclick="deleteOrder({{ o.id }})" title="حذف" aria-label="حذف" data-i18n-title="remove" data-i18n-aria="remove">×</button>
|
||||
{% elif o.status == 'done' %}
|
||||
<span class="badge badge-done">✓ <span data-i18n="status_done">Done</span></span>
|
||||
{% elif o.status == 'printing' %}
|
||||
<span class="badge badge-accent">🖨 <span data-i18n="status_printing">Printing</span></span>
|
||||
{% else %}
|
||||
<span class="badge badge-cancelled">✕ <span data-i18n="status_cancelled">Cancelled</span></span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr><td colspan="9" class="empty-state" data-i18n="no_orders">No orders yet</td></tr>
|
||||
<tr><td colspan="6" class="empty-state" data-i18n="no_orders">No orders yet</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user