diff --git a/app.py b/app.py index cd4fe86..1f23136 100644 --- a/app.py +++ b/app.py @@ -3276,6 +3276,28 @@ def admin_list_items_json(list_id): ) +@app.route("/admin/add_suggestion", methods=["POST"]) +@login_required +@admin_required +def add_suggestion(): + name = request.form.get("suggestion_name", "").strip() + + if not name: + flash("Nazwa nie może być pusta", "warning") + return redirect(url_for("list_products")) + + existing = db.session.query(SuggestedProduct).filter_by(name=name).first() + if existing: + flash("Sugestia już istnieje", "warning") + else: + new_suggestion = SuggestedProduct(name=name) + db.session.add(new_suggestion) + db.session.commit() + flash("Dodano sugestię", "success") + + return redirect(url_for("list_products")) + + @app.route("/healthcheck") def healthcheck(): header_token = request.headers.get("X-Internal-Check") diff --git a/static/js/product_suggestion.js b/static/js/product_suggestion.js index 0c1af4c..4d3b0c8 100644 --- a/static/js/product_suggestion.js +++ b/static/js/product_suggestion.js @@ -66,7 +66,7 @@ function bindDeleteButton(button) { const syncBtn = cell.querySelector('.sync-btn'); if (syncBtn) bindSyncButton(syncBtn); } else { - cell.innerHTML = 'Usunięto synchronizacje'; + cell.innerHTML = 'Usunięto z bazy danych'; } }) .catch(() => { diff --git a/static/js/table_search.js b/static/js/table_search.js new file mode 100644 index 0000000..2958ba2 --- /dev/null +++ b/static/js/table_search.js @@ -0,0 +1,28 @@ +document.addEventListener("DOMContentLoaded", function () { + const searchInput = document.getElementById("search-table"); + const clearButton = document.getElementById("clear-search"); + const rows = document.querySelectorAll("table tbody tr"); + + if (!searchInput || !rows.length) return; + + function filterTable(query) { + const q = query.toLowerCase(); + + rows.forEach(row => { + const rowText = row.textContent.toLowerCase(); + row.style.display = rowText.includes(q) ? "" : "none"; + }); + } + + searchInput.addEventListener("input", function () { + filterTable(this.value); + }); + + if (clearButton) { + clearButton.addEventListener("click", function () { + searchInput.value = ""; + filterTable(""); // Pokaż wszystko + searchInput.focus(); + }); + } +}); \ No newline at end of file diff --git a/templates/admin/list_products.html b/templates/admin/list_products.html index 94aec51..3871da0 100644 --- a/templates/admin/list_products.html +++ b/templates/admin/list_products.html @@ -7,6 +7,32 @@ ← Powrót do panelu +
+
+ + +
+ +
+ + +
+
+ +
+ + + +
+ + +
+ +
+
+
@@ -96,7 +122,9 @@ {% endfor %} {% if orphan_suggestions|length == 0 %} - Brak sugestii do wyświetlenia. + + Brak niepowiązanych sugestii do wyświetlenia + {% endif %} @@ -135,6 +163,7 @@ {% block scripts %} + {% endblock %} {% endblock %} \ No newline at end of file