feat: preserve and display archived course file versions

This commit is contained in:
Meghdad committed 2026-08-13 16:55:59 +03:30
1 parent 53b6dad560
commit 3869d94cfe
11 files changed
+301 -16

No files matched your search

+52 -5
View File
@@ -246,7 +246,8 @@ function isComplete(item) {
}
function resourceMatches(item) {
const haystack = normalized(`${item.title} ${item.filename} ${item.section}`);
const versionNames = (item.file_versions || []).map((version) => version.filename).join(" ");
const haystack = normalized(`${item.title} ${item.filename} ${versionNames} ${item.section}`);
if (state.query && !haystack.includes(state.query)) return false;
if (state.filter === "all") return true;
if (state.filter === "downloaded" || state.filter === "missing") return item.status === state.filter;
@@ -266,11 +267,20 @@ function resourceRow(item, index) {
title.className = "resource-title";
title.dir = "auto";
title.textContent = item.title;
const fileLine = document.createElement("div");
fileLine.className = "resource-file-line";
const filename = document.createElement("span");
filename.className = "resource-file";
filename.dir = "auto";
filename.textContent = item.filename || item.badge || item.activity_type;
main.append(title, filename);
fileLine.append(filename);
if ((item.file_versions || []).some((version) => version.state === "current")) {
const currentBadge = document.createElement("span");
currentBadge.className = "current-version-badge";
currentBadge.textContent = "Current";
fileLine.append(currentBadge);
}
main.append(title, fileLine);
if (item.description) {
const description = document.createElement("span");
description.className = "resource-description";
@@ -297,6 +307,43 @@ function resourceRow(item, index) {
});
main.append(artifactActions);
}
const archivedVersions = (item.file_versions || []).filter((version) => version.state === "archived");
if (archivedVersions.length) {
const history = document.createElement("details");
history.className = "version-history";
const historyTitle = document.createElement("summary");
historyTitle.textContent = `${archivedVersions.length} archived version${archivedVersions.length === 1 ? "" : "s"}`;
history.append(historyTitle);
const versionList = document.createElement("div");
versionList.className = "version-list";
archivedVersions.forEach((version) => {
const versionRow = document.createElement("div");
versionRow.className = "version-row";
const versionInfo = document.createElement("span");
versionInfo.className = "version-info";
versionInfo.dir = "auto";
const modified = version.modified_at ? new Date(version.modified_at).toLocaleDateString() : "";
versionInfo.textContent = `${version.filename} · ${formatBytes(version.size)}${modified ? ` · ${modified}` : ""}`;
let versionAction;
if (String(version.mimetype || "").startsWith("video/")) {
versionAction = document.createElement("button");
versionAction.type = "button";
versionAction.textContent = "Play archived";
versionAction.addEventListener("click", () => openVideo(item, version));
} else {
versionAction = document.createElement("a");
versionAction.href = version.url;
versionAction.target = "_blank";
versionAction.rel = "noopener";
versionAction.textContent = "Open archived";
}
versionAction.className = "version-action";
versionRow.append(versionInfo, versionAction);
versionList.append(versionRow);
});
history.append(versionList);
main.append(history);
}
const stateLabels = { download: "File", transcript: "Transcript", summary: "Summary", questions: "Questions" };
const visibleStates = Object.entries(item.state || {}).filter(([, value]) => value !== "not_applicable");
if (visibleStates.length) {
@@ -402,11 +449,11 @@ function renderResources() {
byId("emptyResources").hidden = visibleCount !== 0;
}
function openVideo(item) {
function openVideo(item, version = null) {
const dialog = byId("mediaDialog");
const player = byId("mediaPlayer");
setText("mediaTitle", item.title);
player.src = item.local_url;
setText("mediaTitle", version ? `${item.title} — ${version.filename} (Archived)` : item.title);
player.src = version?.url || item.local_url;
dialog.showModal();
player.play().catch(() => {});
}
+9 -1
View File
@@ -338,11 +338,19 @@ main {
.resource-index { color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
.resource-main { min-width: 0; }
.resource-title { display: block; overflow: hidden; font-weight: 730; text-overflow: ellipsis; white-space: nowrap; }
.resource-file { display: block; overflow: hidden; margin-top: 4px; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.resource-file-line { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; margin-top: 4px; }
.resource-file { display: block; overflow: hidden; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.current-version-badge { padding: 3px 6px; border-radius: 6px; color: var(--accent-strong); background: color-mix(in srgb, var(--accent) 22%, var(--surface)); font-size: .6rem; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.resource-description { display: -webkit-box; overflow: hidden; margin-top: 5px; color: var(--muted); font-size: .76rem; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.artifact-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.artifact-button { padding: 5px 9px; border: 1px solid color-mix(in srgb, var(--blue) 24%, var(--line)); border-radius: 8px; color: var(--blue); background: var(--blue-soft); cursor: pointer; font-size: .7rem; font-weight: 750; }
.artifact-button:hover { border-color: var(--blue); }
.version-history { max-width: 680px; margin-top: 9px; color: var(--muted); font-size: .72rem; }
.version-history summary { width: max-content; cursor: pointer; color: color-mix(in srgb, var(--ink) 62%, #c48600); font-weight: 750; }
.version-list { display: grid; gap: 6px; margin-top: 7px; }
.version-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 9px; border: 1px solid color-mix(in srgb, #c48600 32%, var(--line)); border-radius: 9px; background: color-mix(in srgb, #c48600 9%, var(--surface)); }
.version-info { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.version-action { flex: 0 0 auto; padding: 4px 7px; border: 0; border-radius: 6px; color: color-mix(in srgb, var(--ink) 70%, #a76c00); background: color-mix(in srgb, #c48600 18%, var(--surface-strong)); cursor: pointer; font: inherit; font-weight: 750; text-decoration: none; }
.state-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.state-chip { padding: 4px 7px; border-radius: 7px; color: var(--muted); background: var(--surface-strong); font-size: .65rem; font-weight: 700; text-transform: capitalize; }
.state-chip.complete { color: var(--accent-strong); background: color-mix(in srgb, var(--accent-soft) 78%, transparent); }