frenzy/lib/frenzy_web/templates/filter/edit.html.eex

75 lines
2.7 KiB
Elixir

<h2>Filter</h2>
<%= form_for @changeset, Routes.filter_path(@conn, :update, @changeset.data.id), fn form -> %>
<div class="form-group row">
<label for="mode" class="col-sm-2 col-form-label">Mode</label>
<div class="col-sm-10">
<%= select form, :mode, [{"Accept", :accept}, {"Reject", :reject}], class: "form-control" %>
</div>
</div>
<div class="form-group row">
<label for="score" class="col-sm-2 col-form-label">Score</label>
<div class="col-sm-10">
<%= number_input form, :score, class: "form-control" %>
</div>
</div>
<div class="card mt-5 mb-5">
<div class="card-body">
<h3>Rules</h3>
<table class="table">
<thead>
<tr>
<th>Property</th>
<th>Mode</th>
<th>Param</th>
<th>Weight</th>
<th></th>
</tr>
</thead>
<tbody>
<%= inputs_for form, :rules, fn p -> %>
<tr>
<td>
<%= select p, :property, [{"URL", :url}, {"Title", :title}, {"Author", :author}, {"Content", :content}], class: "form-control" %>
</td>
<td>
<%= select p, :mode, [{"contains", :contains_string}, {"matches regex", :matches_regex}], class: "form-control" %>
</td>
<td>
<%= text_input p, :param, class: "form-control" %>
</td>
<td>
<%= number_input p, :weight, class: "form-control" %>
</td>
<td>
<%# when nesting form tags, the first nested one seems to get removed %>
<%# not the first nested one in each row, but the first nested one overall %>
<%# so we include a dummy form with display: none that gets stripped from the first row %>
<%# but is present and invisible in subsequent rows %>
<form style="display: none;"></form>
<%= form_tag Routes.filter_path(@conn, :remove_rule, @changeset.data.id, [rule_id: p.data.id]), method: :post do %>
<%= submit "Delete", class: "btn btn-danger" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="form-group row">
<div class="col-sm-10">
<%= form_tag Routes.filter_path(@conn, :add_rule, @changeset.data.id), method: :post do %>
<%= submit "Add Rule", class: "btn btn-secondary" %>
<% end %>
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-sm-10">
<%= submit "Update Filter", class: "btn btn-primary" %>
</div>
</div>
<% end %>