graph_starter 0.4.0 → 0.4.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 +4 -4
- data/app/controllers/graph_starter/application_controller.rb +1 -1
- data/app/controllers/graph_starter/assets_controller.rb +25 -13
- data/app/models/graph_starter/asset.rb +15 -1
- data/app/views/graph_starter/assets/index.html.slim +2 -2
- data/lib/graph_starter/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c62eaa30a0e1b703a7565ba225b97e7b4639006
|
4
|
+
data.tar.gz: 350c64371b1f49d43e3ad5a5a3d8835b26a49c64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fea3be17b5a3518836b448fe14ebbcd129cb77427f645a821c83397d2f316b121c76cc490d1b2b0ed6afe31c8834ae1980d5a171a0449b5391bb8fd24d67fb36
|
7
|
+
data.tar.gz: 321801dd33ef789366f29cd680e1b841949404f302b107d07b3bd7bec4d1a42aa2552eb358c465667893f41874e2c9289563681dbbb9dda11620ebc423e46624
|
@@ -8,31 +8,41 @@ module GraphStarter
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def search
|
11
|
-
|
12
|
-
assets = asset_set { |scope| scope.where(title: regexp) }
|
11
|
+
assets = asset_set { |scope| scope.for_query(params[:query]) }
|
13
12
|
results_data = assets.map do |asset|
|
13
|
+
description = model_class.search_properties.map do |property|
|
14
|
+
"<b>#{property.to_s.humanize}:</b> #{asset.read_attribute(property)}"
|
15
|
+
end.join("<br>")
|
16
|
+
|
14
17
|
{
|
15
18
|
title: asset.title,
|
16
19
|
url: asset_path(id: asset, model_slug: asset.class.model_slug),
|
17
|
-
|
18
|
-
|
20
|
+
description: description,
|
21
|
+
image: images? && asset.first_image_source_url || nil
|
22
|
+
}.reject {|_, v| v.nil? }.tap do |result|
|
23
|
+
model_class.search_properties.each do |property|
|
24
|
+
result[property] = asset.read_attribute(property)
|
25
|
+
end
|
26
|
+
end
|
19
27
|
end
|
20
28
|
|
29
|
+
# INCLUDE SEARCH QUERY PROPERTIES IN RESULT!!!
|
30
|
+
|
21
31
|
render json: {results: results_data}.to_json
|
22
32
|
end
|
23
33
|
|
24
|
-
def asset_set
|
34
|
+
def asset_set(var = :asset)
|
25
35
|
associations = []
|
26
36
|
associations << :images if images?
|
27
37
|
associations << model_class.category_association if model_class.category_association
|
28
38
|
|
29
|
-
scope = model_class_scope
|
39
|
+
scope = model_class_scope(var)
|
30
40
|
scope = yield scope if block_given?
|
31
41
|
|
32
42
|
scope = scope.limit(50)
|
33
43
|
|
34
44
|
if associations.present?
|
35
|
-
scope.query_as(
|
45
|
+
scope.query_as(var).with(var).proxy_as(model_class, var).with_associations(*associations)
|
36
46
|
else
|
37
47
|
scope
|
38
48
|
end
|
@@ -78,12 +88,14 @@ module GraphStarter
|
|
78
88
|
model_class_scope.has_images?
|
79
89
|
end
|
80
90
|
|
81
|
-
def model_class_scope
|
82
|
-
|
83
|
-
|
84
|
-
else
|
85
|
-
|
86
|
-
end
|
91
|
+
def model_class_scope(var = :asset)
|
92
|
+
#@model_class_scope = if defined?(current_user)
|
93
|
+
# model_class.authorized_for(current_user)
|
94
|
+
#else
|
95
|
+
# model_class.all(var)
|
96
|
+
#end
|
97
|
+
|
98
|
+
@model_class_scope ||= model_class.all(var)
|
87
99
|
end
|
88
100
|
end
|
89
101
|
end
|
@@ -117,8 +117,22 @@ module GraphStarter
|
|
117
117
|
end
|
118
118
|
|
119
119
|
|
120
|
+
def self.search_properties(*array)
|
121
|
+
if array.empty?
|
122
|
+
@search_properties || [name_property]
|
123
|
+
else
|
124
|
+
@search_properties = array
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
120
128
|
def self.for_query(query)
|
121
|
-
|
129
|
+
where_clause = self.search_properties.map do |property|
|
130
|
+
fail "Invalid property: #{property}" if attributes[property].nil?
|
131
|
+
"asset.#{property} =~ {query}"
|
132
|
+
end.join(' OR ')
|
133
|
+
|
134
|
+
query_string = query.strip.gsub(/\s+/, '.*')
|
135
|
+
all(:asset).where(where_clause).params(query: "(?i).*#{query_string}.*")
|
122
136
|
end
|
123
137
|
|
124
138
|
def secret_sauce_recommendations
|
@@ -9,7 +9,7 @@
|
|
9
9
|
.ui.divider
|
10
10
|
|
11
11
|
javascript:
|
12
|
-
var controller = #{@
|
12
|
+
var controller = #{@model_slug.to_json.html_safe}
|
13
13
|
|
14
14
|
coffee:
|
15
15
|
$('.ui.search').search
|
@@ -25,4 +25,4 @@
|
|
25
25
|
|
26
26
|
.ui.divider
|
27
27
|
|
28
|
-
= render partial: 'graph_starter/assets/cards', locals: {assets: @assets}
|
28
|
+
= render partial: 'graph_starter/assets/cards', locals: {assets: @assets}
|