mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-06-10 10:25:29 +03:00
update
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
from aiogram.types import User
|
||||
from aiogram_dialog import Dialog, Window, DialogManager
|
||||
from aiogram_dialog.widgets.text import Format
|
||||
from aiogram_dialog.widgets.text import Format, Const
|
||||
from aiogram_dialog.widgets.kbd import SwitchTo, Back
|
||||
from dishka import FromDishka
|
||||
from dishka.integrations.aiogram_dialog import inject
|
||||
|
||||
from dutylog.application.bot.user_dialogs.states import MainMenuSG
|
||||
from dutylog.infrastructure.database.repositories.users_repository import UsersRepository
|
||||
from dutylog.infrastructure.database.repositories.hours_transactions_repository import HoursTransactionsRepository
|
||||
from dutylog.infrastructure.utils.config import Config
|
||||
|
||||
|
||||
@@ -40,9 +42,9 @@ async def get_main_menu_data(
|
||||
|
||||
⏰ <b>Ваши часы дежурств</b>
|
||||
|
||||
<blockquote>🟢 <b>Неотработанные часы:</b> <code>{user.active_hours}</code> ч
|
||||
━━━━━━━━━━━━━━━
|
||||
🔴 Неактивные часы: <code>{user.inactive_hours}</code> ч</blockquote>
|
||||
<blockquote>🟢 <b>Отработанные часы:</b> <code>{user.active_hours}</code> ч
|
||||
━━━━━━━━━━━━━━━━
|
||||
🔴 Неотработанные часы: <code>{user.inactive_hours}</code> ч</blockquote>
|
||||
"""
|
||||
else:
|
||||
content = f"""
|
||||
@@ -53,13 +55,63 @@ async def get_main_menu_data(
|
||||
Добро пожаловать в систему учета дежурств!
|
||||
"""
|
||||
|
||||
return {"content": content}
|
||||
return {
|
||||
"content": content,
|
||||
"is_regular_user": not is_admin and not is_creator,
|
||||
}
|
||||
|
||||
|
||||
@inject
|
||||
async def get_history_data(
|
||||
dialog_manager: DialogManager,
|
||||
event_from_user: User,
|
||||
transactions_repository: FromDishka[HoursTransactionsRepository],
|
||||
**kwargs,
|
||||
):
|
||||
transactions = await transactions_repository.get_user_history(event_from_user.id)
|
||||
last_10 = transactions[:10]
|
||||
|
||||
if not last_10:
|
||||
history_text = """
|
||||
<blockquote>📜 <b>История операций</b></blockquote>
|
||||
|
||||
<i>История операций пуста</i>
|
||||
"""
|
||||
else:
|
||||
history_lines = []
|
||||
for tx in last_10:
|
||||
emoji = "➕" if tx.transaction_type == "increase" else "➖"
|
||||
date_str = tx.created_at.strftime("%d.%m.%Y %H:%M")
|
||||
history_lines.append(
|
||||
f"{emoji} <code>{tx.amount}</code> ч • <i>{date_str}</i>"
|
||||
)
|
||||
|
||||
history_text = f"""
|
||||
<blockquote>📜 <b>История операций</b></blockquote>
|
||||
|
||||
{"".join(f"{line}\n" for line in history_lines)}
|
||||
<i>Показаны последние 10 операций</i>
|
||||
"""
|
||||
|
||||
return {"history_content": history_text}
|
||||
|
||||
|
||||
main_menu_dialog = Dialog(
|
||||
Window(
|
||||
Format("{content}"),
|
||||
SwitchTo(
|
||||
Const("📜 История"),
|
||||
id="history_btn",
|
||||
state=MainMenuSG.history,
|
||||
when="is_regular_user",
|
||||
),
|
||||
state=MainMenuSG.main,
|
||||
getter=get_main_menu_data,
|
||||
),
|
||||
Window(
|
||||
Format("{history_content}"),
|
||||
Back(Const("◀️ Назад")),
|
||||
state=MainMenuSG.history,
|
||||
getter=get_history_data,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -3,3 +3,4 @@ from aiogram.fsm.state import State, StatesGroup
|
||||
|
||||
class MainMenuSG(StatesGroup):
|
||||
main = State()
|
||||
history = State()
|
||||
|
||||
Reference in New Issue
Block a user