Compare commits
No commits in common. "eb0ebeba9166ad0cef1ed6a4e3eae07b95358d9c" and "72e32305046421c0c1259b3f2a1eb324cbc6ab50" have entirely different histories.
eb0ebeba91
...
72e3230504
|
@ -21,8 +21,6 @@ defmodule Frenzy.Feed do
|
|||
field :title, :string
|
||||
field :filter_enabled, :boolean
|
||||
|
||||
belongs_to :group, Frenzy.Group
|
||||
|
||||
has_many :items, Frenzy.Item, on_delete: :delete_all
|
||||
has_one :filter, Frenzy.Filter, on_delete: :delete_all
|
||||
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
defmodule Frenzy.Group do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "groups" do
|
||||
field :title, :string
|
||||
|
||||
has_many :feeds, Frenzy.Feed, on_delete: :delete_all
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(group, attrs) do
|
||||
group
|
||||
|> cast(attrs, [:title])
|
||||
|> validate_required([:title])
|
||||
end
|
||||
end
|
|
@ -100,9 +100,9 @@ defmodule Frenzy.UpdateFeeds do
|
|||
end
|
||||
|
||||
defp create_item(feed, entry) do
|
||||
url = get_real_url(entry)
|
||||
Logger.debug("Creating item for #{entry.url}")
|
||||
|
||||
Logger.debug("Creating item for #{url}")
|
||||
url = get_real_url(entry)
|
||||
|
||||
content =
|
||||
case get_article_content(url) do
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
defmodule FrenzyWeb.FeedController do
|
||||
use FrenzyWeb, :controller
|
||||
alias Frenzy.{Repo, Group, Feed, Filter, Item}
|
||||
alias Frenzy.{Repo, Feed, Filter, Item}
|
||||
alias FrenzyWeb.Router.Helpers, as: Routes
|
||||
alias FrenzyWeb.Endpoint
|
||||
import Ecto.Query
|
||||
|
||||
def index(conn, _params) do
|
||||
render(conn, "index.html", feeds: Repo.all(Feed))
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
feed = Repo.get(Feed, id) |> Repo.preload(:filter)
|
||||
items = Repo.all(from Item, where: [feed_id: ^id, tombstone: false], order_by: [desc: :date])
|
||||
|
@ -15,27 +19,36 @@ defmodule FrenzyWeb.FeedController do
|
|||
})
|
||||
end
|
||||
|
||||
def create(conn, %{"feed" => %{"group_id" => group_id, "feed_url" => feed_url}}) do
|
||||
group = Repo.get(Group, group_id)
|
||||
def new(conn, _params) do
|
||||
changeset = Feed.changeset(%Feed{}, %{})
|
||||
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
|
||||
def create(conn, %{"feed" => %{"feed_url" => feed_url}}) do
|
||||
changeset =
|
||||
Ecto.build_assoc(group, :feeds, %{
|
||||
Feed.changeset(
|
||||
%Feed{
|
||||
feed_url: feed_url,
|
||||
filter: %Filter{
|
||||
mode: "reject",
|
||||
score: 0
|
||||
}
|
||||
})
|
||||
},
|
||||
%{}
|
||||
)
|
||||
|
||||
{:ok, feed} = Repo.insert(changeset)
|
||||
|
||||
redirect(conn, to: Routes.group_path(Endpoint, :show, group_id))
|
||||
end
|
||||
# changeset =
|
||||
# Ecto.build_assoc(feed, :filter, %{
|
||||
# mode: "reject",
|
||||
# score: 0
|
||||
# })
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
feed = Repo.get(Feed, id)
|
||||
{:ok, _} = Repo.delete(feed)
|
||||
redirect(conn, to: Routes.group_path(Endpoint, :show, feed.group_id))
|
||||
# {:ok, _} = Repo.insert(changeset)
|
||||
|
||||
redirect(conn, to: Routes.feed_path(Endpoint, :index))
|
||||
end
|
||||
|
||||
def enable_filter(conn, %{"id" => id}) do
|
||||
|
@ -52,6 +65,12 @@ defmodule FrenzyWeb.FeedController do
|
|||
redirect(conn, to: Routes.feed_path(Endpoint, :show, id))
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
feed = Repo.get(Feed, id)
|
||||
{:ok, _} = Repo.delete(feed)
|
||||
redirect(conn, to: Routes.feed_path(Endpoint, :index))
|
||||
end
|
||||
|
||||
def refresh(conn, %{"id" => id}) do
|
||||
feed = Repo.get(Feed, id) |> Repo.preload(:filter)
|
||||
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
defmodule FrenzyWeb.GroupController do
|
||||
use FrenzyWeb, :controller
|
||||
alias Frenzy.{Repo, Group, Feed}
|
||||
alias FrenzyWeb.Router.Helpers, as: Routes
|
||||
alias FrenzyWeb.Endpoint
|
||||
import Ecto.Query
|
||||
|
||||
def index(conn, _params) do
|
||||
groups = Repo.all(from group in Group, preload: [:feeds])
|
||||
render(conn, "index.html", groups: groups)
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
group = Repo.get(Group, id) |> Repo.preload(:feeds)
|
||||
|
||||
create_feed_changeset =
|
||||
Feed.changeset(
|
||||
%Feed{
|
||||
group_id: id
|
||||
},
|
||||
%{}
|
||||
)
|
||||
|
||||
render(conn, "show.html", %{
|
||||
group: group,
|
||||
create_feed_changeset: create_feed_changeset
|
||||
})
|
||||
end
|
||||
|
||||
def new(conn, _params) do
|
||||
changeset = Group.changeset(%Group{}, %{})
|
||||
|
||||
render(conn, "new.html", changeset: changeset)
|
||||
end
|
||||
|
||||
def create(conn, %{"group" => %{"title" => title}}) do
|
||||
changeset = Group.changeset(%Group{title: title}, %{})
|
||||
|
||||
{:ok, group} = Repo.insert(changeset)
|
||||
|
||||
redirect(conn, to: Routes.group_path(Endpoint, :index))
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
group = Repo.get(Group, id)
|
||||
{:ok, _} = Repo.delete(group)
|
||||
redirect(conn, to: Routes.group_path(Endpoint, :index))
|
||||
end
|
||||
end
|
|
@ -17,10 +17,10 @@ defmodule FrenzyWeb.Router do
|
|||
scope "/", FrenzyWeb do
|
||||
pipe_through :browser
|
||||
|
||||
get "/", GroupController, :index
|
||||
resources "/groups", GroupController, except: [:edit, :update]
|
||||
# get "/", PageController, :index
|
||||
|
||||
resources "/feeds", FeedController, only: [:show, :create, :delete]
|
||||
get "/", FeedController, :index
|
||||
resources "/feeds", FeedController, except: [:edit, :update]
|
||||
post "/feeds/:id/refresh", FeedController, :refresh
|
||||
post "/feeds/:id/enable_filter", FeedController, :enable_filter
|
||||
post "/feeds/:id/disable_filter", FeedController, :disable_filter
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<a href="/feeds/new" class="button">Add Feed</a>
|
||||
|
||||
<table>
|
||||
<%= for feed <- @feeds do %>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/feeds/<%= feed.id %>"><%= feed.feed_url %></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<%= feed.site_url %>"><%= feed.title %></a>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
|
@ -0,0 +1,9 @@
|
|||
<%= form_for @changeset, Routes.feed_path(@conn, :create), fn form -> %>
|
||||
<div class="form-group">
|
||||
<label for="feed_url">Feed URL</label>
|
||||
<%= text_input form, :feed_url %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= submit "Create Feed" %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -1,17 +0,0 @@
|
|||
<a href="<%= Routes.group_path(@conn, :new) %>" class="button">Add Group</a>
|
||||
|
||||
<table>
|
||||
<%= for group <- @groups do %>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/groups/<%= group.id %>"><%= group.title %></a>
|
||||
</td>
|
||||
<td>
|
||||
<%= case Enum.count(group.feeds) do
|
||||
1 -> "1 feed"
|
||||
count -> "#{count} feeds"
|
||||
end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
|
@ -1,9 +0,0 @@
|
|||
<%= form_for @changeset, Routes.group_path(@conn, :create), fn form -> %>
|
||||
<div class="form-group">
|
||||
<label for="title">Title</label>
|
||||
<%= text_input form, :title %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= submit "Create Group" %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -1,29 +0,0 @@
|
|||
<h2><%= @group.title %></h2>
|
||||
|
||||
<%= form_tag Routes.group_path(@conn, :delete, @group.id), method: :delete do %>
|
||||
<%= submit "Delete Group" %>
|
||||
<% end %>
|
||||
|
||||
<%= form_for @create_feed_changeset, Routes.feed_path(@conn, :create), fn form -> %>
|
||||
<%= hidden_input form, :group_id %>
|
||||
<div class="form-group">
|
||||
<%= label form, :feed_url, "Feed URL" %>
|
||||
<%= text_input form, :feed_url %>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<%= submit "Create Feed" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<table>
|
||||
<%= for feed <- @group.feeds do %>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="<%= Routes.feed_path(@conn, :show, feed.id) %>"><%= feed.feed_url %></a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="<%= feed.site_url %>"><%= feed.title %></a>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
|
@ -1,3 +0,0 @@
|
|||
defmodule FrenzyWeb.GroupView do
|
||||
use FrenzyWeb, :view
|
||||
end
|
|
@ -1,11 +0,0 @@
|
|||
defmodule Frenzy.Repo.Migrations.CreateGroups do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:groups) do
|
||||
add :title, :string
|
||||
|
||||
timestamps()
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
defmodule Frenzy.Repo.Migrations.FeedsAddGroup do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:feeds) do
|
||||
add :group_id, references(:groups, on_delete: :delete_all)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue