wyszukiwanie i dodawanie sugestii oraz poprawki

This commit is contained in:
Mateusz Gruszczyński
2025-08-17 22:56:25 +02:00
parent 268f8d2e85
commit dd65230636
4 changed files with 81 additions and 2 deletions

22
app.py
View File

@@ -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")

View File

@@ -66,7 +66,7 @@ function bindDeleteButton(button) {
const syncBtn = cell.querySelector('.sync-btn');
if (syncBtn) bindSyncButton(syncBtn);
} else {
cell.innerHTML = '<span class="badge rounded-pill bg-warning opacity-75">Usunięto synchronizacje</span>';
cell.innerHTML = '<span class="badge rounded-pill bg-warning opacity-75">Usunięto z bazy danych</span>';
}
})
.catch(() => {

28
static/js/table_search.js Normal file
View File

@@ -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();
});
}
});

View File

@@ -7,6 +7,32 @@
<a href="{{ url_for('admin_panel') }}" class="btn btn-outline-secondary">← Powrót do panelu</a>
</div>
<div class="card bg-dark text-white mb-4">
<div class="card-body">
<!-- Formularz dodawania sugestii -->
<form action="{{ url_for('add_suggestion') }}" method="POST" class="mb-4">
<label class="form-label fw-bold mb-2"> Dodaj nową sugestię:</label>
<div class="input-group">
<input type="text" name="suggestion_name" class="form-control bg-dark text-white border-secondary"
placeholder="Nowa sugestia produktu…" required>
<button type="submit" class="btn btn-outline-light"> Dodaj</button>
</div>
</form>
<hr class="border-secondary opacity-50 mb-4 mt-2">
<!-- Szukajka z przyciskiem wyczyść -->
<label for="search-table" class="form-label fw-bold mb-2">🔍 Przeszukaj tabelę produktów i sugestii:</label>
<div class="input-group">
<input type="text" id="search-table" class="form-control bg-dark text-white border-secondary"
placeholder="Wpisz frazę, np. 'mleko'">
<button type="button" id="clear-search" class="btn btn-outline-light">🧹 Wyczyść</button>
</div>
</div>
</div>
<div class="card bg-dark text-white mb-5">
<div class="card-body">
<div class="card-header d-flex justify-content-between align-items-center">
@@ -96,7 +122,9 @@
{% endfor %}
{% if orphan_suggestions|length == 0 %}
<tr>
<td colspan="3" class="text-center">Brak sugestii do wyświetlenia.</td>
<td colspan="12" class="text-center py-4">
Brak niepowiązanych sugestii do wyświetlenia
</td>
</tr>
{% endif %}
</tbody>
@@ -135,6 +163,7 @@
{% block scripts %}
<script src="{{ url_for('static_bp.serve_js', filename='product_suggestion.js') }}"></script>
<script src="{{ url_for('static_bp.serve_js', filename='table_search.js') }}"></script>
{% endblock %}
{% endblock %}