in web/js/main.js [314:402]
async function init() {
// Check to see if we're logged in
const isCognitoRedirect = await checkAuthCode()
if (isCognitoRedirect) return
// Show what environment we're in
document.getElementById("target-env").innerHTML = TARGET_ENV
// console.log(APIGATEWAY_URL)
// Wire up the title link to reload the page
document.getElementById("graph-title-link").onclick = () => {
// Clear the selected parition and reload
removeCookie("partition")
window.location = "/"
}
// See if we previously selected a partition
const partition = getCookie("partition")
if (partition) {
await search(partition)
return
}
// Go get a list of partitions
try {
// Get the template
if (!partsTemplate) {
partsTemplate = await (await fetch("/tmpl/partitions.html?r=" + Math.random())).text()
}
// Fetch the list of partitions
const partitionResult = await post("search-post", { }, META_PARTITION)
console.log(partitionResult)
// Render the template to show the user the list of parts
const view = {}
view.parts = []
for (const node of partitionResult.nodes) {
if (node.labels[0] === "part") {
view.parts.push(node.properties.name)
}
}
const rendered = Mustache.render(partsTemplate, view)
const partsContainer = document.getElementById("parts-container")
partsContainer.innerHTML = rendered
partsContainer.style.display = "block"
if (view.parts.length === 0) {
document.getElementById("no-parts").style.display = "block"
} else {
document.getElementById("parts").style.display = "block"
// Wire up event handlers for the part buttons
for (const partName of view.parts) {
(function(p) {
const el = document.getElementById(`btn-${p}`)
el.onclick = async function() {
console.log("Selected partition", p)
setCookie("partition", p)
await search(p)
}
}(partName))
}
}
// Save the partition and reload
document.getElementById("btn-create-part").onclick = async () => {
const partName = document.getElementById("txt-part").value
if (!partName) return
await post("node-post", {
id: uuid.v4(),
labels: ["part"],
properties: {
name: partName,
},
}, META_PARTITION)
await search(partName)
}
} catch (ex) {
console.error(ex)
}
}