From c4dc4b58b875f8d839921e447ee93028143bb381 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Fri, 6 Jun 2025 10:36:19 +1000 Subject: [PATCH] feat: assessment overview get letter grades from Assessment Averages plugin --- .../built-in/assessmentsOverview/index.ts | 4 +-- .../built-in/assessmentsOverview/ui.ts | 34 +++++++++++++++---- .../built-in/assessmentsOverview/utils.ts | 23 +++++++------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/plugins/built-in/assessmentsOverview/index.ts b/src/plugins/built-in/assessmentsOverview/index.ts index 33888ae7..095fb719 100644 --- a/src/plugins/built-in/assessmentsOverview/index.ts +++ b/src/plugins/built-in/assessmentsOverview/index.ts @@ -14,7 +14,7 @@ const assessmentsOverviewPlugin: Plugin<{}> = { disableToggle: false, styles, - run: async () => { + run: async (api) => { const menu = (await waitForElm('[data-key="assessments"] > .sub > ul', true, 100, 60)) as HTMLElement; const gridItem = document.createElement('li'); gridItem.className = 'item'; @@ -55,7 +55,7 @@ const assessmentsOverviewPlugin: Plugin<{}> = { try { const data = await getAssessmentsData(); const { renderGrid } = await import('./ui'); - renderGrid(container, data); + renderGrid(container, data, api); } catch (err) { console.error('Failed to load assessments:', err); renderErrorState(container, err instanceof Error ? err.message : 'Unknown error'); diff --git a/src/plugins/built-in/assessmentsOverview/ui.ts b/src/plugins/built-in/assessmentsOverview/ui.ts index 6035aac2..3b2ee593 100644 --- a/src/plugins/built-in/assessmentsOverview/ui.ts +++ b/src/plugins/built-in/assessmentsOverview/ui.ts @@ -1,4 +1,16 @@ import { determineStatus, formatDate, getGradeValue } from './utils'; +import { settingsState } from '@/seqta/utils/listeners/SettingsState'; + +function percentageToLetter(percentage: number): string { + const letterMap: Record = { + 100: 'A+', 95: 'A', 90: 'A-', 85: 'B+', 80: 'B', 75: 'B-', + 70: 'C+', 65: 'C', 60: 'C-', 55: 'D+', 50: 'D', 45: 'D-', + 40: 'E+', 35: 'E', 30: 'E-', 0: 'F' + }; + + const rounded = Math.ceil(percentage / 5) * 5; + return letterMap[rounded] || 'F'; +} interface FilterOptions { subject: string; @@ -10,7 +22,7 @@ let currentFilters: FilterOptions = { sortBy: 'due' }; -export function renderGrid(container: HTMLElement, data: any) { +export function renderGrid(container: HTMLElement, data: any, api?: any) { container.innerHTML = ''; container.className = ''; container.id = 'grid-view-container'; @@ -93,10 +105,10 @@ export function renderGrid(container: HTMLElement, data: any) { return; } - renderKanbanBoard(contentArea, filteredAssessments, data); + renderKanbanBoard(contentArea, filteredAssessments, data, api); } - function renderKanbanBoard(container: HTMLElement, assessments: any[], data: any) { + function renderKanbanBoard(container: HTMLElement, assessments: any[], data: any, api?: any) { // Group assessments by status const statusGroups = { 'UPCOMING': [] as any[], @@ -172,7 +184,7 @@ export function renderGrid(container: HTMLElement, data: any) { `; } else { assessmentList.forEach(assessment => { - cardsContainer.appendChild(createKanbanCard(assessment, data.colors[assessment.code] || '#6366f1')); + cardsContainer.appendChild(createKanbanCard(assessment, data.colors[assessment.code] || '#6366f1', api)); }); } @@ -183,7 +195,7 @@ export function renderGrid(container: HTMLElement, data: any) { container.appendChild(board); } - function createKanbanCard(assessment: any, color: string): HTMLElement { + function createKanbanCard(assessment: any, color: string, api?: any): HTMLElement { const status = determineStatus(assessment); const dueDateClass = getDueDateClass(assessment); @@ -201,7 +213,7 @@ export function renderGrid(container: HTMLElement, data: any) {

${assessment.title}

- 📅 ${formatDate(assessment.due)} + 📅 ${formatDate(assessment.due, assessment.submitted)}
${assessment.results @@ -209,7 +221,15 @@ export function renderGrid(container: HTMLElement, data: any) { diff --git a/src/plugins/built-in/assessmentsOverview/utils.ts b/src/plugins/built-in/assessmentsOverview/utils.ts index 32d0ea41..33304933 100644 --- a/src/plugins/built-in/assessmentsOverview/utils.ts +++ b/src/plugins/built-in/assessmentsOverview/utils.ts @@ -1,11 +1,11 @@ -export function formatDate(dateStr: string): string { +export function formatDate(dateStr: string, submitted?: boolean): string { const d = new Date(dateStr); const now = new Date(); const diffTime = d.getTime() - now.getTime(); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); - // If it's overdue - if (diffDays < 0) { + // If it's overdue but don't show overdue text for submitted assessments + if (diffDays < 0 && !submitted) { const overdueDays = Math.abs(diffDays); if (overdueDays === 1) return '1 day overdue'; return `${overdueDays} days overdue`; @@ -42,19 +42,20 @@ export function determineStatus(item: any): string { const now = new Date(); const due = new Date(item.due); - // Check if overdue, but only if not submitted - if (due.getTime() < now.getTime()) { - // If it's submitted, treat it as marks pending (upcoming) instead of overdue + // Calculate the difference in days (more precise calculation) + const diffTime = due.getTime() - now.getTime(); + const diffDays = diffTime / (1000 * 60 * 60 * 24); + + // Check if overdue (more than 1 day past due) + if (diffDays < -1) { + // If it's submitted but still overdue, treat as DUE_SOON since it's awaiting marking if (item.submitted) { - return 'UPCOMING'; + return 'DUE_SOON'; } return 'OVERDUE'; } - // Check if due soon (within 7 days) - const diffTime = due.getTime() - now.getTime(); - const diffDays = diffTime / (1000 * 60 * 60 * 24); - + // Check if due soon (today through 7 days from now) if (diffDays <= 7) { return 'DUE_SOON'; }