add team navbar
This commit is contained in:
parent
f691851c9e
commit
48ad800853
@ -1,18 +1,29 @@
|
||||
from copy import copy, deepcopy
|
||||
from typing import Optional
|
||||
|
||||
from rio import *
|
||||
|
||||
from src.ez_lan_manager import ConfigurationService
|
||||
from src.ez_lan_manager import ConfigurationService, UserService
|
||||
from src.ez_lan_manager.components.DesktopNavigationButton import DesktopNavigationButton
|
||||
from src.ez_lan_manager.components.UserInfoAndLoginBox import UserInfoAndLoginBox
|
||||
from src.ez_lan_manager.types.SessionStorage import SessionStorage
|
||||
from src.ez_lan_manager.types.User import User
|
||||
|
||||
|
||||
class DesktopNavigation(Component):
|
||||
user: Optional[User] = None
|
||||
|
||||
@event.on_populate
|
||||
async def async_init(self) -> None:
|
||||
self.session[SessionStorage].subscribe_to_logged_in_or_out_event(str(self.__class__), self.async_init)
|
||||
if self.session[SessionStorage].user_id:
|
||||
self.user = await self.session[UserService].get_user(self.session[SessionStorage].user_id)
|
||||
else:
|
||||
self.user = None
|
||||
|
||||
def build(self) -> Component:
|
||||
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),
|
||||
UserInfoAndLoginBox(),
|
||||
user_navigation = [
|
||||
DesktopNavigationButton("News", "./news"),
|
||||
Spacer(min_height=1),
|
||||
DesktopNavigationButton(f"Über {lan_info.name} {lan_info.iteration}", "./overview"),
|
||||
@ -28,7 +39,31 @@ class DesktopNavigation(Component):
|
||||
DesktopNavigationButton("Die EZ GG e.V.", "https://ezgg-ev.de/about", open_new_tab=True),
|
||||
DesktopNavigationButton("Kontakt", "./contact"),
|
||||
DesktopNavigationButton("Impressum & DSGVO", "./imprint"),
|
||||
Spacer(min_height=1)
|
||||
]
|
||||
team_navigation = [
|
||||
Text("Verwaltung", align_x=0.5, margin_top=0.3, style=TextStyle(fill=Color.from_hex("F0EADE"), font_size=1.2)),
|
||||
Text("Vorsichtig sein!", align_x=0.5, margin_top=0.3, style=TextStyle(fill=self.session.theme.danger_color, font_size=0.6)),
|
||||
DesktopNavigationButton("News", "./manage_news", is_team_navigation=True),
|
||||
DesktopNavigationButton("Benutzer", "./manage_users", is_team_navigation=True),
|
||||
DesktopNavigationButton("Catering", "./manage_catering", is_team_navigation=True),
|
||||
DesktopNavigationButton("Turniere", "./manage_tournaments", is_team_navigation=True),
|
||||
Spacer(min_height=1),
|
||||
Revealer(
|
||||
header="Normale Navigation",
|
||||
content=Column(*user_navigation),
|
||||
header_style=TextStyle(fill=self.session.theme.primary_color, font_size=0.9)
|
||||
)
|
||||
] if self.user is not None and self.user.is_team_member else []
|
||||
|
||||
nav_to_use = copy(team_navigation) if self.user is not None and self.user.is_team_member else copy(user_navigation)
|
||||
|
||||
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),
|
||||
UserInfoAndLoginBox(),
|
||||
*nav_to_use,
|
||||
align_y=0
|
||||
),
|
||||
color=self.session.theme.neutral_color,
|
||||
|
||||
@ -1,19 +1,20 @@
|
||||
from rio import Component, TextStyle, Color, Link, Button, Text
|
||||
|
||||
|
||||
class DesktopNavigationButton(Component):
|
||||
STYLE = TextStyle(fill=Color.from_hex("02dac5"), font_size=0.9)
|
||||
TEAM_STYLE = TextStyle(fill=Color.from_hex("F0EADE"), font_size=0.9)
|
||||
label: str
|
||||
target_url: str
|
||||
is_team_navigation: bool = False
|
||||
open_new_tab: bool = False
|
||||
|
||||
def build(self) -> Component:
|
||||
return Link(
|
||||
content=Button(
|
||||
content=Text(self.label, style=self.STYLE),
|
||||
content=Text(self.label, style=self.TEAM_STYLE if self.is_team_navigation else self.STYLE),
|
||||
shape="rectangle",
|
||||
style="minor",
|
||||
color="secondary",
|
||||
color="danger" if self.is_team_navigation else "secondary",
|
||||
grow_x=True,
|
||||
margin_left=0.6,
|
||||
margin_right=0.6,
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
import logging
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Optional
|
||||
|
||||
logger = logging.getLogger(__name__.split(".")[-1])
|
||||
|
||||
|
||||
# ToDo: Persist between reloads: https://rio.dev/docs/howto/persistent-settings
|
||||
# Note for ToDo: rio.UserSettings are saved LOCALLY, do not just read a user_id here!
|
||||
@ -22,5 +25,6 @@ class SessionStorage:
|
||||
|
||||
async def set_user_id(self, user_id: Optional[int]) -> None:
|
||||
self._user_id = user_id
|
||||
for callback in self._notification_callbacks.values():
|
||||
for component_id, callback in self._notification_callbacks.items():
|
||||
logger.debug(f"Calling logged in callback from {component_id}")
|
||||
await callback()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user