Add rule deletion
This commit is contained in:
parent
eefa65ed56
commit
dbbae6a1a6
|
@ -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
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<th>Mode</th>
|
||||
<th>Param</th>
|
||||
<th>Weight</th>
|
||||
<th>Delete?</th>
|
||||
</tr>
|
||||
<%= inputs_for form, :rules, fn p -> %>
|
||||
<tr>
|
||||
|
@ -30,6 +31,9 @@
|
|||
<td>
|
||||
<%= number_input p, :weight %>
|
||||
</td>
|
||||
<td>
|
||||
<%= checkbox p, :delete %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue