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, Rectangle, CursorStyle
|
||||||
from rio import Component, Row, Text, TextStyle, Color
|
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
|
MAX_LEN = 24
|
||||||
|
|
||||||
class CateringOrderItem(Component):
|
class CateringOrderItem(Component):
|
||||||
order_id: int
|
order: CateringOrder
|
||||||
order_datetime: datetime
|
info_modal_cb: Callable
|
||||||
order_status: CateringOrderStatus
|
|
||||||
|
|
||||||
def get_display_text_and_color_for_order_status(self, order_status: CateringOrderStatus) -> tuple[str, Color]:
|
def get_display_text_and_color_for_order_status(self, order_status: CateringOrderStatus) -> tuple[str, Color]:
|
||||||
match order_status:
|
match order_status:
|
||||||
@ -29,10 +28,20 @@ class CateringOrderItem(Component):
|
|||||||
case _:
|
case _:
|
||||||
return "Unbekannt(wtf?)", self.session.theme.danger_color
|
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)
|
def build(self) -> Component:
|
||||||
return Row(
|
order_status, color = self.get_display_text_and_color_for_order_status(self.order.status)
|
||||||
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),
|
return PointerEventListener(
|
||||||
Text(order_status, overflow="wrap", min_width=10, style=TextStyle(fill=color, font_size=0.9), margin_right=1),
|
Rectangle(
|
||||||
Text(self.order_datetime.strftime("%d.%m. %H:%M"), style=TextStyle(fill=self.session.theme.background_color, font_size=0.9), align_x=1)
|
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)),
|
Text(AccountingService.make_euro_string_from_int(self.article_price), style=TextStyle(fill=self.session.theme.background_color, font_size=0.9)),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon="material/add",
|
icon="material/add",
|
||||||
size=2,
|
min_size=2,
|
||||||
color=self.session.theme.success_color,
|
color=self.session.theme.success_color,
|
||||||
style="plain-text",
|
style="plain-text",
|
||||||
on_press=lambda: self.on_add_callback(self.article_id),
|
on_press=lambda: self.on_add_callback(self.article_id),
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
from asyncio import sleep, create_task
|
from asyncio import sleep, create_task
|
||||||
|
|
||||||
import rio
|
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.CateringCartItem import CateringCartItem
|
||||||
from src.ez_lan_manager.components.CateringOrderItem import CateringOrderItem
|
from src.ez_lan_manager.components.CateringOrderItem import CateringOrderItem
|
||||||
@ -87,6 +87,44 @@ class ShoppingCartAndOrders(Component):
|
|||||||
self.order_button_loading = False
|
self.order_button_loading = False
|
||||||
_ = create_task(self.show_popup("Bestellung erfolgreich aufgegeben!", 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:
|
def build(self) -> rio.Component:
|
||||||
user_id = self.session[SessionStorage].user_id
|
user_id = self.session[SessionStorage].user_id
|
||||||
catering_service = self.session[CateringService]
|
catering_service = self.session[CateringService]
|
||||||
@ -158,9 +196,8 @@ class ShoppingCartAndOrders(Component):
|
|||||||
orders_container = ScrollContainer(
|
orders_container = ScrollContainer(
|
||||||
content=Column(
|
content=Column(
|
||||||
*[CateringOrderItem(
|
*[CateringOrderItem(
|
||||||
order_id=order_item.order_id,
|
order=order_item,
|
||||||
order_datetime=order_item.order_date,
|
info_modal_cb=self._create_order_info_modal
|
||||||
order_status=order_item.status,
|
|
||||||
) for order_item in self.orders],
|
) for order_item in self.orders],
|
||||||
Spacer(grow_y=True)
|
Spacer(grow_y=True)
|
||||||
),
|
),
|
||||||
@ -168,4 +205,4 @@ class ShoppingCartAndOrders(Component):
|
|||||||
min_width=33,
|
min_width=33,
|
||||||
margin=1
|
margin=1
|
||||||
)
|
)
|
||||||
return Column(orders_container)
|
return Column(orders_container)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user