2020 DSM Hack repo for Iowa C.O.R.E. Rethink Iowa Website
WordPress website using PHP and JavaScript
- Tony Brobston
- Mike Kang
- Paul Kang
- Edwin O. Martinez
- Leah Haugh
- Josh Angolano
- Val Yeltman
- Gopo Iyer
- Wesley Ng
- Peter Chodakowski
- Jordan Van Kampen
Ideally we would refactor what we currently have and build some sort of contract or interface, like a function that takes in an api endpoint, the json path to the field we want to use for the heatmap weighting, etc. and return that heatmap weighting value, zip code, and county. If we coded a solution that expects this contract we could create a form to input these values and store them in wordpress, then pull that value in map.php
and interate over these form entries to build heatmaps. However this is quite a bit of work and at the hackathon we didn't have time to prove this concept.
For a future developer, to add another heat map you will do something similar to the following. I apologize that this guide will not be complete, so please follow loosly.
- Assuming you can use docker run
docker-compose.yaml
- Navigate to http://localhost:8080
- Create a new site (copy the password)
- Login as admin and navigate to Appearance > Themes and enabled "Iowa Core"
- Navgiate back to http://localhost:8080 to see the theme
- At this point you now have a non-production environment to play around (no you won't have data unfortunately).
- Next we'll make some code changes
- Make another option here:
Line 29 in ce092ea
- Use the value from the last step and create another
else if
here:Line 287 in ce092ea
- Make another function call here:
Line 286 in ce092ea
- Create the function it will call like this one:
Line 127 in ce092ea
- In the function from the last step, you'll need to find another GET Rest endpoint. When calling this endpoint the response data will be in
xhr.responseText
. You'll need to pull the heatmap weighting value from this data and pass it to thecensus_variable
like this:Line 150 in ce092ea
- Assuming you copied another function, you should be able to navigate to http://localhost:8080 and choose your new heatmap from the dropdown in the top left corner of the map.
- If I had to guess the most challenging part will be returning the correct data through a GET Rest endpoint and then pulling the heatmap weighting value from that data. This requires knowledge in rest endpoints, specifically how to call them and return different data, I can't explain this in 10 words or less 🤷, and JSON (JavaScript Object Notation). The best advice that I can give is reading up on these previously mentioned things and look at the other examples in this repo.
Line 130 in ce092ea
Line 137 in ce092ea
Line 187 in ce092ea
Line 193 in ce092ea
- Once this is working you'll need to FTP these changes to the Wordpress server. At one point I had some CI/CD (continuous integration/continuous deployment) setup which you can find a code sample here: https://github.com/dsmHack/iowa-core/blob/762045f50832290cb8ace716a5f1863d068c5dba/.scripts/deploy.sh The travis-ci likely does not have the correct ftp values set, so those would need updated if we went this route. Using something like Filezilla will work in the short term.
- Ideally we would refactor to change the code to make it easier to understand and more concise, there is definitely a lot of duplicate code that is unnecessary. Refactoring this is not a requirement.