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