-
Notifications
You must be signed in to change notification settings - Fork 1
/
sidebar.py
160 lines (148 loc) · 4.89 KB
/
sidebar.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from flet import (
UserControl,
Column,
Container,
IconButton,
Row,
Text,
IconButton,
NavigationRail,
NavigationRailDestination,
TextField,
alignment,
border_radius,
colors,
icons,
padding,
margin,
)
from data_store import DataStore
class Sidebar(UserControl):
def __init__(self, app_layout, store: DataStore, page):
super().__init__()
self.store: DataStore = store
self.app_layout = app_layout
self.nav_rail_visible = True
self.top_nav_items = [
NavigationRailDestination(
label_content=Text("Boards"),
label="Boards",
icon=icons.BOOK_OUTLINED,
selected_icon=icons.BOOK_OUTLINED
),
NavigationRailDestination(
label_content=Text("Members"),
label="Members",
icon=icons.PERSON,
selected_icon=icons.PERSON
),
]
self.top_nav_rail = NavigationRail(
selected_index=None,
label_type="all",
on_change=self.top_nav_change,
destinations=self.top_nav_items,
extended=True,
height=110,
bgcolor=colors.ORANGE_900
)
self.bottom_nav_rail = NavigationRail(
selected_index=None,
label_type="all",
on_change=self.bottom_nav_change,
extended=True,
expand=True,
bgcolor=colors.ORANGE_900,
)
self.toggle_nav_rail_button = IconButton(icons.ARROW_BACK)
def build(self):
self.view = Container(
content=Column([
Row([
Text("Workspace"),
], alignment="spaceBetween"),
# divider
Container(
bgcolor=colors.WHITE,
border_radius=border_radius.all(30),
height=1,
alignment=alignment.center_right,
width=220
),
self.top_nav_rail,
# divider
Container(
bgcolor=colors.WHITE,
border_radius=border_radius.all(30),
height=1,
alignment=alignment.center_right,
width=220
),
self.bottom_nav_rail
], tight=True),
padding=padding.all(15),
margin=margin.all(0),
width=250,
expand=True,
bgcolor=colors.ORANGE_900,
visible=self.nav_rail_visible,
)
return self.view
def sync_board_destinations(self):
boards = self.store.get_boards()
self.bottom_nav_rail.destinations = []
for i in range(len(boards)):
b = boards[i]
self.bottom_nav_rail.destinations.append(
NavigationRailDestination(
label_content=TextField(
value=b.board_name,
hint_text=b.board_name,
text_size=12,
read_only=True,
on_focus=self.board_name_focus,
on_blur=self.board_name_blur,
border="none",
height=50,
width=150,
text_align="start",
data=i
),
label=b.board_name,
selected_icon=icons.CHEVRON_RIGHT_ROUNDED,
icon=icons.CHEVRON_RIGHT_OUTLINED
)
)
self.view.update()
def toggle_nav_rail(self, e):
self.view.visible = not self.view.visible
self.view.update()
self.page.update()
def board_name_focus(self, e):
e.control.read_only = False
e.control.border = "outline"
e.control.update()
def board_name_blur(self, e):
self.store.update_board(self.store.get_boards()[e.control.data], {
'name': e.control.value})
self.app_layout.hydrate_all_boards_view()
e.control.read_only = True
e.control.border = "none"
self.page.update()
def top_nav_change(self, e):
index = e if (type(e) == int) else e.control.selected_index
self.bottom_nav_rail.selected_index = None
self.top_nav_rail.selected_index = index
self.view.update()
if index == 0:
self.page.route = "/boards"
elif index == 1:
self.page.route = "/members"
self.page.update()
def bottom_nav_change(self, e):
index = e if (type(e) == int) else e.control.selected_index
self.top_nav_rail.selected_index = None
self.bottom_nav_rail.selected_index = index
self.page.route = f"/board/{index}"
self.view.update()
self.page.update()