Remove more old code related to filters
This commit is contained in:
parent
07a62fec25
commit
6a30b57ca4
|
@ -48,7 +48,7 @@ defmodule FrenzyWeb.FeedController do
|
||||||
feed_url: feed_url
|
feed_url: feed_url
|
||||||
})
|
})
|
||||||
|
|
||||||
{:ok, feed} = Repo.insert(changeset)
|
{:ok, _feed} = Repo.insert(changeset)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> put_flash(:info, "Feed created")
|
|> put_flash(:info, "Feed created")
|
||||||
|
@ -67,7 +67,7 @@ defmodule FrenzyWeb.FeedController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit(conn, _params) do
|
def edit(conn, _params) do
|
||||||
feed = conn.assigns[:feed] |> Repo.preload([:pipeline_stages])
|
feed = conn.assigns[:feed]
|
||||||
stages = Enum.sort_by(feed.pipeline_stages, fn stage -> stage.index end)
|
stages = Enum.sort_by(feed.pipeline_stages, fn stage -> stage.index end)
|
||||||
|
|
||||||
render(conn, "edit.html", %{
|
render(conn, "edit.html", %{
|
||||||
|
@ -77,7 +77,7 @@ defmodule FrenzyWeb.FeedController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(conn, %{"feed" => feed_params}) do
|
def update(conn, %{"feed" => feed_params}) do
|
||||||
feed = conn.assigns[:feed] |> Repo.preload(:filter)
|
feed = conn.assigns[:feed]
|
||||||
changeset = Feed.changeset(feed, feed_params)
|
changeset = Feed.changeset(feed, feed_params)
|
||||||
{:ok, feed} = Repo.update(changeset)
|
{:ok, feed} = Repo.update(changeset)
|
||||||
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
||||||
|
@ -90,21 +90,21 @@ defmodule FrenzyWeb.FeedController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def enable_filter(conn, _params) do
|
def enable_filter(conn, _params) do
|
||||||
feed = conn.assigns[:feed] |> Repo.preload(:filter)
|
feed = conn.assigns[:feed]
|
||||||
changeset = Feed.changeset(feed, %{filter_enabled: true})
|
changeset = Feed.changeset(feed, %{filter_enabled: true})
|
||||||
Repo.update(changeset)
|
Repo.update(changeset)
|
||||||
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable_filter(conn, _params) do
|
def disable_filter(conn, _params) do
|
||||||
feed = conn.assigns[:feed] |> Repo.preload(:filter)
|
feed = conn.assigns[:feed]
|
||||||
changeset = Feed.changeset(feed, %{filter_enabled: false})
|
changeset = Feed.changeset(feed, %{filter_enabled: false})
|
||||||
Repo.update(changeset)
|
Repo.update(changeset)
|
||||||
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def refresh(conn, _params) do
|
def refresh(conn, _params) do
|
||||||
feed = conn.assigns[:feed] |> Repo.preload(:filter)
|
feed = conn.assigns[:feed]
|
||||||
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
|
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
|
||||||
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
defmodule FrenzyWeb.FilterController do
|
|
||||||
use FrenzyWeb, :controller
|
|
||||||
alias Frenzy.{Repo, Feed, Filter, Rule}
|
|
||||||
alias FrenzyWeb.Router.Helpers, as: Routes
|
|
||||||
alias FrenzyWeb.Endpoint
|
|
||||||
import Ecto.Query
|
|
||||||
|
|
||||||
def edit(conn, %{"id" => id}) do
|
|
||||||
filter = Repo.get(Filter, id) |> Repo.preload(:rules)
|
|
||||||
changeset = Filter.changeset(filter, %{})
|
|
||||||
render(conn, "edit.html", changeset: changeset)
|
|
||||||
end
|
|
||||||
|
|
||||||
def update(conn, %{"id" => id, "filter" => filter_params}) do
|
|
||||||
filter = Repo.get(Filter, id) |> Repo.preload(:rules)
|
|
||||||
changeset = Filter.changeset(filter, filter_params)
|
|
||||||
Repo.update(changeset)
|
|
||||||
redirect(conn, to: Routes.filter_path(Endpoint, :edit, id))
|
|
||||||
end
|
|
||||||
|
|
||||||
def add_rule(conn, %{"id" => id}) do
|
|
||||||
filter = Repo.get(Filter, id)
|
|
||||||
|
|
||||||
changeset =
|
|
||||||
Ecto.build_assoc(filter, :rules, %{
|
|
||||||
property: "title",
|
|
||||||
mode: "contains_string",
|
|
||||||
param: "",
|
|
||||||
weight: 5
|
|
||||||
})
|
|
||||||
|
|
||||||
Repo.insert(changeset)
|
|
||||||
|
|
||||||
redirect(conn, to: Routes.filter_path(Endpoint, :edit, id))
|
|
||||||
end
|
|
||||||
|
|
||||||
def remove_rule(conn, %{"id" => id, "rule_id" => rule_id}) do
|
|
||||||
rule = Repo.get(Rule, rule_id)
|
|
||||||
Repo.delete(rule)
|
|
||||||
redirect(conn, to: Routes.filter_path(Endpoint, :edit, id))
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -60,10 +60,6 @@ defmodule FrenzyWeb.Router do
|
||||||
get "/feeds/:feed_id/pipelines/new", PipelineController, :new
|
get "/feeds/:feed_id/pipelines/new", PipelineController, :new
|
||||||
post "/feeds/:feed_id/pipelines/create", PipelineController, :create
|
post "/feeds/:feed_id/pipelines/create", PipelineController, :create
|
||||||
|
|
||||||
resources "/filters", FilterController, only: [:edit, :update]
|
|
||||||
post "/filters/:id/add_rule", FilterController, :add_rule
|
|
||||||
post "/filters/:id/remove_rule", FilterController, :remove_rule
|
|
||||||
|
|
||||||
resources "/items", ItemController, only: [:show]
|
resources "/items", ItemController, only: [:show]
|
||||||
post "/items/:id/read", ItemController, :read
|
post "/items/:id/read", ItemController, :read
|
||||||
post "/items/:id/unread", ItemController, :unread
|
post "/items/:id/unread", ItemController, :unread
|
||||||
|
|
|
@ -1,75 +0,0 @@
|
||||||
<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 %>
|
|
|
@ -1,3 +0,0 @@
|
||||||
defmodule FrenzyWeb.FilterView do
|
|
||||||
use FrenzyWeb, :view
|
|
||||||
end
|
|
Loading…
Reference in New Issue