Renamed "sorting" to "reorder", and the "sort-form" route to "order".

This commit is contained in:
依瑪貓 2023-02-03 10:19:52 +08:00
parent 8363ce6602
commit 589da0c1c6
7 changed files with 56 additions and 60 deletions

View File

@ -131,11 +131,11 @@ def sort_accounts_in(base_code: str, exclude: int) -> None:
accounts[i].no = i + 1 accounts[i].no = i + 1
class AccountSortForm: class AccountReorderForm:
"""The form to sort the accounts.""" """The form to reorder the accounts."""
def __init__(self, base: BaseAccount): def __init__(self, base: BaseAccount):
"""Constructs the form to sort the accounts under a base account. """Constructs the form to reorder the accounts under a base account.
:param base: The base account. :param base: The base account.
""" """

View File

@ -29,7 +29,7 @@ from accounting.models import Account, BaseAccount
from accounting.utils.next_url import inherit_next, or_next from accounting.utils.next_url import inherit_next, or_next
from accounting.utils.pagination import Pagination from accounting.utils.pagination import Pagination
from accounting.utils.permission import can_view, has_permission, can_edit from accounting.utils.permission import can_view, has_permission, can_edit
from .forms import AccountForm, sort_accounts_in, AccountSortForm from .forms import AccountForm, sort_accounts_in, AccountReorderForm
bp: Blueprint = Blueprint("account", __name__) bp: Blueprint = Blueprint("account", __name__)
"""The view blueprint for the account management.""" """The view blueprint for the account management."""
@ -168,28 +168,27 @@ def delete_account(account: Account) -> redirect:
return redirect(or_next(url_for("accounting.account.list"))) return redirect(or_next(url_for("accounting.account.list")))
@bp.get("/sort/<baseAccount:base>", endpoint="sort-form") @bp.get("/base/<baseAccount:base>", endpoint="order")
@has_permission(can_edit) @has_permission(can_edit)
def show_sort_form(base: BaseAccount) -> str: def show_account_order(base: BaseAccount) -> str:
"""Shows the form to sort the accounts under a base account. """Shows the order of the accounts under a same base account.
:param base: The base account. :param base: The base account.
:return: The form to sort the accounts under the base account. :return: The order of the accounts under the base account.
""" """
return render_template("accounting/account/sort.html", return render_template("accounting/account/order.html", base=base)
base=base)
@bp.post("/sort/<baseAccount:base>", endpoint="sort") @bp.post("/base/<baseAccount:base>", endpoint="sort")
@has_permission(can_edit) @has_permission(can_edit)
def sort_accounts(base: BaseAccount) -> redirect: def sort_accounts(base: BaseAccount) -> redirect:
"""Sorts the accounts under a base account. """Reorders the accounts under a base account.
:param base: The base account. :param base: The base account.
:return: The redirection to the incoming account or the account list. The :return: The redirection to the incoming account or the account list. The
sorting operation does not fail. reordering operation does not fail.
""" """
form: AccountSortForm = AccountSortForm(base) form: AccountReorderForm = AccountReorderForm(base)
form.save_order() form.save_order()
if not form.is_modified: if not form.is_modified:
flash(lazy_gettext("The order was not modified."), "success") flash(lazy_gettext("The order was not modified."), "success")

View File

@ -1,5 +1,5 @@
/* The Mia! Accounting Flask Project /* The Mia! Accounting Flask Project
* account-sort.js: The JavaScript for the account sorting form * account-order.js: The JavaScript for the account order
*/ */
/* Copyright (c) 2023 imacat. /* Copyright (c) 2023 imacat.
@ -23,15 +23,15 @@
// Initializes the page JavaScript. // Initializes the page JavaScript.
document.addEventListener("DOMContentLoaded", function () { document.addEventListener("DOMContentLoaded", function () {
const list = document.getElementById("sort-account-list"); const list = document.getElementById("account-order-list");
const onReorder = function () { const onReorder = function () {
const accounts = Array.from(list.children); const accounts = Array.from(list.children);
for (let i = 0; i < accounts.length; i++) { for (let i = 0; i < accounts.length; i++) {
const input = document.getElementById("sort-" + accounts[i].dataset.id + "-no"); const no = document.getElementById("account-order-" + accounts[i].dataset.id + "-no");
const code = document.getElementById("sort-" + accounts[i].dataset.id + "-code"); const code = document.getElementById("account-order-" + accounts[i].dataset.id + "-code");
input.value = i + 1; no.value = String(i + 1);
code.innerText = list.dataset.baseCode + "-" + ("000" + (i + 1)).slice(-3); code.innerText = list.dataset.baseCode + "-" + ("000" + (i + 1)).slice(-3);
} }
}; };
initializeDragAndDropSorting(list, onReorder); initializeDragAndDropReordering(list, onReorder);
}); });

View File

@ -1,5 +1,5 @@
/* The Mia! Accounting Flask Project /* The Mia! Accounting Flask Project
* drag-and-drop-sorting.js: The JavaScript for the sorting with drag-and-drop * drag-and-drop-reorder.js: The JavaScript for the reorder a list with drag-and-drop
*/ */
/* Copyright (c) 2023 imacat. /* Copyright (c) 2023 imacat.
@ -22,24 +22,24 @@
*/ */
/** /**
* Initializes the drag-and-drop sorting on a list. * Initializes the drag-and-drop reordering on a list.
* *
* @param list {HTMLElement} the list to be sorted * @param list {HTMLElement} the list to be reordered
* @param onReorder {(function())|*} The callback to reorder the items * @param onReorder {(function())|*} The callback to reorder the items
*/ */
function initializeDragAndDropSorting(list, onReorder) { function initializeDragAndDropReordering(list, onReorder) {
initializeMouseDragAndDropSorting(list, onReorder); initializeMouseDragAndDropReordering(list, onReorder);
initializeTouchDragAndDropSorting(list, onReorder); initializeTouchDragAndDropReordering(list, onReorder);
} }
/** /**
* Initializes the drag-and-drop sorting with mouse. * Initializes the drag-and-drop reordering with mouse.
* *
* @param list {HTMLElement} the list to be sorted * @param list {HTMLElement} the list to be reordered
* @param onReorder {(function())|*} The callback to reorder the items * @param onReorder {(function())|*} The callback to reorder the items
* @private * @private
*/ */
function initializeMouseDragAndDropSorting(list, onReorder) { function initializeMouseDragAndDropReordering(list, onReorder) {
const items = Array.from(list.children); const items = Array.from(list.children);
let dragged = null; let dragged = null;
items.forEach(function (item) { items.forEach(function (item) {
@ -60,13 +60,13 @@ function initializeMouseDragAndDropSorting(list, onReorder) {
} }
/** /**
* Initializes the drag-and-drop sorting with touch devices. * Initializes the drag-and-drop reordering with touch devices.
* *
* @param list {HTMLElement} the list to be sorted * @param list {HTMLElement} the list to be reordered
* @param onReorder {(function())|*} The callback to reorder the items * @param onReorder {(function())|*} The callback to reorder the items
* @private * @private
*/ */
function initializeTouchDragAndDropSorting(list, onReorder) { function initializeTouchDragAndDropReordering(list, onReorder) {
const items = Array.from(list.children); const items = Array.from(list.children);
items.forEach(function (item) { items.forEach(function (item) {
item.addEventListener("touchstart", function () { item.addEventListener("touchstart", function () {

View File

@ -35,9 +35,9 @@ First written: 2023/1/31
<i class="fa-solid fa-gear"></i> <i class="fa-solid fa-gear"></i>
{{ A_("Settings") }} {{ A_("Settings") }}
</a> </a>
<a class="btn btn-primary" href="{{ url_for("accounting.account.sort-form", base=obj.base)|append_next }}"> <a class="btn btn-primary" href="{{ url_for("accounting.account.order", base=obj.base)|append_next }}">
<i class="fa-solid fa-sort"></i> <i class="fa-solid fa-bars-staggered"></i>
{{ A_("Sort") }} {{ A_("Order") }}
</a> </a>
<button class="btn btn-danger" type="button" data-bs-toggle="modal" data-bs-target="#delete-modal"> <button class="btn btn-danger" type="button" data-bs-toggle="modal" data-bs-target="#delete-modal">
<i class="fa-solid fa-trash"></i> <i class="fa-solid fa-trash"></i>

View File

@ -1,6 +1,6 @@
{# {#
The Mia! Accounting Flask Project The Mia! Accounting Flask Project
sort.html: The account sorting form order.html: The order of the accounts under a same base account
Copyright (c) 2023 imacat. Copyright (c) 2023 imacat.
@ -22,11 +22,11 @@ First written: 2023/2/2
{% extends "accounting/account/include/form.html" %} {% extends "accounting/account/include/form.html" %}
{% block accounting_scripts %} {% block accounting_scripts %}
<script src="{{ url_for("accounting.static", filename="js/drag-and-drop-sorting.js") }}"></script> <script src="{{ url_for("accounting.static", filename="js/drag-and-drop-reorder.js") }}"></script>
<script src="{{ url_for("accounting.static", filename="js/account-sort.js") }}"></script> <script src="{{ url_for("accounting.static", filename="js/account-order.js") }}"></script>
{% endblock %} {% endblock %}
{% block header %}{% block title %}{{ A_("Sort the Accounts of %(base)s", base=base) }}{% endblock %}{% endblock %} {% block header %}{% block title %}{{ A_("The Accounts of %(base)s", base=base) }}{% endblock %}{% endblock %}
{% block content %} {% block content %}
@ -42,18 +42,15 @@ First written: 2023/2/2
{% if "next" in request.args %} {% if "next" in request.args %}
<input type="hidden" name="next" value="{{ request.args["next"] }}"> <input type="hidden" name="next" value="{{ request.args["next"] }}">
{% endif %} {% endif %}
<ul id="sort-account-list" class="list-group mb-3" data-base-code="{{ base.code }}"> <ul id="account-order-list" class="list-group mb-3" data-base-code="{{ base.code }}">
{% for account in base.accounts|sort(attribute="no") %} {% for account in base.accounts|sort(attribute="no") %}
<li class="list-group-item d-flex justify-content-between" data-id="{{ account.id }}"> <li class="list-group-item d-flex justify-content-between" data-id="{{ account.id }}">
<input id="sort-{{ account.id }}-no" type="hidden" name="{{ account.id }}-no" value="{{ loop.index }}"> <input id="account-order-{{ account.id }}-no" type="hidden" name="{{ account.id }}-no" value="{{ loop.index }}">
<div> <div>
<span id="sort-{{ account.id }}-code">{{ account.code }}</span> <span id="account-order-{{ account.id }}-code">{{ account.code }}</span>
{{ account.title }} {{ account.title }}
</div> </div>
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"> <i class="fa-solid fa-bars"></i>
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M3 15h18v-2H3v2zm0 4h18v-2H3v2zm0-8h18V9H3v2zm0-6v2h18V5H3z"/>
</svg>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>

View File

@ -8,8 +8,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Mia! Accounting Flask 0.0.0\n" "Project-Id-Version: Mia! Accounting Flask 0.0.0\n"
"Report-Msgid-Bugs-To: imacat@mail.imacat.idv.tw\n" "Report-Msgid-Bugs-To: imacat@mail.imacat.idv.tw\n"
"POT-Creation-Date: 2023-02-03 07:40+0800\n" "POT-Creation-Date: 2023-02-03 10:15+0800\n"
"PO-Revision-Date: 2023-02-03 07:42+0800\n" "PO-Revision-Date: 2023-02-03 10:16+0800\n"
"Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n" "Last-Translator: imacat <imacat@mail.imacat.idv.tw>\n"
"Language: zh_Hant\n" "Language: zh_Hant\n"
"Language-Team: zh_Hant <imacat@mail.imacat.idv.tw>\n" "Language-Team: zh_Hant <imacat@mail.imacat.idv.tw>\n"
@ -42,23 +42,23 @@ msgstr "逐筆核銷"
msgid "The account is added successfully" msgid "The account is added successfully"
msgstr "科目加好了。" msgstr "科目加好了。"
#: src/accounting/account/views.py:140 #: src/accounting/account/views.py:143
msgid "The account was not modified." msgid "The account was not modified."
msgstr "科目未異動。" msgstr "科目未異動。"
#: src/accounting/account/views.py:145 #: src/accounting/account/views.py:148
msgid "The account is updated successfully." msgid "The account is updated successfully."
msgstr "科目存好了。" msgstr "科目存好了。"
#: src/accounting/account/views.py:163 #: src/accounting/account/views.py:167
msgid "The account is deleted successfully." msgid "The account is deleted successfully."
msgstr "科目刪掉了" msgstr "科目刪掉了"
#: src/accounting/account/views.py:190 #: src/accounting/account/views.py:194
msgid "The order was not modified." msgid "The order was not modified."
msgstr "順序未異動。" msgstr "順序未異動。"
#: src/accounting/account/views.py:193 #: src/accounting/account/views.py:197
msgid "The order is updated successfully." msgid "The order is updated successfully."
msgstr "順序存好了。" msgstr "順序存好了。"
@ -72,7 +72,7 @@ msgstr "新增科目"
#: src/accounting/templates/accounting/account/detail.html:31 #: src/accounting/templates/accounting/account/detail.html:31
#: src/accounting/templates/accounting/account/include/form.html:33 #: src/accounting/templates/accounting/account/include/form.html:33
#: src/accounting/templates/accounting/account/sort.html:35 #: src/accounting/templates/accounting/account/order.html:36
#: src/accounting/templates/accounting/base-account/detail.html:31 #: src/accounting/templates/accounting/base-account/detail.html:31
msgid "Back" msgid "Back"
msgstr "回上頁" msgstr "回上頁"
@ -82,8 +82,8 @@ msgid "Settings"
msgstr "設定" msgstr "設定"
#: src/accounting/templates/accounting/account/detail.html:40 #: src/accounting/templates/accounting/account/detail.html:40
msgid "Sort" msgid "Order"
msgstr "序" msgstr "序"
#: src/accounting/templates/accounting/account/detail.html:44 #: src/accounting/templates/accounting/account/detail.html:44
msgid "Delete" msgid "Delete"
@ -138,13 +138,13 @@ msgstr "搜尋"
msgid "There is no data." msgid "There is no data."
msgstr "沒有資料。" msgstr "沒有資料。"
#: src/accounting/templates/accounting/account/sort.html:28 #: src/accounting/templates/accounting/account/order.html:29
#, python-format #, python-format
msgid "Sort the Accounts of %(base)s" msgid "The Accounts of %(base)s"
msgstr "%(base)s下的科目排序" msgstr "%(base)s下的科目"
#: src/accounting/templates/accounting/account/include/form.html:75 #: src/accounting/templates/accounting/account/include/form.html:75
#: src/accounting/templates/accounting/account/sort.html:67 #: src/accounting/templates/accounting/account/order.html:61
msgid "Save" msgid "Save"
msgstr "儲存" msgstr "儲存"