Skip to content

Commit 7ce9308

Browse files
authored
Merge pull request #4755 from manyfold3d/remove-attachments
Add form option to remove avatar and banner images
2 parents 89b1751 + 6ba2e23 commit 7ce9308

File tree

5 files changed

+15
-4
lines changed

5 files changed

+15
-4
lines changed

app/deserializers/form/creator_deserializer.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ def deserialize
1010
:indexable,
1111
:ai_indexable,
1212
:avatar,
13+
:remove_avatar,
1314
:banner,
15+
:remove_banner,
1416
links_attributes: [:id, :url, :_destroy]
1517
).deep_merge(caber_relations_params(type: :creator))
1618
end

app/helpers/application_helper.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,18 @@ def file_input_row(form, name, options = {})
210210
form.label(name, options[:label], class: "col-auto col-form-label"),
211211
content_tag(:div, class: "col p-0") do
212212
safe_join [
213-
form.file_field(name, {class: "form-control"}.merge(options)),
213+
content_tag(:div, class: "input-group") do
214+
safe_join [
215+
form.file_field(name, class: "form-control"),
216+
options[:remove] ? form.check_box(:"remove_#{name}", class: "btn-check", autocomplete: "off") : nil,
217+
options[:remove] ? form.label(:"remove_#{name}", icon("trash", options[:remove_label]), class: "btn btn-outline-danger") : nil
218+
].compact
219+
end,
214220
errors_for(form.object, name),
215221
(options[:help] ? content_tag(:span, class: "form-text") { options[:help] } : nil)
216222
].compact
217223
end
218-
]
224+
].compact
219225
end
220226
end
221227

app/uploaders/application_uploader.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ApplicationUploader < Shrine
1818
plugin :remote_url, max_size: SiteSettings.max_file_upload_size
1919
plugin :infer_extension
2020
plugin :derivatives
21+
plugin :remove_attachment
2122

2223
self.storages = {
2324
cache: Shrine::Storage::FileSystem.new("tmp/shrine"),

app/views/creators/_form.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<%= rich_text_input_row form, :notes, help: t(".notes.help_html") %>
1010
<%= select_input_row form, :indexable, indexable_select_options(form.object) %>
1111
<%= select_input_row form, :ai_indexable, ai_indexable_select_options(form.object) if SiteSettings.allow_ai_bots %>
12-
<%= file_input_row form, :avatar, help: "#{t(".avatar.help")} #{@creator.avatar ? t(".avatar.current", filename: @creator.avatar.metadata["filename"]) : t(".avatar.none")}" %>
13-
<%= file_input_row form, :banner, help: "#{t(".banner.help")} #{@creator.banner ? t(".banner.current", filename: @creator.banner.metadata["filename"]) : t(".banner.none")}" %>
12+
<%= file_input_row form, :avatar, help: "#{t(".avatar.help")} #{@creator.avatar ? t(".avatar.current", filename: @creator.avatar.metadata["filename"]) : t(".avatar.none")}", remove: @creator.avatar.present?, remove_label: t(".avatar.remove") %>
13+
<%= file_input_row form, :banner, help: "#{t(".banner.help")} #{@creator.banner ? t(".banner.current", filename: @creator.banner.metadata["filename"]) : t(".banner.none")}", remove: @creator.banner.present?, remove_label: t(".banner.remove") %>
1414
<%= render "caber_relations_form", form: form %>
1515
<%= form.submit translate("general.save"), class: "btn btn-primary float-start" %>
1616
<% end %>

config/locales/creators/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ en:
2222
current: Currently using `%{filename}`.
2323
help: A square profile image around 256x256px, in WEBP, PNG, GIF or JPG format.
2424
none: Not currently set.
25+
remove: Remove avatar
2526
banner:
2627
current: Currently using `%{filename}`.
2728
help: A background image around 1000x200px, in WEBP, PNG, GIF or JPG format.
2829
none: Not currently set.
30+
remove: Remove banner
2931
notes:
3032
help_html: You can use <a href="https://www.markdownguide.org/cheat-sheet/" target="markdown">Markdown</a>.
3133
slug:

0 commit comments

Comments
 (0)