Compare commits

...

2 Commits

7 changed files with 10 additions and 134 deletions

View File

@ -1,6 +1,6 @@
defmodule Frenzy.UpdateFeeds do
use GenServer
alias Frenzy.{Repo, Feed, Item, FilterEngine}
alias Frenzy.{Repo, Feed, Item}
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: entry.id,
guid: item_params.guid,
tombstone: true
})

View File

@ -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] |> Repo.preload([:pipeline_stages])
feed = conn.assigns[:feed]
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] |> Repo.preload(:filter)
feed = conn.assigns[:feed]
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] |> Repo.preload(:filter)
feed = conn.assigns[:feed]
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] |> Repo.preload(:filter)
feed = conn.assigns[:feed]
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] |> Repo.preload(:filter)
feed = conn.assigns[:feed]
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
redirect(conn, to: Routes.feed_path(Endpoint, :show, feed.id))
end

View File

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

View File

@ -60,10 +60,6 @@ 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

View File

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

View File

@ -1,3 +0,0 @@
defmodule FrenzyWeb.FilterView do
use FrenzyWeb, :view
end