Skip to content
Snippets Groups Projects
Commit afa15018 authored by Steffen Vogel's avatar Steffen Vogel :santa_tone2:
Browse files

fix link wizard

parent 8b676dd7
No related branches found
No related tags found
No related merge requests found
Pipeline #353189 passed
......@@ -12,33 +12,11 @@ function escapeHtml(unsafe) {
.replace(/'/g, "'");
}
function getProfiles() {
window.fetch(serviceUrl + '/profile/all', { mode: 'no-cors' })
.then((response) => response.json())
.then((json) => {
this.console.log(json);
for (const i in json.jobs) {
let job = json.jobs[i];
elm = this.document.getElementById('build-' + job.name);
if (elm) {
elm.classList.add(job.status);
elm.innerText = job.status;
elm.insertAdjacentHTML('afterend', '<span class="build-log">(open <a href="' + job.web_url + '">build log</a> #' + job.id + ' from ' + new Date(job.created_at).toLocaleString() + ')</span>');
}
}
});
async function getProfiles() {
let response = await fetch(serviceUrl + '/profile/api/all');
let json = await response.json();
return [
{
slug: "pti",
display_name: "[PTI] Praktikum Technische Informatik"
},
{
slug: "gdet3",
display_name: "[GDET3] Grundgebiete der Elektrotechnik 3"
}
]
return json.profiles;
}
function updateLink(event) {
......@@ -46,6 +24,7 @@ function updateLink(event) {
var filePath = document.getElementById("link-wizard-path");
var outputDiv = document.getElementById("link-wizard-output");
var directLink = document.getElementById("link-wizard-direct-link");
var badgeDiv = document.getElementById("link-wizard-badge");
var badgePre_md = document.getElementById("link-wizard-badge-md");
var badgePreHtml = document.getElementById("link-wizard-badge-html");
......@@ -56,23 +35,26 @@ function updateLink(event) {
if (profileSlug.length > 0) {
var link = updateDirectLink(slug, path);
// Link
directLink.innerHTML = link;
// Badges
// Badge Code
var badge_md = '[![](' + badgeURL + ')](' + link +')';
var badgeHtml = '<a href="' + link + '"><img src="' + badgeURL + '" /></a>';
badgePre_md.innerHTML = badge_md;
badgePreHtml.innerHTML = escapeHtml(badgeHtml);
// Link
directLink.innerHTML = '<a href="' + link + '">' + link + '</a>';
// Badge
badgeDiv.innerHTML = badgeHtml
outputDiv.style.display = 'block';
}
}
function generateProfileDropdown(profilesSelect) {
async function generateProfileDropdown(profilesSelect) {
// Fill profiles select
var profiles = getProfiles();
let profiles = await getProfiles();
for(var i = 0; i < profiles.length; i++) {
var o = document.createElement("option");
......@@ -95,8 +77,8 @@ function updateDirectLink(profileSlug, path) {
function loadBuildStatus() {
window.fetch(serviceUrl + '/profile/all')
.then((response) => response.json())
.then((json) => {
.then(response => response.json())
.then(json => {
this.console.log(json);
for (const i in json.jobs) {
let job = json.jobs[i];
......@@ -203,10 +185,10 @@ function insertVersionCollapsibles() {
}
}
window.addEventListener('load', function () {
window.addEventListener('load', e => {
if (window.location.pathname.endsWith('/Profiles.html')) {
loadBuildStatus();
insertVersionCollapsibles();
loadBuildStatus();
}
if (window.location.pathname.endsWith('/Links.html')) {
......
......@@ -25,7 +25,7 @@ You can use the following wizard to generate links and badges which open specifi
<h3>Link</h3>
<pre id="link-wizard-direct-link"></pre>
<h3>Badge</h3>
<img src="https://jupyter.pages.rwth-aachen.de/documentation/images/badge-launch-rwth-jupyter.svg" alt="RWTHjupyter badge">
<div id="link-wizard-badge"><img src="https://jupyter.pages.rwth-aachen.de/documentation/images/badge-launch-rwth-jupyter.svg" alt="RWTHjupyter badge"></div>
<h5>Markdown Snippet</h5>
<pre id="link-wizard-badge-md"></pre>
<h5>HTML Snippet</h5>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment