- menus controller gains the app accessor and FormAfterCreate/Update/Delete purging kind menu with the menu code - menu entries purge kind menu_entry with the entry id after the placement checks pass, on delete, and through pact.ReorderAfterSave with partition:<menu id> - purgeSiteCache helper on cabana.TxFromContext and cooler.SiteCacheFromApp - TestMenuAdminPurgesSiteCache on Postgres
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.golem15.com/golem15/sm-menu-plugin/models"
|
|
"git.golem15.com/golem15/summercms/modules/backpack"
|
|
"git.golem15.com/golem15/summercms/modules/pact"
|
|
)
|
|
|
|
// MenusControllerID is the cabana controller id of the Menus screen.
|
|
const MenusControllerID = "golem15.menu.menus"
|
|
|
|
// menusAdminController lists and edits menus: name, code, CSS class and the
|
|
// active switch.
|
|
type menusAdminController struct {
|
|
app func() *backpack.App
|
|
}
|
|
|
|
func (menusAdminController) ID() string { return MenusControllerID }
|
|
|
|
func (menusAdminController) ModelName() string { return `Golem15\Menu\Models\Menu` }
|
|
|
|
func (menusAdminController) ConfigDir() string { return "controllers/menus" }
|
|
|
|
func (menusAdminController) RequiredPermissions() []string {
|
|
return []string{PermissionManageMenu}
|
|
}
|
|
|
|
func (menusAdminController) NewRecord() any { return &models.Menu{} }
|
|
|
|
// Site-cache purge kinds of the menu plugin's saves.
|
|
const (
|
|
siteCacheKindMenu = "menu"
|
|
siteCacheKindEntry = "menu_entry"
|
|
)
|
|
|
|
// FormAfterCreate purges the host site's page caches once the save commits.
|
|
func (c menusAdminController) FormAfterCreate(ctx context.Context, model any) error {
|
|
c.purge(ctx, model)
|
|
return nil
|
|
}
|
|
|
|
// FormAfterUpdate purges the host site's page caches once the save commits.
|
|
func (c menusAdminController) FormAfterUpdate(ctx context.Context, model any) error {
|
|
c.purge(ctx, model)
|
|
return nil
|
|
}
|
|
|
|
// FormAfterDelete purges the host site's page caches once the delete
|
|
// commits.
|
|
func (c menusAdminController) FormAfterDelete(ctx context.Context, model any) error {
|
|
c.purge(ctx, model)
|
|
return nil
|
|
}
|
|
|
|
// purge registers a purge of kind menu with the menu's code.
|
|
func (c menusAdminController) purge(ctx context.Context, model any) {
|
|
if menu, ok := model.(*models.Menu); ok && menu != nil {
|
|
purgeSiteCache(ctx, c.app, siteCacheKindMenu, menu.Code)
|
|
}
|
|
}
|
|
|
|
var (
|
|
_ pact.AdminController = menusAdminController{}
|
|
_ pact.AdminPermissioned = menusAdminController{}
|
|
_ pact.AdminRecordSource = menusAdminController{}
|
|
_ pact.FormAfterCreate = menusAdminController{}
|
|
_ pact.FormAfterUpdate = menusAdminController{}
|
|
_ pact.FormAfterDelete = menusAdminController{}
|
|
)
|