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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue