feat(17-01): tree reorder page and singleton admin controllers
- cabana: config_reorder.yaml (title, nameFrom, modelClass, parentColumn,
sortColumn, maxDepth, partition) with fail-loud boot checks and the
built-in reorder toolbar button; list schema carries reorder
- GET/POST {controller}/reorder: scoped set (ListExtendQuery plus the
partition) locked FOR UPDATE, 409 reorder_stale on any set difference,
422 for duplicates, foreign parents, cycles and maxDepth, both columns
written without model hooks
- pact.AdminSingleton: GET {controller}/singleton (first or create, form
scope checked), form schema singleton, list/create/bulk/delete 404,
no config_list.yaml needed
- swag, inventories, token classes, CSRF walk, conformance cases, backend
lang reorder.stale and load_failed, reorder and singleton smoke tests, docs
This commit is contained in:
@@ -2,6 +2,8 @@ package cabana
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -79,14 +81,32 @@ func compileRegistryWithTypes(items []controllerRef, types *fieldTypeRegistry) (
|
||||
if !ok || fsys == nil || fsys.AdminFS() == nil {
|
||||
return nil, fmt.Errorf("cabana: plugin %s has admin controllers but no AdminFS", item.plugin.ID())
|
||||
}
|
||||
list, err := compileListWithTypes(item.plugin.ID(), item.ctl, fsys.AdminFS(), types)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// A singleton controller (pact.AdminSingleton, D-11) edits one
|
||||
// record and needs no config_list.yaml.
|
||||
_, singleton := item.ctl.(pact.AdminSingleton)
|
||||
var (
|
||||
list *ListSchema
|
||||
err error
|
||||
)
|
||||
if !singleton || hasListConfig(item.ctl, fsys.AdminFS()) {
|
||||
list, err = compileListWithTypes(item.plugin.ID(), item.ctl, fsys.AdminFS(), types)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
form, err := compileFormIfPresent(item.plugin.ID(), item.ctl, fsys.AdminFS(), types)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if singleton {
|
||||
if form == nil {
|
||||
return nil, fmt.Errorf("cabana: admin controller %s/%s: a singleton controller (pact.AdminSingleton) needs config_form.yaml", item.plugin.ID(), id)
|
||||
}
|
||||
form.singleton = true
|
||||
if list != nil {
|
||||
list.ToolbarButtons = withoutAction(withoutAction(list.ToolbarButtons, "create"), "delete")
|
||||
}
|
||||
}
|
||||
relations, err := compileRelationsWithTypes(item.plugin.ID(), item.ctl, fsys.AdminFS(), form, types)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -106,6 +126,7 @@ func compileRegistryWithTypes(items []controllerRef, types *fieldTypeRegistry) (
|
||||
Form: form,
|
||||
Relations: relations,
|
||||
FieldRelations: fieldRelations,
|
||||
singleton: singleton,
|
||||
}
|
||||
if err := BindWritableFields(compiled); err != nil {
|
||||
return nil, err
|
||||
@@ -122,6 +143,9 @@ func compileRegistryWithTypes(items []controllerRef, types *fieldTypeRegistry) (
|
||||
if err := compileExtension(item.plugin.ID(), compiled, fsys.AdminFS()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := compileReorder(item.plugin.ID(), compiled, fsys.AdminFS()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Two controllers of one plugin declaring the same file share an entry.
|
||||
for _, file := range append(append([]*pluginAsset(nil), compiled.scripts...), compiled.styles...) {
|
||||
if _, exists := assets[file.key]; !exists {
|
||||
@@ -147,6 +171,14 @@ func (cc *CompiledController) operationDeclared(op string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// hasListConfig reports whether the controller's config directory holds a
|
||||
// config_list.yaml.
|
||||
func hasListConfig(ctl pact.AdminController, fsys fs.FS) bool {
|
||||
dir := strings.Trim(path.Clean(ctl.ConfigDir()), "/")
|
||||
_, err := fs.Stat(fsys, path.Join(dir, "config_list.yaml"))
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func hasToolbarButton(list *ListSchema, name string) bool {
|
||||
for _, button := range list.ToolbarButtons {
|
||||
if button == name {
|
||||
|
||||
Reference in New Issue
Block a user