Skip to content

Commit

Permalink
Standardize on episode ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed Aug 9, 2023
1 parent e1d6e42 commit d1d6ef2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/controllers/episodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def index

filtered_episodes = episodes.filter_by_title(params[:q]).includes(:contents, :uncut)

@published_episodes = filtered_episodes.published.order(published_at: :desc).page(params[:published_page]).per(10)
@scheduled_episodes = filtered_episodes.draft_or_scheduled.reorder("released_at ASC NULLS FIRST").page(params[:scheduled_page]).per(10)
@published_episodes = filtered_episodes.published.dropdate_desc.page(params[:published_page]).per(10)
@scheduled_episodes = filtered_episodes.draft_or_scheduled.dropdate_asc.page(params[:scheduled_page]).per(10)
end

# GET /episodes/1
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/podcasts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def add_sorting(query)
def show
authorize @podcast

@recently_published = @podcast.episodes.published.order(published_at: :desc).limit(3)
@next_scheduled = @podcast.episodes.draft_or_scheduled.order(released_at: :asc).limit(3)
@recently_published = @podcast.episodes.published.dropdate_desc.limit(3)
@next_scheduled = @podcast.episodes.draft_or_scheduled.dropdate_asc.limit(3)

@metrics_jwt = prx_jwt
@metrics_castle_root = castle_root
Expand Down
2 changes: 2 additions & 0 deletions app/models/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Episode < ApplicationRecord
scope :draft_or_scheduled, -> { draft.or(scheduled) }
scope :after, ->(time) { where("COALESCE(published_at, released_at) > ?", time) }
scope :filter_by_title, ->(text) { where("episodes.title ILIKE ?", "%#{text}%") }
scope :dropdate_asc, -> { reorder(Arel.sql("COALESCE(published_at, released_at) ASC NULLS FIRST")) }
scope :dropdate_desc, -> { reorder(Arel.sql("COALESCE(published_at, released_at) DESC NULLS LAST")) }

enum :medium, [:audio, :uncut, :video], prefix: true

Expand Down

0 comments on commit d1d6ef2

Please sign in to comment.