Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New Features] New UI changes #20

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 82 additions & 28 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def check_login():
)
)
col1, col2 = st.columns(2)
st.session_state.id = col1.text_input(_("ID"), st.session_state.id)
st.session_state.pw = col2.text_input(_("PW"), st.session_state.pw, type="password")
st.session_state.id = col1.text_input(_("ID"), st.session_state.id, key="username")
st.session_state.pw = col2.text_input(_("PW"), st.session_state.pw, type="password", key="password")
login_button = st.button(_("Login"))
if login_button:
KTrains = name_to_class[st.session_state.mode]
Expand Down Expand Up @@ -128,28 +128,40 @@ def check_login():
# Main layout
ktrains = st.session_state.ktrains

# Set with two columns
col1, col2 = st.columns(2)
dep = col1.selectbox(
_("Departure"), stations.station_names(), index=107 if mode == "korail" else 0
)
arr = col2.selectbox(
_("Arrival"), stations.station_names(), index=44 if mode == "korail" else 5
)
dep = stations.convert_station_name(dep)
arr = stations.convert_station_name(arr)
stations_names = stations.station_names()
stations_names = list(map(str, stations_names))
if 'dep_index' not in st.session_state or 'arr_index' not in st.session_state:
if mode == "korail":
st.session_state.dep_index = 107
st.session_state.arr_index = 44
else:
st.session_state.dep_index = 0
st.session_state.arr_index = 5

col1, swap_col, col2 = st.columns([1, 0.2, 1])
swap_col.write(" ")
if swap_col.button("⇄"):
# Swap the values in session state
st.session_state.dep_index, st.session_state.arr_index = st.session_state.arr_index, st.session_state.dep_index
dep = stations_names[st.session_state.dep_index]
arr = stations_names[st.session_state.arr_index]
# Use session state for indices
dep = col1.selectbox(_("Departure"), stations_names, index=st.session_state.dep_index)
arr = col2.selectbox(_("Arrival"), stations_names, index=st.session_state.arr_index)

col1, col2 = st.columns(2)
date = col1.date_input("Date", value=st.session_state.cur_date)
time = col2.time_input("Time", value=st.session_state.cur_time)
st.session_state.cur_date = date
st.session_state.cur_time = time
date = date.strftime("%Y%m%d")
time = time.strftime("%H%M%S")
time_selected = time.strftime("%H%M%S")
#time = time.strftime("%H%M%S")
time = "000000"

table_stations = Stations(mode, language_sched)
if st.button(_("Search")):
trains = ktrains.search_train(dep, arr, date, time, available_only=False)
trains = ktrains.search_train(stations.convert_station_name(dep), stations.convert_station_name(arr), date, time, available_only=False)
if trains == []:
st.error("No trains found")
st.session_state.trains = None
Expand Down Expand Up @@ -242,18 +254,60 @@ def check_login():
date_formatted = date[:4] + "/" + date[4:6] + "/" + date[6:]
st.write(_("Search results for {}:").format(date_formatted))

grid_return = AgGrid(
df,
gridOptions=grid_options,
fit_columns_on_grid_load=False,
allow_unsafe_jscode=True,
columns_auto_size_mode=2,
enable_enterprise_modules=False,
header_checkbox_selection_filtered_only=True,
theme="streamlit",
use_checkbox=True,
width="200%",
)
# Split the dataframe into chunks for pagination
if 'current_chunk_index' not in st.session_state:
st.session_state['current_chunk_index'] = 0

if 'current_selected_time' not in st.session_state:
st.session_state['current_selected_time'] = "111111"

# Check if DataFrame is not empty
flag_time = time_selected
if not df.empty:
chunk_size = 10 # Default chunk size
if len(df) < chunk_size:
chunk_size = len(df)
chunks = [df[i:i + chunk_size] for i in range(0, len(df), chunk_size)]
total_chunks = len(chunks)

#Time changed
if st.session_state['current_selected_time'] != time_selected:
st.session_state['current_selected_time'] = time_selected
for i, chunk in enumerate(chunks):
times_chunks = chunk['Time'].str[:2]
if time_selected[:2] in times_chunks.tolist():
st.session_state['current_chunk_index'] = i
break

# Assuming grid_options is defined and AgGrid is imported
grid_return = AgGrid(
chunks[st.session_state['current_chunk_index']],
gridOptions=grid_options,
fit_columns_on_grid_load=False,
allow_unsafe_jscode=True,
columns_auto_size_mode=2,
enable_enterprise_modules=False,
header_checkbox_selection_filtered_only=True,
theme="streamlit",
use_checkbox=True,
width="200%",
)

# Navigation Buttons
kol2, kol1, kol3 = st.columns([0.7, 1, 1])

# Previous Button
with kol1:
if st.session_state['current_chunk_index'] > 0 and st.button("<- Previous"):
st.session_state['current_chunk_index'] -= 1
st.experimental_rerun()

# Next Button
with kol3:
if st.session_state['current_chunk_index'] < total_chunks - 1 and st.button("Next ->"):
st.session_state['current_chunk_index'] += 1
st.experimental_rerun()


new_df = pd.DataFrame(grid_return["selected_rows"])

Expand Down Expand Up @@ -360,9 +414,9 @@ def check_login():
"--email-receivers",
email_receivers,
"--dep",
dep,
stations.convert_station_name(dep),
"--arr",
arr,
stations.convert_station_name(arr),
"--date",
date,
"--time",
Expand Down
Loading