/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]>
111 lines
3.1 KiB
Go
111 lines
3.1 KiB
Go
package graph
|
|
|
|
// This file will be automatically regenerated based on the schema, any resolver
|
|
// implementations
|
|
// will be copied through when generating and any unknown code will be moved to the end.
|
|
// Code generated by github.com/99designs/gqlgen version v0.17.95
|
|
|
|
import (
|
|
"context"
|
|
|
|
"adam-french.co.uk/backend/graph/model"
|
|
"adam-french.co.uk/backend/models"
|
|
)
|
|
|
|
// CreateBox is the resolver for the createBox field.
|
|
func (r *mutationResolver) CreateBox(ctx context.Context, input model.CreateBoxInput) (*models.Box, error) {
|
|
// Framed defaults to true here rather than in the gorm tag — see the
|
|
// comment on models.Box.Framed. Sizes not supplied fall back to the
|
|
// same 300x200 the column defaults use.
|
|
box := models.Box{
|
|
Kind: input.Kind,
|
|
Widget: input.Widget,
|
|
HTML: input.HTML,
|
|
Title: input.Title,
|
|
W: 300,
|
|
H: 200,
|
|
Framed: true,
|
|
}
|
|
setInt(&box.X, input.X)
|
|
setInt(&box.Y, input.Y)
|
|
setInt(&box.W, input.W)
|
|
setInt(&box.H, input.H)
|
|
setInt(&box.Z, input.Z)
|
|
if input.Framed != nil {
|
|
box.Framed = *input.Framed
|
|
}
|
|
if input.HideOnMobile != nil {
|
|
box.HideOnMobile = *input.HideOnMobile
|
|
}
|
|
if err := validateBox(&box); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := r.Store.DB.Create(&box).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &box, nil
|
|
}
|
|
|
|
// UpdateBox is the resolver for the updateBox field.
|
|
func (r *mutationResolver) UpdateBox(ctx context.Context, id int, input model.UpdateBoxInput) (*models.Box, error) {
|
|
// Partial update: nil fields are left alone. The canvas sends only the
|
|
// geometry after a drag and only the html after an edit, so this is
|
|
// what keeps the two from overwriting each other. Kind is not
|
|
// updatable — switching a widget box to html is a delete and create.
|
|
var box models.Box
|
|
if err := r.Store.DB.First(&box, id).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if input.Widget != nil {
|
|
box.Widget = input.Widget
|
|
}
|
|
if input.HTML != nil {
|
|
box.HTML = input.HTML
|
|
}
|
|
if input.Title != nil {
|
|
box.Title = input.Title
|
|
}
|
|
setInt(&box.X, input.X)
|
|
setInt(&box.Y, input.Y)
|
|
setInt(&box.W, input.W)
|
|
setInt(&box.H, input.H)
|
|
setInt(&box.Z, input.Z)
|
|
if input.Framed != nil {
|
|
box.Framed = *input.Framed
|
|
}
|
|
if input.HideOnMobile != nil {
|
|
box.HideOnMobile = *input.HideOnMobile
|
|
}
|
|
if err := validateBox(&box); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := r.Store.DB.Save(&box).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &box, nil
|
|
}
|
|
|
|
// DeleteBox is the resolver for the deleteBox field.
|
|
func (r *mutationResolver) DeleteBox(ctx context.Context, id int) (*models.Box, error) {
|
|
var box models.Box
|
|
if err := r.Store.DB.First(&box, id).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
if err := r.Store.DB.Delete(&box).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &box, nil
|
|
}
|
|
|
|
// Boxes is the resolver for the boxes field.
|
|
func (r *queryResolver) Boxes(ctx context.Context) ([]*models.Box, error) {
|
|
// Public: this is the page layout every visitor loads. Ordered by z so
|
|
// DOM order matches stacking order, which keeps tab order sensible.
|
|
var boxes []models.Box
|
|
if err := r.Store.DB.Order("z ASC, id ASC").Find(&boxes).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return ptrs(boxes), nil
|
|
}
|
|
|