add news mananger

This commit is contained in:
David Rodenkirchen
2024-11-28 18:52:51 +01:00
parent 48ad800853
commit 947a05ad14
10 changed files with 278 additions and 10 deletions
@@ -44,10 +44,10 @@ class DesktopNavigation(Component):
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),
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",
+3 -1
View File
@@ -4,6 +4,7 @@ from rio import Component, TextStyle, Color, TextInput, Button, Text, Rectangle,
from src.ez_lan_manager.services.UserService import UserService
from src.ez_lan_manager.types.SessionStorage import SessionStorage
from src.ez_lan_manager.types.User import User
class LoginBox(Component):
@@ -17,10 +18,11 @@ class LoginBox(Component):
async def _on_login_pressed(self) -> None:
if await self.session[UserService].is_login_valid(self.user_name_input_text[0], self.password_input_text[0]):
user: User = await self.session[UserService].get_user(self.user_name_input_text[0])
self.user_name_input_is_valid = True
self.password_input_is_valid = True
self.login_button_is_loading = False
await self.session[SessionStorage].set_user_id((await self.session[UserService].get_user(self.user_name_input_text[0])).user_id)
await self.session[SessionStorage].set_user_id_and_team_member_flag(user.user_id, user.is_team_member)
await self.status_change_cb()
else:
self.user_name_input_is_valid = False
+69 -1
View File
@@ -1,4 +1,8 @@
from rio import Component, Rectangle, Text, TextStyle, Column, Row
from datetime import datetime
from functools import partial
from typing import Optional, Callable
from rio import Component, Rectangle, Text, TextStyle, Column, Row, TextInput, DateInput, MultiLineTextInput, IconButton, Color, Button
class NewsPost(Component):
@@ -79,3 +83,67 @@ class NewsPost(Component):
shadow_offset_y=0,
corner_radius=0.2
)
class EditableNewsPost(NewsPost):
news_id: int = -1
save_cb: Callable = lambda _: None
delete_cb: Callable = lambda _: None
def set_prop(self, prop, value) -> None:
self.__setattr__(prop, value)
def build(self) -> Component:
return Rectangle(
content=Column(
Row(
TextInput(
text=self.title,
label="Titel",
style="rounded",
min_width=15,
on_change=lambda e: self.set_prop("title", e.text)
),
DateInput(
value=datetime.strptime(self.date, "%d.%m.%Y"),
style="rounded",
on_change=lambda e: self.set_prop("date", e.value.strftime("%d.%m.%Y"))
)
),
TextInput(
text=self.subtitle,
label="Untertitel",
style="rounded",
grow_x=True,
on_change=lambda e: self.set_prop("subtitle", e.text)
),
MultiLineTextInput(
text=self.text,
label="Text",
style="rounded",
grow_x=True,
min_height=12,
on_change=lambda e: self.set_prop("text", e.text)
),
Row(
TextInput(
text=self.author,
label="Autor",
style="rounded",
grow_x=True,
on_change=lambda e: self.set_prop("author", e.text)
),
Rectangle(content=Button(icon="material/delete", style="major", color="danger", shape="rectangle", on_press=partial(self.delete_cb, self.news_id)), fill=Color.from_hex("0b7372")),
Rectangle(content=Button(icon="material/save", style="major", color="success", shape="rectangle", on_press=partial(self.save_cb, self)), fill=Color.from_hex("0b7372"))
)
),
fill=self.session.theme.primary_color,
margin_left=1,
margin_right=1,
margin_top=2,
margin_bottom=1,
shadow_radius=0.2,
shadow_color=self.session.theme.background_color,
shadow_offset_y=0,
corner_radius=0.2
)