Skip to content

Commit

Permalink
Refine podcast status system
Browse files Browse the repository at this point in the history
- Rename published to publishing
- Change retired to inactive, add archived
- Show inactive on /podcasts and in footer
  • Loading branch information
jerodsanto committed Jan 3, 2024
1 parent d378172 commit a328b8d
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 63 deletions.
2 changes: 1 addition & 1 deletion lib/changelog/cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ defmodule Changelog.Cache do

def podcasts do
get_or_store("podcasts", :infinity, fn ->
Podcast.active()
Podcast.public()
|> Podcast.by_position()
|> Podcast.preload_active_hosts()
|> Podcast.preload_retired_hosts()
Expand Down
2 changes: 1 addition & 1 deletion lib/changelog/schema/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ defmodule Changelog.Factory do
%Changelog.Podcast{
name: sequence(:name, &"Show #{&1}"),
slug: sequence(:slug, &"show-#{&1}"),
status: :published
status: :publishing
}
end

Expand Down
25 changes: 14 additions & 11 deletions lib/changelog/schema/podcast/podcast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Changelog.Podcast do

require Logger

defenum(Status, draft: 0, soon: 1, published: 2, retired: 3)
defenum(Status, draft: 0, soon: 1, publishing: 2, inactive: 3, archived: 4)

schema "podcasts" do
field :name, :string
Expand Down Expand Up @@ -70,7 +70,7 @@ defmodule Changelog.Podcast do
%__MODULE__{
name: "Changelog Master Feed",
slug: "master",
status: :published,
status: :publishing,
is_meta: true,
twitter_handle: "changelog",
mastodon_handle: "[email protected]",
Expand All @@ -91,7 +91,7 @@ defmodule Changelog.Podcast do
%__MODULE__{
name: "The Changelog",
slug: "podcast",
status: :published,
status: :publishing,
is_meta: true,
vanity_domain: "https://changelog.fm",
twitter_handle: "changelog",
Expand Down Expand Up @@ -135,20 +135,19 @@ defmodule Changelog.Podcast do
|> file_changeset(attrs)
end

def active(query \\ __MODULE__), do: from(q in query, where: q.status in [^:soon, ^:published])
def draft(query \\ __MODULE__), do: from(q in query, where: q.status == ^:draft)
def private(query \\ __MODULE__), do: from(q in query, where: q.status in [^:draft, ^:archived])

def public(query \\ __MODULE__), do: from(q in query, where: q.status in [^:soon, ^:publishing, ^:inactive])
def active(query \\ __MODULE__), do: from(q in query, where: q.status in [^:soon, ^:publishing])
def inactive(query \\ __MODULE__), do: from(q in query, where: q.status == ^:inactive)

def public(query \\ __MODULE__),
do: from(q in query, where: q.status in [^:soon, ^:published, ^:retired])
def draft(query \\ __MODULE__), do: from(q in query, where: q.status == ^:draft)
def archived(query \\ __MODULE__), do: from(q in query, where: q.status == ^:archived)

def retired(query \\ __MODULE__), do: from(q in query, where: q.status == ^:retired)
def not_retired(query \\ __MODULE__), do: from(q in query, where: q.status != ^:retired)
def oldest_first(query \\ __MODULE__), do: from(q in query, order_by: [asc: q.id])
def retired_last(query \\ __MODULE__), do: from(q in query, order_by: [asc: q.status])

def with_vanity_domain(query \\ __MODULE__), do: from(q in query, where: not is_nil(q.vanity_domain))


def get_by_slug!("interviews"), do: get_by_slug!("podcast")
def get_by_slug!("master"), do: master()

Expand Down Expand Up @@ -198,6 +197,10 @@ defmodule Changelog.Podcast do

def is_master(podcast), do: podcast.slug == "master"

def is_active(podcast), do: Enum.member?([:soon, :publishing], podcast.status)

def is_publishing(podcast), do: podcast.status == :publishing

def published_episode_count(%{slug: "master"}), do: Repo.count(Episode.published())

def published_episode_count(podcast) do
Expand Down
17 changes: 12 additions & 5 deletions lib/changelog_web/controllers/admin/podcast_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,30 @@ defmodule ChangelogWeb.Admin.PodcastController do

active =
Podcast.active()
|> Podcast.not_retired()
|> Podcast.by_position()
|> Podcast.preload_active_hosts()
|> Repo.all()
|> Enum.filter(fn p -> Policies.Admin.Podcast.show(user, p) end)

retired =
Podcast.retired()
inactive =
Podcast.inactive()
|> Podcast.by_position()
|> Podcast.preload_active_hosts()
|> Repo.all()
|> Enum.filter(fn p -> Policies.Admin.Podcast.show(user, p) end)

archived =
Podcast.archived()
|> Podcast.oldest_first()
|> Podcast.preload_active_hosts()
|> Repo.all()
|> Enum.filter(fn p -> Policies.Admin.Podcast.show(user, p) end)

conn
|> assign(:active, active)
|> assign(:draft, draft)
|> assign(:retired, retired)
|> assign(:active, active)
|> assign(:inactive, inactive)
|> assign(:archived, archived)
|> assign(:downloads, ChangelogWeb.Admin.PageController.downloads())
|> render(:index)
end
Expand Down
21 changes: 14 additions & 7 deletions lib/changelog_web/templates/admin/podcast/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@
<%= render(EpisodeView, "_downloads.html", assigns) %>
</div>

<%= if Enum.any?(@draft) do %>
<div class="ui basic segment">
<h2 class="ui header">Draft pods</h2>
<%= render("_table.html", Map.merge(assigns, %{podcasts: @draft})) %>
</div>
<% end %>

<%= if Enum.any?(@active) do %>
<div class="ui basic segment">
<h2 class="ui header">Active podcasts</h2>
<h2 class="ui header">Active pods</h2>
<%= render("_table.html", Map.merge(assigns, %{podcasts: @active})) %>
</div>
<% end %>

<%= if Enum.any?(@draft) do %>
<%= if Enum.any?(@inactive) do %>
<div class="ui basic segment">
<h2 class="ui header">Draft podcasts</h2>
<%= render("_table.html", Map.merge(assigns, %{podcasts: @draft})) %>
<h2 class="ui header">Inactive pods (still public)</h2>
<%= render("_table.html", Map.merge(assigns, %{podcasts: @inactive})) %>
</div>
<% end %>

<%= if Enum.any?(@retired) do %>
<%= if Enum.any?(@archived) do %>
<div class="ui basic segment">
<h2 class="ui header">Retired podcasts</h2>
<%= render("_table.html", Map.merge(assigns, %{podcasts: @retired})) %>
<h2 class="ui header">Archived pods (private)</h2>
<%= render("_table.html", Map.merge(assigns, %{podcasts: @archived})) %>
</div>
<% end %>
11 changes: 6 additions & 5 deletions lib/changelog_web/templates/layout/_footer.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<nav class="footer-primary">
<div class="footer-primary_wrap">
<ul class="footer-primary-list footer-primary-list--company">
<li><%= link "About", to: Routes.page_path(@conn, :about) %></li>
<li><%= link "Contact", to: Routes.page_path(@conn, :contact) %></li>
<li><%= link "About", to: ~p"/about" %></li>
<li><%= link "Contact", to: ~p"/contact" %></li>
<li><a href="tel:+1-888-974-2454">888-974-CHLG (2454)</a></li>
</ul>

Expand Down Expand Up @@ -50,12 +50,13 @@
<div class="footer-nav-list">
<h4><%= link("Podcasts", to: ~p"/podcasts", title: "View all podcasts") %></h4>
<ul>
<%= for podcast <- @podcasts do %>
<%= for podcast <- ChangelogWeb.PodcastView.active_podcasts_for_index(@podcasts) do %>
<li><%= link(podcast.name, to: ~p"/#{podcast.slug}", title: podcast.name) %></li>
<% end %>
<li>---</li>
<li><%= link("Master", to: ~p"/master", title: "Master feed") %></li>

<%= for podcast <- ChangelogWeb.PodcastView.inactive_podcasts_for_index(@podcasts) do %>
<li><%= link(podcast.name, to: ~p"/#{podcast.slug}", title: podcast.name) %></li>
<% end %>
</ul>
</div>
<div class="footer-nav-list">
Expand Down
2 changes: 1 addition & 1 deletion lib/changelog_web/templates/page/index.html.eex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= render(ChangelogWeb.PodcastView, "index.html", assigns) %>
<%= render(ChangelogWeb.PodcastView, "_index_active.html", assigns) %>

<div class="show">
<a id="recent" class="anchor"></a>
Expand Down
2 changes: 1 addition & 1 deletion lib/changelog_web/templates/person/subscribe.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="main-podcasts">
<section class="show_list" id="podcasts">
<div class="show_list-shows">
<%= render_many(PodcastView.podcasts_for_index(@podcasts), PodcastView, "_summary.html", assigns) %>
<%= render_many(PodcastView.active_podcasts_for_index(@podcasts), PodcastView, "_summary.html", assigns) %>
</div>
</section>
</div>
4 changes: 2 additions & 2 deletions lib/changelog_web/templates/podcast/_feed.html.eex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= if @podcast.status == :retired do %>
<p class="feed-note">This podcast has been retired. Please browse and enjoy the archive below.</p>
<%= if @podcast.status == :inactive do %>
<p class="feed-note">This podcast is not in production. Please browse and enjoy the archive below.</p>
<% end %>

<nav class="subnav">
Expand Down
12 changes: 6 additions & 6 deletions lib/changelog_web/templates/podcast/_header_landing.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
sizes="(min-width:880px) 490w, 440w"
alt="<%= @podcast.name %> Artwork"
>
<%= if @podcast.status != :published do %>
<%= if @podcast.status != :publishing do %>
<div class="show-header-art-status show-header-art-status--<%= @podcast.status %>"><span><%= status_text(@podcast) %></span></div>
<% end %>
</div>

<div class="show-header-content">
<%= if @podcast.status != :retired do %>
<%= if Podcast.is_active(@podcast) do %>
<%= if is_map(@trailer) do %>
<%= link("Listen to the Trailer",
title: "Play the Trailer",
Expand Down Expand Up @@ -58,17 +58,17 @@
<hr class="show-header-break">

<%= cond do %>
<% @podcast.status == :retired -> %>
<p class="show-header-signup_text">This podcast has been retired. <%= link("Head here", to: Routes.podcast_path(@conn, :index)) %> for more awesome podcasts.</p>
<% @podcast.status == :inactive -> %>
<p class="show-header-signup_text">This podcast is not currently in production. <%= link("Head here", to: Routes.podcast_path(@conn, :index)) %> for more awesome podcasts.</p>
<% !Podcast.has_feed(@podcast) -> %>
<p>You can only subscribe to <em><%= @podcast.name %></em> by subscribing to our <%= link("Master Feed", to: Routes.podcast_path(@conn, :show, "master")) %></p>
<% Podcast.is_a_changelog_pod(@podcast) -> %>
<%= render("_news_subscribe.html", assigns) %>
<%= render("_subscribe_buttons.html", assigns) %>
<% true -> %>
<%= render("_podcast_subscribe.html", assigns) %>
<%= render("_subscribe_buttons.html", assigns) %>
<% end %>

<%= render("_subscribe_buttons.html", assigns) %>
</div>

</div>
Expand Down
11 changes: 11 additions & 0 deletions lib/changelog_web/templates/podcast/_index_active.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<section class="show_list">
<header class="show_list-header">
<h2>Changelog makes great podcasts for developers</h2>
<p><%= link("The Changelog", to: "/podcast", title: "The Changelog") %> podcast is the software world's best weekly <%= link("news brief", to: "/news") %> (Mondays), deep <%= link("technical interviews", to: "/interviews") %> (Wednesdays) and <%= link("talk show", to: "/friends") %> (Fridays) that's like putting the hallway track at your favorite tech conference on repeat.</p>
<p class="show_list-header-master_cta"><a href="/subscribe/news"><strong>Subscribe to the Changelog News(letter)!</strong> We keep it brief, entertaining &amp; always on-point.</a></p>
<p>But that's not all! We produce other great shows about web development, open source, building startups, AI & the human brain.</p>
</header>
<div class="show_list-shows">
<%= render_many(active_podcasts_for_index(@podcasts), __MODULE__, "_summary.html", assigns) %>
</div>
</section>
8 changes: 8 additions & 0 deletions lib/changelog_web/templates/podcast/_index_inactive.html.eex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<section class="show_list">
<header class="show_list-header">
<h2>More great podcasts that are not currently in production</h2>
</header>
<div class="show_list-shows">
<%= render_many(inactive_podcasts_for_index(@podcasts), __MODULE__, "_summary.html", assigns) %>
</div>
</section>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= if Podcast.has_feed(@podcast) && @podcast.status != :retired do %>
<%= if Podcast.has_feed(@podcast) && @podcast.status != :inactive do %>
<div class="show-header-subscribe">
<div class="show-header-subscribe-buttons">
<%= if @podcast.apple_url do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
<% end %>
<li><%= link("Email", to: subscribe_via_email_path(@conn, @podcast), title: "Subscribe via Email") %></li>
<% else %>
<li><%= link("Via Master", to: Routes.podcast_path(@conn, :show, "master")) %></li>
<li><%= link("Via Master", to: ~p"/master") %></li>
<% end %>
</ul>
<div class="tooltip-footer">
<%= link("Request Episode", to: Routes.episode_request_path(@conn, :new, @podcast.slug)) %>
<%= link("Request Episode", to: ~p"/request/#{@podcast.slug}") %>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion lib/changelog_web/templates/podcast/_summary.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div class="show_list-shows-item-content">
<div class="show_list-shows-item-content-heading">
<h2><a href="<%= ~p"/#{@podcast.slug}" %>"><%= @podcast.name %></a></h2>
<%= if @podcast.status != :soon do %>
<%= if Podcast.is_publishing(@podcast) do %>
<button class="show_list-shows-item-content-heading-subscribe has-tooltip" title="Subscribe">Subscribe</button>
<%= render("_subscribe_tooltip.html", conn: @conn, podcast: @podcast) %>
<% end %>
Expand Down
13 changes: 2 additions & 11 deletions lib/changelog_web/templates/podcast/index.html.eex
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
<div class="page_podcasts">
<section class="show_list">
<header class="show_list-header">
<h2>Changelog makes great podcasts for developers</h2>
<p><%= link("The Changelog", to: "/podcast", title: "The Changelog") %> podcast is the software world's best weekly <%= link("news brief", to: "/news") %> (Mondays), deep <%= link("technical interviews", to: "/interviews") %> (Wednesdays) and <%= link("talk show", to: "/friends") %> (Fridays) that's like putting the hallway track at your favorite tech conference on repeat.</p>
<p class="show_list-header-master_cta"><a href="/subscribe/news"><strong>Subscribe to the Changelog News(letter)!</strong> We keep it brief, entertaining &amp; always on-point.</a></p>
<p>But that's not all! We produce other great shows about web development, open source, building startups, AI & the human brain.</p>
</header>
<div class="show_list-shows">
<%= render_many(podcasts_for_index(@podcasts), __MODULE__, "_summary.html", assigns) %>
</div>
</section>
<%= render("_index_active.html", assigns) %>
<%= render("_index_inactive.html", assigns) %>
</div>
7 changes: 4 additions & 3 deletions lib/changelog_web/views/admin/podcast_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ defmodule ChangelogWeb.Admin.PodcastView do
end

def position_options do
1..Repo.count(Podcast.not_retired())
1..Repo.count(Podcast.public())
end

def subscribers_count(%{subscribers: nil}), do: 0
Expand All @@ -29,8 +29,9 @@ defmodule ChangelogWeb.Admin.PodcastView do
case podcast.status do
:draft -> content_tag(:span, "Draft", class: "ui tiny yellow basic label")
:soon -> content_tag(:span, "Coming Soon", class: "ui tiny yellow basic label")
:published -> content_tag(:span, "Published", class: "ui tiny green basic label")
:retired -> content_tag(:span, "Retired", class: "ui tiny basic label")
:publishing -> content_tag(:span, "Publishing", class: "ui tiny green basic label")
:inactive -> content_tag(:span, "Inactive", class: "ui tiny red basic label")
:archived -> content_tag(:span, "Archived", class: "ui tiny basic label")
end
end

Expand Down
15 changes: 11 additions & 4 deletions lib/changelog_web/views/podcast_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ defmodule ChangelogWeb.PodcastView do
alias ChangelogWeb.{Endpoint, EpisodeView, PersonView, SharedView}
alias Changelog.Files.Cover

def podcasts_for_index(podcasts) do
pods = Enum.reject(podcasts, &Podcast.is_a_changelog_pod/1)
def active_podcasts_for_index(podcasts) do
pods =
podcasts
|> Enum.reject(&Podcast.is_a_changelog_pod/1)
|> Enum.filter(&Podcast.is_active/1)

List.flatten([Podcast.changelog, pods, Podcast.master])
end

def inactive_podcasts_for_index(podcasts) do
Enum.reject(podcasts, &Podcast.is_active/1)
end

def apple_id(podcast) do
if url = podcast.apple_url do
url
Expand Down Expand Up @@ -94,9 +101,9 @@ defmodule ChangelogWeb.PodcastView do

def subscribe_via_email_path(conn, podcast) do
if conn.assigns.current_user do
Routes.home_path(conn, :show) <> "#podcasts"
~p"/~" <> "#podcasts"
else
Routes.person_path(conn, :subscribe, podcast.slug)
~p"/subscribe/#{podcast.slug}"
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ChangelogWeb.Admin.PodcastControllerTest do

alias Changelog.Podcast

@valid_attrs %{name: "Polyglot", slug: "polyglot", status: :published}
@valid_attrs %{name: "Polyglot", slug: "polyglot", status: :publishing}
@invalid_attrs %{name: "Polyglot", slug: ""}

@tag :as_admin
Expand Down
8 changes: 8 additions & 0 deletions test/changelog_web/controllers/podcast_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ defmodule ChangelogWeb.PodcastControllerTest do
end
end

test "getting an archived podcast page", %{conn: conn} do
p = insert(:podcast, status: :archived)

assert_raise Ecto.NoResultsError, fn ->
get(conn, Routes.podcast_path(conn, :show, p.slug))
end
end

test "getting a podcast page", %{conn: conn} do
p = insert(:podcast)
conn = get(conn, Routes.podcast_path(conn, :show, p.slug))
Expand Down

0 comments on commit a328b8d

Please sign in to comment.