From b7ea06a9f2a86bd039294684c2c64aa958e6cb9c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Jun 2026 12:36:11 +0000 Subject: [PATCH 1/5] Initial plan From d3ea11d5e066a79ee3f784b84fc46ae858eee50d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 9 Jun 2026 12:45:32 +0000 Subject: [PATCH 2/5] Create dedicated admin exams page --- static/admin-exams.html | 172 ++++++++ static/admin-questions.html | 3 +- static/admin-quizzes.html | 3 +- static/admin-topics.html | 3 +- static/admin.html | 3 +- static/dashboard.html | 2 +- static/instructor.html | 764 ---------------------------------- static/js/admin/exams-page.js | 322 ++++++++++++++ static/quiz.html | 2 +- 9 files changed, 504 insertions(+), 770 deletions(-) create mode 100644 static/admin-exams.html create mode 100644 static/js/admin/exams-page.js diff --git a/static/admin-exams.html b/static/admin-exams.html new file mode 100644 index 0000000..6dfde3b --- /dev/null +++ b/static/admin-exams.html @@ -0,0 +1,172 @@ + + + + + + + + Admin – Exams - Athena + + + + + + + + + + +
+
+ +
+
+ +
+
+
+

Assigned Exams

+ +
+ +
+
+
+
+
Generate New Exam
+
+
+

Select categories and difficulty levels to randomly generate questions for a named exam. Default is 30 questions (configurable below).

+
+ + +
+
+ +
+ Loading categories... +
+
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+ + +
+
+
+ +
+
+
+
Assign Exam to Students
+
+
+

Select an exam and choose students to assign it to.

+
+ + +
+
+ +
+ + +
+
+
+ +
+ Loading students... +
+
+ + +
+
+ + +
+
+
+
+ +
+
+
Exam Status & Scores
+
+
+
+

Click Refresh to load status.

+
+ +
+
+
+
+ + + + + + diff --git a/static/admin-questions.html b/static/admin-questions.html index 9b218ab..932f359 100644 --- a/static/admin-questions.html +++ b/static/admin-questions.html @@ -24,7 +24,7 @@ @@ -38,6 +38,7 @@ + diff --git a/static/admin-quizzes.html b/static/admin-quizzes.html index 2037906..e10bb87 100644 --- a/static/admin-quizzes.html +++ b/static/admin-quizzes.html @@ -24,7 +24,7 @@ @@ -38,6 +38,7 @@ + diff --git a/static/admin-topics.html b/static/admin-topics.html index 77d7f3d..2a2aadd 100644 --- a/static/admin-topics.html +++ b/static/admin-topics.html @@ -24,7 +24,7 @@ @@ -38,6 +38,7 @@ + diff --git a/static/admin.html b/static/admin.html index 89484f1..b8e9864 100644 --- a/static/admin.html +++ b/static/admin.html @@ -24,7 +24,7 @@ @@ -38,6 +38,7 @@ + diff --git a/static/dashboard.html b/static/dashboard.html index 26ddfd1..127b259 100644 --- a/static/dashboard.html +++ b/static/dashboard.html @@ -30,7 +30,7 @@ - + diff --git a/static/instructor.html b/static/instructor.html index 298b9e1..62b7cbe 100644 --- a/static/instructor.html +++ b/static/instructor.html @@ -63,12 +63,6 @@ - - @@ -349,247 +343,6 @@
Import Questions
- -
-
-

Assigned Quizzes

- -
- -
- -
-
-
-
Create Quiz from JSON
-
-
-

Import questions from a JSON file to create a named, categorized quiz that can be assigned to students.

-
- JSON Format: -
{
-  "topic": "Optional Topic Name",
-  "questions": [
-    {
-      "text": "Question text?",
-      "difficulty": 3,
-      "tags": ["tag1"],
-      "answers": [
-        {"text": "Correct answer", "is_correct": true},
-        {"text": "Wrong answer", "is_correct": false}
-      ]
-    }
-  ]
-}
-
-
-
- - -
-
- - -
-
- - -
-
- - -
- -
- -
-
-
- - -
-
-
-
Assign Quiz to Students
-
-
-

Select a quiz and choose students to assign it to.

-
- - -
-
- -
- Loading students... -
-
- - -
-
- - -
-
-
-
- - -
-
-
Assigned Quiz Status
-
-
-
-

Click Refresh to load status.

-
- - - -
-
-
- - -
-
-

Assigned Exams

- -
- -
- -
-
-
-
Generate New Exam
-
-
-

Select categories and difficulty levels to randomly generate questions for a named exam. Default is 30 questions (configurable below).

-
- - -
-
- -
- Loading categories... -
-
-
- -
-
- - -
-
- - -
-
- - -
-
-
-
- - -
- - -
-
-
- - -
-
-
-
Assign Exam to Students
-
-
-

Select an exam and choose students to assign it to.

-
- - -
-
- -
- - -
-
-
- -
- Loading students... -
-
- - -
-
- - -
-
-
-
- - -
-
-
Exam Status & Scores
-
-
-
-

Click Refresh to load status.

-
- - -
-
-
@@ -630,13 +383,6 @@
Exam Results
// Load the data loadCohortAnalytics(); loadQuizzes(); - loadStudentList(); - loadAssignedQuizDropdown(); - loadAssignStudentsList(); - // Exam section - loadExamCategories(); - loadAssignedExamDropdown(); - loadExamAssignStudentsList(); } } catch (e) { console.error('Failed to parse user data:', e); @@ -977,516 +723,6 @@
Exam Results
reader.readAsText(file); } - // ============ Assigned Quizzes Functions ============ - - async function createQuizFromJson() { - const name = document.getElementById('newQuizName').value.trim(); - const category = document.getElementById('newQuizCategory').value; - const description = document.getElementById('newQuizDescription').value.trim(); - const fileInput = document.getElementById('newQuizJsonFile'); - const resultDiv = document.getElementById('createQuizResult'); - - if (!name || !category || !fileInput.files[0]) { - alert('Quiz name, category, and JSON file are required.'); - return; - } - - const formData = new FormData(); - formData.append('quiz_name', name); - formData.append('category', category); - formData.append('description', description); - formData.append('file', fileInput.files[0]); - - resultDiv.style.display = 'none'; - try { - const response = await fetch('/instructor/assigned-quizzes/import', { - method: 'POST', - headers: {'X-User-ID': userId}, - body: formData - }); - const result = await response.json(); - - if (response.ok && result.success) { - resultDiv.className = 'alert alert-success'; - resultDiv.innerHTML = `✅ Quiz "${escapeHtml(result.quiz_name)}" created (ID: ${result.quiz_id}) with ${result.imported} questions imported.`; - resultDiv.style.display = 'block'; - // Refresh quiz dropdowns - loadQuizzes(); - loadAssignedQuizDropdown(); - } else { - const errors = Array.isArray(result.errors) ? result.errors.join('
') : JSON.stringify(result); - resultDiv.className = 'alert alert-danger'; - resultDiv.innerHTML = `❌ Failed to create quiz:
${errors}`; - resultDiv.style.display = 'block'; - } - } catch (e) { - resultDiv.className = 'alert alert-danger'; - resultDiv.innerHTML = '❌ Network error: ' + e.message; - resultDiv.style.display = 'block'; - } - } - - async function loadAssignedQuizDropdown() { - const select = document.getElementById('assignQuizSelect'); - select.innerHTML = ''; - try { - const response = await fetch('/admin/quizzes', {headers: {'X-User-ID': userId}}); - const quizzes = await response.json(); - quizzes.forEach(q => { - const opt = document.createElement('option'); - opt.value = q.id; - opt.textContent = `${q.name}${q.category ? ' [' + q.category + ']' : ''}`; - select.appendChild(opt); - }); - } catch (e) { - console.error('Error loading quizzes for assign dropdown:', e); - } - } - - async function loadAssignStudentsList() { - const container = document.getElementById('assignStudentsList'); - container.innerHTML = 'Loading...'; - try { - const response = await fetch('/instructor/students', {headers: {'X-User-ID': userId}}); - const students = await response.json(); - if (!students || students.length === 0) { - container.innerHTML = 'No students found.'; - return; - } - container.innerHTML = ''; - students.forEach(s => { - if (s.is_admin) return; // skip admins - const div = document.createElement('div'); - div.className = 'form-check'; - div.innerHTML = ` - `; - container.appendChild(div); - }); - } catch (e) { - container.innerHTML = 'Error loading students.'; - } - } - - function selectAllStudents() { - document.querySelectorAll('.student-assign-check').forEach(cb => cb.checked = true); - } - function deselectAllStudents() { - document.querySelectorAll('.student-assign-check').forEach(cb => cb.checked = false); - } - - async function assignQuizToStudents() { - const quizId = parseInt(document.getElementById('assignQuizSelect').value); - const resultDiv = document.getElementById('assignQuizResult'); - - if (!quizId) { - alert('Please select a quiz.'); - return; - } - - const checked = document.querySelectorAll('.student-assign-check:checked'); - if (checked.length === 0) { - alert('Please select at least one student.'); - return; - } - - const userIds = Array.from(checked).map(cb => parseInt(cb.value)); - - resultDiv.style.display = 'none'; - try { - const response = await fetch(`/instructor/assigned-quizzes/assign?quiz_id=${quizId}`, { - method: 'POST', - headers: {'Content-Type': 'application/json', 'X-User-ID': userId}, - body: JSON.stringify({user_ids: userIds}) - }); - const result = await response.json(); - - if (response.ok) { - resultDiv.className = 'alert alert-success'; - resultDiv.innerHTML = `✅ Quiz assigned to ${result.assigned} student(s).`; - resultDiv.style.display = 'block'; - loadAssignedQuizStatus(); - } else { - resultDiv.className = 'alert alert-danger'; - resultDiv.innerHTML = '❌ Failed to assign quiz.'; - resultDiv.style.display = 'block'; - } - } catch (e) { - resultDiv.className = 'alert alert-danger'; - resultDiv.innerHTML = '❌ Network error: ' + e.message; - resultDiv.style.display = 'block'; - } - } - - async function loadAssignedQuizStatus() { - const container = document.getElementById('assignedQuizSummaryTable'); - container.innerHTML = '

Loading...

'; - try { - const response = await fetch('/instructor/assigned-quizzes/status', {headers: {'X-User-ID': userId}}); - const summaries = await response.json(); - - if (!summaries || summaries.length === 0) { - container.innerHTML = '

No quizzes have been assigned yet.

'; - return; - } - - let html = `
- - - - `; - summaries.forEach(s => { - html += ` - - - - - - - `; - }); - html += '
Quiz NameCategoryDescriptionAssignedCompletedActions
${escapeHtml(s.quiz_name)}${escapeHtml(s.quiz_category || '')}${escapeHtml(s.quiz_description || '')}${s.assigned_count}${s.completed_count} / ${s.assigned_count}
'; - container.innerHTML = html; - } catch (e) { - container.innerHTML = '

Error loading quiz status: ' + e.message + '

'; - } - } - - async function showQuizDetail(quizId, quizName) { - const panel = document.getElementById('quizDetailPanel'); - const title = document.getElementById('quizDetailTitle'); - const content = document.getElementById('quizDetailContent'); - - title.textContent = `Results: ${quizName}`; - content.innerHTML = '

Loading...

'; - panel.style.display = 'block'; - panel.scrollIntoView({behavior: 'smooth'}); - - try { - const response = await fetch(`/instructor/assigned-quizzes/status/quiz?quiz_id=${quizId}`, {headers: {'X-User-ID': userId}}); - const status = await response.json(); - - if (!status.student_results || status.student_results.length === 0) { - content.innerHTML = '

No students assigned to this quiz.

'; - return; - } - - let html = `
- - - `; - status.student_results.forEach(r => { - const completed = r.completed_at - ? new Date(r.completed_at).toLocaleString() - : 'Not completed'; - const scoreHtml = r.score !== undefined && r.score !== null - ? `${r.score.toFixed(0)}%` - : '—'; - const correct = r.correct_answers !== undefined && r.correct_answers !== null - ? `${r.correct_answers}/${r.total_questions}` - : '—'; - - html += ` - - - - - - `; - }); - html += '
StudentAssignedCompletedScoreCorrect
${escapeHtml(r.username)}${new Date(r.assigned_at).toLocaleDateString()}${completed}${scoreHtml}${correct}
'; - content.innerHTML = html; - } catch (e) { - content.innerHTML = '

Error loading results: ' + e.message + '

'; - } - } - - function hideQuizDetail() { - document.getElementById('quizDetailPanel').style.display = 'none'; - } - - // ============ Assigned Exams Functions ============ - - async function loadExamCategories() { - const container = document.getElementById('examCategoriesCheckboxes'); - try { - const response = await fetch('/instructor/exams/categories', {headers: {'X-User-ID': userId}}); - const categories = await response.json(); - if (!categories || categories.length === 0) { - container.innerHTML = 'No categories available.'; - return; - } - container.innerHTML = ''; - categories.forEach(cat => { - const div = document.createElement('div'); - div.className = 'form-check form-check-inline'; - div.innerHTML = ` - `; - container.appendChild(div); - }); - } catch (e) { - container.innerHTML = 'Error loading categories.'; - } - } - - async function generateExam() { - const name = document.getElementById('newExamName').value.trim(); - const resultDiv = document.getElementById('generateExamResult'); - - if (!name) { - alert('Exam name is required.'); - return; - } - - const checkedCats = Array.from(document.querySelectorAll('.exam-category-check:checked')).map(cb => cb.value); - if (checkedCats.length === 0) { - alert('Please select at least one category.'); - return; - } - - const checkedDiffs = Array.from(document.querySelectorAll('.exam-difficulty-check:checked')).map(cb => parseInt(cb.value)); - if (checkedDiffs.length === 0) { - alert('Please select at least one difficulty level.'); - return; - } - - const questionCount = parseInt(document.getElementById('examQuestionCount').value) || 30; - - resultDiv.style.display = 'none'; - try { - const response = await fetch('/instructor/exams/generate', { - method: 'POST', - headers: {'Content-Type': 'application/json', 'X-User-ID': userId}, - body: JSON.stringify({ - name: name, - categories: checkedCats, - difficulty_levels: checkedDiffs, - question_count: questionCount - }) - }); - const result = await response.json(); - - if (response.ok && result.success) { - const examUrl = window.location.origin + result.exam_url; - resultDiv.className = 'alert alert-success'; - resultDiv.innerHTML = `✅ Exam "${escapeHtml(result.exam_name)}" created with ${result.question_count} questions.
- Exam URL: ${escapeHtml(examUrl)}`; - resultDiv.style.display = 'block'; - document.getElementById('newExamName').value = ''; - loadAssignedExamDropdown(); - } else { - resultDiv.className = 'alert alert-danger'; - resultDiv.innerHTML = `❌ Failed to generate exam: ${escapeHtml(result.error || JSON.stringify(result))}`; - resultDiv.style.display = 'block'; - } - } catch (e) { - resultDiv.className = 'alert alert-danger'; - resultDiv.innerHTML = '❌ Network error: ' + e.message; - resultDiv.style.display = 'block'; - } - } - - async function loadAssignedExamDropdown() { - const select = document.getElementById('assignExamSelect'); - select.innerHTML = ''; - try { - const response = await fetch('/instructor/exams', {headers: {'X-User-ID': userId}}); - const exams = await response.json(); - exams.forEach(e => { - const opt = document.createElement('option'); - opt.value = e.id; - opt.dataset.token = e.access_token; - opt.textContent = `${e.name} (${e.question_count} questions)`; - select.appendChild(opt); - }); - } catch (e) { - console.error('Error loading exams for dropdown:', e); - } - } - - document.getElementById('assignExamSelect') && document.getElementById('assignExamSelect').addEventListener('change', function() { - const opt = this.options[this.selectedIndex]; - const token = opt ? opt.dataset.token : ''; - const urlInput = document.getElementById('examUrlDisplay'); - if (token) { - urlInput.value = window.location.origin + '/exam.html?token=' + token; - } else { - urlInput.value = ''; - } - }); - - function copyExamUrl() { - const urlInput = document.getElementById('examUrlDisplay'); - if (urlInput.value) { - navigator.clipboard.writeText(urlInput.value).then(() => { - alert('URL copied to clipboard!'); - }).catch(() => { - urlInput.select(); - document.execCommand('copy'); - }); - } - } - - async function loadExamAssignStudentsList() { - const container = document.getElementById('examAssignStudentsList'); - container.innerHTML = 'Loading...'; - try { - const response = await fetch('/instructor/students', {headers: {'X-User-ID': userId}}); - const students = await response.json(); - if (!students || students.length === 0) { - container.innerHTML = 'No students found.'; - return; - } - container.innerHTML = ''; - students.forEach(s => { - if (s.is_admin) return; - const div = document.createElement('div'); - div.className = 'form-check'; - div.innerHTML = ` - `; - container.appendChild(div); - }); - } catch (e) { - container.innerHTML = 'Error loading students.'; - } - } - - function selectAllExamStudents() { - document.querySelectorAll('.exam-student-check').forEach(cb => cb.checked = true); - } - function deselectAllExamStudents() { - document.querySelectorAll('.exam-student-check').forEach(cb => cb.checked = false); - } - - async function assignExamToStudents() { - const examId = parseInt(document.getElementById('assignExamSelect').value); - const resultDiv = document.getElementById('assignExamResult'); - - if (!examId) { - alert('Please select an exam.'); - return; - } - - const checked = document.querySelectorAll('.exam-student-check:checked'); - if (checked.length === 0) { - alert('Please select at least one student.'); - return; - } - - const userIds = Array.from(checked).map(cb => parseInt(cb.value)); - resultDiv.style.display = 'none'; - try { - const response = await fetch(`/instructor/exams/assign?exam_id=${examId}`, { - method: 'POST', - headers: {'Content-Type': 'application/json', 'X-User-ID': userId}, - body: JSON.stringify({user_ids: userIds}) - }); - const result = await response.json(); - - if (response.ok) { - resultDiv.className = 'alert alert-success'; - resultDiv.innerHTML = `✅ Exam assigned to ${result.assigned} student(s).`; - resultDiv.style.display = 'block'; - loadExamStatus(); - } else { - resultDiv.className = 'alert alert-danger'; - resultDiv.innerHTML = '❌ Failed to assign exam.'; - resultDiv.style.display = 'block'; - } - } catch (e) { - resultDiv.className = 'alert alert-danger'; - resultDiv.innerHTML = '❌ Network error: ' + e.message; - resultDiv.style.display = 'block'; - } - } - - async function loadExamStatus() { - const container = document.getElementById('examSummaryTable'); - container.innerHTML = '

Loading...

'; - try { - const response = await fetch('/instructor/exams', {headers: {'X-User-ID': userId}}); - const exams = await response.json(); - - if (!exams || exams.length === 0) { - container.innerHTML = '

No exams have been created yet.

'; - return; - } - - let html = `
- - - - `; - exams.forEach(e => { - const cats = Array.isArray(e.categories) ? e.categories.join(', ') : ''; - const diffs = Array.isArray(e.difficulty_levels) ? e.difficulty_levels.map(d => 'Level ' + d).join(', ') : ''; - const examUrl = window.location.origin + '/exam.html?token=' + e.access_token; - html += ` - - - - - - - `; - }); - html += '
Exam NameCategoriesDifficulty LevelsQuestionsExam URLActions
${escapeHtml(e.name)}${escapeHtml(cats)}${escapeHtml(diffs)}${e.question_count}${escapeHtml(examUrl)}
'; - container.innerHTML = html; - } catch (e) { - container.innerHTML = '

Error loading exam status: ' + e.message + '

'; - } - } - - async function showExamDetail(examId, examName) { - const panel = document.getElementById('examDetailPanel'); - const title = document.getElementById('examDetailTitle'); - const content = document.getElementById('examDetailContent'); - - title.textContent = `Scores: ${examName}`; - content.innerHTML = '

Loading...

'; - panel.style.display = 'block'; - panel.scrollIntoView({behavior: 'smooth'}); - - try { - const response = await fetch(`/instructor/exams/status?exam_id=${examId}`, {headers: {'X-User-ID': userId}}); - const status = await response.json(); - - if (!status.student_results || status.student_results.length === 0) { - content.innerHTML = '

No students assigned to this exam yet.

'; - return; - } - - let html = `
- - - `; - status.student_results.forEach(r => { - const completed = r.completed_at - ? new Date(r.completed_at).toLocaleString() - : 'Not completed'; - const scoreHtml = r.score !== undefined && r.score !== null - ? `${r.score.toFixed(0)}%` - : '—'; - const correct = r.correct_answers !== undefined && r.correct_answers !== null - ? `${r.correct_answers} / ${r.total_questions}` - : '—'; - html += ` - - - - - - `; - }); - html += '
StudentAssignedCompletedScoreCorrect / Total
${escapeHtml(r.username)}${new Date(r.assigned_at).toLocaleDateString()}${completed}${scoreHtml}${correct}
'; - content.innerHTML = html; - } catch (e) { - content.innerHTML = '

Error loading results: ' + e.message + '

'; - } - } - - function hideExamDetail() { - document.getElementById('examDetailPanel').style.display = 'none'; - }