Skip to content

Commit

Permalink
Add itunes categories to feed overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed Aug 9, 2023
1 parent 6a32f9f commit a6cad16
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
7 changes: 5 additions & 2 deletions app/controllers/feeds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def new
@feed = @podcast.feeds.new(private: false, slug: "")
authorize @feed

@feed.assign_attributes(feed_params)
@feed.clear_attribute_changes(%i[file_name podcast_id private slug])
end

Expand Down Expand Up @@ -106,6 +107,10 @@ def nilified_feed_params
:title,
:subtitle,
:description,
:itunes_category,
:itunes_subcategory,
:include_donation_url,
:include_podcast_value,
:private,
:url,
:new_feed_url,
Expand All @@ -122,8 +127,6 @@ def nilified_feed_params
:house,
:paid,
:sonic_id,
:include_donation_url,
:include_podcast_value,
include_tags: [],
feed_tokens_attributes: %i[id label token _destroy],
feed_images_attributes: %i[id original_url size alt_text caption credit _destroy _retry],
Expand Down
56 changes: 40 additions & 16 deletions app/views/feeds/_form_overrides.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,46 @@

<div class="card-body">
<div class="row">
<div class="col-12 mb-4">
<div class="form-floating input-group">
<%= form.text_field :subtitle %>
<%= form.label :subtitle %>
<%= field_help_text t(".help.subtitle") %>
</div>
</div>

<div class="col-12 mb-4">
<div class="form-floating input-group">
<%= form.trix_editor :description %>
<%= form.label :description %>
<%= field_help_text t(".help.description") %>
</div>
</div>

<div class="col-lg-6 mb-4">
<div class="form-floating input-group" data-controller="dynamic-form">
<%# HACK: display nested validation errors %>
<% nested_errors = feed.errors.full_messages_for("itunes_categories.name").join(", ") %>
<% klass = nested_errors.present? ? "is-invalid form-select" : "form-select" %>
<%= form.select :itunes_category, itunes_category_options, {include_blank: true}, class: klass, data: {action: "dynamic-form#change"} %>
<% if nested_errors.present? %><div class="invalid-feedback"><%= nested_errors %></div><% end %>
<%= form.label :itunes_category %>
<%= field_help_text t(".help.itunes_category") %>
<%# update subcategory turbo-frame when category changes %>
<a hidden href="<%= new_podcast_feed_path(podcast) %>" data-dynamic-form-target="link" data-turbo-frame="itunes-subcategory"></a>
</div>
</div>

<div class="col-lg-6 mb-4">
<%= turbo_frame_tag "itunes-subcategory" do %>
<div class="form-floating">
<% opts = itunes_subcategory_options(feed.itunes_category) %>
<%= form.select :itunes_subcategory, opts, {include_blank: true}, disabled: opts.blank? %>
<%= form.label :itunes_subcategory %>
</div>
<% end %>
</div>

<div class="col-lg-6 mb-4">
<div class="form-check">
<%= form.check_box :include_donation_url %>
Expand All @@ -26,22 +66,6 @@
</div>
</div>
</div>

<div class="mb-4">
<div class="form-floating input-group">
<%= form.text_field :subtitle %>
<%= form.label :subtitle %>
<%= field_help_text t(".help.subtitle") %>
</div>
</div>

<div>
<div class="form-floating input-group">
<%= form.trix_editor :description %>
<%= form.label :description %>
<%= field_help_text t(".help.description") %>
</div>
</div>
</div>
</div>
</div>

0 comments on commit a6cad16

Please sign in to comment.