diff --git a/lib/frenzy/rule.ex b/lib/frenzy/rule.ex index b303507..d347f85 100644 --- a/lib/frenzy/rule.ex +++ b/lib/frenzy/rule.ex @@ -7,6 +7,7 @@ defmodule Frenzy.Rule do field :property, :string field :param, :string field :weight, :integer + field :delete, :boolean, virtual: true belongs_to :filter, Frenzy.Filter @@ -16,7 +17,16 @@ defmodule Frenzy.Rule do @doc false def changeset(rule, attrs) do rule - |> cast(attrs, [:mode, :property, :param, :weight]) + |> cast(attrs, [:mode, :property, :param, :weight, :delete]) + |> set_delete_action() |> validate_required([:mode, :property, :param, :weight]) end + + def set_delete_action(changeset) do + if get_change(changeset, :delete) do + %{changeset | action: :delete} + else + changeset + end + end end diff --git a/lib/frenzy_web/templates/filter/edit.html.eex b/lib/frenzy_web/templates/filter/edit.html.eex index c2ae383..aa0f269 100644 --- a/lib/frenzy_web/templates/filter/edit.html.eex +++ b/lib/frenzy_web/templates/filter/edit.html.eex @@ -15,6 +15,7 @@