diff --git a/lib/changelog/cache.ex b/lib/changelog/cache.ex index bfb1c46a16..9054de4d42 100644 --- a/lib/changelog/cache.ex +++ b/lib/changelog/cache.ex @@ -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() diff --git a/lib/changelog/schema/factory.ex b/lib/changelog/schema/factory.ex index 88b94b308c..26bb7b49fa 100644 --- a/lib/changelog/schema/factory.ex +++ b/lib/changelog/schema/factory.ex @@ -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 diff --git a/lib/changelog/schema/podcast/podcast.ex b/lib/changelog/schema/podcast/podcast.ex index 427ae291c2..57dddaeee9 100644 --- a/lib/changelog/schema/podcast/podcast.ex +++ b/lib/changelog/schema/podcast/podcast.ex @@ -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 @@ -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: "changelog@changelog.social", @@ -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", @@ -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() @@ -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 diff --git a/lib/changelog_web/controllers/admin/podcast_controller.ex b/lib/changelog_web/controllers/admin/podcast_controller.ex index cd1bece8d5..8275cd7789 100644 --- a/lib/changelog_web/controllers/admin/podcast_controller.ex +++ b/lib/changelog_web/controllers/admin/podcast_controller.ex @@ -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 diff --git a/lib/changelog_web/templates/admin/podcast/index.html.eex b/lib/changelog_web/templates/admin/podcast/index.html.eex index abf783515f..3e2059f5b7 100644 --- a/lib/changelog_web/templates/admin/podcast/index.html.eex +++ b/lib/changelog_web/templates/admin/podcast/index.html.eex @@ -19,23 +19,30 @@ <%= render(EpisodeView, "_downloads.html", assigns) %> +<%= if Enum.any?(@draft) do %> +
+

Draft pods

+ <%= render("_table.html", Map.merge(assigns, %{podcasts: @draft})) %> +
+<% end %> + <%= if Enum.any?(@active) do %>
-

Active podcasts

+

Active pods

<%= render("_table.html", Map.merge(assigns, %{podcasts: @active})) %>
<% end %> -<%= if Enum.any?(@draft) do %> +<%= if Enum.any?(@inactive) do %>
-

Draft podcasts

- <%= render("_table.html", Map.merge(assigns, %{podcasts: @draft})) %> +

Inactive pods (still public)

+ <%= render("_table.html", Map.merge(assigns, %{podcasts: @inactive})) %>
<% end %> -<%= if Enum.any?(@retired) do %> +<%= if Enum.any?(@archived) do %>
-

Retired podcasts

- <%= render("_table.html", Map.merge(assigns, %{podcasts: @retired})) %> +

Archived pods (private)

+ <%= render("_table.html", Map.merge(assigns, %{podcasts: @archived})) %>
<% end %> diff --git a/lib/changelog_web/templates/layout/_footer.html.eex b/lib/changelog_web/templates/layout/_footer.html.eex index 54eb5ab28c..b3e0b5bef6 100644 --- a/lib/changelog_web/templates/layout/_footer.html.eex +++ b/lib/changelog_web/templates/layout/_footer.html.eex @@ -2,8 +2,8 @@