calendar
All repositories: gitoria
5.2 KB
// lib/events-helpers.hl — what lib/events.hl looks up (calendar mission 001, code order): the size limits, what the// page sends → a WorldAPI Event record (build), a stored event → what the page shows (viewOf), the temporary ids of// events made offline, the window check of the faces and the order by start.import { isText, isDate, isTime, isZone, nextDay, prevDay, before } from '../components/month-view/dates.hl'import { envOr } from './util.hl'import { toReminders, toRows } from '../components/month-view/reminders.hl'static maxTitle = 200static maxPlace = 200static maxNotes = 5000// events per user (security mission SC: a signed-in user could fill the disk): CALENDAR_MAX_EVENTSstatic maxEvents = toNumber(envOr('CALENDAR_MAX_EVENTS', '20000'))// what the page sends: { id?, custom, reminders (rows), title, allDay, startDate, startTime, endDate, endTime, place, notes, zone }// → { error } or { record } (a WorldAPI Event without owner/id). endDate/endTime may be empty (no end); all-day: the// last day, inclusive ('' = one day).static build = (b) => {if (b == null || hlTypeName(b) != 'Hybrid') { return { error = 'the event must be an object' } }if (!isText(b.title) || b.title.trim() == '') { return { error = 'the event needs a title' } }if (b.title.length > maxTitle) { return { error = 'the title is too long (at most ' + maxTitle + ' characters)' } }if (!isText(b.place) || b.place.length > maxPlace) { return { error = 'the place is too long (at most ' + maxPlace + ' characters)' } }if (!isText(b.notes) || b.notes.length > maxNotes) { return { error = 'the notes are too long (at most ' + maxNotes + ' characters)' } }if (b.allDay != true && b.allDay != false) { return { error = 'allDay must be true or false' } }if (!isDate(b.startDate)) { return { error = 'the start date is not a date' } }if (!isZone(b.zone)) { return { error = 'the time zone is missing' } }r = {}r['$type'] = 'event'r['$version'] = 1r['$title'] = b.title.trim()if (b.notes.trim() != '') { r['$description'] = b.notes }if (b.place.trim() != '') { r['$location'] = b.place.trim() }r['$status'] = 'confirmed'r['$visibility'] = 'private'// no own reminders: `$reminders` stays out and the calendar's apply; own ones (also none at all) are writtenif (b.custom == true) {rem = toReminders(b.reminders)if (rem.error != null) { return { error = rem.error } }r['$reminders'] = rem.reminders}if (b.allDay) {r['$kind'] = 'allday'r['$start'] = b.startDateif (isText(b.endDate) && b.endDate != '') {if (!isDate(b.endDate)) { return { error = 'the end date is not a date' } }if (before(b.endDate, b.startDate)) { return { error = 'the end is before the start' } }if (b.endDate != b.startDate) { r['$end'] = nextDay(b.endDate) }}return { record = r }}if (!isTime(b.startTime)) { return { error = 'the start time is not a time' } }r['$kind'] = 'appointment'r['$timezone'] = b.zoner['$start'] = b.startDate + 'T' + b.startTime + ':00'hasEnd = (isText(b.endDate) && b.endDate != '') || (isText(b.endTime) && b.endTime != '')if (hasEnd) {ed = isText(b.endDate) && b.endDate != '' ? b.endDate : b.startDateif (!isDate(ed)) { return { error = 'the end date is not a date' } }if (!isTime(b.endTime)) { return { error = 'the end time is not a time' } }end = ed + 'T' + b.endTime + ':00'if (before(end, r['$start'])) { return { error = 'the end is before the start' } }r['$end'] = end}return { record = r }}// what the page shows of a stored event: first / last day (inclusive), times, textsstatic viewOf = (Hybrid e) => {allDay = e['$kind'] == 'allday'start = e['$start']end = e['$end']first = start.slice(0, 10)let last = firstif (allDay) {if (end != null) { last = prevDay(end) }} else if (end != null) {last = end.slice(0, 10)}v = { id = e.id title = e['$title'] allDay = allDay first = first last = laststartDate = first startTime = allDay ? '' : start.slice(11, 16)endDate = end == null ? '' : last endTime = allDay || end == null ? '' : end.slice(11, 16)place = e['$location'] == null ? '' : e['$location'] notes = e['$description'] == null ? '' : e['$description']start = start zone = e['$timezone'] == null ? '' : e['$timezone']custom = e['$reminders'] != null rows = e['$reminders'] == null ? [] : toRows(e['$reminders']) }return v}// an event made offline carries a temporary id `local-…` until the page reloads; the server keeps it as `ref`, so an edit// (or delete) sent with that id reaches the same event instead of making a second onestatic isLocalId = (id) => { return isText(id) && id.length > 6 && id.length <= 60 && id.slice(0, 6) == 'local-' }// the window is two dates the page shows; anything else is refusedstatic validWindow = (first, last) => { return isDate(first) && isDate(last) }// the views ordered by start (a hand-written selection sort)static byStart = (Hybrid views) => {m = views.lengthout = []used = []let i = 0while (i < m) { used.push(false) i = i + 1 }let round = 0while (round < m) {let best = -1let j = 0while (j < m) {if (!used[j] && (best < 0 || before(views[j].start, views[best].start))) { best = j }j = j + 1}used[best] = trueout.push(views[best])round = round + 1}return out}
Branches
Latest commits
- b37cc1da|||PR Vendor Hybriel day59Atlas
- 05665102Merge branch 'vendor-day56' into mainAtlas
- 687296fb|||PR Vendor Hybriel day56Atlas
- a6166d4eMerge branch 'hl-standard-3' into mainAtlas
- 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas
- add4b499|||PR Make calendar day actions keyboard accessibleAtlas
- 79e49b4dMerge branch 'hl-standard' into mainAtlas
- e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
- eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
- cef81394Wait for the DST fixture page instead of an unused socketmre
- 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
- 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
- cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
- f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
- edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
- bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre
- 5d8579d7README: login.js stays by caramboleyo's explicit rulemre
- cc759328Merge sb3-standby: calendar deploys through its standbymre
- f2fcdc6dcalendar: a standby container (port 45015, profile standby, reminder clock off) and a /health page; deploy hands over through standby-swap.sh without a gapmre