Compare commits
No commits in common. "9e6b185cfda340cd3e56347fceef7f359939adc4" and "07a62fec25dff8cc62419e760fc480d6a6fda904" have entirely different histories.
9e6b185cfd
...
07a62fec25
|
@ -1,6 +1,6 @@
|
|||
defmodule Frenzy.UpdateFeeds do
|
||||
use GenServer
|
||||
alias Frenzy.{Repo, Feed, Item}
|
||||
alias Frenzy.{Repo, Feed, Item, FilterEngine}
|
||||
import Ecto.Query
|
||||
require Logger
|
||||
|
||||
|
@ -70,10 +70,10 @@ defmodule Frenzy.UpdateFeeds do
|
|||
status_code: 200,
|
||||
body: body,
|
||||
headers: headers
|
||||
}} ->
|
||||
}} = response ->
|
||||
{_, content_type} =
|
||||
headers
|
||||
|> Enum.find(fn {k, _v} -> k == "Content-Type" end)
|
||||
|> Enum.find(fn {k, v} -> k == "Content-Type" end)
|
||||
|
||||
content_type =
|
||||
content_type
|
||||
|
@ -183,7 +183,7 @@ defmodule Frenzy.UpdateFeeds do
|
|||
:tombstone ->
|
||||
changeset =
|
||||
Ecto.build_assoc(feed, :items, %{
|
||||
guid: item_params.guid,
|
||||
guid: entry.id,
|
||||
tombstone: true
|
||||
})
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ defmodule FrenzyWeb.FeedController do
|
|||
feed_url: feed_url
|
||||
})
|
||||
|
||||
{:ok, _feed} = Repo.insert(changeset)
|
||||
{:ok, feed} = Repo.insert(changeset)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Feed created")
|
||||
|
@ -67,7 +67,7 @@ defmodule FrenzyWeb.FeedController do
|
|||
end
|
||||
|
||||
def edit(conn, _params) do
|
||||
feed = conn.assigns[:feed]
|
||||
feed = conn.assigns[:feed] |> Repo.preload([:pipeline_stages])
|
||||
stages = Enum.sort_by(feed.pipeline_stages, fn stage -> stage.index end)
|
||||
|
||||
render(conn, "edit.html", %{
|
||||
|
@ -77,7 +77,7 @@ defmodule FrenzyWeb.FeedController do
|
|||
end
|
||||
|
||||
def update(conn, %{"feed" => feed_params}) do
|
||||
feed = conn.assigns[:feed]
|
||||
feed = conn.assigns[:feed] |> Repo.preload(:filter)
|
||||
changeset = Feed.changeset(feed, feed_params)
|
||||
{:ok, feed} = Repo.update(changeset)
|
||||
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
||||
|
@ -90,21 +90,21 @@ defmodule FrenzyWeb.FeedController do
|
|||
end
|
||||
|
||||
def enable_filter(conn, _params) do
|
||||
feed = conn.assigns[:feed]
|
||||
feed = conn.assigns[:feed] |> Repo.preload(:filter)
|
||||
changeset = Feed.changeset(feed, %{filter_enabled: true})
|
||||
Repo.update(changeset)
|
||||
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
||||
end
|
||||
|
||||
def disable_filter(conn, _params) do
|
||||
feed = conn.assigns[:feed]
|
||||
feed = conn.assigns[:feed] |> Repo.preload(:filter)
|
||||
changeset = Feed.changeset(feed, %{filter_enabled: false})
|
||||
Repo.update(changeset)
|
||||
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
||||
end
|
||||
|
||||
def refresh(conn, _params) do
|
||||
feed = conn.assigns[:feed]
|
||||
feed = conn.assigns[:feed] |> Repo.preload(:filter)
|
||||
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
|
||||
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
|
||||
end
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
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,6 +60,10 @@ defmodule FrenzyWeb.Router do
|
|||
get "/feeds/:feed_id/pipelines/new", PipelineController, :new
|
||||
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]
|
||||
post "/items/:id/read", ItemController, :read
|
||||
post "/items/:id/unread", ItemController, :unread
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
<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 %>
|
|
@ -0,0 +1,3 @@
|
|||
defmodule FrenzyWeb.FilterView do
|
||||
use FrenzyWeb, :view
|
||||
end
|
Loading…
Reference in New Issue