Skip to content

Commit

Permalink
[admin] Remove dependency on scrivener_html
Browse files Browse the repository at this point in the history
  • Loading branch information
jerodsanto committed Aug 22, 2024
1 parent 5900093 commit 9720109
Show file tree
Hide file tree
Showing 28 changed files with 62 additions and 22 deletions.
4 changes: 0 additions & 4 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ config :phoenix, :generators,
migration: true,
binary_id: false

config :scrivener_html,
routes_helper: ChangelogWeb.Router.Helpers,
view_style: :semantic

config :mime, :types, %{"application/javascript" => ["js"], "application/xml" => ["xml"]}

config :shopify,
Expand Down
3 changes: 2 additions & 1 deletion lib/changelog_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ defmodule ChangelogWeb do
quote do
use Phoenix.View, root: "lib/changelog_web/templates", namespace: ChangelogWeb
use Phoenix.HTML

import Phoenix.Controller, only: [get_flash: 1, get_flash: 2, view_module: 1]
import Scrivener.HTML

alias ChangelogWeb.Router.Helpers, as: Routes
alias ChangelogWeb.Helpers.{AdminHelpers, SharedHelpers}
alias Changelog.Policies
Expand Down
2 changes: 1 addition & 1 deletion lib/changelog_web/templates/admin/episode/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@

<h2 class="ui header">Published</h2>
<%= render("_table.html", Map.merge(assigns, %{status: :published, podcast: @podcast, episodes: @episodes, actions: false})) %>
<%= pagination_links(@conn, @page, [@podcast.slug], path: &Routes.admin_podcast_episode_path/4) %>
<%= render(SharedView, "_pagination.html", assigns) %>
</div>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

<div class="ui basic segment">
<%= render("_table.html", assigns) %>
<%= pagination_links(@conn, @page, path: &Routes.admin_membership_path/3, filter: @filter) %>
<%= render(SharedView, "_pagination.html", assigns) %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@
<div class="ui basic segment">
<h2 class="ui header">Published</h2>
<%= render("_table.html", conn: @conn, issues: @issues) %>
<%= pagination_links(@conn, @page, path: &Routes.admin_news_source_path/3) %>
<%= render(SharedView, "_pagination.html", assigns) %>
</div>
<% end %>
2 changes: 1 addition & 1 deletion lib/changelog_web/templates/admin/news_item/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
<%= if Enum.any?(@published) do %>
<h2 id="published" class="ui header">Published (<%= @page.total_entries |> SharedHelpers.comma_separated %>)</h2>
<%= render("_table.html", Map.merge(assigns, %{status: :published, items: @published})) %>
<%= pagination_links(@conn, @page, path: &Routes.admin_news_item_path/3) %>
<%= render(SharedView, "_pagination.html", assigns) %>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
<div class="ui basic segment">
<%= if Enum.any?(@comments) do %>
<%= render("_table.html", conn: @conn, comments: @comments) %>
<%= pagination_links @conn, @page, path: &Routes.admin_news_item_comment_path/3 %>
<%= render(SharedView, "_pagination.html", assigns) %>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@
</tbody>
</table>

<%= pagination_links(@conn, @page, [@item], path: &Routes.admin_news_item_subscription_path/4) %>
<%= render(SharedView, "_pagination.html", assigns) %>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
<div class="ui basic segment">
<%= if Enum.any?(@sources) do %>
<%= render("_table.html", conn: @conn, sources: @sources) %>
<%= pagination_links(@conn, @page, path: &Routes.admin_news_source_path/3) %>
<%= render(SharedView, "_pagination.html", assigns) %>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
<div class="ui basic segment">
<%= if Enum.any?(@sponsorships) do %>
<%= render("_table.html", conn: @conn, sponsorships: @sponsorships) %>
<%= pagination_links(@conn, @page, path: &Routes.admin_news_sponsorship_path/3) %>
<%= render(SharedView, "_pagination.html", assigns) %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion lib/changelog_web/templates/admin/person/comments.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

<div class="ui basic segment">
<%= render(NewsItemCommentView, "_table.html", Map.merge(assigns, %{comments: @comments})) %>
<%= pagination_links(@conn, @page, [@person], path: &Routes.admin_person_path/4, action: :comments) %>
<%= render(SharedView, "_pagination.html", assigns) %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
<div class="ui basic segment">
<%= if Enum.any?(@people) do %>
<%= render("_table.html", assigns) %>
<%= pagination_links(@conn, @page, path: &Routes.admin_person_path/3, filter: @filter) %>
<%= render(SharedView, "_pagination.html", assigns) %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion lib/changelog_web/templates/admin/person/news.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@

<div class="ui basic segment">
<%= render(NewsItemView, "_table.html", Map.merge(assigns, %{status: :published, items: @published})) %>
<%= pagination_links(@conn, @page, [@person], path: &Routes.admin_person_path/4, action: :news) %>
<%= render(SharedView, "_pagination.html", assigns) %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@
</tbody>
</table>

<%= pagination_links(@conn, @page, [@podcast.slug], path: &Routes.admin_podcast_subscription_path/4) %>
<%= render(SharedView, "_pagination.html", assigns) %>
<% end %>
</div>
2 changes: 1 addition & 1 deletion lib/changelog_web/templates/admin/post/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
<%= if Enum.any?(@posts) do %>
<h2 class="ui header">Published (<%= @page.total_entries |> SharedHelpers.comma_separated %>)</h2>
<%= render("_table.html", Map.merge(assigns, %{conn: @conn, status: :published, posts: @posts})) %>
<%= pagination_links(@conn, @page, path: &Routes.admin_post_path/3) %>
<%= render(SharedView, "_pagination.html", assigns) %>
<% end %>
</div>
15 changes: 15 additions & 0 deletions lib/changelog_web/templates/admin/shared/_pagination.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= if @page.total_pages > 1 do %>
<div class="ui pagination menu">
<%= link("<< 1", to: pagination_path(@conn, 1), class: pagination_link_classes(@page, 1)) %>
<%= if @page.page_number != 1 do %>
<%= link("< Prev", to: pagination_path(@conn, @page.page_number - 1), class: "item") %>
<% end %>
<%= if @page.page_number != 1 && @page.page_number < @page.total_pages do %>
<%= link(@page.page_number, to: "", class: "active item") %>
<% end %>
<%= if @page.page_number < @page.total_pages do %>
<%= link("Next >", to: pagination_path(@conn, @page.page_number + 1), class: "item") %>
<% end %>
<%= link("#{@page.total_pages} >>", to: pagination_path(@conn, @page.total_pages), class: pagination_link_classes(@page, @page.total_pages)) %>
</div>
<% end %>
2 changes: 1 addition & 1 deletion lib/changelog_web/views/admin/episode_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ChangelogWeb.Admin.EpisodeView do

alias Changelog.{Episode, Person, Podcast, Sponsor, StringKit, Topic}
alias ChangelogWeb.{EpisodeView, PersonView, TimeView}
alias ChangelogWeb.Admin.{EpisodeRequestView, PodcastView}
alias ChangelogWeb.Admin.{EpisodeRequestView, PodcastView, SharedView}

def audio_filename(episode), do: EpisodeView.audio_filename(episode)
def plusplus_filename(episode), do: EpisodeView.plusplus_filename(episode)
Expand Down
1 change: 1 addition & 0 deletions lib/changelog_web/views/admin/membership_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule ChangelogWeb.Admin.MembershipView do
use ChangelogWeb, :admin_view

alias ChangelogWeb.PersonView
alias ChangelogWeb.Admin.SharedView

def last_changed_at(membership) do
if membership.updated_at > membership.inserted_at do
Expand Down
1 change: 1 addition & 0 deletions lib/changelog_web/views/admin/news_item_comment_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule ChangelogWeb.Admin.NewsItemCommentView do

alias Changelog.NewsItem
alias ChangelogWeb.{NewsItemCommentView, PersonView}
alias ChangelogWeb.Admin.SharedView

def permalink(conn, comment) do
Routes.news_item_path(conn, :show, NewsItem.slug(comment.news_item)) <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ defmodule ChangelogWeb.Admin.NewsItemSubscriptionView do

alias Changelog.{NewsItem, Subscription}
alias ChangelogWeb.PersonView
alias ChangelogWeb.Admin.SharedView
end
1 change: 1 addition & 0 deletions lib/changelog_web/views/admin/news_item_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule ChangelogWeb.Admin.NewsItemView do

alias Changelog.{NewsItem, NewsSource, Person, Topic}
alias ChangelogWeb.{Endpoint, PersonView, NewsItemView}
alias ChangelogWeb.Admin.SharedView

def bookmarklet_code do
url = Routes.admin_news_item_url(Endpoint, :new, quick: true, url: "")
Expand Down
1 change: 1 addition & 0 deletions lib/changelog_web/views/admin/news_source_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule ChangelogWeb.Admin.NewsSourceView do
use ChangelogWeb, :admin_view

alias ChangelogWeb.NewsSourceView
alias ChangelogWeb.Admin.SharedView

def icon_url(source), do: NewsSourceView.icon_url(source)
end
2 changes: 1 addition & 1 deletion lib/changelog_web/views/admin/news_sponsorship_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ChangelogWeb.Admin.NewsSponsorshipView do

alias Changelog.{ListKit, NewsAd, NewsSponsorship, Sponsor}
alias ChangelogWeb.{Endpoint, TimeView}
alias ChangelogWeb.Admin.{NewsAdView}
alias ChangelogWeb.Admin.{NewsAdView, SharedView}

def active_ads(sponsorship), do: Enum.filter(sponsorship.ads, & &1.active)
def inactive_ads(sponsorship), do: Enum.reject(sponsorship.ads, & &1.active)
Expand Down
2 changes: 1 addition & 1 deletion lib/changelog_web/views/admin/person_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ChangelogWeb.Admin.PersonView do

alias Changelog.Person
alias ChangelogWeb.PersonView
alias ChangelogWeb.Admin.{EpisodeView, EpisodeRequestView, FeedView, NewsItemView, NewsItemCommentView}
alias ChangelogWeb.Admin.{EpisodeView, EpisodeRequestView, FeedView, NewsItemView, NewsItemCommentView, SharedView}

def avatar_url(person), do: PersonView.avatar_url(person)

Expand Down
1 change: 1 addition & 0 deletions lib/changelog_web/views/admin/podcast_subscription_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule ChangelogWeb.Admin.PodcastSubscriptionView do

alias Changelog.Subscription
alias ChangelogWeb.PersonView
alias ChangelogWeb.Admin.SharedView

def chart_data(podcast) do
this_month = Timex.today() |> Timex.beginning_of_month()
Expand Down
1 change: 1 addition & 0 deletions lib/changelog_web/views/admin/post_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule ChangelogWeb.Admin.PostView do

alias Changelog.{Post, Topic}
alias ChangelogWeb.PostView
alias ChangelogWeb.Admin.SharedView

def image_url(post, version), do: PostView.image_url(post, version)

Expand Down
22 changes: 22 additions & 0 deletions lib/changelog_web/views/admin/shared_view.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule ChangelogWeb.Admin.SharedView do
use ChangelogWeb, :admin_view

def pagination_link_classes(paginator, page_number) do
if paginator.page_number == page_number do
"active item"
else
"item"
end
end


@doc"""
Constructs a pagination path for the given page, extracting relevant
path params [filter, action] from the connection to construct said path
"""
def pagination_path(conn, page) do
scopes = [:filter, :action]
params = Map.merge(%{page: page}, Map.take(conn.assigns, scopes))
SharedHelpers.current_path(conn, params)
end
end
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ defmodule Changelog.Mixfile do
{:oban_web, "~> 2.10.2", repo: "oban", only: @oban_envs},
{:timex, "~> 3.0"},
{:scrivener_ecto, "~> 2.0"},
{:scrivener_html, "~> 1.8", github: "jerodsanto/scrivener_html", branch: "phx-1-7"},
{:cmark, "~> 0.6"},
{:floki, "~> 0.35.2"},
{:waffle_ecto, "~> 0.0"},
Expand Down

0 comments on commit 9720109

Please sign in to comment.