Add saved layouts, and make /stp an ordinary canvas page
A layout is a named copy of one canvas page's boxes and background (models.Layout, layout.graphql), saved from the canvas's new Layouts button and loaded onto any page from there or from the admin Pages tab. Loading onto a page with boxes asks whether to replace them or add on top; a replace first saves the page as a "<page> before <layout>" layout so it can be undone. Copies, not links: editing a page never changes a layout or another page. The copying is server-side in one transaction, and everything is @admin since a layout keeps admin-only boxes. /stp loses its static route and becomes a Page with slug "stp", created once at start-up (ensureStpPage), so it can be renamed, hidden or deleted like a shrine. Its boxes were already keyed "stp". Home3.vue is kept as legacy; its starter is now "Old /stp grid" in pageStarters.js. ConfirmDialog gains an optional second button. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -76,7 +76,7 @@ Dockerized multi-service personal website self-hosted on `stpvm` (an x86-64 Ubun
|
|||||||
- `graph/*.resolvers.go` — resolver implementations (one per schema file, `follow-schema` layout)
|
- `graph/*.resolvers.go` — resolver implementations (one per schema file, `follow-schema` layout)
|
||||||
- `graph/generated.go` — auto-generated by gqlgen, do not edit
|
- `graph/generated.go` — auto-generated by gqlgen, do not edit
|
||||||
- `graph/model/models_gen.go` — auto-generated GraphQL models, do not edit
|
- `graph/model/models_gen.go` — auto-generated GraphQL models, do not edit
|
||||||
- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box, Page, Background)
|
- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box, Page, Background, Layout)
|
||||||
- `graph/directives.go` — the `@admin` / `@signedIn` schema directives (see Key Patterns)
|
- `graph/directives.go` — the `@admin` / `@signedIn` schema directives (see Key Patterns)
|
||||||
- `services/` — database init, JWT auth, WebSocket server, Spotify OAuth, Gitea feed, the Python-service call helper (`python_call.go`), uploads (`uploads.go`: validation, naming, Garage bucket with disk fallback), DB seeding. There is no Claude client in Go any more
|
- `services/` — database init, JWT auth, WebSocket server, Spotify OAuth, Gitea feed, the Python-service call helper (`python_call.go`), uploads (`uploads.go`: validation, naming, Garage bucket with disk fallback), DB seeding. There is no Claude client in Go any more
|
||||||
|
|
||||||
@@ -85,8 +85,8 @@ Dockerized multi-service personal website self-hosted on `stpvm` (an x86-64 Ubun
|
|||||||
- `src/graphql.js` — thin axios-based GraphQL client (`POST /api/graphql`)
|
- `src/graphql.js` — thin axios-based GraphQL client (`POST /api/graphql`)
|
||||||
- `src/api.js` — thin REST client for the `/api` JSON endpoints; failures become an `ApiError` carrying the backend's `error` message and the status
|
- `src/api.js` — thin REST client for the `/api` JSON endpoints; failures become an `ApiError` carrying the backend's `error` message and the status
|
||||||
- `src/uploads.js` — storing and showing uploaded files: `uploadFile(file)` → public `/uploads/...` URL, `ACCEPT` for file pickers, `kindOf`/`tagFor`/`isUploadUrl`/`mediaSize`. Every upload goes through it
|
- `src/uploads.js` — storing and showing uploaded files: `uploadFile(file)` → public `/uploads/...` URL, `ACCEPT` for file pickers, `kindOf`/`tagFor`/`isUploadUrl`/`mediaSize`. Every upload goes through it
|
||||||
- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes, pages. `createCrudStore.js` is the factory behind places, boxes and pages; `createMirrorStore.js` is the one behind the home-page slices
|
- `src/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes, pages, layouts. `createCrudStore.js` is the factory behind places, boxes and pages; `createMirrorStore.js` is the one behind the home-page slices
|
||||||
- `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines). `/stp` is `views/home3/Home3.vue`: a canvas of admin-arranged boxes (built-in widgets or sandboxed-iframe HTML) stored as the `Box` GraphQL type. The canvas (`views/home3/BoxCanvas.vue`) is reusable per page key: the landing page (`/`) is one too, and admin-created `Page`s (e.g. shrines) are served at `/<slug>` by the router's catch-all, `views/canvas/CanvasPage.vue`. Boxes and pages can be admin-only, filtered server-side. Each canvas page key also has an optional `Background`, set from the canvas's Background button and painted by `DefaultLayout`. See "The /stp canvas" in `vue/README.md`
|
- `src/views/` — page components (Home, Admin, CV, Notes, Bookmarks, shrines). Canvas pages are admin-arranged boxes (built-in widgets or sandboxed-iframe HTML) stored as the `Box` GraphQL type, drawn by `views/home3/BoxCanvas.vue` per page key: the landing page (`/`, key `index`) is one, and admin-created `Page`s (e.g. shrines, and `/stp`, the `Page` with slug `stp`) are served at `/<slug>` by the router's catch-all, `views/canvas/CanvasPage.vue`. A `Layout` is a saved, named copy of a page's boxes and background that can be loaded onto any canvas (the canvas's Layouts button, or the admin Pages tab). Boxes and pages can be admin-only, filtered server-side. Each canvas page key also has an optional `Background`, set from the canvas's Background button and painted by `DefaultLayout`. See "The /stp canvas" in `vue/README.md`
|
||||||
- `src/components/` — reusable UI components
|
- `src/components/` — reusable UI components
|
||||||
- `src/assets/styles.css` — design tokens (Tailwind `@theme`), base element styles, shared classes and transitions. `layouts/CVLayout.vue` re-points the colour tokens for the light CV theme. See "Styling" in `vue/README.md`.
|
- `src/assets/styles.css` — design tokens (Tailwind `@theme`), base element styles, shared classes and transitions. `layouts/CVLayout.vue` re-points the colour tokens for the light CV theme. See "Styling" in `vue/README.md`.
|
||||||
|
|
||||||
|
|||||||
@@ -94,3 +94,13 @@ models:
|
|||||||
fields:
|
fields:
|
||||||
deletedAt:
|
deletedAt:
|
||||||
resolver: false
|
resolver: false
|
||||||
|
Layout:
|
||||||
|
model:
|
||||||
|
- adam-french.co.uk/backend/models.Layout
|
||||||
|
fields:
|
||||||
|
deletedAt:
|
||||||
|
resolver: false
|
||||||
|
boxCount:
|
||||||
|
resolver: true
|
||||||
|
hasBackground:
|
||||||
|
resolver: true
|
||||||
|
|||||||
@@ -187,9 +187,10 @@ func TestSignedInMutationsArePinned(t *testing.T) {
|
|||||||
// `spotifyNeedsReauth` is false for non-admins.
|
// `spotifyNeedsReauth` is false for non-admins.
|
||||||
func TestGuardedQueriesArePinned(t *testing.T) {
|
func TestGuardedQueriesArePinned(t *testing.T) {
|
||||||
want := map[string]string{
|
want := map[string]string{
|
||||||
"users": "admin",
|
"users": "admin",
|
||||||
"user": "admin",
|
"user": "admin",
|
||||||
"places": "signedIn",
|
"places": "signedIn",
|
||||||
|
"layouts": "admin",
|
||||||
}
|
}
|
||||||
got := map[string]string{}
|
got := map[string]string{}
|
||||||
for _, field := range schemaUnderTest().Query.Fields {
|
for _, field := range schemaUnderTest().Query.Fields {
|
||||||
|
|||||||
+943
-1
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,144 @@
|
|||||||
|
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"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"adam-french.co.uk/backend/graph/model"
|
||||||
|
"adam-french.co.uk/backend/models"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BoxCount is the resolver for the boxCount field.
|
||||||
|
func (r *layoutResolver) BoxCount(ctx context.Context, obj *models.Layout) (int, error) {
|
||||||
|
// Decoded rather than stored, so it can never disagree with the boxes.
|
||||||
|
boxes, err := decodeLayoutBoxes(obj)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return len(boxes), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasBackground is the resolver for the hasBackground field.
|
||||||
|
func (r *layoutResolver) HasBackground(ctx context.Context, obj *models.Layout) (bool, error) {
|
||||||
|
return obj.Background != nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateLayout is the resolver for the createLayout field.
|
||||||
|
func (r *mutationResolver) CreateLayout(ctx context.Context, input model.CreateLayoutInput) (*models.Layout, error) {
|
||||||
|
// A snapshot of the page as it is now, adminOnly boxes included —
|
||||||
|
// which is why every layout field is @admin.
|
||||||
|
name, err := cleanLayoutName(input.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !validPageKey(input.Page) {
|
||||||
|
return nil, errors.New("a layout needs a valid page")
|
||||||
|
}
|
||||||
|
taken, err := layoutNameTaken(r.Store.DB, name, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if taken {
|
||||||
|
return nil, errors.New("there is already a layout with that name")
|
||||||
|
}
|
||||||
|
layout, empty, err := snapshotPage(r.Store.DB, input.Page, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if empty {
|
||||||
|
return nil, errors.New("that page has nothing on it to save")
|
||||||
|
}
|
||||||
|
if err := r.Store.DB.Create(&layout).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &layout, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateLayout is the resolver for the updateLayout field.
|
||||||
|
func (r *mutationResolver) UpdateLayout(ctx context.Context, id int, input model.UpdateLayoutInput) (*models.Layout, error) {
|
||||||
|
// Only the name changes: a layout is a snapshot, and saving the page
|
||||||
|
// again under a new name is how its content is refreshed.
|
||||||
|
var layout models.Layout
|
||||||
|
if err := r.Store.DB.First(&layout, id).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if input.Name != nil {
|
||||||
|
name, err := cleanLayoutName(*input.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
taken, err := layoutNameTaken(r.Store.DB, name, layout.ID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if taken {
|
||||||
|
return nil, errors.New("there is already a layout with that name")
|
||||||
|
}
|
||||||
|
layout.Name = name
|
||||||
|
}
|
||||||
|
if err := r.Store.DB.Save(&layout).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &layout, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteLayout is the resolver for the deleteLayout field.
|
||||||
|
func (r *mutationResolver) DeleteLayout(ctx context.Context, id int) (*models.Layout, error) {
|
||||||
|
// Pages it was loaded onto keep their boxes: they were copies.
|
||||||
|
var layout models.Layout
|
||||||
|
if err := r.Store.DB.First(&layout, id).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := r.Store.DB.Delete(&layout).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &layout, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyLayout is the resolver for the applyLayout field.
|
||||||
|
func (r *mutationResolver) ApplyLayout(ctx context.Context, id int, page string, replace bool) ([]*models.Box, error) {
|
||||||
|
// One transaction, so a replace that fails partway leaves the page as
|
||||||
|
// it was rather than half emptied.
|
||||||
|
var layout models.Layout
|
||||||
|
if err := r.Store.DB.First(&layout, id).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
exists, err := canvasExists(r.Store.DB, page)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return nil, errors.New("there is no page at that address")
|
||||||
|
}
|
||||||
|
err = r.Store.DB.Transaction(func(tx *gorm.DB) error {
|
||||||
|
return applyLayoutTo(tx, &layout, page, replace)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
boxes, err := pageBoxes(r.Store.DB, page)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ptrs(boxes), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Layouts is the resolver for the layouts field.
|
||||||
|
func (r *queryResolver) Layouts(ctx context.Context) ([]*models.Layout, error) {
|
||||||
|
var layouts []models.Layout
|
||||||
|
if err := r.Store.DB.Order("created_at DESC").Find(&layouts).Error; err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ptrs(layouts), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Layout returns LayoutResolver implementation.
|
||||||
|
func (r *Resolver) Layout() LayoutResolver { return &layoutResolver{r} }
|
||||||
|
|
||||||
|
type layoutResolver struct{ *Resolver }
|
||||||
@@ -0,0 +1,235 @@
|
|||||||
|
package graph
|
||||||
|
|
||||||
|
// Hand-written helpers for layout.resolvers.go, kept out of the resolver file
|
||||||
|
// for the same reason as box_helpers.go.
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"adam-french.co.uk/backend/graph/model"
|
||||||
|
"adam-french.co.uk/backend/models"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
const maxLayoutNameLen = 100
|
||||||
|
|
||||||
|
// layoutBox is one box as a layout stores it: what makes it look the way it
|
||||||
|
// does, without the id and page that tie a row to one canvas. Changing these
|
||||||
|
// field names would make older layouts load with the renamed fields empty.
|
||||||
|
type layoutBox struct {
|
||||||
|
Kind string `json:"kind"`
|
||||||
|
Widget *string `json:"widget,omitempty"`
|
||||||
|
HTML *string `json:"html,omitempty"`
|
||||||
|
Title *string `json:"title,omitempty"`
|
||||||
|
X int `json:"x"`
|
||||||
|
Y int `json:"y"`
|
||||||
|
W int `json:"w"`
|
||||||
|
H int `json:"h"`
|
||||||
|
Z int `json:"z"`
|
||||||
|
Framed bool `json:"framed"`
|
||||||
|
HideOnMobile bool `json:"hideOnMobile"`
|
||||||
|
AdminOnly bool `json:"adminOnly"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type layoutBackground struct {
|
||||||
|
Color string `json:"color"`
|
||||||
|
Image string `json:"image"`
|
||||||
|
Fit string `json:"fit"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanLayoutName trims name and reports why it can't be a layout's name.
|
||||||
|
func cleanLayoutName(name string) (string, error) {
|
||||||
|
name = strings.TrimSpace(name)
|
||||||
|
if name == "" {
|
||||||
|
return name, errors.New("a layout needs a name")
|
||||||
|
}
|
||||||
|
if len(name) > maxLayoutNameLen {
|
||||||
|
return name, fmt.Errorf("a layout name is at most %d characters", maxLayoutNameLen)
|
||||||
|
}
|
||||||
|
return name, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// layoutNameTaken reports whether a live layout other than exceptID has this
|
||||||
|
// name. Checked up front, like slugTaken, so the admin gets a sentence rather
|
||||||
|
// than a constraint violation.
|
||||||
|
func layoutNameTaken(db *gorm.DB, name string, exceptID uint) (bool, error) {
|
||||||
|
var count int64
|
||||||
|
err := db.Model(&models.Layout{}).Where("name = ? AND id <> ?", name, exceptID).Count(&count).Error
|
||||||
|
return count > 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// canvasExists reports whether page is a canvas boxes can be put on: the
|
||||||
|
// landing page, or a live Page. Loading a layout onto any other key would
|
||||||
|
// leave its boxes where nothing shows them.
|
||||||
|
func canvasExists(db *gorm.DB, page string) (bool, error) {
|
||||||
|
if page == "index" {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
if !validPageKey(page) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
var count int64
|
||||||
|
err := db.Model(&models.Page{}).Where("slug = ?", page).Count(&count).Error
|
||||||
|
return count > 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// pageBoxes is every box on page, adminOnly ones included, in the order the
|
||||||
|
// boxes query returns them. Only for admin-only callers.
|
||||||
|
func pageBoxes(db *gorm.DB, page string) ([]models.Box, error) {
|
||||||
|
var boxes []models.Box
|
||||||
|
err := db.Where("page = ?", page).Order("z ASC, id ASC").Find(&boxes).Error
|
||||||
|
return boxes, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// snapshotPage is an unsaved Layout holding page's boxes and background as
|
||||||
|
// they are now. empty is true when there was nothing to keep.
|
||||||
|
func snapshotPage(db *gorm.DB, page, name string) (layout models.Layout, empty bool, err error) {
|
||||||
|
boxes, err := pageBoxes(db, page)
|
||||||
|
if err != nil {
|
||||||
|
return layout, false, err
|
||||||
|
}
|
||||||
|
stored := make([]layoutBox, len(boxes))
|
||||||
|
for i, b := range boxes {
|
||||||
|
stored[i] = layoutBox{
|
||||||
|
Kind: b.Kind, Widget: b.Widget, HTML: b.HTML, Title: b.Title,
|
||||||
|
X: b.X, Y: b.Y, W: b.W, H: b.H, Z: b.Z,
|
||||||
|
Framed: b.Framed, HideOnMobile: b.HideOnMobile, AdminOnly: b.AdminOnly,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boxesJSON, err := json.Marshal(stored)
|
||||||
|
if err != nil {
|
||||||
|
return layout, false, err
|
||||||
|
}
|
||||||
|
layout = models.Layout{Name: name, SourcePage: page, Boxes: string(boxesJSON)}
|
||||||
|
|
||||||
|
var bg models.Background
|
||||||
|
err = db.Where("page = ?", page).First(&bg).Error
|
||||||
|
switch {
|
||||||
|
case err == nil:
|
||||||
|
bgJSON, err := json.Marshal(layoutBackground{Color: bg.Color, Image: bg.Image, Fit: bg.Fit})
|
||||||
|
if err != nil {
|
||||||
|
return layout, false, err
|
||||||
|
}
|
||||||
|
s := string(bgJSON)
|
||||||
|
layout.Background = &s
|
||||||
|
case !errors.Is(err, gorm.ErrRecordNotFound):
|
||||||
|
return layout, false, err
|
||||||
|
}
|
||||||
|
return layout, len(boxes) == 0 && layout.Background == nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeLayoutBoxes(layout *models.Layout) ([]layoutBox, error) {
|
||||||
|
var boxes []layoutBox
|
||||||
|
if err := json.Unmarshal([]byte(layout.Boxes), &boxes); err != nil {
|
||||||
|
return nil, fmt.Errorf("layout %q is unreadable: %w", layout.Name, err)
|
||||||
|
}
|
||||||
|
return boxes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// pageLabel is how a page key reads in a generated layout name.
|
||||||
|
func pageLabel(page string) string {
|
||||||
|
if page == "index" {
|
||||||
|
return "/"
|
||||||
|
}
|
||||||
|
return "/" + page
|
||||||
|
}
|
||||||
|
|
||||||
|
// uniqueLayoutName is base, or base with " (2)", " (3)"… if that is taken.
|
||||||
|
func uniqueLayoutName(db *gorm.DB, base string) (string, error) {
|
||||||
|
name := base
|
||||||
|
for n := 2; ; n++ {
|
||||||
|
taken, err := layoutNameTaken(db, name, 0)
|
||||||
|
if err != nil || !taken {
|
||||||
|
return name, err
|
||||||
|
}
|
||||||
|
name = fmt.Sprintf("%s (%d)", base, n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// applyLayoutTo copies layout onto page inside tx; see applyLayout in
|
||||||
|
// layout.graphql for what replace does. The copies are new rows, so the page
|
||||||
|
// owns them outright.
|
||||||
|
func applyLayoutTo(tx *gorm.DB, layout *models.Layout, page string, replace bool) error {
|
||||||
|
stored, err := decodeLayoutBoxes(layout)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Added on top, the copies keep their own stacking order but all sit
|
||||||
|
// above what the page already has.
|
||||||
|
zShift := 0
|
||||||
|
if replace {
|
||||||
|
// What is being replaced is kept first, so a replace can be undone by
|
||||||
|
// loading that layout back. A page with nothing on it has nothing to
|
||||||
|
// keep.
|
||||||
|
name, err := uniqueLayoutName(tx, fmt.Sprintf("%s before %s, %s",
|
||||||
|
pageLabel(page), layout.Name, time.Now().Format("2 Jan 2006 15:04")))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
backup, empty, err := snapshotPage(tx, page, name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !empty {
|
||||||
|
if err := tx.Create(&backup).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := tx.Where("page = ?", page).Delete(&models.Box{}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Where("page = ?", page).Delete(&models.Background{}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if len(stored) > 0 {
|
||||||
|
var top *int
|
||||||
|
if err := tx.Model(&models.Box{}).Where("page = ?", page).Select("MAX(z)").Scan(&top).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if top != nil {
|
||||||
|
lowest := stored[0].Z
|
||||||
|
for _, b := range stored {
|
||||||
|
lowest = min(lowest, b.Z)
|
||||||
|
}
|
||||||
|
zShift = *top + 1 - lowest
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boxes := make([]models.Box, len(stored))
|
||||||
|
for i, b := range stored {
|
||||||
|
boxes[i] = models.Box{
|
||||||
|
Page: page, Kind: b.Kind, Widget: b.Widget, HTML: b.HTML, Title: b.Title,
|
||||||
|
X: b.X, Y: b.Y, W: b.W, H: b.H, Z: b.Z + zShift,
|
||||||
|
Framed: b.Framed, HideOnMobile: b.HideOnMobile, AdminOnly: b.AdminOnly,
|
||||||
|
}
|
||||||
|
if err := validateBox(&boxes[i]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(boxes) > 0 {
|
||||||
|
if err := tx.Create(&boxes).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adding on top leaves the page's own background alone.
|
||||||
|
if replace && layout.Background != nil {
|
||||||
|
var saved layoutBackground
|
||||||
|
if err := json.Unmarshal([]byte(*layout.Background), &saved); err != nil {
|
||||||
|
return fmt.Errorf("layout %q is unreadable: %w", layout.Name, err)
|
||||||
|
}
|
||||||
|
bg, err := backgroundFrom(page, model.BackgroundInput{Color: saved.Color, Image: saved.Image, Fit: saved.Fit})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := tx.Create(&bg).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -52,6 +52,11 @@ type CreateFavoriteInput struct {
|
|||||||
Link *string `json:"link,omitempty"`
|
Link *string `json:"link,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CreateLayoutInput struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Page string `json:"page"`
|
||||||
|
}
|
||||||
|
|
||||||
type CreatePageInput struct {
|
type CreatePageInput struct {
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
@@ -155,6 +160,10 @@ type UpdateBoxInput struct {
|
|||||||
AdminOnly *bool `json:"adminOnly,omitempty"`
|
AdminOnly *bool `json:"adminOnly,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateLayoutInput struct {
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type UpdatePageInput struct {
|
type UpdatePageInput struct {
|
||||||
Slug *string `json:"slug,omitempty"`
|
Slug *string `json:"slug,omitempty"`
|
||||||
Title *string `json:"title,omitempty"`
|
Title *string `json:"title,omitempty"`
|
||||||
|
|||||||
@@ -24,11 +24,11 @@ const maxSlugLen = 100
|
|||||||
// reservedFirstSegments are paths a page could never be reached at, because
|
// reservedFirstSegments are paths a page could never be reached at, because
|
||||||
// nginx or one of the SPA's own routes answers them first (see
|
// nginx or one of the SPA's own routes answers them first (see
|
||||||
// nginx/nginx_routes.conf.template and vue/src/router/index.js), plus the
|
// nginx/nginx_routes.conf.template and vue/src/router/index.js), plus the
|
||||||
// built-in canvases' page keys, whose boxes a page of the same slug would
|
// landing page's key "index", whose boxes a page of the same slug would
|
||||||
// share. "shrines" is deliberately absent: /shrines and the shrine pages under
|
// share. "shrines" and "stp" are deliberately absent: /shrines, the shrine
|
||||||
// it are all canvas pages.
|
// pages under it and the home page /stp are all canvas pages.
|
||||||
var reservedFirstSegments = map[string]bool{
|
var reservedFirstSegments = map[string]bool{
|
||||||
"stp": true, "stp2": true, "index": true, "admin": true, "cv": true,
|
"stp2": true, "index": true, "admin": true, "cv": true,
|
||||||
"automata": true, "hotels": true, "api": true, "py": true, "radio": true,
|
"automata": true, "hotels": true, "api": true, "py": true, "radio": true,
|
||||||
"gitea": true, "notes": true, "sb": true, "jobs": true, "tracker": true,
|
"gitea": true, "notes": true, "sb": true, "jobs": true, "tracker": true,
|
||||||
"usaco": true, "uploads": true, "img": true, "fonts": true, "pdf": true,
|
"usaco": true, "uploads": true, "img": true, "fonts": true, "pdf": true,
|
||||||
@@ -52,7 +52,7 @@ func validateSlug(slug string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pageHiddenFrom reports whether the page with this key is an adminOnly page
|
// pageHiddenFrom reports whether the page with this key is an adminOnly page
|
||||||
// and the caller is not an admin. A key with no Page row (a built-in canvas,
|
// and the caller is not an admin. A key with no Page row (the landing page,
|
||||||
// or a page that doesn't exist) is not hidden.
|
// or a page that doesn't exist) is not hidden.
|
||||||
func pageHiddenFrom(ctx context.Context, db *gorm.DB, key string) (bool, error) {
|
func pageHiddenFrom(ctx context.Context, db *gorm.DB, key string) (bool, error) {
|
||||||
if IsAdminFromCtx(ctx) {
|
if IsAdminFromCtx(ctx) {
|
||||||
|
|||||||
@@ -21,8 +21,9 @@ func TestValidateSlug(t *testing.T) {
|
|||||||
{"shrines/demoman", true}, // no longer an SPA route
|
{"shrines/demoman", true}, // no longer an SPA route
|
||||||
{"admin/pages", false}, // under an SPA route
|
{"admin/pages", false}, // under an SPA route
|
||||||
{"jobs/x", false}, // under an nginx route
|
{"jobs/x", false}, // under an nginx route
|
||||||
{"stp", false}, // a built-in canvas's key
|
{"stp", true}, // the home page is a canvas page too
|
||||||
{"index", false}, // likewise
|
{"stp2", false}, // an SPA route
|
||||||
|
{"index", false}, // the landing canvas's key
|
||||||
{"stp-fan-page", true}, // only whole segments are reserved
|
{"stp-fan-page", true}, // only whole segments are reserved
|
||||||
} {
|
} {
|
||||||
err := validateSlug(c.slug)
|
err := validateSlug(c.slug)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# The background behind a canvas page, keyed by the same page key as its
|
# The background behind a canvas page, keyed by the same page key as its
|
||||||
# boxes ("index" for the landing page, "stp", or a Page's slug), so the
|
# boxes ("index" for the landing page, or a Page's slug), so the landing
|
||||||
# landing page and every shrine are set the same way. Edited from the
|
# page and every other canvas page are set the same way. Edited from the
|
||||||
# canvas's "Background" button; see models.Background.
|
# canvas's "Background" button; see models.Background.
|
||||||
#
|
#
|
||||||
# Anyone may read it, as part of the page, except that an adminOnly page's
|
# Anyone may read it, as part of the page, except that an adminOnly page's
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# Boxes on a canvas page: the home page (/stp, page "stp"), the landing
|
# Boxes on a canvas page: the landing page (page "index") or an
|
||||||
# page's overlay (page "index") or an admin-created Page (page = its slug).
|
# admin-created Page (page = its slug; the home page /stp is the Page "stp").
|
||||||
# Anyone may read a page's layout — it is the page — but only an admin may
|
# Anyone may read a page's layout — it is the page — but only an admin may
|
||||||
# change it, and adminOnly boxes are only ever returned to an admin. x/y/w/h
|
# change it, and adminOnly boxes are only ever returned to an admin. x/y/w/h
|
||||||
# are px on a fixed 1400px-wide design canvas; see models.Box.
|
# are px on a fixed 1400px-wide design canvas; see models.Box.
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
# Saved layouts: a named copy of one canvas page's boxes and background,
|
||||||
|
# which can be loaded onto any canvas page — the landing page ("index") or a
|
||||||
|
# Page's slug. Loading copies: the new boxes belong to the target page, so
|
||||||
|
# editing a page afterwards never changes the layout or another page. Moving
|
||||||
|
# a layout is saving it on one page and loading it on another with
|
||||||
|
# replace: true. See models.Layout and graph/layout_helpers.go.
|
||||||
|
#
|
||||||
|
# Admin only throughout, reads included, because a layout keeps a page's
|
||||||
|
# adminOnly boxes along with the rest.
|
||||||
|
|
||||||
|
type Layout {
|
||||||
|
id: ID!
|
||||||
|
createdAt: Time!
|
||||||
|
updatedAt: Time!
|
||||||
|
name: String!
|
||||||
|
# The page key it was saved from.
|
||||||
|
sourcePage: String!
|
||||||
|
boxCount: Int!
|
||||||
|
hasBackground: Boolean!
|
||||||
|
}
|
||||||
|
|
||||||
|
input CreateLayoutInput {
|
||||||
|
name: String!
|
||||||
|
# The page key to save, as it is now.
|
||||||
|
page: String!
|
||||||
|
}
|
||||||
|
|
||||||
|
input UpdateLayoutInput {
|
||||||
|
name: String
|
||||||
|
}
|
||||||
|
|
||||||
|
extend type Query {
|
||||||
|
# Newest first.
|
||||||
|
layouts: [Layout!]! @admin
|
||||||
|
}
|
||||||
|
|
||||||
|
extend type Mutation {
|
||||||
|
createLayout(input: CreateLayoutInput!): Layout! @admin
|
||||||
|
# Renames it; what a layout holds never changes after it is saved.
|
||||||
|
updateLayout(id: ID!, input: UpdateLayoutInput!): Layout! @admin
|
||||||
|
deleteLayout(id: ID!): Layout! @admin
|
||||||
|
# Copies the layout onto `page` and answers with that page's boxes.
|
||||||
|
# replace: false adds the copies on top of what is there, leaving the
|
||||||
|
# background alone. replace: true first saves the page as a layout named
|
||||||
|
# "<page> before <layout>, <time>", then swaps its boxes and background
|
||||||
|
# for the layout's.
|
||||||
|
applyLayout(id: ID!, page: String!, replace: Boolean!): [Box!]! @admin
|
||||||
|
}
|
||||||
@@ -157,9 +157,9 @@ type Place struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Box is one panel on a canvas page. Page names the canvas it belongs to:
|
// Box is one panel on a canvas page. Page names the canvas it belongs to:
|
||||||
// "stp" for the home page, "index" for the landing page's overlay, or a
|
// "index" for the landing page, or a Page.Slug for an admin-created page
|
||||||
// Page.Slug for an admin-created page — it is a key, not a foreign key, so the
|
// (the home page is the Page "stp") — it is a key, not a foreign key, so the
|
||||||
// built-in canvases need no Page row. Its position and size are in px on a
|
// built-in landing canvas needs no Page row. Its position and size are in px on a
|
||||||
// fixed 1400px-wide design canvas, which the page scales down on narrower
|
// fixed 1400px-wide design canvas, which the page scales down on narrower
|
||||||
// screens — so the stored numbers mean the same thing for every visitor. Kind "widget" renders a built-in Vue component named by Widget;
|
// screens — so the stored numbers mean the same thing for every visitor. Kind "widget" renders a built-in Vue component named by Widget;
|
||||||
// kind "html" renders HTML in a sandboxed iframe on the front end, which is
|
// kind "html" renders HTML in a sandboxed iframe on the front end, which is
|
||||||
@@ -207,7 +207,7 @@ type Page struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Background is the page background behind one canvas (Page is the same page
|
// Background is the page background behind one canvas (Page is the same page
|
||||||
// key a Box has: "index" for the landing page, "stp", or a Page's slug), so
|
// key a Box has: "index" for the landing page, or a Page's slug), so
|
||||||
// built-in canvases and admin-created pages are set the same way. A page with
|
// built-in canvases and admin-created pages are set the same way. A page with
|
||||||
// no row shows the theme's halftone; deleting the row is "reset to default".
|
// no row shows the theme's halftone; deleting the row is "reset to default".
|
||||||
// The unique index is partial for the same reason as Page's.
|
// The unique index is partial for the same reason as Page's.
|
||||||
@@ -224,3 +224,25 @@ type Background struct {
|
|||||||
// Fit is how Image fills the window: "cover", "contain" or "tile".
|
// Fit is how Image fills the window: "cover", "contain" or "tile".
|
||||||
Fit string `gorm:"not null;default:cover" json:"fit"`
|
Fit string `gorm:"not null;default:cover" json:"fit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Layout is a named copy of one canvas page's boxes and background, saved so
|
||||||
|
// it can be loaded onto any page later (graph/layout_helpers.go). It is a
|
||||||
|
// snapshot, not a link: loading it creates new boxes that belong to the
|
||||||
|
// target page, so editing either page afterwards never touches the other or
|
||||||
|
// the layout. The content is JSON rather than child rows because nothing
|
||||||
|
// queries inside it — it is only ever written whole and read whole. The
|
||||||
|
// unique index is partial for the same reason as Page's.
|
||||||
|
type Layout struct {
|
||||||
|
ID uint `gorm:"primarykey" json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedAt"`
|
||||||
|
Name string `gorm:"not null;index:idx_layouts_name,unique,where:deleted_at IS NULL" json:"name"`
|
||||||
|
// SourcePage is the page key it was saved from, for the list only.
|
||||||
|
SourcePage string `gorm:"not null" json:"sourcePage"`
|
||||||
|
// Boxes is a JSON array of the boxes' content and geometry, without id
|
||||||
|
// or page.
|
||||||
|
Boxes string `gorm:"type:text;not null" json:"-"`
|
||||||
|
// Background is the page's background as JSON, or nil if it had none.
|
||||||
|
Background *string `gorm:"type:text" json:"-"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -54,12 +54,29 @@ func migrateDatabase(db *gorm.DB) error {
|
|||||||
&models.Box{},
|
&models.Box{},
|
||||||
&models.Page{},
|
&models.Page{},
|
||||||
&models.Background{},
|
&models.Background{},
|
||||||
|
&models.Layout{},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return ensureStpPage(db)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensureStpPage turns the home page (/stp) into an ordinary canvas Page once.
|
||||||
|
// It used to be a built-in canvas with its own route; its boxes and
|
||||||
|
// background were already keyed "stp", so a Page row with that slug is all
|
||||||
|
// it takes. Unscoped, so that deleting the page on purpose sticks rather than
|
||||||
|
// bringing it back on the next start.
|
||||||
|
func ensureStpPage(db *gorm.DB) error {
|
||||||
|
var count int64
|
||||||
|
if err := db.Unscoped().Model(&models.Page{}).Where("slug = ?", "stp").Count(&count).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if count > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return db.Create(&models.Page{Slug: "stp", Title: "STP"}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitDatabase connects to Postgres and runs the auto-migration.
|
// InitDatabase connects to Postgres and runs the auto-migration.
|
||||||
|
|||||||
+23
-7
@@ -64,7 +64,7 @@ Two layout shells, defined in `src/router/index.js`:
|
|||||||
| Path | Layout | Notes |
|
| Path | Layout | Notes |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `/` | DefaultLayout | Landing page (statically imported — it's the first paint): a box canvas, page key `index`; the old fixed page is its starter layout, `views/landing/landingLayout.js` |
|
| `/` | DefaultLayout | Landing page (statically imported — it's the first paint): a box canvas, page key `index`; the old fixed page is its starter layout, `views/landing/landingLayout.js` |
|
||||||
| `/stp` | DefaultLayout | The personal home page: an admin-editable canvas of boxes (`views/home3/`, see "The /stp canvas" below) |
|
| `/stp` | DefaultLayout | The personal home page: an ordinary canvas page (the `Page` with slug `stp`) served by the catch-all, see "The /stp canvas" below |
|
||||||
| `/admin`, `/admin/login` | DefaultLayout | `/admin` is guarded by `meta.requiresAdmin` |
|
| `/admin`, `/admin/login` | DefaultLayout | `/admin` is guarded by `meta.requiresAdmin` |
|
||||||
| `/automata`, `/hotels` | DefaultLayout | |
|
| `/automata`, `/hotels` | DefaultLayout | |
|
||||||
| `/shrines`, `/shrines/*` | DefaultLayout | All canvas pages via the catch-all: `/shrines` is an index whose links are Link boxes placed by hand |
|
| `/shrines`, `/shrines/*` | DefaultLayout | All canvas pages via the catch-all: `/shrines` is an index whose links are Link boxes placed by hand |
|
||||||
@@ -227,14 +227,18 @@ so every visitor sees the saved layout. The canvas is `views/home3/BoxCanvas.vue
|
|||||||
and it is not only `/stp`: every box has a `page` key, and the same component
|
and it is not only `/stp`: every box has a `page` key, and the same component
|
||||||
renders any page's boxes.
|
renders any page's boxes.
|
||||||
|
|
||||||
- **Pages.** `"stp"` is `/stp` (`Home3.vue`). `"index"` is the landing page
|
- **Pages.** `"index"` is the landing page
|
||||||
(`Landing.vue`), which is nothing but the canvas. Any other key is the slug of a **`Page`** (GraphQL
|
(`Landing.vue`), which is nothing but the canvas. Any other key is the slug of a **`Page`** (GraphQL
|
||||||
type, `stores/pages.js`), an admin-created page served at `/<slug>` by the
|
type, `stores/pages.js`), an admin-created page served at `/<slug>` by the
|
||||||
router's catch-all (`views/canvas/CanvasPage.vue`). Pages are created from
|
router's catch-all (`views/canvas/CanvasPage.vue`). Pages are created from
|
||||||
the admin panel's Pages tab (which also has a "New shrine" form, a blank page
|
the admin panel's Pages tab (which also has a "New shrine" form, a blank page
|
||||||
under `shrines/`), or from the 404 of the address you want; each can start
|
under `shrines/`), or from the 404 of the address you want; each can start
|
||||||
from a layout in `views/canvas/pageStarters.js` (Blank, Notes board). Title, address and visibility are under "Page
|
from a layout in `views/canvas/pageStarters.js` (Blank, Notes board, Old /stp grid). Title, address and visibility are under "Page
|
||||||
settings" on the page; renaming moves its boxes, deleting takes them too.
|
settings" on the page; renaming moves its boxes, deleting takes them too.
|
||||||
|
`/stp` is one of these pages too (slug `stp`): it used to have its own route
|
||||||
|
(`Home3.vue`, now legacy), and the backend creates its `Page` row once at
|
||||||
|
start-up (`ensureStpPage` in `backend/services/database.go`), so it can be
|
||||||
|
renamed, hidden or deleted like any other.
|
||||||
The server refuses slugs that an SPA or nginx route would answer first
|
The server refuses slugs that an SPA or nginx route would answer first
|
||||||
(`validateSlug` in `backend/graph/page_helpers.go`) — add to that list when
|
(`validateSlug` in `backend/graph/page_helpers.go`) — add to that list when
|
||||||
adding a route.
|
adding a route.
|
||||||
@@ -247,6 +251,18 @@ renders any page's boxes.
|
|||||||
it behind the whole window, navbar included, while that canvas is mounted,
|
it behind the whole window, navbar included, while that canvas is mounted,
|
||||||
and falls back to the halftone. Renaming or deleting a page carries its
|
and falls back to the halftone. Renaming or deleting a page carries its
|
||||||
background along; an admin-only page's background is hidden with it.
|
background along; an admin-only page's background is hidden with it.
|
||||||
|
- **Saved layouts.** A **`Layout`** (GraphQL type, `stores/layouts.js`) is a
|
||||||
|
named copy of one page's boxes and background, made with the "Layouts"
|
||||||
|
button next to "Background" (`LayoutPanel.vue`). "Load here" copies a layout
|
||||||
|
onto the page on screen; the admin panel's Pages tab copies one onto any page
|
||||||
|
without opening it. Loading onto a page with boxes asks whether to replace
|
||||||
|
them or add on top (copies stacked above). A replace first saves the page
|
||||||
|
as a layout called "<page> before <layout>, <time>", so it can be undone by
|
||||||
|
loading that back. They are copies, not links: editing a page never changes
|
||||||
|
a layout or another page. That is also how a layout moves: save it on one
|
||||||
|
page, load it on another. The copying happens on the server
|
||||||
|
(`backend/graph/layout_helpers.go`); the browser only sees names and box
|
||||||
|
counts. All of it is admin-only, since a layout keeps admin-only boxes.
|
||||||
- **Admin only.** A box or a page can be marked admin-only. The server never
|
- **Admin only.** A box or a page can be marked admin-only. The server never
|
||||||
sends those to anyone else, so they are fit for private notes; admins see
|
sends those to anyone else, so they are fit for private notes; admins see
|
||||||
such boxes outlined, with a 🔒 in edit mode. The "Note" template starts
|
such boxes outlined, with a 🔒 in edit mode. The "Note" template starts
|
||||||
@@ -284,9 +300,9 @@ renders any page's boxes.
|
|||||||
drop would (`UploadPicker`). Starter HTML is in `templates.js`; links in a box
|
drop would (`UploadPicker`). Starter HTML is in `templates.js`; links in a box
|
||||||
need `target="_top"` or `_blank` (the Link templates set it), or they open
|
need `target="_top"` or `_blank` (the Link templates set it), or they open
|
||||||
inside the frame. A canvas given a `starter` has an import button in edit
|
inside the frame. A canvas given a `starter` has an import button in edit
|
||||||
mode (it confirms first if the page isn't empty): on `/stp`, "Import current
|
mode (it confirms first if the page isn't empty): only `/` has one, "Import
|
||||||
layout" recreates the old `Home.vue` grid from `defaultLayout.js`; on `/`,
|
old landing page", which recreates the old bio and links. The old `Home.vue`
|
||||||
"Import old landing page" recreates the old bio and links.
|
grid (`defaultLayout.js`) is the "Old /stp grid" starter for a new page.
|
||||||
- **Phones (≤700px)** get no canvas: boxes stack full-width in `(y, x)` order at
|
- **Phones (≤700px)** get no canvas: boxes stack full-width in `(y, x)` order at
|
||||||
their saved height, skipping any with `hideOnMobile`. There is no separate
|
their saved height, skipping any with `hideOnMobile`. There is no separate
|
||||||
mobile layout. To change the order, move boxes on the desktop canvas.
|
mobile layout. To change the order, move boxes on the desktop canvas.
|
||||||
@@ -331,7 +347,7 @@ in its header comment; the summary:
|
|||||||
|
|
||||||
| File | Status |
|
| File | Status |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `views/home3/Home3.vue` | live (`/stp`) — the box canvas; its widget boxes use **Intro3** and **Gym2** |
|
| `views/home3/Home3.vue` | legacy: `/stp`'s old route, before it became a canvas `Page`; no route. The rest of `views/home3/` (`BoxCanvas.vue` and friends) is live |
|
||||||
| `views/home/shrines/{Shrines,Demoman,GTO,Evangelion,Skipskipbenben}.vue` | the old `/shrines` index and hand-written shrines (Demoman a video wall, the rest `<Wip />`), unrouted; shrines are canvas pages now |
|
| `views/home/shrines/{Shrines,Demoman,GTO,Evangelion,Skipskipbenben}.vue` | the old `/shrines` index and hand-written shrines (Demoman a video wall, the rest `<Wip />`), unrouted; shrines are canvas pages now |
|
||||||
| `views/home/Home.vue` | legacy fixed grid that `/stp` used to be; no route. Its widgets are still live through `home3/widgetRegistry.js` |
|
| `views/home/Home.vue` | legacy fixed grid that `/stp` used to be; no route. Its widgets are still live through `home3/widgetRegistry.js` |
|
||||||
| `views/home/Intro.vue` | superseded by `Intro2.vue`; not imported |
|
| `views/home/Intro.vue` | superseded by `Intro2.vue`; not imported |
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ defineProps({
|
|||||||
title: { type: String, default: "Are you sure?" },
|
title: { type: String, default: "Are you sure?" },
|
||||||
message: { type: String, required: true },
|
message: { type: String, required: true },
|
||||||
confirmLabel: { type: String, default: "Confirm" },
|
confirmLabel: { type: String, default: "Confirm" },
|
||||||
|
// A second, milder choice beside the confirm button, e.g. "Add on top"
|
||||||
|
// next to "Replace". Omitted, there are only Confirm and Cancel.
|
||||||
|
secondaryLabel: { type: String, default: "" },
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits(["confirm", "cancel"]);
|
const emit = defineEmits(["confirm", "secondary", "cancel"]);
|
||||||
|
|
||||||
function cancel() {
|
function cancel() {
|
||||||
open.value = false;
|
open.value = false;
|
||||||
@@ -20,6 +23,11 @@ function confirm() {
|
|||||||
open.value = false;
|
open.value = false;
|
||||||
emit("confirm");
|
emit("confirm");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function secondary() {
|
||||||
|
open.value = false;
|
||||||
|
emit("secondary");
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -29,6 +37,7 @@ function confirm() {
|
|||||||
<p>{{ message }}</p>
|
<p>{{ message }}</p>
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<button type="button" class="confirm-button" @click="confirm">{{ confirmLabel }}</button>
|
<button type="button" class="confirm-button" @click="confirm">{{ confirmLabel }}</button>
|
||||||
|
<button v-if="secondaryLabel" type="button" @click="secondary">{{ secondaryLabel }}</button>
|
||||||
<button type="button" class="cancel-button" @click="cancel">Cancel</button>
|
<button type="button" class="cancel-button" @click="cancel">Cancel</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -33,11 +33,6 @@ const router = createRouter({
|
|||||||
name: "landing",
|
name: "landing",
|
||||||
component: Landing,
|
component: Landing,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "stp",
|
|
||||||
name: "home",
|
|
||||||
component: () => import("@/views/home3/Home3.vue"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "admin/login",
|
path: "admin/login",
|
||||||
name: "admin-login",
|
name: "admin-login",
|
||||||
@@ -66,9 +61,10 @@ const router = createRouter({
|
|||||||
component: () =>
|
component: () =>
|
||||||
import("@/views/architecture/Architecture.vue"),
|
import("@/views/architecture/Architecture.vue"),
|
||||||
},
|
},
|
||||||
// /shrines and the shrines under it are canvas pages, made
|
// /stp, /shrines and the shrines under it are canvas pages,
|
||||||
// from the admin panel's Pages tab and served by the catch-all
|
// made from the admin panel's Pages tab and served by the
|
||||||
// below. The old hand-written ones (views/home/shrines/) are
|
// catch-all below. /stp's old route (views/home3/Home3.vue)
|
||||||
|
// and the hand-written shrines (views/home/shrines/) are
|
||||||
// unrouted.
|
// unrouted.
|
||||||
// Anything else is an admin-created canvas page if one exists
|
// Anything else is an admin-created canvas page if one exists
|
||||||
// at that address (the Page GraphQL type), else the 404.
|
// at that address (the Page GraphQL type), else the 404.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Page backgrounds (the `Background` GraphQL type), one per canvas page key —
|
* Page backgrounds (the `Background` GraphQL type), one per canvas page key —
|
||||||
* "index" for the landing page, "stp", or a Page slug such as
|
* "index" for the landing page, or a Page slug such as "stp" or
|
||||||
* "shrines/evangelion" — and which one is on screen.
|
* "shrines/evangelion" — and which one is on screen.
|
||||||
*
|
*
|
||||||
* DefaultLayout paints `style` behind everything, navbar included, so a
|
* DefaultLayout paints `style` behind everything, navbar included, so a
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
* Boxes on one canvas page (views/home3/BoxCanvas.vue) — full CRUD, built on
|
* Boxes on one canvas page (views/home3/BoxCanvas.vue) — full CRUD, built on
|
||||||
* createCrudStore().
|
* createCrudStore().
|
||||||
*
|
*
|
||||||
* `useBoxesStore(page)` returns the store for that page key: "stp" for the
|
* `useBoxesStore(page)` returns the store for that page key: "index" for the
|
||||||
* home page, "index" for the landing page's overlay, or a Page slug. Each key
|
* landing page, or a Page slug ("stp" for the home page). Each key
|
||||||
* gets its own Pinia store (id `boxes:<page>`), so moving between pages
|
* gets its own Pinia store (id `boxes:<page>`), so moving between pages
|
||||||
* neither refetches a page already visited nor mixes two pages' boxes.
|
* neither refetches a page already visited nor mixes two pages' boxes.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/**
|
||||||
|
* Saved layouts (the `Layout` GraphQL type): named copies of a canvas page's
|
||||||
|
* boxes and background — full CRUD, built on createCrudStore(), plus apply().
|
||||||
|
*
|
||||||
|
* `create({ name, page })` saves that page as it is now; `update` only
|
||||||
|
* renames. What a layout holds never reaches the browser, only its size: the
|
||||||
|
* server does both the copying in and the copying out.
|
||||||
|
*
|
||||||
|
* Admin only, so nothing fetches it until an admin opens a layouts list
|
||||||
|
* (views/home3/LayoutPanel.vue, the admin panel's Pages tab).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { createCrudStore } from "@/stores/createCrudStore";
|
||||||
|
import { gql } from "@/graphql";
|
||||||
|
import { useBoxesStore } from "@/stores/boxes";
|
||||||
|
import { useBackgroundStore } from "@/stores/background";
|
||||||
|
|
||||||
|
const LAYOUT_FIELDS = `
|
||||||
|
id
|
||||||
|
name
|
||||||
|
sourcePage
|
||||||
|
boxCount
|
||||||
|
hasBackground
|
||||||
|
createdAt
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const useLayoutsStore = createCrudStore("layouts", {
|
||||||
|
type: "Layout",
|
||||||
|
list: "layouts",
|
||||||
|
fields: LAYOUT_FIELDS,
|
||||||
|
// The list query is newest first.
|
||||||
|
insert: "prepend",
|
||||||
|
deleteReturns: "object",
|
||||||
|
extend: ({ fetch }) => ({
|
||||||
|
/**
|
||||||
|
* Copy layout `id` onto page key `page`, replacing what is there or
|
||||||
|
* adding on top. Throws on failure.
|
||||||
|
*/
|
||||||
|
async apply(id, page, replace) {
|
||||||
|
await gql(
|
||||||
|
`mutation ApplyLayout($id: ID!, $page: String!, $replace: Boolean!) {
|
||||||
|
applyLayout(id: $id, page: $page, replace: $replace) { id }
|
||||||
|
}`,
|
||||||
|
{ id, page, replace },
|
||||||
|
);
|
||||||
|
// The page's own stores are refetched rather than patched from the
|
||||||
|
// answer, so they stay in the shape their list query gives. A replace
|
||||||
|
// also saved the old page as a new layout, hence the list too.
|
||||||
|
await Promise.all([useBoxesStore(page).fetch(), useBackgroundStore().load(page), replace && fetch()]);
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
/** How a page key reads to a person: "/" for the landing page. */
|
||||||
|
export function pagePath(page) {
|
||||||
|
return page === "index" ? "/" : `/${page}`;
|
||||||
|
}
|
||||||
@@ -7,8 +7,13 @@
|
|||||||
* "New shrine" is the same form with the address fixed under /shrines/. It
|
* "New shrine" is the same form with the address fixed under /shrines/. It
|
||||||
* starts blank and adds no link anywhere: /shrines is itself a canvas page,
|
* starts blank and adds no link anywhere: /shrines is itself a canvas page,
|
||||||
* and its links are boxes put there by hand.
|
* and its links are boxes put there by hand.
|
||||||
|
*
|
||||||
|
* "Layouts" lists the saved layouts (stores/layouts.js) and copies one onto
|
||||||
|
* any page without opening it — the same as "Load here" in that page's
|
||||||
|
* Layouts panel, where layouts are also saved and renamed.
|
||||||
*/
|
*/
|
||||||
import { usePagesStore } from "@/stores/pages";
|
import { usePagesStore } from "@/stores/pages";
|
||||||
|
import { pagePath, useLayoutsStore } from "@/stores/layouts";
|
||||||
import PageForm from "@/views/canvas/PageForm.vue";
|
import PageForm from "@/views/canvas/PageForm.vue";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
import ConfirmDialog from "@/components/util/ConfirmDialog.vue";
|
import ConfirmDialog from "@/components/util/ConfirmDialog.vue";
|
||||||
@@ -19,6 +24,46 @@ const removeTarget = ref(null);
|
|||||||
const confirmationOpen = ref(false);
|
const confirmationOpen = ref(false);
|
||||||
const removeError = ref("");
|
const removeError = ref("");
|
||||||
|
|
||||||
|
const layouts = useLayoutsStore();
|
||||||
|
layouts.fetch();
|
||||||
|
const layoutError = ref("");
|
||||||
|
const layoutNotice = ref("");
|
||||||
|
// { layout, page } waiting on "replace or add?", and the layout to delete.
|
||||||
|
const copyRequest = ref(null);
|
||||||
|
const deleteLayoutTarget = ref(null);
|
||||||
|
|
||||||
|
function askCopy(layout, event) {
|
||||||
|
const page = event.target.value;
|
||||||
|
event.target.value = "";
|
||||||
|
if (page) copyRequest.value = { layout, page };
|
||||||
|
}
|
||||||
|
|
||||||
|
async function layoutAction(action, done) {
|
||||||
|
layoutError.value = "";
|
||||||
|
layoutNotice.value = "";
|
||||||
|
try {
|
||||||
|
await action();
|
||||||
|
layoutNotice.value = done;
|
||||||
|
} catch (err) {
|
||||||
|
layoutError.value = err?.message || "Failed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function copy(replace) {
|
||||||
|
const { layout, page } = copyRequest.value;
|
||||||
|
copyRequest.value = null;
|
||||||
|
layoutAction(
|
||||||
|
() => layouts.apply(layout.id, page, replace),
|
||||||
|
`“${layout.name}” ${replace ? "now fills" : "was added to"} ${pagePath(page)}.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmDeleteLayout() {
|
||||||
|
const layout = deleteLayoutTarget.value;
|
||||||
|
deleteLayoutTarget.value = null;
|
||||||
|
layoutAction(() => layouts.remove(layout.id), `Deleted “${layout.name}”.`);
|
||||||
|
}
|
||||||
|
|
||||||
async function remove(page) {
|
async function remove(page) {
|
||||||
removeTarget.value = page;
|
removeTarget.value = page;
|
||||||
confirmationOpen.value = true;
|
confirmationOpen.value = true;
|
||||||
@@ -42,8 +87,8 @@ async function confirmRemove() {
|
|||||||
<section>
|
<section>
|
||||||
<h1>Pages</h1>
|
<h1>Pages</h1>
|
||||||
<p class="text-muted">
|
<p class="text-muted">
|
||||||
The home page (/stp) and the landing page's notes are canvases too —
|
The landing page (/) is a canvas too, but not listed here — edit it on
|
||||||
edit those on the pages themselves.
|
the page itself.
|
||||||
</p>
|
</p>
|
||||||
<p v-if="removeError" class="text-tertiary" role="alert">
|
<p v-if="removeError" class="text-tertiary" role="alert">
|
||||||
{{ removeError }}
|
{{ removeError }}
|
||||||
@@ -64,6 +109,39 @@ async function confirmRemove() {
|
|||||||
<p v-else-if="pages.loaded" class="text-muted">No pages yet.</p>
|
<p v-else-if="pages.loaded" class="text-muted">No pages yet.</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h1>Layouts</h1>
|
||||||
|
<p class="text-muted">
|
||||||
|
Saved copies of a page's boxes and background. Save one from a page's
|
||||||
|
Layouts button; copy it onto another page here or from that page.
|
||||||
|
Replacing a page's contents saves them as a layout first.
|
||||||
|
</p>
|
||||||
|
<p v-if="layoutError" class="text-tertiary" role="alert">{{ layoutError }}</p>
|
||||||
|
<p v-else-if="layoutNotice" class="text-muted" role="status">{{ layoutNotice }}</p>
|
||||||
|
<p v-if="layouts.error" class="text-tertiary">Couldn't load the layouts.</p>
|
||||||
|
<table v-else-if="layouts.layouts.length" class="w-full">
|
||||||
|
<tr v-for="layout in layouts.layouts" :key="layout.id">
|
||||||
|
<td>{{ layout.name }}</td>
|
||||||
|
<td class="text-muted">
|
||||||
|
from {{ pagePath(layout.sourcePage) }} · {{ layout.boxCount }} box{{ layout.boxCount === 1 ? "" : "es" }}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<select class="copy-select" aria-label="Copy onto page" @change="askCopy(layout, $event)">
|
||||||
|
<option value="">Copy onto…</option>
|
||||||
|
<option value="index">/ (landing)</option>
|
||||||
|
<option v-for="page in pages.pages" :key="page.id" :value="page.slug">/{{ page.slug }}</option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
<td class="text-right">
|
||||||
|
<button type="button" class="text-tertiary cursor-pointer" @click="deleteLayoutTarget = layout">
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<p v-else-if="layouts.loaded" class="text-muted">No saved layouts yet.</p>
|
||||||
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<h1>New shrine</h1>
|
<h1>New shrine</h1>
|
||||||
<p class="text-muted">
|
<p class="text-muted">
|
||||||
@@ -87,5 +165,34 @@ async function confirmRemove() {
|
|||||||
@confirm="confirmRemove"
|
@confirm="confirmRemove"
|
||||||
@cancel="removeTarget = null"
|
@cancel="removeTarget = null"
|
||||||
/>
|
/>
|
||||||
|
<ConfirmDialog
|
||||||
|
v-if="copyRequest"
|
||||||
|
:model-value="true"
|
||||||
|
title="Copy layout"
|
||||||
|
:message="`Replace everything on ${pagePath(copyRequest.page)} with “${copyRequest.layout.name}”, or add it on top? Replacing saves the page as a layout first.`"
|
||||||
|
confirm-label="Replace"
|
||||||
|
secondary-label="Add on top"
|
||||||
|
@confirm="copy(true)"
|
||||||
|
@secondary="copy(false)"
|
||||||
|
@cancel="copyRequest = null"
|
||||||
|
/>
|
||||||
|
<ConfirmDialog
|
||||||
|
v-if="deleteLayoutTarget"
|
||||||
|
:model-value="true"
|
||||||
|
title="Delete layout"
|
||||||
|
:message="`Delete the layout “${deleteLayoutTarget.name}”? Pages it was copied onto keep their boxes.`"
|
||||||
|
confirm-label="Delete"
|
||||||
|
@confirm="confirmDeleteLayout"
|
||||||
|
@cancel="deleteLayoutTarget = null"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.copy-select {
|
||||||
|
padding: 0.25rem;
|
||||||
|
color: var(--color-primary);
|
||||||
|
background: var(--color-surface-deep);
|
||||||
|
border: 1px solid var(--color-primary);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -9,8 +9,8 @@
|
|||||||
<DiagramFigure id="frontend-route-tree" title="The route tree and its layouts" :min-width="800">
|
<DiagramFigure id="frontend-route-tree" title="The route tree and its layouts" :min-width="800">
|
||||||
<svg class="dg" viewBox="0 0 1140 640" role="img" aria-labelledby="frontend-route-tree-t">
|
<svg class="dg" viewBox="0 0 1140 640" role="img" aria-labelledby="frontend-route-tree-t">
|
||||||
<title id="frontend-route-tree-t">
|
<title id="frontend-route-tree-t">
|
||||||
Vue Router table: DefaultLayout holding the landing page, /stp, admin routes, automata, hotels and
|
Vue Router table: DefaultLayout holding the landing page, admin routes, automata, hotels and
|
||||||
the catch-all CanvasPage; /stp2 with no layout; /cv inside CVLayout
|
the catch-all CanvasPage (which serves /stp); /stp2 with no layout; /cv inside CVLayout
|
||||||
</title>
|
</title>
|
||||||
|
|
||||||
<!-- Router -->
|
<!-- Router -->
|
||||||
@@ -47,14 +47,13 @@
|
|||||||
|
|
||||||
<!-- Trunk to DefaultLayout children -->
|
<!-- Trunk to DefaultLayout children -->
|
||||||
<path class="dg-edge dg-edge--plain" d="M450,211 H475" />
|
<path class="dg-edge dg-edge--plain" d="M450,211 H475" />
|
||||||
<path class="dg-edge dg-edge--plain" d="M475,43 V379" />
|
<path class="dg-edge dg-edge--plain" d="M475,43 V323" />
|
||||||
<path class="dg-edge" d="M475,43 H496" />
|
<path class="dg-edge" d="M475,43 H496" />
|
||||||
<path class="dg-edge" d="M475,99 H496" />
|
<path class="dg-edge" d="M475,99 H496" />
|
||||||
<path class="dg-edge" d="M475,155 H496" />
|
<path class="dg-edge dg-edge--pink" d="M475,155 H496" />
|
||||||
<path class="dg-edge dg-edge--pink" d="M475,211 H496" />
|
<path class="dg-edge" d="M475,211 H496" />
|
||||||
<path class="dg-edge" d="M475,267 H496" />
|
<path class="dg-edge" d="M475,267 H496" />
|
||||||
<path class="dg-edge" d="M475,323 H496" />
|
<path class="dg-edge" d="M475,323 H496" />
|
||||||
<path class="dg-edge" d="M475,379 H496" />
|
|
||||||
<path class="dg-edge dg-edge--muted" d="M450,453 H496" />
|
<path class="dg-edge dg-edge--muted" d="M450,453 H496" />
|
||||||
<path class="dg-edge" d="M450,523 H496" />
|
<path class="dg-edge" d="M450,523 H496" />
|
||||||
|
|
||||||
@@ -110,18 +109,16 @@ import DiagramFigure from "../../DiagramFigure.vue";
|
|||||||
const rows = [
|
const rows = [
|
||||||
{ y: 20, path: "/", name: "landing", file: "views/landing/Landing.vue", static: true,
|
{ y: 20, path: "/", name: "landing", file: "views/landing/Landing.vue", static: true,
|
||||||
note: "BoxCanvas page=\"index\"; the canvas itself is a defineAsyncComponent chunk" },
|
note: "BoxCanvas page=\"index\"; the canvas itself is a defineAsyncComponent chunk" },
|
||||||
{ y: 76, path: "/stp", name: "home", file: "views/home3/Home3.vue",
|
{ y: 76, path: "/admin/login", name: "admin-login", file: "views/admin/Login.vue",
|
||||||
note: "BoxCanvas page=\"stp\" with the defaultLayout.js starter" },
|
|
||||||
{ y: 132, path: "/admin/login", name: "admin-login", file: "views/admin/Login.vue",
|
|
||||||
note: "not guarded: calls auth.ensureLoaded() itself for its \"Already signed in\" card" },
|
note: "not guarded: calls auth.ensureLoaded() itself for its \"Already signed in\" card" },
|
||||||
{ y: 188, path: "/admin", name: "admin", file: "views/admin/Admin.vue", admin: true,
|
{ y: 132, path: "/admin", name: "admin", file: "views/admin/Admin.vue", admin: true,
|
||||||
note: "meta: { requiresAdmin: true }, the only flag the beforeEach guard acts on" },
|
note: "meta: { requiresAdmin: true }, the only flag the beforeEach guard acts on" },
|
||||||
{ y: 244, path: "/automata", name: "mobile-automata", file: "views/automata/MobileAutomata.vue",
|
{ y: 188, path: "/automata", name: "mobile-automata", file: "views/automata/MobileAutomata.vue",
|
||||||
note: "Turing machine / mobile automaton drawn to a <canvas>" },
|
note: "Turing machine / mobile automaton drawn to a <canvas>" },
|
||||||
{ y: 300, path: "/hotels", name: "cheap-hotels", file: "views/hotels/CheapHotels.vue",
|
{ y: 244, path: "/hotels", name: "cheap-hotels", file: "views/hotels/CheapHotels.vue",
|
||||||
note: "Travelodge price scanner over /py/hotels (NDJSON streams via fetch)" },
|
note: "Travelodge price scanner over /py/hotels (NDJSON streams via fetch)" },
|
||||||
{ y: 356, path: "/:pathMatch(.*)*", name: "404", file: "views/canvas/CanvasPage.vue",
|
{ y: 300, path: "/:pathMatch(.*)*", name: "404", file: "views/canvas/CanvasPage.vue",
|
||||||
note: "any other path: query page(slug) → BoxCanvas for that slug, else the 404 view" },
|
note: "any other path, /stp included: query page(slug) → BoxCanvas for that slug, else the 404 view" },
|
||||||
{ y: 430, path: "/stp2", name: "home2", file: "views/home2/Home2.vue", bare: true,
|
{ y: 430, path: "/stp2", name: "home2", file: "views/home2/Home2.vue", bare: true,
|
||||||
note: "static full-bleed CSS mock: no navbar, no footer, unlinked" },
|
note: "static full-bleed CSS mock: no navbar, no footer, unlinked" },
|
||||||
{ y: 500, path: "/cv", name: "cv", file: "views/CV/CV.vue",
|
{ y: 500, path: "/cv", name: "cv", file: "views/CV/CV.vue",
|
||||||
|
|||||||
@@ -3,7 +3,12 @@
|
|||||||
* (PageForm.vue). Each `boxes(title)` returns box inputs for
|
* (PageForm.vue). Each `boxes(title)` returns box inputs for
|
||||||
* stores/boxes.js — without `page`, which the store adds. Everything is an
|
* stores/boxes.js — without `page`, which the store adds. Everything is an
|
||||||
* ordinary box afterwards: move it, edit it, delete it.
|
* ordinary box afterwards: move it, edit it, delete it.
|
||||||
|
*
|
||||||
|
* These are built into the code; layouts saved from a page in the browser
|
||||||
|
* live in stores/layouts.js and are loaded from the canvas's Layouts panel.
|
||||||
*/
|
*/
|
||||||
|
import { defaultLayout } from "@/views/home3/defaultLayout";
|
||||||
|
|
||||||
const html = (title, body, geom, extra = {}) => ({ kind: "html", title, html: body, ...geom, ...extra });
|
const html = (title, body, geom, extra = {}) => ({ kind: "html", title, html: body, ...geom, ...extra });
|
||||||
|
|
||||||
function notes() {
|
function notes() {
|
||||||
@@ -29,4 +34,7 @@ function notes() {
|
|||||||
export const STARTERS = [
|
export const STARTERS = [
|
||||||
{ id: "blank", label: "Blank", boxes: () => [] },
|
{ id: "blank", label: "Blank", boxes: () => [] },
|
||||||
{ id: "notes", label: "Notes board (admin-only notes)", boxes: notes },
|
{ id: "notes", label: "Notes board (admin-only notes)", boxes: notes },
|
||||||
|
// What /stp's "Import current layout" button used to add, from when /stp
|
||||||
|
// was its own route.
|
||||||
|
{ id: "stp-grid", label: "Old /stp grid", boxes: defaultLayout },
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
/**
|
/**
|
||||||
* STATUS: legacy — no route points here. `/stp` is now views/home3/Home3.vue,
|
* STATUS: legacy — no route points here. `/stp` is now a canvas page (see
|
||||||
* the admin-editable box canvas; views/home3/defaultLayout.js is this page's
|
* views/canvas/CanvasPage.vue); views/home3/defaultLayout.js is this page's
|
||||||
* arrangement redrawn as boxes. Kept for reference.
|
* arrangement redrawn as boxes, offered as the "Old /stp grid" starter.
|
||||||
|
* Kept for reference.
|
||||||
*
|
*
|
||||||
* Was route `/stp` — the personal home page: an A4-shaped widget grid flanked by two
|
* Was route `/stp` — the personal home page: an A4-shaped widget grid flanked by two
|
||||||
* sidebars.
|
* sidebars.
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
/**
|
/**
|
||||||
* A free-form canvas of boxes the admin arranges in the browser, for one page
|
* A free-form canvas of boxes the admin arranges in the browser, for one page
|
||||||
* key (see stores/boxes.js). Home3.vue (/stp), the landing page and every
|
* key (see stores/boxes.js). The landing page and every admin-created page
|
||||||
* admin-created page (views/canvas/CanvasPage.vue) are this component.
|
* (views/canvas/CanvasPage.vue, /stp included) are this component.
|
||||||
*
|
*
|
||||||
* Every box (the `Box` GraphQL type) has a position, size and z-index in px
|
* Every box (the `Box` GraphQL type) has a position, size and z-index in px
|
||||||
* on a fixed CANVAS_W-wide design canvas. The canvas is drawn at that width
|
* on a fixed CANVAS_W-wide design canvas. The canvas is drawn at that width
|
||||||
@@ -26,6 +26,10 @@
|
|||||||
* The canvas also owns its page's background (stores/background.js), which
|
* The canvas also owns its page's background (stores/background.js), which
|
||||||
* DefaultLayout paints behind the whole window while the canvas is mounted;
|
* DefaultLayout paints behind the whole window while the canvas is mounted;
|
||||||
* admins change it with the Background button.
|
* admins change it with the Background button.
|
||||||
|
*
|
||||||
|
* The Layouts button saves the page as a named layout, or loads a saved one
|
||||||
|
* onto it (LayoutPanel.vue, stores/layouts.js) — which is how a layout moves
|
||||||
|
* from one page to another.
|
||||||
*/
|
*/
|
||||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue";
|
||||||
import { useMediaQuery } from "@vueuse/core";
|
import { useMediaQuery } from "@vueuse/core";
|
||||||
@@ -33,6 +37,7 @@ import { useAuthStore } from "@/stores/auth";
|
|||||||
import { useBoxesStore } from "@/stores/boxes";
|
import { useBoxesStore } from "@/stores/boxes";
|
||||||
import { useBackgroundStore } from "@/stores/background";
|
import { useBackgroundStore } from "@/stores/background";
|
||||||
import BackgroundEditor from "./BackgroundEditor.vue";
|
import BackgroundEditor from "./BackgroundEditor.vue";
|
||||||
|
import LayoutPanel from "./LayoutPanel.vue";
|
||||||
import ConfirmDialog from "@/components/util/ConfirmDialog.vue";
|
import ConfirmDialog from "@/components/util/ConfirmDialog.vue";
|
||||||
import UploadPicker from "@/components/util/UploadPicker.vue";
|
import UploadPicker from "@/components/util/UploadPicker.vue";
|
||||||
import BoxFrame from "./BoxFrame.vue";
|
import BoxFrame from "./BoxFrame.vue";
|
||||||
@@ -67,6 +72,7 @@ const background = useBackgroundStore();
|
|||||||
background.show(props.page);
|
background.show(props.page);
|
||||||
onBeforeUnmount(() => background.hide(props.page));
|
onBeforeUnmount(() => background.hide(props.page));
|
||||||
const backgroundOpen = ref(false);
|
const backgroundOpen = ref(false);
|
||||||
|
const layoutsOpen = ref(false);
|
||||||
const confirmation = ref(null);
|
const confirmation = ref(null);
|
||||||
|
|
||||||
const isMobile = useMediaQuery(MOBILE_QUERY);
|
const isMobile = useMediaQuery(MOBILE_QUERY);
|
||||||
@@ -317,12 +323,26 @@ async function placePicked(url) {
|
|||||||
// selection changes or it unmounts.
|
// selection changes or it unmounts.
|
||||||
function select(box) {
|
function select(box) {
|
||||||
backgroundOpen.value = false;
|
backgroundOpen.value = false;
|
||||||
|
layoutsOpen.value = false;
|
||||||
selectedId.value = box.id;
|
selectedId.value = box.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The background and layouts panels sit in the same place, so one closes the
|
||||||
|
// other, and either closes the box editor.
|
||||||
function toggleBackground() {
|
function toggleBackground() {
|
||||||
backgroundOpen.value = !backgroundOpen.value;
|
backgroundOpen.value = !backgroundOpen.value;
|
||||||
if (backgroundOpen.value) selectedId.value = null;
|
if (backgroundOpen.value) {
|
||||||
|
layoutsOpen.value = false;
|
||||||
|
selectedId.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function toggleLayouts() {
|
||||||
|
layoutsOpen.value = !layoutsOpen.value;
|
||||||
|
if (layoutsOpen.value) {
|
||||||
|
backgroundOpen.value = false;
|
||||||
|
selectedId.value = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleEdit() {
|
function toggleEdit() {
|
||||||
@@ -340,9 +360,12 @@ function toggleEdit() {
|
|||||||
<button type="button" class="bar-btn" :class="{ on: editing }" @click="toggleEdit">
|
<button type="button" class="bar-btn" :class="{ on: editing }" @click="toggleEdit">
|
||||||
{{ editing ? "Done" : "Edit layout" }}
|
{{ editing ? "Done" : "Edit layout" }}
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="bar-btn" :class="{ on: backgroundOpen }" @click="toggleBackground">
|
<button type="button" class="bar-btn" :class="{ on: backgroundOpen }" @click="toggleBackground">
|
||||||
Background
|
Background
|
||||||
</button>
|
</button>
|
||||||
|
<button type="button" class="bar-btn" :class="{ on: layoutsOpen }" @click="toggleLayouts">
|
||||||
|
Layouts
|
||||||
|
</button>
|
||||||
<template v-if="inEditMode">
|
<template v-if="inEditMode">
|
||||||
<select v-model="newChoice" class="bar-btn" @change="addBox">
|
<select v-model="newChoice" class="bar-btn" @change="addBox">
|
||||||
<option value="" disabled>+ New box…</option>
|
<option value="" disabled>+ New box…</option>
|
||||||
@@ -430,6 +453,7 @@ function toggleEdit() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<BackgroundEditor v-if="backgroundOpen && canEdit" :page="page" @close="backgroundOpen = false" />
|
<BackgroundEditor v-if="backgroundOpen && canEdit" :page="page" @close="backgroundOpen = false" />
|
||||||
|
<LayoutPanel v-if="layoutsOpen && canEdit" :page="page" @close="layoutsOpen = false" />
|
||||||
|
|
||||||
<BoxEditor
|
<BoxEditor
|
||||||
v-if="inEditMode && selected"
|
v-if="inEditMode && selected"
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
/**
|
/**
|
||||||
* Route `/stp` — the home page as a free-form canvas of boxes the admin
|
* STATUS: legacy — no route points here. `/stp` is now an ordinary canvas
|
||||||
|
* Page (slug "stp", created by ensureStpPage in backend/services/database.go)
|
||||||
|
* served by views/canvas/CanvasPage.vue; the "Old /stp grid" starter in
|
||||||
|
* views/canvas/pageStarters.js replaces this view's import button. Kept for
|
||||||
|
* reference.
|
||||||
|
*
|
||||||
|
* Was route `/stp` — the home page as a free-form canvas of boxes the admin
|
||||||
* arranges in the browser (page key "stp"). Replaces views/home/Home.vue's
|
* arranges in the browser (page key "stp"). Replaces views/home/Home.vue's
|
||||||
* fixed grid. The canvas itself is BoxCanvas.vue, shared with the landing
|
* fixed grid. The canvas itself is BoxCanvas.vue, shared with the landing
|
||||||
* page's notes and the admin-created pages.
|
* page's notes and the admin-created pages.
|
||||||
|
|||||||
@@ -0,0 +1,228 @@
|
|||||||
|
<script setup>
|
||||||
|
/**
|
||||||
|
* The admin's layouts panel for one canvas page, opened from BoxCanvas's
|
||||||
|
* "Layouts" button: save the page as a named layout, or load a saved one
|
||||||
|
* onto it (stores/layouts.js).
|
||||||
|
*
|
||||||
|
* Loading onto a page that already has boxes asks whether to replace them or
|
||||||
|
* add the layout on top. A replace is undoable: the server saves the page
|
||||||
|
* first, as a layout named "<page> before <layout>, <time>", which shows up
|
||||||
|
* at the top of this list. Onto an empty page it simply replaces, so the
|
||||||
|
* layout's background comes with it.
|
||||||
|
*/
|
||||||
|
import { ref } from "vue";
|
||||||
|
import { pagePath, useLayoutsStore } from "@/stores/layouts";
|
||||||
|
import { useBoxesStore } from "@/stores/boxes";
|
||||||
|
import OverlayShell from "@/components/util/OverlayShell.vue";
|
||||||
|
import ConfirmDialog from "@/components/util/ConfirmDialog.vue";
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
page: { type: String, required: true },
|
||||||
|
});
|
||||||
|
const emit = defineEmits(["close"]);
|
||||||
|
const open = ref(true);
|
||||||
|
|
||||||
|
const layouts = useLayoutsStore();
|
||||||
|
layouts.fetch();
|
||||||
|
const boxes = useBoxesStore(props.page);
|
||||||
|
|
||||||
|
const name = ref("");
|
||||||
|
const busy = ref(false);
|
||||||
|
const error = ref("");
|
||||||
|
const loadTarget = ref(null); // the layout waiting on "replace or add?"
|
||||||
|
const deleteTarget = ref(null);
|
||||||
|
const renaming = ref(null); // id of the layout whose name is being edited
|
||||||
|
const renameDraft = ref("");
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
open.value = false;
|
||||||
|
emit("close");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function act(action, failure) {
|
||||||
|
error.value = "";
|
||||||
|
busy.value = true;
|
||||||
|
try {
|
||||||
|
await action();
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
error.value = err?.message || failure;
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
busy.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function save() {
|
||||||
|
const ok = await act(() => layouts.create({ name: name.value.trim(), page: props.page }), "Failed to save");
|
||||||
|
if (ok) name.value = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function load(layout) {
|
||||||
|
if (boxes.boxes.length) loadTarget.value = layout;
|
||||||
|
else apply(layout, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function apply(layout, replace) {
|
||||||
|
loadTarget.value = null;
|
||||||
|
act(() => layouts.apply(layout.id, props.page, replace), "Failed to load");
|
||||||
|
}
|
||||||
|
|
||||||
|
function startRename(layout) {
|
||||||
|
renaming.value = layout.id;
|
||||||
|
renameDraft.value = layout.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function rename(layout) {
|
||||||
|
const ok = await act(() => layouts.update(layout.id, { name: renameDraft.value.trim() }), "Failed to rename");
|
||||||
|
if (ok) renaming.value = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmDelete() {
|
||||||
|
const layout = deleteTarget.value;
|
||||||
|
deleteTarget.value = null;
|
||||||
|
act(() => layouts.remove(layout.id), "Failed to delete");
|
||||||
|
}
|
||||||
|
|
||||||
|
function describe(layout) {
|
||||||
|
const parts = [`from ${pagePath(layout.sourcePage)}`, `${layout.boxCount} box${layout.boxCount === 1 ? "" : "es"}`];
|
||||||
|
if (layout.hasBackground) parts.push("background");
|
||||||
|
return parts.join(" · ");
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<OverlayShell v-model="open" title="Layouts" @close="close">
|
||||||
|
<div class="layout-panel bdr-2 bg-surface">
|
||||||
|
<h3>Layouts</h3>
|
||||||
|
|
||||||
|
<form class="row" @submit.prevent="save">
|
||||||
|
<input v-model="name" type="text" placeholder="Name for this page's layout" required class="flex-1" />
|
||||||
|
<button type="submit" class="bar-btn" :disabled="busy || !boxes.boxes.length">Save</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p v-if="layouts.error" class="text-tertiary">Couldn't load the layouts.</p>
|
||||||
|
<p v-else-if="layouts.loaded && !layouts.layouts.length" class="hint">
|
||||||
|
No saved layouts yet. Save this page to start one.
|
||||||
|
</p>
|
||||||
|
<ul v-else class="list">
|
||||||
|
<li v-for="layout in layouts.layouts" :key="layout.id">
|
||||||
|
<form v-if="renaming === layout.id" class="row" @submit.prevent="rename(layout)">
|
||||||
|
<input v-model="renameDraft" type="text" required class="flex-1" />
|
||||||
|
<button type="submit" class="bar-btn small" :disabled="busy">Save</button>
|
||||||
|
<button type="button" class="bar-btn small" @click="renaming = null">Cancel</button>
|
||||||
|
</form>
|
||||||
|
<template v-else>
|
||||||
|
<span class="name">{{ layout.name }}</span>
|
||||||
|
<span class="hint">{{ describe(layout) }}</span>
|
||||||
|
<span class="row">
|
||||||
|
<button type="button" class="bar-btn small" :disabled="busy" @click="load(layout)">Load here</button>
|
||||||
|
<button type="button" class="bar-btn small" @click="startRename(layout)">Rename</button>
|
||||||
|
<button type="button" class="bar-btn small danger" @click="deleteTarget = layout">Delete</button>
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<button type="button" class="bar-btn" @click="close">Close</button>
|
||||||
|
<span v-if="busy" class="hint">Working…</span>
|
||||||
|
</div>
|
||||||
|
<p v-if="error" class="text-tertiary">{{ error }}</p>
|
||||||
|
</div>
|
||||||
|
</OverlayShell>
|
||||||
|
|
||||||
|
<ConfirmDialog
|
||||||
|
v-if="loadTarget"
|
||||||
|
:model-value="true"
|
||||||
|
title="Load layout"
|
||||||
|
:message="`This page already has ${boxes.boxes.length} box${boxes.boxes.length === 1 ? '' : 'es'}. Replace them with “${loadTarget.name}”, or add it on top? Replacing saves the page as a layout first.`"
|
||||||
|
confirm-label="Replace"
|
||||||
|
secondary-label="Add on top"
|
||||||
|
@confirm="apply(loadTarget, true)"
|
||||||
|
@secondary="apply(loadTarget, false)"
|
||||||
|
@cancel="loadTarget = null"
|
||||||
|
/>
|
||||||
|
<ConfirmDialog
|
||||||
|
v-if="deleteTarget"
|
||||||
|
:model-value="true"
|
||||||
|
title="Delete layout"
|
||||||
|
:message="`Delete the layout “${deleteTarget.name}”? Pages it was loaded onto keep their boxes.`"
|
||||||
|
confirm-label="Delete"
|
||||||
|
@confirm="confirmDelete"
|
||||||
|
@cancel="deleteTarget = null"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.layout-panel {
|
||||||
|
position: fixed;
|
||||||
|
top: 80px;
|
||||||
|
left: 16px;
|
||||||
|
z-index: 65;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
width: min(420px, calc(100vw - 32px));
|
||||||
|
max-height: calc(100vh - 100px);
|
||||||
|
overflow-y: auto;
|
||||||
|
padding: 0.75rem;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
h3 {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
.row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.4rem;
|
||||||
|
}
|
||||||
|
.list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
.list li {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 2px;
|
||||||
|
padding-bottom: 0.5rem;
|
||||||
|
border-bottom: 1px solid var(--color-quaternary);
|
||||||
|
}
|
||||||
|
.name {
|
||||||
|
color: var(--color-primary);
|
||||||
|
}
|
||||||
|
.hint {
|
||||||
|
color: var(--color-muted);
|
||||||
|
font-size: 0.85rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.bar-btn {
|
||||||
|
padding: 0.25rem 0.75rem;
|
||||||
|
color: var(--color-primary);
|
||||||
|
background: var(--color-link-bg);
|
||||||
|
border: 2px solid var(--color-quaternary);
|
||||||
|
font-family: var(--font-heading);
|
||||||
|
font-size: 1.1rem;
|
||||||
|
letter-spacing: 0.025em;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.bar-btn:hover {
|
||||||
|
border-color: var(--color-primary);
|
||||||
|
}
|
||||||
|
.bar-btn:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
.bar-btn.small {
|
||||||
|
padding: 0.1rem 0.5rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
.bar-btn.danger:hover {
|
||||||
|
border-color: var(--color-tertiary);
|
||||||
|
color: var(--color-tertiary);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* The pre-Home3 /stp page (views/home/Home.vue) redrawn as boxes, for the
|
* The pre-Home3 /stp page (views/home/Home.vue) redrawn as boxes, offered
|
||||||
* one-off "Import current layout" button on an empty canvas.
|
* as the "Old /stp grid" starter when a page is created
|
||||||
|
* (views/canvas/pageStarters.js).
|
||||||
*
|
*
|
||||||
* Home.vue was an A4 sheet (~800×1120px) holding a 10×10 CSS grid with 5px
|
* Home.vue was an A4 sheet (~800×1120px) holding a 10×10 CSS grid with 5px
|
||||||
* gaps, between two 240px sidebars. The grid areas below are copied from its
|
* gaps, between two 240px sidebars. The grid areas below are copied from its
|
||||||
|
|||||||
Reference in New Issue
Block a user