inventoryrouter/index.html

33 lines
1.2 KiB
HTML

<body>
<div id="status">Trying to find the right wiki page...</div>
<script>
const status_div = document.getElementById("status");
const asset_tag = window.location.search.slice(1);
fetch(
`https://wiki.claremontmakerspace.org/api.php?action=ask&query=[[Asset Tag::${asset_tag}]]&format=json&api_version=3&origin=*`
)
.then((r) => r.json())
.then((r) => {
if (r && r.query && r.query.results && r.query.results.length > 0) {
Object.entries(r.query.results[0]).forEach(([name, data]) => {
status_div.innerText = `Redirecting to Wiki Page for "${name}"...`;
window.location.assign(data.fullurl);
});
} else {
throw new Error("No results for query!");
}
})
.catch((e) => {
console.error(e);
status_div.innerText = "Failed to find an appropriate wiki page. ";
const link = status_div.appendChild(document.createElement("a"));
link.href =
"https://inventory.claremontmakerspace.org/hardware/bytag?assetTag=" +
asset_tag;
link.textContent = "Click here to go to the Inventory page";
});
</script>
</body>