Add rule deletion

This commit is contained in:
Shadowfacts 2019-03-14 22:15:09 -04:00
parent eefa65ed56
commit dbbae6a1a6
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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>