tickets
All repositories: gitoria
5.6 KB
// lib/util.hl — small helpers every topic shares (env, storage path, URLs, lists, text checks, Vienna time).// Statics only; no topic logic here.import { env } from 'hl:proc'import { timestamp } from 'hl:time'// ---- env and storage -----------------------------------------------------------------------static envOr = (name, fallback) => {v = env(name)return v != null && v.trim() != '' ? v.trim() : fallback}// THE TABLE DIRECTORY of every hl:mpackdb table (storage/mpackdb/; TICKETS_STORAGE moves it — the gate runs on its// own). Relative paths resolve against the ENTRY SCRIPT's directory (project.hl's) — tools must pass an absolute one.static storageDir = env('TICKETS_STORAGE') != null ? env('TICKETS_STORAGE') : './storage/mpackdb'// ---- the URLs a person uses ------------------------------------------------------------------// ticket #25: a project's page is /<slug>, a ticket's /<slug>/<number> (the old /projects/… forms answer 301);// the API keeps its /api/projects/… pathsstatic ticketHref = (project, number) => { return '/' + project + '/' + number }static ticketApiHref = (project, number) => { return '/api/projects/' + project + '/tickets/' + number }static projectHrefOf = (project) => { return '/' + project }static settingsHrefOf = (project) => { return '/projects/' + project + '/settings' }// ---- lists and records -----------------------------------------------------------------------// an empty list written to hl:mpackdb comes back as an empty hybrid (`.length` null):// every read of a found list goes through herestatic countOf = (list) => {if (list == null) { return 0 }n = list.lengthreturn n == null ? 0 : n}static first = (list) => { return countOf(list) > 0 ? list[0] : null }// every record is written as a whole (hl:mpackdb's update replaces it)static merged = (rec, changes) => {out = {}for (k of rec.keys()) { out[k] = rec[k] }for (k of changes.keys()) { out[k] = changes[k] }return out}// insertion sorts (no list sort() in the language, hybriel #6) — stable; they sort their copy and return itstatic oldestFirst = (rows, field) => {let i = 1while (i < rows.length) {let cur = rows[i]let j = i - 1while (j >= 0 && rows[j][field] > cur[field]) {rows[j + 1] = rows[j]j = j - 1}rows[j + 1] = curi = i + 1}return rows}static newestFirst = (rows, field) => {let i = 1while (i < rows.length) {let cur = rows[i]let j = i - 1while (j >= 0 && rows[j][field] < cur[field]) {rows[j + 1] = rows[j]j = j - 1}rows[j + 1] = curi = i + 1}return rows}// ---- text ---------------------------------------------------------------------------------------static clean = (s) => { return s == null ? '' : ('' + s).trim() }// a query value, percent-encoded (encodeURIComponent is a global, hybriel#14)static encode = (s) => { return encodeURIComponent('' + s) }// a string of ASCII digits only (a ticket number in a URL); '' is notstatic isDigits = (s) => {if (s == null) { return false }t = '' + sif (t.length == 0 || t.length > 12) { return false }let i = 0while (i < t.length) {let c = t.charCodeAt(i)if (c < 48 || c > 57) { return false }i = i + 1}return true}// only lowercase hex (ident's one-time codes are 48 hex)static isHex = (s, max) => {if (s == null || hlTypeName(s) != 'String' || s.length == 0 || s.length > max) { return false }let i = 0while (i < s.length) {let c = s.charCodeAt(i)if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 102))) { return false }i = i + 1}return true}// a short one-line text: trimmed, at most `max` characters, no control charactersstatic plainError = (s, max, what) => {if (s == null || hlTypeName(s) != 'String') { return what + ' must be text' }t = s.trim()if (t.length > max) { return what + ' is too long (at most ' + max + ' characters)' }let i = 0while (i < t.length) {let c = t.charCodeAt(i)if (c < 32 || c == 127) { return what + ' must be one line without control characters' }i = i + 1}return null}// ---- time: epoch ms → "YYYY-MM-DD HH:MM" in Europe/Vienna (ticket #10) ---------------------------// hl:time has no time zones (now() + a UTC timestamp() only; "timezones are a userland// concern" — its header). This is the smallest correct userland rule for Vienna: the EU// rule in force since 1996 — CEST (UTC+2) from the last Sunday of March 01:00 UTC to the// last Sunday of October 01:00 UTC, CET (UTC+1) otherwise. Storage stays epoch ms (UTC);// only the rendering shifts. Checked against node's Intl (tests/localtime.hl + the gate).static DAY = 86400000static HOUR = 3600000// integer division for a >= 0 (the language has `%` but no floor in the core)static idiv = (a, b) => { return (a - a % b) / b }// days since 1970-01-01 of a civil date (H. Hinnant's days_from_civil, years >= 1970)static daysFromCivil = (y, m, d) => {yy = m <= 2 ? y - 1 : yera = idiv(yy, 400)yoe = yy - era * 400mp = m > 2 ? m - 3 : m + 9doy = idiv(153 * mp + 2, 5) + d - 1doe = yoe * 365 + idiv(yoe, 4) - idiv(yoe, 100) + doyreturn era * 146097 + doe - 719468}// the last Sunday of a 31-day month (March, October), 01:00 UTC, as epoch msstatic lastSundayAt1 = (y, m) => {days = daysFromCivil(y, m, 31)wd = (days + 4) % 7 // 0 = Sunday: 1970-01-01 was a Thursdayreturn (days - wd) * DAY + HOUR}static viennaOffset = (ms) => {y = toNumber(timestamp(ms).slice(0, 4))return ms >= lastSundayAt1(y, 3) && ms < lastSundayAt1(y, 10) ? 2 * HOUR : HOUR}// "YYYY-MM-DD HH:MM", Vienna wall time — what a person readsstatic localStamp = (ms) => {t = timestamp(ms + viennaOffset(ms))return t.slice(0, 10) + ' ' + t.slice(11, 16)}
Branches
Latest commits
- b6277497report MT-mobile, LOGmre
- 6709398blist paging: the newest rows come first (the sorted array was not used); filter rows hide their scrollbar; gate checks the ordermre
- 31736a80gate: member-name check fails on the old row layout toomre
- e03ae537gate: the phone checks run on without the Show more button (so old code reports every failed check)mre
- adf7f132gate: 390 px checks for the mobile audit fixes (row number, filters, field widths, Edit, member names, relation taps, paging)mre
- 28e9c938ticket list: draw the newest 50 rows and a Show more button (500 rows were a 2-4 s first paint, 740 KB, a 90 000 px phone page)mre
- ccebb0c7mobile: ticket number stays on one line, filter chips one scrolling row, fields full width under their caption, Edit/action buttons, member names whole, 44 px relation linksmre
- f2dc7741gate: the phone toolbar is two even rows (E2)mre
- 20f7c33async components.hybriel 214c318: MdEditor on a phone, two even toolbar rows of 44 px targets, label 15 px, table head 16 px (E2)mre
- d74a5482sync components.hybriel 134b4e3: MdEditor builds an editor put into the page at once, redraws a surface put in anew (F5, hybriel#211)mre
- 9d02c540sync components.hybriel 6b0936a: the 'edited' foldable drops the theme's border and marginmre
- 22751914sync components.hybriel 8d79ff7: bubble hugs its content, quiet 'edited' label; gate checksmre
- c8452453sync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
- 52ba11e8sync-components: copy icons/icons.hl + README (F4); testsmre
- 138d198dmd-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
- 18d2df60md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
- f6764bedreports/H1-hydrate.mdmre
- 1bbbf0edtests/browser.mjs: wait for hydration before clicking the login button on / (device B)mre
- 6f503cfctests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
- e17e2855re-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