From 7969859955183018d87d5ba7756f260c3ed31ed8 Mon Sep 17 00:00:00 2001 From: Adam French Date: Fri, 23 Oct 2026 22:32:40 +0100 Subject: [PATCH] Add saved components: reusable HTML boxes, placed as copies or linked A component (models.Component, component.graphql) is a named HTML box. "+ New box" now lists components and places a copy, as it did with the hard-coded starters; the canvas's new Components button (ComponentPanel) can also place one linked. A linked box has Box.componentId, its row's html is nil, and the resolvers fill in the component's html before answering (fillLinked), so saving the html in the box editor saves the component and every linked box on every page changes. Only the html is shared: title, geometry, frame and visibility stay each box's own. The box editor gains "Save as component" (makes one from an html box and links it) and, on a linked box, a banner with Detach (gives the box its own copy). updateBox refuses html on a linked box. Deleting a component detaches its boxes first, so no page changes. Layouts store the link and the html; loading relinks only if the component still exists. The built-in starters in templates.js are no longer listed directly: "Import built-ins" in the panel creates them as components (skipping names already taken), so they can be edited and deleted like the rest. The html helpers there are unchanged. Everything is @admin. Co-Authored-By: Claude Opus 5.5 --- CLAUDE.md | 6 +- backend/gqlgen.yml | 8 + backend/graph/box.resolvers.go | 31 + backend/graph/box_helpers.go | 6 +- backend/graph/box_helpers_test.go | 3 + backend/graph/component.resolvers.go | 183 ++++ backend/graph/component_helpers.go | 112 ++ backend/graph/component_helpers_test.go | 30 + backend/graph/directives_test.go | 1 + backend/graph/generated.go | 1300 ++++++++++++++++++++++- backend/graph/layout.resolvers.go | 3 + backend/graph/layout_helpers.go | 39 + backend/graph/model/models_gen.go | 21 + backend/graph/schema/box.graphql | 8 +- backend/graph/schema/component.graphql | 64 ++ backend/models/models.go | 29 + backend/services/database.go | 1 + vue/README.md | 17 +- vue/src/stores/boxes.js | 30 +- vue/src/stores/components.js | 149 +++ vue/src/views/home3/BoxCanvas.vue | 114 +- vue/src/views/home3/BoxEditor.vue | 93 +- vue/src/views/home3/ComponentPanel.vue | 227 ++++ vue/src/views/home3/templates.js | 21 +- 24 files changed, 2431 insertions(+), 65 deletions(-) create mode 100644 backend/graph/component.resolvers.go create mode 100644 backend/graph/component_helpers.go create mode 100644 backend/graph/component_helpers_test.go create mode 100644 backend/graph/schema/component.graphql create mode 100644 vue/src/stores/components.js create mode 100644 vue/src/views/home3/ComponentPanel.vue diff --git a/CLAUDE.md b/CLAUDE.md index 5af7551..3faa313 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -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/generated.go` — auto-generated by gqlgen, 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, Layout) +- `models/models.go` — GORM database models (User, Post, Message, Activity, Favorite, Rowing, Bookmark, Place, Box, Page, Background, Layout, Component) - `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 @@ -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/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/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). 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 `/` 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/stores/` — Pinia stores for auth, posts, favorites, activities, songs, messages, homeData, places, boxes, pages, layouts, components. `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). 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 `/` 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). A `Component` is a saved, named HTML box: "+ New box" places copies of it, and the canvas's Components button also places it *linked* (`Box.componentId`), so the box shows the component's HTML and editing it edits every linked box; the built-in starters in `templates.js` become components through that panel's "Import built-ins". 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/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`. diff --git a/backend/gqlgen.yml b/backend/gqlgen.yml index c2748a7..298057c 100644 --- a/backend/gqlgen.yml +++ b/backend/gqlgen.yml @@ -108,3 +108,11 @@ models: resolver: true hasBackground: resolver: true + Component: + model: + - adam-french.co.uk/backend/models.Component + fields: + deletedAt: + resolver: false + uses: + resolver: true diff --git a/backend/graph/box.resolvers.go b/backend/graph/box.resolvers.go index 9e88e03..1500455 100644 --- a/backend/graph/box.resolvers.go +++ b/backend/graph/box.resolvers.go @@ -7,6 +7,7 @@ package graph import ( "context" + "errors" "adam-french.co.uk/backend/graph/model" "adam-french.co.uk/backend/models" @@ -41,12 +42,31 @@ func (r *mutationResolver) CreateBox(ctx context.Context, input model.CreateBoxI if input.AdminOnly != nil { box.AdminOnly = *input.AdminOnly } + // A linked box takes its html from the component, so its own is + // dropped rather than stored as a copy that would quietly go stale. + if input.ComponentID != nil { + id := uint(*input.ComponentID) + exists, err := componentExists(r.Store.DB, id) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.New("there is no such component") + } + box.Kind = "html" + box.Widget = nil + box.HTML = nil + box.ComponentID = &id + } if err := validateBox(&box); err != nil { return nil, err } if err := r.Store.DB.Create(&box).Error; err != nil { return nil, err } + if err := fillLinkedOne(r.Store.DB, &box); err != nil { + return nil, err + } return &box, nil } @@ -64,6 +84,11 @@ func (r *mutationResolver) UpdateBox(ctx context.Context, id int, input model.Up box.Widget = input.Widget } if input.HTML != nil { + // A linked box's html is the component's; changing it here would + // only fork a copy. The editor sends it to updateComponent instead. + if box.ComponentID != nil { + return nil, errors.New("that box is linked to a component: edit the component, or detach the box first") + } box.HTML = input.HTML } if input.Title != nil { @@ -89,6 +114,9 @@ func (r *mutationResolver) UpdateBox(ctx context.Context, id int, input model.Up if err := r.Store.DB.Save(&box).Error; err != nil { return nil, err } + if err := fillLinkedOne(r.Store.DB, &box); err != nil { + return nil, err + } return &box, nil } @@ -127,5 +155,8 @@ func (r *queryResolver) Boxes(ctx context.Context, page string) ([]*models.Box, if err := query.Order("z ASC, id ASC").Find(&boxes).Error; err != nil { return nil, err } + if err := fillLinked(r.Store.DB, boxes); err != nil { + return nil, err + } return ptrs(boxes), nil } diff --git a/backend/graph/box_helpers.go b/backend/graph/box_helpers.go index d70d9e8..00de91d 100644 --- a/backend/graph/box_helpers.go +++ b/backend/graph/box_helpers.go @@ -33,12 +33,16 @@ func validateBox(box *models.Box) error { return errors.New("a widget box needs a widget name") } case "html": - if box.HTML == nil { + // A linked box's html lives on its component (fillLinked). + if box.HTML == nil && box.ComponentID == nil { return errors.New("an html box needs html") } default: return errors.New(`box kind must be "widget" or "html"`) } + if box.ComponentID != nil && box.Kind != "html" { + return errors.New("only an html box can be linked to a component") + } box.X = max(box.X, 0) box.Y = max(box.Y, 0) box.W = max(box.W, minBoxSize) diff --git a/backend/graph/box_helpers_test.go b/backend/graph/box_helpers_test.go index b74e7a3..6d58102 100644 --- a/backend/graph/box_helpers_test.go +++ b/backend/graph/box_helpers_test.go @@ -8,6 +8,7 @@ import ( func TestValidateBox(t *testing.T) { str := func(s string) *string { return &s } + one := uint(1) for _, c := range []struct { name string @@ -20,6 +21,8 @@ func TestValidateBox(t *testing.T) { {"html with html", models.Box{Page: "stp", Kind: "html", HTML: str("

hi

")}, false}, {"html with empty html", models.Box{Page: "stp", Kind: "html", HTML: str("")}, false}, {"html without html", models.Box{Page: "stp", Kind: "html"}, true}, + {"linked html without html", models.Box{Page: "stp", Kind: "html", ComponentID: &one}, false}, + {"linked widget", models.Box{Page: "stp", Kind: "widget", Widget: str("Chat"), ComponentID: &one}, true}, {"no page", models.Box{Kind: "widget", Widget: str("Chat")}, true}, {"bad page", models.Box{Page: "Shrines/GTO", Kind: "widget", Widget: str("Chat")}, true}, {"unknown kind", models.Box{Page: "stp", Kind: "iframe", HTML: str("x")}, true}, diff --git a/backend/graph/component.resolvers.go b/backend/graph/component.resolvers.go new file mode 100644 index 0000000..166a623 --- /dev/null +++ b/backend/graph/component.resolvers.go @@ -0,0 +1,183 @@ +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" +) + +// Uses is the resolver for the uses field. +func (r *componentResolver) Uses(ctx context.Context, obj *models.Component) (int, error) { + // One count per component, which is fine for an admin-only list of a + // handful; soft-deleted boxes are excluded by GORM's default scope. + var count int64 + if err := r.Store.DB.Model(&models.Box{}).Where("component_id = ?", obj.ID).Count(&count).Error; err != nil { + return 0, err + } + return int(count), nil +} + +// CreateComponent is the resolver for the createComponent field. +func (r *mutationResolver) CreateComponent(ctx context.Context, input model.CreateComponentInput) (*models.Component, error) { + // Framed defaults to true and the size to 300x200, as for a new box. + name, err := usableComponentName(r.Store.DB, input.Name, 0) + if err != nil { + return nil, err + } + c := models.Component{Name: name, Title: input.Title, HTML: input.HTML, W: 300, H: 200, Framed: true} + setInt(&c.W, input.W) + setInt(&c.H, input.H) + if input.Framed != nil { + c.Framed = *input.Framed + } + if input.AdminOnly != nil { + c.AdminOnly = *input.AdminOnly + } + c.W = max(c.W, minBoxSize) + c.H = max(c.H, minBoxSize) + if err := r.Store.DB.Create(&c).Error; err != nil { + return nil, err + } + return &c, nil +} + +// UpdateComponent is the resolver for the updateComponent field. +func (r *mutationResolver) UpdateComponent(ctx context.Context, id int, input model.UpdateComponentInput) (*models.Component, error) { + // Partial, like updateBox. Nothing to do for the linked boxes: they + // read the html from here every time they are fetched. + var c models.Component + if err := r.Store.DB.First(&c, id).Error; err != nil { + return nil, err + } + if input.Name != nil { + name, err := usableComponentName(r.Store.DB, *input.Name, c.ID) + if err != nil { + return nil, err + } + c.Name = name + } + if input.Title != nil { + c.Title = input.Title + } + if input.HTML != nil { + c.HTML = *input.HTML + } + setInt(&c.W, input.W) + setInt(&c.H, input.H) + if input.Framed != nil { + c.Framed = *input.Framed + } + if input.AdminOnly != nil { + c.AdminOnly = *input.AdminOnly + } + c.W = max(c.W, minBoxSize) + c.H = max(c.H, minBoxSize) + if err := r.Store.DB.Save(&c).Error; err != nil { + return nil, err + } + return &c, nil +} + +// DeleteComponent is the resolver for the deleteComponent field. +func (r *mutationResolver) DeleteComponent(ctx context.Context, id int) (*models.Component, error) { + // The linked boxes keep showing what they showed, as copies, so + // deleting a component never changes a page. One transaction, so a + // failure can't leave boxes linked to a deleted component. + var c models.Component + if err := r.Store.DB.First(&c, id).Error; err != nil { + return nil, err + } + err := r.Store.DB.Transaction(func(tx *gorm.DB) error { + if err := detachFrom(tx, &c); err != nil { + return err + } + return tx.Delete(&c).Error + }) + if err != nil { + return nil, err + } + return &c, nil +} + +// SaveBoxAsComponent is the resolver for the saveBoxAsComponent field. +func (r *mutationResolver) SaveBoxAsComponent(ctx context.Context, id int, name string) (*models.Box, error) { + // The box becomes the component's first linked instance, so carrying + // on editing it edits the component. A box that is already linked + // would make a component of a component's html; detach it first. + var box models.Box + if err := r.Store.DB.First(&box, id).Error; err != nil { + return nil, err + } + if box.Kind != "html" || box.HTML == nil { + return nil, errors.New("only an html box can be saved as a component") + } + if box.ComponentID != nil { + return nil, errors.New("that box is already linked to a component") + } + name, err := usableComponentName(r.Store.DB, name, 0) + if err != nil { + return nil, err + } + c := models.Component{ + Name: name, Title: box.Title, HTML: *box.HTML, + W: box.W, H: box.H, Framed: box.Framed, AdminOnly: box.AdminOnly, + } + err = r.Store.DB.Transaction(func(tx *gorm.DB) error { + if err := tx.Create(&c).Error; err != nil { + return err + } + box.ComponentID = &c.ID + box.HTML = nil + return tx.Save(&box).Error + }) + if err != nil { + return nil, err + } + if err := fillLinkedOne(r.Store.DB, &box); err != nil { + return nil, err + } + return &box, nil +} + +// DetachBox is the resolver for the detachBox field. +func (r *mutationResolver) DetachBox(ctx context.Context, id int) (*models.Box, error) { + // The html is filled in from the component and then saved, which is + // exactly the copy fillLinked otherwise never lets reach the row. + var box models.Box + if err := r.Store.DB.First(&box, id).Error; err != nil { + return nil, err + } + if box.ComponentID == nil { + return nil, errors.New("that box isn't linked to a component") + } + if err := fillLinkedOne(r.Store.DB, &box); err != nil { + return nil, err + } + box.ComponentID = nil + if err := r.Store.DB.Save(&box).Error; err != nil { + return nil, err + } + return &box, nil +} + +// Components is the resolver for the components field. +func (r *queryResolver) Components(ctx context.Context) ([]*models.Component, error) { + var components []models.Component + if err := r.Store.DB.Order("name ASC").Find(&components).Error; err != nil { + return nil, err + } + return ptrs(components), nil +} + +// Component returns ComponentResolver implementation. +func (r *Resolver) Component() ComponentResolver { return &componentResolver{r} } + +type componentResolver struct{ *Resolver } diff --git a/backend/graph/component_helpers.go b/backend/graph/component_helpers.go new file mode 100644 index 0000000..d2e0d05 --- /dev/null +++ b/backend/graph/component_helpers.go @@ -0,0 +1,112 @@ +package graph + +// Hand-written helpers for component.resolvers.go, kept out of the resolver +// file for the same reason as box_helpers.go. + +import ( + "errors" + "fmt" + "strings" + + "adam-french.co.uk/backend/models" + "gorm.io/gorm" +) + +const maxComponentNameLen = 100 + +// cleanComponentName trims name and reports why it can't be a component's +// name. +func cleanComponentName(name string) (string, error) { + name = strings.TrimSpace(name) + if name == "" { + return name, errors.New("a component needs a name") + } + if len(name) > maxComponentNameLen { + return name, fmt.Errorf("a component name is at most %d characters", maxComponentNameLen) + } + return name, nil +} + +// componentNameTaken reports whether a live component other than exceptID +// has this name. Checked up front, like layoutNameTaken, so the admin gets a +// sentence rather than a constraint violation. +func componentNameTaken(db *gorm.DB, name string, exceptID uint) (bool, error) { + var count int64 + err := db.Model(&models.Component{}).Where("name = ? AND id <> ?", name, exceptID).Count(&count).Error + return count > 0, err +} + +// usableComponentName checks name and answers with a sentence if it can't be +// used, so the resolvers that name a component share one set of messages. +func usableComponentName(db *gorm.DB, name string, exceptID uint) (string, error) { + name, err := cleanComponentName(name) + if err != nil { + return name, err + } + taken, err := componentNameTaken(db, name, exceptID) + if err != nil { + return name, err + } + if taken { + return name, errors.New("there is already a component with that name") + } + return name, nil +} + +// fillLinked sets each linked box's in-memory HTML to its component's, with +// one query for all of them. Only for boxes about to be returned or +// snapshotted: a linked row's own HTML is nil, and saving a filled box would +// freeze a copy of the component into it. A box whose component has gone +// (deleted outside deleteComponent, which detaches first) is left with +// empty HTML rather than failing the whole page. +func fillLinked(db *gorm.DB, boxes []models.Box) error { + var ids []uint + for _, b := range boxes { + if b.ComponentID != nil { + ids = append(ids, *b.ComponentID) + } + } + if len(ids) == 0 { + return nil + } + var components []models.Component + if err := db.Where("id IN ?", ids).Find(&components).Error; err != nil { + return err + } + html := make(map[uint]string, len(components)) + for _, c := range components { + html[c.ID] = c.HTML + } + for i := range boxes { + if id := boxes[i].ComponentID; id != nil { + h := html[*id] + boxes[i].HTML = &h + } + } + return nil +} + +// fillLinkedOne is fillLinked for a single box. +func fillLinkedOne(db *gorm.DB, box *models.Box) error { + boxes := []models.Box{*box} + if err := fillLinked(db, boxes); err != nil { + return err + } + *box = boxes[0] + return nil +} + +// componentExists reports whether id is a live component, for linking a box +// to it. +func componentExists(db *gorm.DB, id uint) (bool, error) { + var count int64 + err := db.Model(&models.Component{}).Where("id = ?", id).Count(&count).Error + return count > 0, err +} + +// detachFrom gives every box linked to component c its own copy of c's HTML +// and unlinks it, inside tx. +func detachFrom(tx *gorm.DB, c *models.Component) error { + return tx.Model(&models.Box{}).Where("component_id = ?", c.ID). + Updates(map[string]any{"html": c.HTML, "component_id": nil}).Error +} diff --git a/backend/graph/component_helpers_test.go b/backend/graph/component_helpers_test.go new file mode 100644 index 0000000..915d319 --- /dev/null +++ b/backend/graph/component_helpers_test.go @@ -0,0 +1,30 @@ +package graph + +import ( + "strings" + "testing" +) + +func TestCleanComponentName(t *testing.T) { + for _, c := range []struct { + name, in, want string + wantErr bool + }{ + {"plain", "Clock", "Clock", false}, + {"trimmed", " Clock \n", "Clock", false}, + {"empty", "", "", true}, + {"only spaces", " ", "", true}, + {"at the limit", strings.Repeat("a", maxComponentNameLen), strings.Repeat("a", maxComponentNameLen), false}, + {"too long", strings.Repeat("a", maxComponentNameLen+1), "", true}, + } { + t.Run(c.name, func(t *testing.T) { + got, err := cleanComponentName(c.in) + if (err != nil) != c.wantErr { + t.Fatalf("err = %v, wantErr %v", err, c.wantErr) + } + if !c.wantErr && got != c.want { + t.Fatalf("got %q, want %q", got, c.want) + } + }) + } +} diff --git a/backend/graph/directives_test.go b/backend/graph/directives_test.go index 92a7ce7..e3a87e1 100644 --- a/backend/graph/directives_test.go +++ b/backend/graph/directives_test.go @@ -191,6 +191,7 @@ func TestGuardedQueriesArePinned(t *testing.T) { "user": "admin", "places": "signedIn", "layouts": "admin", + "components": "admin", "permissionTypes": "signedIn", } got := map[string]string{} diff --git a/backend/graph/generated.go b/backend/graph/generated.go index 0c76c87..f3790f6 100644 --- a/backend/graph/generated.go +++ b/backend/graph/generated.go @@ -32,6 +32,7 @@ func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { type Config = graphql.Config[ResolverRoot, DirectiveRoot, ComplexityRoot] type ResolverRoot interface { + Component() ComponentResolver Layout() LayoutResolver Message() MessageResolver Mutation() MutationResolver @@ -78,6 +79,7 @@ type ComplexityRoot struct { Box struct { AdminOnly func(childComplexity int) int + ComponentID func(childComplexity int) int CreatedAt func(childComplexity int) int Framed func(childComplexity int) int H func(childComplexity int) int @@ -95,6 +97,20 @@ type ComplexityRoot struct { Z func(childComplexity int) int } + Component struct { + AdminOnly func(childComplexity int) int + CreatedAt func(childComplexity int) int + Framed func(childComplexity int) int + H func(childComplexity int) int + HTML func(childComplexity int) int + ID func(childComplexity int) int + Name func(childComplexity int) int + Title func(childComplexity int) int + UpdatedAt func(childComplexity int) int + Uses func(childComplexity int) int + W func(childComplexity int) int + } + Favorite struct { CreatedAt func(childComplexity int) int ID func(childComplexity int) int @@ -138,6 +154,7 @@ type ComplexityRoot struct { CreateActivity func(childComplexity int, input model.CreateActivityInput) int CreateBookmark func(childComplexity int, input model.CreateBookmarkInput) int CreateBox func(childComplexity int, input model.CreateBoxInput) int + CreateComponent func(childComplexity int, input model.CreateComponentInput) int CreateFavorite func(childComplexity int, input model.CreateFavoriteInput) int CreateLayout func(childComplexity int, input model.CreateLayoutInput) int CreatePage func(childComplexity int, input model.CreatePageInput) int @@ -146,18 +163,22 @@ type ComplexityRoot struct { CreateUser func(childComplexity int, input model.CreateUserInput) int DeleteBookmark func(childComplexity int, id int) int DeleteBox func(childComplexity int, id int) int + DeleteComponent func(childComplexity int, id int) int DeleteLayout func(childComplexity int, id int) int DeletePage func(childComplexity int, id int) int DeletePlace func(childComplexity int, id int) int DeletePost func(childComplexity int, id int) int DeleteUser func(childComplexity int, id int) int + DetachBox func(childComplexity int, id int) int Login func(childComplexity int, input model.LoginInput) int Logout func(childComplexity int) int RefreshToken func(childComplexity int) int + SaveBoxAsComponent func(childComplexity int, id int, name string) int SetBackground func(childComplexity int, page string, input model.BackgroundInput) int SetUserAdmin func(childComplexity int, id int, admin bool) int SetUserPermissions func(childComplexity int, id int, permissions []string) int UpdateBox func(childComplexity int, id int, input model.UpdateBoxInput) int + UpdateComponent func(childComplexity int, id int, input model.UpdateComponentInput) int UpdateLayout func(childComplexity int, id int, input model.UpdateLayoutInput) int UpdatePage func(childComplexity int, id int, input model.UpdatePageInput) int UpdatePlace func(childComplexity int, id int, input model.UpdatePlaceInput) int @@ -207,6 +228,7 @@ type ComplexityRoot struct { Background func(childComplexity int, page string) int Bookmarks func(childComplexity int) int Boxes func(childComplexity int, page string) int + Components func(childComplexity int) int Favorites func(childComplexity int) int GiteaFeed func(childComplexity int) int Layouts func(childComplexity int) int @@ -293,6 +315,9 @@ type ComplexityRoot struct { // region ************************** generated!.gotpl ************************** +type ComponentResolver interface { + Uses(ctx context.Context, obj *models.Component) (int, error) +} type LayoutResolver interface { BoxCount(ctx context.Context, obj *models.Layout) (int, error) HasBackground(ctx context.Context, obj *models.Layout) (bool, error) @@ -312,6 +337,11 @@ type MutationResolver interface { CreateBox(ctx context.Context, input model.CreateBoxInput) (*models.Box, error) UpdateBox(ctx context.Context, id int, input model.UpdateBoxInput) (*models.Box, error) DeleteBox(ctx context.Context, id int) (*models.Box, error) + CreateComponent(ctx context.Context, input model.CreateComponentInput) (*models.Component, error) + UpdateComponent(ctx context.Context, id int, input model.UpdateComponentInput) (*models.Component, error) + DeleteComponent(ctx context.Context, id int) (*models.Component, error) + SaveBoxAsComponent(ctx context.Context, id int, name string) (*models.Box, error) + DetachBox(ctx context.Context, id int) (*models.Box, error) CreateFavorite(ctx context.Context, input model.CreateFavoriteInput) (*models.Favorite, error) CreateLayout(ctx context.Context, input model.CreateLayoutInput) (*models.Layout, error) UpdateLayout(ctx context.Context, id int, input model.UpdateLayoutInput) (*models.Layout, error) @@ -337,6 +367,7 @@ type QueryResolver interface { Background(ctx context.Context, page string) (*models.Background, error) Bookmarks(ctx context.Context) ([]*models.Bookmark, error) Boxes(ctx context.Context, page string) ([]*models.Box, error) + Components(ctx context.Context) ([]*models.Component, error) Favorites(ctx context.Context) ([]*models.Favorite, error) GiteaFeed(ctx context.Context) (*model.GiteaFeedItem, error) Layouts(ctx context.Context) ([]*models.Layout, error) @@ -502,6 +533,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Box.AdminOnly(childComplexity), true + case "Box.componentId": + if e.ComplexityRoot.Box.ComponentID == nil { + break + } + + return e.ComplexityRoot.Box.ComponentID(childComplexity), true case "Box.createdAt": if e.ComplexityRoot.Box.CreatedAt == nil { break @@ -593,6 +630,73 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.ComplexityRoot.Box.Z(childComplexity), true + case "Component.adminOnly": + if e.ComplexityRoot.Component.AdminOnly == nil { + break + } + + return e.ComplexityRoot.Component.AdminOnly(childComplexity), true + case "Component.createdAt": + if e.ComplexityRoot.Component.CreatedAt == nil { + break + } + + return e.ComplexityRoot.Component.CreatedAt(childComplexity), true + case "Component.framed": + if e.ComplexityRoot.Component.Framed == nil { + break + } + + return e.ComplexityRoot.Component.Framed(childComplexity), true + case "Component.h": + if e.ComplexityRoot.Component.H == nil { + break + } + + return e.ComplexityRoot.Component.H(childComplexity), true + case "Component.html": + if e.ComplexityRoot.Component.HTML == nil { + break + } + + return e.ComplexityRoot.Component.HTML(childComplexity), true + case "Component.id": + if e.ComplexityRoot.Component.ID == nil { + break + } + + return e.ComplexityRoot.Component.ID(childComplexity), true + case "Component.name": + if e.ComplexityRoot.Component.Name == nil { + break + } + + return e.ComplexityRoot.Component.Name(childComplexity), true + case "Component.title": + if e.ComplexityRoot.Component.Title == nil { + break + } + + return e.ComplexityRoot.Component.Title(childComplexity), true + case "Component.updatedAt": + if e.ComplexityRoot.Component.UpdatedAt == nil { + break + } + + return e.ComplexityRoot.Component.UpdatedAt(childComplexity), true + case "Component.uses": + if e.ComplexityRoot.Component.Uses == nil { + break + } + + return e.ComplexityRoot.Component.Uses(childComplexity), true + case "Component.w": + if e.ComplexityRoot.Component.W == nil { + break + } + + return e.ComplexityRoot.Component.W(childComplexity), true + case "Favorite.createdAt": if e.ComplexityRoot.Favorite.CreatedAt == nil { break @@ -802,6 +906,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.CreateBox(childComplexity, args["input"].(model.CreateBoxInput)), true + case "Mutation.createComponent": + if e.ComplexityRoot.Mutation.CreateComponent == nil { + break + } + + args, err := ec.field_Mutation_createComponent_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.CreateComponent(childComplexity, args["input"].(model.CreateComponentInput)), true case "Mutation.createFavorite": if e.ComplexityRoot.Mutation.CreateFavorite == nil { break @@ -890,6 +1005,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.DeleteBox(childComplexity, args["id"].(int)), true + case "Mutation.deleteComponent": + if e.ComplexityRoot.Mutation.DeleteComponent == nil { + break + } + + args, err := ec.field_Mutation_deleteComponent_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.DeleteComponent(childComplexity, args["id"].(int)), true case "Mutation.deleteLayout": if e.ComplexityRoot.Mutation.DeleteLayout == nil { break @@ -945,6 +1071,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.DeleteUser(childComplexity, args["id"].(int)), true + case "Mutation.detachBox": + if e.ComplexityRoot.Mutation.DetachBox == nil { + break + } + + args, err := ec.field_Mutation_detachBox_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.DetachBox(childComplexity, args["id"].(int)), true case "Mutation.login": if e.ComplexityRoot.Mutation.Login == nil { break @@ -968,6 +1105,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.RefreshToken(childComplexity), true + case "Mutation.saveBoxAsComponent": + if e.ComplexityRoot.Mutation.SaveBoxAsComponent == nil { + break + } + + args, err := ec.field_Mutation_saveBoxAsComponent_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.SaveBoxAsComponent(childComplexity, args["id"].(int), args["name"].(string)), true case "Mutation.setBackground": if e.ComplexityRoot.Mutation.SetBackground == nil { break @@ -1012,6 +1160,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.UpdateBox(childComplexity, args["id"].(int), args["input"].(model.UpdateBoxInput)), true + case "Mutation.updateComponent": + if e.ComplexityRoot.Mutation.UpdateComponent == nil { + break + } + + args, err := ec.field_Mutation_updateComponent_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.UpdateComponent(childComplexity, args["id"].(int), args["input"].(model.UpdateComponentInput)), true case "Mutation.updateLayout": if e.ComplexityRoot.Mutation.UpdateLayout == nil { break @@ -1251,6 +1410,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Query.Boxes(childComplexity, args["page"].(string)), true + case "Query.components": + if e.ComplexityRoot.Query.Components == nil { + break + } + + return e.ComplexityRoot.Query.Components(childComplexity), true case "Query.favorites": if e.ComplexityRoot.Query.Favorites == nil { break @@ -1584,6 +1749,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputCreateActivityInput, ec.unmarshalInputCreateBookmarkInput, ec.unmarshalInputCreateBoxInput, + ec.unmarshalInputCreateComponentInput, ec.unmarshalInputCreateFavoriteInput, ec.unmarshalInputCreateLayoutInput, ec.unmarshalInputCreatePageInput, @@ -1592,6 +1758,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputCreateUserInput, ec.unmarshalInputLoginInput, ec.unmarshalInputUpdateBoxInput, + ec.unmarshalInputUpdateComponentInput, ec.unmarshalInputUpdateLayoutInput, ec.unmarshalInputUpdatePageInput, ec.unmarshalInputUpdatePlaceInput, @@ -1670,7 +1837,7 @@ func newExecutionContext( } } -//go:embed "schema/activity.graphql" "schema/auth.graphql" "schema/background.graphql" "schema/bookmark.graphql" "schema/box.graphql" "schema/favorite.graphql" "schema/gitea.graphql" "schema/layout.graphql" "schema/message.graphql" "schema/page.graphql" "schema/place.graphql" "schema/post.graphql" "schema/rowing.graphql" "schema/schema.graphql" "schema/spotify.graphql" "schema/steam.graphql" "schema/user.graphql" +//go:embed "schema/activity.graphql" "schema/auth.graphql" "schema/background.graphql" "schema/bookmark.graphql" "schema/box.graphql" "schema/component.graphql" "schema/favorite.graphql" "schema/gitea.graphql" "schema/layout.graphql" "schema/message.graphql" "schema/page.graphql" "schema/place.graphql" "schema/post.graphql" "schema/rowing.graphql" "schema/schema.graphql" "schema/spotify.graphql" "schema/steam.graphql" "schema/user.graphql" var sourcesFS embed.FS func sourceData(filename string) string { @@ -1687,6 +1854,7 @@ var sources = []*ast.Source{ {Name: "schema/background.graphql", Input: sourceData("schema/background.graphql"), BuiltIn: false}, {Name: "schema/bookmark.graphql", Input: sourceData("schema/bookmark.graphql"), BuiltIn: false}, {Name: "schema/box.graphql", Input: sourceData("schema/box.graphql"), BuiltIn: false}, + {Name: "schema/component.graphql", Input: sourceData("schema/component.graphql"), BuiltIn: false}, {Name: "schema/favorite.graphql", Input: sourceData("schema/favorite.graphql"), BuiltIn: false}, {Name: "schema/gitea.graphql", Input: sourceData("schema/gitea.graphql"), BuiltIn: false}, {Name: "schema/layout.graphql", Input: sourceData("schema/layout.graphql"), BuiltIn: false}, @@ -1802,10 +1970,40 @@ func (ec *executionContext) childFields_Box(ctx context.Context, field graphql.C return ec.fieldContext_Box_hideOnMobile(ctx, field) case "adminOnly": return ec.fieldContext_Box_adminOnly(ctx, field) + case "componentId": + return ec.fieldContext_Box_componentId(ctx, field) } return nil, fmt.Errorf("no field named %q was found under type Box", field.Name) } +func (ec *executionContext) childFields_Component(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Component_id(ctx, field) + case "createdAt": + return ec.fieldContext_Component_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Component_updatedAt(ctx, field) + case "name": + return ec.fieldContext_Component_name(ctx, field) + case "title": + return ec.fieldContext_Component_title(ctx, field) + case "html": + return ec.fieldContext_Component_html(ctx, field) + case "w": + return ec.fieldContext_Component_w(ctx, field) + case "h": + return ec.fieldContext_Component_h(ctx, field) + case "framed": + return ec.fieldContext_Component_framed(ctx, field) + case "adminOnly": + return ec.fieldContext_Component_adminOnly(ctx, field) + case "uses": + return ec.fieldContext_Component_uses(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Component", field.Name) +} + func (ec *executionContext) childFields_Favorite(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "id": @@ -2280,6 +2478,20 @@ func (ec *executionContext) field_Mutation_createBox_args(ctx context.Context, r return args, nil } +func (ec *executionContext) field_Mutation_createComponent_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "input", + func(ctx context.Context, v any) (model.CreateComponentInput, error) { + return ec.unmarshalNCreateComponentInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateComponentInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_createFavorite_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2392,6 +2604,20 @@ func (ec *executionContext) field_Mutation_deleteBox_args(ctx context.Context, r return args, nil } +func (ec *executionContext) field_Mutation_deleteComponent_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_deleteLayout_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2462,6 +2688,20 @@ func (ec *executionContext) field_Mutation_deleteUser_args(ctx context.Context, return args, nil } +func (ec *executionContext) field_Mutation_detachBox_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_login_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2476,6 +2716,28 @@ func (ec *executionContext) field_Mutation_login_args(ctx context.Context, rawAr return args, nil } +func (ec *executionContext) field_Mutation_saveBoxAsComponent_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + arg1, err := graphql.ProcessArgField(ctx, rawArgs, "name", + func(ctx context.Context, v any) (string, error) { + return ec.unmarshalNString2string(ctx, v) + }) + if err != nil { + return nil, err + } + args["name"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_setBackground_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2564,6 +2826,28 @@ func (ec *executionContext) field_Mutation_updateBox_args(ctx context.Context, r return args, nil } +func (ec *executionContext) field_Mutation_updateComponent_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { + var err error + args := map[string]any{} + arg0, err := graphql.ProcessArgField(ctx, rawArgs, "id", + func(ctx context.Context, v any) (int, error) { + return ec.unmarshalNID2int(ctx, v) + }) + if err != nil { + return nil, err + } + args["id"] = arg0 + arg1, err := graphql.ProcessArgField(ctx, rawArgs, "input", + func(ctx context.Context, v any) (model.UpdateComponentInput, error) { + return ec.unmarshalNUpdateComponentInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateComponentInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_updateLayout_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -3610,6 +3894,282 @@ func (ec *executionContext) fieldContext_Box_adminOnly(_ context.Context, field return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type Boolean does not have child fields")) } +func (ec *executionContext) _Box_componentId(ctx context.Context, field graphql.CollectedField, obj *models.Box) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Box_componentId(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.ComponentID, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v *uint) graphql.Marshaler { + return ec.marshalOID2ᚖuint(ctx, selections, v) + }, + true, + false, + ) +} +func (ec *executionContext) fieldContext_Box_componentId(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Box", field, false, false, errors.New("field of type ID does not have child fields")) +} + +func (ec *executionContext) _Component_id(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_id(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.ID, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v uint) graphql.Marshaler { + return ec.marshalNID2uint(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type ID does not have child fields")) +} + +func (ec *executionContext) _Component_createdAt(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_createdAt(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.CreatedAt, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v time.Time) graphql.Marshaler { + return ec.marshalNTime2timeᚐTime(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _Component_updatedAt(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_updatedAt(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.UpdatedAt, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v time.Time) graphql.Marshaler { + return ec.marshalNTime2timeᚐTime(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _Component_name(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_name(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Name, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler { + return ec.marshalNString2string(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Component_title(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_title(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Title, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v *string) graphql.Marshaler { + return ec.marshalOString2ᚖstring(ctx, selections, v) + }, + true, + false, + ) +} +func (ec *executionContext) fieldContext_Component_title(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Component_html(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_html(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.HTML, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v string) graphql.Marshaler { + return ec.marshalNString2string(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_html(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Component_w(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_w(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.W, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v int) graphql.Marshaler { + return ec.marshalNInt2int(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_w(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type Int does not have child fields")) +} + +func (ec *executionContext) _Component_h(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_h(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.H, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v int) graphql.Marshaler { + return ec.marshalNInt2int(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_h(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type Int does not have child fields")) +} + +func (ec *executionContext) _Component_framed(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_framed(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.Framed, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v bool) graphql.Marshaler { + return ec.marshalNBoolean2bool(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_framed(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type Boolean does not have child fields")) +} + +func (ec *executionContext) _Component_adminOnly(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_adminOnly(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.AdminOnly, nil + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v bool) graphql.Marshaler { + return ec.marshalNBoolean2bool(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_adminOnly(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, false, false, errors.New("field of type Boolean does not have child fields")) +} + +func (ec *executionContext) _Component_uses(ctx context.Context, field graphql.CollectedField, obj *models.Component) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Component_uses(ctx, field) + }, + func(ctx context.Context) (any, error) { + return ec.Resolvers.Component().Uses(ctx, obj) + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v int) graphql.Marshaler { + return ec.marshalNInt2int(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Component_uses(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Component", field, true, true, errors.New("field of type Int does not have child fields")) +} + func (ec *executionContext) _Favorite_id(ctx context.Context, field graphql.CollectedField, obj *models.Favorite) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -4740,6 +5300,291 @@ func (ec *executionContext) fieldContext_Mutation_deleteBox(ctx context.Context, return fc, nil } +func (ec *executionContext) _Mutation_createComponent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_createComponent(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().CreateComponent(ctx, fc.Args["input"].(model.CreateComponentInput)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.Component + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.Component) graphql.Marshaler { + return ec.marshalNComponent2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐComponent(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_createComponent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Component(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_createComponent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_updateComponent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_updateComponent(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().UpdateComponent(ctx, fc.Args["id"].(int), fc.Args["input"].(model.UpdateComponentInput)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.Component + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.Component) graphql.Marshaler { + return ec.marshalNComponent2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐComponent(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_updateComponent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Component(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_updateComponent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteComponent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_deleteComponent(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().DeleteComponent(ctx, fc.Args["id"].(int)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.Component + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.Component) graphql.Marshaler { + return ec.marshalNComponent2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐComponent(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_deleteComponent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Component(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_deleteComponent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_saveBoxAsComponent(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_saveBoxAsComponent(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().SaveBoxAsComponent(ctx, fc.Args["id"].(int), fc.Args["name"].(string)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.Box + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.Box) graphql.Marshaler { + return ec.marshalNBox2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐBox(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_saveBoxAsComponent(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Box(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_saveBoxAsComponent_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_detachBox(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Mutation_detachBox(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().DetachBox(ctx, fc.Args["id"].(int)) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal *models.Box + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v *models.Box) graphql.Marshaler { + return ec.marshalNBox2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐBox(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_detachBox(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Mutation", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Box(ctx, field) + }, + } + defer func() { + if r := recover(); r != nil { + err = ec.Recover(ctx, r) + ec.Error(ctx, err) + } + }() + ctx = graphql.WithFieldContext(ctx, fc) + if fc.Args, err = ec.field_Mutation_detachBox_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Mutation_createFavorite(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -6557,6 +7402,51 @@ func (ec *executionContext) fieldContext_Query_boxes(ctx context.Context, field return fc, nil } +func (ec *executionContext) _Query_components(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Query_components(ctx, field) + }, + func(ctx context.Context) (any, error) { + return ec.Resolvers.Query().Components(ctx) + }, + func(ctx context.Context, next graphql.Resolver) graphql.Resolver { + directive0 := next + + directive1 := func(ctx context.Context) (any, error) { + if ec.Directives.Admin == nil { + var zeroVal []*models.Component + return zeroVal, errors.New("directive admin is not implemented") + } + return ec.Directives.Admin(ctx, nil, directive0) + } + + next = directive1 + return next + }, + func(ctx context.Context, selections ast.SelectionSet, v []*models.Component) graphql.Marshaler { + return ec.marshalNComponent2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐComponentᚄ(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Query_components(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "Query", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.childFields_Component(ctx, field) + }, + } + return fc, nil +} + func (ec *executionContext) _Query_favorites(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -9238,7 +10128,7 @@ func (ec *executionContext) unmarshalInputCreateBoxInput(ctx context.Context, ob asMap[k] = v } - fieldsInOrder := [...]string{"page", "kind", "widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile", "adminOnly"} + fieldsInOrder := [...]string{"page", "kind", "widget", "html", "title", "x", "y", "w", "h", "z", "framed", "hideOnMobile", "adminOnly", "componentId"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -9336,6 +10226,85 @@ func (ec *executionContext) unmarshalInputCreateBoxInput(ctx context.Context, ob return it, err } it.AdminOnly = data + case "componentId": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("componentId")) + data, err := ec.unmarshalOID2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.ComponentID = data + } + } + return it, nil +} + +func (ec *executionContext) unmarshalInputCreateComponentInput(ctx context.Context, obj any) (model.CreateComponentInput, error) { + var it model.CreateComponentInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"name", "title", "html", "w", "h", "framed", "adminOnly"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "html": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("html")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.HTML = data + case "w": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("w")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.W = data + case "h": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("h")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.H = data + case "framed": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("framed")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.Framed = data + case "adminOnly": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.AdminOnly = data } } return it, nil @@ -9756,6 +10725,78 @@ func (ec *executionContext) unmarshalInputUpdateBoxInput(ctx context.Context, ob return it, nil } +func (ec *executionContext) unmarshalInputUpdateComponentInput(ctx context.Context, obj any) (model.UpdateComponentInput, error) { + var it model.UpdateComponentInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"name", "title", "html", "w", "h", "framed", "adminOnly"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "name": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Name = data + case "title": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.Title = data + case "html": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("html")) + data, err := ec.unmarshalOString2ᚖstring(ctx, v) + if err != nil { + return it, err + } + it.HTML = data + case "w": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("w")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.W = data + case "h": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("h")) + data, err := ec.unmarshalOInt2ᚖint(ctx, v) + if err != nil { + return it, err + } + it.H = data + case "framed": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("framed")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.Framed = data + case "adminOnly": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("adminOnly")) + data, err := ec.unmarshalOBoolean2ᚖbool(ctx, v) + if err != nil { + return it, err + } + it.AdminOnly = data + } + } + return it, nil +} + func (ec *executionContext) unmarshalInputUpdateLayoutInput(ctx context.Context, obj any) (model.UpdateLayoutInput, error) { var it model.UpdateLayoutInput if obj == nil { @@ -10273,6 +11314,132 @@ func (ec *executionContext) _Box(ctx context.Context, sel ast.SelectionSet, obj if out.Values[i] == graphql.Null { out.Invalids++ } + case "componentId": + out.Values[i] = ec._Box_componentId(ctx, field, obj) + if out.Values[i] == graphql.RequiredNull { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.Deferred, int32(min(len(deferLabelToView), math.MaxInt32))) + + ec.ProcessDeferredGroup(graphql.DeferredGroup{ + Defers: deferLabelToView, + Path: graphql.GetPath(ctx), + FieldSet: deferredFieldSet, + Context: ctx, + }) + + return out +} + +var componentImplementors = []string{"Component"} + +func (ec *executionContext) _Component(ctx context.Context, sel ast.SelectionSet, obj *models.Component) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, componentImplementors) + + out := graphql.NewFieldSet(fields) + deferredFieldSet := graphql.NewFieldSet(nil) + deferLabelToView := make(map[string]*graphql.FieldSetView) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Component") + case "id": + out.Values[i] = ec._Component_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "createdAt": + out.Values[i] = ec._Component_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "updatedAt": + out.Values[i] = ec._Component_updatedAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "name": + out.Values[i] = ec._Component_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "title": + out.Values[i] = ec._Component_title(ctx, field, obj) + if out.Values[i] == graphql.RequiredNull { + atomic.AddUint32(&out.Invalids, 1) + } + case "html": + out.Values[i] = ec._Component_html(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "w": + out.Values[i] = ec._Component_w(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "h": + out.Values[i] = ec._Component_h(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "framed": + out.Values[i] = ec._Component_framed(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "adminOnly": + out.Values[i] = ec._Component_adminOnly(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "uses": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Component_uses(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + if field.IsDeferred() { + deferredFieldSet.AddField(field) + fieldIndex := len(deferredFieldSet.Values) - 1 + deferredFieldSet.Concurrently(fieldIndex, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, deferredFieldSet) + }) + + for _, deferrable := range field.Deferrables { + view, ok := deferLabelToView[deferrable.Label] + if !ok { + view = deferredFieldSet.NewView() + deferLabelToView[deferrable.Label] = view + } + view.AddIndices(fieldIndex) + } + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -10747,6 +11914,41 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { out.Invalids++ } + case "createComponent": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createComponent(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updateComponent": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updateComponent(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deleteComponent": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteComponent(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "saveBoxAsComponent": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_saveBoxAsComponent(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "detachBox": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_detachBox(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "createFavorite": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_createFavorite(ctx, field) @@ -11285,6 +12487,28 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) + case "components": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_components(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + rrm := func(ctx context.Context) graphql.Marshaler { + return ec.OperationContext.RootResolverMiddleware(ctx, + func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return rrm(innerCtx) }) case "favorites": field := field @@ -12757,6 +13981,32 @@ func (ec *executionContext) marshalNBox2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋm return ec._Box(ctx, sel, v) } +func (ec *executionContext) marshalNComponent2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐComponentᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Component) graphql.Marshaler { + ret := graphql.MarshalSliceConcurrently(ctx, len(v), 0, false, func(ctx context.Context, i int) graphql.Marshaler { + fc := graphql.GetFieldContext(ctx) + fc.Result = &v[i] + return ec.marshalNComponent2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐComponent(ctx, sel, v[i]) + }) + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNComponent2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐComponent(ctx context.Context, sel ast.SelectionSet, v *models.Component) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + graphql.AddErrorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._Component(ctx, sel, v) +} + func (ec *executionContext) unmarshalNCreateActivityInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateActivityInput(ctx context.Context, v any) (model.CreateActivityInput, error) { res, err := ec.unmarshalInputCreateActivityInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -12772,6 +14022,11 @@ func (ec *executionContext) unmarshalNCreateBoxInput2adamᚑfrenchᚗcoᚗukᚋb return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateComponentInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateComponentInput(ctx context.Context, v any) (model.CreateComponentInput, error) { + res, err := ec.unmarshalInputCreateComponentInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCreateFavoriteInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateFavoriteInput(ctx context.Context, v any) (model.CreateFavoriteInput, error) { res, err := ec.unmarshalInputCreateFavoriteInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -13253,6 +14508,11 @@ func (ec *executionContext) unmarshalNUpdateBoxInput2adamᚑfrenchᚗcoᚗukᚋb return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNUpdateComponentInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateComponentInput(ctx context.Context, v any) (model.UpdateComponentInput, error) { + res, err := ec.unmarshalInputUpdateComponentInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNUpdateLayoutInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateLayoutInput(ctx context.Context, v any) (model.UpdateLayoutInput, error) { res, err := ec.unmarshalInputUpdateLayoutInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -13483,6 +14743,42 @@ func (ec *executionContext) marshalOGiteaFeedItem2ᚖadamᚑfrenchᚗcoᚗukᚋb return ec._GiteaFeedItem(ctx, sel, v) } +func (ec *executionContext) unmarshalOID2ᚖint(ctx context.Context, v any) (*int, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalIntID(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOID2ᚖint(ctx context.Context, sel ast.SelectionSet, v *int) graphql.Marshaler { + if v == nil { + return graphql.Null + } + _ = sel + _ = ctx + res := graphql.MarshalIntID(*v) + return res +} + +func (ec *executionContext) unmarshalOID2ᚖuint(ctx context.Context, v any) (*uint, error) { + if v == nil { + return nil, nil + } + res, err := graphql.UnmarshalUintID(v) + return &res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalOID2ᚖuint(ctx context.Context, sel ast.SelectionSet, v *uint) graphql.Marshaler { + if v == nil { + return graphql.Null + } + _ = sel + _ = ctx + res := graphql.MarshalUintID(*v) + return res +} + func (ec *executionContext) unmarshalOInt2ᚖint(ctx context.Context, v any) (*int, error) { if v == nil { return nil, nil diff --git a/backend/graph/layout.resolvers.go b/backend/graph/layout.resolvers.go index 15c21bc..f499517 100644 --- a/backend/graph/layout.resolvers.go +++ b/backend/graph/layout.resolvers.go @@ -126,6 +126,9 @@ func (r *mutationResolver) ApplyLayout(ctx context.Context, id int, page string, if err != nil { return nil, err } + if err := fillLinked(r.Store.DB, boxes); err != nil { + return nil, err + } return ptrs(boxes), nil } diff --git a/backend/graph/layout_helpers.go b/backend/graph/layout_helpers.go index 4ba292b..c51bb30 100644 --- a/backend/graph/layout_helpers.go +++ b/backend/graph/layout_helpers.go @@ -33,6 +33,10 @@ type layoutBox struct { Framed bool `json:"framed"` HideOnMobile bool `json:"hideOnMobile"` AdminOnly bool `json:"adminOnly"` + // ComponentID is the component a linked box was linked to. HTML is + // stored too, so that a layout outlives the component: loading links the + // box again if the component is still there and uses HTML if not. + ComponentID *uint `json:"componentId,omitempty"` } type layoutBackground struct { @@ -92,12 +96,16 @@ func snapshotPage(db *gorm.DB, page, name string) (layout models.Layout, empty b if err != nil { return layout, false, err } + if err := fillLinked(db, boxes); 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, + ComponentID: b.ComponentID, } } boxesJSON, err := json.Marshal(stored) @@ -200,6 +208,10 @@ func applyLayoutTo(tx *gorm.DB, layout *models.Layout, page string, replace bool } } + live, err := liveComponents(tx, stored) + if err != nil { + return err + } boxes := make([]models.Box, len(stored)) for i, b := range stored { boxes[i] = models.Box{ @@ -207,6 +219,10 @@ func applyLayoutTo(tx *gorm.DB, layout *models.Layout, page string, replace bool 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 b.ComponentID != nil && live[*b.ComponentID] { + boxes[i].ComponentID = b.ComponentID + boxes[i].HTML = nil + } if err := validateBox(&boxes[i]); err != nil { return err } @@ -233,3 +249,26 @@ func applyLayoutTo(tx *gorm.DB, layout *models.Layout, page string, replace bool } return nil } + +// liveComponents is the set of components the stored boxes were linked to +// that still exist, so applyLayoutTo knows which boxes to link again. +func liveComponents(db *gorm.DB, stored []layoutBox) (map[uint]bool, error) { + var ids []uint + for _, b := range stored { + if b.ComponentID != nil { + ids = append(ids, *b.ComponentID) + } + } + live := map[uint]bool{} + if len(ids) == 0 { + return live, nil + } + var found []uint + if err := db.Model(&models.Component{}).Where("id IN ?", ids).Pluck("id", &found).Error; err != nil { + return nil, err + } + for _, id := range found { + live[id] = true + } + return live, nil +} diff --git a/backend/graph/model/models_gen.go b/backend/graph/model/models_gen.go index a321f8f..6417b02 100644 --- a/backend/graph/model/models_gen.go +++ b/backend/graph/model/models_gen.go @@ -44,6 +44,17 @@ type CreateBoxInput struct { Framed *bool `json:"framed,omitempty"` HideOnMobile *bool `json:"hideOnMobile,omitempty"` AdminOnly *bool `json:"adminOnly,omitempty"` + ComponentID *int `json:"componentId,omitempty"` +} + +type CreateComponentInput struct { + Name string `json:"name"` + Title *string `json:"title,omitempty"` + HTML string `json:"html"` + W *int `json:"w,omitempty"` + H *int `json:"h,omitempty"` + Framed *bool `json:"framed,omitempty"` + AdminOnly *bool `json:"adminOnly,omitempty"` } type CreateFavoriteInput struct { @@ -160,6 +171,16 @@ type UpdateBoxInput struct { AdminOnly *bool `json:"adminOnly,omitempty"` } +type UpdateComponentInput struct { + Name *string `json:"name,omitempty"` + Title *string `json:"title,omitempty"` + HTML *string `json:"html,omitempty"` + W *int `json:"w,omitempty"` + H *int `json:"h,omitempty"` + Framed *bool `json:"framed,omitempty"` + AdminOnly *bool `json:"adminOnly,omitempty"` +} + type UpdateLayoutInput struct { Name *string `json:"name,omitempty"` } diff --git a/backend/graph/schema/box.graphql b/backend/graph/schema/box.graphql index c1b8021..89b6052 100644 --- a/backend/graph/schema/box.graphql +++ b/backend/graph/schema/box.graphql @@ -5,7 +5,9 @@ # are px on a fixed 1400px-wide design canvas; see models.Box. # # kind is "widget" (a built-in Vue component named by `widget`) or "html" -# (`html` rendered in a sandboxed iframe on the front end). +# (`html` rendered in a sandboxed iframe on the front end). An html box with a +# componentId is linked to that Component: its html is the component's, and +# updateBox refuses to change it (component.graphql). type Box { id: ID! @@ -24,6 +26,7 @@ type Box { framed: Boolean! hideOnMobile: Boolean! adminOnly: Boolean! + componentId: ID } input CreateBoxInput { @@ -40,6 +43,9 @@ input CreateBoxInput { framed: Boolean hideOnMobile: Boolean adminOnly: Boolean + # Links the new box to this component; kind is then "html" and html is + # ignored. + componentId: ID } input UpdateBoxInput { diff --git a/backend/graph/schema/component.graphql b/backend/graph/schema/component.graphql new file mode 100644 index 0000000..ce3a02d --- /dev/null +++ b/backend/graph/schema/component.graphql @@ -0,0 +1,64 @@ +# Components: named HTML boxes that can be placed on any canvas page, either +# as a copy (an ordinary box) or linked (a Box whose componentId is set). +# Linked boxes share only the html — editing a component changes every box +# linked to it — while title, geometry, frame and visibility stay each box's +# own. title, w, h, framed and adminOnly here are what a newly placed box +# starts with. See models.Component and graph/component_helpers.go. +# +# Admin only throughout, reads included, because a component may have been +# saved from an adminOnly note. A linked box's html still reaches visitors +# through the boxes query, which is the point. + +type Component { + id: ID! + createdAt: Time! + updatedAt: Time! + name: String! + title: String + html: String! + w: Int! + h: Int! + framed: Boolean! + adminOnly: Boolean! + # How many boxes are linked to it. + uses: Int! +} + +input CreateComponentInput { + name: String! + title: String + html: String! + w: Int + h: Int + framed: Boolean + adminOnly: Boolean +} + +input UpdateComponentInput { + name: String + title: String + html: String + w: Int + h: Int + framed: Boolean + adminOnly: Boolean +} + +extend type Query { + # By name. + components: [Component!]! @admin +} + +extend type Mutation { + createComponent(input: CreateComponentInput!): Component! @admin + # A new html changes every box linked to it. + updateComponent(id: ID!, input: UpdateComponentInput!): Component! @admin + # Detaches every linked box first, giving each its own copy of the html, so + # no page changes. + deleteComponent(id: ID!): Component! @admin + # Makes html box `id` into a component named `name`, from its html, title, + # size, frame and adminOnly, and links the box to it. Answers with the box. + saveBoxAsComponent(id: ID!, name: String!): Box! @admin + # Gives linked box `id` its own copy of the component's html and unlinks it. + detachBox(id: ID!): Box! @admin +} diff --git a/backend/models/models.go b/backend/models/models.go index 595a91a..6acd99b 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -196,6 +196,12 @@ type Box struct { // AdminOnly boxes are never sent to anyone but an admin (the boxes // resolver filters them out), so they suit private notes. AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"` + // ComponentID links an html box to a Component, whose HTML it shows + // instead of its own: the row's HTML is nil, and the resolvers fill it in + // from the component before answering (graph/component_helpers.go). There + // is deliberately no association field — with one, DB.Save(&box) would + // write the component back too. + ComponentID *uint `gorm:"index" json:"componentId"` } // Page is an admin-created canvas page, served by the SPA's catch-all route @@ -254,3 +260,26 @@ type Layout struct { // Background is the page's background as JSON, or nil if it had none. Background *string `gorm:"type:text" json:"-"` } + +// Component is a named HTML box that can be placed on any canvas page, either +// as a copy (an ordinary box) or linked (a box with ComponentID set). Linked +// boxes share only the HTML — editing it changes every one of them at once — +// while title, geometry, frame and visibility stay each box's own, since +// those are about where it sits on a page rather than what it is. Title, W, +// H, Framed and AdminOnly are the defaults a newly placed box starts with. +// Widgets are not components: a widget box is just a name, with nothing +// worth sharing. The unique index is partial for the same reason as Page's. +type Component 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_components_name,unique,where:deleted_at IS NULL" json:"name"` + Title *string `json:"title"` + HTML string `gorm:"type:text;not null" json:"html"` + W int `gorm:"not null" json:"w"` + H int `gorm:"not null" json:"h"` + // No gorm default on Framed, for the same reason as Box.Framed. + Framed bool `gorm:"not null" json:"framed"` + AdminOnly bool `gorm:"not null;default:false" json:"adminOnly"` +} diff --git a/backend/services/database.go b/backend/services/database.go index 3c44145..3bc9cd2 100644 --- a/backend/services/database.go +++ b/backend/services/database.go @@ -55,6 +55,7 @@ func migrateDatabase(db *gorm.DB) error { &models.Page{}, &models.Background{}, &models.Layout{}, + &models.Component{}, ) if err != nil { return err diff --git a/vue/README.md b/vue/README.md index c377f86..7c8f709 100644 --- a/vue/README.md +++ b/vue/README.md @@ -264,6 +264,21 @@ renders any page's boxes. 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. +- **Components.** A **`Component`** (GraphQL type, `stores/components.js`) is + a named HTML box. "+ New box" lists them and places a copy, an ordinary box. + The "Components" button (`ComponentPanel.vue`) can also place one + **linked**: the box has a `componentId`, the server answers with the + component's html in its `html` (`fillLinked` in + `backend/graph/component_helpers.go`), and saving the html in `BoxEditor` + saves the component, so every linked box on every page changes. Only the + html is shared; title, geometry, frame and visibility stay each box's own. + "Save as component" in the editor makes a component from an html box and + links it; "Detach" gives a linked box its own copy. Deleting a component + detaches its boxes first, so no page changes. A layout keeps both the link + and the html, and loading it links again only if the component still + exists. The built-in starters in `templates.js` are not listed directly: + "Import built-ins" in the panel makes them components, after which they can + be edited or deleted like the rest. Admin-only throughout. - **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 such boxes outlined, with a 🔒 in edit mode. The "Note" template starts @@ -301,7 +316,7 @@ renders any page's boxes. file through `@/uploads` (see "Uploading files") and puts an ``/`