defmodule Kaffy.ResourceAdmin do alias Kaffy.ResourceSchema alias Kaffy.Utils @moduledoc """ ResourceAdmin modules should be created for every schema you want to customize/configure in Kaffy. If you have a schema like `MyApp.Products.Product`, you should create an admin module with name `MyApp.Products.ProductAdmin` and add functions documented in this module to customize the behavior. All functions are optional. """ @doc """ `index/1` takes the schema module and should return a keyword list of fields and their options. Supported options are `:name` and `:value`. Both options can be a string or an anonymous function. If a fuction is provided, the current entry is passed to it. If index/1 is not defined, Kaffy will return all the fields of the schema and their default values. Example: ```elixir def index(_schema) do [ id: %{name: "ID", value: fn post -> post.id + 100 end}, title: nil, # this will render the default name for this field (Title) and its default value (post.title) views: %{name: "Hits", value: fn post -> post.views + 10 end}, published: %{name: "Published?", value: fn post -> published?(post) end}, comment_count: %{name: "Comments", value: fn post -> comment_count(post) end} ] end ``` """ def index(resource) do schema = resource[:schema] Utils.get_assigned_value_or_default(resource, :index, ResourceSchema.index_fields(schema)) end @doc """ form_fields/1 takes a schema and returns a keyword list of fields and their options for the new/edit form. Supported options are: `:label`, `:type`, `:choices`, and `:permission` `:type` can be any ecto type in addition to `:file` and `:textarea` If `:choices` is provided, it must be a keyword list and the field will be rendered as a `