Six more dashboard features, all built on the per-course progress-file
scanning infrastructure from earlier sessions:
- Notes Hub (/notes): every lesson note across the library in one place,
newest first, reusing the existing /recent/open cross-course jump route.
- Transcript search: opt-in checkbox on the Library search box, searching
inside .srt/.vtt files. Kept cheap by doing a raw substring match as the
filter step and only extracting a snippet for files that actually match.
- Stale course nudges ("Pick Back Up"): courses with progress that haven't
been touched in 14+ days.
- Study guide export: compiles a course's notes into one downloadable
markdown file, section/lesson structure preserved.
- Next Up queue: an ordered, persisted "what to tackle next" list with
up/down reordering and a queue button on every course row.
- Activity heatmap: a 90-day contribution-style calendar in the Library
Stats card.
_scan_library_activity() now does one walk over every course's progress
file per dashboard load; library stats, stale courses, and the heatmap all
derive from that single scan instead of three independent ones.
Also refactored the duplicated lesson-progress-key lookup (used in three
places now) into _resolve_lesson_progress_key(), and flagged a pre-existing
bug found along the way (not fixed here, kept out of scope): subtitle files
never actually attach to a Lesson object, so the video player's caption
track has never had anything to render.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
874 lines
34 KiB
HTML
874 lines
34 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>{{ lesson.title }} - {{ course.name }}</title>
|
|
<link rel="manifest" href="/static/manifest.json">
|
|
<meta name="theme-color" content="#007acc">
|
|
<link rel="apple-touch-icon" href="/static/icons/icon-192.png">
|
|
<style>
|
|
:root {
|
|
--bg-primary: #1a1a1a;
|
|
--bg-secondary: #2d2d2d;
|
|
--bg-tertiary: #3d3d3d;
|
|
--bg-tertiary-hover: #404040;
|
|
--text-primary: #e0e0e0;
|
|
--text-muted: #999;
|
|
--border-color: #555;
|
|
--accent: #007acc;
|
|
--accent-hover: #005a9e;
|
|
--font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
--font-size-base: 16px;
|
|
--container-max-width: 1600px;
|
|
--radius: 8px;
|
|
}
|
|
[data-theme="light"] {
|
|
--bg-primary: #f2f2f2;
|
|
--bg-secondary: #ffffff;
|
|
--bg-tertiary: #eeeeee;
|
|
--bg-tertiary-hover: #e2e2e2;
|
|
--text-primary: #222222;
|
|
--text-muted: #666666;
|
|
--border-color: #cccccc;
|
|
}
|
|
[data-density="compact"] .container { padding: 10px; }
|
|
[data-density="compact"] .text-content { padding: 10px; margin: 10px 0; }
|
|
[data-density="compact"] .navigation,
|
|
[data-density="compact"] .nav-buttons { gap: 5px; margin: 10px 0; }
|
|
[data-card-style="elevated"] .container,
|
|
[data-card-style="elevated"] .text-content,
|
|
[data-card-style="elevated"] .file-link {
|
|
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
|
|
}
|
|
[data-card-style="bordered"] .container,
|
|
[data-card-style="bordered"] .text-content,
|
|
[data-card-style="bordered"] .file-link {
|
|
border: 1px solid var(--border-color);
|
|
}
|
|
html, body {
|
|
height: 100%;
|
|
}
|
|
body {
|
|
font-family: var(--font-family);
|
|
font-size: var(--font-size-base);
|
|
margin: 0;
|
|
background: var(--bg-primary);
|
|
color: var(--text-primary);
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 100vh;
|
|
}
|
|
.page-content {
|
|
flex: 1;
|
|
padding: 20px;
|
|
}
|
|
.app-header {
|
|
background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
|
|
padding: 18px 0;
|
|
border-bottom: 3px solid var(--accent);
|
|
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
|
|
}
|
|
.app-header .container {
|
|
max-width: var(--container-max-width);
|
|
width: 95%;
|
|
margin: 0 auto;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
.app-header .brand-icon {
|
|
font-size: 1.6em;
|
|
}
|
|
.app-header a.brand-link {
|
|
color: var(--accent);
|
|
text-decoration: none;
|
|
font-size: 1.3em;
|
|
font-weight: 600;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
.app-footer {
|
|
background: var(--bg-secondary);
|
|
border-top: 1px solid var(--border-color);
|
|
padding: 18px 0;
|
|
}
|
|
.app-footer .container-inner {
|
|
max-width: var(--container-max-width);
|
|
width: 95%;
|
|
margin: 0 auto;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 15px;
|
|
flex-wrap: wrap;
|
|
}
|
|
.footer-brand {
|
|
color: var(--text-muted);
|
|
font-size: 0.9em;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.footer-links {
|
|
display: flex;
|
|
gap: 20px;
|
|
}
|
|
.footer-links a {
|
|
color: var(--text-muted);
|
|
text-decoration: none;
|
|
font-size: 0.9em;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
transition: color 0.2s;
|
|
}
|
|
.footer-links a:hover {
|
|
color: var(--accent);
|
|
}
|
|
.container {
|
|
max-width: var(--container-max-width);
|
|
width: 95%;
|
|
margin: 20px auto;
|
|
background: var(--bg-secondary);
|
|
padding: 20px;
|
|
border-radius: var(--radius);
|
|
}
|
|
video, audio {
|
|
width: 100%;
|
|
max-width: 100%;
|
|
border-radius: var(--radius);
|
|
display: block;
|
|
margin: 0 auto;
|
|
}
|
|
video {
|
|
resize: both;
|
|
overflow: hidden;
|
|
object-fit: contain;
|
|
background: #000;
|
|
min-width: 320px;
|
|
min-height: 200px;
|
|
}
|
|
.resize-hint {
|
|
text-align: center;
|
|
font-size: 0.8em;
|
|
color: var(--text-muted);
|
|
margin-top: 6px;
|
|
}
|
|
.speed-controls {
|
|
display: flex;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
gap: 6px;
|
|
margin-top: 10px;
|
|
}
|
|
.speed-label {
|
|
color: var(--text-muted);
|
|
font-size: 0.9em;
|
|
margin-right: 4px;
|
|
}
|
|
.speed-btn {
|
|
padding: 5px 12px;
|
|
margin: 0;
|
|
font-size: 0.85em;
|
|
background: var(--bg-tertiary);
|
|
color: var(--text-primary);
|
|
}
|
|
.speed-btn:hover {
|
|
background: var(--bg-tertiary-hover);
|
|
}
|
|
.speed-btn.active {
|
|
background: var(--accent);
|
|
color: white;
|
|
}
|
|
.content {
|
|
margin: 20px 0;
|
|
}
|
|
.notes-section {
|
|
margin: 20px 0;
|
|
}
|
|
.lesson-note-textarea {
|
|
width: 100%;
|
|
min-height: 90px;
|
|
padding: 12px;
|
|
background: var(--bg-tertiary);
|
|
color: var(--text-primary);
|
|
border: 1px solid var(--border-color);
|
|
border-radius: var(--radius);
|
|
font-family: var(--font-family);
|
|
font-size: 0.95em;
|
|
resize: vertical;
|
|
}
|
|
.note-status {
|
|
display: block;
|
|
font-size: 0.85em;
|
|
color: var(--text-muted);
|
|
margin-top: 6px;
|
|
min-height: 1.2em;
|
|
}
|
|
.outline-topic-row {
|
|
display: flex;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
gap: 8px;
|
|
margin-top: 10px;
|
|
}
|
|
.outline-topic-row label {
|
|
font-size: 0.9em;
|
|
color: var(--text-muted);
|
|
}
|
|
.outline-topic-row select,
|
|
.outline-new-topic-input {
|
|
background: var(--bg-tertiary);
|
|
color: var(--text-primary);
|
|
border: 1px solid var(--border-color);
|
|
border-radius: var(--radius);
|
|
padding: 6px 10px;
|
|
font-size: 0.9em;
|
|
font-family: var(--font-family);
|
|
}
|
|
.outline-new-topic-input {
|
|
flex: 1;
|
|
min-width: 140px;
|
|
}
|
|
.navigation {
|
|
margin: 20px 0;
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
}
|
|
button {
|
|
padding: 10px 20px;
|
|
margin: 5px;
|
|
cursor: pointer;
|
|
background: var(--accent);
|
|
color: white;
|
|
border: none;
|
|
border-radius: var(--radius);
|
|
transition: background 0.3s;
|
|
}
|
|
button:hover {
|
|
background: var(--accent-hover);
|
|
}
|
|
button:disabled {
|
|
background: #666;
|
|
cursor: not-allowed;
|
|
}
|
|
.file-link {
|
|
display: block;
|
|
margin: 5px 0;
|
|
padding: 10px;
|
|
background: var(--bg-tertiary);
|
|
text-decoration: none;
|
|
color: var(--text-primary);
|
|
border-radius: var(--radius);
|
|
transition: background 0.3s;
|
|
}
|
|
.file-link:hover {
|
|
background: var(--bg-tertiary-hover);
|
|
}
|
|
.lesson-path {
|
|
background: var(--bg-tertiary);
|
|
padding: 10px;
|
|
border-radius: var(--radius);
|
|
margin-bottom: 20px;
|
|
font-family: monospace;
|
|
color: var(--text-muted);
|
|
}
|
|
.lesson-title {
|
|
color: var(--accent);
|
|
margin-bottom: 20px;
|
|
}
|
|
.text-content {
|
|
background: var(--bg-tertiary);
|
|
padding: 20px;
|
|
border-radius: var(--radius);
|
|
margin: 20px 0;
|
|
}
|
|
.text-content.plain-text {
|
|
max-height: 600px;
|
|
overflow-y: auto;
|
|
white-space: pre-wrap;
|
|
font-family: 'Courier New', monospace;
|
|
line-height: 1.6;
|
|
}
|
|
.text-content iframe {
|
|
background: white;
|
|
border-radius: var(--radius);
|
|
}
|
|
.nav-buttons {
|
|
display: flex;
|
|
gap: 10px;
|
|
margin-top: 20px;
|
|
}
|
|
.nav-buttons a {
|
|
text-decoration: none;
|
|
color: inherit;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="app-header">
|
|
<div class="container">
|
|
<span class="brand-icon">📚</span>
|
|
<a href="/reset_course" class="brand-link">OfflineU</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="page-content">
|
|
<div class="container">
|
|
<h1 class="lesson-title">{{ lesson.title }}</h1>
|
|
|
|
<div class="lesson-path">
|
|
<strong>Path:</strong> {{ lesson_path }}
|
|
</div>
|
|
|
|
<div class="navigation">
|
|
<a href="/" style="text-decoration: none; color: var(--accent);">← Back to Course</a>
|
|
<button onclick="markCompleted()">Mark as Completed</button>
|
|
</div>
|
|
|
|
<div class="content">
|
|
{% if lesson.video_file %}
|
|
<h3>Video</h3>
|
|
<video controls preload="metadata" id="video-player">
|
|
<source src="/files/{{ lesson.video_file }}" type="video/mp4">
|
|
{% if lesson.subtitle_file %}
|
|
<track kind="subtitles" src="/files/{{ lesson.subtitle_file }}" srclang="en" label="English">
|
|
{% endif %}
|
|
Your browser does not support the video tag.
|
|
</video>
|
|
<p class="resize-hint">↘ Drag the bottom-right corner to resize the player</p>
|
|
{% endif %}
|
|
|
|
{% if lesson.audio_file %}
|
|
<h3>Audio</h3>
|
|
<audio controls preload="metadata" id="audio-player">
|
|
<source src="/files/{{ lesson.audio_file }}" type="audio/mp3">
|
|
Your browser does not support the audio tag.
|
|
</audio>
|
|
{% endif %}
|
|
|
|
{% if lesson.video_file or lesson.audio_file %}
|
|
<div class="speed-controls" id="speed-controls">
|
|
<span class="speed-label">Speed:</span>
|
|
{% for speed in ['0.75', '1', '1.25', '1.5', '1.75', '2'] %}
|
|
<button type="button" class="speed-btn" data-speed="{{ speed }}" onclick="setPlaybackSpeed('{{ speed }}')">{{ speed }}x</button>
|
|
{% endfor %}
|
|
</div>
|
|
{% endif %}
|
|
|
|
{% if lesson.text_files %}
|
|
<h3>Content</h3>
|
|
{% for text_file in lesson.text_files %}
|
|
<div style="margin-bottom: 20px;">
|
|
<h4>{{ text_file.split('/')[-1] }}</h4>
|
|
<div class="text-content" id="content-{{ loop.index0 }}">
|
|
<div style="text-align: center; color: #666;">Loading content...</div>
|
|
</div>
|
|
<a href="/files/{{ text_file|replace('\\', '/') }}" class="file-link" target="_blank">
|
|
📄 Open {{ text_file.split('/')[-1] }} in new tab
|
|
</a>
|
|
</div>
|
|
{% endfor %}
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="notes-section">
|
|
<h3>Notes</h3>
|
|
<textarea id="lesson-note" class="lesson-note-textarea"
|
|
placeholder="Jot something down about this lesson…">{{ lesson_note }}</textarea>
|
|
<span id="note-status" class="note-status"></span>
|
|
|
|
<div class="outline-topic-row">
|
|
<label for="outline-topic-select">Push to Outline topic</label>
|
|
<select id="outline-topic-select" onchange="handleOutlineTopicChange()">
|
|
<option value="">— Don't push —</option>
|
|
<option value="__new__">+ New topic…</option>
|
|
</select>
|
|
<input type="text" id="outline-new-topic-input" class="outline-new-topic-input"
|
|
placeholder="New topic name" style="display: none;">
|
|
</div>
|
|
<span id="outline-topic-status" class="note-status"></span>
|
|
</div>
|
|
|
|
<div class="nav-buttons">
|
|
{% if prev_lesson %}
|
|
<a href="/lesson/{{ prev_lesson }}">
|
|
<button>← Previous</button>
|
|
</a>
|
|
{% else %}
|
|
<button disabled>← Previous</button>
|
|
{% endif %}
|
|
|
|
{% if next_lesson %}
|
|
<a href="/lesson/{{ next_lesson }}">
|
|
<button>Next →</button>
|
|
</a>
|
|
{% else %}
|
|
<button disabled>Next →</button>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<script>
|
|
// Load text content
|
|
{% for text_file in lesson.text_files %}
|
|
console.log('Loading file: {{ text_file }}');
|
|
const filePath = '{{ text_file|replace("\\", "/") }}';
|
|
console.log('Encoded file path:', filePath);
|
|
|
|
// Check if this is an HTML file
|
|
const isHtmlFile = filePath.toLowerCase().endsWith('.html') || filePath.toLowerCase().endsWith('.htm');
|
|
const isPdfFile = filePath.toLowerCase().endsWith('.pdf');
|
|
const isBinaryDoc = ['.docx', '.doc', '.rtf'].some(ext => filePath.toLowerCase().endsWith(ext));
|
|
const contentDiv = document.getElementById('content-{{ loop.index0 }}');
|
|
|
|
if (isHtmlFile) {
|
|
// For HTML files, create an iframe
|
|
console.log('Creating iframe for HTML file');
|
|
contentDiv.innerHTML = `
|
|
<iframe
|
|
src="/files/${encodeURIComponent(filePath)}"
|
|
style="width: 100%; height: 600px; border: none; border-radius: 5px;"
|
|
title="${filePath.split('/').pop()}"
|
|
></iframe>
|
|
`;
|
|
} else if (isPdfFile) {
|
|
// For PDFs, embed via iframe rather than fetching as text -
|
|
// browsers render PDFs natively in an iframe, but fetching
|
|
// the raw bytes as text (like below) produces garbage.
|
|
console.log('Embedding PDF in iframe');
|
|
contentDiv.innerHTML = `
|
|
<iframe
|
|
src="/files/${encodeURIComponent(filePath)}"
|
|
style="width: 100%; height: 85vh; border: none; border-radius: 5px; background: #fff;"
|
|
title="${filePath.split('/').pop()}"
|
|
></iframe>
|
|
`;
|
|
} else if (isBinaryDoc) {
|
|
// .docx/.doc/.rtf can't be rendered inline by the browser;
|
|
// fetching them as text would show garbled binary content,
|
|
// so just point at the download/open link instead.
|
|
contentDiv.innerHTML =
|
|
'<div style="color: #999;">Preview isn\'t available for this file type. ' +
|
|
'Use the "Open in new tab" link below to view or download it.</div>';
|
|
} else {
|
|
// For text files, fetch and display content
|
|
fetch('/files/' + encodeURIComponent(filePath))
|
|
.then(response => {
|
|
console.log('Response status:', response.status);
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
return response.text();
|
|
})
|
|
.then(content => {
|
|
console.log('Content loaded successfully, length:', content.length);
|
|
if (contentDiv) {
|
|
contentDiv.classList.add('plain-text');
|
|
// Check if it's HTML content
|
|
if (content.trim().startsWith('<') && content.includes('</')) {
|
|
contentDiv.innerHTML = content;
|
|
} else {
|
|
// Treat as plain text
|
|
contentDiv.textContent = content;
|
|
}
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error loading content:', error);
|
|
if (contentDiv) {
|
|
contentDiv.innerHTML =
|
|
'<div style="color: #ff6b6b;">Error loading content: ' + error.message + '</div>' +
|
|
'<div style="color: #999; font-size: 0.9em; margin-top: 10px;">File path: ' + filePath + '</div>';
|
|
}
|
|
});
|
|
}
|
|
{% endfor %}
|
|
|
|
// Media progress tracking
|
|
const video = document.getElementById('video-player');
|
|
const audio = document.getElementById('audio-player');
|
|
const activeMedia = video || audio;
|
|
let isCompleted = false;
|
|
|
|
// Restore last-used video player size, and persist future resizes
|
|
// (dragging the native corner handle) so it sticks next time.
|
|
if (video) {
|
|
let applyingStoredSize = true;
|
|
let resizeSaveTimeout = null;
|
|
|
|
fetch('/api/settings')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
const s = data.settings || {};
|
|
if (s.video_width && s.video_height) {
|
|
video.style.width = s.video_width + 'px';
|
|
video.style.height = s.video_height + 'px';
|
|
}
|
|
setTimeout(() => { applyingStoredSize = false; }, 300);
|
|
})
|
|
.catch(() => { applyingStoredSize = false; });
|
|
|
|
if (window.ResizeObserver) {
|
|
const observer = new ResizeObserver(() => {
|
|
if (applyingStoredSize) return;
|
|
clearTimeout(resizeSaveTimeout);
|
|
resizeSaveTimeout = setTimeout(() => {
|
|
const rect = video.getBoundingClientRect();
|
|
fetch('/api/settings', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
video_width: Math.round(rect.width),
|
|
video_height: Math.round(rect.height)
|
|
})
|
|
}).catch(() => {});
|
|
}, 500);
|
|
});
|
|
observer.observe(video);
|
|
}
|
|
}
|
|
|
|
// Restore the persisted playback speed and highlight the active
|
|
// button; clicking a button applies it immediately and persists
|
|
// it via /api/settings, mirroring the video-size pattern above.
|
|
if (activeMedia) {
|
|
fetch('/api/settings')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
const speed = (data.settings || {}).playback_speed || '1';
|
|
activeMedia.playbackRate = parseFloat(speed);
|
|
highlightSpeedButton(speed);
|
|
})
|
|
.catch(() => {});
|
|
}
|
|
|
|
function highlightSpeedButton(speed) {
|
|
document.querySelectorAll('.speed-btn').forEach(function(btn) {
|
|
btn.classList.toggle('active', btn.dataset.speed === speed);
|
|
});
|
|
}
|
|
|
|
function setPlaybackSpeed(speed) {
|
|
if (activeMedia) activeMedia.playbackRate = parseFloat(speed);
|
|
highlightSpeedButton(speed);
|
|
fetch('/api/settings', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ playback_speed: speed })
|
|
}).catch(() => {});
|
|
}
|
|
|
|
// Lesson notes: debounced autosave on typing, plus an immediate
|
|
// save on blur so navigating away doesn't lose the last edit.
|
|
const noteField = document.getElementById('lesson-note');
|
|
const noteStatus = document.getElementById('note-status');
|
|
let noteSaveTimeout = null;
|
|
|
|
function saveNote() {
|
|
if (!noteField) return;
|
|
fetch('/api/lesson-note', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ lesson_path: '{{ lesson_path }}', note: noteField.value })
|
|
})
|
|
.then(() => {
|
|
if (noteStatus) {
|
|
noteStatus.textContent = 'Saved';
|
|
setTimeout(() => { noteStatus.textContent = ''; }, 2000);
|
|
}
|
|
})
|
|
.catch(() => {
|
|
if (noteStatus) noteStatus.textContent = 'Could not save note';
|
|
});
|
|
}
|
|
|
|
if (noteField) {
|
|
noteField.addEventListener('input', function() {
|
|
clearTimeout(noteSaveTimeout);
|
|
noteSaveTimeout = setTimeout(saveNote, 1000);
|
|
});
|
|
noteField.addEventListener('blur', function() {
|
|
clearTimeout(noteSaveTimeout);
|
|
saveNote();
|
|
});
|
|
}
|
|
|
|
// ---- Outline topic chooser + push-on-leave ----
|
|
const LESSON_PATH = {{ lesson_path|tojson }};
|
|
const LESSON_TITLE = {{ lesson.title|tojson }};
|
|
const INITIAL_TOPIC_ID = {{ outline_topic_id|tojson }};
|
|
const INITIAL_TOPIC_NAME = {{ outline_topic_name|tojson }};
|
|
|
|
const topicSelect = document.getElementById('outline-topic-select');
|
|
const newTopicInput = document.getElementById('outline-new-topic-input');
|
|
const topicStatus = document.getElementById('outline-topic-status');
|
|
|
|
if (topicSelect) {
|
|
fetch('/api/outline/topics')
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
const newOption = topicSelect.querySelector('option[value="__new__"]');
|
|
(data.topics || []).forEach(function(c) {
|
|
const opt = document.createElement('option');
|
|
opt.value = c.id;
|
|
opt.textContent = c.name;
|
|
topicSelect.insertBefore(opt, newOption);
|
|
});
|
|
if (INITIAL_TOPIC_ID) {
|
|
topicSelect.value = INITIAL_TOPIC_ID;
|
|
} else if (INITIAL_TOPIC_NAME) {
|
|
topicSelect.value = '__new__';
|
|
newTopicInput.style.display = 'inline-block';
|
|
newTopicInput.value = INITIAL_TOPIC_NAME;
|
|
}
|
|
if (data.error && topicStatus) {
|
|
topicStatus.textContent = data.error;
|
|
}
|
|
})
|
|
.catch(() => {});
|
|
|
|
// Resolve a freshly-typed topic name to a real collection
|
|
// id immediately (find-or-create), rather than saving it as
|
|
// a pending name for the fire-and-forget pagehide push to
|
|
// deal with later - a page that fires pagehide more than
|
|
// once for the same view (e.g. restored from the browser's
|
|
// back/forward cache) would otherwise re-send the same "new
|
|
// topic" intent every time and create a duplicate
|
|
// collection per navigation.
|
|
newTopicInput.addEventListener('blur', function() {
|
|
const name = this.value.trim();
|
|
if (!name) return;
|
|
topicStatus.textContent = 'Creating topic…';
|
|
fetch('/api/outline/resolve-topic', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ name: name })
|
|
})
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
if (!data.success) {
|
|
topicStatus.textContent = data.error || 'Could not create topic';
|
|
return;
|
|
}
|
|
const newOption = topicSelect.querySelector('option[value="__new__"]');
|
|
const opt = document.createElement('option');
|
|
opt.value = data.id;
|
|
opt.textContent = data.name;
|
|
topicSelect.insertBefore(opt, newOption);
|
|
topicSelect.value = data.id;
|
|
newTopicInput.style.display = 'none';
|
|
newTopicInput.value = '';
|
|
topicStatus.textContent = '';
|
|
saveOutlineTopicChoice(data.id, '');
|
|
})
|
|
.catch(() => {
|
|
topicStatus.textContent = 'Could not reach the server';
|
|
});
|
|
});
|
|
}
|
|
|
|
function handleOutlineTopicChange() {
|
|
if (topicSelect.value === '__new__') {
|
|
newTopicInput.style.display = 'inline-block';
|
|
newTopicInput.focus();
|
|
return; // wait for a name before resolving
|
|
}
|
|
newTopicInput.style.display = 'none';
|
|
newTopicInput.value = '';
|
|
saveOutlineTopicChoice(topicSelect.value, '');
|
|
}
|
|
|
|
function saveOutlineTopicChoice(topicId, topicName) {
|
|
fetch('/api/lesson-note/topic', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ lesson_path: LESSON_PATH, topic_id: topicId, topic_name: topicName })
|
|
}).catch(() => {});
|
|
}
|
|
|
|
// Fire the push via sendBeacon on pagehide - fires on any real
|
|
// navigation away (Previous/Next/Back-to-Course, browser back,
|
|
// closing the tab) and is far more likely to actually complete
|
|
// than a beforeunload-triggered fetch. No result to show the
|
|
// user either way, since the page is already gone by the time
|
|
// it lands.
|
|
window.addEventListener('pagehide', function() {
|
|
if (!topicSelect) return;
|
|
const isNew = topicSelect.value === '__new__';
|
|
const topicId = isNew ? '' : topicSelect.value;
|
|
const newTopicName = isNew ? newTopicInput.value.trim() : '';
|
|
if (!topicId && !newTopicName) return;
|
|
|
|
const payload = JSON.stringify({
|
|
lesson_path: LESSON_PATH,
|
|
lesson_title: LESSON_TITLE,
|
|
topic_id: topicId,
|
|
new_topic_name: newTopicName
|
|
});
|
|
navigator.sendBeacon('/api/outline/push', new Blob([payload], { type: 'application/json' }));
|
|
});
|
|
|
|
if (activeMedia) {
|
|
let lastSaveTime = 0;
|
|
|
|
activeMedia.addEventListener('timeupdate', function() {
|
|
const currentTime = activeMedia.currentTime;
|
|
|
|
// Save progress every 15 seconds
|
|
if (currentTime - lastSaveTime > 15) {
|
|
saveProgress(currentTime);
|
|
lastSaveTime = currentTime;
|
|
}
|
|
});
|
|
|
|
activeMedia.addEventListener('ended', function() {
|
|
saveProgress(activeMedia.currentTime, true);
|
|
markAsCompleted();
|
|
});
|
|
|
|
// Resume from saved position
|
|
const savedProgress = {{ lesson.progress_seconds|default(0) }};
|
|
if (savedProgress > 0 && savedProgress < activeMedia.duration - 30) {
|
|
activeMedia.currentTime = savedProgress;
|
|
showNotification(`Resumed from ${Math.floor(savedProgress / 60)}:${String(Math.floor(savedProgress % 60)).padStart(2, '0')}`);
|
|
}
|
|
}
|
|
|
|
function saveProgress(progressSeconds, completed = false) {
|
|
const duration = activeMedia && isFinite(activeMedia.duration) ? Math.floor(activeMedia.duration) : null;
|
|
fetch('/api/progress', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({
|
|
lesson_path: '{{ lesson_path }}',
|
|
completed: completed,
|
|
progress_seconds: Math.floor(progressSeconds),
|
|
duration_seconds: duration
|
|
})
|
|
}).catch(err => console.error('Failed to save progress:', err));
|
|
}
|
|
|
|
function markCompleted() {
|
|
if (isCompleted) return;
|
|
|
|
const currentTime = activeMedia ? activeMedia.currentTime : 0;
|
|
saveProgress(currentTime, true);
|
|
markAsCompleted();
|
|
}
|
|
|
|
function markAsCompleted() {
|
|
const btn = document.querySelector('button[onclick="markCompleted()"]');
|
|
if (btn) {
|
|
btn.textContent = 'Completed ✓';
|
|
btn.style.background = '#28a745';
|
|
btn.disabled = true;
|
|
}
|
|
isCompleted = true;
|
|
showNotification('Lesson marked as completed!', 'success');
|
|
}
|
|
|
|
function showNotification(message, type = 'info') {
|
|
const notification = document.createElement('div');
|
|
notification.style.cssText = `
|
|
position: fixed;
|
|
top: 20px;
|
|
right: 20px;
|
|
background: ${type === 'success' ? '#28a745' : '#007acc'};
|
|
color: white;
|
|
padding: 15px 20px;
|
|
border-radius: 5px;
|
|
z-index: 10000;
|
|
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
|
|
opacity: 0;
|
|
transform: translateY(-20px);
|
|
transition: all 0.3s ease;
|
|
`;
|
|
notification.textContent = message;
|
|
|
|
document.body.appendChild(notification);
|
|
|
|
setTimeout(() => {
|
|
notification.style.opacity = '1';
|
|
notification.style.transform = 'translateY(0)';
|
|
}, 100);
|
|
|
|
setTimeout(() => {
|
|
notification.style.opacity = '0';
|
|
notification.style.transform = 'translateY(-20px)';
|
|
setTimeout(() => {
|
|
if (document.body.contains(notification)) {
|
|
document.body.removeChild(notification);
|
|
}
|
|
}, 300);
|
|
}, 3000);
|
|
}
|
|
|
|
// Keyboard shortcuts - skip while typing in the note (or any
|
|
// other text field), so space/arrow keys type normally instead
|
|
// of hijacking video playback.
|
|
function isTypingTarget(el) {
|
|
if (!el) return false;
|
|
const tag = el.tagName;
|
|
return tag === 'TEXTAREA' || tag === 'INPUT' || tag === 'SELECT' || el.isContentEditable;
|
|
}
|
|
|
|
document.addEventListener('keydown', function(e) {
|
|
if (isTypingTarget(e.target)) return;
|
|
if (activeMedia && !e.ctrlKey && !e.altKey && !e.metaKey) {
|
|
switch(e.key) {
|
|
case ' ':
|
|
e.preventDefault();
|
|
if (activeMedia.paused) {
|
|
activeMedia.play();
|
|
} else {
|
|
activeMedia.pause();
|
|
}
|
|
break;
|
|
case 'ArrowLeft':
|
|
e.preventDefault();
|
|
activeMedia.currentTime = Math.max(0, activeMedia.currentTime - 10);
|
|
break;
|
|
case 'ArrowRight':
|
|
e.preventDefault();
|
|
activeMedia.currentTime = Math.min(activeMedia.duration, activeMedia.currentTime + 10);
|
|
break;
|
|
case 'ArrowUp':
|
|
e.preventDefault();
|
|
activeMedia.volume = Math.min(1, activeMedia.volume + 0.1);
|
|
showNotification(`Volume: ${Math.round(activeMedia.volume * 100)}%`);
|
|
break;
|
|
case 'ArrowDown':
|
|
e.preventDefault();
|
|
activeMedia.volume = Math.max(0, activeMedia.volume - 0.1);
|
|
showNotification(`Volume: ${Math.round(activeMedia.volume * 100)}%`);
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
// Set completed state if already completed
|
|
if ({{ 'true' if lesson.completed else 'false' }}) {
|
|
markAsCompleted();
|
|
}
|
|
</script>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="app-footer">
|
|
<div class="container-inner">
|
|
<div class="footer-brand">
|
|
📚 <a href="/reset_course" style="color: inherit; text-decoration: none;">OfflineU</a>
|
|
</div>
|
|
<div class="footer-links">
|
|
<a href="/notes">📝 Notes</a>
|
|
<a href="/help">❓ Help</a>
|
|
<a href="/settings">⚙ Settings</a>
|
|
</div>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="/static/theme.js"></script>
|
|
</body>
|
|
</html> |