From 8acc77e4413a9781b26e258cfb41286663f72726 Mon Sep 17 00:00:00 2001 From: tyuXX Date: Wed, 21 Oct 2026 18:21:11 +0000 Subject: [PATCH] Add disinclude option for assignments from other classes --- public/css/style.css | 28 ++++++++++++++ public/js/app.js | 83 ++++++++++++++++++++++++++++++++++++----- src/server.ts | 31 +++++++++++++++ src/services/db.ts | 24 ++++++++++-- src/services/insight.ts | 11 +++++- src/types/index.ts | 2 + test/run-tests.ts | 48 ++++++++++++++++++++++++ views/dashboard.ejs | 20 +++++++++- 8 files changed, 230 insertions(+), 17 deletions(-) diff --git a/public/css/style.css b/public/css/style.css index c6804e3..2dc6113 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -617,6 +617,34 @@ code { border: 1px solid #e9d5ff; } +.badge-excluded { + background: #f1f5f9; + color: #64748b; + border: 1px solid #cbd5e1; +} + +.btn-disinclude { + background: transparent; + border: 1px solid #cbd5e1; + color: var(--text-muted); + font-size: 0.7rem; + padding: 1px 6px; + border-radius: 4px; + cursor: pointer; +} + +.btn-disinclude:hover { + background: #f1f5f9; + color: var(--text-main); + border-color: #94a3b8; +} + +.assignment-card.is-excluded { + opacity: 0.5; + background-color: #f8fafc; + border-left: 3px solid #94a3b8 !important; +} + .card-sub-meta { font-size: 0.78rem; color: var(--text-muted); diff --git a/public/js/app.js b/public/js/app.js index 0e62125..a2897f9 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -20,6 +20,60 @@ document.addEventListener('DOMContentLoaded', () => { // Checkbox toggle if (assignmentList) { + assignmentList.addEventListener('click', async (e) => { + const target = e.target; + + // Disinclude / Restore button + if (target.classList.contains('btn-disinclude')) { + const assignmentId = target.dataset.id; + const card = target.closest('.assignment-card'); + if (!card) return; + + const currentExcluded = card.dataset.excluded === 'true'; + const newExcluded = !currentExcluded; + target.disabled = true; + + try { + const res = await fetch('/api/exclude', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ assignmentId, excluded: newExcluded }) + }); + const data = await res.json(); + if (data.success && data.stats) { + card.dataset.excluded = newExcluded ? 'true' : 'false'; + card.classList.toggle('is-excluded', newExcluded); + target.textContent = newExcluded ? 'Restore' : 'Disinclude'; + target.title = newExcluded ? 'Restore this homework to your active list' : 'Disinclude this homework (e.g. from another class)'; + + const checkbox = card.querySelector('.assignment-toggle'); + if (checkbox) checkbox.disabled = newExcluded; + + let badgeExcluded = card.querySelector('.badge-excluded'); + if (newExcluded && !badgeExcluded) { + const badgesContainer = card.querySelector('.card-badges'); + if (badgesContainer) { + const b = document.createElement('span'); + b.className = 'badge badge-excluded'; + b.textContent = 'Disincluded'; + badgesContainer.insertBefore(b, target); + } + } else if (!newExcluded && badgeExcluded) { + badgeExcluded.remove(); + } + + updateStatsUI(data.stats); + applyFilters(); + } + } catch (err) { + console.error('Failed to toggle disinclude:', err); + } finally { + target.disabled = false; + } + return; + } + }); + assignmentList.addEventListener('change', async (e) => { const target = e.target; if (!target.classList.contains('assignment-toggle')) return; @@ -112,6 +166,7 @@ document.addEventListener('DOMContentLoaded', () => { const tabDue = document.getElementById('tabDueSoonCount'); const tabComp = document.getElementById('tabCompletedCount'); const tabOver = document.getElementById('tabOverdueCount'); + const tabExcluded = document.getElementById('tabExcludedCount'); if (tabAll) tabAll.textContent = stats.total; if (tabNext) tabNext.textContent = stats.checkedNextWeek; @@ -119,6 +174,7 @@ document.addEventListener('DOMContentLoaded', () => { if (tabDue) tabDue.textContent = stats.dueSoon; if (tabComp) tabComp.textContent = stats.completed; if (tabOver) tabOver.textContent = stats.overdue; + if (tabExcluded) tabExcluded.textContent = stats.excludedCount || 0; if (stats.bySubject) { Object.values(stats.bySubject).forEach(s => { @@ -194,20 +250,27 @@ document.addEventListener('DOMContentLoaded', () => { cards.forEach(card => { const status = card.dataset.status; const isCompleted = card.dataset.completed === 'true'; + const isExcluded = card.dataset.excluded === 'true'; const subject = card.dataset.subject; const searchText = card.dataset.search || ''; let matchesTab = true; - if (currentTab === 'completed') { - matchesTab = isCompleted; - } else if (currentTab === 'active') { - matchesTab = !isCompleted && (status === 'active' || status === 'next-week' || status === 'due-soon'); - } else if (currentTab === 'next-week') { - matchesTab = !isCompleted && status === 'next-week'; - } else if (currentTab === 'due-soon') { - matchesTab = !isCompleted && status === 'due-soon'; - } else if (currentTab === 'overdue') { - matchesTab = !isCompleted && status === 'overdue'; + if (currentTab === 'excluded') { + matchesTab = isExcluded; + } else { + if (isExcluded) { + matchesTab = false; + } else if (currentTab === 'completed') { + matchesTab = isCompleted; + } else if (currentTab === 'active') { + matchesTab = !isCompleted && (status === 'active' || status === 'next-week' || status === 'due-soon'); + } else if (currentTab === 'next-week') { + matchesTab = !isCompleted && status === 'next-week'; + } else if (currentTab === 'due-soon') { + matchesTab = !isCompleted && status === 'due-soon'; + } else if (currentTab === 'overdue') { + matchesTab = !isCompleted && status === 'overdue'; + } } let matchesSubject = true; diff --git a/src/server.ts b/src/server.ts index 7a1d977..c069ba5 100644 --- a/src/server.ts +++ b/src/server.ts @@ -268,6 +268,37 @@ app.post('/api/toggle', requireAuth, (req: Request, res: Response) => { }); }); +/** + * POST /api/exclude + * Toggle assignment disinclude/exclude state + */ +app.post('/api/exclude', requireAuth, (req: Request, res: Response) => { + const studentId = req.session.studentId!; + const { assignmentId, excluded } = req.body; + + if (!assignmentId) { + return res.status(400).json({ success: false, error: 'Assignment ID is required' }); + } + + const updated = db.toggleExcludeAssignment(studentId, assignmentId, excluded); + if (!updated) { + return res.status(404).json({ success: false, error: 'Assignment not found' }); + } + + const studentStore = db.getStudentStore(studentId); + const list = Object.values(studentStore.assignments).map(a => ({ + ...a, + status: InsightService.computeStatus(a) + })); + const stats = InsightService.calculateStats(list); + + res.json({ + success: true, + assignment: updated, + stats + }); +}); + /** * POST /api/sync * Sync recent pages (1-2) diff --git a/src/services/db.ts b/src/services/db.ts index 4da2f96..57fe79b 100644 --- a/src/services/db.ts +++ b/src/services/db.ts @@ -77,14 +77,18 @@ export class LocalDatabase { for (const item of newAssignments) { const existing = student.assignments[item.id]; if (existing) { - // Preserve user completion status and completion timestamp + // Preserve user completion status, timestamp, and disincluded flag student.assignments[item.id] = { ...item, completed: existing.completed, - completedAt: existing.completedAt + completedAt: existing.completedAt, + excluded: existing.excluded || false }; } else { - student.assignments[item.id] = item; + student.assignments[item.id] = { + ...item, + excluded: false + }; } } @@ -92,6 +96,20 @@ export class LocalDatabase { return student; } + public toggleExcludeAssignment(studentId: string, assignmentId: string, excluded?: boolean): Assignment | null { + const student = this.getStudentStore(studentId); + const assignment = student.assignments[assignmentId]; + if (!assignment) { + return null; + } + + const newExcluded = excluded !== undefined ? excluded : !assignment.excluded; + assignment.excluded = newExcluded; + + this.save(); + return assignment; + } + public toggleAssignment(studentId: string, assignmentId: string, completed?: boolean): Assignment | null { const student = this.getStudentStore(studentId); const assignment = student.assignments[assignmentId]; diff --git a/src/services/insight.ts b/src/services/insight.ts index 91eef57..65a9c7a 100644 --- a/src/services/insight.ts +++ b/src/services/insight.ts @@ -170,7 +170,7 @@ export class InsightService { } /** - * Aggregate statistics across a list of assignments + * Aggregate statistics across a list of assignments (excludes disincluded assignments) */ public static calculateStats(assignments: Assignment[]): DashboardStats { let completed = 0; @@ -178,10 +178,16 @@ export class InsightService { let checkedNextWeek = 0; let dueSoon = 0; let overdue = 0; + let excludedCount = 0; const bySubject: Record = {}; for (const item of assignments) { + if (item.excluded) { + excludedCount += 1; + continue; + } + const subj = item.subject.trim() || 'Other'; if (!bySubject[subj]) { bySubject[subj] = { @@ -222,7 +228,7 @@ export class InsightService { s.percentage = s.total > 0 ? Math.round((s.completed / s.total) * 100) : 0; } - const total = assignments.length; + const total = assignments.length - excludedCount; const completionRate = total > 0 ? Math.round((completed / total) * 100) : 0; return { @@ -232,6 +238,7 @@ export class InsightService { checkedNextWeek, dueSoon, overdue, + excludedCount, completionRate, bySubject }; diff --git a/src/types/index.ts b/src/types/index.ts index 8129a16..2a88453 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -21,6 +21,7 @@ export interface Assignment { status: AssignmentStatus; completed: boolean; completedAt: string | null; + excluded?: boolean; // disincluded by user page?: number; } @@ -39,6 +40,7 @@ export interface DashboardStats { checkedNextWeek: number; dueSoon: number; overdue: number; + excludedCount: number; completionRate: number; bySubject: Record; } diff --git a/test/run-tests.ts b/test/run-tests.ts index 3e1f351..cfcb4f3 100644 --- a/test/run-tests.ts +++ b/test/run-tests.ts @@ -179,6 +179,33 @@ async function runAllTests() { assert.strictEqual(stats.bySubject['Kimya'].total, 2); assert.strictEqual(stats.bySubject['Kimya'].completed, 1); assert.strictEqual(stats.bySubject['Kimya'].percentage, 50); + + // Test with an excluded (disincluded) assignment + const sampleWithExcluded: Assignment[] = [ + ...sampleAssignments, + { + id: '4', + subject: 'Fizik', + type: 'Yayın', + unit: '', + topic: '', + startDate: '20.10.2026', + endDate: '26.10.2026', + parsedStartDate: '2026-10-20', + parsedEndDate: '2026-10-26', + description: 'Other class homework', + detectedCheckDate: null, + status: 'active', + completed: false, + completedAt: null, + excluded: true + } + ]; + + const statsExcluded = InsightService.calculateStats(sampleWithExcluded); + assert.strictEqual(statsExcluded.total, 3, 'Disincluded assignment must NOT increase total count'); + assert.strictEqual(statsExcluded.excludedCount, 1); + assert.strictEqual(statsExcluded.bySubject['Fizik'].total, 1, 'Disincluded assignment must NOT be in subject total'); }); // 5. Local Database @@ -223,6 +250,27 @@ async function runAllTests() { 'mergeAssignments MUST preserve user checked status!' ); + // Test disinclude / exclude toggle & preservation across merge + const excludedRes = db.toggleExcludeAssignment(testStudentId, testItem.id, true); + assert.strictEqual(excludedRes?.excluded, true); + + // Re-merge from scraper (which always returns excluded undefined or false) + db.mergeAssignments(testStudentId, [{ + ...testItem, + completed: false + }]); + store = db.getStudentStore(testStudentId); + assert.strictEqual( + store.assignments[testItem.id].excluded, + true, + 'mergeAssignments MUST preserve disincluded (excluded) status across scraper syncs!' + ); + + // Restore / Include back + db.toggleExcludeAssignment(testStudentId, testItem.id, false); + store = db.getStudentStore(testStudentId); + assert.strictEqual(store.assignments[testItem.id].excluded, false); + db.saveCredentials(testStudentId, 'test_pass'); const creds = db.getRememberedCredentials(testStudentId); assert.strictEqual(creds?.password, 'test_pass'); diff --git a/views/dashboard.ejs b/views/dashboard.ejs index 65deaf2..ef1ba59 100644 --- a/views/dashboard.ejs +++ b/views/dashboard.ejs @@ -116,6 +116,9 @@ +
@@ -154,11 +157,12 @@
<% assignments.forEach(function(item) { %>
@@ -167,6 +171,7 @@ class="assignment-toggle" data-id="<%= item.id %>" <%= item.completed ? 'checked' : '' %> + <%= item.excluded ? 'disabled' : '' %> >
@@ -186,7 +191,9 @@ <% } %> - <% if (item.completed) { %> + <% if (item.excluded) { %> + Disincluded + <% } else if (item.completed) { %> Done <% } else if (item.status === 'next-week') { %> Next Week @@ -197,6 +204,15 @@ <% } else { %> Active <% } %> + +