kenken999 commited on
Commit
b9cf572
1 Parent(s): dde85ab
Files changed (1) hide show
  1. routers/postg/gradio_app.py +9 -1
routers/postg/gradio_app.py CHANGED
@@ -81,7 +81,7 @@ def crud_interface():
81
  started_at = gr.Textbox(label="Started At")
82
  ended_at = gr.Textbox(label="Ended At")
83
  member_casual = gr.Textbox(label="Member Casual")
84
- ride_id = gr.Number(label="Ride ID (for update/delete)", value=-1)
85
 
86
  create_button = gr.Button("Create Ride")
87
  update_button = gr.Button("Update Ride")
@@ -125,6 +125,12 @@ def crud_interface():
125
  def read_rides_click():
126
  return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
127
 
 
 
 
 
 
 
128
  create_button.click(fn=create_ride_click,
129
  inputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual],
130
  outputs=output)
@@ -133,6 +139,8 @@ def crud_interface():
133
  outputs=output)
134
  delete_button.click(fn=delete_ride_click, inputs=ride_id, outputs=output)
135
  read_button.click(fn=read_rides_click, outputs=output)
 
 
136
 
137
  return interface
138
 
 
81
  started_at = gr.Textbox(label="Started At")
82
  ended_at = gr.Textbox(label="Ended At")
83
  member_casual = gr.Textbox(label="Member Casual")
84
+ ride_id = gr.Number(label="Ride ID (for update/delete)", value=-1, interactive=False)
85
 
86
  create_button = gr.Button("Create Ride")
87
  update_button = gr.Button("Update Ride")
 
125
  def read_rides_click():
126
  return [[r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]] for r in read_rides()]
127
 
128
+ def load_ride_details(evt: gr.SelectData):
129
+ ride_id = int(evt.value[0]) # クリックした行のride_idを取得
130
+ ride = read_ride(ride_id)
131
+ if ride:
132
+ return ride[1], ride[2], ride[3], ride[4], ride[5], ride[6], ride[7], ride[8], ride[0]
133
+
134
  create_button.click(fn=create_ride_click,
135
  inputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual],
136
  outputs=output)
 
139
  outputs=output)
140
  delete_button.click(fn=delete_ride_click, inputs=ride_id, outputs=output)
141
  read_button.click(fn=read_rides_click, outputs=output)
142
+
143
+ output.select(load_ride_details, inputs=None, outputs=[rideable_type, start_station_id, start_station_name, end_station_id, end_station_name, started_at, ended_at, member_casual, ride_id])
144
 
145
  return interface
146