Skip to content

Commit

Permalink
Merge pull request #1140 from PRX/fix/transcript_last_updated
Browse files Browse the repository at this point in the history
Fix/transcript last updated
  • Loading branch information
radical-ube authored Oct 31, 2024
2 parents a9f8b35 + 8add63c commit 722dc5e
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 38 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ PLATFORMS
arm64-darwin-21
arm64-darwin-22
arm64-darwin-23
arm64-darwin-24
x86_64-darwin-21
x86_64-darwin-22
x86_64-darwin-23
Expand Down
14 changes: 10 additions & 4 deletions app/helpers/episodes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ def episode_status_class(episode)
end

def episode_media_status(episode)
all_media = episode.media.append(episode.uncut).compact.reject(&:new_record?)

if all_media.any? { |m| upload_problem?(m) }
if episode_all_media(episode).any? { |m| upload_problem?(m) }
"error"
elsif all_media.any? { |m| upload_processing?(m) }
elsif episode_all_media(episode).any? { |m| upload_processing?(m) }
"processing"
elsif episode.media_ready?(true)
"complete"
Expand Down Expand Up @@ -119,6 +117,14 @@ def episode_medium_options
Episode.mediums.keys.map { |k| [I18n.t("helpers.label.episode.mediums.#{k}"), k] }
end

def episode_media_updated_at(episode)
episode_all_media(episode).maximum(:updated_at)
end

def episode_all_media(episode)
episode.media.append(episode.uncut).compact.reject(&:new_record?)
end

def episode_category_button_class(episode, value)
if episode.categories.include?(value)
"btn-primary"
Expand Down
2 changes: 1 addition & 1 deletion app/models/transcript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Transcript < ApplicationRecord

acts_as_paranoid

belongs_to :episode
belongs_to :episode, -> { with_deleted }, touch: true, optional: true

has_one :task, -> { order("id desc") }, as: :owner
has_many :tasks, as: :owner
Expand Down
4 changes: 3 additions & 1 deletion app/views/episode_media/_form_status.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
<%= form.submit t(".update"), class: "btn btn-primary", data: data %>
<% end %>
</div>
<p class="status-text mt-2 mb-0 text-end"><strong><%= t(".updated_at_hint") %>:</strong> <%= l(episode.updated_at) %></p>
<% if episode_media_updated_at(episode).present? %>
<p class="status-text mt-2 mb-0 text-end"><strong><%= t(".updated_at_hint") %>:</strong> <%= local_time_ago(episode_media_updated_at(episode)) %></p>
<% end %>
</div>
</div>

Expand Down
25 changes: 15 additions & 10 deletions app/views/episode_transcripts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@
<%= form.submit class: "d-none" %>
<%= turbo_frame_tag "episode-form-transcript", data: {controller: "media-upload"} do %>
<div class="container">
<div class="row mt-4 mx-2">
<div class="col-lg-8">
<div class="row">
<%= render "form_transcript", episode: episode, form: form %>
<%= render "form_main", episode: episode, form: form %>
<% episode.build_transcript if episode.transcript.blank? %>
<% episode.transcript.clear_attribute_changes(%i[format]) %>
<%= form.fields_for :transcript do |fields| %>
<div class="container">
<div class="row mt-4 mx-2">
<div class="col-lg-8">
<div class="row">
<%= render "form_transcript", episode: episode, fields: fields %>
<%= render "form_main", fields: fields %>
</div>
</div>
<div class="col-lg-4 d-grid align-content-start gap-3">
<%= render "form_status", episode: episode, form: form %>
</div>
</div>
<div class="col-lg-4 d-grid align-content-start gap-3">
<%= render "form_status", episode: episode, form: form %>
</div>
</div>
</div>
<% end %>
<% end %>
<%= render "layouts/stale_record_modal", form: form, discard_path: episode_transcripts_path(episode) %>
Expand Down
14 changes: 6 additions & 8 deletions app/views/episode_transcripts/_form_main.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<%= form.fields_for :transcript, episode.transcript, include_id: false do |fields| %>
<div class="col-12 mb-4">
<div class="form-floating input-group">
<%= fields.select :format, episode_transcript_options, {} %>
<%= fields.label :format, required: true %>
<%= field_help_text t(".help.transcript") %>
</div>
<div class="col-12 mb-4">
<div class="form-floating input-group">
<%= fields.select :format, episode_transcript_options, {} %>
<%= fields.label :format, required: true %>
<%= field_help_text t(".help.transcript") %>
</div>
<% end %>
</div>
4 changes: 3 additions & 1 deletion app/views/episode_transcripts/_form_status.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<%= form.submit t(".update"), class: "btn btn-primary", data: data %>
<% end %>
</div>
<p class="status-text mt-2 mb-0 text-end"><strong><%= t(".updated_at_hint") %>:</strong> <%= l(episode.updated_at) %></p>
<% if episode.transcript.persisted? %>
<p class="status-text mt-2 mb-0 text-end"><strong><%= t(".updated_at_hint") %>:</strong> <%= local_time_ago(episode.transcript.updated_at) %></p>
<% end %>
</div>
</div>
11 changes: 3 additions & 8 deletions app/views/episode_transcripts/_form_transcript.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<div class="prx-uploads col-12 mb-2">
<%= turbo_frame_tag "episode-media-form-transcript", data: {controller: "morphdom"} do %>
<% episode.build_transcript if episode.transcript.blank? %>
<% episode.transcript.clear_attribute_changes(%i[format]) %>
<% path = episode_transcripts_path(episode, uploads_destroy_params(fields)) %>
<% rpath = episode_transcripts_path(episode, uploads_retry_params(fields)) %>
<%= form.fields_for :transcript do |fields| %>
<% path = episode_transcripts_path(episode, uploads_destroy_params(fields)) %>
<% rpath = episode_transcripts_path(episode, uploads_retry_params(fields)) %>
<%= render "episode_transcripts/transcripts/form", form: fields, transcript: fields.object, delete_path: path, retry_path: rpath %>
<% end %>
<%= render "episode_transcripts/transcripts/form", form: fields, transcript: fields.object, delete_path: path, retry_path: rpath %>
<% end %>
</div>
5 changes: 0 additions & 5 deletions test/models/transcript_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
assert transcript.valid?
end

it "must belong to an episode" do
transcript.episode = nil
refute transcript.valid?
end

it "requires an original_url" do
transcript.original_url = nil
refute transcript.valid?
Expand Down

0 comments on commit 722dc5e

Please sign in to comment.