Add Syllabus (Ders Programı) with station filtering and weekly auto-refresh

This commit is contained in:
tyuXX 2026-10-21 18:42:06 +00:00
parent 8acc77e441
commit d0fd394fbd
10 changed files with 1196 additions and 3 deletions

View file

@ -718,3 +718,328 @@ code {
flex-direction: column;
}
}
/* ---------------- Syllabus & Navigation Styles ---------------- */
.brand-group {
display: flex;
align-items: center;
gap: 20px;
}
.main-nav {
display: flex;
gap: 6px;
}
.nav-item {
text-decoration: none;
color: var(--text-muted);
font-size: 0.85rem;
font-weight: 500;
padding: 4px 10px;
border-radius: var(--radius);
transition: all 0.15s ease;
}
.nav-item:hover {
color: var(--text-main);
background: #f1f5f9;
}
.nav-item.active {
color: var(--primary);
font-weight: 600;
background: #eff6ff;
}
.station-select-row, .view-toggle-row {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
}
.toolbar-label {
font-size: 0.8rem;
font-weight: 600;
color: var(--text-muted);
min-width: 55px;
}
.station-pills, .view-toggle-pills {
display: flex;
gap: 6px;
flex-wrap: wrap;
}
.station-btn, .view-btn {
background: #f1f5f9;
border: 1px solid var(--border);
color: var(--text-main);
font-size: 0.8rem;
padding: 4px 10px;
border-radius: var(--radius);
cursor: pointer;
transition: all 0.15s ease;
}
.station-btn:hover, .view-btn:hover {
background: #e2e8f0;
}
.station-btn.active, .view-btn.active {
background: var(--primary);
border-color: var(--primary);
color: white;
font-weight: 600;
}
.live-period-banner {
background: #eff6ff;
border: 1px solid #bfdbfe;
color: #1e40af;
padding: 8px 12px;
border-radius: var(--radius);
font-size: 0.85rem;
font-weight: 500;
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 14px;
}
.live-dot {
color: #2563eb;
animation: pulse 1.5s infinite;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.3; }
100% { opacity: 1; }
}
.day-tabs {
display: flex;
gap: 6px;
margin-bottom: 12px;
flex-wrap: wrap;
}
.day-tab-btn {
background: var(--bg-card);
border: 1px solid var(--border);
color: var(--text-muted);
padding: 6px 12px;
border-radius: var(--radius);
font-size: 0.85rem;
font-weight: 500;
cursor: pointer;
display: flex;
align-items: center;
gap: 6px;
transition: all 0.15s ease;
}
.day-tab-btn:hover {
background: #f8fafc;
color: var(--text-main);
}
.day-tab-btn.active {
background: var(--primary);
border-color: var(--primary);
color: white;
}
.today-badge {
background: #fef3c7;
color: #b45309;
font-size: 0.7rem;
padding: 1px 4px;
border-radius: 3px;
font-weight: 600;
}
.day-tab-btn.active .today-badge {
background: rgba(255, 255, 255, 0.25);
color: white;
}
.day-count-badge {
background: #f1f5f9;
color: var(--text-muted);
font-size: 0.7rem;
padding: 1px 5px;
border-radius: 9999px;
}
.day-tab-btn.active .day-count-badge {
background: rgba(255, 255, 255, 0.2);
color: white;
}
.timetable-list {
display: flex;
flex-direction: column;
gap: 8px;
}
.timetable-row {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 12px 16px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.period-col {
display: flex;
flex-direction: column;
min-width: 90px;
}
.period-num {
font-weight: 700;
font-size: 0.95rem;
}
.period-time {
font-size: 0.78rem;
color: var(--text-muted);
}
.subject-col {
flex: 1;
}
.subject-title {
font-weight: 600;
font-size: 0.95rem;
color: var(--text-main);
}
.teacher-info {
display: flex;
align-items: center;
gap: 6px;
margin-top: 2px;
}
.teacher-thumb {
width: 20px;
height: 20px;
border-radius: 50%;
object-fit: cover;
}
.teacher-name {
font-size: 0.8rem;
color: var(--text-muted);
}
.station-badge {
background: #fef3c7;
color: #b45309;
font-size: 0.75rem;
font-weight: 700;
padding: 2px 8px;
border-radius: 4px;
border: 1px solid #fde68a;
}
.class-badge {
background: #f1f5f9;
color: var(--text-muted);
font-size: 0.75rem;
padding: 2px 8px;
border-radius: 4px;
}
.table-responsive {
overflow-x: auto;
}
.week-grid-table {
width: 100%;
border-collapse: collapse;
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
font-size: 0.825rem;
}
.week-grid-table th, .week-grid-table td {
border: 1px solid var(--border);
padding: 8px 10px;
text-align: left;
vertical-align: top;
}
.week-grid-table th {
background: #f8fafc;
font-weight: 600;
}
.grid-today-th {
background: #eff6ff !important;
color: var(--primary);
}
.grid-today-pill {
font-size: 0.68rem;
background: #dbeafe;
color: #1e40af;
padding: 1px 4px;
border-radius: 3px;
margin-left: 4px;
}
.grid-period-cell {
min-width: 80px;
background: #f8fafc;
}
.grid-period-title {
font-weight: 700;
}
.grid-period-time {
font-size: 0.725rem;
color: var(--text-muted);
}
.grid-lesson-cell {
min-width: 135px;
}
.grid-lesson-cell.has-lesson {
background: #ffffff;
}
.grid-lesson-subject {
font-weight: 600;
font-size: 0.825rem;
}
.grid-lesson-teacher {
font-size: 0.75rem;
color: var(--text-muted);
}
.grid-station-tag {
display: inline-block;
font-size: 0.68rem;
background: #fef3c7;
color: #b45309;
padding: 1px 4px;
border-radius: 3px;
margin-top: 3px;
}
.grid-empty-cell {
color: var(--text-light);
}

106
public/js/syllabus.js Normal file
View file

@ -0,0 +1,106 @@
document.addEventListener('DOMContentLoaded', () => {
const stationPills = document.getElementById('stationPills');
const viewTogglePills = document.getElementById('viewTogglePills');
const dayTabs = document.getElementById('dayTabs');
const dayViewContainer = document.getElementById('dayViewContainer');
const weekViewContainer = document.getElementById('weekViewContainer');
const btnSyncSyllabus = document.getElementById('btnSyncSyllabus');
const syllabusAlert = document.getElementById('syllabusAlert');
// 1. Station Pill Selection (AJAX)
if (stationPills) {
stationPills.addEventListener('click', async (e) => {
const btn = e.target.closest('.station-btn');
if (!btn) return;
const station = btn.dataset.station;
stationPills.querySelectorAll('.station-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
try {
const res = await fetch('/api/syllabus/station', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ station })
});
const data = await res.json();
if (data.success) {
// Fast reload to render both day & week grids accurately
window.location.reload();
}
} catch (err) {
console.error('Failed to change station:', err);
}
});
}
// 2. View Toggle (Day View vs Full Week Grid)
if (viewTogglePills) {
viewTogglePills.addEventListener('click', (e) => {
const btn = e.target.closest('.view-btn');
if (!btn) return;
const viewMode = btn.dataset.view;
viewTogglePills.querySelectorAll('.view-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
if (viewMode === 'day') {
if (dayViewContainer) dayViewContainer.classList.remove('hidden');
if (weekViewContainer) weekViewContainer.classList.add('hidden');
} else {
if (dayViewContainer) dayViewContainer.classList.add('hidden');
if (weekViewContainer) weekViewContainer.classList.remove('hidden');
}
});
}
// 3. Day Tabs Switching
if (dayTabs) {
dayTabs.addEventListener('click', (e) => {
const btn = e.target.closest('.day-tab-btn');
if (!btn) return;
const dayNumber = btn.dataset.day;
dayTabs.querySelectorAll('.day-tab-btn').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
// Hide all panels, show target panel
document.querySelectorAll('.day-schedule-panel').forEach(p => p.classList.add('hidden'));
const activePanel = document.getElementById(`panelDay${dayNumber}`);
if (activePanel) activePanel.classList.remove('hidden');
});
}
// 4. Sync Syllabus
if (btnSyncSyllabus) {
btnSyncSyllabus.addEventListener('click', async () => {
btnSyncSyllabus.disabled = true;
btnSyncSyllabus.textContent = 'Syncing...';
showAlert('Fetching weekly timetable across all 5 days...', 'info');
try {
const res = await fetch('/api/syllabus/sync', { method: 'POST' });
const data = await res.json();
if (data.success) {
showAlert('Syllabus updated successfully!', 'info');
window.location.reload();
} else {
showAlert(`Sync failed: ${data.error}`, 'danger');
btnSyncSyllabus.disabled = false;
btnSyncSyllabus.textContent = 'Sync Syllabus';
}
} catch (err) {
showAlert('Network error while syncing syllabus.', 'danger');
btnSyncSyllabus.disabled = false;
btnSyncSyllabus.textContent = 'Sync Syllabus';
}
});
}
function showAlert(msg, type = 'info') {
if (!syllabusAlert) return;
syllabusAlert.className = `alert alert-${type}`;
syllabusAlert.textContent = msg;
syllabusAlert.classList.remove('hidden');
}
});