/stp is now views/home3/Home3.vue: boxes an admin creates, drags, resizes and edits in the browser, saved to the database so every visitor sees the same layout. - backend: a Box GraphQL type (kind widget|html, x/y/w/h/z in px on a 1400px design canvas, framed, hideOnMobile). Public `boxes` query; create/update/delete are @admin. Geometry is clamped rather than rejected. Framed has no gorm default, since GORM would turn an explicit false into true on insert. - vue: widget boxes render the existing widgets from a registry; html boxes render in an iframe sandboxed with allow-scripts and no allow-same-origin, so admin script can't read cookies or call /api. The site tokens and fonts (inlined as data: URLs) are injected into each frame. The canvas scales to fit the window; phones get a single column in (y, x) order. Edit mode saves geometry on release and has a CodeMirror side panel (lazy-loaded) with a live HTML preview. Templates cover Clock, Weather (Open-Meteo) and Image/GIF. "Import current layout" recreates the old Home.vue grid on an empty canvas. - Home.vue is kept with a STATUS: legacy header. Docs updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package graph
|
|
|
|
// Hand-written helpers for box.resolvers.go. Kept out of that file because
|
|
// gqlgen moves unknown code in a resolvers file to the end, under a warning
|
|
// comment, on every regenerate.
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"adam-french.co.uk/backend/models"
|
|
)
|
|
|
|
// minBoxSize stops a box being resized to nothing, after which it could not
|
|
// be grabbed again on the canvas.
|
|
const minBoxSize = 40
|
|
|
|
func setInt(dst *int, src *int) {
|
|
if src != nil {
|
|
*dst = *src
|
|
}
|
|
}
|
|
|
|
// validateBox checks the fields a box needs to render and clamps geometry
|
|
// rather than rejecting it, because a drag that overshoots the canvas edge
|
|
// should land at the edge, not fail.
|
|
func validateBox(box *models.Box) error {
|
|
switch box.Kind {
|
|
case "widget":
|
|
if box.Widget == nil || *box.Widget == "" {
|
|
return errors.New("a widget box needs a widget name")
|
|
}
|
|
case "html":
|
|
if box.HTML == nil {
|
|
return errors.New("an html box needs html")
|
|
}
|
|
default:
|
|
return errors.New(`box kind must be "widget" or "html"`)
|
|
}
|
|
box.X = max(box.X, 0)
|
|
box.Y = max(box.Y, 0)
|
|
box.W = max(box.W, minBoxSize)
|
|
box.H = max(box.H, minBoxSize)
|
|
return nil
|
|
}
|