diff --git a/lib/kaffy/resource_admin.ex b/lib/kaffy/resource_admin.ex
index 2eabad26..95285a6f 100644
--- a/lib/kaffy/resource_admin.ex
+++ b/lib/kaffy/resource_admin.ex
@@ -293,6 +293,16 @@ defmodule Kaffy.ResourceAdmin do
Utils.get_assigned_value_or_default(resource, :list_actions, nil, [conn], false)
end
+ def crud_actions(resource, conn) do
+ Utils.get_assigned_value_or_default(
+ resource,
+ :crud_actions,
+ [:new, :show, :update, :delete],
+ [conn],
+ false
+ )
+ end
+
def widgets(resource, conn) do
Utils.get_assigned_value_or_default(
resource,
diff --git a/lib/kaffy/resource_form.ex b/lib/kaffy/resource_form.ex
index 957dd641..22795afc 100644
--- a/lib/kaffy/resource_form.ex
+++ b/lib/kaffy/resource_form.ex
@@ -50,7 +50,7 @@ defmodule Kaffy.ResourceForm do
end
permission =
- case is_nil(changeset.data.id) do
+ case is_nil(Map.get(changeset.data, :id)) do
true -> Map.get(options, :create, :editable)
false -> Map.get(options, :update, :editable)
end
@@ -93,12 +93,14 @@ defmodule Kaffy.ResourceForm do
inputs_for(form, field, fn fp ->
[
{:safe, ~s(
)},
- Enum.reduce(embed_fields, [], fn f, all ->
+ Enum.reduce(embed_fields, [], fn {embed_f, embed_f_options}, all ->
content_tag :div, class: "form-group" do
[
[
- form_label(fp, f),
- form_field(embed_changeset, fp, {f, options}, class: "form-control")
+ form_label(fp, embed_f),
+ form_field(embed_changeset, fp, {embed_f, embed_f_options},
+ class: "form-control"
+ )
]
| all
]
diff --git a/lib/kaffy/resource_schema.ex b/lib/kaffy/resource_schema.ex
index 57beecea..b226e37e 100644
--- a/lib/kaffy/resource_schema.ex
+++ b/lib/kaffy/resource_schema.ex
@@ -88,7 +88,7 @@ defmodule Kaffy.ResourceSchema do
end
defp reorder_fields(fields_list, schema) do
- [_id, first_field | _fields] = schema.__schema__(:fields)
+ [first_field | _fields] = schema.__schema__(:fields) -- [:id]
# this is a "nice" feature to re-order the default fields to put the specified fields at the top/bottom of the form
fields_list
@@ -299,6 +299,7 @@ defmodule Kaffy.ResourceSchema do
def field_type(_schema, {_, type}), do: type
def field_type(schema, field), do: schema.__changeset__() |> Map.get(field, :string)
+
# def field_type(schema, field), do: schema.__schema__(:type, field)
def get_map_fields(schema) do
diff --git a/lib/kaffy_web/templates/resource/_table.html.eex b/lib/kaffy_web/templates/resource/_table.html.eex
index 2abcc2f8..ccc45981 100644
--- a/lib/kaffy_web/templates/resource/_table.html.eex
+++ b/lib/kaffy_web/templates/resource/_table.html.eex
@@ -13,7 +13,7 @@
<%= for {field, index} <- Enum.with_index(@fields) do %>
- <%= if index == 0 do %>
+ <%= if index == 0 and :update in Kaffy.ResourceAdmin.crud_actions(@my_resource, @conn) do %>
<%= link Kaffy.ResourceSchema.kaffy_field_value(@conn, entry, field), to: Kaffy.Utils.router().kaffy_resource_path(@conn, :show, @context, @resource, entry.id) %> |
<% else %>
<%= Kaffy.ResourceSchema.kaffy_field_value(@conn, entry, field) %> |
diff --git a/lib/kaffy_web/templates/resource/index.html.eex b/lib/kaffy_web/templates/resource/index.html.eex
index 1f11cbcf..4183fa3c 100644
--- a/lib/kaffy_web/templates/resource/index.html.eex
+++ b/lib/kaffy_web/templates/resource/index.html.eex
@@ -9,12 +9,14 @@
+ <%= if :new in Kaffy.ResourceAdmin.crud_actions(@my_resource, @conn) do %>
<%= link to: Kaffy.Utils.router().kaffy_resource_path(@conn, :new, @context, @resource), class: "btn btn-outline-primary" do %>
New <%= Kaffy.ResourceAdmin.singular_name(@my_resource) %>
<% end %>
+ <% end %>