prerelease/0.6.0 (#1)
Co-authored-by: David Rodenkirchen <drodenkirchen@linetco.com> Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from pathlib import Path
|
||||
from uuid import uuid4
|
||||
|
||||
from from_root import from_root
|
||||
from rio import App, Theme, Color, Font, Icon, Session
|
||||
|
||||
from elm.components.RootComponent import RootComponent
|
||||
from elm.services import ConfigurationService, DatabaseService, UserService, LocalData, LocalDataService, MailingService, AccountingService, PreloadService, ReceiptPrintingService
|
||||
from elm.types import UserSession
|
||||
|
||||
logger = logging.getLogger("ELM")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
||||
theme = Theme.from_colors(
|
||||
primary_color=Color.from_hex("02DAC5"),
|
||||
secondary_color=Color.from_hex("018786"),
|
||||
neutral_color=Color.from_hex("0D1117"),
|
||||
background_color=Color.from_hex("0D1117"),
|
||||
hud_color=Color.from_hex("003736"),
|
||||
text_color=Color.from_hex("b9ccb2"),
|
||||
mode="dark",
|
||||
corner_radius_small=0,
|
||||
corner_radius_medium=0,
|
||||
corner_radius_large=0,
|
||||
font=Font(
|
||||
regular=from_root("src/elm/assets/PixelOperatorMono8.ttf"),
|
||||
bold=from_root("src/elm/assets/PixelOperatorMono8-Bold.ttf")
|
||||
)
|
||||
)
|
||||
|
||||
theme.primary_color_darker = Color.from_hex("008679")
|
||||
theme.primary_color_dark = Color.from_hex("003731")
|
||||
theme.danger_color_dark = Color.from_hex("7f1b15")
|
||||
theme.box_color = Color.from_hex("181c22")
|
||||
theme.box_border_color = Color.from_hex("354333")
|
||||
theme.header_box_background_color = Color.from_hex("30343b")
|
||||
theme.text_color = Color.from_hex("b9ccb2")
|
||||
theme.MAX_MOBILE_SCREEN_WIDTH = 28
|
||||
|
||||
Icon.register_single_icon(
|
||||
icon_source=from_root("src/elm/assets/custom_icons/ts3.svg"),
|
||||
set_name="custom",
|
||||
icon_name="ts3"
|
||||
)
|
||||
|
||||
configuration_service = ConfigurationService(from_root("config.toml"))
|
||||
database_service = DatabaseService(configuration_service.get_database_configuration())
|
||||
mailing_service = MailingService(configuration_service)
|
||||
lan_info = configuration_service.get_lan_info()
|
||||
|
||||
def is_mobile(self: Session) -> bool:
|
||||
return self.screen_width < self.theme.MAX_MOBILE_SCREEN_WIDTH
|
||||
|
||||
Session.is_mobile = is_mobile
|
||||
|
||||
async def on_session_start(session: Session) -> None:
|
||||
if configuration_service.DEV_MODE_ACTIVE:
|
||||
# Use this line to fake being any user without having to log in
|
||||
dev_user = await session[UserService].get_user("Typhus")
|
||||
if not dev_user:
|
||||
logger.fatal("DEV MODE USER DOES NOT EXIST")
|
||||
exit(1)
|
||||
session.attach(UserSession(id=uuid4(), user_name=dev_user.user_name, is_team_member=True, profile_picture=dev_user.user_picture))
|
||||
await session.set_title(f"{lan_info.name} - {lan_info.iteration}")
|
||||
if session[LocalData].stored_session_token:
|
||||
user_session = session[LocalDataService].verify_token(session[LocalData].stored_session_token)
|
||||
if user_session is not None:
|
||||
session.attach(user_session)
|
||||
|
||||
async def on_app_start(a: App) -> None:
|
||||
logger.info("Initializing mongodb...")
|
||||
await a.default_attachments[2].initialize()
|
||||
|
||||
app = App(
|
||||
name="elm",
|
||||
theme=theme,
|
||||
assets_dir=Path(__file__).parent / "assets",
|
||||
build=RootComponent,
|
||||
default_attachments=[LocalData(), configuration_service, database_service, UserService(), LocalDataService(), mailing_service, AccountingService(configuration_service, mailing_service), PreloadService(), ReceiptPrintingService(configuration_service.get_receipt_printing_configuration(), configuration_service.DEV_MODE_ACTIVE)],
|
||||
on_app_start=on_app_start,
|
||||
on_session_start=on_session_start,
|
||||
icon=from_root("src/elm/assets/img/favicon.png"),
|
||||
meta_tags={
|
||||
"robots": "INDEX,FOLLOW",
|
||||
"description": f"Info und Verwaltungs-Seite der LAN Party '{lan_info.name} - {lan_info.iteration}'.",
|
||||
"og:description": f"Info und Verwaltungs-Seite der LAN Party '{lan_info.name} - {lan_info.iteration}'.",
|
||||
"keywords": "Gaming, Clan, Guild, Verein, Club, Einfach, Zocken, Gesellschaft, Videospiele, "
|
||||
"Videogames, LAN, Party, EZ, EZGG, LAN, Manager",
|
||||
"author": "David Rodenkirchen",
|
||||
"publisher": "EZ GG e.V.",
|
||||
"copyright": "EZ GG e.V.",
|
||||
"audience": "Alle",
|
||||
"page-type": "Management Application",
|
||||
"page-topic": "LAN Party",
|
||||
"expires": "",
|
||||
"revisit-after": "2 days"
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user