redisign and bug fix

This commit is contained in:
vrubelroman 2026-03-22 12:48:20 +03:00
parent a18b5ad1ce
commit 8542ce8e01
10 changed files with 1622 additions and 1169 deletions

View file

@ -4,22 +4,33 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Расписание</title>
<link rel="stylesheet" href="/static/style.css">
<link rel="stylesheet" href="/static/style.css?v=3">
</head>
<body>
<div class="container">
<div id="today-section" class="day-section">
<h1 class="day-title" id="today-title">Сегодня</h1>
<div id="today-content"></div>
</div>
<div id="tomorrow-section" class="day-section">
<h1 class="day-title" id="tomorrow-title">Завтра</h1>
<div id="tomorrow-content"></div>
</div>
</div>
<script src="/static/script.js?v=2"></script>
<main class="board">
<section class="board-hero">
<p class="board-label">Сегодня и завтра</p>
<h1>Расписание на ближайшие дни</h1>
<p class="board-copy">Задачи отображаются сверху, занятия ниже по времени. Данные обновляются автоматически каждые пять минут.</p>
</section>
<section class="days-grid">
<article id="today-section" class="day-panel">
<div class="panel-head">
<h2 class="day-title" id="today-title">Сегодня</h2>
</div>
<div id="today-content"></div>
</article>
<article id="tomorrow-section" class="day-panel">
<div class="panel-head">
<h2 class="day-title" id="tomorrow-title">Завтра</h2>
</div>
<div id="tomorrow-content"></div>
</article>
</section>
</main>
<script src="/static/script.js?v=3"></script>
</body>
</html>

View file

@ -1,88 +1,35 @@
const TZ = 'Europe/Moscow';
const MOSCOW_TIMEZONE = 'Europe/Moscow';
const WEEKDAYS = ['Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота', 'Воскресенье'];
const MONTHS = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'];
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 getTodayInMoscow() {
// Получаем текущую дату в таймзоне Moscow
const now = new Date();
function getMoscowDateString() {
const formatter = new Intl.DateTimeFormat('en-CA', {
timeZone: 'Europe/Moscow',
timeZone: MOSCOW_TIMEZONE,
year: 'numeric',
month: '2-digit',
day: '2-digit'
});
return formatter.format(now);
return formatter.format(new Date());
}
function getTomorrowInLondon() {
const today = getTodayInMoscow();
const date = new Date(today);
date.setDate(date.getDate() + 1);
return date.toISOString().split('T')[0];
function parseISODate(value) {
const [year, month, day] = value.split('-').map(Number);
return new Date(year, month - 1, day);
}
function renderDay(container, titleEl, dateStr, items, isToday = false, isTomorrow = false) {
let titleText = formatDate(dateStr);
if (isToday) {
// Преобразуем "Вторник, 30 декабря" в "Сегодня вторник, 30 декабря"
const parts = titleText.split(', ');
if (parts.length === 2) {
titleText = `Сегодня ${parts[0].toLowerCase()}, ${parts[1]}`;
}
} else if (isTomorrow) {
// Преобразуем "Среда, 31 декабря" в "Завтра среда, 31 декабря"
const parts = titleText.split(', ');
if (parts.length === 2) {
titleText = `Завтра ${parts[0].toLowerCase()}, ${parts[1]}`;
}
}
titleEl.textContent = titleText;
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 formatISODate(date) {
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`;
}
function addDays(dateStr, days) {
const date = parseISODate(dateStr);
date.setDate(date.getDate() + days);
return formatISODate(date);
}
function formatDate(dateStr) {
const date = parseISODate(dateStr);
return `${WEEKDAYS[(date.getDay() + 6) % 7]}, ${date.getDate()} ${MONTHS[date.getMonth()]}`;
}
function calculateEndTime(startTime, durationMin) {
@ -93,49 +40,79 @@ function calculateEndTime(startTime, durationMin) {
return `${String(endHour).padStart(2, '0')}:${String(endMinute).padStart(2, '0')}`;
}
async function loadSchedule() {
const today = getTodayInMoscow();
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,
true, // isToday
false
);
renderDay(
document.getElementById('tomorrow-content'),
document.getElementById('tomorrow-title'),
tomorrow,
tomorrowItems,
false,
true // isTomorrow
);
} catch (error) {
console.error('Error loading schedule:', error);
function renderDay(container, titleEl, dateStr, items, options = {}) {
let titleText = formatDate(dateStr);
if (options.today) {
titleText = `Сегодня, ${titleText.toLowerCase()}`;
} else if (options.tomorrow) {
titleText = `Завтра, ${titleText.toLowerCase()}`;
}
titleEl.textContent = titleText;
const tasks = items.filter((item) => item.kind === 'task');
const events = items
.filter((item) => item.kind === 'event')
.sort((a, b) => a.start_time.localeCompare(b.start_time));
if (!tasks.length && !events.length) {
container.innerHTML = '<div class="empty-message">На этот день расписания нет.</div>';
return;
}
const tasksHtml = tasks.length ? `
<div class="tasks-list">
${tasks.map((task) => `<div class="task-item">${task.repeat_weekly ? 'Каждую неделю: ' : ''}${escapeHtml(task.title)}</div>`).join('')}
</div>
` : '';
const eventsHtml = events.length ? `
<div class="events-list">
${events.map((event) => `
<div class="event-item">
<span class="event-time">${event.start_time}-${calculateEndTime(event.start_time, event.duration_min)}</span>
<span class="event-title">${escapeHtml(event.title)}</span>
</div>
`).join('')}
</div>
` : '';
container.innerHTML = `${tasksHtml}${eventsHtml}`;
}
// Загружаем расписание при загрузке страницы
loadSchedule();
function escapeHtml(value) {
return String(value)
.replaceAll('&', '&amp;')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
.replaceAll("'", '&#39;');
}
// Автообновление каждые 5 минут
setInterval(loadSchedule, 5 * 60 * 1000);
async function loadSchedule() {
const today = getMoscowDateString();
const tomorrow = addDays(today, 1);
const response = await fetch(`/api/schedule?from_date=${today}&to_date=${tomorrow}`);
if (!response.ok) {
throw new Error('Не удалось загрузить расписание');
}
const data = await response.json();
renderDay(
document.getElementById('today-content'),
document.getElementById('today-title'),
today,
data.items.filter((item) => item.date === today),
{ today: true }
);
renderDay(
document.getElementById('tomorrow-content'),
document.getElementById('tomorrow-title'),
tomorrow,
data.items.filter((item) => item.date === tomorrow),
{ tomorrow: true }
);
}
loadSchedule().catch((error) => console.error(error));
setInterval(() => loadSchedule().catch((error) => console.error(error)), 5 * 60 * 1000);

View file

@ -1,100 +1,153 @@
:root {
--bg: #f4efe8;
--panel: rgba(255, 251, 246, 0.9);
--text: #1f2937;
--muted: #6b7280;
--task: #166534;
--event: #0f766e;
--line: rgba(123, 92, 62, 0.18);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: #f5f5f5;
padding: 20px;
font-size: 24px;
line-height: 1.6;
min-height: 100vh;
font-family: Georgia, "Times New Roman", serif;
color: var(--text);
background:
radial-gradient(circle at top left, rgba(245, 158, 11, 0.16), transparent 28%),
radial-gradient(circle at bottom right, rgba(15, 118, 110, 0.14), transparent 22%),
linear-gradient(180deg, #faf4eb 0%, #efe4d2 100%);
padding: 24px;
}
.container {
max-width: 1200px;
.board {
max-width: 1440px;
margin: 0 auto;
}
.day-section {
background: white;
border-radius: 12px;
padding: 30px;
margin-bottom: 30px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
.board-hero,
.day-panel {
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.6);
box-shadow: 0 18px 45px rgba(101, 67, 33, 0.12);
backdrop-filter: blur(14px);
}
.board-hero {
border-radius: 28px;
padding: 28px;
margin-bottom: 20px;
}
.board-label {
text-transform: uppercase;
letter-spacing: 0.18em;
font-size: 12px;
color: #92400e;
margin-bottom: 10px;
}
.board-hero h1 {
font-size: clamp(34px, 5vw, 62px);
line-height: 0.95;
margin-bottom: 12px;
}
.board-copy {
max-width: 780px;
color: var(--muted);
font-size: 22px;
line-height: 1.4;
}
.days-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 20px;
}
.day-panel {
border-radius: 28px;
padding: 28px;
}
.panel-head {
border-bottom: 1px solid var(--line);
padding-bottom: 16px;
margin-bottom: 18px;
}
.day-title {
font-size: 36px;
font-weight: 600;
color: #333;
margin-bottom: 20px;
padding-bottom: 15px;
border-bottom: 3px solid #4CAF50;
line-height: 1.1;
}
.tasks-list,
.events-list {
display: flex;
flex-direction: column;
gap: 12px;
}
.tasks-list {
margin-bottom: 30px;
margin-bottom: 18px;
}
.task-item,
.event-item,
.empty-message {
border-radius: 18px;
padding: 16px 18px;
}
.task-item {
background: rgba(22, 101, 52, 0.08);
border: 1px solid rgba(22, 101, 52, 0.14);
font-size: 28px;
padding: 15px 0;
color: #555;
border-bottom: 1px solid #eee;
}
.task-item:last-child {
border-bottom: none;
}
.events-list {
margin-top: 20px;
}
.event-item {
display: grid;
grid-template-columns: 160px 1fr;
gap: 14px;
background: rgba(15, 118, 110, 0.08);
border: 1px solid rgba(15, 118, 110, 0.14);
font-size: 28px;
padding: 15px 0;
color: #333;
border-bottom: 1px solid #eee;
display: flex;
align-items: center;
gap: 15px;
}
.event-item:last-child {
border-bottom: none;
align-items: start;
}
.event-time {
font-weight: 600;
color: #4CAF50;
min-width: 120px;
}
.event-title {
flex: 1;
color: var(--event);
font-weight: 700;
}
.empty-message {
color: #999;
font-style: italic;
padding: 20px 0;
color: var(--muted);
border: 1px dashed var(--line);
font-size: 24px;
}
@media (max-width: 768px) {
body {
font-size: 20px;
padding: 15px;
@media (max-width: 900px) {
.days-grid {
grid-template-columns: 1fr;
}
.day-title {
font-size: 28px;
}
.task-item, .event-item {
font-size: 22px;
.board-copy,
.task-item,
.event-item {
font-size: 20px;
}
.event-item {
grid-template-columns: 1fr;
}
}