Skip to content

Commit

Permalink
Episode media status indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed Aug 8, 2023
1 parent 79b14c4 commit 1d23d80
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 26 deletions.
6 changes: 6 additions & 0 deletions app/controllers/episode_media_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ def show
@episode.valid?
end

# GET /episodes/1/media/status
def status
authorize @episode, :show?
render :status, layout: false
end

# PATCH/PUT /episodes/1/media
def update
authorize @episode, :update?
Expand Down
29 changes: 9 additions & 20 deletions app/helpers/episodes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,17 @@ def episode_status_class(episode)
end
end

def episode_media_badge(episode)
def episode_media_status(episode)
all_media = episode.media.append(episode.uncut).compact

status =
if all_media.any? { |m| upload_problem?(m) }
"error"
elsif all_media.any? { |m| upload_processing?(m) }
"processing"
elsif episode.media_ready?(true)
"complete"
else
"incomplete"
end

label = I18n.t("helpers.label.episode.media_statuses.#{status}")

tag.span class: "badge rounded-pill prx-badge-#{status}" do
if status == "processing"
safe_concat(label + " " + tag.span(class: "spinner-border"))
else
label
end
if all_media.any? { |m| upload_problem?(m) }
"error"
elsif all_media.any? { |m| upload_processing?(m) }
"processing"
elsif episode.media_ready?(true)
"complete"
else
"incomplete"
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/episode_media/_form_uncut.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="card-header card-header-info d-flex justify-content-between">
<h2 class="card-title h5"><%= t(".title.media") %></h2>
</div>
<div class="card-body pb-0" data-morph="false">
<div class="card-body pb-0">
<%= render "episode_media/media/media", form: fields, episode: episode, media: fields.object %>
</div>
</div>
Expand Down
15 changes: 15 additions & 0 deletions app/views/episode_media/_tab.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%= turbo_frame_tag "episode-media-status", data: {controller: "morphdom"} do %>
<% status = episode_media_status(episode) %>
<%= tab_link_to episode_media_path(episode), active: /media/, data: {turbo_frame: "_top"} do %>
<%= t("episodes.tabs.media") %>
<span class="badge rounded-pill prx-badge-<%= status %>">
<%= t("helpers.label.episode.media_statuses.#{status}") %>
<% if status == "processing" %><span class="spinner-border"></span><% end %>
</span>
<% end %>
<% if status == "processing" %>
<%= link_to "", episode_media_status_path(episode), class: "d-none", data: {controller: "polling", polling_debounce_value: 3000} %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/episode_media/media/_new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="col-12 mb-4" data-controller="upload" data-upload-disable-outlet="form">
<div class="col-12 mb-4" data-controller="upload" data-upload-disable-outlet="form" data-morph="false">

<%# step 0: destroying media (will be nulled out if we actually replace it) %>
<%= form.hidden_field :id, data: {upload_target: "replace"} %>
Expand Down
1 change: 1 addition & 0 deletions app/views/episode_media/status.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render "tab", episode: @episode %>
5 changes: 1 addition & 4 deletions app/views/episodes/_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<% content_for :tabs do %>
<div class="list-group d-flex col">
<% if @episode.persisted? %>
<!-- TODO: Change to show episode title instead of Metadata -->
<%= tab_link_to @episode.title, edit_episode_path(@episode), class: "text-truncate", active: episode_metadata_active? %>
<%= tab_link_to episode_media_path(@episode) do %>
<%= t(".media") %><%= episode_media_badge(@episode) %>
<% end %>
<%= render "episode_media/tab", episode: @episode %>
<%= tab_link_to t(".player"), episode_player_path(@episode) %>
<% else %>
<%= tab_link_to t(".new"), new_podcast_episode_path(@podcast), active: true %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

resources :episodes, except: [:create, :new] do
resource :media, only: [:show, :update], controller: :episode_media
get "media_status", to: "episode_media#status"
resource :player, only: :show, controller: :episode_player
end

Expand Down

0 comments on commit 1d23d80

Please sign in to comment.