calendar
All repositories: gitoria
5.2 KB
// lib/events.hl — THE EVENTS (ticket calendar#2). One hl:mpackdb table, storage/mpackdb/events.db, pk @id, index owner.// A record IS a WorldAPI Event (https://worldapi.org/standards/event): the `$`-keys `$type $version $kind $title// $description $start $end $timezone $location $status $visibility $created $updated`, plus `owner` (the users @id)// and the @id. Appointment: `$start`/`$end` local wall-clock `YYYY-MM-DDTHH:MM:SS` in `$timezone`. All-day:// `$kind = 'allday'`, `$start` a date, `$end` the EXCLUSIVE end date (left out for one day). Every event is// `$visibility = 'private'`: every function takes the owner's user id and reaches only that user's events.// Every write to the table is here. Looked up in lib/events-helpers.hl: build (page fields → record), viewOf (record →// what the page shows), isLocalId, byStart. The default reminders are lib/settings.hl.import { MPackDB } from 'hl:mpackdb'import { timestamp } from 'hl:time'import { storageDir, countOfList } from './util.hl'import { build, viewOf, isLocalId, byStart, maxEvents } from './events-helpers.hl'import { defaultsOf } from './settings.hl'import { before } from '../components/month-view/dates.hl'import { describe, shift } from '../components/month-view/reminders.hl'import { serverToday } from '../components/month-view/clock.hl'static eventsTable = new MPackDB(file = storageDir + '/events.db', primaryKey = '@id', indexes = ['owner'])static ownEvent = (userId, id) => {if (id == null || hlTypeName(id) != 'String' || id == '') { return null }e = eventsTable.fetch(id)if (e == null || e.owner != userId) { return null }return e}// the owner's events that touch first..last (dates), by startstatic eventsBetween = (userId, first, last) => {found = eventsTable.find('owner', userId)n = countOfList(found)views = []let i = 0while (i < n) {let v = viewOf(found[i])if (!before(v.last, first) && !before(last, v.first)) { views.push(v) }i = i + 1}return byStart(views)}static realId = (userId, id) => {if (!isLocalId(id)) { return id }found = eventsTable.find('owner', userId)n = countOfList(found)let i = 0while (i < n) {if (found[i].ref == id) { return found[i].id }i = i + 1}return null}// create, or change when the fields name an event (real or temporary id)static saveEvent = (userId, b) => {if (b != null && hlTypeName(b) == 'Hybrid' && b.id != null && b.id != '') {id = realId(userId, b.id)if (id != null) { return changeEvent(userId, id, b) }if (!isLocalId(b.id)) { return changeEvent(userId, b.id, b) }}return createEvent(userId, b)}static createEvent = (userId, b) => {if (countOfList(eventsTable.find('owner', userId)) >= maxEvents) { return { error = 'too many events (at most ' + maxEvents + ')' } }x = build(b)if (x.error != null) { return x }r = x.recordt = timestamp()r['$created'] = tr['$updated'] = tr.owner = userIdif (isLocalId(b.id)) { r.ref = b.id }let id = eventsTable.put(r)if (id == null) { return { error = 'could not store the event: ' + eventsTable.lastError() } }return { id = id }}static changeEvent = (userId, id, b) => {old = ownEvent(userId, id)if (old == null) { return { error = 'no such event' } }x = build(b)if (x.error != null) { return x }r = x.recordr['$created'] = old['$created']r['$updated'] = timestamp()r.owner = userIdif (old.ref != null) { r.ref = old.ref }r.id = ideventsTable.update(id, r)return { id = id }}static deleteEvent = (userId, given) => {id = realId(userId, given)old = ownEvent(userId, id)if (old == null) { return { error = 'no such event' } }eventsTable.delete(id)return { ok = true }}// ---- the reminders still to come ------------------------------------------------------------------------// the owner's events starting first..last with the reminders that apply (own, else the defaults); timed and all-daystatic upcoming = (userId, first, last) => {defaults = defaultsOf(userId)found = eventsTable.find('owner', userId)n = countOfList(found)out = []let i = 0while (i < n) {let v = viewOf(found[i])if (!before(v.first, first) && !before(last, v.first)) {let list = { id = v.id title = v.title allDay = v.allDay startDate = v.startDate startTime = v.startTime place = v.place zone = v.zone rows = v.custom ? v.rows : defaults }out.push(list)}i = i + 1}return out}// the events with the reminders that apply, from two days back to nine days ahead (what the browser plans its notifications from)static soonOf = (userId) => {t = serverToday()return upcoming(userId, shift(t, -2), shift(t, 9))}// ---- what the faces answer (components/calendar.hl) -----------------------------------------------------// the events of the six weeks on screen, the defaults (text and rows) and the reminders still to comestatic calendarView = (userId, first, last) => {return { events = eventsBetween(userId, first, last) defaults = describe(defaultsOf(userId)) soon = soonOf(userId) defaultRows = defaultsOf(userId) }}// the settings editor: the default reminders as rows, their text and the reminders still to comestatic settingsView = (userId) => {return { rows = defaultsOf(userId) defaults = describe(defaultsOf(userId)) soon = soonOf(userId) defaultRows = defaultsOf(userId) }}
Branches
Latest commits
- 490c658aident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- 18095868calendar: Reminder settings button opens its dialog again (the dialog's open handler still closed the removed user menu and stopped); old e2e and gate scripts use the new headermre
- 6eee4b5acalendar header: the selector alone top right plus Log out as before the theme missions; Reminder settings back on the month page (WIP: the settings test still fails)mre
- 0b909decident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- 0c8f9364Merge branch 'sy-sync'mre
- 9fab1c8fsync components.hybriel 4922f9c into the month view: prev / next 44 px targets, names formatted in UTC (a UTC+12 zone showed the wrong first weekday); the calendar keeps its own language handling (Accept-Language / browser) and the P1/C13 reminder code; gate: 44 px check (SY)mre
- 27d3e294theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 2ac9c1bbdeploy: security gate (tests/security.mjs)mre
- 6b0a2571merge sc-sec (calendar security) with 99-year sessionsmre
- 92001e52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- 0f76c99dSecurity audit SC: push endpoint SSRF guard, uploadMax 0, Secure cookie, login session rotation + rate limit, event cap, nosniff, security gatemre
- 2dd53dccP1: one reminder shows once: arm() one at a time, the page skips reminders the server already pushed; push-twice gatemre
- 3a29760aC13 report (handoff)mre
- 33ab66ffCalendar: notification controls move from the month view into Reminder settings (user menu), one consistent state, state read when the dialog opensmre
- 682a5b43reports: calendar gate countsmre
- 876d22b2reports/H1-hydrate.mdmre
- ef0cae45tests/dst.mjs: wait for hydration instead of a fixed 2.5 s sleep before clicking #gomre
- d9cadecatests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- efa61227re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
- 7808adbecalendar#12: report 011, LOG, STATUS, push-shots-testmre