Add rule deletion
This commit is contained in:
parent
eefa65ed56
commit
dbbae6a1a6
|
@ -7,6 +7,7 @@ defmodule Frenzy.Rule do
|
||||||
field :property, :string
|
field :property, :string
|
||||||
field :param, :string
|
field :param, :string
|
||||||
field :weight, :integer
|
field :weight, :integer
|
||||||
|
field :delete, :boolean, virtual: true
|
||||||
|
|
||||||
belongs_to :filter, Frenzy.Filter
|
belongs_to :filter, Frenzy.Filter
|
||||||
|
|
||||||
|
@ -16,7 +17,16 @@ defmodule Frenzy.Rule do
|
||||||
@doc false
|
@doc false
|
||||||
def changeset(rule, attrs) do
|
def changeset(rule, attrs) do
|
||||||
rule
|
rule
|
||||||
|> cast(attrs, [:mode, :property, :param, :weight])
|
|> cast(attrs, [:mode, :property, :param, :weight, :delete])
|
||||||
|
|> set_delete_action()
|
||||||
|> validate_required([:mode, :property, :param, :weight])
|
|> validate_required([:mode, :property, :param, :weight])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_delete_action(changeset) do
|
||||||
|
if get_change(changeset, :delete) do
|
||||||
|
%{changeset | action: :delete}
|
||||||
|
else
|
||||||
|
changeset
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
<th>Mode</th>
|
<th>Mode</th>
|
||||||
<th>Param</th>
|
<th>Param</th>
|
||||||
<th>Weight</th>
|
<th>Weight</th>
|
||||||
|
<th>Delete?</th>
|
||||||
</tr>
|
</tr>
|
||||||
<%= inputs_for form, :rules, fn p -> %>
|
<%= inputs_for form, :rules, fn p -> %>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -30,6 +31,9 @@
|
||||||
<td>
|
<td>
|
||||||
<%= number_input p, :weight %>
|
<%= number_input p, :weight %>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<%= checkbox p, :delete %>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in New Issue