#4 Add bustime search options

trunk
HeNine 3 years ago
parent 753784657e
commit 22e270b6ff

@ -2,7 +2,7 @@ from datetime import timedelta
import common
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 flask import request, jsonify, Response, render_template
@ -68,20 +68,32 @@ def get_json():
(https://www.postgresql.org/docs/13/functions-textsearch.html)"""
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:
try:
start_time = dateutil.parse(start_time_string)
except ParserError:
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:
start_time = None
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:
try:
end_time = dateutil.parse(end_time_string)
except ParserError:
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:
end_time = None

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

@ -9,18 +9,26 @@
<body onload="onSiteLoad()">
<div id="search_tools">
<div id="text_search_line" class="form_line">
<label for="search_text">Search</label> <input type="search" id="search_text" oninput="doSearch()"
placeholder="Supports quotes, 'or' and -.">
</div>
<div id="time_search_line" class="form_line">
<label for="start_time">Start time</label> <input id="start_time" type="datetime-local">
<label for="end_time">End time</label> <input id="end_time" type="datetime-local">
<div id="text_search_line" class="form_line">
<label for="search_text">Search</label> <input type="search" id="search_text" oninput="doSearch()"
placeholder="Supports quotes, 'or' and -.">
</div>
<div id="time_search_line" class="form_line">
<div><label for="start_time">Start time</label> <input id="start_time" type="datetime-local"></div>
<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">
<option value="loadingreadyrun">loadingreadyrun</option>
</select>
<button id="search_button" onclick="doSearch()" type="button">Search</button>
<option value="loadingreadyrun">loadingreadyrun</option>
</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>
</div>
</div>
<div id="results">

@ -11,11 +11,13 @@ function onSiteLoad(e) {
function query(text, start_time, end_time) {
let query_string = ""
const time_type = document.getElementById("UTC_time_radio").checked ? "" : "bus_";
if (start_time !== "") {
query_string += `start_time=${start_time}`;
query_string += `${time_type}start_time=${start_time}`;
}
if (end_time !== "") {
query_string += `&end_time=${end_time}`;
query_string += `&${time_type}end_time=${end_time}`;
}
if (text !== "") {
query_string += `&query=${text}`
@ -62,4 +64,14 @@ function fillResults(results) {
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