-
Notifications
You must be signed in to change notification settings - Fork 0
/
welcome.py
63 lines (58 loc) · 2.22 KB
/
welcome.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from nicegui import ui
import swimport as sp
import swimview as sv
def projects_grid() -> ui.aggrid:
grid = ui.aggrid({
'columnDefs':[
{'headerName':'Name','field':'name','checkboxSelection':True}
],
'rowData':sp.list_projects(),
}).classes('max-h-40')
return grid
def handle_create(name):
try:
sp.create_project(name)
ui.notify(f'Created {name}')
except sp.projectExists:
ui.notify(f'{name} already exists')
except sp.noName:
ui.notify('Name is required')
@ui.page('/create')
def project_maker():
ui.link('Back','/')
project_name = ui.input(label='Project Name',
on_change=lambda e: safename_preview.set_text('Project will save as: ' + sp.make_project_name(e.value) if e.value else ''),
validation={'Input too long!': lambda value: len(value) < 200})
safename_preview = ui.label()
ui.button('Create', on_click=lambda: handle_create(project_name.value))
@ui.page('/open')
def project_opener():
ui.link('Back','/')
async def open_selected_project():
project = await projects_list.get_selected_row()
if project:
try:
ui.notify(f'''Open {project['name']}''')
ui.navigate.to(f'''/swimview?project_name={project['name']}''')
except sp.projectMissing:
ui.notify(f'''{project['name']} has moved, changed, or deleted. Try reloading.''')
else:
ui.notify('Select a project to open!')
projects_list = projects_grid()
ui.button('Open', on_click=open_selected_project)
@ui.page('/manage')
def project_manager():
ui.link('Back','/')
async def delete_selected_project():
project = await projects_list.get_selected_row()
if project:
try:
sp.delete_project(project['name'])
ui.navigate.reload()
# ui.notify(f'''{project['name']} deleted''')
except sp.projectMissing:
ui.notify(f'''{project['name']} should be gone already. Try reloading.''')
else:
ui.notify('Select a project to delete!')
projects_list = projects_grid()
ui.button('Delete', on_click=delete_selected_project)