Skip to content

Commit 05995b9

Browse files
committed
add a debug mode for in-browser development
1 parent 1168442 commit 05995b9

File tree

3 files changed

+142
-1
lines changed

3 files changed

+142
-1
lines changed

static/assets/codam.svg

Lines changed: 34 additions & 0 deletions
Loading

static/debug.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
console.warn('debug.js loaded');
2+
document.getElementById('info-debug').innerText = 'Running in debug mode';
3+
4+
// Make sure all elements are somewhat presentable
5+
const logo = document.getElementById('logo');
6+
logo.src = 'assets/codam.svg';
7+
8+
const message = document.getElementById('message');
9+
message.innerText = 'This is a test message that could have been sent by the back-end server for displaying.';
10+
11+
const examModeProjects = document.getElementById('exam-mode-projects');
12+
examModeProjects.innerText = 'Exam Rank 00, Exam Rank 01, Exam Rank 02, non-existing debug exams';
13+
14+
const lockedAgo = document.getElementById('active-user-session-locked-ago');
15+
lockedAgo.innerText = 'Automated logout occurs in 42 minutes';
16+
17+
// Add options container
18+
const optionsContainer = document.createElement('div');
19+
optionsContainer.id = 'screen-switcher';
20+
optionsContainer.style.position = 'fixed';
21+
optionsContainer.style.bottom = '48px';
22+
optionsContainer.style.left = '0';
23+
optionsContainer.style.width = '100%';
24+
optionsContainer.style.textAlign = 'center';
25+
optionsContainer.style.zIndex = '9000';
26+
document.body.appendChild(optionsContainer);
27+
28+
// Screen switcher
29+
const screenSwitcherContainer = document.createElement('div');
30+
screenSwitcherContainer.style.marginTop = '8px';
31+
optionsContainer.appendChild(screenSwitcherContainer);
32+
function switchScreen(screenId) {
33+
const screens = document.querySelectorAll('main > form');
34+
screens.forEach(screen => {
35+
screen.style.display = 'none';
36+
});
37+
38+
const selectedScreen = document.getElementById(screenId);
39+
selectedScreen.style.display = 'block';
40+
41+
logo.style.display = (screenId === 'lock-form') ? 'none' : 'block';
42+
43+
// Make sure the correct input field is checked
44+
const selectedInput = document.getElementById(`radio-${screenId}`);
45+
selectedInput.checked = true;
46+
}
47+
function addScreenSwitchOption(screenName, screenId) {
48+
const screenSwitcherInput = document.createElement('input');
49+
screenSwitcherInput.type = 'radio';
50+
screenSwitcherInput.name = 'screen';
51+
screenSwitcherInput.value = screenId;
52+
screenSwitcherInput.id = `radio-${screenId}`;
53+
54+
const screenSwitcherLabel = document.createElement('label');
55+
screenSwitcherLabel.textContent = screenName;
56+
screenSwitcherLabel.htmlFor = `radio-${screenId}`;
57+
screenSwitcherLabel.style.marginRight = '8px';
58+
59+
screenSwitcherContainer.appendChild(screenSwitcherInput);
60+
screenSwitcherContainer.appendChild(screenSwitcherLabel);
61+
62+
screenSwitcherInput.addEventListener('change', () => {
63+
switchScreen(screenId);
64+
});
65+
}
66+
addScreenSwitchOption('Login screen', 'login-form');
67+
addScreenSwitchOption('Lock screen', 'lock-form');
68+
addScreenSwitchOption('Exam mode', 'exam-form');
69+
switchScreen('login-form');
70+
71+
// Add a fake calendar event from the template in HTML
72+
// Unfortunately these are not clickable without the proper UI toolkit
73+
const calendarEventTemplate = document.getElementById('intra-calendar-event-template');
74+
for (let i = 0; i < 5; i++) {
75+
const calendarEvent = calendarEventTemplate.content.cloneNode(true);
76+
document.getElementById('intra-calendar').appendChild(calendarEvent);
77+
}
78+
79+
// Add slider to change the background brightness
80+
const brightnessFilter = document.createElement('div');
81+
brightnessFilter.style.position = 'fixed';
82+
brightnessFilter.style.top = '0';
83+
brightnessFilter.style.left = '0';
84+
brightnessFilter.style.width = '100%';
85+
brightnessFilter.style.height = '100%';
86+
brightnessFilter.style.backdropFilter = 'brightness(1)';
87+
document.body.insertBefore(brightnessFilter, document.body.firstChild);
88+
89+
const brightnessSlider = document.createElement('input');
90+
brightnessSlider.type = 'range';
91+
brightnessSlider.min = '0';
92+
brightnessSlider.max = '5';
93+
brightnessSlider.step = '0.1';
94+
brightnessSlider.value = '1';
95+
brightnessSlider.title = 'Adjust wallpaper brightness';
96+
optionsContainer.appendChild(brightnessSlider);
97+
brightnessSlider.addEventListener('input', () => {
98+
brightnessFilter.style.backdropFilter = `brightness(${brightnessSlider.value})`;
99+
});

static/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ <h3>This computer is reserved for an exam between <span id="exam-mode-start">...
9999
</footer>
100100

101101
<!-- Scripts (paths are relative to the dist folder) -->
102-
<script src="bundle.js"></script>
102+
<script>
103+
function debugFallback() {
104+
console.warn('JS Bundle failed to load, falling back to debug mode');
105+
const script = document.createElement('script');
106+
script.src = 'debug.js';
107+
document.body.appendChild(script);
108+
}
109+
</script>
110+
<script src="bundle.js" onerror="debugFallback(this);"></script>
103111
</body>
104112
</html>

0 commit comments

Comments
 (0)