init
This commit is contained in:
commit
5577214005
22 changed files with 4997 additions and 0 deletions
692
public/css/style.css
Normal file
692
public/css/style.css
Normal file
|
|
@ -0,0 +1,692 @@
|
|||
:root {
|
||||
--primary: #2563eb;
|
||||
--primary-hover: #1d4ed8;
|
||||
--text-main: #1e293b;
|
||||
--text-muted: #64748b;
|
||||
--text-light: #94a3b8;
|
||||
--bg-page: #f8fafc;
|
||||
--bg-card: #ffffff;
|
||||
--border: #e2e8f0;
|
||||
|
||||
--success: #16a34a;
|
||||
--warning: #d97706;
|
||||
--urgent: #ea580c;
|
||||
--danger: #dc2626;
|
||||
|
||||
--radius: 6px;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
background-color: var(--bg-page);
|
||||
color: var(--text-main);
|
||||
line-height: 1.45;
|
||||
font-size: 14px;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Menlo, Monaco, Consolas, monospace;
|
||||
font-size: 0.9em;
|
||||
background: #f1f5f9;
|
||||
padding: 2px 4px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* ---------------- Header ---------------- */
|
||||
.app-header {
|
||||
background: var(--bg-card);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.header-container {
|
||||
max-width: 1080px;
|
||||
margin: 0 auto;
|
||||
padding: 10px 16px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.brand-link {
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.brand-name {
|
||||
font-size: 1.15rem;
|
||||
font-weight: 700;
|
||||
color: var(--text-main);
|
||||
}
|
||||
|
||||
.user-nav {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.user-id {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
/* ---------------- Main Layout ---------------- */
|
||||
.main-content {
|
||||
flex: 1;
|
||||
max-width: 1080px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
padding: 18px 16px;
|
||||
}
|
||||
|
||||
/* ---------------- Buttons ---------------- */
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 6px 14px;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 500;
|
||||
border-radius: var(--radius);
|
||||
border: 1px solid transparent;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
background-color: var(--primary-hover);
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background-color: white;
|
||||
border-color: var(--border);
|
||||
color: var(--text-main);
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background-color: #f1f5f9;
|
||||
}
|
||||
|
||||
.btn-outline {
|
||||
background: transparent;
|
||||
border-color: var(--border);
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.btn-outline:hover {
|
||||
background: #f1f5f9;
|
||||
color: var(--text-main);
|
||||
}
|
||||
|
||||
.btn-sm {
|
||||
padding: 5px 10px;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.btn-block {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* ---------------- Login ---------------- */
|
||||
.auth-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding-top: 60px;
|
||||
}
|
||||
|
||||
.auth-card {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 28px 24px;
|
||||
max-width: 360px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.auth-title {
|
||||
font-size: 1.3rem;
|
||||
font-weight: 700;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.auth-subtitle {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.auth-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.form-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.form-label {
|
||||
font-size: 0.8rem;
|
||||
font-weight: 600;
|
||||
color: var(--text-main);
|
||||
}
|
||||
|
||||
.form-control {
|
||||
width: 100%;
|
||||
padding: 8px 10px;
|
||||
font-size: 0.9rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
background: white;
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
.form-row-between {
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.checkbox-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
cursor: pointer;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.form-actions {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
/* ---------------- Alerts ---------------- */
|
||||
.alert {
|
||||
padding: 8px 12px;
|
||||
border-radius: var(--radius);
|
||||
font-size: 0.85rem;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.alert-danger {
|
||||
background: #fef2f2;
|
||||
color: #991b1b;
|
||||
border: 1px solid #fecaca;
|
||||
}
|
||||
|
||||
.alert-info {
|
||||
background: #eff6ff;
|
||||
color: #1e40af;
|
||||
border: 1px solid #bfdbfe;
|
||||
}
|
||||
|
||||
/* ---------------- Dashboard Top Bar ---------------- */
|
||||
.dashboard-topbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.dashboard-title {
|
||||
font-size: 1.4rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.dashboard-subtitle {
|
||||
font-size: 0.85rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.dot-separator {
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
.sync-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
/* ---------------- Stats Grid ---------------- */
|
||||
.stats-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
|
||||
gap: 10px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.stat-card {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 12px 14px;
|
||||
}
|
||||
|
||||
.stat-highlight {
|
||||
border-left: 3px solid var(--warning);
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-size: 1.45rem;
|
||||
font-weight: 700;
|
||||
margin: 4px 0 2px;
|
||||
}
|
||||
|
||||
.stat-subtext {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.progress-bar-container {
|
||||
background: #e2e8f0;
|
||||
height: 4px;
|
||||
border-radius: 9999px;
|
||||
overflow: hidden;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.progress-bar-fill {
|
||||
background: var(--success);
|
||||
height: 100%;
|
||||
border-radius: 9999px;
|
||||
transition: width 0.3s;
|
||||
}
|
||||
|
||||
/* ---------------- Subjects ---------------- */
|
||||
.section-card {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
padding: 10px 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
border-bottom: 1px solid var(--border);
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.cursor-pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.toggle-indicator {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.subject-breakdown-body {
|
||||
padding: 12px 14px;
|
||||
}
|
||||
|
||||
.subject-breakdown-body.collapsed {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.subject-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.subject-item {
|
||||
background: #f8fafc;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 8px 10px;
|
||||
}
|
||||
|
||||
.subject-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 4px;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.subject-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.subject-fraction {
|
||||
color: var(--text-muted);
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.subject-bar {
|
||||
background: #e2e8f0;
|
||||
height: 4px;
|
||||
border-radius: 9999px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.subject-bar-fill {
|
||||
background: var(--primary);
|
||||
height: 100%;
|
||||
border-radius: 9999px;
|
||||
}
|
||||
|
||||
/* ---------------- Toolbar ---------------- */
|
||||
.toolbar-card {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 12px 14px;
|
||||
margin-bottom: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.filter-tabs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.tab-btn {
|
||||
background: #f1f5f9;
|
||||
border: 1px solid transparent;
|
||||
color: var(--text-muted);
|
||||
padding: 4px 10px;
|
||||
border-radius: var(--radius);
|
||||
font-size: 0.8rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.tab-btn:hover {
|
||||
background: #e2e8f0;
|
||||
}
|
||||
|
||||
.tab-btn.active {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.filter-controls {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.search-box {
|
||||
flex: 1;
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
width: 100%;
|
||||
padding: 6px 26px 6px 10px;
|
||||
font-size: 0.85rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.search-input:focus {
|
||||
outline: none;
|
||||
border-color: var(--primary);
|
||||
}
|
||||
|
||||
.search-clear {
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
background: none;
|
||||
border: none;
|
||||
font-size: 1rem;
|
||||
color: var(--text-light);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.form-select {
|
||||
padding: 6px 10px;
|
||||
font-size: 0.85rem;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
background: white;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.list-meta {
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
/* ---------------- Cards ---------------- */
|
||||
.assignment-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.assignment-card {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 12px 14px;
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.assignment-card.status-next-week:not(.is-completed) {
|
||||
border-left: 3px solid var(--warning);
|
||||
}
|
||||
|
||||
.assignment-card.status-due-soon:not(.is-completed) {
|
||||
border-left: 3px solid var(--urgent);
|
||||
}
|
||||
|
||||
.assignment-card.status-overdue:not(.is-completed) {
|
||||
border-left: 3px solid var(--danger);
|
||||
}
|
||||
|
||||
.assignment-card.status-active:not(.is-completed) {
|
||||
border-left: 3px solid #38bdf8;
|
||||
}
|
||||
|
||||
.assignment-card.is-completed {
|
||||
border-left: 3px solid var(--success);
|
||||
opacity: 0.65;
|
||||
}
|
||||
|
||||
.assignment-card.is-completed .card-description {
|
||||
text-decoration: line-through;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.card-checkbox-col {
|
||||
padding-top: 2px;
|
||||
}
|
||||
|
||||
.assignment-toggle {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.card-content-col {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.card-top-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.card-subject-wrap {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.card-subject {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.card-badges {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.badge {
|
||||
font-size: 0.725rem;
|
||||
font-weight: 600;
|
||||
padding: 1px 6px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.badge-type {
|
||||
background: #f1f5f9;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.badge-active {
|
||||
background: #e0f2fe;
|
||||
color: #0369a1;
|
||||
}
|
||||
|
||||
.badge-next-week {
|
||||
background: #fef3c7;
|
||||
color: #b45309;
|
||||
}
|
||||
|
||||
.badge-due-soon {
|
||||
background: #ffedd5;
|
||||
color: #c2410c;
|
||||
}
|
||||
|
||||
.badge-overdue {
|
||||
background: #fee2e2;
|
||||
color: #b91c1c;
|
||||
}
|
||||
|
||||
.badge-completed {
|
||||
background: #dcfce7;
|
||||
color: #15803d;
|
||||
}
|
||||
|
||||
.badge-check-date {
|
||||
background: #f3e8ff;
|
||||
color: #7e22ce;
|
||||
border: 1px solid #e9d5ff;
|
||||
}
|
||||
|
||||
.card-sub-meta {
|
||||
font-size: 0.78rem;
|
||||
color: var(--text-muted);
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.card-description {
|
||||
font-size: 0.88rem;
|
||||
line-height: 1.45;
|
||||
color: #1e293b;
|
||||
white-space: pre-line;
|
||||
word-break: break-word;
|
||||
background: #f8fafc;
|
||||
padding: 6px 10px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.card-footer-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.card-timestamps {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.card-hash {
|
||||
font-family: Menlo, Monaco, monospace;
|
||||
font-size: 0.7rem;
|
||||
color: var(--text-light);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 24px;
|
||||
text-align: center;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.empty-state p {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.app-footer {
|
||||
border-top: 1px solid var(--border);
|
||||
padding: 12px 16px;
|
||||
text-align: center;
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-light);
|
||||
margin-top: auto;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.dashboard-topbar {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.filter-controls {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
303
public/js/app.js
Normal file
303
public/js/app.js
Normal file
|
|
@ -0,0 +1,303 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const assignmentList = document.getElementById('assignmentList');
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
const searchClear = document.getElementById('searchClear');
|
||||
const subjectSelect = document.getElementById('subjectSelect');
|
||||
const filterTabs = document.getElementById('filterTabs');
|
||||
const filteredCountText = document.getElementById('filteredCountText');
|
||||
const noResults = document.getElementById('noResults');
|
||||
const btnResetFilters = document.getElementById('btnResetFilters');
|
||||
const syncAlert = document.getElementById('syncAlert');
|
||||
const btnSyncRecent = document.getElementById('btnSyncRecent');
|
||||
const btnSyncAll = document.getElementById('btnSyncAll');
|
||||
const subjectToggleHeader = document.getElementById('subjectToggleHeader');
|
||||
const subjectBreakdownBody = document.getElementById('subjectBreakdownBody');
|
||||
const subjectToggleIcon = document.getElementById('subjectToggleIcon');
|
||||
|
||||
let currentTab = 'all';
|
||||
let currentSearch = '';
|
||||
let currentSubject = '';
|
||||
|
||||
// Checkbox toggle
|
||||
if (assignmentList) {
|
||||
assignmentList.addEventListener('change', async (e) => {
|
||||
const target = e.target;
|
||||
if (!target.classList.contains('assignment-toggle')) return;
|
||||
|
||||
const assignmentId = target.dataset.id;
|
||||
const isChecked = target.checked;
|
||||
const card = target.closest('.assignment-card');
|
||||
if (!card) return;
|
||||
|
||||
if (isChecked) {
|
||||
card.classList.add('is-completed');
|
||||
card.dataset.completed = 'true';
|
||||
updateCardBadge(card, 'completed');
|
||||
} else {
|
||||
card.classList.remove('is-completed');
|
||||
card.dataset.completed = 'false';
|
||||
updateCardBadge(card, card.dataset.status);
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/toggle', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ assignmentId, completed: isChecked })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.success && data.stats) {
|
||||
updateStatsUI(data.stats);
|
||||
applyFilters();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to toggle assignment:', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateCardBadge(card, status) {
|
||||
const badgesContainer = card.querySelector('.card-badges');
|
||||
if (!badgesContainer) return;
|
||||
|
||||
let existingStatusBadge = badgesContainer.querySelector(
|
||||
'.badge-completed, .badge-next-week, .badge-due-soon, .badge-overdue, .badge-active'
|
||||
);
|
||||
|
||||
if (existingStatusBadge) {
|
||||
if (status === 'completed') {
|
||||
existingStatusBadge.className = 'badge badge-completed';
|
||||
existingStatusBadge.textContent = 'Done';
|
||||
} else {
|
||||
const orig = card.dataset.status;
|
||||
if (orig === 'next-week') {
|
||||
existingStatusBadge.className = 'badge badge-next-week';
|
||||
existingStatusBadge.textContent = 'Next Week';
|
||||
} else if (orig === 'due-soon') {
|
||||
existingStatusBadge.className = 'badge badge-due-soon';
|
||||
existingStatusBadge.textContent = 'Due Soon';
|
||||
} else if (orig === 'overdue') {
|
||||
existingStatusBadge.className = 'badge badge-overdue';
|
||||
existingStatusBadge.textContent = 'Overdue';
|
||||
} else {
|
||||
existingStatusBadge.className = 'badge badge-active';
|
||||
existingStatusBadge.textContent = 'Active';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatsUI(stats) {
|
||||
const statCompRate = document.getElementById('statCompletionRate');
|
||||
const statCompFrac = document.getElementById('statCompletionFraction');
|
||||
const progressBar = document.getElementById('progressBarFill');
|
||||
const statActive = document.getElementById('statActiveCount');
|
||||
const statNextWeek = document.getElementById('statNextWeekCount');
|
||||
const statDueSoon = document.getElementById('statDueSoonCount');
|
||||
const statOverdue = document.getElementById('statOverdueCount');
|
||||
const statTotal = document.getElementById('statTotalCount');
|
||||
|
||||
if (statCompRate) statCompRate.textContent = `${stats.completionRate}%`;
|
||||
if (statCompFrac) statCompFrac.textContent = `${stats.completed} / ${stats.total} done`;
|
||||
if (progressBar) progressBar.style.width = `${stats.completionRate}%`;
|
||||
if (statActive) statActive.textContent = stats.active;
|
||||
if (statNextWeek) statNextWeek.textContent = stats.checkedNextWeek;
|
||||
if (statDueSoon) statDueSoon.textContent = stats.dueSoon;
|
||||
if (statOverdue) statOverdue.textContent = stats.overdue;
|
||||
if (statTotal) statTotal.textContent = stats.total;
|
||||
|
||||
const tabAll = document.getElementById('tabAllCount');
|
||||
const tabNext = document.getElementById('tabNextWeekCount');
|
||||
const tabAct = document.getElementById('tabActiveCount');
|
||||
const tabDue = document.getElementById('tabDueSoonCount');
|
||||
const tabComp = document.getElementById('tabCompletedCount');
|
||||
const tabOver = document.getElementById('tabOverdueCount');
|
||||
|
||||
if (tabAll) tabAll.textContent = stats.total;
|
||||
if (tabNext) tabNext.textContent = stats.checkedNextWeek;
|
||||
if (tabAct) tabAct.textContent = stats.active;
|
||||
if (tabDue) tabDue.textContent = stats.dueSoon;
|
||||
if (tabComp) tabComp.textContent = stats.completed;
|
||||
if (tabOver) tabOver.textContent = stats.overdue;
|
||||
|
||||
if (stats.bySubject) {
|
||||
Object.values(stats.bySubject).forEach(s => {
|
||||
const item = document.querySelector(`.subject-item[data-subject="${CSS.escape(s.subject)}"]`);
|
||||
if (item) {
|
||||
const frac = item.querySelector('.subject-fraction');
|
||||
const fill = item.querySelector('.subject-bar-fill');
|
||||
if (frac) frac.textContent = `${s.completed}/${s.total} (${s.percentage}%)`;
|
||||
if (fill) fill.style.width = `${s.percentage}%`;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Filter tabs
|
||||
if (filterTabs) {
|
||||
filterTabs.addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('.tab-btn');
|
||||
if (!btn) return;
|
||||
filterTabs.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
currentTab = btn.dataset.filter || 'all';
|
||||
applyFilters();
|
||||
});
|
||||
}
|
||||
|
||||
if (searchInput) {
|
||||
searchInput.addEventListener('input', (e) => {
|
||||
currentSearch = e.target.value.trim().toLowerCase();
|
||||
if (searchClear) searchClear.classList.toggle('hidden', currentSearch.length === 0);
|
||||
applyFilters();
|
||||
});
|
||||
}
|
||||
|
||||
if (searchClear) {
|
||||
searchClear.addEventListener('click', () => {
|
||||
searchInput.value = '';
|
||||
currentSearch = '';
|
||||
searchClear.classList.add('hidden');
|
||||
applyFilters();
|
||||
});
|
||||
}
|
||||
|
||||
if (subjectSelect) {
|
||||
subjectSelect.addEventListener('change', (e) => {
|
||||
currentSubject = e.target.value;
|
||||
applyFilters();
|
||||
});
|
||||
}
|
||||
|
||||
if (btnResetFilters) {
|
||||
btnResetFilters.addEventListener('click', () => {
|
||||
currentTab = 'all';
|
||||
currentSearch = '';
|
||||
currentSubject = '';
|
||||
if (searchInput) searchInput.value = '';
|
||||
if (searchClear) searchClear.classList.add('hidden');
|
||||
if (subjectSelect) subjectSelect.value = '';
|
||||
if (filterTabs) {
|
||||
filterTabs.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
||||
const allTab = filterTabs.querySelector('[data-filter="all"]');
|
||||
if (allTab) allTab.classList.add('active');
|
||||
}
|
||||
applyFilters();
|
||||
});
|
||||
}
|
||||
|
||||
function applyFilters() {
|
||||
if (!assignmentList) return;
|
||||
const cards = assignmentList.querySelectorAll('.assignment-card');
|
||||
let visibleCount = 0;
|
||||
|
||||
cards.forEach(card => {
|
||||
const status = card.dataset.status;
|
||||
const isCompleted = card.dataset.completed === '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';
|
||||
}
|
||||
|
||||
let matchesSubject = true;
|
||||
if (currentSubject) {
|
||||
matchesSubject = (subject === currentSubject);
|
||||
}
|
||||
|
||||
let matchesSearch = true;
|
||||
if (currentSearch) {
|
||||
matchesSearch = searchText.includes(currentSearch);
|
||||
}
|
||||
|
||||
if (matchesTab && matchesSubject && matchesSearch) {
|
||||
card.style.display = 'flex';
|
||||
visibleCount++;
|
||||
} else {
|
||||
card.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
if (filteredCountText) {
|
||||
filteredCountText.textContent = `Showing ${visibleCount} assignments`;
|
||||
}
|
||||
|
||||
if (noResults) {
|
||||
noResults.classList.toggle('hidden', visibleCount > 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Sync actions
|
||||
if (btnSyncRecent) {
|
||||
btnSyncRecent.addEventListener('click', async () => {
|
||||
btnSyncRecent.disabled = true;
|
||||
btnSyncRecent.textContent = 'Syncing...';
|
||||
showAlert('Fetching recent assignments...', 'info');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/sync', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
showAlert(`Sync failed: ${data.error}`, 'danger');
|
||||
btnSyncRecent.disabled = false;
|
||||
btnSyncRecent.textContent = 'Sync Recent';
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert('Network error while syncing.', 'danger');
|
||||
btnSyncRecent.disabled = false;
|
||||
btnSyncRecent.textContent = 'Sync Recent';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (btnSyncAll) {
|
||||
btnSyncAll.addEventListener('click', async () => {
|
||||
btnSyncAll.disabled = true;
|
||||
btnSyncAll.textContent = 'Syncing all...';
|
||||
showAlert('Syncing full history from portal...', 'info');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/sync-all', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
showAlert(`Sync all failed: ${data.error}`, 'danger');
|
||||
btnSyncAll.disabled = false;
|
||||
btnSyncAll.textContent = 'Sync Full History';
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert('Network error while syncing full history.', 'danger');
|
||||
btnSyncAll.disabled = false;
|
||||
btnSyncAll.textContent = 'Sync Full History';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showAlert(msg, type = 'info') {
|
||||
if (!syncAlert) return;
|
||||
syncAlert.className = `alert alert-${type}`;
|
||||
syncAlert.textContent = msg;
|
||||
syncAlert.classList.remove('hidden');
|
||||
}
|
||||
|
||||
// Subject collapse
|
||||
if (subjectToggleHeader && subjectBreakdownBody && subjectToggleIcon) {
|
||||
subjectToggleHeader.addEventListener('click', () => {
|
||||
const isHidden = subjectBreakdownBody.classList.toggle('collapsed');
|
||||
subjectToggleIcon.textContent = isHidden ? '▶' : '▼';
|
||||
});
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue