feat(build): scaffold working admin controllers with model, AdminFS and delete (quick-261028-pq8)
- make:admin-controller edits the singular of its name (--model overrides):
ModelName, modelClass and the YAML under models/<model>/
- NewRecord returns &models.<Model>{} when the model exists; otherwise the
nil body stays and the command says to run make:model
- config_list.yaml offers create and delete with showCheckboxes
- registry.gen.go embeds controllers/*/*.yaml and models/*/*.yaml once they
exist and exposes generatedAdminFS(); scaffolded plugins implement
pact.AdminAssets through it, and a plugin without AdminFS gets a note
- blog example moves its YAML to models/post; docs and help text follow
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
name: acme.blog::lang.posts.post
|
||||
form: ~/plugins/acme/blog/models/posts/fields.yaml
|
||||
form: ~/plugins/acme/blog/models/post/fields.yaml
|
||||
modelClass: Post
|
||||
defaultRedirect: acme/blog/posts
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
list: ~/plugins/acme/blog/models/posts/columns.yaml
|
||||
list: ~/plugins/acme/blog/models/post/columns.yaml
|
||||
modelClass: Post
|
||||
title: acme.blog::lang.posts.title
|
||||
recordUrl: acme/blog/posts/update/:id
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestPostsControllerDeclaration(t *testing.T) {
|
||||
if list.ModelClass != "Post" || list.DefaultSort == nil {
|
||||
t.Errorf("list = %+v, want modelClass Post with a default sort", list)
|
||||
}
|
||||
for _, name := range []string{"controllers/posts/config_form.yaml", "controllers/posts/config_list.yaml", "models/posts/fields.yaml", "models/posts/columns.yaml"} {
|
||||
for _, name := range []string{"controllers/posts/config_form.yaml", "controllers/posts/config_list.yaml", "models/post/fields.yaml", "models/post/columns.yaml"} {
|
||||
if _, err := fs.Stat(fsys, name); err != nil {
|
||||
t.Errorf("AdminFS is missing %s: %v", name, err)
|
||||
}
|
||||
|
||||
@@ -38,9 +38,6 @@ var langFS embed.FS
|
||||
//go:embed views/mail
|
||||
var mailFS embed.FS
|
||||
|
||||
//go:embed controllers/*/*.yaml models/*/*.yaml
|
||||
var adminFS embed.FS
|
||||
|
||||
// Plugin is the acme.blog plugin, the Go form of Plugin.php.
|
||||
type Plugin struct {
|
||||
app *backpack.App
|
||||
@@ -79,9 +76,9 @@ func (p *Plugin) Commands() []bonfire.Command {
|
||||
return append(generatedCommands(p.app), console.PublishCommand(p.withDB))
|
||||
}
|
||||
|
||||
// AdminFS is the admin YAML the controllers read: controllers/posts and
|
||||
// models/posts.
|
||||
func (p *Plugin) AdminFS() fs.FS { return adminFS }
|
||||
// AdminFS is the admin YAML the controllers read, controllers/posts and
|
||||
// models/post, which registry.gen.go embeds.
|
||||
func (p *Plugin) AdminFS() fs.FS { return generatedAdminFS() }
|
||||
|
||||
// Permissions replaces registerPermissions().
|
||||
func (p *Plugin) Permissions() []pact.Permission {
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
package blog
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io/fs"
|
||||
|
||||
"git.golem15.com/golem15/summercms/docs/examples/blog/controllers"
|
||||
"git.golem15.com/golem15/summercms/docs/examples/blog/models"
|
||||
"git.golem15.com/golem15/summercms/docs/examples/blog/updates"
|
||||
@@ -40,3 +43,16 @@ func generatedAdminControllers() []pact.AdminController {
|
||||
controllers.PostsController(),
|
||||
}
|
||||
}
|
||||
|
||||
// generatedAdminTree holds the admin YAML of the plugin: the controller
|
||||
// configuration and the model fields and columns. Go evaluates the go:embed
|
||||
// globs at compile time, so YAML files added later in these directories are
|
||||
// included; the next make: command rewrites the line when a glob starts or
|
||||
// stops matching a file.
|
||||
//
|
||||
//go:embed controllers/*/*.yaml models/*/*.yaml
|
||||
var generatedAdminTree embed.FS
|
||||
|
||||
// generatedAdminFS returns the admin YAML for pact.AdminAssets: an empty tree
|
||||
// until the first admin controller is scaffolded.
|
||||
func generatedAdminFS() fs.FS { return generatedAdminTree }
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestScaffoldLayout(t *testing.T) {
|
||||
if _, err := build.MakeMigration(ctx, app, "acme.blog", "AddPublishedAt"); err != nil {
|
||||
t.Fatalf("MakeMigration: %v", err)
|
||||
}
|
||||
if _, err := build.MakeAdminController(ctx, app, "acme.blog", "Posts"); err != nil {
|
||||
if _, err := build.MakeAdminController(ctx, app, "acme.blog", "Posts", ""); err != nil {
|
||||
t.Fatalf("MakeAdminController: %v", err)
|
||||
}
|
||||
if _, err := build.MakeCommand(ctx, app, "acme.blog", "Publish"); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user