registration

Registering resources

A resource is declared by hand with register. Everything the admin shows for a model is stated explicitly. Nothing is inferred at request time.

use MVC::Keayl::Admin;
use MVC::Keayl::Admin::DSL;

MVC::Keayl::Admin.register(Post, {
  menu(:group<Content>, :label<Posts>, :priority(10), :icon<file-text>);

  scope('All', :default);
  scope('Published', { .where(:published(True)) });

  column('title', :sortable);
  column('author', :display({ .author.name }));
  column('published-at', :format<date>);

  filter('title',      :as<string>,  :predicate<cont>);
  filter('published',  :as<boolean>);
  filter('author-id',  :as<select>, :collection({ Author.all.map({ .id => .name }) }));

  attribute('title');
  attribute('body');
  attribute('author');

  field('title',     :as<string>);
  field('body',      :as<text>);
  field('author-id', :as<select>, :collection({ Author.all }));
  field('published', :as<boolean>);

  permit(<title body author-id published>);
});

The declaration vocabulary comes from MVC::Keayl::Admin::DSL. Each call records a declaration on the resource config:

DeclarationRecordsDetail
indexthe index presentation (:as table/grid/blog, a per-record block)Index presentations and panels
belongs-tonests the resource under a parent associationNested resources
includesassociations to eager-load on the indexNested resources
csvexplicit export columns, overriding the index columnsCustomization
actionswhich default actions the resource exposes (:except)Action availability and toolbar
sort-orderthe default ordering (:dir)Action availability and toolbar
action-itema page-toolbar button (:only, :except, :if-can)Action availability and toolbar
columnan index column (:sortable, :display, :format)Index pages
attributea show-page row (:display, :format)Show pages
fielda form input (:as, :label, :collection, :hint, :placeholder, :multiple)Forms
filtera search control (:as, :predicate, :collection)Filters
scopea named scope, one markable :defaultScopes
permitthe strong-params allowlistForms
nesteda nested association form (:multiple)Forms
batch-actiona bulk operation over selected recordsActions
member-actiona per-record action (:confirm)Actions
collection-actiona whole-collection action (:confirm)Actions
sidebara right-column content panel (:on, :priority, :if-can)Index presentations and panels
panela show-page main-column panel (:priority, :if-can)Index presentations and panels
taba show-page tabbed panel (:priority, :if-can)Index presentations and panels
menuthe sidebar entry (:group, :label, :priority, :icon, :hide)Navigation
iconthe resource's Bootstrap icon, shown in the sidebar and page headingsNavigation

Resource options

register takes a block of declarations plus named options that tune the resource as a whole:

OptionDefaultPurpose
slugdasherized pluralThe URL segment for the resource.
singularhumanized model nameThe singular human name.
pluralpluralized singularThe plural human name.
per-page25Index page size (Index pages).
scope-countsTrueWhether scope tabs show counts (Scopes).
filtersTrueWhether the filter UI renders (Action availability).
batch-actionsTrueWhether batch selection renders (Action availability).
exportall formatsExport formats offered, or False to disable (Customization).
MVC::Keayl::Admin.register(Post, { ... },
  slug         => 'articles',
  singular     => 'Article',
  plural       => 'Articles',
  per-page     => 50,
  scope-counts => False,
);

Validation

Declarations are validated when register runs. An unknown option, an unknown field/filter type, or a malformed declaration raises at registration time rather than failing later on a request.

Names and slug

Each resource derives a URL slug, a singular human name, and a plural human name from the model. The slug is the dasherized plural (BlogPost becomes blog-posts). The human names resolve through I18n, falling back to a humanized form of the model name, and translation keys localize them (see Customization). Override any of them with the slug, singular, and plural options above.

The registry indexes resources by model and by slug, with by-model, by-slug, and an all listing in registration order.

Routes and URL helpers

Registering a resource generates the seven routes (index, show, new, create, edit, update, destroy) under the engine. path-for builds the mount-prefixed URL for any resource action, usable from controllers and views:

MVC::Keayl::Admin.path-for('posts');           # /admin/posts
MVC::Keayl::Admin.path-for('post', 5);         # /admin/posts/5
MVC::Keayl::Admin.path-for('edit-post', 5);    # /admin/posts/5/edit
MVC::Keayl::Admin.path-for('new-post');        # /admin/posts/new

MVC::Keayl::Admin v0.9.0

Generated administration interface for MVC::Keayl applications

Authors

  • Greg Donald

License

Artistic-2.0

Dependencies

MVC::Keayl:auth<zef:gdonald>ORM::ActiveRecord:auth<zef:gdonald>Template::HAML:auth<zef:gdonald>

Provides

  • MVC::Keayl::Admin
  • MVC::Keayl::Admin::ActionItem
  • MVC::Keayl::Admin::Assets
  • MVC::Keayl::Admin::AssetsController
  • MVC::Keayl::Admin::Attachments
  • MVC::Keayl::Admin::Attribute
  • MVC::Keayl::Admin::Authentication
  • MVC::Keayl::Admin::Authentication::Basic
  • MVC::Keayl::Admin::Authentication::Session
  • MVC::Keayl::Admin::Authorization
  • MVC::Keayl::Admin::Authorization::Abilities
  • MVC::Keayl::Admin::Authorization::Policy
  • MVC::Keayl::Admin::Authorization::Role
  • MVC::Keayl::Admin::BatchAction
  • MVC::Keayl::Admin::Chrome
  • MVC::Keayl::Admin::Column
  • MVC::Keayl::Admin::Config
  • MVC::Keayl::Admin::Controller
  • MVC::Keayl::Admin::CustomAction
  • MVC::Keayl::Admin::DSL
  • MVC::Keayl::Admin::Dashboard
  • MVC::Keayl::Admin::DashboardController
  • MVC::Keayl::Admin::Engine
  • MVC::Keayl::Admin::ExportSpec
  • MVC::Keayl::Admin::Field
  • MVC::Keayl::Admin::Filter
  • MVC::Keayl::Admin::FilterPanel
  • MVC::Keayl::Admin::Form
  • MVC::Keayl::Admin::Formatter
  • MVC::Keayl::Admin::Generators
  • MVC::Keayl::Admin::I18n
  • MVC::Keayl::Admin::IndexView
  • MVC::Keayl::Admin::Inflection
  • MVC::Keayl::Admin::Menu
  • MVC::Keayl::Admin::MenuEntry
  • MVC::Keayl::Admin::Nested
  • MVC::Keayl::Admin::Page
  • MVC::Keayl::Admin::PageController
  • MVC::Keayl::Admin::Pages
  • MVC::Keayl::Admin::Pagination
  • MVC::Keayl::Admin::Panel
  • MVC::Keayl::Admin::Panels
  • MVC::Keayl::Admin::Paths
  • MVC::Keayl::Admin::Predicate
  • MVC::Keayl::Admin::Registry
  • MVC::Keayl::Admin::Resource
  • MVC::Keayl::Admin::ResourceController
  • MVC::Keayl::Admin::Scope
  • MVC::Keayl::Admin::Scopes
  • MVC::Keayl::Admin::Show
  • MVC::Keayl::Admin::Table
  • MVC::Keayl::Admin::TestSupport
  • MVC::Keayl::Admin::Url
  • MVC::Keayl::Admin::View

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.