|
|
|
|
@ -43,7 +43,9 @@ def styling():
|
|
|
|
|
|
|
|
|
|
def login_check(): |
|
|
|
|
if not app.storage.user.get('authenticated', False): |
|
|
|
|
return RedirectResponse('/login') |
|
|
|
|
return False |
|
|
|
|
else: |
|
|
|
|
return True |
|
|
|
|
|
|
|
|
|
# Create a connection |
|
|
|
|
conn = MontyClient("db") |
|
|
|
|
@ -54,7 +56,8 @@ db = conn.letsswing
|
|
|
|
|
# Routes |
|
|
|
|
@ui.page('/manager/{sede}/{livello}', title="Let's Swing Admin", favicon="assets/favicon.ico") |
|
|
|
|
def manager_page(sede:int, livello:int) -> None: |
|
|
|
|
login_check() |
|
|
|
|
if not login_check(): |
|
|
|
|
return RedirectResponse('/login') |
|
|
|
|
styling() |
|
|
|
|
|
|
|
|
|
manage = manager.Manager(handler) |
|
|
|
|
@ -66,20 +69,23 @@ app.add_static_files('/static', 'static')
|
|
|
|
|
@ui.page('/', title="Let's Swing Admin", favicon="assets/favicon.ico") |
|
|
|
|
def index_page() -> None: |
|
|
|
|
|
|
|
|
|
login_check() |
|
|
|
|
if not login_check(): |
|
|
|
|
return RedirectResponse('/login') |
|
|
|
|
styling() |
|
|
|
|
index.main(db) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ui.page('/user/{userid}', title="Let's Swing Admin", favicon="assets/favicon.ico") |
|
|
|
|
def user_page(userid: str) -> None: |
|
|
|
|
login_check() |
|
|
|
|
if not login_check(): |
|
|
|
|
return RedirectResponse('/login') |
|
|
|
|
styling() |
|
|
|
|
user.main(userid, db, handler) |
|
|
|
|
|
|
|
|
|
@ui.page('/edit/{userid}/{sede}/{livello}', title="Let's Swing Admin", favicon="assets/favicon.ico") |
|
|
|
|
def useredit_page(userid: str, sede: int, livello: int) -> None: |
|
|
|
|
login_check() |
|
|
|
|
if not login_check(): |
|
|
|
|
return RedirectResponse('/login') |
|
|
|
|
styling() |
|
|
|
|
useredit.main(userid, sede, livello, db, handler) |
|
|
|
|
|
|
|
|
|
@ -113,6 +119,19 @@ def page_login() -> None:
|
|
|
|
|
return RedirectResponse('/') |
|
|
|
|
ui.add_head_html(''' |
|
|
|
|
<link rel="manifest" href="/manifest.json"> |
|
|
|
|
<style> |
|
|
|
|
.hbtn { |
|
|
|
|
opacity: 0; |
|
|
|
|
visibility: hidden; |
|
|
|
|
transition: visibility 0s linear 0.5s, opacity 0.5s linear; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
.hbtn.visible { |
|
|
|
|
opacity: 1; |
|
|
|
|
visibility: visible; |
|
|
|
|
transition-delay: 0s; |
|
|
|
|
} |
|
|
|
|
</style> |
|
|
|
|
''') |
|
|
|
|
ui.add_body_html(''' |
|
|
|
|
<script> |
|
|
|
|
@ -128,7 +147,7 @@ def page_login() -> None:
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
</script>''') |
|
|
|
|
async def alert(): |
|
|
|
|
async def install(): |
|
|
|
|
await ui.run_javascript(''' |
|
|
|
|
// Show the prompt |
|
|
|
|
if(!deferredPrompt) |
|
|
|
|
@ -144,9 +163,17 @@ def page_login() -> None:
|
|
|
|
|
deferredPrompt = null; |
|
|
|
|
|
|
|
|
|
});''', respond=False) |
|
|
|
|
|
|
|
|
|
async def installable(btn): |
|
|
|
|
response = await ui.run_javascript(''' |
|
|
|
|
return (deferredPrompt ? true : false); |
|
|
|
|
''') |
|
|
|
|
if response: |
|
|
|
|
btn.classes("hbtn visible") |
|
|
|
|
|
|
|
|
|
with ui.card().classes('absolute-center items-center'): |
|
|
|
|
ui.button('Installa App', on_click=alert) |
|
|
|
|
install_btn =ui.button('Installa App', on_click=install,icon="install_mobile").classes("hbtn").props("outline") |
|
|
|
|
ui.timer(1, lambda: installable(install_btn), once=True) |
|
|
|
|
|
|
|
|
|
ui.image('assets/logo.svg') |
|
|
|
|
ui.label('Let\'s Swing Admin').classes('text-2xl').style("text-align:center") |
|
|
|
|
username = ui.input('Username').on('keydown.enter', try_login).classes('w-full') |
|
|
|
|
|