Initial commit: Schedule service for son
This commit is contained in:
commit
af2ea7be06
19 changed files with 2270 additions and 0 deletions
123
frontend/public/static/script.js
Normal file
123
frontend/public/static/script.js
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
const TZ = 'Europe/London';
|
||||
|
||||
function formatDate(dateStr) {
|
||||
const date = new Date(dateStr + 'T00:00:00');
|
||||
// getDay() возвращает 0=воскресенье, 1=понедельник, ..., 6=суббота
|
||||
// Конвертируем в формат где 0=понедельник
|
||||
const jsDay = date.getDay();
|
||||
const weekdayIndex = jsDay === 0 ? 6 : jsDay - 1; // 0=пн, 6=вс
|
||||
const weekdays = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'];
|
||||
const months = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня',
|
||||
'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'];
|
||||
|
||||
const weekday = weekdays[weekdayIndex];
|
||||
const day = date.getDate();
|
||||
const month = months[date.getMonth()];
|
||||
|
||||
return `${weekday}, ${day} ${month}`;
|
||||
}
|
||||
|
||||
function getTodayInLondon() {
|
||||
// Получаем текущую дату в таймзоне London
|
||||
const now = new Date();
|
||||
const formatter = new Intl.DateTimeFormat('en-CA', {
|
||||
timeZone: 'Europe/London',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit'
|
||||
});
|
||||
return formatter.format(now);
|
||||
}
|
||||
|
||||
function getTomorrowInLondon() {
|
||||
const today = getTodayInLondon();
|
||||
const date = new Date(today);
|
||||
date.setDate(date.getDate() + 1);
|
||||
return date.toISOString().split('T')[0];
|
||||
}
|
||||
|
||||
function renderDay(container, titleEl, dateStr, items) {
|
||||
titleEl.textContent = formatDate(dateStr);
|
||||
|
||||
const tasks = items.filter(item => item.kind === 'task');
|
||||
const events = items.filter(item => item.kind === 'event');
|
||||
|
||||
let html = '';
|
||||
|
||||
if (tasks.length > 0) {
|
||||
html += '<div class="tasks-list">';
|
||||
tasks.forEach(task => {
|
||||
html += `<div class="task-item">• ${task.title}</div>`;
|
||||
});
|
||||
html += '</div>';
|
||||
}
|
||||
|
||||
if (events.length > 0) {
|
||||
html += '<div class="events-list">';
|
||||
events.sort((a, b) => a.start_time.localeCompare(b.start_time)).forEach(event => {
|
||||
const endTime = calculateEndTime(event.start_time, event.duration_min);
|
||||
html += `<div class="event-item">
|
||||
<span class="event-time">${event.start_time}-${endTime}</span>
|
||||
<span class="event-title">${event.title}</span>
|
||||
</div>`;
|
||||
});
|
||||
html += '</div>';
|
||||
}
|
||||
|
||||
if (tasks.length === 0 && events.length === 0) {
|
||||
html = '<div class="empty-message">На этот день расписания нет.</div>';
|
||||
}
|
||||
|
||||
container.innerHTML = html;
|
||||
}
|
||||
|
||||
function calculateEndTime(startTime, durationMin) {
|
||||
const [hour, minute] = startTime.split(':').map(Number);
|
||||
const totalMinutes = hour * 60 + minute + durationMin;
|
||||
const endHour = Math.floor(totalMinutes / 60);
|
||||
const endMinute = totalMinutes % 60;
|
||||
return `${String(endHour).padStart(2, '0')}:${String(endMinute).padStart(2, '0')}`;
|
||||
}
|
||||
|
||||
async function loadSchedule() {
|
||||
const today = getTodayInLondon();
|
||||
const tomorrow = getTomorrowInLondon();
|
||||
|
||||
console.log('Loading schedule from', today, 'to', tomorrow);
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/schedule?from_date=${today}&to_date=${tomorrow}`);
|
||||
const data = await response.json();
|
||||
|
||||
console.log('Received items:', data.items);
|
||||
|
||||
const todayItems = data.items.filter(item => item.date === today);
|
||||
const tomorrowItems = data.items.filter(item => item.date === tomorrow);
|
||||
|
||||
console.log('Today items:', todayItems);
|
||||
console.log('Tomorrow items:', tomorrowItems);
|
||||
|
||||
renderDay(
|
||||
document.getElementById('today-content'),
|
||||
document.getElementById('today-title'),
|
||||
today,
|
||||
todayItems
|
||||
);
|
||||
|
||||
renderDay(
|
||||
document.getElementById('tomorrow-content'),
|
||||
document.getElementById('tomorrow-title'),
|
||||
tomorrow,
|
||||
tomorrowItems
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error loading schedule:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Загружаем расписание при загрузке страницы
|
||||
loadSchedule();
|
||||
|
||||
// Автообновление каждые 5 минут
|
||||
setInterval(loadSchedule, 5 * 60 * 1000);
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue