diff --git a/app/controllers/episode_media_controller.rb b/app/controllers/episode_media_controller.rb index e46ecdee7..fb33e151f 100644 --- a/app/controllers/episode_media_controller.rb +++ b/app/controllers/episode_media_controller.rb @@ -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? diff --git a/app/helpers/episodes_helper.rb b/app/helpers/episodes_helper.rb index 3326846c3..63551fb44 100644 --- a/app/helpers/episodes_helper.rb +++ b/app/helpers/episodes_helper.rb @@ -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 diff --git a/app/views/episode_media/_form_uncut.html.erb b/app/views/episode_media/_form_uncut.html.erb index bbd5476fc..524c027fd 100644 --- a/app/views/episode_media/_form_uncut.html.erb +++ b/app/views/episode_media/_form_uncut.html.erb @@ -6,7 +6,7 @@

<%= t(".title.media") %>

-
+
<%= render "episode_media/media/media", form: fields, episode: episode, media: fields.object %>
diff --git a/app/views/episode_media/_tab.html.erb b/app/views/episode_media/_tab.html.erb new file mode 100644 index 000000000..41776de7b --- /dev/null +++ b/app/views/episode_media/_tab.html.erb @@ -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") %> + + <%= t("helpers.label.episode.media_statuses.#{status}") %> + <% if status == "processing" %><% end %> + + <% end %> + + <% if status == "processing" %> + <%= link_to "", episode_media_status_path(episode), class: "d-none", data: {controller: "polling", polling_debounce_value: 3000} %> + <% end %> +<% end %> diff --git a/app/views/episode_media/media/_new.html.erb b/app/views/episode_media/media/_new.html.erb index 429d637de..5ec2c8de7 100644 --- a/app/views/episode_media/media/_new.html.erb +++ b/app/views/episode_media/media/_new.html.erb @@ -1,4 +1,4 @@ -
+
<%# step 0: destroying media (will be nulled out if we actually replace it) %> <%= form.hidden_field :id, data: {upload_target: "replace"} %> diff --git a/app/views/episode_media/status.html.erb b/app/views/episode_media/status.html.erb new file mode 100644 index 000000000..601725a4c --- /dev/null +++ b/app/views/episode_media/status.html.erb @@ -0,0 +1 @@ +<%= render "tab", episode: @episode %> diff --git a/app/views/episodes/_tabs.html.erb b/app/views/episodes/_tabs.html.erb index 090fc93e7..90c38a857 100644 --- a/app/views/episodes/_tabs.html.erb +++ b/app/views/episodes/_tabs.html.erb @@ -1,11 +1,8 @@ <% content_for :tabs do %>
<% if @episode.persisted? %> - <%= 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 %> diff --git a/config/routes.rb b/config/routes.rb index 76c850255..43c22745e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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