59 lines
2.5 KiB
Python
59 lines
2.5 KiB
Python
from typing import Literal, Callable
|
|
|
|
from rio import Component, Rectangle, Column, Spacer, Text
|
|
from rio.event import on_populate
|
|
|
|
from elm.components import CateringItemBox
|
|
from elm.types.CateringTypes import CateringMenuItem, CateringMenuItemCategory
|
|
|
|
ITEM_CATEGORY_BY_DISPLAY_CATEGORY: dict[Literal["Frühstück", "Hauptspeisen", "Snacks & Dessert", "Softdrinks", "Alkohol"], list[CateringMenuItemCategory]] = {
|
|
"Frühstück": [CateringMenuItemCategory.BREAKFAST],
|
|
"Hauptspeisen": [CateringMenuItemCategory.MAIN_COURSE],
|
|
"Snacks & Dessert": [CateringMenuItemCategory.SNACK, CateringMenuItemCategory.DESSERT],
|
|
"Softdrinks": [CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC],
|
|
"Alkohol": [CateringMenuItemCategory.BEVERAGE_ALCOHOLIC, CateringMenuItemCategory.BEVERAGE_COCKTAIL, CateringMenuItemCategory.BEVERAGE_SHOT]
|
|
}
|
|
|
|
|
|
class CateringCategoryDisplay(Component):
|
|
active_category: Literal["Frühstück", "Hauptspeisen", "Snacks & Dessert", "Softdrinks", "Alkohol"]
|
|
add_to_cart_pressed_callback: Callable
|
|
catering_menu_items: list[CateringMenuItem] = []
|
|
|
|
@on_populate
|
|
async def on_populate(self) -> None:
|
|
self.catering_menu_items = await CateringMenuItem.find(
|
|
{
|
|
"category": {
|
|
"$in": ITEM_CATEGORY_BY_DISPLAY_CATEGORY[self.active_category]
|
|
}
|
|
}
|
|
).to_list()
|
|
|
|
async def add_to_cart_pressed(self, item: CateringMenuItem, changed_options: dict[str, bool]) -> None:
|
|
await self.add_to_cart_pressed_callback(item, changed_options)
|
|
|
|
def build(self) -> Component:
|
|
if len(self.catering_menu_items) <= 0:
|
|
return Spacer()
|
|
|
|
return Rectangle(
|
|
content=Column(
|
|
Rectangle(
|
|
content=Rectangle(
|
|
content=Text(self.active_category, margin=0.5, selectable=False, overflow="wrap"),
|
|
fill=self.session.theme.header_box_background_color,
|
|
margin=0.4
|
|
),
|
|
stroke_width=0.1,
|
|
stroke_color=self.session.theme.box_border_color,
|
|
),
|
|
# Items here
|
|
Column(*[CateringItemBox(item=i, add_to_cart_pressed_callback=self.add_to_cart_pressed, margin=0.5, grow_y=True) for i in self.catering_menu_items]),
|
|
Spacer()
|
|
),
|
|
fill=self.session.theme.box_color,
|
|
stroke_width=0.1,
|
|
stroke_color=self.session.theme.box_border_color
|
|
)
|