improve group renaming
This commit is contained in:
28
frontend.py
28
frontend.py
@@ -10,11 +10,13 @@ OPTIONAL_LANGUAGES = ["French", "Spanish"]
|
||||
if "endpoint_groups" not in st.session_state:
|
||||
st.session_state.endpoint_groups = [
|
||||
{
|
||||
"id": 1,
|
||||
"name": "Gate1",
|
||||
"endpoints": ["endpoint1", "endpoint2"],
|
||||
"languages": DEFAULT_LANGUAGES.copy()
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "Gate2",
|
||||
"endpoints": ["endpoint3"],
|
||||
"languages": DEFAULT_LANGUAGES.copy()
|
||||
@@ -76,21 +78,21 @@ with st.container():
|
||||
col1, col2, col3 = st.columns(3)
|
||||
with col1:
|
||||
if st.button("Final Boarding Call"):
|
||||
group = next(g for g in st.session_state.endpoint_groups if g["name"] == "Gate1")
|
||||
group = next(g for g in st.session_state.endpoint_groups if g["id"] == 1)
|
||||
announcement_system.start_announcement(
|
||||
"This is the final boarding call for flight LX-380 to New York",
|
||||
group
|
||||
)
|
||||
with col2:
|
||||
if st.button("Security Reminder"):
|
||||
group = next(g for g in st.session_state.endpoint_groups if g["name"] == "Gate2")
|
||||
group = next(g for g in st.session_state.endpoint_groups if g["id"] == 2)
|
||||
announcement_system.start_announcement(
|
||||
"Please keep your luggage with you at all times",
|
||||
group
|
||||
)
|
||||
with col3:
|
||||
if st.button("Delay Notice"):
|
||||
group = next(g for g in st.session_state.endpoint_groups if g["name"] == "Gate1")
|
||||
group = next(g for g in st.session_state.endpoint_groups if g["id"] == 1)
|
||||
announcement_system.start_announcement(
|
||||
"We regret to inform you of a 30-minute delay",
|
||||
group
|
||||
@@ -98,13 +100,17 @@ with st.container():
|
||||
|
||||
# Custom announcement
|
||||
with st.form("custom_announcement"):
|
||||
# Get all groups
|
||||
groups = [group["name"] for group in st.session_state.endpoint_groups]
|
||||
selected_group = st.selectbox("Select announcement area", groups)
|
||||
# Get all groups with their names and IDs
|
||||
group_options = [(g["name"], g["id"]) for g in st.session_state.endpoint_groups]
|
||||
selected_group_name = st.selectbox(
|
||||
"Select announcement area",
|
||||
options=[g[0] for g in group_options]
|
||||
)
|
||||
message = st.text_area("Enter announcement text", "")
|
||||
|
||||
if st.form_submit_button("Make Announcement"):
|
||||
group = next(g for g in st.session_state.endpoint_groups if g["name"] == selected_group)
|
||||
selected_group_id = next(g[1] for g in group_options if g[0] == selected_group_name)
|
||||
group = next(g for g in st.session_state.endpoint_groups if g["id"] == selected_group_id)
|
||||
announcement_system.start_announcement(message, group)
|
||||
|
||||
# Configuration section in sidebar
|
||||
@@ -115,11 +121,14 @@ with st.sidebar:
|
||||
for i, group in enumerate(st.session_state.endpoint_groups):
|
||||
cols = st.columns([4, 1])
|
||||
with cols[0]:
|
||||
group["name"] = st.text_input(
|
||||
new_name = st.text_input(
|
||||
f"Group Name {i+1}",
|
||||
value=group["name"],
|
||||
key=f"group_name_{i}"
|
||||
)
|
||||
if new_name != group["name"]:
|
||||
group["name"] = new_name
|
||||
st.rerun()
|
||||
# Initialize session state for this group's endpoints if not already set
|
||||
if f"endpoints_{i}" not in st.session_state:
|
||||
st.session_state[f"endpoints_{i}"] = group["endpoints"]
|
||||
@@ -163,7 +172,10 @@ with st.sidebar:
|
||||
st.markdown("---")
|
||||
|
||||
if st.button("➕ Add Group"):
|
||||
# Generate a unique ID for the new group
|
||||
new_id = max(g["id"] for g in st.session_state.endpoint_groups) + 1 if st.session_state.endpoint_groups else 1
|
||||
st.session_state.endpoint_groups.append({
|
||||
"id": new_id,
|
||||
"name": f"Group {len(st.session_state.endpoint_groups)+1}",
|
||||
"endpoints": [],
|
||||
"languages": DEFAULT_LANGUAGES.copy()
|
||||
|
||||
Reference in New Issue
Block a user