From a64f6340c9b9d8b59672b2f6b84a92e24233ac87 Mon Sep 17 00:00:00 2001 From: Hypernova101 Date: Mon, 18 May 2026 11:21:17 -0700 Subject: [PATCH 1/3] automatic and dynamic assignment creation --- _layouts/post.html | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/_layouts/post.html b/_layouts/post.html index e4a1fbd6a..dfb090010 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -727,6 +727,56 @@ } } + /** + * ============================================ + * AUTO-CREATE ASSIGNMENT FROM FRONTMATTER + * ============================================ + */ + async function autoCreateAssignmentIfNeeded() { + // Only proceed if assignment: true but assignment_id is not set + const hasAssignment = {{ page.assignment | default: false }}; + const hasAssignmentId = ASSIGNMENT_ID !== null; + + if (!hasAssignment || hasAssignmentId) { + return; // Already has ID or not an assignment page + } + + try { + // Call the Spring API to auto-create assignment + // This endpoint allows any authenticated user (student, person, teacher, admin) + const createRes = await fetch(`${javaURI}/api/assignments/auto-create`, { + ...fetchOptions, + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded' + }, + body: new URLSearchParams({ + name: PAGE_TITLE || '{{ page.title }}', + contentUrl: CURRENT_LESSON_ID, + description: '{{ page.description | default: "" }}' + }) + }); + + if (createRes.ok) { + const result = await createRes.json(); + // Set global ASSIGNMENT_ID for use in submission forms + window.ASSIGNMENT_ID = result.id; + window.ASSIGNMENT_NAME = result.name; + console.log('Assignment auto-created with ID:', result.id); + } else if (createRes.status === 200) { + // Assignment already exists + const result = await createRes.json(); + window.ASSIGNMENT_ID = result.id; + window.ASSIGNMENT_NAME = result.name; + console.log('Assignment already exists with ID:', result.id); + } else { + console.error('Failed to auto-create assignment:', createRes.statusText); + } + } catch (error) { + console.error('Error auto-creating assignment:', error); + } + } + /** * ============================================ * MASTER INITIALIZATION @@ -743,6 +793,9 @@ setupMobileModal(); window.addEventListener('resize', () => setupMobileModal()); + // Auto-create assignment if needed + autoCreateAssignmentIfNeeded(); + // Assignment submission setupSubmissionForms(); From d01c8aaf3d26c6bf734fee9a0aae168e7fa8ae57 Mon Sep 17 00:00:00 2001 From: Hypernova101 Date: Mon, 18 May 2026 12:16:09 -0700 Subject: [PATCH 2/3] duplicate assignments handling --- _layouts/post.html | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/_layouts/post.html b/_layouts/post.html index dfb090010..beead6d08 100644 --- a/_layouts/post.html +++ b/_layouts/post.html @@ -759,18 +759,25 @@ if (createRes.ok) { const result = await createRes.json(); - // Set global ASSIGNMENT_ID for use in submission forms + // Set global ASSIGNMENT_ID and ASSIGNMENT_NAME for use in submission forms window.ASSIGNMENT_ID = result.id; window.ASSIGNMENT_NAME = result.name; - console.log('Assignment auto-created with ID:', result.id); - } else if (createRes.status === 200) { - // Assignment already exists - const result = await createRes.json(); - window.ASSIGNMENT_ID = result.id; - window.ASSIGNMENT_NAME = result.name; - console.log('Assignment already exists with ID:', result.id); + + // Distinguish between newly created (201) and already existing (200) + if (createRes.status === 201) { + console.log('✓ Assignment auto-created with ID:', result.id); + } else if (createRes.status === 200) { + console.log('ℹ Assignment already exists with ID:', result.id, '- reusing for this session'); + } else { + console.log('Assignment resolved with ID:', result.id); + } + } else if (createRes.status === 403) { + console.warn('Not authenticated - assignment creation skipped. Please log in to enable assignments.'); + } else if (createRes.status === 400) { + const error = await createRes.json(); + console.error('Bad request for auto-create assignment:', error.error); } else { - console.error('Failed to auto-create assignment:', createRes.statusText); + console.error('Failed to auto-create assignment:', createRes.status, createRes.statusText); } } catch (error) { console.error('Error auto-creating assignment:', error); From c95720a9ae70cb900278bbbadedf0cc873439d16 Mon Sep 17 00:00:00 2001 From: CyberLord09 Date: Tue, 19 May 2026 09:51:51 -0700 Subject: [PATCH 3/3] assignment true --- .../CSA/ap_frq_lessons/2018/2026-01-05-ap_frq_2018_q4.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/_notebooks/CSA/ap_frq_lessons/2018/2026-01-05-ap_frq_2018_q4.ipynb b/_notebooks/CSA/ap_frq_lessons/2018/2026-01-05-ap_frq_2018_q4.ipynb index 7bca41845..d2be9fe9e 100644 --- a/_notebooks/CSA/ap_frq_lessons/2018/2026-01-05-ap_frq_2018_q4.ipynb +++ b/_notebooks/CSA/ap_frq_lessons/2018/2026-01-05-ap_frq_2018_q4.ipynb @@ -22,6 +22,7 @@ "description: \"AP CSA 2018 FRQ #4 - 2D Arrays - ArrayTester Class and Latin Squares\"\n", "permalink: /csa/frqs/2018/4\n", "author: Database Guys - Yash Parikh\n", + "assignment: true\n", "---" ] },