Add article copy icons to individual order lists
This commit is contained in:
1 parent
6f2e322b74
commit
552a17fbc9
8 files changed
+79
-73
No files matched your search
@@ -325,8 +325,7 @@ main {
|
||||
gap: 20px;
|
||||
margin-bottom: clamp(22px, 3vw, 36px);
|
||||
}
|
||||
.order-page-actions,
|
||||
.order-shop-links {
|
||||
.order-page-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
@@ -339,6 +338,46 @@ main {
|
||||
.article-copy [hidden] {
|
||||
display: none;
|
||||
}
|
||||
.article-copy .article-copy-icon-button {
|
||||
min-height: 30px;
|
||||
min-width: 30px;
|
||||
padding: 0;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.article-copy-icon {
|
||||
position: relative;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
}
|
||||
.article-copy-icon::before,
|
||||
.article-copy-icon::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
width: 8px;
|
||||
height: 10px;
|
||||
border: 1px solid currentColor;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.article-copy-icon::before {
|
||||
top: 0;
|
||||
left: 1px;
|
||||
}
|
||||
.article-copy-icon::after {
|
||||
right: 1px;
|
||||
bottom: 0;
|
||||
background: var(--surface-solid);
|
||||
}
|
||||
.article-copy-icon-button[data-copy-state] {
|
||||
background: var(--light);
|
||||
}
|
||||
.article-copy-icon-button[data-copy-state="copied"] .article-copy-icon::before {
|
||||
content: "✓";
|
||||
position: static;
|
||||
border: 0;
|
||||
}
|
||||
.article-copy-icon-button[data-copy-state="copied"] .article-copy-icon::after {
|
||||
display: none;
|
||||
}
|
||||
.eyebrow {
|
||||
letter-spacing: 2px;
|
||||
font-size: 10px;
|
||||
|
||||
+8
-4
@@ -3,16 +3,18 @@
|
||||
const copyStatus = document.querySelector("[data-copy-status]");
|
||||
|
||||
for (const button of document.querySelectorAll("[data-copy-article]")) {
|
||||
const article = button.closest(".article-copy").querySelector("[data-article-code]");
|
||||
const label = button.querySelector("[data-copy-label]");
|
||||
button.hidden = false;
|
||||
let resetLabel;
|
||||
button.addEventListener("click", async () => {
|
||||
const article = document.getElementById(button.dataset.copyArticle);
|
||||
const code = article.textContent.trim();
|
||||
clearTimeout(resetLabel);
|
||||
copyStatus.textContent = "";
|
||||
try {
|
||||
await navigator.clipboard.writeText(code);
|
||||
button.textContent = "Kopiert";
|
||||
button.dataset.copyState = "copied";
|
||||
if (label) label.textContent = "Kopiert";
|
||||
copyStatus.textContent = `Artikelnummer ${code} kopiert.`;
|
||||
} catch {
|
||||
const range = document.createRange();
|
||||
@@ -20,11 +22,13 @@ for (const button of document.querySelectorAll("[data-copy-article]")) {
|
||||
const selection = window.getSelection();
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
button.textContent = "Markiert";
|
||||
button.dataset.copyState = "selected";
|
||||
if (label) label.textContent = "Markiert";
|
||||
copyStatus.textContent = "Artikelnummer markiert. Kopiere die Auswahl.";
|
||||
}
|
||||
resetLabel = setTimeout(() => {
|
||||
button.textContent = "Kopieren";
|
||||
delete button.dataset.copyState;
|
||||
if (label) label.textContent = "Kopieren";
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
@@ -53,8 +53,12 @@ class CatalogTests(CatalogTestCase):
|
||||
self.assertContains(response, 'referrerpolicy="no-referrer"', count=1)
|
||||
self.assertContains(response, 'title="Hersteller-Farbcode"')
|
||||
self.assertContains(response, "Artikelnr.")
|
||||
self.assertContains(response, '<td class="article-number">11200</td>', count=1)
|
||||
self.assertContains(response, '<td class="article-number">–</td>', count=1)
|
||||
if url == "/bestand/":
|
||||
self.assertContains(response, '<td class="article-number">11200</td>', count=1)
|
||||
else:
|
||||
self.assertContains(response, "<span data-article-code>11200</span>", count=1)
|
||||
self.assertContains(response, 'aria-label="Artikelnummer 11200 kopieren"', count=1)
|
||||
self.assertContains(response, '<td class="article-number">–</td>', count=1, html=True)
|
||||
self.assertIn("https://cdn.shopify.com", response["Content-Security-Policy"])
|
||||
self.assertNotIn(
|
||||
"https://cdn.shopify.com", self.client.get("/katalog/")["Content-Security-Policy"]
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
from datetime import UTC, datetime
|
||||
from unittest.mock import patch
|
||||
from urllib.parse import parse_qs, urlsplit
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.test import Client
|
||||
from django.urls import reverse
|
||||
|
||||
from filament.models import Color, InventoryItem, OrderItem, StockMovement, Variant
|
||||
from filament.models import InventoryItem, OrderItem, StockMovement, Variant
|
||||
from filament.services import add_quantity
|
||||
|
||||
from .base import CatalogTestCase
|
||||
@@ -32,7 +31,10 @@ class SharedOrderTests(CatalogTestCase):
|
||||
OrderItem.objects.create(owner=self.bob, variant=self.spool, quantity=4, status=status)
|
||||
|
||||
self.client.force_login(self.alice)
|
||||
self.assertContains(self.client.get(reverse("orders")), url)
|
||||
orders = self.client.get(reverse("orders"))
|
||||
self.assertContains(orders, url)
|
||||
self.assertContains(orders, 'class="article-copy-icon"', count=6)
|
||||
self.assertContains(orders, 'aria-label="Artikelnummer 10100 kopieren"', count=5)
|
||||
result = self.client.get(url, {"q": "10100"})
|
||||
self.assertEqual(
|
||||
{variant.pk: variant.order_quantity for variant in result.context["variants"]},
|
||||
@@ -40,37 +42,11 @@ class SharedOrderTests(CatalogTestCase):
|
||||
)
|
||||
self.assertContains(result, 'aria-label="Artikelnummer 10100 kopieren"', count=2)
|
||||
self.assertEqual(result.context["total"], 4)
|
||||
self.assertEqual(
|
||||
result.context["shop_searches"],
|
||||
["https://eu.store.bambulab.com/search?q=10100"],
|
||||
)
|
||||
self.assertNotContains(result, "Im Bambu-Shop suchen")
|
||||
self.assertNotContains(result, 'class="article-copy-icon"')
|
||||
self.assertEqual(self.client.get(url, {"q": "10100, 10101"}).context["total"], 5)
|
||||
self.assertEqual(self.client.post(url).status_code, 405)
|
||||
|
||||
def test_shopping_list_shop_search_batches_distinct_codes(self):
|
||||
codes = [str(10800 + offset) for offset in range(13)]
|
||||
for code in codes:
|
||||
variant = Variant.objects.create(
|
||||
product_type=self.product,
|
||||
color=Color.objects.create(name=code),
|
||||
spool_type=Variant.SpoolType.SPOOL,
|
||||
manufacturer_color_code=code,
|
||||
)
|
||||
OrderItem.objects.create(owner=self.alice, variant=variant, quantity=1)
|
||||
OrderItem.objects.create(
|
||||
owner=self.alice, variant=self.spool, quantity=2, status=OrderItem.Status.UNAVAILABLE
|
||||
)
|
||||
self.client.force_login(self.bob)
|
||||
url = reverse("order_shopping_list")
|
||||
result = self.client.get(url)
|
||||
batches = [
|
||||
parse_qs(urlsplit(link).query)["q"][0].split(", ")
|
||||
for link in result.context["shop_searches"]
|
||||
]
|
||||
self.assertEqual(batches, [codes[:12], codes[12:]])
|
||||
self.assertContains(result, "Im Bambu-Shop suchen (2/2)")
|
||||
self.assertEqual(result.context["total"], 13)
|
||||
|
||||
def test_history_is_shared_and_records_order_and_handover_times(self):
|
||||
url = reverse("order_history")
|
||||
self.assertRedirects(self.client.get(url), f"/anmelden/?next={url}")
|
||||
|
||||
+1
-14
@@ -1,7 +1,6 @@
|
||||
import re
|
||||
from itertools import batched, groupby
|
||||
from itertools import groupby
|
||||
from pathlib import PurePosixPath
|
||||
from urllib.parse import urlencode
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from django.contrib import messages
|
||||
@@ -966,17 +965,6 @@ def order_shopping_list(request):
|
||||
for variant in variants
|
||||
if variant.manufacturer_color_code.strip().casefold() in codes
|
||||
]
|
||||
bambu_codes = dict.fromkeys(
|
||||
variant.manufacturer_color_code.strip()
|
||||
for variant in variants
|
||||
if variant.manufacturer.name.casefold() == "bambu lab"
|
||||
and re.fullmatch(r"[0-9]{5}", variant.manufacturer_color_code.strip())
|
||||
)
|
||||
# The shop accepted a dozen codes in one search. A full order can exceed its limit.
|
||||
shop_searches = [
|
||||
"https://eu.store.bambulab.com/search?" + urlencode({"q": ", ".join(batch)})
|
||||
for batch in batched(bambu_codes, 12)
|
||||
]
|
||||
return render(
|
||||
request,
|
||||
"filament/order_shopping_list.html",
|
||||
@@ -984,7 +972,6 @@ def order_shopping_list(request):
|
||||
"variants": variants,
|
||||
"total": sum(variant.order_quantity for variant in variants),
|
||||
"search": search,
|
||||
"shop_searches": shop_searches,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{% if article %}
|
||||
<div class="article-copy">
|
||||
<span data-article-code>{{ article }}</span>
|
||||
<button type="button" class="button secondary{% if icon_only %} article-copy-icon-button{% endif %}" data-copy-article aria-label="Artikelnummer {{ article }} kopieren" title="Artikelnummer kopieren" hidden>
|
||||
{% if icon_only %}<span class="article-copy-icon" aria-hidden="true"></span>{% else %}<span data-copy-label>Kopieren</span>{% endif %}
|
||||
</button>
|
||||
</div>
|
||||
{% else %}–{% endif %}
|
||||
@@ -7,14 +7,6 @@
|
||||
<div><h1>Konsolidierte Bestellliste</h1><p class="muted">Offene Bestellwünsche aller Personen, zusammengezählt pro Variante.</p></div>
|
||||
</div>
|
||||
{% include "filament/list_search.html" with search_url="order_shopping_list" search_label="Nach einer oder mehreren Artikelnummern suchen" placeholder="Artikelnummern, z. B. 10100, 10604" %}
|
||||
{% if shop_searches %}
|
||||
<div class="order-shop-links" role="group" aria-label="Bambu-Lab-Shop-Suche">
|
||||
{% for url in shop_searches %}
|
||||
<a class="button secondary" href="{{ url }}" target="_blank" rel="noreferrer">Im Bambu-Shop suchen{% if shop_searches|length > 1 %} ({{ forloop.counter }}/{{ shop_searches|length }}){% endif %} ↗</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<p class="hint">Prüfe im Shop Farbe, Spulenausführung und Stückzahl anhand dieser Liste.</p>
|
||||
{% endif %}
|
||||
{% if variants %}
|
||||
<section class="panel" aria-label="Offene Bestellwünsche">
|
||||
<div class="panel-heading">
|
||||
@@ -26,7 +18,6 @@
|
||||
<thead><tr><th scope="col">Stück</th><th scope="col">Produktart</th><th scope="col">Farbe</th><th scope="col">Spulenausführung</th><th scope="col">Artikelnr.</th></tr></thead>
|
||||
<tbody>
|
||||
{% for variant in variants %}
|
||||
{% with article=variant.manufacturer_color_code.strip %}
|
||||
<tr>
|
||||
<td class="quantity">{{ variant.order_quantity }}</td>
|
||||
<td>{{ variant.product_type.name }}<small>{{ variant.manufacturer }}</small></td>
|
||||
@@ -36,23 +27,15 @@
|
||||
{% if variant.net_weight_g or variant.diameter_mm %}<small>{% if variant.net_weight_g %}{{ variant.net_weight_g }} g{% endif %}{% if variant.net_weight_g and variant.diameter_mm %} · {% endif %}{% if variant.diameter_mm %}{{ variant.diameter_mm }} mm{% endif %}</small>{% endif %}
|
||||
{% if not variant.is_active %}<small class="warning">Katalogvariante deaktiviert</small>{% endif %}
|
||||
</td>
|
||||
<td class="article-number">
|
||||
{% if article %}
|
||||
<div class="article-copy">
|
||||
<span id="order-article-{{ variant.pk }}">{{ article }}</span>
|
||||
<button type="button" class="button secondary" data-copy-article="order-article-{{ variant.pk }}" aria-label="Artikelnummer {{ article }} kopieren" hidden>Kopieren</button>
|
||||
</div>
|
||||
{% else %}–{% endif %}
|
||||
</td>
|
||||
<td class="article-number">{% include "filament/order_article_number.html" with article=variant.manufacturer_color_code.strip only %}</td>
|
||||
</tr>
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p class="sr-only" role="status" data-copy-status></p>
|
||||
</section>
|
||||
<script src="{% static 'filament/order_shopping_list.js' %}" defer></script>
|
||||
<script src="{% static 'filament/order_article_copy.js' %}" defer></script>
|
||||
{% else %}
|
||||
<section class="panel"><div class="empty"><h2>{% if search %}Keine offenen Wünsche zu diesen Artikelnummern{% else %}Keine offenen Bestellwünsche{% endif %}</h2></div></section>
|
||||
{% endif %}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% load static %}
|
||||
{% block title %}Sammelbestellung · Fil-A-Management{% endblock %}
|
||||
{% block content %}
|
||||
<div class="page-heading">
|
||||
@@ -27,7 +28,7 @@
|
||||
<td class="quantity">{{ entry.quantity }}</td>
|
||||
<td>{{ entry.variant.product_type.name }}<small>{{ entry.variant.manufacturer }}</small></td>
|
||||
<td><div class="variant-preview">{% include "filament/variant_thumbnail.html" with variant=entry.variant only %}<strong>{{ entry.variant.color_label }}</strong></div></td>
|
||||
<td class="article-number">{{ entry.variant.manufacturer_color_code|default:"–" }}</td>
|
||||
<td class="article-number">{% include "filament/order_article_number.html" with article=entry.variant.manufacturer_color_code.strip icon_only=True only %}</td>
|
||||
<td><span class="badge">{{ entry.variant.get_spool_type_display }}</span>{% if not entry.variant.is_active %}<small class="warning">Deaktiviert · Katalogvariante</small>{% endif %}</td>
|
||||
<td>
|
||||
<form class="order-status-form" method="post" action="{% url 'order_status' entry.pk %}">
|
||||
@@ -60,4 +61,8 @@
|
||||
{% empty %}
|
||||
<section class="panel"><div class="empty"><h2>Keine laufenden Bestellwünsche</h2><p>Neue Wünsche erscheinen hier nach Person sortiert.</p><a class="button" href="{% url 'order_add' %}">Bestellwunsch hinzufügen</a></div></section>
|
||||
{% endfor %}
|
||||
{% if groups %}
|
||||
<p class="sr-only" role="status" data-copy-status></p>
|
||||
<script src="{% static 'filament/order_article_copy.js' %}" defer></script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
Reference in new issue
Block a user