Skip to content

Commit

Permalink
Add initial player preview and episode number input
Browse files Browse the repository at this point in the history
  • Loading branch information
radical-ube committed Aug 3, 2023
1 parent 52bc998 commit 60b0d36
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/controllers/podcast_player_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ class PodcastPlayerController < ApplicationController

# GET /podcasts/1/player
def show
@player_options = {}
@player_options[:embed_player_type] = params[:embed_player_type]
@player_options[:episode_number] = params[:episode_number]
@player_options[:season] = params[:season]
@player_options[:category] = params[:category]
@player_options[:recent] = params[:recent]
end

private
Expand Down
30 changes: 30 additions & 0 deletions app/helpers/embed_player_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module EmbedPlayerHelper
EMBED_PLAYER_RSS_URL = "us"
EMBED_PLAYER_AUDIO_URL = "ua"
DOVETAIL_TOKEN = "_t"
EMBED_PLAYER_PLAYLIST = "sp"
EMBED_PLAYER_SEASON = "se"
EMBED_PLAYER_CATEGORY = "ct"

def embed_player_episode_url(ep, type = nil, preview = false)
params = {}
Expand All @@ -33,6 +36,19 @@ def embed_player_episode_url(ep, type = nil, preview = false)
embed_params(params)
end

def embed_player_podcast_url(podcast, preview = false, options)
params = {}

params[EMBED_PLAYER_FEED] = podcast.published_url
params[EMBED_PLAYER_PLAYLIST] = options[:episode_number] || "10"

# if options[:embed_player_type] == "card" || options[:embed_player_type] == "fixed_card"
# params[EMBED_PLAYER_CARD] = "1"
# end

embed_params(params)
end

def embed_player_episode_iframe(ep, type = nil, preview = false)
src = embed_player_episode_url(ep, type, preview)
allow = "monetization"
Expand All @@ -47,6 +63,20 @@ def embed_player_episode_iframe(ep, type = nil, preview = false)
end
end

def embed_player_podcast_iframe(podcast, preview = false, options)
src = embed_player_podcast_url(podcast, preview, options)
allow = "monetization"

if options[:embed_player_type] == "card"
# TODO: this is NOW working, but I'm not sure how helpful this is to a producer that wishes to embed it.
tag.iframe src: src, allow: allow, width: "100%", height: "700", style: "--aspect-ratio: 2/3; width: 100%;"
elsif options[:embed_player_type] == "fixed_card"
tag.iframe src: src, allow: allow, width: "500", height: "700"
else
tag.iframe src: src, allow: allow, width: "100%", height: "600", style: "--aspect-ratio: 2/3; width: 100%;"
end
end

def embed_player_type_options(selected)
opts = %w[standard card fixed_card].map { |v| [t("helpers.label.episode.embed_player_types.#{v}"), v] }
options_for_select(opts, selected)
Expand Down
65 changes: 65 additions & 0 deletions app/views/podcast_player/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<%= turbo_frame_tag "embed-player", data: {controller: "morphdom"} do %>

<div class="col-12 mb-4">
<div class="form-floating input-group" data-controller="dynamic-form">
<%= select_tag :embed_player_type, embed_player_type_options(player_options[:embed_player_type]), class: "form-control", data: {action: "dynamic-form#change"} %>
<%= label_tag :embed_player_style, t("helpers.label.episode.embed_player_type") %>
<a hidden href="<%= request.fullpath %>" data-dynamic-form-target="link"></a>
</div>

<div class="form-text">
<%= t(".help.types.#{player_options[:embed_player_type] || "card"}") %>
</div>
</div>

<div class="col-12 mb-4" data-controller="toggle-field">
<div class="mb-4">
<div class="form-check">
<%= check_box_tag :playlist, "1", true, data: {toggle_field_target: "check", action: "toggle-field#toggleDisplay"}, class: "form-check-input" %>
<%= label_tag :playlist %>
</div>
</div>

<div class="" data-toggle-field-target="field">
<div class="form-floating input-group" data-controller="dynamic-form">
<%= number_field_tag :episode_number, player_options[:episode_number], class: "form-control", data: {action: "dynamic-form#change"}, min: 1 %>
<%= label_tag "Number of Episodes" %>
<a hidden href="<%= request.fullpath %>" data-dynamic-form-target="link"></a>
</div>

<div class="form-check">
<%= check_box_tag :season, nil, false %>
<%= label_tag :season, "Play a single season" %>
</div>

<div class="form-check">
<%= check_box_tag :category, nil, false %>
<%= label_tag :category, "Play a single category" %>
</div>

<div class="form-check">
<%= check_box_tag :recent, nil, false %>
<%= label_tag :recent, "Play the most recent episode" %>
</div>
</div>
</div>

<div class="col-12 mb-4">
<div class="form-floating input-group">

</div>
</div>

<div class="col-12 mb-4">
<div class="form-floating input-group">

</div>
</div>

<div class="col-12 mb-4">
<h3 class="fw-bold"><%= t(".title.preview") %></h3>

<%= embed_player_podcast_iframe(podcast, true, player_options) %>
</div>

<% end %>
10 changes: 9 additions & 1 deletion app/views/podcast_player/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
<%= render "podcasts/tabs" %>

podcast player
<div class="row my-4 mx-2">
<div class="col-lg-8">
<div class="row">
<%= render "form", podcast: @podcast, player_options: @player_options %>
</div>
</div>
<div class="col-lg-4 d-grid align-content-start gap-3">
</div>
</div>

0 comments on commit 60b0d36

Please sign in to comment.