Refactor logged-in and out messaging, Prepare Catering Module with shopping cart
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from typing import Callable
|
||||
|
||||
import rio
|
||||
from rio import Component, Row, Text, IconButton, TextStyle
|
||||
|
||||
from src.ez_lan_manager import AccountingService
|
||||
|
||||
MAX_LEN = 24
|
||||
|
||||
class CateringCartItem(Component):
|
||||
article_name: str
|
||||
article_price: int
|
||||
article_id: int
|
||||
list_id: int
|
||||
remove_item_cb: Callable
|
||||
|
||||
@staticmethod
|
||||
def ellipsize_string(string: str) -> str:
|
||||
if len(string) <= MAX_LEN:
|
||||
return string
|
||||
|
||||
return string[:MAX_LEN - 3] + "..."
|
||||
|
||||
def build(self) -> rio.Component:
|
||||
return Row(
|
||||
Text(self.ellipsize_string(self.article_name), align_x=0, wrap=True, min_width=19, 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(icon="material/close", size=2, color=self.session.theme.danger_color, style="plain", on_press=lambda: self.remove_item_cb(self.list_id)),
|
||||
proportions=(19, 5, 2)
|
||||
)
|
||||
@@ -7,20 +7,20 @@ from src.ez_lan_manager.components.UserInfoBox import UserInfoBox
|
||||
from src.ez_lan_manager.types.SessionStorage import SessionStorage
|
||||
|
||||
class DesktopNavigation(Component):
|
||||
def __post_init__(self) -> None:
|
||||
self.session[SessionStorage].subscribe_to_logged_in_or_out_event(self.__class__.__name__, self.refresh_cb)
|
||||
|
||||
async def refresh_cb(self) -> None:
|
||||
self.box = self.login_box if self.session[SessionStorage].user_id is None else self.user_info_box
|
||||
await self.force_refresh()
|
||||
|
||||
def build(self) -> Component:
|
||||
self.user_info_box = UserInfoBox()
|
||||
self.login_box = LoginBox(self.refresh_cb)
|
||||
self.box = self.login_box if self.session[SessionStorage].user_id is None else self.user_info_box
|
||||
box = LoginBox() if self.session[SessionStorage].user_id is None else UserInfoBox()
|
||||
lan_info = self.session[ConfigurationService].get_lan_info()
|
||||
return Card(
|
||||
Column(
|
||||
Text(lan_info.name, align_x=0.5, margin_top=0.3, style=TextStyle(fill=self.session.theme.hud_color, font_size=2.5)),
|
||||
Text(f"Edition {lan_info.iteration}", align_x=0.5, style=TextStyle(fill=self.session.theme.hud_color, font_size=1.2), margin_top=0.3, margin_bottom=2),
|
||||
self.box,
|
||||
box,
|
||||
DesktopNavigationButton("News", "./news"),
|
||||
Spacer(min_height=1),
|
||||
DesktopNavigationButton(f"Über {lan_info.name} {lan_info.iteration}", "./overview"),
|
||||
|
||||
@@ -8,17 +8,15 @@ from src.ez_lan_manager.types.SessionStorage import SessionStorage
|
||||
|
||||
class LoginBox(Component):
|
||||
TEXT_STYLE = TextStyle(fill=Color.from_hex("02dac5"), font_size=0.9)
|
||||
refresh_cb: Callable
|
||||
|
||||
async def _on_login_pressed(self) -> None:
|
||||
self.login_button.is_loading = True
|
||||
user_name = self.user_name_input.text.lower()
|
||||
if self.session[UserService].is_login_valid(user_name, self.password_input.text):
|
||||
self.session[SessionStorage].user_id = self.session[UserService].get_user(user_name).user_id
|
||||
self.user_name_input.is_valid = True
|
||||
self.password_input.is_valid = True
|
||||
self.login_button.is_loading = False
|
||||
await self.refresh_cb()
|
||||
await self.session[SessionStorage].set_user_id(self.session[UserService].get_user(user_name).user_id)
|
||||
else:
|
||||
self.user_name_input.is_valid = False
|
||||
self.password_input.is_valid = False
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from random import choice
|
||||
|
||||
from rio import Component, Card, Column, Text, Row, Rectangle, Button, TextStyle, Color, Spacer, TextInput, Link
|
||||
from rio import Component, Column, Text, Row, Rectangle, Button, TextStyle, Color, Link
|
||||
|
||||
from src.ez_lan_manager import UserService, AccountingService, TicketingService, SeatingService
|
||||
from src.ez_lan_manager.components.UserInfoBoxButton import UserInfoBoxButton
|
||||
@@ -35,6 +35,10 @@ class UserInfoBox(Component):
|
||||
def get_greeting() -> str:
|
||||
return choice(["Grüße", "Hallo", "Willkommen", "Moin", "Ahoi"])
|
||||
|
||||
async def logout(self) -> None:
|
||||
await self.session[SessionStorage].clear()
|
||||
await self.force_refresh()
|
||||
|
||||
def build(self) -> Component:
|
||||
user = self.session[UserService].get_user(self.session[SessionStorage].user_id)
|
||||
if user is None: # Noone logged in
|
||||
@@ -52,7 +56,17 @@ class UserInfoBox(Component):
|
||||
),
|
||||
UserInfoBoxButton("Profil bearbeiten", "./edit-profile"),
|
||||
UserInfoBoxButton(f"Guthaben: {a_s.make_euro_string_from_int(a_s.get_balance(user.user_id))}", "./account"),
|
||||
UserInfoBoxButton("Ausloggen", "./logout")
|
||||
Button(
|
||||
content=Text("Ausloggen", style=TextStyle(fill=Color.from_hex("02dac5"), font_size=0.6)),
|
||||
shape="rectangle",
|
||||
style="minor",
|
||||
color="secondary",
|
||||
grow_x=True,
|
||||
margin_left=0.6,
|
||||
margin_right=0.6,
|
||||
margin_top=0.6,
|
||||
on_press=self.logout
|
||||
)
|
||||
),
|
||||
fill=Color.TRANSPARENT,
|
||||
min_height=8,
|
||||
|
||||
Reference in New Issue
Block a user