diff --git a/app.py b/app.py index 9208665..2e2e1c3 100644 --- a/app.py +++ b/app.py @@ -1527,20 +1527,18 @@ def edit_my_list(list_id): next_page = request.args.get("next") or request.referrer if request.method == "POST": - move_to_month = request.form.get("move_to_month", "") - + move_to_month = request.form.get("move_to_month") if move_to_month: try: year, month = map(int, move_to_month.split("-")) new_created_at = datetime(year, month, 1, tzinfo=timezone.utc) - if l.created_at is None or l.created_at.year != year or l.created_at.month != month: - l.created_at = new_created_at - db.session.commit() - flash( - f"Zmieniono datę utworzenia listy na {new_created_at.strftime('%Y-%m-%d')}", - "success", - ) - return redirect(next_page or url_for("main_page")) + l.created_at = new_created_at + db.session.commit() + flash( + f"Zmieniono datę utworzenia listy na {new_created_at.strftime('%Y-%m-%d')}", + "success", + ) + return redirect(next_page or url_for("main_page")) except ValueError: flash("Nieprawidłowy format miesiąca", "danger") return redirect(next_page or url_for("main_page")) @@ -1577,26 +1575,15 @@ def edit_my_list(list_id): flash("Zaktualizowano dane listy", "success") return redirect(next_page or url_for("main_page")) - if l.created_at: - selected_year = l.created_at.year - selected_month = f"{l.created_at.month:02d}" - else: - now = datetime.now() - selected_year = now.year - selected_month = f"{now.month:02d}" - return render_template( "edit_my_list.html", list=l, receipts=receipts, categories=categories, selected_categories=selected_categories_ids, - current_year=selected_year, - current_month=selected_month, ) - @app.route("/delete_user_list/", methods=["POST"]) @login_required def delete_user_list(list_id): diff --git a/static/js/_unused_receipt_crop.js b/static/js/_unused_receipt_crop.js deleted file mode 100644 index 33754a0..0000000 --- a/static/js/_unused_receipt_crop.js +++ /dev/null @@ -1,109 +0,0 @@ -let cropper; -let currentReceiptId; - -document.addEventListener("DOMContentLoaded", function () { - const cropModal = document.getElementById("cropModal"); - const cropImage = document.getElementById("cropImage"); - const spinner = document.getElementById("cropLoading"); - - cropModal.addEventListener("shown.bs.modal", function (event) { - const button = event.relatedTarget; - const imgSrc = button.getAttribute("data-img-src"); - currentReceiptId = button.getAttribute("data-receipt-id"); - - cropImage.src = imgSrc; - - if (cropper) { - cropper.destroy(); - cropper = null; - } - - cropImage.onload = () => { - cropper = new Cropper(cropImage, { - viewMode: 1, - autoCropArea: 1, - responsive: true, - background: false, - zoomable: true, - movable: true, - dragMode: 'move', - minContainerHeight: 400, - minContainerWidth: 400, - }); - }; - }); - - document.getElementById("saveCrop").addEventListener("click", function () { - if (!cropper) return; - - spinner.classList.remove("d-none"); - - const cropData = cropper.getData(); - const imageData = cropper.getImageData(); - - const scaleX = imageData.naturalWidth / imageData.width; - const scaleY = imageData.naturalHeight / imageData.height; - - const width = cropData.width * scaleX; - const height = cropData.height * scaleY; - - if (width < 1 || height < 1) { - spinner.classList.add("d-none"); - showToast("Obszar przycięcia jest zbyt mały lub pusty", "danger"); - return; - } - - // Ogranicz do 2000x2000 w proporcji - const maxDim = 2000; - const scale = Math.min(1, maxDim / Math.max(width, height)); - - const finalWidth = Math.round(width * scale); - const finalHeight = Math.round(height * scale); - - const croppedCanvas = cropper.getCroppedCanvas({ - width: finalWidth, - height: finalHeight, - imageSmoothingEnabled: true, - imageSmoothingQuality: 'high', - }); - - - if (!croppedCanvas) { - spinner.classList.add("d-none"); - showToast("Nie można uzyskać obrazu przycięcia", "danger"); - return; - } - - croppedCanvas.toBlob(function (blob) { - if (!blob) { - spinner.classList.add("d-none"); - showToast("Nie udało się zapisać obrazu", "danger"); - return; - } - - const formData = new FormData(); - formData.append("receipt_id", currentReceiptId); - formData.append("cropped_image", blob); - - fetch("/admin/crop_receipt", { - method: "POST", - body: formData, - }) - .then((res) => res.json()) - .then((data) => { - spinner.classList.add("d-none"); - if (data.success) { - showToast("Zapisano przycięty paragon", "success"); - setTimeout(() => location.reload(), 1500); - } else { - showToast("Błąd: " + (data.error || "Nieznany"), "danger"); - } - }) - .catch((err) => { - spinner.classList.add("d-none"); - showToast("Błąd sieci", "danger"); - console.error(err); - }); - }, "image/webp", 1.0); - }); -}); diff --git a/static/js/move_to_month.js b/static/js/move_to_month.js deleted file mode 100644 index 1700b56..0000000 --- a/static/js/move_to_month.js +++ /dev/null @@ -1,11 +0,0 @@ - function updateMoveToMonth() { - const year = document.getElementById('move_to_month_year').value; - const month = document.getElementById('move_to_month_month').value; - const hiddenInput = document.getElementById('move_to_month'); - hiddenInput.value = `${year}-${month}`; - } - - document.getElementById('move_to_month_year').addEventListener('change', updateMoveToMonth); - document.getElementById('move_to_month_month').addEventListener('change', updateMoveToMonth); - - updateMoveToMonth(); \ No newline at end of file diff --git a/templates/admin/edit_list.html b/templates/admin/edit_list.html index fba946e..dc2a95b 100644 --- a/templates/admin/edit_list.html +++ b/templates/admin/edit_list.html @@ -282,5 +282,4 @@ {% endblock %} {% block scripts %} - {% endblock %} \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 0edbd4e..1378871 100644 --- a/templates/base.html +++ b/templates/base.html @@ -8,26 +8,26 @@ {# --- Style CSS ładowane tylko dla niezablokowanych --- #} -{% if not is_blocked %} + {% if not is_blocked %} -{% endif %} + {% endif %} -{# --- Bootstrap zawsze --- #} - + {# --- Bootstrap zawsze --- #} + -{# --- Cropper CSS tylko dla wybranych podstron --- #} -{% set substrings_cropper = ['/admin/receipts', '/edit_my_list'] %} -{% if substrings_cropper | select("in", request.path) | list | length > 0 %} + {# --- Cropper CSS tylko dla wybranych podstron --- #} + {% set substrings_cropper = ['/admin/receipts', '/edit_my_list'] %} + {% if substrings_cropper | select("in", request.path) | list | length > 0 %} -{% endif %} + {% endif %} -{# --- Tom Select CSS tylko dla wybranych podstron --- #} -{% set substrings_tomselect = ['/edit_my_list', '/admin/edit_list', '/admin/mass_edit_categories'] %} -{% if substrings_tomselect | select("in", request.path) | list | length > 0 %} + {# --- Tom Select CSS tylko dla wybranych podstron --- #} + {% set substrings_tomselect = ['/edit_my_list', '/admin/edit_list', '/admin/mass_edit_categories'] %} + {% if substrings_tomselect | select("in", request.path) | list | length > 0 %} -{% endif %} + {% endif %} diff --git a/templates/edit_my_list.html b/templates/edit_my_list.html index 5216720..f4e5ca9 100644 --- a/templates/edit_my_list.html +++ b/templates/edit_my_list.html @@ -22,20 +22,20 @@
- +
- +
- +
@@ -55,35 +55,25 @@ -
+ +
- - - {{ list.created_at.strftime('%Y-%m-%d') }} - + +

+ + {{ list.created_at.strftime('%Y-%m-%d') }} + + +

-
- - -
- - - +
+
@@ -108,55 +98,55 @@
- {% if receipts %} -
-
Paragony przypisane do tej listy
+{% if receipts %} +
+
Paragony przypisane do tej listy
-
- {% for r in receipts %} -
-
- - - -
-

{{ r.filename }}

-

Wgrano: {{ r.uploaded_at.strftime('%Y-%m-%d %H:%M') }}

- {% if r.filesize and r.filesize >= 1024 * 1024 %} -

Rozmiar: {{ (r.filesize / 1024 / 1024) | round(2) }} MB

- {% elif r.filesize %} -

Rozmiar: {{ (r.filesize / 1024) | round(1) }} kB

- {% else %} -

Brak danych o rozmiarze

- {% endif %} +
+ {% for r in receipts %} +
+
+ + + +
+

{{ r.filename }}

+

Wgrano: {{ r.uploaded_at.strftime('%Y-%m-%d %H:%M') }}

+ {% if r.filesize and r.filesize >= 1024 * 1024 %} +

Rozmiar: {{ (r.filesize / 1024 / 1024) | round(2) }} MB

+ {% elif r.filesize %} +

Rozmiar: {{ (r.filesize / 1024) | round(1) }} kB

+ {% else %} +

Brak danych o rozmiarze

+ {% endif %} - 🔄 Obróć o 90° + 🔄 Obróć o 90° - - ✂️ Przytnij - - 🗑️ Usuń -
-
+ + ✂️ Przytnij + + 🗑️ Usuń
- {% endfor %} -
- {% endif %} - -
- -
-
+ {% endfor %} +
+{% endif %} + +
+ +
+ +
+