caboose-cms 0.2.99 → 0.2.100

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjZhMDhjMzMyMGJmOTFhMTFiOWRkNGZkNTMwYTE3ZDFiOGFiMGNiNg==
4
+ ZWU0MjQ4ZTg2ODI3ZDczYWQ3YzJjOTBkNWE2NzA5NzQ1NDMxZTM0Yg==
5
5
  data.tar.gz: !binary |-
6
- NTdhMmRjOGZhYjhhNzJiMWVkODUyY2Y0ZTUxNDEyMTY5NjIxM2YzNw==
6
+ ZDNhZTBhMDI2OWM1YTJhMzkyNWI5OWUyNmZkMzI2YjE5ZGRiM2Y4MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NjUwMjM5ZTk4ZjhiNmU0ODZmNTNkYTI3M2M0N2U3MDc4YzcyMDU3Nzk0MmU2
10
- ZWM4NDJjOTIwMWIxZDc0OTg5ZDk3ZTAwMzlkNjY1MTYzNTQ3ZTM1ZjljMjky
11
- ZDg2NTM4MWQxMDZmZTllODEzZmJlODRhNzJlM2Y0MjcxNGI0MmI=
9
+ NGU0Zjk5MTUxNGU4Y2RlZjQ0NzVmYWVmZGY4NmYyYjA3OTI4NjFkOGQ1MTdm
10
+ ZjU1YWQxZTU2YjFmZTA1YzdmYmMwNzgzOTU2NjhiMDkxYzVjOTgyMmU4NjZj
11
+ MzNkNTM0ODJlNmU1Y2RmNzU0YzMwOWRlYTJiNGRmZDk2N2YwN2I=
12
12
  data.tar.gz: !binary |-
13
- ZWE4N2IwOTExYzBlMTE5ODRiODQ0YWZiZGYyZmQxM2FmZTgxNmY5MDk3ZjVh
14
- Zjg0MmJiZjFlOGUwNjYyOWZhZWRlNDE0Mjg1YmUwZDdhNjFmMTBmZWJlNWM1
15
- NGFmMjZmMGQyNzVkOTY3ODI3OThhYmM2YmMyZDZmOWNmMThiZTQ=
13
+ MDc4ZWYwNTkwMzg1YTUyZGIxYTAxNzY0MGJlYzljNDhiN2NjODE0ZGFlNmFm
14
+ M2FjMjhmNGE2ZTBiOTAwYzlmY2IyODE4NTliYjk0NGU0MmNhYWFmOWI2NjMx
15
+ OTdjNDI5OTE0ODExYThiNTNlOWM4MWJkZTYzNDJiYzJlYzRjNGI=
@@ -0,0 +1,19 @@
1
+ module Caboose
2
+ module ProductsHelper
3
+
4
+ def average_review(product_id)
5
+ all_reviews = Review.where(:product_id => product_id)
6
+ score = 0
7
+ count = 0
8
+ all_reviews.each do |r|
9
+ if r.rating && r.rating != 0
10
+ score += r.rating
11
+ count += 1
12
+ end
13
+ end
14
+ return score/count if count > 0
15
+ return 0
16
+ end
17
+
18
+ end
19
+ end
@@ -1,3 +1,13 @@
1
+ # Note:
2
+ # For includes to work with namespaces other than the root namespace, the
3
+ # full namespaced class_name has to be set in the model on the association
4
+ # being included. For example:
5
+ #
6
+ # class Animals::Dog
7
+ # has_many :friends, :class_name => 'Animals::Dog'
8
+ # end
9
+ #
10
+
1
11
  module Caboose
2
12
  class PageBarGenerator
3
13
  #
@@ -28,14 +38,37 @@ module Caboose
28
38
  'base_url' => '',
29
39
  'page' => 1,
30
40
  'item_count' => 0,
31
- 'items_per_page' => 10
41
+ 'items_per_page' => 10,
42
+ 'includes' => nil # Hash of association includes
43
+ # {
44
+ # search_field_1 => [association_name, join_table, column_name],
45
+ # search_field_2 => [association_name, join_table, column_name]
46
+ # }
32
47
  }
33
48
  params.each { |key, val| @params[key] = val }
34
49
  options.each { |key, val| @options[key] = val }
35
50
  @params.each { |key, val| @params[key] = post_get[key].nil? ? val : post_get[key] }
36
51
  @options.each { |key, val| @options[key] = post_get[key].nil? ? val : post_get[key] }
37
52
  fix_desc
38
- @options['item_count'] = @options['model'].constantize.where(where).count
53
+
54
+ @options['item_count'] = model_with_includes.where(where).count
55
+ end
56
+
57
+ def model_with_includes
58
+ m = @options['model'].constantize
59
+ return m if @options['includes'].nil?
60
+
61
+ associations = []
62
+ @options['includes'].each do |field, arr|
63
+ next if @params[field].nil? || (@params[field].kind_of?(String) && @params[field].length == 0)
64
+ associations << arr[0]
65
+ end
66
+ associations.uniq.each { |assoc| m = m.includes(assoc) }
67
+ return m
68
+ end
69
+
70
+ def table_name_of_association(assoc)
71
+ return @options['model'].constantize.reflect_on_association(assoc.to_sym).class_name.constantize.table_name
39
72
  end
40
73
 
41
74
  def fix_desc
@@ -61,13 +94,25 @@ module Caboose
61
94
  return true
62
95
  end
63
96
 
64
- def items
65
- assoc = @options['model'].constantize.where(where)
97
+ def items
98
+ assoc = model_with_includes.where(where)
66
99
  if @options['items_per_page'] != -1
67
100
  assoc = assoc.limit(limit).offset(offset)
68
101
  end
69
102
  return assoc.reorder(reorder).all
70
103
  end
104
+
105
+ def all_items
106
+ return model_with_includes.where(where).all
107
+ end
108
+
109
+ def item_values(attribute)
110
+ arr = []
111
+ model_with_includes.where(where).all.each do |m|
112
+ arr << m[attribute]
113
+ end
114
+ return arr.uniq
115
+ end
71
116
 
72
117
  def generate
73
118
 
@@ -137,7 +182,8 @@ module Caboose
137
182
  vars.push("#{k}[]=#{v2}") if !v2.nil? && v2.length > 0
138
183
  end
139
184
  else
140
- vars.push("#{k}=#{v}") if !v.nil? && v.length > 0
185
+ next if v.nil? || (v.kind_of?(String) && v.length == 0)
186
+ vars.push("#{k}=#{v}")
141
187
  end
142
188
  end
143
189
  return URI.escape(vars.join('&'))
@@ -158,30 +204,45 @@ module Caboose
158
204
 
159
205
  def where
160
206
  sql = []
161
- values = []
207
+ values = []
208
+ table = @options['model'].constantize.table_name
162
209
  @params.each do |k,v|
163
- next if v.nil? || v.length == 0
210
+ next if v.nil? || (v.kind_of?(String) && v.length == 0)
211
+
212
+ col = nil
213
+ if @options['includes'] && @options['includes'].include?(k)
214
+ arr = @options['includes'][k]
215
+ col = "#{table_name_of_association(arr[0])}.#{arr[1]}"
216
+ end
164
217
 
165
218
  sql2 = ""
166
219
  if k.ends_with?('_gte')
167
- sql2 = "#{k[0..-5]} >= ?"
220
+ col = "#{table}.#{k[0..-5]}" if col.nil?
221
+ sql2 = "#{col} >= ?"
168
222
  elsif k.ends_with?('_gt')
169
- sql2 = "#{k[0..-4]} > ?"
223
+ col = "#{table}.#{k[0..-4]}" if col.nil?
224
+ sql2 = "#{col} > ?"
170
225
  elsif k.ends_with?('_lte')
171
- sql2 = "#{k[0..-5]} <= ?"
226
+ col = "#{table}.#{k[0..-5]}" if col.nil?
227
+ sql2 = "#{col} <= ?"
172
228
  elsif k.ends_with?('_lt')
173
- sql2 = "#{k[0..-4]} < ?"
229
+ col = "#{table}.#{k[0..-4]}" if col.nil?
230
+ sql2 = "#{col} < ?"
174
231
  elsif k.ends_with?('_bw')
175
- sql2 = "upper(#{k[0..-4]}) like ?"
232
+ col = "#{table}.#{k[0..-4]}" if col.nil?
233
+ sql2 = "upper(#{col}) like ?"
176
234
  v = v.kind_of?(Array) ? v.collect{ |v2| "#{v2}%".upcase } : "#{v}%".upcase
177
235
  elsif k.ends_with?('_ew')
178
- sql2 = "upper(#{k[0..-4]}) like ?"
236
+ col = "#{table}.#{k[0..-4]}" if col.nil?
237
+ sql2 = "upper(#{col}) like ?"
179
238
  v = v.kind_of?(Array) ? v.collect{ |v2| "%#{v2}".upcase } : "%#{v}".upcase
180
239
  elsif k.ends_with?('_like')
181
- sql2 = "upper(#{k[0..-6]}) like ?"
240
+ col = "#{table}.#{k[0..-6]}" if col.nil?
241
+ sql2 = "upper(#{col}) like ?"
182
242
  v = v.kind_of?(Array) ? v.collect{ |v2| "%#{v2}%".upcase } : "%#{v}%".upcase
183
- else
184
- sql2 = "#{k} = ?"
243
+ else
244
+ col = "#{table}.#{k}" if col.nil?
245
+ sql2 = "#{col} = ?"
185
246
  end
186
247
 
187
248
  if v.kind_of?(Array)
@@ -6,6 +6,11 @@ class Caboose::Utilities::Schema
6
6
  return nil
7
7
  end
8
8
 
9
+ # Columns (in order) that were removed in the development of the gem.
10
+ def self.removed_columns
11
+ return nil
12
+ end
13
+
9
14
  # Any column indexes that need to exist in the database
10
15
  def self.indexes
11
16
  return nil
@@ -29,7 +34,9 @@ class Caboose::Utilities::Schema
29
34
  def self.create_schema
30
35
  return if self.schema.nil?
31
36
 
32
- rename_tables
37
+ rename_tables
38
+ remove_columns
39
+
33
40
  c = ActiveRecord::Base.connection
34
41
  self.schema.each do |model, columns|
35
42
  tbl = model.table_name
@@ -53,6 +60,7 @@ class Caboose::Utilities::Schema
53
60
  else
54
61
 
55
62
  # Add a temp column
63
+ c.remove_column tbl, "#{col[0]}_temp" if c.column_exists?(tbl, "#{col[0]}_temp")
56
64
  if col.count > 2
57
65
  c.add_column tbl, "#{col[0]}_temp", col[1], col[2]
58
66
  else
@@ -105,6 +113,17 @@ class Caboose::Utilities::Schema
105
113
  self.renamed_tables.each do |old_name, new_name|
106
114
  c.rename_table old_name, new_name if c.table_exists?(old_name)
107
115
  end
108
- end
116
+ end
117
+
118
+ # Removes a set of tables
119
+ def self.remove_columns
120
+ return if self.removed_columns.nil?
121
+ c = ActiveRecord::Base.connection
122
+ self.removed_columns.each do |model, columns|
123
+ columns.each do |col|
124
+ c.remove_column model.table_name, col if c.column_exists?(model.table_name, col)
125
+ end
126
+ end
127
+ end
109
128
 
110
129
  end
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.2.99'
2
+ VERSION = '0.2.100'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.99
4
+ version: 0.2.100
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-07 00:00:00.000000000 Z
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -176,6 +176,7 @@ files:
176
176
  - app/helpers/caboose/application_helper.rb
177
177
  - app/helpers/caboose/pages_helper.rb
178
178
  - app/helpers/caboose/permissions_helper.rb
179
+ - app/helpers/caboose/products_helper.rb
179
180
  - app/models/caboose/approval_request.rb
180
181
  - app/models/caboose/asset.rb
181
182
  - app/models/caboose/authenticator.rb