You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
2.0 KiB
46 lines
2.0 KiB
from nicegui import ui, app |
|
from montydb import MontyClient |
|
|
|
def main(db: MontyClient): |
|
def choose(sede, livello): |
|
if int(livello) < 0: |
|
page.refresh(sede) |
|
else: |
|
ui.open(f"/manager/{sede}/{livello}") |
|
@ui.refreshable |
|
def page(sede): |
|
if int(sede) <0: |
|
results = db.sedi.find() |
|
ui.button(on_click=lambda: (app.storage.user.clear(), ui.open('/login')), icon='logout').props('outline round').style("positon:absolute").style("position:absolute") |
|
with ui.column().classes("w-full h-screen place-items-center items-center").style(""): |
|
ui.row().classes("grow") |
|
for result in results: |
|
ui.button(text=str(result['nome']).capitalize(),on_click=lambda id=result['id']:choose(id, -1)) |
|
ui.row().classes("grow") |
|
else: |
|
results = db.livelli.find() |
|
|
|
with ui.row().classes("w-full").style("position:absolute"): |
|
ui.icon("chevron_left", size="lg").on("click", lambda: page.refresh(-1)) |
|
with ui.column().classes("w-full h-screen place-items-center items-center"): |
|
ui.row().classes("grow") |
|
for result in results: |
|
ui.button(text=str(result['nome']).capitalize(),on_click=lambda id=result['id']:choose(sede, id)) |
|
ui.row().classes("grow") |
|
|
|
## FRONTEND |
|
ui.add_head_html(''' |
|
<link rel="manifest" href="/manifest.json"> |
|
''') |
|
ui.add_body_html('''<script>if ('serviceWorker' in navigator) { |
|
window.addEventListener('load', function() { |
|
navigator.serviceWorker.register('/static/service-worker.js').then(function(registration) { |
|
// Registration was successful |
|
console.log('ServiceWorker registration successful with scope: ', registration.scope); |
|
}, function(err) { |
|
// registration failed :( |
|
console.log('ServiceWorker registration failed: ', err); |
|
}); |
|
}); |
|
}</script>''') |
|
page(-1) |