Add disinclude option for assignments from other classes
This commit is contained in:
parent
5577214005
commit
8acc77e441
8 changed files with 230 additions and 17 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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<string, SubjectStat> = {};
|
||||
|
||||
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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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<string, SubjectStat>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -116,6 +116,9 @@
|
|||
<button type="button" class="tab-btn" data-filter="overdue">
|
||||
Overdue (<span id="tabOverdueCount"><%= stats.overdue %></span>)
|
||||
</button>
|
||||
<button type="button" class="tab-btn" data-filter="excluded">
|
||||
Excluded (<span id="tabExcludedCount"><%= stats.excludedCount || 0 %></span>)
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="filter-controls">
|
||||
|
|
@ -154,11 +157,12 @@
|
|||
<div class="assignment-list" id="assignmentList">
|
||||
<% assignments.forEach(function(item) { %>
|
||||
<div
|
||||
class="assignment-card <%= item.completed ? 'is-completed' : '' %> status-<%= item.status %>"
|
||||
class="assignment-card <%= item.completed ? 'is-completed' : '' %> <%= item.excluded ? 'is-excluded' : '' %> status-<%= item.status %>"
|
||||
data-id="<%= item.id %>"
|
||||
data-status="<%= item.status %>"
|
||||
data-subject="<%= item.subject %>"
|
||||
data-completed="<%= item.completed ? 'true' : 'false' %>"
|
||||
data-excluded="<%= item.excluded ? 'true' : 'false' %>"
|
||||
data-search="<%= (item.subject + ' ' + item.description + ' ' + (item.detectedCheckDate || '') + ' ' + (item.topic || '') + ' ' + (item.unit || '')).toLowerCase() %>"
|
||||
>
|
||||
<div class="card-checkbox-col">
|
||||
|
|
@ -167,6 +171,7 @@
|
|||
class="assignment-toggle"
|
||||
data-id="<%= item.id %>"
|
||||
<%= item.completed ? 'checked' : '' %>
|
||||
<%= item.excluded ? 'disabled' : '' %>
|
||||
>
|
||||
</div>
|
||||
|
||||
|
|
@ -186,7 +191,9 @@
|
|||
</span>
|
||||
<% } %>
|
||||
|
||||
<% if (item.completed) { %>
|
||||
<% if (item.excluded) { %>
|
||||
<span class="badge badge-excluded">Disincluded</span>
|
||||
<% } else if (item.completed) { %>
|
||||
<span class="badge badge-completed">Done</span>
|
||||
<% } else if (item.status === 'next-week') { %>
|
||||
<span class="badge badge-next-week">Next Week</span>
|
||||
|
|
@ -197,6 +204,15 @@
|
|||
<% } else { %>
|
||||
<span class="badge badge-active">Active</span>
|
||||
<% } %>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn-disinclude"
|
||||
data-id="<%= item.id %>"
|
||||
title="<%= item.excluded ? 'Restore this homework to your active list' : 'Disinclude this homework (e.g. from another class)' %>"
|
||||
>
|
||||
<%= item.excluded ? 'Restore' : 'Disinclude' %>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue