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

upgrade to spree 4-1 #45

Open
wants to merge 5 commits 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
13 changes: 4 additions & 9 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
appraise 'spree-3-2' do
gem 'spree', '~> 3.2.0'
appraise 'spree-4-0' do
gem 'spree', '~> 4.0'
gem 'rails-controller-testing', '~> 1.0.1'
end

appraise 'spree-3-3' do
gem 'spree', '~> 3.3.0'
gem 'rails-controller-testing', '~> 1.0.1'
end

appraise 'spree-3-4' do
gem 'spree', '~> 3.4.0'
appraise 'spree-4-1' do
gem 'spree', '~> 4.1'
gem 'rails-controller-testing', '~> 1.0.1'
end

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Try Spree Digital Assets for Spree Master with direct deployment on Heroku:

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/vinsol-spree-contrib/spree-demo-heroku/tree/spree-digital-assets-master)

Try Spree Digital Assets for Spree 4.0 and later with direct deployment on Heroku:

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/vinsol-spree-contrib/spree-demo-heroku/tree/spree-digital-assets-4-1)

Try Spree Digital Assets for Spree 3-4 with direct deployment on Heroku:

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/vinsol-spree-contrib/spree-demo-heroku/tree/spree-digital-assets)
Expand Down Expand Up @@ -114,7 +118,7 @@ For more features or usage manual go [here](http://vinsol.com/spreecommerce-digi
## See It In Action

<a href="http://www.youtube.com/watch?feature=player_embedded&v=bIdsZgUzfs0
" target="_blank"><img src="http://img.youtube.com/vi/bIdsZgUzfs0/0.jpg"
" target="_blank"><img src="http://img.youtube.com/vi/bIdsZgUzfs0/0.jpg"
alt="Youtube Video Tutorial" /></a>

## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
.tree-menu-container .tree-menu > li .link {
display: block;
padding: 10px 15px 10px 30px;
padding: 10px 66px 17px 30px;
}

.tree-menu-container .tree-menu > li > .toggle_list_menu {
Expand Down Expand Up @@ -403,3 +403,18 @@ li.active .link.sidebar-default-font {
.upload-assets-uploader-status .fail {
color: #ff0000;
}
.hidden, .hide{
display: none;
}

#sidebar-assets > li {
width: 100%;
}
.delete-folder {
border: none;
background: none;
color: #36729f;
padding: 0px;
}


33 changes: 20 additions & 13 deletions app/controllers/spree/admin/images_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
Spree::Admin::ImagesController.class_eval do
before_action :load_folder_and_digital_assets, only: [:new, :edit, :create, :update]
before_action :assign_image_attributes, only: :update

def create
invoke_callbacks(:create, :before)
# checking whether the asset is an supported image format.
if SUPPORTED_IMAGE_FORMATS.include? Spree::DigitalAsset.find_by(id: permitted_resource_params[:digital_asset_id]).try(:attachment_content_type)
@object.attributes = permitted_resource_params
end
if @object.save
invoke_callbacks(:create, :after)
flash[:success] = flash_message_for(@object, :successfully_created)
def update
invoke_callbacks(:update, :before)
if [email protected]? && @object.save
invoke_callbacks(:update, :after)
respond_with(@object) do |format|
format.html { redirect_to location_after_save }
format.js { render layout: false }
format.html do
flash[:success] = flash_message_for(@object, :successfully_updated)
redirect_to location_after_save
end
format.js { render layout: false }
end
else
invoke_callbacks(:create, :fails)
invoke_callbacks(:update, :fails)
respond_with(@object) do |format|
format.html { render action: :new }
format.html { render action: :edit }
format.js { render layout: false }
end
end
Expand All @@ -28,4 +27,12 @@ def load_folder_and_digital_assets
@folders = Spree::Folder.all
@digital_assets = Spree::DigitalAsset.approved.page(params[:page])
end

def assign_image_attributes
if SUPPORTED_IMAGE_FORMATS.include? Spree::DigitalAsset.find_by(id: permitted_resource_params[:digital_asset_id]).try(:attachment).try(:content_type)
@object.attributes = permitted_resource_params
else
@object.errors.add(:attachment, :not_allowed_content_type)
end
end
end
12 changes: 6 additions & 6 deletions app/helpers/spree/admin/base_helper_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ def folder_link(folder, options)

def delete_folder_link(folder, options)
if folder.persisted?
link_to 'Delete', admin_folder_path(folder), options
button_to 'Delete', admin_folder_path(folder), options
else
link_to 'Delete', '', options
button_to 'Delete', '', options
end
end

def asset_details(digital_asset)
{
{
id: digital_asset.id,
name: digital_asset.name,
size: number_to_human_size(digital_asset.attachment_file_size),
created_on: digital_asset.created_at.to_date.to_formatted_s(:long),
modified_on: digital_asset.updated_at.to_date.to_formatted_s(:long),
size: number_to_human_size(digital_asset.attachment.byte_size),
created_on: digital_asset.created_at.to_date.to_formatted_s(:long),
modified_on: digital_asset.updated_at.to_date.to_formatted_s(:long),
related_products: related_products(digital_asset)
}
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/asset_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
def build_from_digital_asset
digital_asset = Spree::DigitalAsset.approved.find_by(id: digital_asset_id)
if digital_asset.present?
self.attachment = digital_asset.attachment
self.attachment.attach(digital_asset.attachment.blob)
else
errors.add(:base, 'invalid digital asset id passed')
throw(:abort)
Expand Down
12 changes: 4 additions & 8 deletions app/models/spree/digital_asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ class DigitalAsset < Spree::Base
belongs_to :folder
has_many :assets

has_attached_file :attachment, styles: { small: '100x100>' },
url: '/spree/digital_assets/:id/:style/:basename.:extension',
path: ':rails_root/public/spree/digital_assets/:id/:style/:basename.:extension'

do_not_validate_attachment_file_type :attachment
has_one_attached :attachment

validates :name, :attachment, :folder, presence: true
before_post_process :image?
before_save :image?
before_validation :assign_default_name, on: :create

scope :approved, -> { where(approved: true) }
Expand All @@ -29,11 +25,11 @@ def associated_products

private
def image?
(attachment_content_type =~ SUPPORTED_IMAGES_REGEX).present?
(attachment.content_type =~ SUPPORTED_IMAGES_REGEX).present?
end

def assign_default_name
self.name = File.basename(attachment_file_name.to_s, '.*').titleize.truncate(255) if name.blank?
self.name = attachment.filename.to_s.titleize.truncate(255) if name.blank?
end
end
end
4 changes: 2 additions & 2 deletions app/overrides/add_asset_list_to_side_menu.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Deface::Override.new(virtual_path: 'spree/layouts/admin',
Deface::Override.new(virtual_path: 'spree/admin/shared/_main_menu',
name: 'add_asset_list_to_side_menu',
insert_bottom: "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
insert_bottom: "nav",
partial: 'spree/admin/shared/folder_list',
original: '8d05a6b687057aa2a8c08b3feb480d58a14fe4aa')
4 changes: 2 additions & 2 deletions app/views/spree/admin/shared/_digital_asset.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="text-center asset-area <%= digital_asset.approved? ? 'approved' : 'not-approved' %>">
<div class="digital-assets-image">
<%= image_tag(digital_asset.attachment.url(:small), class: 'img-thumbnail attachment digital_asset_attachment' ,
<%= image_tag(main_app.url_for(digital_asset.attachment), class: 'img-thumbnail attachment digital_asset_attachment' ,
data: asset_details(digital_asset), onerror: "$assetDetails.showFileGlyphicon(this)") %>
<i class="glyphicon glyphicon-file file-icon hide"></i>
</div>
Expand All @@ -18,6 +18,6 @@
<%= link_to '<i class="glyphicon glyphicon-pencil"></i>'.html_safe(), spree.edit_admin_digital_asset_path(digital_asset), class: 'with-tip', data: { original_title: 'Edit' } %>
</li>
<li role="separator" class="divider"></li>
<li><%= link_to '<i class="glyphicon glyphicon-download"></i>'.html_safe(), digital_asset.attachment.url(:original, false), target: '_blank', class: 'with-tip', data: { original_title: 'Download' } %></li>
<li><%= link_to '<i class="glyphicon glyphicon-download"></i>'.html_safe(), main_app.url_for(digital_asset.attachment), target: '_blank', class: 'with-tip', data: { original_title: 'Download' } %></li>
</ul>
</div>
12 changes: 6 additions & 6 deletions app/views/spree/admin/shared/_folder_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<ul class="nav nav-sidebar" id='folder_list'>
<li class="sidebar-menu-item">
<a data-toggle="collapse" data-parent="#sidebar" href="#sidebar-assets">
<span class="icon icon-file"></span>
<ul class="nav nav-sidebar border-bottom">
<li class="sidebar-menu-item d-block w-100">
<a data-toggle="collapse" class="d-flex w-100 p-3 position-relative align-items-center collapsed" href="#sidebar-assets" aria-expanded="false">
<span class="icon icon-file mr-2"></span>
<span class="text"> Assets</span>
<span class="icon icon-chevron-left pull-right"></span>
<span class="icon position-absolute icon-chevron-left"></span>
</a>
<ul data-hook="admin_configurations_sidebar_menu" class="collapse nav nav-pills nav-stacked" id="sidebar-assets">
<ul data-hook="admin_configurations_sidebar_menu" class="border-top bg-white nav nav-pills nav-stacked collapse" id="sidebar-assets" style="">
<li>
<div class="tree-menu-container">
<%= build_nested_set_tree(Spree::Folder.all) do |folder| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/shared/_folder_list_element.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="btn-group">
<button class="btn btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<button class="btn dropdown" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="glyphicon glyphicon-option-vertical"></span>
</button>
<ul class="dropdown-menu">
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/shared/_new_folder_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Add New Folder</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
</div>
<%= form_for [:admin, Spree::Folder.new], html: { multipart: true, class: 'form-horizontal', id: 'new_folder_form' }, remote: true, authenticity_token: true do |f| %>
<div class="modal-body">
Expand Down
1 change: 0 additions & 1 deletion db/migrate/20160223071609_create_spree_digital_assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class CreateSpreeDigitalAssets < SpreeExtension::Migration[4.2]
def change
create_table :spree_digital_assets do |t|
t.string :name
t.attachment :attachment
t.references :folder

t.timestamps null: false
Expand Down
9 changes: 0 additions & 9 deletions gemfiles/spree_3_4.gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/spree_3_2.gemfile → gemfiles/spree_4_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "spree", "~> 3.2.0"
gem "spree", "~> 4.0"
gem "spree_auth_devise", github: "spree/spree_auth_devise"
gem "rails-controller-testing", "~> 1.0.1"

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/spree_3_3.gemfile → gemfiles/spree_4_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

gem "spree", "~> 3.3.0"
gem "spree", "~> 4.1"
gem "spree_auth_devise", github: "spree/spree_auth_devise"
gem "rails-controller-testing", "~> 1.0.1"

Expand Down
6 changes: 3 additions & 3 deletions spree_digital_assets.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency 'spree_core', '>= 3.2.0', '< 4.0'
s.add_dependency 'spree_core', '>= 4.0'
s.add_dependency 'spree_extension'
s.add_dependency 'remotipart'
s.add_dependency 'remotipart', '~> 1.0', '>= 1.0.5'
s.add_dependency 'jquery-fileupload-rails', '~> 0.4.6'

s.add_development_dependency 'appraisal'
s.add_development_dependency 'capybara', '~> 2.5'
s.add_development_dependency 'coffee-rails'
s.add_development_dependency 'database_cleaner'
s.add_development_dependency 'factory_girl', '~> 4.5'
s.add_development_dependency 'ffaker', '~> 2.2.0'
s.add_development_dependency 'ffaker', '~> 2.9.0'
s.add_development_dependency 'rails-controller-testing'
s.add_development_dependency 'rspec-activemodel-mocks'
s.add_development_dependency 'rspec-rails', '~> 3.4'
Expand Down