solidus_taxon_group 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.hound.yml +21 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.md +2 -0
- data/CONTRIBUTING.md +83 -0
- data/Gemfile +5 -0
- data/Guardfile +9 -0
- data/LICENSE.md +26 -0
- data/README.md +52 -0
- data/Rakefile +21 -0
- data/app/controllers/spree/admin/taxon_groups_controller.rb +46 -0
- data/app/models/spree/taxon_decorator.rb +4 -0
- data/app/models/spree/taxon_group.rb +9 -0
- data/app/models/spree/taxon_group_membership.rb +10 -0
- data/app/overrides/add_taxon_groups_under_taxon_in_products_in_admin_sidebar_menu.rb +6 -0
- data/app/views/spree/admin/taxon_groups/_form.html.erb +64 -0
- data/app/views/spree/admin/taxon_groups/_form_positions.html.erb +56 -0
- data/app/views/spree/admin/taxon_groups/_list.html.erb +29 -0
- data/app/views/spree/admin/taxon_groups/edit.html.erb +5 -0
- data/app/views/spree/admin/taxon_groups/index.html.erb +18 -0
- data/app/views/spree/admin/taxon_groups/new.html.erb +5 -0
- data/app/views/spree/admin/taxon_groups/positions.html.erb +5 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +21 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20160120200344_create_spree_taxon_groups.rb +12 -0
- data/db/migrate/20160120200408_create_spree_taxon_group_memberships.rb +12 -0
- data/db/migrate/20160120200431_add_position_to_spree_taxon_group_membership.rb +5 -0
- data/db/migrate/20160120200448_add_key_to_spree_taxon_group.rb +5 -0
- data/db/migrate/20160120200504_update_keys_where_nil_for_spree_taxon_group.rb +7 -0
- data/lib/generators/solidus_taxon_group/install/install_generator.rb +28 -0
- data/lib/solidus_taxon_group.rb +2 -0
- data/lib/solidus_taxon_group/engine.rb +15 -0
- data/lib/solidus_taxon_group/version.rb +17 -0
- data/solidus_taxon_group.gemspec +26 -0
- data/spec/models/spree/taxon_group_spec.rb +5 -0
- data/spec/spec_helper.rb +93 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99ab77d9aa5a12d4d10297d86070b5121b843e0b
|
4
|
+
data.tar.gz: 5f127728bbe0aaf6bd5ffa3e83f5e26314e4f044
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ca28b24d09b47ce2e036e691be6570400d802e1964ca68c972c61dcaae2cd8392c55abfc35f140250d117a221eaee281f9518ee3cad6492826594450bedbf2a
|
7
|
+
data.tar.gz: 5650d1b7f361ee290203f8aaa400a0b1291d4a2eeab8067507f285603306075e391f59a5f3232395107aacb017c1423dae3f94878e316cc773ffb755a3980766
|
data/.gitignore
ADDED
data/.hound.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
# Too picky.
|
3
|
+
LineLength:
|
4
|
+
Enabled: false
|
5
|
+
|
6
|
+
# This should truly be on for well documented gems.
|
7
|
+
Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
# Neatly aligned code is to swell.
|
11
|
+
SingleSpaceBeforeFirstArg:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
# Don't mess with RSpec DSL.
|
15
|
+
Blocks:
|
16
|
+
Exclude:
|
17
|
+
- 'spec/**/*'
|
18
|
+
|
19
|
+
# Avoid contradictory style rules by enforce single quotes.
|
20
|
+
StringLiterals:
|
21
|
+
EnforcedStyle: single_quotes
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
*(Originally copied from [Spree Static Content's Contribution guidelines](https://github.com/spree-contrib/spree_static_content/blob/master/CONTRIBUTING.md)*
|
4
|
+
|
5
|
+
Solidus Taxon Group is an open source project and we encourage contributions.
|
6
|
+
|
7
|
+
In the spirit of [free software][1], **everyone** is encouraged to help improve this project.
|
8
|
+
|
9
|
+
Here are some ways *you* can contribute:
|
10
|
+
|
11
|
+
* by using prerelease versions
|
12
|
+
* by reporting [bugs][2]
|
13
|
+
* by suggesting new features
|
14
|
+
* by writing [translations][3]
|
15
|
+
* by writing or editing documentation
|
16
|
+
* by writing specifications
|
17
|
+
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
|
18
|
+
* by refactoring code
|
19
|
+
* by resolving [issues][2]
|
20
|
+
* by reviewing patches
|
21
|
+
|
22
|
+
---
|
23
|
+
|
24
|
+
## Filing an issue
|
25
|
+
|
26
|
+
When filing an issue on this extension, please first do these things:
|
27
|
+
|
28
|
+
* Verify you can reproduce this issue in a brand new application.
|
29
|
+
* Run through the steps to reproduce the issue again.
|
30
|
+
|
31
|
+
In the issue itself please provide:
|
32
|
+
|
33
|
+
* A comprehensive list of steps to reproduce the issue.
|
34
|
+
* What you're *expecting* to happen compared with what's *actually* happening.
|
35
|
+
* The version of Solidus *and* the version of Rails.
|
36
|
+
* A list of all extensions.
|
37
|
+
* Any relevant stack traces ("Full trace" preferred)
|
38
|
+
* Your `Gemfile`
|
39
|
+
|
40
|
+
In 99% of cases, this information is enough to determine the cause and solution to the problem that is being described.
|
41
|
+
|
42
|
+
---
|
43
|
+
|
44
|
+
## Pull requests
|
45
|
+
|
46
|
+
We gladly accept pull requests to fix bugs and, in some circumstances, add new features to this extension.
|
47
|
+
|
48
|
+
Here's a quick guide:
|
49
|
+
|
50
|
+
1. Fork the repo.
|
51
|
+
|
52
|
+
2. Run the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate.
|
53
|
+
|
54
|
+
3. Create new branch then make changes and add tests for your changes. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need tests!
|
55
|
+
|
56
|
+
4. Push to your fork and submit a pull request. If the changes will apply cleanly to the latest stable branches and master branch, you will only need to submit one pull request.
|
57
|
+
|
58
|
+
At this point you're waiting on us. We may suggest some changes or improvements or alternatives.
|
59
|
+
|
60
|
+
Some things that will increase the chance that your pull request is accepted, taken straight from the Ruby on Rails guide:
|
61
|
+
|
62
|
+
* Use Rails idioms and helpers.
|
63
|
+
* Include tests that fail without your code, and pass with it.
|
64
|
+
* Update the documentation, the surrounding one, examples elsewhere, guides, whatever is affected by your contribution.
|
65
|
+
|
66
|
+
---
|
67
|
+
|
68
|
+
## TL;DR
|
69
|
+
|
70
|
+
* Fork the repo
|
71
|
+
* Clone your repo
|
72
|
+
* Run `bundle install`
|
73
|
+
* Run `bundle exec rake test_app` to create the test application in `spec/dummy`
|
74
|
+
* Make your changes
|
75
|
+
* Ensure specs pass by running `bundle exec rspec spec`
|
76
|
+
* Ensure all syntax ok by running `rubocop .`
|
77
|
+
* Submit your pull request
|
78
|
+
|
79
|
+
And in case we didn't emphasize it enough: **we love tests!**
|
80
|
+
|
81
|
+
[1]: http://www.fsf.org/licensing/essays/free-sw.html
|
82
|
+
[2]: https://github.com/whelton/solidus_taxon_group/issues
|
83
|
+
[3]: https://github.com/whelton/solidus_taxon_group/tree/master/config/locales
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
guard 'rspec', cmd: 'bundle exec rspec' do
|
2
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
3
|
+
watch('config/routes.rb') { 'spec/controllers' }
|
4
|
+
watch('app/controllers/application_controller.rb') { 'spec/controllers' }
|
5
|
+
watch(%r{^spec/(.+)_spec\.rb$}) { |m| "spec/#{m[1]}_spec.rb"}
|
6
|
+
watch(%r{^app/(.+)_decorator\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch(%r{^(app|lib)/(.+)(\.rb|\.erb)$}) { |m| "spec/#{m[2]}_spec.rb" }
|
8
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" }
|
9
|
+
end
|
data/LICENSE.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2016 James Whelton and contributors.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
13
|
+
endorse or promote products derived from this software without specific
|
14
|
+
prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Solidus Taxon Group
|
2
|
+
|
3
|
+
Easily create and manage groups of taxons, irrespective of their parent or children taxons/taxonomies and control the position of taxons in their taxon groups.
|
4
|
+
Useful if you need flexible taxon usage, for example a group of taxons for featured categories from different parent taxon/taxonomies.
|
5
|
+
|
6
|
+
---
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
```erb
|
11
|
+
<% navigation_taxon_group = Spree::TaxonGroup.find_by_key('navigation') %>
|
12
|
+
<% cache [I18n.locale, navigation_taxon_group] do %>
|
13
|
+
<%= navigation_taxon_group.taxons.map do |taxon|
|
14
|
+
'<li>' + link_to(taxon.name, seo_url(taxon)) + '</li>'
|
15
|
+
end.join("\n").html_safe
|
16
|
+
%>
|
17
|
+
<% end %>
|
18
|
+
```
|
19
|
+
|
20
|
+
---
|
21
|
+
|
22
|
+
## Basic Installation
|
23
|
+
|
24
|
+
Add to your `Gemfile`:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'solidus_taxon_group'
|
28
|
+
```
|
29
|
+
|
30
|
+
Run:
|
31
|
+
|
32
|
+
```sh
|
33
|
+
bundle && bundle exec rails g solidus_taxon_group:install
|
34
|
+
```
|
35
|
+
|
36
|
+
That's it!
|
37
|
+
|
38
|
+
---
|
39
|
+
|
40
|
+
## Contributing
|
41
|
+
|
42
|
+
See corresponding [guidelines][1] and check out the [issues][2].
|
43
|
+
|
44
|
+
---
|
45
|
+
|
46
|
+
Copyright (c) 2016 [James Whelton][3] and [contributors][4], released under the [New BSD License][5]
|
47
|
+
|
48
|
+
[1]: https://github.com/whelton/solidus_taxon_group/blob/master/CONTRIBUTING.md
|
49
|
+
[2]: https://github.com/whelton/solidus_taxon_group/issues
|
50
|
+
[3]: https://github.com/whelton
|
51
|
+
[4]: https://github.com/whelton/solidus_taxon_group/graphs/contributors
|
52
|
+
[5]: https://github.com/whelton/solidus_taxon_group/blob/master/LICENSE.md
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'spree/testing_support/extension_rake'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
|
9
|
+
task :default do
|
10
|
+
if Dir['spec/dummy'].empty?
|
11
|
+
Rake::Task[:test_app].invoke
|
12
|
+
Dir.chdir('../../')
|
13
|
+
end
|
14
|
+
Rake::Task[:spec].invoke
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Generates a dummy app for testing'
|
18
|
+
task :test_app do
|
19
|
+
ENV['LIB_NAME'] = 'solidus_taxon_group'
|
20
|
+
Rake::Task['extension:test_app'].invoke
|
21
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Spree
|
2
|
+
module Admin
|
3
|
+
class TaxonGroupsController < ResourceController
|
4
|
+
before_action :load_taxons, only: [:new, :edit, :create]
|
5
|
+
before_action :load_taxon_group, only: [:update_positions]
|
6
|
+
|
7
|
+
def positions
|
8
|
+
@taxon_group_memberships = @taxon_group.taxon_group_memberships.order(:position)
|
9
|
+
end
|
10
|
+
|
11
|
+
def update_positions
|
12
|
+
begin
|
13
|
+
update_taxon_group_memership_positions
|
14
|
+
flash[:success] = flash_message_for(@taxon_group, :successfully_updated)
|
15
|
+
rescue => e
|
16
|
+
flash[:error] = e.message
|
17
|
+
end
|
18
|
+
|
19
|
+
respond_with(@taxon_group) do |format|
|
20
|
+
format.html { redirect_to positions_admin_taxon_group_url(@taxon_group) }
|
21
|
+
format.json { render json: @taxon_group.to_json }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def load_taxons
|
28
|
+
@taxons = Spree::Taxon.all
|
29
|
+
end
|
30
|
+
|
31
|
+
def load_taxon_group
|
32
|
+
@taxon_group = Spree::TaxonGroup.find(params[:id])
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_taxon_group_memership_positions
|
36
|
+
update_positions_params.each do |id, position|
|
37
|
+
Spree::TaxonGroupMembership.update(id, position: position)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def update_positions_params
|
42
|
+
params.require(:taxon_group_membership).require(:position)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module Spree
|
2
|
+
class TaxonGroup < ActiveRecord::Base
|
3
|
+
validates :name, presence: true
|
4
|
+
validates :key, presence: true
|
5
|
+
|
6
|
+
has_many :taxon_group_memberships, class_name: 'Spree::TaxonGroupMembership', dependent: :destroy
|
7
|
+
has_many :taxons, -> { order 'spree_taxon_group_memberships.position' }, through: :taxon_group_memberships
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Spree
|
2
|
+
class TaxonGroupMembership < ActiveRecord::Base
|
3
|
+
validates :taxon_group, presence: true
|
4
|
+
validates :taxon, presence: true
|
5
|
+
validates :position, presence: true, numericality: { only_integer: true }
|
6
|
+
|
7
|
+
belongs_to :taxon_group
|
8
|
+
belongs_to :taxon
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
<% content_for :page_actions do %>
|
2
|
+
<%= button_link_to Spree.t(:back_to_resource_list, resource: Spree.t(:taxon_groups)), spree.admin_taxon_groups_path, icon: 'arrow-left', class: 'btn-primary' %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<%= form_for [:admin, resource] do |f| %>
|
6
|
+
|
7
|
+
<div class="row" data-hook="admin_page_form_fields">
|
8
|
+
<div class="form-group">
|
9
|
+
<%= f.label :name, Spree.t(:name) %> <span class="required">*</span>
|
10
|
+
<%= f.text_field :name, class: 'form-control' %>
|
11
|
+
<%= f.error_message_on :name %>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="form-group">
|
15
|
+
<%= f.label :key, Spree.t(:key) %> <span class="required">*</span>
|
16
|
+
<%= f.text_field :key, class: 'form-control' %>
|
17
|
+
<%= f.error_message_on :key %>
|
18
|
+
</div>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<div class="row" data-hook="admin_page_form_fields">
|
22
|
+
<div class="form-group">
|
23
|
+
<table class="table table-hover">
|
24
|
+
<thead>
|
25
|
+
<tr data-hook="taxons_header">
|
26
|
+
<th></th>
|
27
|
+
<th><%= Spree.t(:taxon_name) %></th>
|
28
|
+
<th><%= Spree.t(:path) %></th>
|
29
|
+
</tr>
|
30
|
+
</thead>
|
31
|
+
<tbody>
|
32
|
+
<% @taxons.each do |taxon| %>
|
33
|
+
<tr id="<%= spree_dom_id(taxon) %>" data-hook="taxons_row">
|
34
|
+
<td><%= check_box_tag('taxon_group[taxon_ids][]', taxon.id, taxon.id.in?(resource.taxons.pluck(:id))) %></td>
|
35
|
+
<td><%= taxon.name %></td>
|
36
|
+
<td><%= taxon_path taxon %></td>
|
37
|
+
</tr>
|
38
|
+
<% end %>
|
39
|
+
<% if @taxons.empty? %>
|
40
|
+
<tr data-hook="taxons_none"><td colspan="3"><%= Spree.t(:none) %>.</td></tr>
|
41
|
+
<% end %>
|
42
|
+
</tbody>
|
43
|
+
</table>
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
<script>
|
48
|
+
$(function() {
|
49
|
+
// Checks a taxon's row checkbox on click
|
50
|
+
$('[data-hook="taxons_row"]').on('click', function(e) {
|
51
|
+
// If checkbox, do nothing (prevent double select)
|
52
|
+
if ($(event.target).context.type == 'checkbox' ) {
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
//debugger;
|
56
|
+
var checkbox = $(this).find('input:checkbox');
|
57
|
+
checkbox.prop("checked", !checkbox.prop("checked"));
|
58
|
+
});
|
59
|
+
});
|
60
|
+
</script>
|
61
|
+
|
62
|
+
<%= render "spree/admin/shared/#{resource.new_record? ? 'new' : 'edit'}_resource_links" %>
|
63
|
+
|
64
|
+
<% end %>
|
@@ -0,0 +1,56 @@
|
|
1
|
+
<% content_for :page_actions do %>
|
2
|
+
<%= button_link_to Spree.t(:back_to_taxon_groups_list), spree.admin_taxon_groups_path, icon: 'arrow-left', class: 'btn-primary' %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<%= form_for [:admin, resource], url: positions_admin_taxon_group_path(resource.id) do |f| %>
|
6
|
+
|
7
|
+
<div class="row" data-hook="admin_page_form_fields">
|
8
|
+
<div class="form-group">
|
9
|
+
<table class="table table-hover">
|
10
|
+
<thead>
|
11
|
+
<tr data-hook="taxons_header">
|
12
|
+
<th></th>
|
13
|
+
<th><%= Spree.t(:taxon_name) %></th>
|
14
|
+
<th><%= Spree.t(:path) %></th>
|
15
|
+
</tr>
|
16
|
+
</thead>
|
17
|
+
<tbody>
|
18
|
+
<% @taxon_group_memberships.each do |membership| %>
|
19
|
+
<tr id="<%= spree_dom_id(membership) %>" data-hook="taxons_row">
|
20
|
+
<td class="move-handle">
|
21
|
+
<span class="icon icon-sort handle" style="cursor: pointer"></span>
|
22
|
+
<%= hidden_field_tag('taxon_group_membership[position]['+membership.id.to_s+']', membership.position) %>
|
23
|
+
</td>
|
24
|
+
<td><%= membership.taxon.name %></td>
|
25
|
+
<td><%= taxon_path membership.taxon %></td>
|
26
|
+
</tr>
|
27
|
+
<% end %>
|
28
|
+
<% if @taxon_group_memberships.empty? %>
|
29
|
+
<tr data-hook="taxons_none"><td colspan="3"><%= Spree.t(:none) %>.</td></tr>
|
30
|
+
<% end %>
|
31
|
+
</tbody>
|
32
|
+
</table>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
|
36
|
+
<div class="form-actions" data-hook="buttons">
|
37
|
+
<%= button Spree.t('actions.update'), 'refresh', 'submit', {class: 'btn-success'} %>
|
38
|
+
<span class="or"><%= Spree.t(:or) %></span>
|
39
|
+
<%= button_link_to Spree.t('actions.cancel'), collection_url, :icon => 'delete' %>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<script>
|
43
|
+
$(function() {
|
44
|
+
// Make the tablesortable (with updating the position field)
|
45
|
+
$('tbody').sortable({
|
46
|
+
handle: '.handle',
|
47
|
+
update: function(event, ui) {
|
48
|
+
$.each($("tbody input"), function(position){
|
49
|
+
$(this).val(position);
|
50
|
+
});
|
51
|
+
}
|
52
|
+
});
|
53
|
+
});
|
54
|
+
</script>
|
55
|
+
|
56
|
+
<% end %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<table class="table sortable" id='listing_taxon_groups' data-hook>
|
2
|
+
<thead>
|
3
|
+
<tr data-hook="taxon_groups_header">
|
4
|
+
<th><%= Spree.t(:name) %></th>
|
5
|
+
<th><%= Spree.t(:key) %></th>
|
6
|
+
<th><%= Spree.t(:taxon_count) %></th>
|
7
|
+
<th class="actions"></th>
|
8
|
+
</tr>
|
9
|
+
</thead>
|
10
|
+
<tbody>
|
11
|
+
<% @taxon_groups.each do |taxon_group| %>
|
12
|
+
<tr id="<%= spree_dom_id taxon_group %>" data-hook="taxon_groups_row">
|
13
|
+
<td><%= taxon_group.name %></td>
|
14
|
+
<td><%= taxon_group.key %></td>
|
15
|
+
<td><%= taxon_group.taxons.count %></td>
|
16
|
+
<td class="actions">
|
17
|
+
<!-- Edit -->
|
18
|
+
<%= link_to_edit taxon_group, no_text: true %>
|
19
|
+
|
20
|
+
<!-- Positions -->
|
21
|
+
<%= link_to '', positions_admin_taxon_group_path(taxon_group.id), class: 'fa fa-arrows-v icon_link with-tip no-text', 'data-action': 'Positions' %>
|
22
|
+
|
23
|
+
<!-- Delete -->
|
24
|
+
<%= link_to_delete taxon_group, no_text: true %>
|
25
|
+
</td>
|
26
|
+
</tr>
|
27
|
+
<% end %>
|
28
|
+
</tbody>
|
29
|
+
</table>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% content_for :page_title do %>
|
2
|
+
<%= Spree.t(:taxon_groups) %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% content_for :page_actions do %>
|
6
|
+
<%= button_link_to Spree.t(:new_taxon_group), new_object_url, class: "btn-success", icon: 'add', id: 'admin_new_taxon_group_link' %>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<% if @taxon_groups.any? %>
|
10
|
+
<div id="list-taxon-groups" data-hook>
|
11
|
+
<%= render 'list' %>
|
12
|
+
</div>
|
13
|
+
<% else %>
|
14
|
+
<div class="alert alert-info no-objects-found">
|
15
|
+
<%= Spree.t(:no_resource_found, resource: Spree.t(:taxon_groups)).html_safe %>,
|
16
|
+
<%= link_to Spree.t(:add_one), new_object_url %>!
|
17
|
+
</div>
|
18
|
+
<% end %>
|
data/bin/rails
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
activerecord:
|
4
|
+
attributes:
|
5
|
+
spree/taxon_group:
|
6
|
+
name: "Taxon Group"
|
7
|
+
models:
|
8
|
+
spree/taxon_group:
|
9
|
+
one: "Taxon Group"
|
10
|
+
other: "Taxon Groups"
|
11
|
+
spree:
|
12
|
+
admin:
|
13
|
+
tab:
|
14
|
+
taxon_groups: "Taxon Groups"
|
15
|
+
taxon_groups: "Taxon Groups"
|
16
|
+
back_to_taxon_groups_list: "Back To Taxon Groups List"
|
17
|
+
new_taxon_group: "New Taxon Group"
|
18
|
+
edit_taxon_group: "Edit Taxon Group"
|
19
|
+
positions_taxon_group: "Taxon Group Positions"
|
20
|
+
taxon_count: "Taxon Count"
|
21
|
+
shop_by_taxon_group: "Shop by %{taxon_group}"
|
data/config/routes.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class CreateSpreeTaxonGroupMemberships < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :spree_taxon_group_memberships do |t|
|
4
|
+
t.integer :taxon_group_id
|
5
|
+
t.integer :taxon_id
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.down
|
10
|
+
drop_table :spree_taxon_group_memberships
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SolidusTaxonGroup
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
5
|
+
|
6
|
+
def add_migrations
|
7
|
+
run 'bundle exec rake railties:install:migrations FROM=solidus_taxon_group'
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_migrations
|
11
|
+
if running_migrations?
|
12
|
+
run 'bundle exec rake db:migrate'
|
13
|
+
else
|
14
|
+
puts "Skiping rake db:migrate, don't forget to run it!"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def running_migrations?
|
21
|
+
options.auto_run_migrations? || begin
|
22
|
+
response = ask 'Would you like to run the migrations now? [Y/n]'
|
23
|
+
['', 'y'].include? response.downcase
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SolidusTaxonGroup
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
engine_name 'solidus_taxon_group'
|
4
|
+
|
5
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
6
|
+
|
7
|
+
def self.activate
|
8
|
+
Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
|
9
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
config.to_prepare(&method(:activate).to_proc)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SolidusTaxonGroup
|
2
|
+
module_function
|
3
|
+
|
4
|
+
# Returns the version of the currently loaded SolidusTaxonGroup as a
|
5
|
+
# <tt>Gem::Version</tt>.
|
6
|
+
def version
|
7
|
+
Gem::Version.new VERSION::STRING
|
8
|
+
end
|
9
|
+
|
10
|
+
module VERSION
|
11
|
+
MAJOR = 1
|
12
|
+
MINOR = 0
|
13
|
+
TINY = 1
|
14
|
+
|
15
|
+
STRING = [MAJOR, MINOR, TINY].compact.join('.')
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
3
|
+
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'solidus_taxon_group/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.name = 'solidus_taxon_group'
|
10
|
+
s.version = SolidusTaxonGroup.version
|
11
|
+
s.summary = 'Solidus extension to create and manage groups of taxons'
|
12
|
+
s.description = s.summary
|
13
|
+
s.required_ruby_version = '>= 2.0.0'
|
14
|
+
|
15
|
+
s.author = 'James Whelton'
|
16
|
+
s.email = 'james@whelton.io'
|
17
|
+
s.homepage = 'https://github.com/whelton/solidus_taxon_group'
|
18
|
+
s.license = 'BSD-3'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.require_path = 'lib'
|
23
|
+
s.requirements << 'none'
|
24
|
+
|
25
|
+
s.add_dependency 'solidus_core', '~> 1.1'
|
26
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Run Coverage report
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec/dummy'
|
5
|
+
add_group 'Controllers', 'app/controllers'
|
6
|
+
add_group 'Helpers', 'app/helpers'
|
7
|
+
add_group 'Mailers', 'app/mailers'
|
8
|
+
add_group 'Models', 'app/models'
|
9
|
+
add_group 'Views', 'app/views'
|
10
|
+
add_group 'Libraries', 'lib'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Configure Rails Environment
|
14
|
+
ENV['RAILS_ENV'] = 'test'
|
15
|
+
|
16
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
17
|
+
|
18
|
+
require 'rspec/rails'
|
19
|
+
require 'database_cleaner'
|
20
|
+
require 'ffaker'
|
21
|
+
|
22
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
23
|
+
# in spec/support/ and its subdirectories.
|
24
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
25
|
+
|
26
|
+
# Requires factories and other useful helpers defined in spree_core.
|
27
|
+
require 'spree/testing_support/authorization_helpers'
|
28
|
+
require 'spree/testing_support/capybara_ext'
|
29
|
+
require 'spree/testing_support/controller_requests'
|
30
|
+
require 'spree/testing_support/factories'
|
31
|
+
require 'spree/testing_support/url_helpers'
|
32
|
+
|
33
|
+
# Requires factories defined in lib/solidus_taxon_group/factories.rb
|
34
|
+
require 'solidus_taxon_group/factories'
|
35
|
+
|
36
|
+
RSpec.configure do |config|
|
37
|
+
config.include FactoryGirl::Syntax::Methods
|
38
|
+
|
39
|
+
# Infer an example group's spec type from the file location.
|
40
|
+
config.infer_spec_type_from_file_location!
|
41
|
+
|
42
|
+
# == URL Helpers
|
43
|
+
#
|
44
|
+
# Allows access to Spree's routes in specs:
|
45
|
+
#
|
46
|
+
# visit spree.admin_path
|
47
|
+
# current_path.should eql(spree.products_path)
|
48
|
+
config.include Spree::TestingSupport::UrlHelpers
|
49
|
+
|
50
|
+
# == Requests support
|
51
|
+
#
|
52
|
+
# Adds convenient methods to request Spree's controllers
|
53
|
+
# spree_get :index
|
54
|
+
config.include Spree::TestingSupport::ControllerRequests, type: :controller
|
55
|
+
|
56
|
+
# == Mock Framework
|
57
|
+
#
|
58
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
59
|
+
#
|
60
|
+
# config.mock_with :mocha
|
61
|
+
# config.mock_with :flexmock
|
62
|
+
# config.mock_with :rr
|
63
|
+
config.mock_with :rspec
|
64
|
+
config.color = true
|
65
|
+
|
66
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
67
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
68
|
+
|
69
|
+
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
|
70
|
+
# to cleanup after each test instead. Without transactional fixtures set to false the records created
|
71
|
+
# to setup a test will be unavailable to the browser, which runs under a separate server instance.
|
72
|
+
config.use_transactional_fixtures = false
|
73
|
+
|
74
|
+
# Ensure Suite is set to use transactions for speed.
|
75
|
+
config.before :suite do
|
76
|
+
DatabaseCleaner.strategy = :transaction
|
77
|
+
DatabaseCleaner.clean_with :truncation
|
78
|
+
end
|
79
|
+
|
80
|
+
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
|
81
|
+
config.before :each do
|
82
|
+
DatabaseCleaner.strategy = RSpec.current_example.metadata[:js] ? :truncation : :transaction
|
83
|
+
DatabaseCleaner.start
|
84
|
+
end
|
85
|
+
|
86
|
+
# After each spec clean the database.
|
87
|
+
config.after :each do
|
88
|
+
DatabaseCleaner.clean
|
89
|
+
end
|
90
|
+
|
91
|
+
config.fail_fast = ENV['FAIL_FAST'] || false
|
92
|
+
config.order = 'random'
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: solidus_taxon_group
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Whelton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: solidus_core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
description: Solidus extension to create and manage groups of taxons
|
28
|
+
email: james@whelton.io
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- ".gitignore"
|
34
|
+
- ".hound.yml"
|
35
|
+
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- ".travis.yml"
|
38
|
+
- CHANGELOG.md
|
39
|
+
- CONTRIBUTING.md
|
40
|
+
- Gemfile
|
41
|
+
- Guardfile
|
42
|
+
- LICENSE.md
|
43
|
+
- README.md
|
44
|
+
- Rakefile
|
45
|
+
- app/controllers/spree/admin/taxon_groups_controller.rb
|
46
|
+
- app/models/spree/taxon_decorator.rb
|
47
|
+
- app/models/spree/taxon_group.rb
|
48
|
+
- app/models/spree/taxon_group_membership.rb
|
49
|
+
- app/overrides/add_taxon_groups_under_taxon_in_products_in_admin_sidebar_menu.rb
|
50
|
+
- app/views/spree/admin/taxon_groups/_form.html.erb
|
51
|
+
- app/views/spree/admin/taxon_groups/_form_positions.html.erb
|
52
|
+
- app/views/spree/admin/taxon_groups/_list.html.erb
|
53
|
+
- app/views/spree/admin/taxon_groups/edit.html.erb
|
54
|
+
- app/views/spree/admin/taxon_groups/index.html.erb
|
55
|
+
- app/views/spree/admin/taxon_groups/new.html.erb
|
56
|
+
- app/views/spree/admin/taxon_groups/positions.html.erb
|
57
|
+
- bin/rails
|
58
|
+
- config/locales/en.yml
|
59
|
+
- config/routes.rb
|
60
|
+
- db/migrate/20160120200344_create_spree_taxon_groups.rb
|
61
|
+
- db/migrate/20160120200408_create_spree_taxon_group_memberships.rb
|
62
|
+
- db/migrate/20160120200431_add_position_to_spree_taxon_group_membership.rb
|
63
|
+
- db/migrate/20160120200448_add_key_to_spree_taxon_group.rb
|
64
|
+
- db/migrate/20160120200504_update_keys_where_nil_for_spree_taxon_group.rb
|
65
|
+
- lib/generators/solidus_taxon_group/install/install_generator.rb
|
66
|
+
- lib/solidus_taxon_group.rb
|
67
|
+
- lib/solidus_taxon_group/engine.rb
|
68
|
+
- lib/solidus_taxon_group/version.rb
|
69
|
+
- solidus_taxon_group.gemspec
|
70
|
+
- spec/models/spree/taxon_group_spec.rb
|
71
|
+
- spec/spec_helper.rb
|
72
|
+
homepage: https://github.com/whelton/solidus_taxon_group
|
73
|
+
licenses:
|
74
|
+
- BSD-3
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 2.0.0
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements:
|
91
|
+
- none
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Solidus extension to create and manage groups of taxons
|
97
|
+
test_files:
|
98
|
+
- spec/models/spree/taxon_group_spec.rb
|
99
|
+
- spec/spec_helper.rb
|