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) { ...@@ -12,33 +12,11 @@ function escapeHtml(unsafe) {
.replace(/'/g, "'"); .replace(/'/g, "'");
} }
function getProfiles() { async function getProfiles() {
window.fetch(serviceUrl + '/profile/all', { mode: 'no-cors' }) let response = await fetch(serviceUrl + '/profile/api/all');
.then((response) => response.json()) let json = await 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>');
}
}
});
return [ return json.profiles;
{
slug: "pti",
display_name: "[PTI] Praktikum Technische Informatik"
},
{
slug: "gdet3",
display_name: "[GDET3] Grundgebiete der Elektrotechnik 3"
}
]
} }
function updateLink(event) { function updateLink(event) {
...@@ -46,6 +24,7 @@ function updateLink(event) { ...@@ -46,6 +24,7 @@ function updateLink(event) {
var filePath = document.getElementById("link-wizard-path"); var filePath = document.getElementById("link-wizard-path");
var outputDiv = document.getElementById("link-wizard-output"); var outputDiv = document.getElementById("link-wizard-output");
var directLink = document.getElementById("link-wizard-direct-link"); 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 badgePre_md = document.getElementById("link-wizard-badge-md");
var badgePreHtml = document.getElementById("link-wizard-badge-html"); var badgePreHtml = document.getElementById("link-wizard-badge-html");
...@@ -56,23 +35,26 @@ function updateLink(event) { ...@@ -56,23 +35,26 @@ function updateLink(event) {
if (profileSlug.length > 0) { if (profileSlug.length > 0) {
var link = updateDirectLink(slug, path); var link = updateDirectLink(slug, path);
// Link // Badge Code
directLink.innerHTML = link;
// Badges
var badge_md = '[![](' + badgeURL + ')](' + link +')'; var badge_md = '[![](' + badgeURL + ')](' + link +')';
var badgeHtml = '<a href="' + link + '"><img src="' + badgeURL + '" /></a>'; var badgeHtml = '<a href="' + link + '"><img src="' + badgeURL + '" /></a>';
badgePre_md.innerHTML = badge_md; badgePre_md.innerHTML = badge_md;
badgePreHtml.innerHTML = escapeHtml(badgeHtml); badgePreHtml.innerHTML = escapeHtml(badgeHtml);
// Link
directLink.innerHTML = '<a href="' + link + '">' + link + '</a>';
// Badge
badgeDiv.innerHTML = badgeHtml
outputDiv.style.display = 'block'; outputDiv.style.display = 'block';
} }
} }
function generateProfileDropdown(profilesSelect) { async function generateProfileDropdown(profilesSelect) {
// Fill profiles select // Fill profiles select
var profiles = getProfiles(); let profiles = await getProfiles();
for(var i = 0; i < profiles.length; i++) { for(var i = 0; i < profiles.length; i++) {
var o = document.createElement("option"); var o = document.createElement("option");
...@@ -95,8 +77,8 @@ function updateDirectLink(profileSlug, path) { ...@@ -95,8 +77,8 @@ function updateDirectLink(profileSlug, path) {
function loadBuildStatus() { function loadBuildStatus() {
window.fetch(serviceUrl + '/profile/all') window.fetch(serviceUrl + '/profile/all')
.then((response) => response.json()) .then(response => response.json())
.then((json) => { .then(json => {
this.console.log(json); this.console.log(json);
for (const i in json.jobs) { for (const i in json.jobs) {
let job = json.jobs[i]; let job = json.jobs[i];
...@@ -203,10 +185,10 @@ function insertVersionCollapsibles() { ...@@ -203,10 +185,10 @@ function insertVersionCollapsibles() {
} }
} }
window.addEventListener('load', function () { window.addEventListener('load', e => {
if (window.location.pathname.endsWith('/Profiles.html')) { if (window.location.pathname.endsWith('/Profiles.html')) {
loadBuildStatus();
insertVersionCollapsibles(); insertVersionCollapsibles();
loadBuildStatus();
} }
if (window.location.pathname.endsWith('/Links.html')) { 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 ...@@ -25,7 +25,7 @@ You can use the following wizard to generate links and badges which open specifi
<h3>Link</h3> <h3>Link</h3>
<pre id="link-wizard-direct-link"></pre> <pre id="link-wizard-direct-link"></pre>
<h3>Badge</h3> <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> <h5>Markdown Snippet</h5>
<pre id="link-wizard-badge-md"></pre> <pre id="link-wizard-badge-md"></pre>
<h5>HTML Snippet</h5> <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