add catering order info modal
This commit is contained in:
parent
4706183bde
commit
b1dc4071cf
@ -1,16 +1,15 @@
|
||||
from datetime import datetime
|
||||
from typing import Callable
|
||||
|
||||
import rio
|
||||
from rio import Component, Row, Text, TextStyle, Color
|
||||
from rio import Component, Row, Text, TextStyle, Color, Rectangle, CursorStyle
|
||||
from rio.components.pointer_event_listener import PointerEvent, PointerEventListener
|
||||
|
||||
from src.ez_lan_manager.types.CateringOrder import CateringOrderStatus
|
||||
from src.ez_lan_manager.types.CateringOrder import CateringOrderStatus, CateringOrder
|
||||
|
||||
MAX_LEN = 24
|
||||
|
||||
class CateringOrderItem(Component):
|
||||
order_id: int
|
||||
order_datetime: datetime
|
||||
order_status: CateringOrderStatus
|
||||
order: CateringOrder
|
||||
info_modal_cb: Callable
|
||||
|
||||
def get_display_text_and_color_for_order_status(self, order_status: CateringOrderStatus) -> tuple[str, Color]:
|
||||
match order_status:
|
||||
@ -29,10 +28,20 @@ class CateringOrderItem(Component):
|
||||
case _:
|
||||
return "Unbekannt(wtf?)", self.session.theme.danger_color
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
order_status, color = self.get_display_text_and_color_for_order_status(self.order_status)
|
||||
return Row(
|
||||
Text(f"ID: {str(self.order_id):0>6}", align_x=0, overflow="wrap", min_width=10, style=TextStyle(fill=self.session.theme.background_color, font_size=0.9), margin_right=1),
|
||||
Text(order_status, overflow="wrap", min_width=10, style=TextStyle(fill=color, font_size=0.9), margin_right=1),
|
||||
Text(self.order_datetime.strftime("%d.%m. %H:%M"), style=TextStyle(fill=self.session.theme.background_color, font_size=0.9), align_x=1)
|
||||
|
||||
def build(self) -> Component:
|
||||
order_status, color = self.get_display_text_and_color_for_order_status(self.order.status)
|
||||
return PointerEventListener(
|
||||
Rectangle(
|
||||
content=Row(
|
||||
Text(f"ID: {str(self.order.order_id):0>6}", align_x=0, overflow="wrap", min_width=10, style=TextStyle(fill=self.session.theme.background_color, font_size=0.9), margin_right=1),
|
||||
Text(order_status, overflow="wrap", min_width=10, style=TextStyle(fill=color, font_size=0.9), margin_right=1),
|
||||
Text(self.order.order_date.strftime("%d.%m. %H:%M"), style=TextStyle(fill=self.session.theme.background_color, font_size=0.9), align_x=1)
|
||||
),
|
||||
fill=self.session.theme.primary_color,
|
||||
hover_fill=self.session.theme.hud_color,
|
||||
transition_time=0.1,
|
||||
cursor=CursorStyle.POINTER
|
||||
),
|
||||
on_press=lambda _: self.info_modal_cb(self.order),
|
||||
)
|
||||
|
||||
@ -44,7 +44,7 @@ class CateringSelectionItem(Component):
|
||||
Text(AccountingService.make_euro_string_from_int(self.article_price), style=TextStyle(fill=self.session.theme.background_color, font_size=0.9)),
|
||||
IconButton(
|
||||
icon="material/add",
|
||||
size=2,
|
||||
min_size=2,
|
||||
color=self.session.theme.success_color,
|
||||
style="plain-text",
|
||||
on_press=lambda: self.on_add_callback(self.article_id),
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
from asyncio import sleep, create_task
|
||||
|
||||
import rio
|
||||
from rio import Component, Column, Text, TextStyle, Button, Row, ScrollContainer, Spacer, Popup
|
||||
from rio import Component, Column, Text, TextStyle, Button, Row, ScrollContainer, Spacer, Popup, Table
|
||||
|
||||
from src.ez_lan_manager.components.CateringCartItem import CateringCartItem
|
||||
from src.ez_lan_manager.components.CateringOrderItem import CateringOrderItem
|
||||
@ -87,6 +87,44 @@ class ShoppingCartAndOrders(Component):
|
||||
self.order_button_loading = False
|
||||
_ = create_task(self.show_popup("Bestellung erfolgreich aufgegeben!", False))
|
||||
|
||||
async def _create_order_info_modal(self, order: CateringOrder) -> None:
|
||||
def build_dialog_content() -> rio.Component:
|
||||
# @todo: rio 0.10.8 did not have the ability to align the columns, check back in a future version
|
||||
table = Table(
|
||||
{
|
||||
"Artikel": [item.name for item in order.items.keys()] + ["Gesamtpreis:"],
|
||||
"Anzahl": [item for item in order.items.values()] + [""],
|
||||
"Preis": [AccountingService.make_euro_string_from_int(item.price) for item in order.items.keys()] + [AccountingService.make_euro_string_from_int(order.price)],
|
||||
},
|
||||
show_row_numbers=False
|
||||
)
|
||||
return rio.Card(
|
||||
rio.Column(
|
||||
rio.Text(
|
||||
f"Deine Bestellung ({order.order_id})",
|
||||
align_x=0.5,
|
||||
margin_bottom=0.5
|
||||
),
|
||||
table,
|
||||
margin=2,
|
||||
),
|
||||
align_x=0.5,
|
||||
align_y=0.2,
|
||||
min_width=50,
|
||||
min_height=10,
|
||||
color=self.session.theme.primary_color,
|
||||
margin_left=1,
|
||||
margin_right=1,
|
||||
margin_top=2,
|
||||
margin_bottom=1,
|
||||
)
|
||||
dialog = await self.session.show_custom_dialog(
|
||||
build=build_dialog_content,
|
||||
modal=True,
|
||||
user_closeable=True,
|
||||
)
|
||||
await dialog.wait_for_close()
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
user_id = self.session[SessionStorage].user_id
|
||||
catering_service = self.session[CateringService]
|
||||
@ -158,9 +196,8 @@ class ShoppingCartAndOrders(Component):
|
||||
orders_container = ScrollContainer(
|
||||
content=Column(
|
||||
*[CateringOrderItem(
|
||||
order_id=order_item.order_id,
|
||||
order_datetime=order_item.order_date,
|
||||
order_status=order_item.status,
|
||||
order=order_item,
|
||||
info_modal_cb=self._create_order_info_modal
|
||||
) for order_item in self.orders],
|
||||
Spacer(grow_y=True)
|
||||
),
|
||||
@ -168,4 +205,4 @@ class ShoppingCartAndOrders(Component):
|
||||
min_width=33,
|
||||
margin=1
|
||||
)
|
||||
return Column(orders_container)
|
||||
return Column(orders_container)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user