diff --git a/Dockerfile b/Dockerfile index 4c464fdf..d250560a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,7 +19,7 @@ RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - # # Read more on Dockerfile best practices at the source: # https://docs.docker.com/develop/develop-images/dockerfile_best-practices -RUN apt-get update && apt-get install -y --no-install-recommends postgresql-client nodejs +RUN apt-get update && apt-get install -y --no-install-recommends postgresql-client nodejs npm # Inside the container, create an app directory and switch into it RUN mkdir /app diff --git a/parserator_web/static/js/index.js b/parserator_web/static/js/index.js index 492674cc..0feeaa34 100644 --- a/parserator_web/static/js/index.js +++ b/parserator_web/static/js/index.js @@ -1,2 +1,42 @@ /* TODO: Flesh this out to connect the form to the API and render results in the #address-results div. */ +var api_url = "/api/parse"; +var button = document.getElementById("submit"); +var address = document.getElementById("address"); +var parse_type = document.getElementById("parse-type") +button.addEventListener("click", function (event) { + event.preventDefault(); + fetch(api_url + "?address=" + address.value).then(response => response.json()) + .then(data => { + const table_body = document.getElementById("table_body") + table_body.innerHTML = ''; + document.getElementById("address-results").style.display = "none"; + const errors = document.getElementById('errors'); + errors.style.display = "none" + if (data.errors) { + errors.innerText = data.errors; + errors.style.display = "block" + } + else { + let address_parts, address_type; + [address_parts, address_type] = data.payload; + parse_type.innerText = address_type + for (const key in address_parts) { + let r1 = document.createElement("tr") + let c1 = document.createElement("td") + c1.innerText = key + let c2 = document.createElement("td") + c2.innerText = address_parts[key] + r1.appendChild(c1); + r1.appendChild(c2); + table_body.appendChild(r1); + } + + document.getElementById("address-results").style.display = "block"; + } + }) + .catch(error => { + console.error('Error', error); + }); + +}); \ No newline at end of file diff --git a/parserator_web/templates/parserator_web/base.html b/parserator_web/templates/parserator_web/base.html index 8de4f844..15bebcd4 100644 --- a/parserator_web/templates/parserator_web/base.html +++ b/parserator_web/templates/parserator_web/base.html @@ -1,98 +1,96 @@ {% load static %} -
- - - -