add seat booking

This commit is contained in:
David Rodenkirchen
2024-09-06 14:12:33 +02:00
parent 871d8d6a3d
commit 3c3fd878c5
4 changed files with 183 additions and 17 deletions
@@ -1,18 +1,21 @@
from typing import Optional
from typing import Optional, Callable
from rio import Component, Column, Text, TextStyle, Button, Spacer
from src.ez_lan_manager import AccountingService
class SeatingPlanInfoBox(Component):
show: bool
purchase_cb: Callable
is_booking_blocked: bool
seat_id: Optional[str] = None
seat_occupant: Optional[str] = None
seat_price: int = 0
is_blocked: bool = False
user_has_seat: bool = False
def build(self) -> Component:
if not self.show:
return Spacer()
if self.is_blocked:
return Column(Text(f"Sitzplatz gesperrt", margin=1, style=TextStyle(fill=self.session.theme.neutral_color, font_size=1.4), wrap=True, justify="center"), min_height=10)
if self.seat_id is None and self.seat_occupant is None:
@@ -25,7 +28,7 @@ class SeatingPlanInfoBox(Component):
Text(f"Dieser Sitzplatz ({self.seat_id}) ist frei", margin=1, style=TextStyle(fill=self.session.theme.neutral_color), wrap=True, justify="center"),
Button(
Text(
f"Buchen ({AccountingService.make_euro_string_from_int(self.seat_price)})",
f"Buchen",
margin=1,
style=TextStyle(fill=self.session.theme.neutral_color, font_size=1.1),
wrap=True,
@@ -36,7 +39,8 @@ class SeatingPlanInfoBox(Component):
color="secondary",
margin=1,
grow_y=False,
is_sensitive=not self.user_has_seat
is_sensitive=not self.is_booking_blocked,
on_press=self.purchase_cb
),
min_height=10
)
@@ -0,0 +1,96 @@
from typing import Optional, Callable
from rio import Component, Column, Text, TextStyle, Button, Spacer, Row, ProgressCircle
class SeatingPurchaseBox(Component):
show: bool
seat_id: str
is_loading: bool
confirm_cb: Callable
cancel_cb: Callable
error_msg: Optional[str] = None
success_msg: Optional[str] = None
def build(self) -> Component:
if not self.show:
return Spacer()
if self.is_loading:
return Column(
ProgressCircle(
color="secondary",
align_x=0.5,
margin_top=2,
margin_bottom=2
),
min_height=10
)
if self.success_msg:
return Column(
Text(f"{self.success_msg}", margin=1, style=TextStyle(fill=self.session.theme.success_color, font_size=1.1),
wrap=True, justify="center"),
Row(
Button(
Text("Zurück",
margin=1,
style=TextStyle(fill=self.session.theme.success_color, font_size=1.1),
wrap=True,
justify="center"
),
shape="rounded",
style="plain",
on_press=self.cancel_cb
)
),
min_height=10
)
if self.error_msg:
return Column(
Text(f"{self.error_msg}", margin=1, style=TextStyle(fill=self.session.theme.danger_color, font_size=1.1),
wrap=True, justify="center"),
Row(
Button(
Text("Zurück",
margin=1,
style=TextStyle(fill=self.session.theme.danger_color, font_size=1.1),
wrap=True,
justify="center"
),
shape="rounded",
style="plain",
on_press=self.cancel_cb
)
),
min_height=10
)
return Column(
Text(f"Sitzplatz {self.seat_id} verbindlich buchen?", margin=1, style=TextStyle(fill=self.session.theme.neutral_color, font_size=1.4), wrap=True, justify="center"),
Row(
Button(
Text("Nein",
margin=1,
style=TextStyle(fill=self.session.theme.danger_color, font_size=1.1),
wrap=True,
justify="center"
),
shape="rounded",
style="plain",
on_press=self.cancel_cb
),
Button(
Text("Ja",
margin=1,
style=TextStyle(fill=self.session.theme.success_color, font_size=1.1),
wrap=True,
justify="center"
),
shape="rounded",
style="minor",
on_press=self.confirm_cb
)
),
min_height=10
)
@@ -58,7 +58,7 @@ class UserInfoAndLoginBox(Component):
@staticmethod
def get_greeting() -> str:
return choice(["Guten Tacho", "Tuten Gag", "Servus", "Moinjour", "Hallöchen Popöchen", "Heyho", "Moinsen"])
return choice(["Guten Tacho", "Tuten Gag", "Servus", "Moinjour", "Hallöchen", "Heyho", "Moinsen"])
# @FixMe: If the user logs out and then tries to log back in, it does not work
# If the user navigates to another page and then tries again. It works.