mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-08-08 18:11:14 +03:00
add delete button to resident history detail window for creator only; dynamic back navigation from delete confirmation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from aiogram import Bot
|
||||
from aiogram.enums import ContentType
|
||||
from aiogram.types import Message, CallbackQuery, InputMediaPhoto
|
||||
from aiogram.types import Message, CallbackQuery, InputMediaPhoto, User
|
||||
from aiogram.utils.markdown import html_decoration as hd
|
||||
from aiogram_dialog import Window, DialogManager
|
||||
from aiogram_dialog.widgets.text import Format, Const
|
||||
@@ -28,6 +28,7 @@ from dutylog.infrastructure.database.repositories.users_repository import (
|
||||
from dutylog.infrastructure.database.repositories.hours_transactions_repository import (
|
||||
HoursTransactionsRepository,
|
||||
)
|
||||
from dutylog.infrastructure.utils.config import Config
|
||||
from dutylog.infrastructure.utils.datetime import msk_now
|
||||
|
||||
|
||||
@@ -660,10 +661,12 @@ async def on_transaction_selected(
|
||||
|
||||
@inject
|
||||
async def get_transaction_detail_data(
|
||||
event_from_user: User,
|
||||
dialog_manager: DialogManager,
|
||||
transactions_repository: FromDishka[HoursTransactionsRepository],
|
||||
residents_repository: FromDishka[ResidentsRepository],
|
||||
users_repository: FromDishka[UsersRepository],
|
||||
config: FromDishka[Config],
|
||||
**kwargs,
|
||||
):
|
||||
tx_id = dialog_manager.dialog_data.get("selected_transaction_id")
|
||||
@@ -712,10 +715,13 @@ async def get_transaction_detail_data(
|
||||
else:
|
||||
detail_content = content
|
||||
|
||||
is_creator = event_from_user.id == config.bot.creator_id
|
||||
|
||||
return {
|
||||
"detail_content": detail_content,
|
||||
"photo_media": photo_media,
|
||||
"has_multiple_photos": has_multiple_photos,
|
||||
"is_creator": is_creator,
|
||||
}
|
||||
|
||||
|
||||
@@ -727,6 +733,16 @@ async def on_search_transactions(
|
||||
await dialog_manager.switch_to(AdminMenuSG.resident_history_search_input)
|
||||
|
||||
|
||||
@inject
|
||||
async def on_resident_delete_transaction_click(
|
||||
callback: CallbackQuery,
|
||||
button: Button,
|
||||
dialog_manager: DialogManager,
|
||||
):
|
||||
dialog_manager.dialog_data["delete_source"] = "resident_history"
|
||||
await dialog_manager.switch_to(AdminMenuSG.transactions_history_delete_confirm)
|
||||
|
||||
|
||||
async def on_transaction_search_input(
|
||||
message: Message,
|
||||
widget: MessageInput,
|
||||
@@ -1141,8 +1157,16 @@ resident_history_window = Window(
|
||||
)
|
||||
|
||||
resident_history_detail_window = Window(
|
||||
DynamicMedia("photo_media"),
|
||||
DynamicMedia("photo_media", when=F["photo_media"]),
|
||||
Format("{detail_content}", when=F["detail_content"]),
|
||||
Row(
|
||||
Button(
|
||||
Const("🗑 Удалить"),
|
||||
id="resident_delete_transaction_btn",
|
||||
on_click=on_resident_delete_transaction_click,
|
||||
when=F["is_creator"],
|
||||
),
|
||||
),
|
||||
SwitchTo(
|
||||
Const("◀️ К списку"),
|
||||
id="back_to_history_from_detail",
|
||||
|
||||
@@ -118,6 +118,7 @@ async def on_delete_transaction_click(
|
||||
button: Button,
|
||||
dialog_manager: DialogManager,
|
||||
):
|
||||
dialog_manager.dialog_data["delete_source"] = "transactions_history"
|
||||
await dialog_manager.switch_to(AdminMenuSG.transactions_history_delete_confirm)
|
||||
|
||||
|
||||
@@ -132,7 +133,24 @@ async def on_delete_transaction_confirm(
|
||||
if tx_id:
|
||||
await transactions_repository.delete_transaction(int(tx_id))
|
||||
await callback.answer("✅ Транзакция удалена", show_alert=True)
|
||||
await dialog_manager.switch_to(AdminMenuSG.transactions_history)
|
||||
source = dialog_manager.dialog_data.pop("delete_source", "transactions_history")
|
||||
if source == "resident_history":
|
||||
await dialog_manager.switch_to(AdminMenuSG.resident_history)
|
||||
else:
|
||||
await dialog_manager.switch_to(AdminMenuSG.transactions_history)
|
||||
|
||||
|
||||
@inject
|
||||
async def on_delete_transaction_back(
|
||||
callback: CallbackQuery,
|
||||
button: Button,
|
||||
dialog_manager: DialogManager,
|
||||
):
|
||||
source = dialog_manager.dialog_data.pop("delete_source", "transactions_history")
|
||||
if source == "resident_history":
|
||||
await dialog_manager.switch_to(AdminMenuSG.resident_history_detail)
|
||||
else:
|
||||
await dialog_manager.switch_to(AdminMenuSG.transactions_history_detail)
|
||||
|
||||
|
||||
@inject
|
||||
@@ -257,10 +275,10 @@ transactions_history_delete_confirm_window = Window(
|
||||
on_click=on_delete_transaction_confirm,
|
||||
),
|
||||
),
|
||||
SwitchTo(
|
||||
Button(
|
||||
Const("◀️ Назад"),
|
||||
id="back_to_transaction_detail",
|
||||
state=AdminMenuSG.transactions_history_detail,
|
||||
on_click=on_delete_transaction_back,
|
||||
),
|
||||
state=AdminMenuSG.transactions_history_delete_confirm,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user