Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

576 list podcasts #590

Merged
merged 22 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion app/controllers/podcasts_controller.rb
a-maci29 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
class PodcastsController < ApplicationController
before_action :set_podcast, only: %i[show edit update destroy]

# Translate the user selected sort to a query order argument
DISPLAY_ORDER = {"A-Z" => {title: :asc},
"Z-A" => {title: :desc},
"" => {updated_at: :desc}}.freeze

DEFAULT_PAGE_SIZE = 10

# GET /podcasts
def index
@podcasts = Podcast.all.limit(10)
base_query = policy_scope(Podcast).page(params[:page]).per(DEFAULT_PAGE_SIZE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need to happen in this PR, but would be nice to also accept the ?per query param here. (Still defaulting to 10, if it's blank).

@podcasts = add_sorting(base_query)
end

def add_sorting(query)
if params[:sort] == "episode_count"
query.left_joins(:episodes).group(:id).order("COUNT(episodes.id) DESC")
else
query.order(DISPLAY_ORDER[params[:sort].to_s])
end
end

# GET /podcasts/1
Expand Down
2 changes: 1 addition & 1 deletion app/views/fake/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<div class="dashboard-header">
<div class="col d-flex align-items-center">
<h1 class="text-black fw-bold me-4 mb-0">My Podcasts</h1>
<div class="btn-group">
<div class="btn-group btn btn-light btn-sm dropdown-toggle">
<button class="btn btn-outline-light btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Sort <span class="material-icons" aria-hidden="true">sort</span>
</button>
Expand Down
22 changes: 22 additions & 0 deletions app/views/podcasts/_podcast_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="prx-podcast | card">
<div class="d-flex g-2 p-3 align-items-center">
<div class="card-image">
<% if podcast.feed_image %>
<%= image_tag(podcast.feed_image.url, width: 80, alt: podcast.feed_image.alt_text, class: "d-flex me-4") %>
<% end %>
</div>
<div class="card-body flex-grow-1 ">
<h2 class="card-title"><%= podcast.title %></h2>
<p class="card-text m-0 lh-xs fs-sm">
<%= podcast.episodes.published.count %> Published Episodes |
<%= podcast.episodes.scheduled.count %> Scheduled Episodes |
<%= podcast.episodes.draft.count %> Drafted Episodes
</p>
<%= link_to "Go to Podcast", podcast_path(podcast), class: "card-link" %>
</div>
<div class="card-footer d-grid g-1 lh-sm fs-sm text-end">
<strong>Last Saved</strong>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably add all these strings (lines 11 thru here) to en.yml. Or open another ticket to do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do it as part of this ticket! I was already thinking about it, so might as well just get to it rather than spend the time making another ticket for it.

<datetime><%= podcast.updated_at.strftime("%-m/%-d/%Y, %-l:%M %p") %></datetime>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a @brandonhundt question... but what format is this? And is this something we use throughout the app?

Generally, we should define a :short and :long format for dates and times (4 total), in en.yml. Or maybe a couple more, if we really need to display dates/times differently for some reason. But they should get defined only there, instead of in the views.

</div>
</div>
</div>
40 changes: 31 additions & 9 deletions app/views/podcasts/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
<% content_for :title, "My Podcasts" %>

<p style="color: green"><%= notice %></p>
<div class="row mt-4 mb-4">
<div class="dashboard header">
<div class="col d-flex align-items-center ">
<h1 class="text-black fw-bold me-4 mb-0">My Podcasts</h1>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a design question, but "My" may not be true - this is podcasts they can access, not some kind of implied ownership

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deferred to the design, but I can change it if you like

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brandonhundt any preference?


<h1>Podcasts</h1>
<a data-bs-toggle="dropdown">
<button class="btn btn-outline-light btn-sm dropdown-toggle">
Sort <span class="material-icons" style="color: green" aria-hidden="true" aria-hidden="true">sort</span>
</button>
<ul class="dropdown-menu"><a class="dropdown-item active" href="<%= podcasts_path(sort: "Recent") %>">Recent Activity</a></li>
<li><%= link_to "# of Episodes", podcasts_path(sort: "episode_count"), class: "dropdown-item" %></li>
<li><%= link_to "A-Z", podcasts_path(sort: "A-Z"), class: "dropdown-item" %></li>
<li><%= link_to "Z-A", podcasts_path(sort: "Z-A"), class: "dropdown-item" %></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also get these values from the hash in the controller, instead of duplicating them

</ul>
</a>
</div>
</div>
</div>

<div id="podcasts">
<% @podcasts.each do |podcast| %>
<%= render podcast %>
<p>
<%= link_to "Show this podcast", podcast %>
</p>
<% end %>
</div>
<section class="col-lg-12">
<div class="dashboard-list mb-4 shadow">
<% @podcasts.each do |podcast| %>
<%= render "podcast_page", podcast: podcast %>
<% end %>
<div class="mt-2">
</div>
</div>
</section>

<%= link_to "New podcast", new_podcast_path %>
<%= paginate @podcasts, window: 2, outer_window: 1 %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should maybe standardize these window/outer_window configs for all our views. (At some point - doesn't need to happen here).

<%= page_entries_info @podcasts %>
</div>