IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Commit 51cd8647 authored by Amy Rose's avatar Amy Rose
Browse files

add basic information loading from Mystic

parent 31124f78
Pipeline #769 passed with stage
in 3 minutes and 23 seconds
......@@ -9,6 +9,7 @@ load_scripts:
{% comment %}
Divs to be filled in by the project.js script
{% endcomment %}
<h2>About</h2>
<div id="project-about"></div>
<div id="project-owner"></div> <!-- TODO: include for this? -->
......@@ -19,8 +20,12 @@ load_scripts:
{% comment %}
More divs to be filled in by project.js
{% endcomment %}
<h2>Metrics</h2>
<div id="project-metrics"></div>
<div id="project-members"></div> <!-- TODO: include for this? -->
<!-- TODO: include for this?
<h2>Team Members</h2>
<div id="project-members"></div>
-->
</div>
<noscript>
<p class="error">
......@@ -28,4 +33,16 @@ load_scripts:
be loaded. Please enable JavaScript to see project information.
</p>
</noscript>
<div id="loading-error" style="display: none;">
<p class="error">
Sorry, there was a problem loading the information for this project.
Please try again later. <br/>
If this problem persists, please contact Michael Nolan using the
contact information below.
</p>
</div>
</main>
<script>
const MYSTIC_PID = "{{ page.mystic-pid }}";
fetch_data();
</script>
/* TODO */
/* TODO: replace with live Mystic URL */
const MYSTIC_URL = new URL("http://localhost:5000/");
const API_PREFIX = "/";
/* MYSTIC_PID set by project.html layout */
function get_endpoint_url() {
const api_url = new URL(API_PREFIX, MYSTIC_URL);
const endpoint_url = new URL(`${MYSTIC_PID}.json`, api_url);
return endpoint_url;
}
function fetch_data() {
fetch(get_endpoint_url())
.then(response => {
if (response.status === 200) {
return response.json();
} else {
throw new Error("HTTP Error " + response.status +
": " + response.statusText);
}
})
.then(json_data => {
if (document.readyState === "complete") {
populate(json_data);
} else {
window.addEventListener("load", () => {
populate(json_data);
});
}
})
.catch(() => {
unhide_div("loading-error");
});
}
function unhide_div(div_id) {
const div = document.getElementById(div_id);
div.removeAttribute("style"); // remove display: none
}
function populate(data) {
console.log(data);
const project_about_div = document.getElementById("project-about");
project_about_div.innerText = data["desc"];
const project_metrics_div = document.getElementById("project-metrics");
data["embeds"].forEach(embed_data => {
const embed = document.createElement("iframe");
embed.setAttribute("src", new URL(embed_data["url"], MYSTIC_URL));
embed.setAttribute("title", embed_data["title"]);
project_metrics_div.appendChild(embed);
});
/* Content ready to show */
unhide_div("project-content");
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment