diff --git a/CLAUDE.md b/CLAUDE.md index 42cb42c..41b36da 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) +- `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) - `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. `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 `/` 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/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/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 39ac09d..8a55a2c 100644 --- a/backend/gqlgen.yml +++ b/backend/gqlgen.yml @@ -94,3 +94,13 @@ models: fields: deletedAt: resolver: false + Layout: + model: + - adam-french.co.uk/backend/models.Layout + fields: + deletedAt: + resolver: false + boxCount: + resolver: true + hasBackground: + resolver: true diff --git a/backend/graph/directives_test.go b/backend/graph/directives_test.go index 04c9c84..2380e7d 100644 --- a/backend/graph/directives_test.go +++ b/backend/graph/directives_test.go @@ -187,9 +187,10 @@ func TestSignedInMutationsArePinned(t *testing.T) { // `spotifyNeedsReauth` is false for non-admins. func TestGuardedQueriesArePinned(t *testing.T) { want := map[string]string{ - "users": "admin", - "user": "admin", - "places": "signedIn", + "users": "admin", + "user": "admin", + "places": "signedIn", + "layouts": "admin", } got := map[string]string{} for _, field := range schemaUnderTest().Query.Fields { diff --git a/backend/graph/generated.go b/backend/graph/generated.go index 86b6db8..4791401 100644 --- a/backend/graph/generated.go +++ b/backend/graph/generated.go @@ -31,6 +31,7 @@ func NewExecutableSchema(cfg Config) graphql.ExecutableSchema { type Config = graphql.Config[ResolverRoot, DirectiveRoot, ComplexityRoot] type ResolverRoot interface { + Layout() LayoutResolver Message() MessageResolver Mutation() MutationResolver Query() QueryResolver @@ -111,6 +112,16 @@ type ComplexityRoot struct { RepoURL func(childComplexity int) int } + Layout struct { + BoxCount func(childComplexity int) int + CreatedAt func(childComplexity int) int + HasBackground func(childComplexity int) int + ID func(childComplexity int) int + Name func(childComplexity int) int + SourcePage func(childComplexity int) int + UpdatedAt func(childComplexity int) int + } + Message struct { AuthorID func(childComplexity int) int Content func(childComplexity int) int @@ -121,17 +132,20 @@ type ComplexityRoot struct { } Mutation struct { + ApplyLayout func(childComplexity int, id int, page string, replace bool) int ClearBackground func(childComplexity int, page string) int CreateActivity func(childComplexity int, input model.CreateActivityInput) int CreateBookmark func(childComplexity int, input model.CreateBookmarkInput) int CreateBox func(childComplexity int, input model.CreateBoxInput) 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 CreatePlace func(childComplexity int, input model.CreatePlaceInput) int CreatePost func(childComplexity int, input model.CreatePostInput) int CreateUser func(childComplexity int, input model.CreateUserInput) int DeleteBookmark func(childComplexity int, id int) int DeleteBox 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 @@ -142,6 +156,7 @@ type ComplexityRoot struct { SetBackground func(childComplexity int, page string, input model.BackgroundInput) int SetUserAdmin func(childComplexity int, id int, admin bool) int UpdateBox func(childComplexity int, id int, input model.UpdateBoxInput) 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 UpdatePost func(childComplexity int, id int, input model.UpdatePostInput) int @@ -186,6 +201,7 @@ type ComplexityRoot struct { Boxes func(childComplexity int, page string) int Favorites func(childComplexity int) int GiteaFeed func(childComplexity int) int + Layouts func(childComplexity int) int Me func(childComplexity int) int Messages func(childComplexity int) int Page func(childComplexity int, slug string) int @@ -267,6 +283,10 @@ type ComplexityRoot struct { // region ************************** generated!.gotpl ************************** +type LayoutResolver interface { + BoxCount(ctx context.Context, obj *models.Layout) (int, error) + HasBackground(ctx context.Context, obj *models.Layout) (bool, error) +} type MessageResolver interface { AuthorID(ctx context.Context, obj *models.Message) (int, error) } @@ -283,6 +303,10 @@ type MutationResolver interface { UpdateBox(ctx context.Context, id int, input model.UpdateBoxInput) (*models.Box, error) DeleteBox(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) + DeleteLayout(ctx context.Context, id int) (*models.Layout, error) + ApplyLayout(ctx context.Context, id int, page string, replace bool) ([]*models.Box, error) CreatePage(ctx context.Context, input model.CreatePageInput) (*models.Page, error) UpdatePage(ctx context.Context, id int, input model.UpdatePageInput) (*models.Page, error) DeletePage(ctx context.Context, id int) (*models.Page, error) @@ -304,6 +328,7 @@ type QueryResolver interface { Boxes(ctx context.Context, page string) ([]*models.Box, error) Favorites(ctx context.Context) ([]*models.Favorite, error) GiteaFeed(ctx context.Context) (*model.GiteaFeedItem, error) + Layouts(ctx context.Context) ([]*models.Layout, error) Messages(ctx context.Context) ([]*models.Message, error) Pages(ctx context.Context) ([]*models.Page, error) Page(ctx context.Context, slug string) (*models.Page, error) @@ -630,6 +655,49 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.ComplexityRoot.GiteaFeedItem.RepoURL(childComplexity), true + case "Layout.boxCount": + if e.ComplexityRoot.Layout.BoxCount == nil { + break + } + + return e.ComplexityRoot.Layout.BoxCount(childComplexity), true + case "Layout.createdAt": + if e.ComplexityRoot.Layout.CreatedAt == nil { + break + } + + return e.ComplexityRoot.Layout.CreatedAt(childComplexity), true + case "Layout.hasBackground": + if e.ComplexityRoot.Layout.HasBackground == nil { + break + } + + return e.ComplexityRoot.Layout.HasBackground(childComplexity), true + case "Layout.id": + if e.ComplexityRoot.Layout.ID == nil { + break + } + + return e.ComplexityRoot.Layout.ID(childComplexity), true + case "Layout.name": + if e.ComplexityRoot.Layout.Name == nil { + break + } + + return e.ComplexityRoot.Layout.Name(childComplexity), true + case "Layout.sourcePage": + if e.ComplexityRoot.Layout.SourcePage == nil { + break + } + + return e.ComplexityRoot.Layout.SourcePage(childComplexity), true + case "Layout.updatedAt": + if e.ComplexityRoot.Layout.UpdatedAt == nil { + break + } + + return e.ComplexityRoot.Layout.UpdatedAt(childComplexity), true + case "Message.authorId": if e.ComplexityRoot.Message.AuthorID == nil { break @@ -667,6 +735,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.ComplexityRoot.Message.Private(childComplexity), true + case "Mutation.applyLayout": + if e.ComplexityRoot.Mutation.ApplyLayout == nil { + break + } + + args, err := ec.field_Mutation_applyLayout_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.ApplyLayout(childComplexity, args["id"].(int), args["page"].(string), args["replace"].(bool)), true case "Mutation.clearBackground": if e.ComplexityRoot.Mutation.ClearBackground == nil { break @@ -722,6 +801,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.CreateFavorite(childComplexity, args["input"].(model.CreateFavoriteInput)), true + case "Mutation.createLayout": + if e.ComplexityRoot.Mutation.CreateLayout == nil { + break + } + + args, err := ec.field_Mutation_createLayout_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.CreateLayout(childComplexity, args["input"].(model.CreateLayoutInput)), true case "Mutation.createPage": if e.ComplexityRoot.Mutation.CreatePage == nil { break @@ -788,6 +878,17 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin } return e.ComplexityRoot.Mutation.DeleteBox(childComplexity, args["id"].(int)), true + case "Mutation.deleteLayout": + if e.ComplexityRoot.Mutation.DeleteLayout == nil { + break + } + + args, err := ec.field_Mutation_deleteLayout_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.DeleteLayout(childComplexity, args["id"].(int)), true case "Mutation.deletePage": if e.ComplexityRoot.Mutation.DeletePage == nil { break @@ -888,6 +989,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.updateLayout": + if e.ComplexityRoot.Mutation.UpdateLayout == nil { + break + } + + args, err := ec.field_Mutation_updateLayout_args(ctx, rawArgs) + if err != nil { + return 0, false + } + + return e.ComplexityRoot.Mutation.UpdateLayout(childComplexity, args["id"].(int), args["input"].(model.UpdateLayoutInput)), true case "Mutation.updatePage": if e.ComplexityRoot.Mutation.UpdatePage == nil { break @@ -1110,6 +1222,12 @@ func (e *executableSchema) Complexity(ctx context.Context, typeName, field strin return e.ComplexityRoot.Query.GiteaFeed(childComplexity), true + case "Query.layouts": + if e.ComplexityRoot.Query.Layouts == nil { + break + } + + return e.ComplexityRoot.Query.Layouts(childComplexity), true case "Query.me": if e.ComplexityRoot.Query.Me == nil { break @@ -1413,12 +1531,14 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputCreateBookmarkInput, ec.unmarshalInputCreateBoxInput, ec.unmarshalInputCreateFavoriteInput, + ec.unmarshalInputCreateLayoutInput, ec.unmarshalInputCreatePageInput, ec.unmarshalInputCreatePlaceInput, ec.unmarshalInputCreatePostInput, ec.unmarshalInputCreateUserInput, ec.unmarshalInputLoginInput, ec.unmarshalInputUpdateBoxInput, + ec.unmarshalInputUpdateLayoutInput, ec.unmarshalInputUpdatePageInput, ec.unmarshalInputUpdatePlaceInput, ec.unmarshalInputUpdatePostInput, @@ -1496,7 +1616,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/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/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 { @@ -1515,6 +1635,7 @@ var sources = []*ast.Source{ {Name: "schema/box.graphql", Input: sourceData("schema/box.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}, {Name: "schema/message.graphql", Input: sourceData("schema/message.graphql"), BuiltIn: false}, {Name: "schema/page.graphql", Input: sourceData("schema/page.graphql"), BuiltIn: false}, {Name: "schema/place.graphql", Input: sourceData("schema/place.graphql"), BuiltIn: false}, @@ -1667,6 +1788,26 @@ func (ec *executionContext) childFields_GiteaFeedItem(ctx context.Context, field return nil, fmt.Errorf("no field named %q was found under type GiteaFeedItem", field.Name) } +func (ec *executionContext) childFields_Layout(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "id": + return ec.fieldContext_Layout_id(ctx, field) + case "createdAt": + return ec.fieldContext_Layout_createdAt(ctx, field) + case "updatedAt": + return ec.fieldContext_Layout_updatedAt(ctx, field) + case "name": + return ec.fieldContext_Layout_name(ctx, field) + case "sourcePage": + return ec.fieldContext_Layout_sourcePage(ctx, field) + case "boxCount": + return ec.fieldContext_Layout_boxCount(ctx, field) + case "hasBackground": + return ec.fieldContext_Layout_hasBackground(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type Layout", field.Name) +} + func (ec *executionContext) childFields_Message(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "id": @@ -1985,6 +2126,36 @@ func (ec *executionContext) childFields___Type(ctx context.Context, field graphq // region ***************************** args.gotpl ***************************** +func (ec *executionContext) field_Mutation_applyLayout_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, "page", + func(ctx context.Context, v any) (string, error) { + return ec.unmarshalNString2string(ctx, v) + }) + if err != nil { + return nil, err + } + args["page"] = arg1 + arg2, err := graphql.ProcessArgField(ctx, rawArgs, "replace", + func(ctx context.Context, v any) (bool, error) { + return ec.unmarshalNBoolean2bool(ctx, v) + }) + if err != nil { + return nil, err + } + args["replace"] = arg2 + return args, nil +} + func (ec *executionContext) field_Mutation_clearBackground_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2055,6 +2226,20 @@ func (ec *executionContext) field_Mutation_createFavorite_args(ctx context.Conte return args, nil } +func (ec *executionContext) field_Mutation_createLayout_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.CreateLayoutInput, error) { + return ec.unmarshalNCreateLayoutInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateLayoutInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg0 + return args, nil +} + func (ec *executionContext) field_Mutation_createPage_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2139,6 +2324,20 @@ func (ec *executionContext) field_Mutation_deleteBox_args(ctx context.Context, r 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{} + 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_deletePage_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -2275,6 +2474,28 @@ func (ec *executionContext) field_Mutation_updateBox_args(ctx context.Context, r 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{} + 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.UpdateLayoutInput, error) { + return ec.unmarshalNUpdateLayoutInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdateLayoutInput(ctx, v) + }) + if err != nil { + return nil, err + } + args["input"] = arg1 + return args, nil +} + func (ec *executionContext) field_Mutation_updatePage_args(ctx context.Context, rawArgs map[string]any) (map[string]any, error) { var err error args := map[string]any{} @@ -3575,6 +3796,167 @@ func (ec *executionContext) fieldContext_GiteaFeedItem_createdAt(_ context.Conte return graphql.NewScalarFieldContext("GiteaFeedItem", field, false, false, errors.New("field of type Time does not have child fields")) } +func (ec *executionContext) _Layout_id(ctx context.Context, field graphql.CollectedField, obj *models.Layout) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Layout_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_Layout_id(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Layout", field, false, false, errors.New("field of type ID does not have child fields")) +} + +func (ec *executionContext) _Layout_createdAt(ctx context.Context, field graphql.CollectedField, obj *models.Layout) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Layout_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_Layout_createdAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Layout", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _Layout_updatedAt(ctx context.Context, field graphql.CollectedField, obj *models.Layout) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Layout_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_Layout_updatedAt(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Layout", field, false, false, errors.New("field of type Time does not have child fields")) +} + +func (ec *executionContext) _Layout_name(ctx context.Context, field graphql.CollectedField, obj *models.Layout) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Layout_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_Layout_name(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Layout", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Layout_sourcePage(ctx context.Context, field graphql.CollectedField, obj *models.Layout) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Layout_sourcePage(ctx, field) + }, + func(ctx context.Context) (any, error) { + return obj.SourcePage, 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_Layout_sourcePage(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Layout", field, false, false, errors.New("field of type String does not have child fields")) +} + +func (ec *executionContext) _Layout_boxCount(ctx context.Context, field graphql.CollectedField, obj *models.Layout) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Layout_boxCount(ctx, field) + }, + func(ctx context.Context) (any, error) { + return ec.Resolvers.Layout().BoxCount(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_Layout_boxCount(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Layout", field, true, true, errors.New("field of type Int does not have child fields")) +} + +func (ec *executionContext) _Layout_hasBackground(ctx context.Context, field graphql.CollectedField, obj *models.Layout) (ret graphql.Marshaler) { + return graphql.ResolveField( + ctx, + ec.OperationContext, + field, + func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return ec.fieldContext_Layout_hasBackground(ctx, field) + }, + func(ctx context.Context) (any, error) { + return ec.Resolvers.Layout().HasBackground(ctx, obj) + }, + nil, + func(ctx context.Context, selections ast.SelectionSet, v bool) graphql.Marshaler { + return ec.marshalNBoolean2bool(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Layout_hasBackground(_ context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + return graphql.NewScalarFieldContext("Layout", field, true, true, errors.New("field of type Boolean does not have child fields")) +} + func (ec *executionContext) _Message_id(ctx context.Context, field graphql.CollectedField, obj *models.Message) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -4325,6 +4707,234 @@ func (ec *executionContext) fieldContext_Mutation_createFavorite(ctx context.Con return fc, nil } +func (ec *executionContext) _Mutation_createLayout(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_createLayout(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().CreateLayout(ctx, fc.Args["input"].(model.CreateLayoutInput)) + }, + 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.Layout + 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.Layout) graphql.Marshaler { + return ec.marshalNLayout2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐLayout(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_createLayout(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_Layout(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_createLayout_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_updateLayout(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_updateLayout(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().UpdateLayout(ctx, fc.Args["id"].(int), fc.Args["input"].(model.UpdateLayoutInput)) + }, + 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.Layout + 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.Layout) graphql.Marshaler { + return ec.marshalNLayout2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐLayout(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_updateLayout(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_Layout(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_updateLayout_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_deleteLayout(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_deleteLayout(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().DeleteLayout(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.Layout + 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.Layout) graphql.Marshaler { + return ec.marshalNLayout2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐLayout(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Mutation_deleteLayout(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_Layout(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_deleteLayout_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + +func (ec *executionContext) _Mutation_applyLayout(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_applyLayout(ctx, field) + }, + func(ctx context.Context) (any, error) { + fc := graphql.GetFieldContext(ctx) + return ec.Resolvers.Mutation().ApplyLayout(ctx, fc.Args["id"].(int), fc.Args["page"].(string), fc.Args["replace"].(bool)) + }, + 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_applyLayout(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_applyLayout_args(ctx, field.ArgumentMap(ec.Variables)); err != nil { + ec.Error(ctx, err) + return fc, err + } + return fc, nil +} + func (ec *executionContext) _Mutation_createPage(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -5795,6 +6405,51 @@ func (ec *executionContext) fieldContext_Query_giteaFeed(_ context.Context, fiel return fc, nil } +func (ec *executionContext) _Query_layouts(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_layouts(ctx, field) + }, + func(ctx context.Context) (any, error) { + return ec.Resolvers.Query().Layouts(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.Layout + 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.Layout) graphql.Marshaler { + return ec.marshalNLayout2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐLayoutᚄ(ctx, selections, v) + }, + true, + true, + ) +} +func (ec *executionContext) fieldContext_Query_layouts(_ 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_Layout(ctx, field) + }, + } + return fc, nil +} + func (ec *executionContext) _Query_messages(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { return graphql.ResolveField( ctx, @@ -8446,6 +9101,43 @@ func (ec *executionContext) unmarshalInputCreateFavoriteInput(ctx context.Contex return it, nil } +func (ec *executionContext) unmarshalInputCreateLayoutInput(ctx context.Context, obj any) (model.CreateLayoutInput, error) { + var it model.CreateLayoutInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"name", "page"} + 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 "page": + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("page")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Page = data + } + } + return it, nil +} + func (ec *executionContext) unmarshalInputCreatePageInput(ctx context.Context, obj any) (model.CreatePageInput, error) { var it model.CreatePageInput if obj == nil { @@ -8780,6 +9472,36 @@ func (ec *executionContext) unmarshalInputUpdateBoxInput(ctx context.Context, ob return it, nil } +func (ec *executionContext) unmarshalInputUpdateLayoutInput(ctx context.Context, obj any) (model.UpdateLayoutInput, error) { + var it model.UpdateLayoutInput + if obj == nil { + return it, nil + } + + asMap := map[string]any{} + for k, v := range obj.(map[string]any) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"name"} + 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 + } + } + return it, nil +} + func (ec *executionContext) unmarshalInputUpdatePageInput(ctx context.Context, obj any) (model.UpdatePageInput, error) { var it model.UpdatePageInput if obj == nil { @@ -9414,6 +10136,140 @@ func (ec *executionContext) _GiteaFeedItem(ctx context.Context, sel ast.Selectio return out } +var layoutImplementors = []string{"Layout"} + +func (ec *executionContext) _Layout(ctx context.Context, sel ast.SelectionSet, obj *models.Layout) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, layoutImplementors) + + 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("Layout") + case "id": + out.Values[i] = ec._Layout_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "createdAt": + out.Values[i] = ec._Layout_createdAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "updatedAt": + out.Values[i] = ec._Layout_updatedAt(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "name": + out.Values[i] = ec._Layout_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "sourcePage": + out.Values[i] = ec._Layout_sourcePage(ctx, field, obj) + if out.Values[i] == graphql.Null { + atomic.AddUint32(&out.Invalids, 1) + } + case "boxCount": + 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._Layout_boxCount(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) }) + case "hasBackground": + 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._Layout_hasBackground(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)) + } + } + 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 messageImplementors = []string{"Message"} func (ec *executionContext) _Message(ctx context.Context, sel ast.SelectionSet, obj *models.Message) graphql.Marshaler { @@ -9614,6 +10470,34 @@ func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) if out.Values[i] == graphql.Null { out.Invalids++ } + case "createLayout": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_createLayout(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "updateLayout": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_updateLayout(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "deleteLayout": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_deleteLayout(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "applyLayout": + out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { + return ec._Mutation_applyLayout(ctx, field) + }) + if out.Values[i] == graphql.Null { + out.Invalids++ + } case "createPage": out.Values[i] = ec.OperationContext.RootResolverMiddleware(innerCtx, func(ctx context.Context) (res graphql.Marshaler) { return ec._Mutation_createPage(ctx, field) @@ -10106,6 +10990,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 "layouts": + 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_layouts(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 "messages": field := field @@ -11505,6 +12411,11 @@ func (ec *executionContext) unmarshalNCreateFavoriteInput2adamᚑfrenchᚗcoᚗu return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) unmarshalNCreateLayoutInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreateLayoutInput(ctx context.Context, v any) (model.CreateLayoutInput, error) { + res, err := ec.unmarshalInputCreateLayoutInput(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) unmarshalNCreatePageInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐCreatePageInput(ctx context.Context, v any) (model.CreatePageInput, error) { res, err := ec.unmarshalInputCreatePageInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -11615,6 +12526,32 @@ func (ec *executionContext) marshalNInt2int(ctx context.Context, sel ast.Selecti return res } +func (ec *executionContext) marshalNLayout2ᚕᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐLayoutᚄ(ctx context.Context, sel ast.SelectionSet, v []*models.Layout) 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.marshalNLayout2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐLayout(ctx, sel, v[i]) + }) + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + + return ret +} + +func (ec *executionContext) marshalNLayout2ᚖadamᚑfrenchᚗcoᚗukᚋbackendᚋmodelsᚐLayout(ctx context.Context, sel ast.SelectionSet, v *models.Layout) 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._Layout(ctx, sel, v) +} + func (ec *executionContext) unmarshalNLoginInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐLoginInput(ctx context.Context, v any) (model.LoginInput, error) { res, err := ec.unmarshalInputLoginInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) @@ -11895,6 +12832,11 @@ func (ec *executionContext) unmarshalNUpdateBoxInput2adamᚑfrenchᚗcoᚗukᚋb 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) +} + func (ec *executionContext) unmarshalNUpdatePageInput2adamᚑfrenchᚗcoᚗukᚋbackendᚋgraphᚋmodelᚐUpdatePageInput(ctx context.Context, v any) (model.UpdatePageInput, error) { res, err := ec.unmarshalInputUpdatePageInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) diff --git a/backend/graph/layout.resolvers.go b/backend/graph/layout.resolvers.go new file mode 100644 index 0000000..15c21bc --- /dev/null +++ b/backend/graph/layout.resolvers.go @@ -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 } diff --git a/backend/graph/layout_helpers.go b/backend/graph/layout_helpers.go new file mode 100644 index 0000000..4ba292b --- /dev/null +++ b/backend/graph/layout_helpers.go @@ -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 +} diff --git a/backend/graph/model/models_gen.go b/backend/graph/model/models_gen.go index 593638b..a321f8f 100644 --- a/backend/graph/model/models_gen.go +++ b/backend/graph/model/models_gen.go @@ -52,6 +52,11 @@ type CreateFavoriteInput struct { Link *string `json:"link,omitempty"` } +type CreateLayoutInput struct { + Name string `json:"name"` + Page string `json:"page"` +} + type CreatePageInput struct { Slug string `json:"slug"` Title string `json:"title"` @@ -155,6 +160,10 @@ type UpdateBoxInput struct { AdminOnly *bool `json:"adminOnly,omitempty"` } +type UpdateLayoutInput struct { + Name *string `json:"name,omitempty"` +} + type UpdatePageInput struct { Slug *string `json:"slug,omitempty"` Title *string `json:"title,omitempty"` diff --git a/backend/graph/page_helpers.go b/backend/graph/page_helpers.go index 3e32206..bf3f992 100644 --- a/backend/graph/page_helpers.go +++ b/backend/graph/page_helpers.go @@ -24,11 +24,11 @@ const maxSlugLen = 100 // 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/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 -// share. "shrines" is deliberately absent: /shrines and the shrine pages under -// it are all canvas pages. +// landing page's key "index", whose boxes a page of the same slug would +// share. "shrines" and "stp" are deliberately absent: /shrines, the shrine +// pages under it and the home page /stp are all canvas pages. 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, "gitea": true, "notes": true, "sb": true, "jobs": true, "tracker": 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 -// 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. func pageHiddenFrom(ctx context.Context, db *gorm.DB, key string) (bool, error) { if IsAdminFromCtx(ctx) { diff --git a/backend/graph/page_helpers_test.go b/backend/graph/page_helpers_test.go index 392711d..7e76eaf 100644 --- a/backend/graph/page_helpers_test.go +++ b/backend/graph/page_helpers_test.go @@ -21,8 +21,9 @@ func TestValidateSlug(t *testing.T) { {"shrines/demoman", true}, // no longer an SPA route {"admin/pages", false}, // under an SPA route {"jobs/x", false}, // under an nginx route - {"stp", false}, // a built-in canvas's key - {"index", false}, // likewise + {"stp", true}, // the home page is a canvas page too + {"stp2", false}, // an SPA route + {"index", false}, // the landing canvas's key {"stp-fan-page", true}, // only whole segments are reserved } { err := validateSlug(c.slug) diff --git a/backend/graph/schema/background.graphql b/backend/graph/schema/background.graphql index 47c81a4..7b6e20d 100644 --- a/backend/graph/schema/background.graphql +++ b/backend/graph/schema/background.graphql @@ -1,6 +1,6 @@ # 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 -# landing page and every shrine are set the same way. Edited from the +# boxes ("index" for the landing page, or a Page's slug), so the landing +# page and every other canvas page are set the same way. Edited from the # canvas's "Background" button; see models.Background. # # Anyone may read it, as part of the page, except that an adminOnly page's diff --git a/backend/graph/schema/box.graphql b/backend/graph/schema/box.graphql index ce8a569..c1b8021 100644 --- a/backend/graph/schema/box.graphql +++ b/backend/graph/schema/box.graphql @@ -1,5 +1,5 @@ -# Boxes on a canvas page: the home page (/stp, page "stp"), the landing -# page's overlay (page "index") or an admin-created Page (page = its slug). +# Boxes on a canvas page: the landing page (page "index") or an +# 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 # 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. diff --git a/backend/graph/schema/layout.graphql b/backend/graph/schema/layout.graphql new file mode 100644 index 0000000..cb14166 --- /dev/null +++ b/backend/graph/schema/layout.graphql @@ -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 + # " before ,