diff --git a/lib/frenzy/feed.ex b/lib/frenzy/feed.ex index 3bc812c..e899adb 100644 --- a/lib/frenzy/feed.ex +++ b/lib/frenzy/feed.ex @@ -35,6 +35,7 @@ defmodule Frenzy.Feed do field :site_url, :string field :title, :string field :filter_enabled, :boolean + field :scrape_remote_content, :boolean belongs_to :group, Frenzy.Group @@ -47,7 +48,7 @@ defmodule Frenzy.Feed do @doc false def changeset(feed, attrs) do feed - |> cast(attrs, [:title, :feed_url, :site_url, :last_updated, :filter_enabled]) + |> cast(attrs, [:title, :feed_url, :site_url, :last_updated, :filter_enabled, :scrape_remote_content]) |> cast_assoc(:filter, required: true) |> validate_required([:feed_url, :filter]) end diff --git a/lib/frenzy/update_feeds.ex b/lib/frenzy/update_feeds.ex index bc3e612..d519442 100644 --- a/lib/frenzy/update_feeds.ex +++ b/lib/frenzy/update_feeds.ex @@ -124,13 +124,17 @@ defmodule Frenzy.UpdateFeeds do Logger.debug("Creating item for #{url}") content = - case get_article_content(url) do - {:ok, content} -> - content + if feed.scrape_remote_content do + case get_article_content(url) do + {:ok, content} -> + content - {:err, reason} -> - Logger.warn("Unable to fetch article for #{url}: #{inspect(reason)}") - entry.description + {:err, reason} -> + Logger.warn("Unable to fetch article for #{url}: #{inspect(reason)}") + entry.description + end + else + entry.description end item_params = %{ diff --git a/lib/frenzy_web/controllers/feed_controller.ex b/lib/frenzy_web/controllers/feed_controller.ex index fb518f3..70528c2 100644 --- a/lib/frenzy_web/controllers/feed_controller.ex +++ b/lib/frenzy_web/controllers/feed_controller.ex @@ -52,6 +52,19 @@ defmodule FrenzyWeb.FeedController do redirect(conn, to: Routes.group_path(Endpoint, :show, group_id)) end + def edit(conn, _params) do + feed = conn.assigns[:feed] |> Repo.preload(:filter) + changeset = Feed.changeset(feed, %{}) + render(conn, "edit.html", changeset: changeset) + end + + def update(conn, %{"feed" => feed_params}) do + 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)) + end + def delete(conn, _params) do feed = conn.assigns[:feed] {:ok, _} = Repo.delete(feed) diff --git a/lib/frenzy_web/router.ex b/lib/frenzy_web/router.ex index 7bbf759..4f7e673 100644 --- a/lib/frenzy_web/router.ex +++ b/lib/frenzy_web/router.ex @@ -47,10 +47,10 @@ defmodule FrenzyWeb.Router do get "/", GroupController, :index resources "/groups", GroupController, except: [:edit, :update] - resources "/feeds", FeedController, only: [:show, :create, :delete] + resources "/feeds", FeedController, except: [:index, :new] post "/feeds/:id/refresh", FeedController, :refresh - post "/feeds/:id/enable_filter", FeedController, :enable_filter - post "/feeds/:id/disable_filter", FeedController, :disable_filter + #post "/feeds/:id/enable_filter", FeedController, :enable_filter + #post "/feeds/:id/disable_filter", FeedController, :disable_filter resources "/filters", FilterController, only: [:edit, :update] post "/filters/:id/add_rule", FilterController, :add_rule diff --git a/lib/frenzy_web/templates/feed/edit.html.eex b/lib/frenzy_web/templates/feed/edit.html.eex new file mode 100644 index 0000000..6acb57a --- /dev/null +++ b/lib/frenzy_web/templates/feed/edit.html.eex @@ -0,0 +1,25 @@ +