spree_taxon_group 3.0.0.beta → 3.1.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +15 -3
- data/app/controllers/spree/admin/taxon_groups_controller.rb +34 -1
- data/app/helpers/spree/frontend_helper_decorator.rb +3 -3
- data/app/models/spree/taxon_group.rb +2 -1
- data/app/models/spree/taxon_group_membership.rb +1 -0
- data/app/views/spree/admin/taxon_groups/_form.html.erb +11 -5
- data/app/views/spree/admin/taxon_groups/_form_positions.html.erb +56 -0
- data/app/views/spree/admin/taxon_groups/_list.html.erb +10 -0
- data/app/views/spree/admin/taxon_groups/positions.html.erb +5 -0
- data/config/locales/en.yml +1 -0
- data/config/routes.rb +6 -1
- data/db/migrate/20151018171108_add_position_to_spree_taxon_group_membership.rb +5 -0
- data/db/migrate/20151019140301_add_key_to_spree_taxon_group.rb +5 -0
- data/db/migrate/20151019140742_update_keys_where_nil_for_spree_taxon_group.rb +7 -0
- data/lib/spree_taxon_group/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e76e2eb51ec86d40bd3baefa94f689a93d8d9b6
|
4
|
+
data.tar.gz: 0359460858e8c233ef5cbf09c783632a342c3798
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc52c16f902531c34841d7dddd3767e89997ae83fca6bdc39192ab3a6d16e60ce5a8db386f762d01f63900046d28eef66f84f0b9c84aea48ee29a770a5445b08
|
7
|
+
data.tar.gz: 74117d1d131c67e36afcd81f236495b15214048cb6e118d534786e604e64531c87e5bb785e87767e619fd4620986953c53be3d2c9b9dcb8d1746f4fb33fe3e0d
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Spree Taxon Group
|
2
2
|
|
3
|
-
Easily create and manage groups of taxons, irrespective of their parent or children taxons/taxonomies.
|
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
4
|
Useful if you need flexible taxon usage, for example a group of taxons for featured categories from different parent taxon/taxonomies.
|
5
5
|
|
6
6
|
---
|
@@ -11,7 +11,7 @@ If you want a taxon tree, similar to `taxons_tree` in the default spree sidebar.
|
|
11
11
|
|
12
12
|
```html
|
13
13
|
<nav id="featured-categories" class="sidebar-item" data-hook>
|
14
|
-
<% featured = Spree::TaxonGroup.
|
14
|
+
<% featured = Spree::TaxonGroup.find_by_key('featured') %>
|
15
15
|
<% cache [I18n.locale, featured] do %>
|
16
16
|
<h4 class='taxon-group-root'><%= Spree.t(:shop_by_taxon_group, :taxon_group => featured.name) %></h4>
|
17
17
|
<%= taxon_group_tree(featured, @taxon) %>
|
@@ -19,6 +19,18 @@ If you want a taxon tree, similar to `taxons_tree` in the default spree sidebar.
|
|
19
19
|
</nav>
|
20
20
|
```
|
21
21
|
|
22
|
+
or for more control, without `taxon_group_tree`:
|
23
|
+
|
24
|
+
```html
|
25
|
+
<% navigation_taxon_upcase_group = Spree::TaxonGroup.find_by_key('navigation') %>
|
26
|
+
<% cache [I18n.locale, navigation_taxon_upcase_group] do %>
|
27
|
+
<%= navigation_taxon_upcase_group.taxons.map do |taxon|
|
28
|
+
'<li class="hidden-lg hidden-md">' + link_to(taxon.name.upcase, seo_url(taxon)) + '</li>'
|
29
|
+
end.join("\n").html_safe
|
30
|
+
%>
|
31
|
+
<% end %>
|
32
|
+
```
|
33
|
+
|
22
34
|
---
|
23
35
|
|
24
36
|
## Basic Installation
|
@@ -26,7 +38,7 @@ If you want a taxon tree, similar to `taxons_tree` in the default spree sidebar.
|
|
26
38
|
Add to your `Gemfile`:
|
27
39
|
|
28
40
|
```ruby
|
29
|
-
gem 'spree_taxon_group',
|
41
|
+
gem 'spree_taxon_group', '~> 3.1', '>= 3.1.0.beta'
|
30
42
|
```
|
31
43
|
|
32
44
|
Run:
|
@@ -1,13 +1,46 @@
|
|
1
1
|
module Spree
|
2
2
|
module Admin
|
3
3
|
class TaxonGroupsController < ResourceController
|
4
|
-
before_action :load_taxons, only: [:new, :edit]
|
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
|
5
24
|
|
6
25
|
private
|
7
26
|
|
8
27
|
def load_taxons
|
9
28
|
@taxons = Spree::Taxon.all
|
10
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
|
11
44
|
end
|
12
45
|
end
|
13
46
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Spree::FrontendHelper.class_eval do
|
2
2
|
def taxon_group_tree(taxon_group, current_taxon)
|
3
3
|
content_tag :div, class: 'list-group' do
|
4
|
-
taxon_group.
|
5
|
-
css_class = (current_taxon.eql? taxon) ? 'list-group-item active' : 'list-group-item'
|
6
|
-
link_to(taxon.name, seo_url(taxon), class: css_class)
|
4
|
+
taxon_group.taxon_group_memberships.sort_by(&:position).map do |membership|
|
5
|
+
css_class = (current_taxon.eql? membership.taxon) ? 'list-group-item active' : 'list-group-item'
|
6
|
+
link_to(membership.taxon.name, seo_url(membership.taxon), class: css_class)
|
7
7
|
end.join("\n").html_safe
|
8
8
|
end
|
9
9
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module Spree
|
2
2
|
class TaxonGroup < ActiveRecord::Base
|
3
3
|
validates :name, presence: true
|
4
|
+
validates :key, presence: true
|
4
5
|
|
5
6
|
has_many :taxon_group_memberships, class_name: 'Spree::TaxonGroupMembership', dependent: :destroy
|
6
|
-
has_many :taxons, through: :taxon_group_memberships
|
7
|
+
has_many :taxons, -> { order 'spree_taxon_group_memberships.position' }, through: :taxon_group_memberships
|
7
8
|
end
|
8
9
|
end
|
@@ -10,6 +10,12 @@
|
|
10
10
|
<%= f.text_field :name, class: 'form-control' %>
|
11
11
|
<%= f.error_message_on :name %>
|
12
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>
|
13
19
|
</div>
|
14
20
|
|
15
21
|
<div class="row" data-hook="admin_page_form_fields">
|
@@ -25,7 +31,7 @@
|
|
25
31
|
<tbody>
|
26
32
|
<% @taxons.each do |taxon| %>
|
27
33
|
<tr id="<%= spree_dom_id(taxon) %>" data-hook="taxons_row">
|
28
|
-
<td><%= check_box_tag(
|
34
|
+
<td><%= check_box_tag('taxon_group[taxon_ids][]', taxon.id, taxon.id.in?(resource.taxons.pluck(:id))) %></td>
|
29
35
|
<td><%= taxon.name %></td>
|
30
36
|
<td><%= taxon_path taxon %></td>
|
31
37
|
</tr>
|
@@ -42,12 +48,12 @@
|
|
42
48
|
$(function() {
|
43
49
|
// Checks a taxon's row checkbox on click
|
44
50
|
$('[data-hook="taxons_row"]').on('click', function(e) {
|
45
|
-
|
51
|
+
// If checkbox, do nothing (prevent double select)
|
46
52
|
if ($(event.target).context.type == 'checkbox' ) {
|
47
|
-
return;
|
53
|
+
return;
|
48
54
|
}
|
49
|
-
|
50
|
-
var checkbox = $(this).
|
55
|
+
//debugger;
|
56
|
+
var checkbox = $(this).find('input:checkbox');
|
51
57
|
checkbox.prop("checked", !checkbox.prop("checked"));
|
52
58
|
});
|
53
59
|
});
|
@@ -0,0 +1,56 @@
|
|
1
|
+
<% content_for :page_actions do %>
|
2
|
+
<%= button_link_to Spree.t(:back_to_resource_list, resource: plural_resource_name(Spree::TaxonGroup)), 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 %>
|
@@ -2,6 +2,7 @@
|
|
2
2
|
<thead>
|
3
3
|
<tr data-hook="taxon_groups_header">
|
4
4
|
<th><%= Spree.t(:name) %></th>
|
5
|
+
<th><%= Spree.t(:key) %></th>
|
5
6
|
<th><%= Spree.t(:taxon_count) %></th>
|
6
7
|
<th class="actions"></th>
|
7
8
|
</tr>
|
@@ -10,9 +11,18 @@
|
|
10
11
|
<% @taxon_groups.each do |taxon_group| %>
|
11
12
|
<tr id="<%= spree_dom_id taxon_group %>" data-hook="taxon_groups_row">
|
12
13
|
<td><%= taxon_group.name %></td>
|
14
|
+
<td><%= taxon_group.key %></td>
|
13
15
|
<td><%= taxon_group.taxons.count %></td>
|
14
16
|
<td class="actions actions-2 text-right">
|
17
|
+
<!-- Edit -->
|
15
18
|
<%= link_to_edit taxon_group.id, no_text: true %>
|
19
|
+
|
20
|
+
<!-- Positions -->
|
21
|
+
<%= link_to positions_admin_taxon_group_path(taxon_group.id), class: 'btn btn-default btn-sm icon-link with-tip action-positions no-text', 'data-original-title': 'Positions' do %>
|
22
|
+
<span class="icon icon-sort"></span>
|
23
|
+
<% end %>
|
24
|
+
|
25
|
+
<!-- Delete -->
|
16
26
|
<%= link_to_delete taxon_group, no_text: true %>
|
17
27
|
</td>
|
18
28
|
</tr>
|
data/config/locales/en.yml
CHANGED
data/config/routes.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_taxon_group
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Whelton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- ".rspec"
|
36
36
|
- ".rubocop.yml"
|
37
37
|
- ".travis.yml"
|
38
|
+
- CHANGELOG.md
|
38
39
|
- CONTRIBUTING.md
|
39
40
|
- Gemfile
|
40
41
|
- Guardfile
|
@@ -48,15 +49,20 @@ files:
|
|
48
49
|
- app/models/spree/taxon_group_membership.rb
|
49
50
|
- app/overrides/add_taxon_groups_under_taxon_in_products_in_admin_sidebar_menu.rb
|
50
51
|
- app/views/spree/admin/taxon_groups/_form.html.erb
|
52
|
+
- app/views/spree/admin/taxon_groups/_form_positions.html.erb
|
51
53
|
- app/views/spree/admin/taxon_groups/_list.html.erb
|
52
54
|
- app/views/spree/admin/taxon_groups/edit.html.erb
|
53
55
|
- app/views/spree/admin/taxon_groups/index.html.erb
|
54
56
|
- app/views/spree/admin/taxon_groups/new.html.erb
|
57
|
+
- app/views/spree/admin/taxon_groups/positions.html.erb
|
55
58
|
- bin/rails
|
56
59
|
- config/locales/en.yml
|
57
60
|
- config/routes.rb
|
58
61
|
- db/migrate/20151004162900_create_spree_taxon_groups.rb
|
59
62
|
- db/migrate/20151004173034_create_spree_taxon_group_memberships.rb
|
63
|
+
- db/migrate/20151018171108_add_position_to_spree_taxon_group_membership.rb
|
64
|
+
- db/migrate/20151019140301_add_key_to_spree_taxon_group.rb
|
65
|
+
- db/migrate/20151019140742_update_keys_where_nil_for_spree_taxon_group.rb
|
60
66
|
- lib/generators/spree_taxon_group/install/install_generator.rb
|
61
67
|
- lib/spree_taxon_group.rb
|
62
68
|
- lib/spree_taxon_group/engine.rb
|