Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DAM-001] fixed digital assets due to latest merges in admin #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/spree/admin/digital_assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def index

def create
@object.assign_attributes(permitted_resource_params)
@object.position = 1
if @object.save
render layout: false
else
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/spree/admin/base_helper_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def asset_details(digital_asset)
def related_products(digital_asset)
products = {}
digital_asset.assets.each do |asset|
product = asset.viewable.product
products[product.id] = { slug: product.slug, name: product.name }
product = asset.viewable.product if asset.viewable.present?
products[product.id] = { slug: product.slug, name: product.name } if product.present?
end
products.values
end
Expand Down
17 changes: 13 additions & 4 deletions app/models/spree/digital_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,30 @@
SUPPORTED_IMAGES_REGEX = Regexp.new('\A(' + SUPPORTED_IMAGE_FORMATS.join('|') + ')\Z')

module Spree
class DigitalAsset < Spree::Base
class DigitalAsset < Asset

self.table_name = "spree_digital_assets"

belongs_to :folder
has_many :assets

has_attached_file :attachment, styles: { small: '100x100>' },
has_attached_file :attachment,
styles: { mini: '48x48>', small: '100x100>', product: '240x240>', large: '600x600>' },
default_style: :product,
default_url: 'noimage/:style.png',
url: '/spree/digital_assets/:id/:style/:basename.:extension',
path: ':rails_root/public/spree/digital_assets/:id/:style/:basename.:extension'
path: ':rails_root/public/spree/digital_assets/:id/:style/:basename.:extension',
convert_options: { all: '-strip -auto-orient -colorspace sRGB' }

do_not_validate_attachment_file_type :attachment

validates :name, :attachment, :folder, presence: true

before_post_process :image?
before_validation :assign_default_name, on: :create


attr_accessor :position

private
def image?
(attachment_content_type =~ SUPPORTED_IMAGES_REGEX).present?
Expand Down