Add Private Lessons (Özel Ders İstek) page and advisory teacher filtering in Syllabus

This commit is contained in:
tyuXX 2026-10-21 19:22:21 +00:00
parent 573a249580
commit 455baa6aa4
11 changed files with 1489 additions and 9 deletions

View file

@ -1065,3 +1065,385 @@ code {
.grid-empty-cell {
color: var(--text-light);
}
/* ---------------- Advisor Pill (Syllabus) ---------------- */
.advisor-row {
display: flex;
align-items: center;
gap: 8px;
}
.advisor-pill {
display: inline-flex;
align-items: center;
gap: 6px;
background: #f1f5f9;
border: 1px solid #e2e8f0;
padding: 3px 10px;
border-radius: 9999px;
font-size: 0.775rem;
}
.advisor-name {
font-weight: 600;
color: var(--text-main);
}
.advisor-sub {
color: var(--text-muted);
font-size: 0.7rem;
background: #e2e8f0;
padding: 1px 6px;
border-radius: 4px;
}
/* ---------------- Private Lessons (Özel Ders) ---------------- */
.student-profile-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 14px 18px;
margin-bottom: 16px;
display: flex;
flex-direction: column;
gap: 12px;
}
.student-profile-main {
display: flex;
align-items: center;
gap: 14px;
}
.student-avatar {
width: 52px;
height: 52px;
border-radius: 50%;
object-fit: cover;
border: 2px solid var(--border);
}
.student-meta {
display: flex;
flex-direction: column;
gap: 2px;
}
.student-name {
font-size: 1.05rem;
font-weight: 700;
margin: 0;
}
.student-school {
font-size: 0.8rem;
color: var(--text-muted);
margin: 0;
}
.student-advisor-badge {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 0.775rem;
margin-top: 4px;
}
.advisor-badge-label {
color: var(--text-muted);
}
.student-policy-note {
display: flex;
align-items: flex-start;
gap: 8px;
font-size: 0.775rem;
color: #92400e;
background: #fef3c7;
padding: 8px 12px;
border-radius: 6px;
border-left: 3px solid #f59e0b;
}
.policy-icon {
font-weight: 700;
}
/* Request Form */
.request-form-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 18px 20px;
margin-bottom: 20px;
}
.form-card-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
padding-bottom: 10px;
border-bottom: 1px solid var(--border);
}
.form-header-badge {
font-size: 0.725rem;
font-weight: 600;
background: #e0f2fe;
color: #0369a1;
padding: 2px 8px;
border-radius: 4px;
}
.form-grid-3 {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 14px;
margin-bottom: 16px;
}
.form-group {
display: flex;
flex-direction: column;
gap: 6px;
}
.form-label {
font-size: 0.8rem;
font-weight: 600;
color: var(--text-main);
display: flex;
align-items: center;
justify-content: space-between;
}
.select-loading {
font-size: 0.7rem;
font-weight: 400;
color: var(--primary);
}
.form-select {
padding: 8px 12px;
border: 1px solid var(--border);
border-radius: var(--radius);
background: #ffffff;
color: var(--text-main);
font-size: 0.875rem;
font-family: inherit;
transition: border-color 0.15s ease;
}
.form-select:focus {
outline: none;
border-color: var(--primary);
box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.08);
}
.form-select:disabled {
background: #f8fafc;
color: var(--text-light);
cursor: not-allowed;
}
.form-actions-row {
display: flex;
justify-content: flex-end;
}
.form-feedback {
margin-top: 12px;
padding: 10px 14px;
border-radius: var(--radius);
font-size: 0.825rem;
font-weight: 500;
}
.feedback-success {
background: #dcfce7;
color: #15803d;
border: 1px solid #bbf7d0;
}
.feedback-error {
background: #fee2e2;
color: #b91c1c;
border: 1px solid #fecaca;
}
/* Lessons List & Grid */
.lessons-section {
display: flex;
flex-direction: column;
gap: 18px;
}
.lessons-header-row {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 10px;
}
.lessons-title-wrap {
display: flex;
align-items: center;
gap: 8px;
}
.lessons-count-badge {
background: #f1f5f9;
color: var(--text-muted);
font-size: 0.75rem;
font-weight: 700;
padding: 2px 7px;
border-radius: 9999px;
}
.subject-filter-pills {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 6px;
}
.subject-pill-btn {
font-family: inherit;
font-size: 0.725rem;
font-weight: 600;
padding: 3px 10px;
border-radius: 9999px;
background: #f1f5f9;
color: var(--text-muted);
border: 1px solid transparent;
cursor: pointer;
transition: all 0.15s ease;
}
.subject-pill-btn:hover {
background: #e2e8f0;
color: var(--text-main);
}
.subject-pill-btn.active {
background: var(--text-main);
color: #ffffff;
}
.upcoming-lessons-group,
.past-lessons-group {
display: flex;
flex-direction: column;
gap: 10px;
}
.group-header {
display: flex;
align-items: center;
gap: 8px;
padding-bottom: 4px;
}
.group-title {
font-size: 0.85rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.03em;
color: var(--text-muted);
}
.lessons-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
gap: 12px;
}
.lesson-card {
background: var(--bg-card);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 12px 14px;
display: flex;
flex-direction: column;
gap: 10px;
transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.lesson-card:hover {
transform: translateY(-1px);
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}
.lesson-card.is-upcoming {
border-left: 3px solid var(--success);
}
.lesson-card-header {
display: flex;
align-items: center;
justify-content: space-between;
}
.lesson-date {
font-size: 0.775rem;
font-weight: 600;
color: var(--text-muted);
}
.lesson-card-body {
display: flex;
align-items: center;
gap: 10px;
}
.lesson-teacher-photo {
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
border: 1px solid var(--border);
}
.lesson-teacher-placeholder {
width: 40px;
height: 40px;
border-radius: 50%;
background: #f1f5f9;
color: var(--text-muted);
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 1rem;
}
.lesson-info {
display: flex;
flex-direction: column;
gap: 2px;
}
.lesson-subject {
font-size: 0.95rem;
font-weight: 700;
margin: 0;
color: var(--text-main);
}
.lesson-teacher {
font-size: 0.8rem;
color: var(--text-muted);
margin: 0;
}
.empty-lessons-card {
background: var(--bg-card);
border: 1px dashed var(--border);
border-radius: var(--radius);
padding: 24px;
text-align: center;
color: var(--text-muted);
font-size: 0.875rem;
}

View file

@ -0,0 +1,219 @@
document.addEventListener('DOMContentLoaded', () => {
const selectCourse = document.getElementById('selectCourse');
const selectUnit = document.getElementById('selectUnit');
const selectTopic = document.getElementById('selectTopic');
const unitLoading = document.getElementById('unitLoading');
const topicLoading = document.getElementById('topicLoading');
const btnSubmit = document.getElementById('btnSubmitRequest');
const form = document.getElementById('privateLessonForm');
const formFeedback = document.getElementById('formFeedback');
const btnSync = document.getElementById('btnSyncPrivateLessons');
const alertBox = document.getElementById('privateLessonsAlert');
const subjectPills = document.querySelectorAll('.subject-pill-btn');
const lessonCards = document.querySelectorAll('.lesson-card');
const sinifIdInput = document.getElementById('sinifId');
function showAlert(message, type = 'info', timeout = 4000) {
if (!alertBox) return;
alertBox.className = `alert alert-${type}`;
alertBox.textContent = message;
alertBox.classList.remove('hidden');
if (timeout > 0) {
setTimeout(() => {
alertBox.classList.add('hidden');
}, timeout);
}
}
function showFeedback(message, type = 'success') {
if (!formFeedback) return;
formFeedback.className = `form-feedback feedback-${type}`;
formFeedback.textContent = message;
formFeedback.classList.remove('hidden');
}
function hideFeedback() {
if (formFeedback) formFeedback.classList.add('hidden');
}
// 1. Course changed -> Load Units
if (selectCourse) {
selectCourse.addEventListener('change', async () => {
hideFeedback();
const dersId = selectCourse.value;
const sinifId = sinifIdInput ? sinifIdInput.value : '';
selectUnit.innerHTML = '<option value="">Önce ders seçiniz...</option>';
selectUnit.disabled = true;
selectTopic.innerHTML = '<option value="">Önce ünite seçiniz...</option>';
selectTopic.disabled = true;
if (btnSubmit) btnSubmit.disabled = true;
if (!dersId) return;
if (unitLoading) unitLoading.classList.remove('hidden');
try {
const res = await fetch(`/api/private-lessons/units?dersId=${encodeURIComponent(dersId)}&sinifId=${encodeURIComponent(sinifId)}`);
const data = await res.json();
if (data.success && data.units && data.units.length > 0) {
selectUnit.innerHTML = '<option value="">Seçiniz...</option>' +
data.units.map(u => `<option value="${u.id}">${u.name}</option>`).join('');
selectUnit.disabled = false;
} else {
selectUnit.innerHTML = '<option value="">Ünite bulunamadı</option>';
}
} catch (err) {
console.error('Error fetching units:', err);
selectUnit.innerHTML = '<option value="">Hata oluştu</option>';
} finally {
if (unitLoading) unitLoading.classList.add('hidden');
}
});
}
// 2. Unit changed -> Load Topics
if (selectUnit) {
selectUnit.addEventListener('change', async () => {
hideFeedback();
const uniteId = selectUnit.value;
selectTopic.innerHTML = '<option value="">Önce ünite seçiniz...</option>';
selectTopic.disabled = true;
if (btnSubmit) btnSubmit.disabled = true;
if (!uniteId) return;
if (topicLoading) topicLoading.classList.remove('hidden');
try {
const res = await fetch(`/api/private-lessons/topics?uniteId=${encodeURIComponent(uniteId)}`);
const data = await res.json();
if (data.success && data.topics && data.topics.length > 0) {
selectTopic.innerHTML = '<option value="">Seçiniz...</option>' +
data.topics.map(t => `<option value="${t.id}">${t.name}</option>`).join('');
selectTopic.disabled = false;
} else {
selectTopic.innerHTML = '<option value="">Konu bulunamadı</option>';
}
} catch (err) {
console.error('Error fetching topics:', err);
selectTopic.innerHTML = '<option value="">Hata oluştu</option>';
} finally {
if (topicLoading) topicLoading.classList.add('hidden');
}
});
}
// 3. Topic changed -> Enable Submit
if (selectTopic) {
selectTopic.addEventListener('change', () => {
hideFeedback();
const hasValue = Boolean(selectTopic.value);
if (btnSubmit) btnSubmit.disabled = !hasValue;
});
}
// 4. Form Submit
if (form) {
form.addEventListener('submit', async (e) => {
e.preventDefault();
hideFeedback();
const ogrenciDonemId = document.getElementById('ogrenciDonemId')?.value || '';
const okulId = document.getElementById('okulId')?.value || '';
const sinifId = document.getElementById('sinifId')?.value || '';
const dersId = selectCourse.value;
const uniteId = selectUnit.value;
const konuId = selectTopic.value;
if (!dersId || !uniteId || !konuId) {
showFeedback('Lütfen ders, ünite ve konu seçimlerini tamamlayınız.', 'error');
return;
}
if (btnSubmit) {
btnSubmit.disabled = true;
btnSubmit.textContent = 'Gönderiliyor...';
}
try {
const res = await fetch('/api/private-lessons/request', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ogrenciDonemId, okulId, sinifId, dersId, uniteId, konuId })
});
const data = await res.json();
if (data.success) {
showFeedback(data.message || 'Özel ders talebiniz başarıyla iletildi!', 'success');
// Reset select elements
selectTopic.innerHTML = '<option value="">Önce ünite seçiniz...</option>';
selectTopic.disabled = true;
selectUnit.innerHTML = '<option value="">Önce ders seçiniz...</option>';
selectUnit.disabled = true;
selectCourse.value = '';
} else {
showFeedback(data.message || 'Talep iletilemedi. Lütfen tekrar deneyiniz.', 'error');
}
} catch (err) {
console.error('Request error:', err);
showFeedback('Bağlantı hatası oluştu. Lütfen tekrar deneyiniz.', 'error');
} finally {
if (btnSubmit) {
btnSubmit.textContent = 'Submit Request (Gönder)';
}
}
});
}
// 5. Subject Filter Pills
subjectPills.forEach(pill => {
pill.addEventListener('click', () => {
const targetSubject = pill.dataset.subject;
subjectPills.forEach(p => p.classList.remove('active'));
pill.classList.add('active');
lessonCards.forEach(card => {
const cardSubject = card.dataset.subject;
if (targetSubject === 'all' || cardSubject === targetSubject) {
card.style.display = '';
} else {
card.style.display = 'none';
}
});
});
});
// 6. Sync Lessons
if (btnSync) {
btnSync.addEventListener('click', async () => {
btnSync.disabled = true;
btnSync.textContent = 'Syncing...';
try {
const res = await fetch('/api/private-lessons/sync', { method: 'POST' });
const data = await res.json();
if (data.success) {
showAlert(`Successfully refreshed ${data.count} private lesson records.`, 'success');
setTimeout(() => {
window.location.reload();
}, 800);
} else {
showAlert(data.error || 'Sync failed.', 'danger');
}
} catch (err) {
showAlert('Network error while syncing private lessons.', 'danger');
} finally {
btnSync.disabled = false;
btnSync.textContent = 'Sync Lessons';
}
});
}
});