Compare commits
2 Commits
72e3230504
...
eb0ebeba91
Author | SHA1 | Date |
---|---|---|
Shadowfacts | eb0ebeba91 | |
Shadowfacts | 7a39e649d1 |
|
@ -21,6 +21,8 @@ defmodule Frenzy.Feed do
|
||||||
field :title, :string
|
field :title, :string
|
||||||
field :filter_enabled, :boolean
|
field :filter_enabled, :boolean
|
||||||
|
|
||||||
|
belongs_to :group, Frenzy.Group
|
||||||
|
|
||||||
has_many :items, Frenzy.Item, on_delete: :delete_all
|
has_many :items, Frenzy.Item, on_delete: :delete_all
|
||||||
has_one :filter, Frenzy.Filter, on_delete: :delete_all
|
has_one :filter, Frenzy.Filter, on_delete: :delete_all
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
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,10 +100,10 @@ defmodule Frenzy.UpdateFeeds do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp create_item(feed, entry) do
|
defp create_item(feed, entry) do
|
||||||
Logger.debug("Creating item for #{entry.url}")
|
|
||||||
|
|
||||||
url = get_real_url(entry)
|
url = get_real_url(entry)
|
||||||
|
|
||||||
|
Logger.debug("Creating item for #{url}")
|
||||||
|
|
||||||
content =
|
content =
|
||||||
case get_article_content(url) do
|
case get_article_content(url) do
|
||||||
{:ok, content} ->
|
{:ok, content} ->
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
defmodule FrenzyWeb.FeedController do
|
defmodule FrenzyWeb.FeedController do
|
||||||
use FrenzyWeb, :controller
|
use FrenzyWeb, :controller
|
||||||
alias Frenzy.{Repo, Feed, Filter, Item}
|
alias Frenzy.{Repo, Group, Feed, Filter, Item}
|
||||||
alias FrenzyWeb.Router.Helpers, as: Routes
|
alias FrenzyWeb.Router.Helpers, as: Routes
|
||||||
alias FrenzyWeb.Endpoint
|
alias FrenzyWeb.Endpoint
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
def index(conn, _params) do
|
|
||||||
render(conn, "index.html", feeds: Repo.all(Feed))
|
|
||||||
end
|
|
||||||
|
|
||||||
def show(conn, %{"id" => id}) do
|
def show(conn, %{"id" => id}) do
|
||||||
feed = Repo.get(Feed, id) |> Repo.preload(:filter)
|
feed = Repo.get(Feed, id) |> Repo.preload(:filter)
|
||||||
items = Repo.all(from Item, where: [feed_id: ^id, tombstone: false], order_by: [desc: :date])
|
items = Repo.all(from Item, where: [feed_id: ^id, tombstone: false], order_by: [desc: :date])
|
||||||
|
@ -19,36 +15,27 @@ defmodule FrenzyWeb.FeedController do
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def new(conn, _params) do
|
def create(conn, %{"feed" => %{"group_id" => group_id, "feed_url" => feed_url}}) do
|
||||||
changeset = Feed.changeset(%Feed{}, %{})
|
group = Repo.get(Group, group_id)
|
||||||
|
|
||||||
render(conn, "new.html", changeset: changeset)
|
|
||||||
end
|
|
||||||
|
|
||||||
def create(conn, %{"feed" => %{"feed_url" => feed_url}}) do
|
|
||||||
changeset =
|
changeset =
|
||||||
Feed.changeset(
|
Ecto.build_assoc(group, :feeds, %{
|
||||||
%Feed{
|
feed_url: feed_url,
|
||||||
feed_url: feed_url,
|
filter: %Filter{
|
||||||
filter: %Filter{
|
mode: "reject",
|
||||||
mode: "reject",
|
score: 0
|
||||||
score: 0
|
}
|
||||||
}
|
})
|
||||||
},
|
|
||||||
%{}
|
|
||||||
)
|
|
||||||
|
|
||||||
{:ok, feed} = Repo.insert(changeset)
|
{:ok, feed} = Repo.insert(changeset)
|
||||||
|
|
||||||
# changeset =
|
redirect(conn, to: Routes.group_path(Endpoint, :show, group_id))
|
||||||
# Ecto.build_assoc(feed, :filter, %{
|
end
|
||||||
# mode: "reject",
|
|
||||||
# score: 0
|
|
||||||
# })
|
|
||||||
|
|
||||||
# {:ok, _} = Repo.insert(changeset)
|
def delete(conn, %{"id" => id}) do
|
||||||
|
feed = Repo.get(Feed, id)
|
||||||
redirect(conn, to: Routes.feed_path(Endpoint, :index))
|
{:ok, _} = Repo.delete(feed)
|
||||||
|
redirect(conn, to: Routes.group_path(Endpoint, :show, feed.group_id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def enable_filter(conn, %{"id" => id}) do
|
def enable_filter(conn, %{"id" => id}) do
|
||||||
|
@ -65,12 +52,6 @@ defmodule FrenzyWeb.FeedController do
|
||||||
redirect(conn, to: Routes.feed_path(Endpoint, :show, id))
|
redirect(conn, to: Routes.feed_path(Endpoint, :show, id))
|
||||||
end
|
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
|
def refresh(conn, %{"id" => id}) do
|
||||||
feed = Repo.get(Feed, id) |> Repo.preload(:filter)
|
feed = Repo.get(Feed, id) |> Repo.preload(:filter)
|
||||||
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
|
feed = Frenzy.UpdateFeeds.refresh(Frenzy.UpdateFeeds, feed)
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
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
|
scope "/", FrenzyWeb do
|
||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
# get "/", PageController, :index
|
get "/", GroupController, :index
|
||||||
|
resources "/groups", GroupController, except: [:edit, :update]
|
||||||
|
|
||||||
get "/", FeedController, :index
|
resources "/feeds", FeedController, only: [:show, :create, :delete]
|
||||||
resources "/feeds", FeedController, except: [:edit, :update]
|
|
||||||
post "/feeds/:id/refresh", FeedController, :refresh
|
post "/feeds/:id/refresh", FeedController, :refresh
|
||||||
post "/feeds/:id/enable_filter", FeedController, :enable_filter
|
post "/feeds/:id/enable_filter", FeedController, :enable_filter
|
||||||
post "/feeds/:id/disable_filter", FeedController, :disable_filter
|
post "/feeds/:id/disable_filter", FeedController, :disable_filter
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
<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>
|
|
|
@ -1,9 +0,0 @@
|
||||||
<%= 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 %>
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
<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>
|
|
@ -0,0 +1,9 @@
|
||||||
|
<%= 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 %>
|
|
@ -0,0 +1,29 @@
|
||||||
|
<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>
|
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule FrenzyWeb.GroupView do
|
||||||
|
use FrenzyWeb, :view
|
||||||
|
end
|
|
@ -0,0 +1,11 @@
|
||||||
|
defmodule Frenzy.Repo.Migrations.CreateGroups do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
create table(:groups) do
|
||||||
|
add :title, :string
|
||||||
|
|
||||||
|
timestamps()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
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