Календарь: настройки первого дня и времени отображения, кружок сегодня

This commit is contained in:
dev
2026-11-28 13:09:40 +03:00
parent e5526617fe
commit c74042f297
10 changed files with 168 additions and 33 deletions
+56 -25
View File
@@ -2,7 +2,9 @@
'use strict';
const API = location.origin;
const CAL_WEEK_START = 1;
const CAL_WEEK_START_DEFAULT = 1;
const CAL_DAY_START_DEFAULT = 480;
const CAL_DAY_END_DEFAULT = 1260;
const HOUR_H = 56;
const VIEWS = ['day', 'week', 'month', 'agenda'];
const DOW_SHORT = ['вс', 'пн', 'вт', 'ср', 'чт', 'пт', 'сб'];
@@ -25,6 +27,9 @@
rangeFrom: '', rangeTo: '', grid: null, uidMap: new Map(), editor: null,
users: [], ownerFilter: '',
};
let calWeekStart = CAL_WEEK_START_DEFAULT;
let calDayStart = CAL_DAY_START_DEFAULT;
let calDayEnd = CAL_DAY_END_DEFAULT;
let nowTimer = null;
let drag = null;
@@ -104,7 +109,7 @@
function weekBounds(iso) {
const dow = isoDow(iso);
if (dow < 0) return { from: iso, to: iso };
const back = (dow - CAL_WEEK_START + 7) % 7;
const back = (dow - calWeekStart + 7) % 7;
return { from: isoAddDays(iso, -back), to: isoAddDays(iso, 6 - back) };
}
@@ -176,6 +181,27 @@
return `${String(Math.floor(n / 60)).padStart(2, '0')}:${String(n % 60).padStart(2, '0')}`;
}
function calMinute(value, fallback) {
const m = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(String(value ?? ''));
return m ? Number(m[1]) * 60 + Number(m[2]) : fallback;
}
async function loadCalendarSettings() {
try {
const res = await fetch(`${API}/api/public-settings`);
if (!res.ok) return;
const s = await res.json();
const week = Number(s.calendar_week_start);
if (Number.isInteger(week) && week >= 0 && week <= 6) calWeekStart = week;
calDayStart = calMinute(s.calendar_day_start, CAL_DAY_START_DEFAULT);
calDayEnd = calMinute(s.calendar_day_end, CAL_DAY_END_DEFAULT);
if (calDayEnd <= calDayStart) {
calDayStart = CAL_DAY_START_DEFAULT;
calDayEnd = CAL_DAY_END_DEFAULT;
}
} catch {}
}
function normalizedItems() {
const out = [];
if (!state.hidden.has('personal')) {
@@ -242,18 +268,18 @@
}
function visibleHours(perDay) {
let start = 7;
let end = 23;
let start = calDayStart;
let end = calDayEnd;
for (const segs of perDay) {
for (const seg of segs) {
if (seg.allDay) continue;
start = Math.min(start, Math.floor(seg.startMin / 60));
end = Math.max(end, Math.ceil(seg.endMin / 60));
start = Math.min(start, Math.floor(seg.startMin / 60) * 60);
end = Math.max(end, Math.ceil(seg.endMin / 60) * 60);
}
}
start = Math.max(0, Math.min(23, start));
end = Math.max(start + 1, Math.min(24, end));
return { start, end };
start = Math.max(0, Math.min(1410, start));
end = Math.min(1440, Math.max(start + 30, end));
return { startMin: start, endMin: end };
}
function layoutLanes(segs) {
@@ -303,7 +329,7 @@
}
function segmentHtml(seg, hours) {
const top = (seg.startMin - hours.start * 60) / 60 * HOUR_H;
const top = (seg.startMin - hours.startMin) / 60 * HOUR_H;
const height = Math.max(20, (seg.endMin - seg.startMin) / 60 * HOUR_H - 2);
const width = 100 / (seg.lanes || 1);
const left = (seg.lane || 0) * width;
@@ -324,8 +350,8 @@
function nowTop(hours) {
const min = toMinutes(nowHm());
if (min < hours.start * 60 || min > hours.end * 60) return null;
return Math.round((min - hours.start * 60) / 60 * HOUR_H);
if (min < hours.startMin || min > hours.endMin) return null;
return Math.round((min - hours.startMin) / 60 * HOUR_H);
}
function renderGrid(days) {
@@ -336,10 +362,11 @@
perDay.flat().forEach(seg => uidMap.set(seg.uid, seg));
state.uidMap = uidMap;
const hours = visibleHours(perDay);
const gridH = (hours.end - hours.start) * HOUR_H;
const gridH = (hours.endMin - hours.startMin) / 60 * HOUR_H;
const gridOffset = ((60 - hours.startMin % 60) % 60) / 60 * HOUR_H;
const today = todayIso();
const todayIndex = days.indexOf(today);
let html = `<div class="cal-grid" style="--cal-days:${days.length};--cal-grid-h:${gridH}px">`;
let html = `<div class="cal-grid" style="--cal-days:${days.length};--cal-grid-h:${gridH}px;--cal-grid-offset:${gridOffset}px">`;
html += '<div class="cal-corner"></div>';
days.forEach(iso => {
const dow = isoDow(iso);
@@ -352,8 +379,8 @@
html += '</div>';
});
html += '<div class="cal-gutter">';
for (let h = hours.start; h < hours.end; h++) {
html += `<div class="cal-hour-label" style="top:${(h - hours.start) * HOUR_H}px">${esc(fmtHmStr(`${String(h).padStart(2, '0')}:00`))}</div>`;
for (let min = Math.ceil(hours.startMin / 60) * 60; min < hours.endMin; min += 60) {
html += `<div class="cal-hour-label" style="top:${(min - hours.startMin) / 60 * HOUR_H}px">${esc(fmtHmStr(hmFromMinutes(min)))}</div>`;
}
const top = nowTop(hours);
if (top !== null) html += `<div class="cal-now-label" style="top:${top}px">${esc(fmtHmStr(nowHm()))}</div>`;
@@ -384,14 +411,15 @@
const today = todayIso();
let html = '<div class="cal-month-grid">';
for (let i = 0; i < 7; i++) {
const dow = (CAL_WEEK_START + i) % 7;
const dow = (calWeekStart + i) % 7;
html += `<div class="cal-month-dow${dow === 0 || dow === 6 ? ' weekend' : ''}">${DOW_SHORT[dow]}</div>`;
}
days.forEach(iso => {
const outer = iso.slice(0, 7) !== bounds.from.slice(0, 7);
const segs = daySegments(iso, all);
html += `<div class="cal-month-cell${outer ? ' outer' : ''}${iso === today ? ' is-today' : ''}" data-day="${iso}">`;
html += `<span class="cal-month-num" data-open-day="${iso}">${iso === bounds.from ? `${Number(iso.slice(8, 10))} ${esc(fmtMonthYearIso(iso).split(' ')[0])}` : Number(iso.slice(8, 10))}</span>`;
html += `<span class="cal-month-num" data-open-day="${iso}">${Number(iso.slice(8, 10))}</span>`;
if (iso === bounds.from) html += `<span class="cal-month-first" data-open-day="${iso}">${esc(fmtMonthYearIso(iso).split(' ')[0])}</span>`;
segs.slice(0, 3).forEach(seg => {
const time = seg.allDay ? '' : `${esc(fmtHmStr(hmFromMinutes(seg.startMin)))} `;
const cls = seg.source === 'personal' ? eventClass('cal-month-chip', seg) : 'cal-month-chip is-source';
@@ -403,7 +431,7 @@
});
html += '</div>';
document.getElementById('calBody').innerHTML = html;
state.grid = { days, hours: { start: 0, end: 24 }, gridH: 0, today };
state.grid = { days, hours: { startMin: 0, endMin: 1440 }, gridH: 0, today };
stopNowTick();
}
@@ -465,7 +493,7 @@
const first = weekBounds(bounds.from).from;
const today = todayIso();
let html = '';
for (let i = 0; i < 7; i++) html += `<div class="cal-mini-dow">${DOW_SHORT[(CAL_WEEK_START + i) % 7]}</div>`;
for (let i = 0; i < 7; i++) html += `<div class="cal-mini-dow">${DOW_SHORT[(calWeekStart + i) % 7]}</div>`;
for (let i = 0; i < 42; i++) {
const iso = isoAddDays(first, i);
const cls = [
@@ -530,8 +558,10 @@
function snapMinute(y, el) {
const rect = el.getBoundingClientRect();
const rel = Math.max(0, Math.min(state.grid.gridH, y - rect.top));
const raw = state.grid.hours.start * 60 + rel / HOUR_H * 60;
return Math.max(state.grid.hours.start * 60, Math.min(state.grid.hours.end * 60, Math.round(raw / 30) * 30));
const start = state.grid.hours.startMin;
const raw = start + rel / HOUR_H * 60;
const snapped = Math.round(raw / 30) * 30;
return Math.max(start, Math.min(state.grid.hours.endMin, snapped));
}
function removeGhost() {
@@ -569,7 +599,7 @@
drag.ghost.className = 'cal-drag';
drag.el.appendChild(drag.ghost);
}
const top = (from - state.grid.hours.start * 60) / 60 * HOUR_H;
const top = (from - state.grid.hours.startMin) / 60 * HOUR_H;
drag.ghost.style.top = `${top}px`;
drag.ghost.style.height = `${Math.max(12, (to - from) / 60 * HOUR_H)}px`;
});
@@ -581,9 +611,9 @@
let to = Math.max(d.startMin, d.endMin);
if (!d.moved) {
from = d.startMin;
to = Math.min(state.grid.hours.end * 60, from + 60);
to = Math.min(state.grid.hours.endMin, from + 60);
}
if (to - from < 30) to = Math.min(state.grid.hours.end * 60, from + 30);
if (to - from < 30) to = Math.min(state.grid.hours.endMin, from + 30);
cancelDrag();
openEditor({
dateStart: d.dayIso, timeStart: hmFromMinutes(from),
@@ -996,6 +1026,7 @@
async function init() {
if (!(await checkAuth())) return;
await loadCalendarSettings();
loadState();
await loadUsers();
buildSidebar(document.body.dataset.page);
+19 -2
View File
@@ -1,6 +1,6 @@
const DIRTY_FIELDS = ['systemName', 'timezone', 'timeFormat', 'spamInterval', 'footerLeft', 'footerRight', 'aiPrompt', 'aiAutoCheck', 'lessonAiPrompt', 'lessonAiEnabled', 'notesAiEnabled', 'shareShowMessage', 'shareShowDate', 'shareShowNames', 'shareShowPhotos', 'cookieNoticeText', 'photoResolution', 'photoQuality', 'photoEngine', 'camEnabled', 'photoAiFaceMode', 'photoAiFaceModel', 'photoAiDevicePref', 'trashPurgeDays', 'notifyEnabled', 'notifyRetentionDays', 'imgbbUrl', 'imgbbKey', 'facesBrokenScanEnabled', 'facesBrokenScanInterval'];
const DIRTY_FIELDS = ['systemName', 'timezone', 'timeFormat', 'calWeekStart', 'calDayStart', 'calDayEnd', 'spamInterval', 'footerLeft', 'footerRight', 'aiPrompt', 'aiAutoCheck', 'lessonAiPrompt', 'lessonAiEnabled', 'notesAiEnabled', 'shareShowMessage', 'shareShowDate', 'shareShowNames', 'shareShowPhotos', 'cookieNoticeText', 'photoResolution', 'photoQuality', 'photoEngine', 'camEnabled', 'photoAiFaceMode', 'photoAiFaceModel', 'photoAiDevicePref', 'trashPurgeDays', 'notifyEnabled', 'notifyRetentionDays', 'imgbbUrl', 'imgbbKey', 'facesBrokenScanEnabled', 'facesBrokenScanInterval'];
const NOTIFY_IDS = [];
const SECTION_IDS = ['sec-system', 'sec-stack', 'sec-brand', 'sec-datetime', 'sec-antispam', 'sec-share', 'sec-ai', 'sec-lesson-ai', 'sec-notes-ai', 'sec-achievements', 'sec-tls', 'sec-backup', 'sec-trash', 'sec-form', 'sec-notify', 'sec-photo', 'sec-photo-ai', 'sec-external-services', 'sec-bans', 'sec-face-broken'];
const SECTION_IDS = ['sec-system', 'sec-stack', 'sec-brand', 'sec-datetime', 'sec-calendar', 'sec-antispam', 'sec-share', 'sec-ai', 'sec-lesson-ai', 'sec-notes-ai', 'sec-achievements', 'sec-tls', 'sec-backup', 'sec-trash', 'sec-form', 'sec-notify', 'sec-photo', 'sec-photo-ai', 'sec-external-services', 'sec-bans', 'sec-face-broken'];
const SPAM_MAX = 10080;
const BAN_REASONS = {
'honeypot': 'Антиспам-поле',
@@ -297,6 +297,13 @@ async function loadSettings() {
const storedTz = String(s.timezone || '');
tzSel.value = Array.from(tzSel.options).some(o => o.value === storedTz) ? storedTz : DateTime.tz;
document.getElementById('timeFormat').value = ['24h', '12h'].includes(s.time_format) ? s.time_format : '24h';
const calWeekStart = String(s.calendar_week_start ?? '');
document.getElementById('calWeekStart').value = /^[0-6]$/.test(calWeekStart) ? calWeekStart : '1';
const calTimeRe = /^([01]\d|2[0-3]):[0-5]\d$/;
const calStart = String(s.calendar_day_start ?? '');
const calEnd = String(s.calendar_day_end ?? '');
document.getElementById('calDayStart').value = calTimeRe.test(calStart) ? calStart : '08:00';
document.getElementById('calDayEnd').value = calTimeRe.test(calEnd) ? calEnd : '21:00';
renderTimePreview();
document.getElementById('footerLeft').value = s.footer_left || '';
document.getElementById('footerRight').value = s.footer_right || '';
@@ -914,6 +921,13 @@ async function saveSettings() {
showError('Проверьте поле «Хранение уведомлений» (от 1 до 365 дней)');
return;
}
const calStart = document.getElementById('calDayStart').value;
const calEnd = document.getElementById('calDayEnd').value;
const calTimeRe = /^([01]\d|2[0-3]):[0-5]\d$/;
if (!calTimeRe.test(calStart) || !calTimeRe.test(calEnd) || calStart >= calEnd) {
showError('Проверьте время отображения календаря: начало должно быть раньше окончания');
return;
}
const fbInterval = document.getElementById('facesBrokenScanInterval').value;
const fbIntervalHours = Math.round(Number(fbInterval));
if (fbInterval === '' || !Number.isFinite(fbIntervalHours) || fbIntervalHours < 1 || fbIntervalHours > 168) {
@@ -931,6 +945,9 @@ async function saveSettings() {
system_name: document.getElementById('systemName').value.trim(),
timezone: document.getElementById('timezone').value,
time_format: document.getElementById('timeFormat').value,
calendar_week_start: document.getElementById('calWeekStart').value,
calendar_day_start: calStart,
calendar_day_end: calEnd,
spam_interval_min: String(Math.round(Number(v))),
footer_left: document.getElementById('footerLeft').value.trim(),
footer_right: document.getElementById('footerRight').value.trim(),