faceted_search 2.1.1 → 2.2.0
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 +4 -4
- data/app/assets/javascripts/faceted_search/Tree.js +24 -7
- data/app/assets/stylesheets/faceted_search/nestable.sass +4 -0
- data/app/models/faceted_search/facets/filter.rb +41 -21
- data/app/views/faceted_search/facets/_filter.html.erb +16 -10
- data/lib/faceted_search/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f82d1b15fdbb630bd290e8d915b5dd109b7e07ad17561c959043a44a13af4ade
|
4
|
+
data.tar.gz: c958ae79ef81325ae652ebe54a0c9fdfebe7ebd0ce8b60a30188c0bb3de3a062
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91a8751b4523d08c0dff7112a05d5d87eebd6ed69c1c7ace85d438093d521c5421e860adeee41beeb931c0833143ced6a45f2f0f0fc16dcbbffdbdec861f4bc9
|
7
|
+
data.tar.gz: cd64b29320ff0a978e436a5df1b48f8f98319d512c3c9984756bc352d6f74d911b1ea2bbc48dbffc4bf17382eed3e95275dd1375b69f8ba54060e0a4364ce178
|
@@ -40,17 +40,33 @@ window.facetedSearch.Tree.prototype.generateItem = function (item) {
|
|
40
40
|
liNode.className = item.selected ? "dd-item dd-item--selected"
|
41
41
|
: "dd-item";
|
42
42
|
|
43
|
-
var
|
44
|
-
|
45
|
-
|
43
|
+
var iconNode = null;
|
44
|
+
iconNode = document.createElement('i');
|
45
|
+
iconNode.className = "back-link fas fa-arrow-left";
|
46
|
+
var titleNode = document.createTextNode(item.title);
|
47
|
+
|
48
|
+
var itemContent = document.createDocumentFragment();
|
49
|
+
if (item.back === "true") {
|
50
|
+
itemContent.appendChild(iconNode);
|
51
|
+
}
|
52
|
+
itemContent.appendChild(titleNode);
|
53
|
+
|
54
|
+
if (item.url !== "") {
|
55
|
+
var aNode = document.createElement('a');
|
56
|
+
aNode.setAttribute("href", item.url);
|
57
|
+
aNode.appendChild(itemContent);
|
58
|
+
liNode.appendChild(aNode);
|
59
|
+
} else {
|
60
|
+
liNode.appendChild(itemContent);
|
61
|
+
}
|
46
62
|
|
47
|
-
liNode.appendChild(aNode);
|
48
63
|
|
49
64
|
if (item.children.length > 0) {
|
50
65
|
var olNode = this.generateList(item.children);
|
51
66
|
liNode.appendChild(olNode);
|
52
67
|
}
|
53
68
|
|
69
|
+
|
54
70
|
return liNode;
|
55
71
|
};
|
56
72
|
|
@@ -82,6 +98,7 @@ window.facetedSearch.Tree.prototype.initDOM = function () {
|
|
82
98
|
selected: elt.getAttribute('data-selected') === "true",
|
83
99
|
resultsCount: parseInt(elt.getAttribute('data-count'), 10),
|
84
100
|
url: elt.getAttribute('data-url'),
|
101
|
+
back: elt.getAttribute('data-back'),
|
85
102
|
title: elt.textContent.trim()
|
86
103
|
};
|
87
104
|
});
|
@@ -103,9 +120,9 @@ window.facetedSearch.Tree.prototype.initNestable = function () {
|
|
103
120
|
"use strict";
|
104
121
|
|
105
122
|
$('.dd', this.wrapper).nestable({
|
106
|
-
expandBtnHTML: '
|
107
|
-
collapseBtnHTML: '
|
108
|
-
}).data("nestable")
|
123
|
+
expandBtnHTML: '',
|
124
|
+
collapseBtnHTML: ''
|
125
|
+
}).data("nestable");
|
109
126
|
};
|
110
127
|
|
111
128
|
window.addEventListener('DOMContentLoaded', function () {
|
@@ -14,36 +14,50 @@ module FacetedSearch
|
|
14
14
|
# and return the modified scope
|
15
15
|
def add_scope(scope)
|
16
16
|
return scope if params_array.blank?
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
identifiers = params_array.dup
|
19
|
+
identifiers << selected_objects.first.descendents if tree?
|
20
|
+
identifiers.flatten!
|
21
|
+
|
22
|
+
habtm? ? scope.joins(name).where(name => { find_by => identifiers })
|
23
|
+
: scope.where(name => identifiers)
|
19
24
|
end
|
20
25
|
|
21
26
|
def find_by
|
22
27
|
@options[:find_by] || :id
|
23
28
|
end
|
24
29
|
|
30
|
+
def selected_objects
|
31
|
+
values.where(find_by => params_array)
|
32
|
+
end
|
33
|
+
|
25
34
|
# Show all values that have corresponding results.
|
26
35
|
# This is a regular SQL inner join.
|
27
36
|
def values
|
28
|
-
|
29
|
-
source.all.joins(joined_table).where(joined_table => { id: facets.model }).distinct
|
37
|
+
@values ||= get_values
|
30
38
|
end
|
31
39
|
|
32
|
-
def
|
33
|
-
|
40
|
+
def tree_values
|
41
|
+
return values.select { |obj| obj.root? } if params_array.empty?
|
42
|
+
|
43
|
+
selected_object = selected_objects.first
|
44
|
+
return [] if selected_object.nil?
|
45
|
+
|
46
|
+
array = []
|
47
|
+
array << values.find { |obj| obj.id == selected_object.parent_id } if selected_object.has_parent? # parent
|
48
|
+
array << values.select { |obj| obj.parent_id == selected_object.parent_id } # selected & siblings
|
49
|
+
array << values.select { |obj| obj.parent_id == selected_object.id } if selected_object.has_children? # selected object's children
|
50
|
+
array.flatten.compact
|
34
51
|
end
|
35
52
|
|
36
|
-
def
|
37
|
-
|
38
|
-
@facets.list.each do |facet|
|
39
|
-
scope = facet == self ? add_scope_with_value(scope, value)
|
40
|
-
: facet.add_scope(scope)
|
41
|
-
end
|
42
|
-
scope
|
53
|
+
def value_selected?(value)
|
54
|
+
value.to_s.in? params_array
|
43
55
|
end
|
44
56
|
|
45
57
|
def path_for(value)
|
46
58
|
value = value.to_s
|
59
|
+
return path_for_tree(value) if tree?
|
60
|
+
|
47
61
|
custom_params = params_array.dup
|
48
62
|
value_selected?(value) ? custom_params.delete(value)
|
49
63
|
: custom_params.push(value)
|
@@ -54,18 +68,24 @@ module FacetedSearch
|
|
54
68
|
@options[:source] || name.to_s.singularize.titleize.constantize.send(:all)
|
55
69
|
end
|
56
70
|
|
71
|
+
def has_params?
|
72
|
+
params_array.any?
|
73
|
+
end
|
74
|
+
|
57
75
|
protected
|
58
76
|
|
59
|
-
def
|
60
|
-
|
77
|
+
def get_values
|
78
|
+
joined_table = facets.model_table_name.to_sym
|
79
|
+
source.all.joins(joined_table).where(joined_table => { id: facets.model }).distinct
|
61
80
|
end
|
62
81
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
82
|
+
def path_for_tree(value)
|
83
|
+
value_selected?(value) ? path('')
|
84
|
+
: path(value)
|
85
|
+
end
|
86
|
+
|
87
|
+
def params_array
|
88
|
+
@params_array ||= @params.to_s.split(',')
|
69
89
|
end
|
70
90
|
|
71
91
|
def habtm?
|
@@ -2,20 +2,28 @@
|
|
2
2
|
<div class="faceted__facet__filter--tree">
|
3
3
|
<div class="dd">
|
4
4
|
<ol class="faceted__facet__filter--tree__level dd-list">
|
5
|
-
<% facet.
|
5
|
+
<% facet.tree_values.each_with_index do |object, index| %>
|
6
6
|
<%
|
7
7
|
identifier = object.send facet.find_by
|
8
|
-
results_count = facet.results_with(identifier).count
|
9
|
-
facet_url = facet.facets.path_for(facet, identifier)
|
10
|
-
display_value = facet.display_method.call(object)
|
11
8
|
selected = facet.value_selected?(identifier)
|
9
|
+
facet_url = selected ? '' : facet.facets.path_for(facet, identifier)
|
10
|
+
back = index == 0 && !selected && facet.has_params?
|
11
|
+
display_value = facet.display_method.call(object)
|
12
12
|
parent_id = object.parent_id.nil? ? 0 : object.parent_id
|
13
13
|
%>
|
14
|
-
|
14
|
+
<% if index == 0 && selected %>
|
15
|
+
<li data-parent="0"
|
16
|
+
data-id="-1"
|
17
|
+
data-back="true"
|
18
|
+
data-selected="false"
|
19
|
+
data-url="<%= facet.facets.path_for(facet, '') %>">
|
20
|
+
</li>
|
21
|
+
<% end %>
|
22
|
+
<li data-parent="<%= back ? 0 : parent_id %>"
|
15
23
|
data-id="<%= object.id %>"
|
24
|
+
data-back="<%= back %>"
|
16
25
|
data-selected="<%= selected %>"
|
17
|
-
data-url="<%= facet_url %>"
|
18
|
-
data-count="<%= results_count %>">
|
26
|
+
data-url="<%= facet_url %>">
|
19
27
|
<%= display_value %>
|
20
28
|
</li>
|
21
29
|
<% end %>
|
@@ -27,12 +35,10 @@
|
|
27
35
|
<% facet.values.each do |value| %>
|
28
36
|
<%
|
29
37
|
identifier = value.send facet.find_by
|
30
|
-
results_count = facet.results_with(identifier).count
|
31
38
|
display_value = facet.display_method.call(value)
|
32
|
-
next if results_count.zero?
|
33
39
|
%>
|
34
40
|
<li class="faceted__facet__filter__value<%= '--selected' if facet.value_selected?(identifier) %>">
|
35
|
-
<%= link_to
|
41
|
+
<%= link_to display_value, facet.facets.path_for(facet, identifier) + anchor %>
|
36
42
|
</li>
|
37
43
|
<% end %>
|
38
44
|
</ul>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faceted_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Levy
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2019-03-
|
13
|
+
date: 2019-03-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -171,8 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
- !ruby/object:Gem::Version
|
172
172
|
version: '0'
|
173
173
|
requirements: []
|
174
|
-
|
175
|
-
rubygems_version: 2.7.6
|
174
|
+
rubygems_version: 3.0.1
|
176
175
|
signing_key:
|
177
176
|
specification_version: 4
|
178
177
|
summary: Faceted search with Active Record
|