-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
337 lines (240 loc) · 12.4 KB
/
ui.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
import streamlit as st
from GSpreadFunctions import get_info, get_check_in_status, get_check_in_dict
import gspread
import pandas as pd
import pandasql as ps
import datetime
from streamlit_free_text_select import st_free_text_select
from itertools import chain
gc = gspread.service_account(filename= 'service_account.json')
def refresh_clicked():
st.session_state.refresh = True
def check_in_clicked():
st.session_state.check_in = True
st.session_state.series_info = get_info(st.session_state.name, st.session_state.email, gc, "DHMS 2024-25", "2/23/2024 - Volunteers")
def login_clicked():
login_creds = pd.read_csv("users.csv")
if st.session_state.username in list(login_creds["username"]) and st.session_state.password in list(login_creds["password"]):
st.session_state.valid_admin = "correct"
st.session_state.sidebar = "collapsed"
else:
st.session_state.valid_admin = "incorrect"
st.session_state.i = st.session_state.i + 1
st.session_state.username_key = f"user_{st.session_state.i}"
st.session_state.password_key = f"pass_{st.session_state.i}"
def admin_clicked():
if st.session_state.sidebar != "expanded":
st.session_state.sidebar = "expanded"
def volunteer_clicked():
st.session_state.valid_admin = None
def close_side():
st.session_state.sidebar = "collapsed"
def color_checked_in(name):
if name == 'n/a':
color = '#f0f0f5'
else:
checked_in = st.session_state.check_in_dict[name]
color = '#90ee90' if checked_in else '#FF7F7F'
return f'background-color: {color}'
def date_selected():
st.session_state.refresh=False
def reassign_name_clicked():
st.session_state.refresh=False
def reassign_teahcer_clicked():
st.session_state.refresh=False
def app() -> None:
if "check_in" not in st.session_state:
st.session_state.check_in = False
if "initial_setup" not in st.session_state:
st.session_state.initial_setup = True
if "valid_admin" not in st.session_state:
st.session_state.valid_admin = None
if "username_key" not in st.session_state:
st.session_state.username_key = "user_2"
if "password_key" not in st.session_state:
st.session_state.password_key = "pass_2"
if "i" not in st.session_state:
st.session_state.i = 2
if "sidebar" not in st.session_state:
st.session_state.sidebar = "collapsed"
if "refresh" not in st.session_state:
st.session_state.refresh = False
if "reassign_name" not in st.session_state:
st.session_state.reassign_name = None
if "reassign_teacher" not in st.session_state:
st.session_state.reassign_teacher = None
# Page configuration
st.set_page_config(
page_title="DHMS Check-In",
page_icon=":large_green_circle:",
layout='wide',
initial_sidebar_state=st.session_state.sidebar
)
st.markdown(
"""
<style>
svg[data-baseweb=icon] {
display: none;
}
div[data-testid="InputInstructions"] > span:nth-child(1) {
visibility: hidden;
}
div[data-testid=stSidebarCollapseButton] {
display: none;
}
.st-emotion-cache-1cyulp7 {
display: none;
}
button[kind=primary] {
float: right;
background-color: #e0e0ef;
border: none;
color: black
}
button[kind=primary]:hover {
background-color: #e0e0ef;
border: none;
color: #0000EE
}
</style>
""",
unsafe_allow_html=True,
)
if st.session_state.initial_setup:
sh = gc.open("DHMS 2024-25")
worksheet = sh.worksheet("2/23/2024 - Volunteers")
df = pd.DataFrame(worksheet.get_all_records())
st.session_state.names = ps.sqldf("""SELECT name FROM df""", locals())
st.session_state.emails = ps.sqldf("""SELECT email FROM df""", locals())
st.session_state.teachers = ps.sqldf("""SELECT DISTINCT teacher FROM df""", locals())
st.session_state.df = get_check_in_status(gc, "2/23/2024 - Volunteers")
st.session_state.check_in_dict = get_check_in_dict(gc, "2/23/2024 - Volunteers")
with st.sidebar:
st.button(
r"$\LARGE{\textsf{x}}$",
on_click=close_side,
type="primary",
)
st.markdown(
"<h1 style='text-align: center; color: black;'>Admin Login</h1>",
unsafe_allow_html=True,
)
if st.session_state.valid_admin == "incorrect":
st.warning("Incorrect username or password, please try again.")
st.session_state.username = st.text_input("Username:")
st.session_state.password = st.text_input("Password:")
st.button("Login", on_click=login_clicked, use_container_width=True, key=1)
else:
st.session_state.username = st.text_input("Username:", key=st.session_state.username_key)
st.session_state.password = st.text_input("Password:", key=st.session_state.password_key)
st.button("Login", on_click=login_clicked, use_container_width=True, key=1)
if st.session_state.valid_admin == "correct":
st.markdown(
"<h1 style='text-align: center; color: black;'>Druid Hills Middle School Admin View</h1>",
unsafe_allow_html=True,
)
# Sub title
st.markdown(
"<p style='text-align: center; color: black; opacity: .6;'>Enter the following information to check-in and receive your volunteer assignments</p>",
unsafe_allow_html=True,
)
_, _, col1, _ = st.columns([1,1.2,.3,1])
with col1:
st.button("Volunteer Check-In", on_click=volunteer_clicked, use_container_width=True)
_, col3, _ = st.columns([1,1.5,1])
with col3:
if st.session_state.refresh:
st.session_state.df = get_check_in_status(gc, "2/23/2024 - Volunteers")
st.session_state.check_in_dict = get_check_in_dict(gc, "2/23/2024 - Volunteers")
st.session_state.refresh = False
tab1, tab2 = st.tabs(["Event Dashboard", "Create New Event"])
with tab1:
with st.container(height=((len(st.session_state.df) + 1) * 35 + 3) + 475):
st.markdown(
"<h5 style='color: black;'>Select the date of the event:</h5>",
unsafe_allow_html=True,
)
st.session_state.date_of_event = st.date_input("What is the date of the event?", None, label_visibility="collapsed")
col5, col2 = st.columns([1,.2])
with col5:
st.markdown(
"<h5 style='color: black;'>Check-in Status:</h5>",
unsafe_allow_html=True,
)
with col2:
st.button("Refresh", on_click=refresh_clicked, use_container_width=True)
st.dataframe(st.session_state.df.style.map(color_checked_in, subset=['vol_1', 'vol_2', 'vol_3']), height = (len(st.session_state.df) + 1) * 35 + 3,use_container_width=True)
st.markdown(
"<h5 style='color: black;'>Re-assign Volunteer:</h5>",
unsafe_allow_html=True,
)
st.session_state.reassign_name = st_free_text_select(label="Name:", options=list(st.session_state.names["name"]), index=None, format_func=lambda x: x.title(), placeholder=' ', disabled=False, delay=300, label_visibility="visible")
st.session_state.reassign_teacher = st_free_text_select(label="New Teacher Assignment:", options=list(st.session_state.teachers["teacher"]), index=None, format_func=lambda x: x.title(), placeholder=' ', disabled=False, delay=300, label_visibility="visible")
st.button("Confirm Re-assign", use_container_width=True, disabled=((st.session_state.reassign_name == None) or (st.session_state.reassign_teacher == None)))
with tab2:
with st.container(height=670):
st.markdown(
"<h5 style='color: black;'>Create New Event:</h5>",
unsafe_allow_html=True,
)
st.session_state.date_of_new_event = st.date_input("What is the date of the new event?", None)
st.session_state.volunteer_assignments = st.file_uploader("Upload your volunteer assignments below", type=['xlsx', 'csv'], help="Upload a csv or xlsx file with the names, emails, and teacher assignment for each volunteer.")
st.button("Confirm New Event", use_container_width=True)
st.markdown(
"<h5 style='color: black;'>Add Volunteer to Event:</h5>",
unsafe_allow_html=True,
)
st.session_state.new_vol_name = st.text_input(label="Name:", label_visibility="visible")
st.session_state.new_vol_email = st.text_input(label="Email:", label_visibility="visible")
st.session_state.new_vol_teacher = st.text_input(label="Teacher Assignment:", label_visibility="visible")
st.button("Confirm New Volunteer", use_container_width=True)
else:
_, col4, _ = st.columns([1,1.2,1])
with col4:
if st.session_state.check_in:
st.markdown(
"<h1 style='text-align: center; color: black;'>Druid Hills Middle School Volunteer Check-In</h1>",
unsafe_allow_html=True,
)
# Sub title
st.markdown(
"<p style='text-align: center; color: black; opacity: .6;'>Enter the following information to check-in and receive your volunteer assignments</p>",
unsafe_allow_html=True,
)
_, col1 = st.columns([1,.23])
with col1:
st.button("Admin Login", on_click=admin_clicked, use_container_width=True)
with st.container(height=340):
st.success("Welcome, you are checked in! See information below and take a screenshot to refer back to.")
st.markdown("**Name:**")
st.write(st.session_state.series_info["name"].iloc[0])
st.markdown("**Teacher:**")
st.write(st.session_state.series_info["teacher"].iloc[0])
st.markdown("**Room Number:**")
st.write(str(st.session_state.series_info["room_number"].iloc[0]))
else:
st.markdown(
"<h1 style='text-align: center; color: black;'>Druid Hills Middle School Volunteer Check-In</h1>",
unsafe_allow_html=True,
)
# Sub title
st.markdown(
"<p style='text-align: center; color: black; opacity: .6;'>Enter the following information to check-in and receive your volunteer assignments</p>",
unsafe_allow_html=True,
)
_, col1 = st.columns([1,.23])
with col1:
st.button("Admin Login", on_click=admin_clicked, use_container_width=True)
with st.container(height=380):
# Title
st.markdown(
"<h5 style='color: black;'>Your Information:</h5>",
unsafe_allow_html=True,
)
st.session_state.name = st_free_text_select(label="Name:", options=list(st.session_state.names["name"]), index=None, format_func=lambda x: x.title(), placeholder=' ', disabled=False, delay=300, label_visibility="visible")
st.session_state.email = st_free_text_select(label="Email:", options=list(st.session_state.emails["email"]), index=None, format_func=lambda x: x.lower(), placeholder=' ', disabled=False, delay=300, label_visibility="visible")
st.session_state.phone_num = st.text_input(label="Phone Number:")
st.button("Check-In", on_click=check_in_clicked, use_container_width=True)
st.session_state.initial_setup = False
if __name__ == "__main__":
app()