-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8eaf852
commit 7c805c2
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
backend/app/controllers/spree/admin/taxonomy/attachment_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
module Spree | ||
module Admin | ||
module Taxonomies | ||
class AttachmentController < Spree::Admin::BaseController | ||
def destroy | ||
taxonomy = Spree::Taxonomy.find(params[:taxonomy_id]) | ||
taxon = taxonomy.taxons.find(params[:taxon_id]) | ||
if taxon.destroy_attachment(params[:attachment_definition]) | ||
flash[:success] = t('spree.successfully_removed', resource: params[:attachment_definition].titleize) | ||
else | ||
flash[:error] = t('spree.taxon_attachment_removal_error') | ||
end | ||
redirect_to edit_admin_taxonomy_taxon_path(taxonomy, taxon.id) | ||
end | ||
end | ||
end | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
core/app/models/spree/taxonomy/active_storage_attachment.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module Spree::Taxonomy::ActiveStorageAttachment | ||
extend ActiveSupport::Concern | ||
include Spree::ActiveStorageAdapter | ||
|
||
included do | ||
has_attachment :icon, | ||
styles: Spree::Config.taxon_image_styles, | ||
default_style: Spree::Config.taxon_image_style_default | ||
validate :icon_is_an_image | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module Spree::Taxonomy::PaperclipAttachment | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
has_attached_file :icon, | ||
styles: Spree::Config.taxon_image_styles, | ||
default_style: Spree::Config.taxon_image_style_default, | ||
url: '/spree/taxonomies/:id/:style/:basename.:extension', | ||
path: ':rails_root/public/spree/taxonomies/:id/:style/:basename.:extension', | ||
default_url: '/assets/default_taxon.png' | ||
|
||
validates_attachment :icon, | ||
content_type: { content_type: Spree::Config.allowed_image_mime_types } | ||
end | ||
|
||
def icon_present? | ||
icon.present? | ||
end | ||
|
||
def destroy_attachment(definition) | ||
return false unless respond_to?(definition) | ||
|
||
attached_file = send(definition) | ||
return false unless attached_file.exists? | ||
|
||
attached_file.destroy && save | ||
end | ||
end |