-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Product_properties#index - use prebuilt action
- Loading branch information
1 parent
d41645f
commit 38e7ebe
Showing
5 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
app/models/spree/admin/actions/product_properties_default_actions_builder.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,55 @@ | ||
module Spree | ||
module Admin | ||
module Actions | ||
class ProductPropertiesDefaultActionsBuilder | ||
include Spree::Core::Engine.routes.url_helpers | ||
|
||
def build | ||
root = Root.new | ||
add_select_from_prototype_action(root) | ||
add_add_product_properties_action(root) | ||
root | ||
end | ||
|
||
private | ||
|
||
def add_select_from_prototype_action(root) | ||
action = | ||
ActionBuilder.new(select_from_prototype_config). | ||
build | ||
|
||
root.add(action) | ||
end | ||
|
||
def select_from_prototype_config | ||
{ | ||
icon_name: 'list.svg', | ||
key: :select_from_prototype, | ||
url: available_admin_prototypes_path, | ||
classes: 'btn-light js-new-ptype-link', | ||
data: { update: 'prototypes', remote: true } | ||
} | ||
end | ||
|
||
def add_add_product_properties_action(root) | ||
action = | ||
ActionBuilder.new(add_product_properties_config). | ||
with_create_ability_check(::Spree::ProductProperty). | ||
build | ||
|
||
root.add(action) | ||
end | ||
|
||
def add_product_properties_config | ||
{ | ||
icon_name: 'add.svg', | ||
key: :add_product_properties, | ||
url: 'javascript:;', | ||
classes: 'btn-success spree_add_fields', | ||
data: { target: 'tbody#sortVert'} | ||
} | ||
end | ||
end | ||
end | ||
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
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
21 changes: 21 additions & 0 deletions
21
spec/models/spree/admin/actions/product_properties_default_actions_builder_spec.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,21 @@ | ||
require 'spec_helper' | ||
|
||
module Spree | ||
module Admin | ||
describe Actions::ProductPropertiesDefaultActionsBuilder, type: :model do | ||
let(:builder) { described_class.new } | ||
let(:default_actions) do | ||
[:select_from_prototype | ||
"javascript:;"] | ||
end | ||
|
||
describe '#build' do | ||
subject { builder.build } | ||
|
||
it 'builds default tabs' do | ||
expect(subject.items.map(&:key)).to match(default_actions) | ||
end | ||
end | ||
end | ||
end | ||
end |