diff --git a/buscribe-api/buscribeapi/buscribeapi.py b/buscribe-api/buscribeapi/buscribeapi.py index a5b847d..4d38718 100644 --- a/buscribe-api/buscribeapi/buscribeapi.py +++ b/buscribe-api/buscribeapi/buscribeapi.py @@ -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 diff --git a/buscribe-web/form.less b/buscribe-web/form.less index 87b1cac..0100603 100644 --- a/buscribe-web/form.less +++ b/buscribe-web/form.less @@ -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; diff --git a/buscribe-web/index.html b/buscribe-web/index.html index 1161146..bc6adb7 100644 --- a/buscribe-web/index.html +++ b/buscribe-web/index.html @@ -9,18 +9,26 @@
-
- -
-
- - +
+ +
+
+
+
+
- + + +
+
+ + +
+ + +
diff --git a/buscribe-web/script.js b/buscribe-web/script.js index 744241d..b7524e7 100644 --- a/buscribe-web/script.js +++ b/buscribe-web/script.js @@ -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"; } \ No newline at end of file