Created
December 16, 2022 19:01
-
-
Save rileyrichter/1ec9c9d6344b42ad206c1f22ebb65f98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this | |
software and associated documentation files (the "Software"), to deal in the Software | |
without restriction, including without limitation the rights to use, copy, modify, merge, | |
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | |
to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or | |
substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | |
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
--> | |
<script> | |
const departmentIds = []; | |
const root = document.getElementById("root"); | |
const loading = document.getElementById("loading"); | |
const jobFilter = document.getElementById("filter"); | |
const errorWrapper = document.getElementById("errwrapper"); | |
const errorText = document.getElementById("errtext"); | |
const blueCard = document.querySelector("#blueCard"); | |
const cardGrid = document.querySelector("#cardGrid"); | |
// Filtering function for select element | |
jobFilter.onchange = function () { | |
let selectedSection = this.value; | |
if (selectedSection == "all") { | |
let filtered = document.querySelectorAll(".department-section"); | |
filtered.forEach((filtered) => { | |
filtered.style.display = "block"; | |
}); | |
} else { | |
let filtered = document.querySelectorAll(".department-section"); | |
filtered.forEach((filtered) => { | |
filtered.style.display = "none"; | |
}); | |
document.getElementById(selectedSection).style.display = "block"; | |
} | |
}; | |
// Triggers when the DOM is ready | |
window.addEventListener("DOMContentLoaded", (event) => { | |
const handleError = (response) => { | |
if (!response.ok) { | |
throw Error(` ${response.status} ${response.statusText}`); | |
} else { | |
return response.json(); | |
} | |
}; | |
fetch( | |
"https://boards-api.greenhouse.io/v1/boards/" + ghSlug + "/departments/" | |
) | |
.then(handleError) | |
.then((data) => { | |
data.departments.forEach((department) => { | |
if (department.jobs.length !== 0) { | |
departmentIds.push(department.id); | |
let sectionWrapper = document.getElementById("section"); | |
let sectionClone = sectionWrapper.cloneNode(true); | |
sectionClone.id = department.id; | |
root.appendChild(sectionClone); | |
let option = document.createElement("option"); | |
option.text = department.name; | |
option.value = department.id; | |
jobFilter.add(option); | |
//code for blue card | |
let blueCardClone = blueCard.cloneNode(true); | |
blueCardClone.querySelector(".stat-small").innerText = | |
department.name; | |
blueCardClone | |
.querySelector(".standard-link") | |
.setAttribute("href", `#${department.id}`); | |
cardGrid.appendChild(blueCardClone); | |
} else { | |
null; | |
} | |
}); | |
}) | |
.catch(function writeError(err) { | |
console.error(err); | |
}) | |
.finally(() => { | |
writeJobs(); | |
}); | |
}); | |
// Triggered in finally above | |
function writeJobs() { | |
departmentIds.forEach((departmentId) => { | |
const handleError = (response) => { | |
if (!response.ok) { | |
throw Error(` ${response.status} ${response.statusText}`); | |
} else { | |
return response.json(); | |
} | |
}; | |
fetch( | |
"https://boards-api.greenhouse.io/v1/boards/" + | |
ghSlug + | |
"/departments/" + | |
departmentId | |
) | |
.then(handleError) | |
.then((data) => { | |
//code for listings table | |
let parent = document.getElementById(data.id); | |
let parentContainer = parent.getElementsByClassName("container")[0]; | |
let sectionHeading = document.getElementById("dname"); | |
let sectionTitle = sectionHeading.cloneNode(true); | |
sectionTitle.innerText = data.name; | |
parentContainer.appendChild(sectionTitle); | |
data.jobs.forEach((job) => { | |
let listing = document.getElementById("listing"); | |
let ghListing = listing.cloneNode(true); | |
ghListing.id = job.id; | |
let jobTitle = ghListing.getElementsByClassName("job-title")[0]; | |
jobTitle.innerText = job.title; | |
jobTitle.setAttribute("href", job.absolute_url); | |
let jobLocation = ghListing.getElementsByClassName("job-location")[0]; | |
jobLocation.innerText = job.location.name; | |
parentContainer.appendChild(ghListing); | |
}); | |
}) | |
.catch(function writeError(err) { | |
console.error(err); | |
}) | |
.finally(() => { | |
loading.classList.add("invisible"); | |
loading.remove(); | |
root.classList.add("visible"); | |
}); | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment