diff options
-rw-r--r-- | app.py | 19 | ||||
-rw-r--r-- | static/scripts.js | 12 | ||||
-rw-r--r-- | static/style.css | 18 | ||||
-rw-r--r-- | templates/template.html.j2 | 7 |
4 files changed, 38 insertions, 18 deletions
@@ -34,6 +34,16 @@ def serve_charts(): def search_redirect(): return flask.redirect("/search?s=%s" % urllib.parse.quote_plus(dict(flask.request.form)["search"])) +@app.route("/plot/<name>/apply_click", methods = ["POST"]) +def apply_redirect(name): + new_args = {} + for k, v in flask.request.form.items(): + if v != "No filter": + new_args[k] = v + + print("/" + "/".join(flask.request.full_path.split("/")[1:-1]) + "?" + urllib.parse.urlencode(new_args)) + return flask.redirect("/" + "/".join(flask.request.full_path.split("/")[1:-1]) + "?" + urllib.parse.urlencode(new_args)) + @app.route("/api/years") def api_get_years(): pay_type = flask.request.args.get("Pay Type") @@ -58,22 +68,25 @@ def search(): def get_chart_elem(url): for i in get_charts()["index"]: - if i["url"] == url: + if urllib.parse.urlparse(i["url"]).path == urllib.parse.urlparse(url).path: return i @app.route("/plot/<name>") def serve_large_plot(name): with database.PayGapDatabase(host = host) as db: + print(flask.request.full_path) elem = get_chart_elem(flask.request.full_path) filters = elem["filters"] for k, v in filters.items(): if v == "<SICType>": filters[k] = {"options": db.get_sic_sections()} + if v == "<CompanyType>": + filters[k] = {"options": db.get_company_types()} + if v == "<CompanySize>": + filters[k] = {"options": db.get_company_sizes()} current_filters = dict(flask.request.args) - print(filters) - print(current_filters) return flask.render_template( "plot.html.j2", title = elem["title"], diff --git a/static/scripts.js b/static/scripts.js index 6fec221..01196d3 100644 --- a/static/scripts.js +++ b/static/scripts.js @@ -1,5 +1,11 @@ -function collapseTogglePress(elem) { - console.log("elem"); +function collapseTogglePress(elem, a_elem, num_hidden) { + if (getComputedStyle(document.getElementById(elem)).display === "none") { + document.getElementById(elem).style.display = "block"; + document.getElementById(a_elem).innerText = `Hide ${num_hidden} filters` + } else { + document.getElementById(elem).style.display = "none"; + document.getElementById(a_elem).innerText =`Un-hide ${num_hidden} hidden filters` + } } const PLOT_FUNC_MAPPINGS = { @@ -7,7 +13,7 @@ const PLOT_FUNC_MAPPINGS = { } $(document).ready(function() { - console.log("ready!"); + document.getElementById("filterform").action = window.location.pathname + "/apply_click"; fetch("/api/charts.json").then((resp) => { resp.json().then((body) => { diff --git a/static/style.css b/static/style.css index 28d53c7..660a3b4 100644 --- a/static/style.css +++ b/static/style.css @@ -40,6 +40,13 @@ input[type="search"] { width: 100%; } +input[type="submit"] { + padding: 3px 5px; + box-sizing: border-box; + border: 2px solid black; + width: 100%; +} + aside form input[type="submit"] { margin-top: 3px; width: 100%; @@ -63,15 +70,8 @@ label { } .collapsetoggle { - color: black; - font-weight: bold; - padding-top: 1px; - text-decoration: none; -} - -.collapsetoggle#hover { - cursor: pointer; - text-decoration: underline; + font-size: x-small; + padding-left: 5px; } #main_content { diff --git a/templates/template.html.j2 b/templates/template.html.j2 index 72cf520..b50f721 100644 --- a/templates/template.html.j2 +++ b/templates/template.html.j2 @@ -36,13 +36,13 @@ </form> {% if filters is defined %} <h4>Filters</h4> - <form id="filterform"> + <form id="filterform" method="POST"> {% for filter_name, filter_content in filters.items() %} <h5>{{ filter_name }}</h5> {% if len(filter_content["options"]) > 5 %} - <button class="collapsetoggle" id="collapsetoggle/{{ filter_name }}" onclick="collapseTogglePress('collapsable/{{ filter_name }}')"> + <a class="collapsetoggle" id="collapsetoggle/{{ filter_name }}" onclick="collapseTogglePress('collapsable/{{ filter_name }}', 'collapsetoggle/{{ filter_name }}', {{ len(filter_content['options']) }})" href="javascript:void(0);"> {{ "Un-hide %d hidden filters" % len(filter_content["options"]) }} - </button> + </a> <div class="collapsable" id="collapsable/{{ filter_name }}"> {% endif %} {% for option in filter_content["options"] %} @@ -65,6 +65,7 @@ </div> {% endif %} {% endfor %} + <input type="submit" value="Apply" id="apply_btn"> </form> {% endif %} </aside> |