Merge branch 'search-conso' into 'main'

Added a search tab for the conso page, fixes #58

Closes #58

See merge request bde/nk20!224
This commit is contained in:
nicomarg 2023-10-27 16:45:41 +02:00
commit 24f54ac876
6 changed files with 165 additions and 64 deletions

View File

@ -258,3 +258,39 @@ function consume (source, source_alias, dest, quantity, amount, reason, type, ca
})
})
}
const searchbar = document.getElementById("search-input")
const search_results = document.getElementById("search-results")
var old_pattern = null;
var firstMatch = null;
/**
* Updates the button search tab
* @param force Forces the update even if the pattern didn't change
*/
function updateSearch(force = false) {
let pattern = searchbar.value
if (pattern === "")
firstMatch = null;
if ((pattern === old_pattern || pattern === "") && !force)
return;
firstMatch = null;
const re = new RegExp(pattern, "i");
Array.from(search_results.children).forEach(function(b) {
if (re.test(b.innerText)) {
b.hidden = false;
if (firstMatch === null) {
firstMatch = b;
}
} else
b.hidden = true;
});
}
searchbar.addEventListener("input", function (e) {
debounce(updateSearch)()
});
searchbar.addEventListener("keyup", function (e) {
if (firstMatch && e.key === "Enter")
firstMatch.click()
});

View File

@ -103,6 +103,11 @@ SPDX-License-Identifier: GPL-3.0-or-later
</a>
</li>
{% endfor %}
<li class="nav-item">
<a class="nav-link font-weight-bold" data-toggle="tab" href="#search">
{% trans "Search" %}
</a>
</li>
</ul>
</div>
@ -123,6 +128,20 @@ SPDX-License-Identifier: GPL-3.0-or-later
</div>
</div>
{% endfor %}
<div class="tab-pane" id="search">
<input class="form-control mx-auto d-block mb-3"
placeholder="{% trans "Search button..." %}" type="search" id="search-input"/>
<div class="d-inline-flex flex-wrap justify-content-center" id="search-results">
{% for button in all_buttons %}
{% if button.display %}
<button class="btn btn-outline-dark rounded-0 flex-fill" hidden
id="search_button{{ button.id }}" name="button" value="{{ button.name }}">
{{ button.name }} ({{ button.amount | pretty_money }})
</button>
{% endif %}
{% endfor %}
</div>
</div>
</div>
</div>
@ -163,7 +182,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
<script type="text/javascript">
{% for button in highlighted %}
{% if button.display %}
$("#highlighted_button{{ button.id }}").click(function() {
document.getElementById("highlighted_button{{ button.id }}").addEventListener("click", function() {
addConso({{ button.destination_id }}, {{ button.amount }},
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
{{ button.id }}, "{{ button.name|escapejs }}");
@ -174,7 +193,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% for category in categories %}
{% for button in category.templates_filtered %}
{% if button.display %}
$("#button{{ button.id }}").click(function() {
document.getElementById("button{{ button.id }}").addEventListener("click", function() {
addConso({{ button.destination_id }}, {{ button.amount }},
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
{{ button.id }}, "{{ button.name|escapejs }}");
@ -182,5 +201,15 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% endif %}
{% endfor %}
{% endfor %}
{% for button in all_buttons %}
{% if button.display %}
document.getElementById("search_button{{ button.id }}").addEventListener("click", function() {
addConso({{ button.destination_id }}, {{ button.amount }},
{{ polymorphic_ctype }}, {{ button.category_id }}, "{{ button.category.name|escapejs }}",
{{ button.id }}, "{{ button.name|escapejs }}");
});
{% endif %}
{% endfor %}
</script>
{% endblock %}

View File

@ -10,12 +10,12 @@ from django.core.exceptions import PermissionDenied
from django.db.models import Q, F
from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, UpdateView, DetailView
from django_tables2 import SingleTableView
from django.urls import reverse_lazy
from django_tables2 import SingleTableView
from activity.models import Entry
from note_kfet.inputs import AmountInput
from permission.backends import PermissionBackend
from permission.views import ProtectQuerysetMixin
from note_kfet.inputs import AmountInput
from .forms import TransactionTemplateForm, SearchTransactionForm
from .models import TemplateCategory, Transaction, TransactionTemplate, RecurrentTransaction, NoteSpecial, Note
@ -190,6 +190,10 @@ class ConsoView(ProtectQuerysetMixin, LoginRequiredMixin, SingleTableView):
).order_by('name').all()
context['polymorphic_ctype'] = ContentType.objects.get_for_model(RecurrentTransaction).pk
context['all_buttons'] = TransactionTemplate.objects.filter(
PermissionBackend.filter_queryset(self.request, TransactionTemplate, "view")
).filter(display=True).order_by('name').all()
return context

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-18 17:27+0200\n"
"POT-Creation-Date: 2023-10-25 19:12+0200\n"
"PO-Revision-Date: 2020-11-16 20:02+0000\n"
"Last-Translator: bleizi <bleizi@crans.org>\n"
"Language-Team: German <http://translate.ynerant.fr/projects/nk20/nk20/de/>\n"
@ -1286,16 +1286,16 @@ msgstr "Rollen in diesen Club bearbeiten"
msgid "Members of the club"
msgstr "Mitlglieder dieses Club"
#: apps/note/admin.py:129 apps/note/models/transactions.py:109
#: apps/note/admin.py:139 apps/note/models/transactions.py:109
msgid "source"
msgstr "Sender"
#: apps/note/admin.py:137 apps/note/admin.py:205
#: apps/note/admin.py:147 apps/note/admin.py:215
#: apps/note/models/transactions.py:56 apps/note/models/transactions.py:122
msgid "destination"
msgstr "Empfänger"
#: apps/note/admin.py:210 apps/note/models/transactions.py:60
#: apps/note/admin.py:220 apps/note/models/transactions.py:60
#: apps/note/models/transactions.py:140
msgid "amount"
msgstr "Anzahl"
@ -1643,7 +1643,7 @@ msgstr ""
msgid "Add back"
msgstr "Neue Bus"
#: apps/note/tables.py:262 apps/note/templates/note/conso_form.html:132
#: apps/note/tables.py:262 apps/note/templates/note/conso_form.html:151
#: apps/wei/tables.py:49 apps/wei/tables.py:50
#: apps/wei/templates/wei/base.html:89
#: apps/wei/templates/wei/bus_detail.html:20
@ -1684,15 +1684,27 @@ msgstr "Konsumieren!"
msgid "Highlighted buttons"
msgstr "Hervorgehobene Tasten"
#: apps/note/templates/note/conso_form.html:138
#: apps/note/templates/note/conso_form.html:108
#, fuzzy
#| msgid "Search WEI"
msgid "Search"
msgstr "WEI finden"
#: apps/note/templates/note/conso_form.html:133
#, fuzzy
#| msgid "Search button"
msgid "Search button..."
msgstr "Tatsen finden"
#: apps/note/templates/note/conso_form.html:157
msgid "Single consumptions"
msgstr "Solo Modus"
#: apps/note/templates/note/conso_form.html:143
#: apps/note/templates/note/conso_form.html:162
msgid "Double consumptions"
msgstr "Doppelte Modus"
#: apps/note/templates/note/conso_form.html:154
#: apps/note/templates/note/conso_form.html:173
#: apps/note/templates/note/transaction_form.html:163
msgid "Recent transactions history"
msgstr "Verlauf der letzten Transaktionen"
@ -1826,7 +1838,7 @@ msgstr "Verbräuche"
msgid "You can't see any button."
msgstr "Sie können keine Taste sehen."
#: apps/note/views.py:200
#: apps/note/views.py:208
msgid "Search transactions"
msgstr "Transaktion finden"
@ -2402,12 +2414,12 @@ msgid "Yes"
msgstr "Ja"
#: apps/treasury/templates/treasury/invoice_confirm_delete.html:10
#: apps/treasury/views.py:180
#: apps/treasury/views.py:173
msgid "Delete invoice"
msgstr "Rechnung löschen"
#: apps/treasury/templates/treasury/invoice_confirm_delete.html:15
#: apps/treasury/views.py:184
#: apps/treasury/views.py:177
msgid "This invoice is locked and can't be deleted."
msgstr "Eine Rechnung kann nicht gelöscht werden, wenn sie gesperrt ist."
@ -2593,36 +2605,36 @@ msgstr "Neue Rechnung"
msgid "Invoices list"
msgstr "Rechnunglist"
#: apps/treasury/views.py:112 apps/treasury/views.py:286
#: apps/treasury/views.py:412
#: apps/treasury/views.py:105 apps/treasury/views.py:275
#: apps/treasury/views.py:401
msgid "You are not able to see the treasury interface."
msgstr "Sie können die Quaestor-App nicht sehen."
#: apps/treasury/views.py:122
#: apps/treasury/views.py:115
msgid "Update an invoice"
msgstr "Rechnung bearbeiten"
#: apps/treasury/views.py:247
#: apps/treasury/views.py:240
msgid "Create a new remittance"
msgstr "Neue Überweisung"
#: apps/treasury/views.py:274
#: apps/treasury/views.py:267
msgid "Remittances list"
msgstr "Überweisungliste"
#: apps/treasury/views.py:337
#: apps/treasury/views.py:326
msgid "Update a remittance"
msgstr "Überweisung bearbeiten"
#: apps/treasury/views.py:360
#: apps/treasury/views.py:349
msgid "Attach a transaction to a remittance"
msgstr "Fügen Sie einer Überweisung eine Transaktion hinzu"
#: apps/treasury/views.py:404
#: apps/treasury/views.py:393
msgid "List of credits from the Société générale"
msgstr "Kreditliste von Société générale"
#: apps/treasury/views.py:449
#: apps/treasury/views.py:438
msgid "Manage credits from the Société générale"
msgstr "Krediten von der Société générale handeln"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-18 17:27+0200\n"
"POT-Creation-Date: 2023-10-25 19:12+0200\n"
"PO-Revision-Date: 2022-04-11 23:12+0200\n"
"Last-Translator: bleizi <bleizi@crans.org>\n"
"Language-Team: \n"
@ -1272,16 +1272,16 @@ msgstr "Gestionar los papeles de un usuario en el club"
msgid "Members of the club"
msgstr "Miembros del club"
#: apps/note/admin.py:129 apps/note/models/transactions.py:109
#: apps/note/admin.py:139 apps/note/models/transactions.py:109
msgid "source"
msgstr "fuente"
#: apps/note/admin.py:137 apps/note/admin.py:205
#: apps/note/admin.py:147 apps/note/admin.py:215
#: apps/note/models/transactions.py:56 apps/note/models/transactions.py:122
msgid "destination"
msgstr "destino"
#: apps/note/admin.py:210 apps/note/models/transactions.py:60
#: apps/note/admin.py:220 apps/note/models/transactions.py:60
#: apps/note/models/transactions.py:140
msgid "amount"
msgstr "monto"
@ -1627,7 +1627,7 @@ msgstr "Añadir como amig@"
msgid "Add back"
msgstr "Añadir en retorno"
#: apps/note/tables.py:262 apps/note/templates/note/conso_form.html:132
#: apps/note/tables.py:262 apps/note/templates/note/conso_form.html:151
#: apps/wei/tables.py:49 apps/wei/tables.py:50
#: apps/wei/templates/wei/base.html:89
#: apps/wei/templates/wei/bus_detail.html:20
@ -1668,15 +1668,27 @@ msgstr "¡ Consumir !"
msgid "Highlighted buttons"
msgstr "Botones resaltados"
#: apps/note/templates/note/conso_form.html:138
#: apps/note/templates/note/conso_form.html:108
#, fuzzy
#| msgid "Search WEI"
msgid "Search"
msgstr "Buscar un WEI"
#: apps/note/templates/note/conso_form.html:133
#, fuzzy
#| msgid "Search button"
msgid "Search button..."
msgstr "Buscar un botón"
#: apps/note/templates/note/conso_form.html:157
msgid "Single consumptions"
msgstr "Consumiciones simples"
#: apps/note/templates/note/conso_form.html:143
#: apps/note/templates/note/conso_form.html:162
msgid "Double consumptions"
msgstr "Consumiciones dobles"
#: apps/note/templates/note/conso_form.html:154
#: apps/note/templates/note/conso_form.html:173
#: apps/note/templates/note/transaction_form.html:163
msgid "Recent transactions history"
msgstr "Historial de las transacciones recientes"
@ -1806,7 +1818,7 @@ msgstr "Consumiciones"
msgid "You can't see any button."
msgstr "Usted no puede ver ningún botón."
#: apps/note/views.py:200
#: apps/note/views.py:208
msgid "Search transactions"
msgstr "Buscar transacciones"
@ -2378,12 +2390,12 @@ msgid "Yes"
msgstr "Sí"
#: apps/treasury/templates/treasury/invoice_confirm_delete.html:10
#: apps/treasury/views.py:180
#: apps/treasury/views.py:173
msgid "Delete invoice"
msgstr "Suprimir la factura"
#: apps/treasury/templates/treasury/invoice_confirm_delete.html:15
#: apps/treasury/views.py:184
#: apps/treasury/views.py:177
msgid "This invoice is locked and can't be deleted."
msgstr "Esta factura esta bloqueada y no puede ser suprimida."
@ -2559,36 +2571,36 @@ msgstr "Crear una nueva factura"
msgid "Invoices list"
msgstr "Lista de las facturas"
#: apps/treasury/views.py:112 apps/treasury/views.py:286
#: apps/treasury/views.py:412
#: apps/treasury/views.py:105 apps/treasury/views.py:275
#: apps/treasury/views.py:401
msgid "You are not able to see the treasury interface."
msgstr "Usted no tiene derecho a ver la interfaz de tesorería."
#: apps/treasury/views.py:122
#: apps/treasury/views.py:115
msgid "Update an invoice"
msgstr "Modificar una factura"
#: apps/treasury/views.py:247
#: apps/treasury/views.py:240
msgid "Create a new remittance"
msgstr "Crear un nuevo descuento"
#: apps/treasury/views.py:274
#: apps/treasury/views.py:267
msgid "Remittances list"
msgstr "Lista de los descuentos"
#: apps/treasury/views.py:337
#: apps/treasury/views.py:326
msgid "Update a remittance"
msgstr "Modificar un descuento"
#: apps/treasury/views.py:360
#: apps/treasury/views.py:349
msgid "Attach a transaction to a remittance"
msgstr "Unir una transacción con un descuento"
#: apps/treasury/views.py:404
#: apps/treasury/views.py:393
msgid "List of credits from the Société générale"
msgstr "Lista de los créditos de la Société Générale"
#: apps/treasury/views.py:449
#: apps/treasury/views.py:438
msgid "Manage credits from the Société générale"
msgstr "Gestionar los créditos de la Société Générale"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-09-18 17:27+0200\n"
"POT-Creation-Date: 2023-10-25 19:12+0200\n"
"PO-Revision-Date: 2022-04-11 22:05+0200\n"
"Last-Translator: bleizi <bleizi@crans.org>\n"
"Language-Team: French <http://translate.ynerant.fr/projects/nk20/nk20/fr/>\n"
@ -1274,16 +1274,16 @@ msgstr "Gérer les rôles d'un utilisateur dans le club"
msgid "Members of the club"
msgstr "Membres du club"
#: apps/note/admin.py:129 apps/note/models/transactions.py:109
#: apps/note/admin.py:139 apps/note/models/transactions.py:109
msgid "source"
msgstr "source"
#: apps/note/admin.py:137 apps/note/admin.py:205
#: apps/note/admin.py:147 apps/note/admin.py:215
#: apps/note/models/transactions.py:56 apps/note/models/transactions.py:122
msgid "destination"
msgstr "destination"
#: apps/note/admin.py:210 apps/note/models/transactions.py:60
#: apps/note/admin.py:220 apps/note/models/transactions.py:60
#: apps/note/models/transactions.py:140
msgid "amount"
msgstr "montant"
@ -1630,7 +1630,7 @@ msgstr "Ajouter en ami"
msgid "Add back"
msgstr "Ajouter"
#: apps/note/tables.py:262 apps/note/templates/note/conso_form.html:132
#: apps/note/tables.py:262 apps/note/templates/note/conso_form.html:151
#: apps/wei/tables.py:49 apps/wei/tables.py:50
#: apps/wei/templates/wei/base.html:89
#: apps/wei/templates/wei/bus_detail.html:20
@ -1671,15 +1671,23 @@ msgstr "Consommer !"
msgid "Highlighted buttons"
msgstr "Boutons mis en avant"
#: apps/note/templates/note/conso_form.html:138
#: apps/note/templates/note/conso_form.html:108
msgid "Search"
msgstr "Recherche"
#: apps/note/templates/note/conso_form.html:133
msgid "Search button..."
msgstr "Chercher un bouton..."
#: apps/note/templates/note/conso_form.html:157
msgid "Single consumptions"
msgstr "Consommations simples"
#: apps/note/templates/note/conso_form.html:143
#: apps/note/templates/note/conso_form.html:162
msgid "Double consumptions"
msgstr "Consommations doubles"
#: apps/note/templates/note/conso_form.html:154
#: apps/note/templates/note/conso_form.html:173
#: apps/note/templates/note/transaction_form.html:163
msgid "Recent transactions history"
msgstr "Historique des transactions récentes"
@ -1809,7 +1817,7 @@ msgstr "Consommations"
msgid "You can't see any button."
msgstr "Vous ne pouvez pas voir le moindre bouton."
#: apps/note/views.py:200
#: apps/note/views.py:208
msgid "Search transactions"
msgstr "Rechercher des transactions"
@ -2382,12 +2390,12 @@ msgid "Yes"
msgstr "Oui"
#: apps/treasury/templates/treasury/invoice_confirm_delete.html:10
#: apps/treasury/views.py:180
#: apps/treasury/views.py:173
msgid "Delete invoice"
msgstr "Supprimer la facture"
#: apps/treasury/templates/treasury/invoice_confirm_delete.html:15
#: apps/treasury/views.py:184
#: apps/treasury/views.py:177
msgid "This invoice is locked and can't be deleted."
msgstr "Cette facture est verrouillée et ne peut pas être supprimée."
@ -2567,36 +2575,36 @@ msgstr "Créer une nouvelle facture"
msgid "Invoices list"
msgstr "Liste des factures"
#: apps/treasury/views.py:112 apps/treasury/views.py:286
#: apps/treasury/views.py:412
#: apps/treasury/views.py:105 apps/treasury/views.py:275
#: apps/treasury/views.py:401
msgid "You are not able to see the treasury interface."
msgstr "Vous n'êtes pas autorisé à voir l'interface de trésorerie."
#: apps/treasury/views.py:122
#: apps/treasury/views.py:115
msgid "Update an invoice"
msgstr "Modifier la facture"
#: apps/treasury/views.py:247
#: apps/treasury/views.py:240
msgid "Create a new remittance"
msgstr "Créer une nouvelle remise"
#: apps/treasury/views.py:274
#: apps/treasury/views.py:267
msgid "Remittances list"
msgstr "Liste des remises"
#: apps/treasury/views.py:337
#: apps/treasury/views.py:326
msgid "Update a remittance"
msgstr "Modifier la remise"
#: apps/treasury/views.py:360
#: apps/treasury/views.py:349
msgid "Attach a transaction to a remittance"
msgstr "Joindre une transaction à une remise"
#: apps/treasury/views.py:404
#: apps/treasury/views.py:393
msgid "List of credits from the Société générale"
msgstr "Liste des crédits de la Société générale"
#: apps/treasury/views.py:449
#: apps/treasury/views.py:438
msgid "Manage credits from the Société générale"
msgstr "Gérer les crédits de la Société générale"