Add disinclude option for assignments from other classes

This commit is contained in:
tyuXX 2026-10-21 18:21:11 +00:00
parent 5577214005
commit 8acc77e441
8 changed files with 230 additions and 17 deletions

View file

@ -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)

View file

@ -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];

View file

@ -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
};

View file

@ -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>;
}