#4 Add bustime search options

pull/414/head
HeNine 3 years ago
parent 753784657e
commit 22e270b6ff

@ -2,7 +2,7 @@ from datetime import timedelta
import common import common
import flask as flask import flask as flask
from common import dateutil, database, format_bustime, dt_to_bustime from common import dateutil, database, format_bustime, dt_to_bustime, bustime_to_dt, parse_bustime
from dateutil.parser import ParserError from dateutil.parser import ParserError
from flask import request, jsonify, Response, render_template from flask import request, jsonify, Response, render_template
@ -68,20 +68,32 @@ def get_json():
(https://www.postgresql.org/docs/13/functions-textsearch.html)""" (https://www.postgresql.org/docs/13/functions-textsearch.html)"""
start_time_string = request.args.get('start_time') start_time_string = request.args.get('start_time')
bus_start_time_string = request.args.get('bus_start_time')
if start_time_string is not None: if start_time_string is not None:
try: try:
start_time = dateutil.parse(start_time_string) start_time = dateutil.parse(start_time_string)
except ParserError: except ParserError:
return "Invalid start time!", 400 return "Invalid start time!", 400
elif bus_start_time_string is not None:
try:
start_time = bustime_to_dt(app.bustime_start, parse_bustime(bus_start_time_string))
except ValueError:
return "Invalid bus end time!", 400
else: else:
start_time = None start_time = None
end_time_string = request.args.get('end_time') end_time_string = request.args.get('end_time')
bus_end_time_string = request.args.get('bus_end_time')
if end_time_string is not None: if end_time_string is not None:
try: try:
end_time = dateutil.parse(end_time_string) end_time = dateutil.parse(end_time_string)
except ParserError: except ParserError:
return "Invalid end time!", 400 return "Invalid end time!", 400
elif bus_end_time_string is not None:
try:
end_time = bustime_to_dt(app.bustime_start, parse_bustime(bus_end_time_string))
except ValueError:
return "Invalid bus end time!", 400
else: else:
end_time = None end_time = None

@ -6,6 +6,12 @@
margin-bottom: 1em; margin-bottom: 1em;
div {
margin: 0;
padding: 0;
display: flex;
}
label { label {
display: inline-block; display: inline-block;
font-family: @sans-serif; font-family: @sans-serif;
@ -29,6 +35,7 @@
#time_search_line { #time_search_line {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
flex-wrap: wrap;
input[type=datetime-local] { input[type=datetime-local] {
width: 13em; width: 13em;

@ -14,12 +14,20 @@
placeholder="Supports quotes, 'or' and -."> placeholder="Supports quotes, 'or' and -.">
</div> </div>
<div id="time_search_line" class="form_line"> <div id="time_search_line" class="form_line">
<label for="start_time">Start time</label> <input id="start_time" type="datetime-local"> <div><label for="start_time">Start time</label> <input id="start_time" type="datetime-local"></div>
<label for="end_time">End time</label> <input id="end_time" type="datetime-local"> <div><label for="end_time">End time</label> <input id="end_time" type="datetime-local"></div>
<div>
<label for="channel_select">Channel</label><select id="channel_select"> <label for="channel_select">Channel</label><select id="channel_select">
<option value="loadingreadyrun">loadingreadyrun</option> <option value="loadingreadyrun">loadingreadyrun</option>
</select> </select>
</div>
<div>
<label>Time type</label>
<input type="radio" name="time_type" id="UTC_time_radio" oninput="switchToUTC()" checked><label for="UTC_time_radio">UTC Time</label>
<input type="radio" name="time_type" id="bus_time_radio" oninput="switchToBus()"><label for="bus_time_radio">Bus Time</label>
</div>
<button id="search_button" onclick="doSearch()" type="button">Search</button> <button id="search_button" onclick="doSearch()" type="button">Search</button>
</div> </div>
</div> </div>

@ -11,11 +11,13 @@ function onSiteLoad(e) {
function query(text, start_time, end_time) { function query(text, start_time, end_time) {
let query_string = "" let query_string = ""
const time_type = document.getElementById("UTC_time_radio").checked ? "" : "bus_";
if (start_time !== "") { if (start_time !== "") {
query_string += `start_time=${start_time}`; query_string += `${time_type}start_time=${start_time}`;
} }
if (end_time !== "") { if (end_time !== "") {
query_string += `&end_time=${end_time}`; query_string += `&${time_type}end_time=${end_time}`;
} }
if (text !== "") { if (text !== "") {
query_string += `&query=${text}` query_string += `&query=${text}`
@ -63,3 +65,13 @@ function fillResults(results) {
results_element.append(line_div) results_element.append(line_div)
} }
} }
function switchToUTC() {
document.getElementById("start_time").type = "datetime-local";
document.getElementById("end_time").type = "datetime-local";
}
function switchToBus() {
document.getElementById("start_time").type = "text";
document.getElementById("end_time").type = "text";
}
Loading…
Cancel
Save