will_filter 3.1.6 → 3.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- will_filter (3.1.6)
4
+ will_filter (3.1.7)
5
5
  coffee-script
6
6
  kaminari
7
7
  rails (>= 3.1.0)
@@ -70,7 +70,7 @@ module WillFilter
70
70
 
71
71
  wf_filter = WillFilter::Filter.deserialize_from_params(params)
72
72
  wf_filter.validate!
73
-
73
+
74
74
  unless wf_filter.errors?
75
75
  wf_filter.save
76
76
  end
@@ -458,8 +458,12 @@ module WillFilter
458
458
  if params[:wf_submitted] == 'true'
459
459
  validate!
460
460
  end
461
+
462
+ if WillFilter::Config.user_filters_enabled? and WillFilter::Config.current_user
463
+ self.user_id = WillFilter::Config.current_user.id
464
+ end
461
465
 
462
- return self
466
+ self
463
467
  end
464
468
 
465
469
  #############################################################################
@@ -515,6 +519,7 @@ module WillFilter
515
519
  0.upto(size - 1) do |index|
516
520
  condition = condition_at(index)
517
521
  next if custom_condition?(condition)
522
+ next unless condition.container
518
523
 
519
524
  sql_condition = condition.container.sql_condition
520
525
 
@@ -574,6 +579,24 @@ module WillFilter
574
579
  #############################################################################
575
580
  # Saved Filters
576
581
  #############################################################################
582
+
583
+ def user_filters
584
+ @user_filters ||= begin
585
+ conditions = ["model_class_name = ?", self.model_class_name]
586
+
587
+ if WillFilter::Config.user_filters_enabled?
588
+ conditions[0] << " and user_id = ? "
589
+ if WillFilter::Config.current_user and WillFilter::Config.current_user.id
590
+ conditions << WillFilter::Config.current_user.id
591
+ else
592
+ conditions << "0"
593
+ end
594
+ end
595
+
596
+ WillFilter::Filter.find(:all, :conditions => conditions)
597
+ end
598
+ end
599
+
577
600
  def saved_filters(include_default = true)
578
601
  @saved_filters ||= begin
579
602
  filters = []
@@ -585,26 +608,8 @@ module WillFilter
585
608
  end
586
609
  end
587
610
 
588
- if include_default
589
- conditions = ["type = ? and model_class_name = ?", self.class.name, self.model_class_name]
590
- else
591
- conditions = ["model_class_name = ?", self.model_class_name]
592
- end
593
-
594
- if WillFilter::Config.user_filters_enabled?
595
- conditions[0] << " and user_id = ? "
596
- if WillFilter::Config.current_user and WillFilter::Config.current_user.id
597
- conditions << WillFilter::Config.current_user.id
598
- else
599
- conditions << "0"
600
- end
601
- end
602
-
603
- user_filters = WillFilter::Filter.find(:all, :conditions => conditions)
604
-
605
- if user_filters.size > 0
611
+ if user_filters.any?
606
612
  filters << ["Select saved filter", "-2"] if include_default
607
-
608
613
  user_filters.each do |filter|
609
614
  filters << [filter.name, filter.id.to_s]
610
615
  end
@@ -613,7 +618,7 @@ module WillFilter
613
618
  filters
614
619
  end
615
620
  end
616
-
621
+
617
622
  #############################################################################
618
623
  # overload this method if you don't want to allow empty filters
619
624
  #############################################################################
@@ -23,9 +23,9 @@
23
23
  <% if wf_filter.show_save_options? %>
24
24
  <div class="end">
25
25
  <%=link_to_function("<span>Save As New...</span>".html_safe, "wfFilter.saveFilter()", :class => "wf_grey_button wf_pcb") %>
26
- <% if params[:wf_id] %>
27
- <%=link_to_function("<span>Update</span>".html_safe, "wfFilter.updateFilter()", :class => "wf_grey_button wf_pcb") %>
28
- <%=link_to_function("<span>Delete</span>".html_safe, "wfFilter.deleteFilter()", :class => "wf_grey_button wf_pcb") %>
26
+ <% if wf_filter.id %>
27
+ <%=link_to_function("<span>Update</span>".html_safe, "wfFilter.updateFilter()", :class => "wf_grey_button wf_pcb") %>
28
+ <%=link_to_function("<span>Delete</span>".html_safe, "wfFilter.deleteFilter()", :class => "wf_grey_button wf_pcb") %>
29
29
  <% end %>
30
30
  </div>
31
31
  <% end %>
@@ -39,9 +39,9 @@ module WillFilter
39
39
 
40
40
  def validate
41
41
  return "Start value must be provided" if start_value.blank?
42
- return "Start value must be a valid date/time (2008-01-01 14:30:00)" if start_time.nil?
42
+ return "Start value must be a valid date/time (2008-01-01 14:30:00)" if time(start_value).nil?
43
43
  return "End value must be provided" if end_value.blank?
44
- return "End value must be a valid date/time (2008-01-01 14:30:00)" if end_time.nil?
44
+ return "End value must be a valid date/time (2008-01-01 14:30:00)" if time(end_value).nil?
45
45
  end
46
46
 
47
47
  def sql_condition
@@ -35,23 +35,35 @@ module WillFilter
35
35
  def template_name
36
36
  'list'
37
37
  end
38
+
39
+ def linked_filter
40
+ @linked_filter ||= begin
41
+ if condition.key == :id
42
+ model_class_name = filter.model_class_name
43
+ else
44
+ model_class_name = condition.key.to_s[0..-4].camelcase
45
+ end
46
+ WillFilter::Filter.new(model_class_name)
47
+ end
48
+ end
38
49
 
39
50
  def options
40
- if condition.key == :id
41
- model_class_name = filter.model_class_name
42
- else
43
- model_class_name = condition.key.to_s[0..-4].camelcase
44
- end
45
-
46
- WillFilter::Filter.new(model_class_name).saved_filters(false)
51
+ linked_filter.saved_filters(false)
47
52
  end
48
53
 
49
54
  def sql_condition
50
55
  return nil unless operator == :is_filtered_by
51
- sub_filter = WillFilter::Filter.find_by_id(value)
56
+ sub_filter = WillFilter::Filter.find_by_id(value) || linked_filter.user_filters.first
57
+ return [""] unless sub_filter
58
+
52
59
  sub_conds = sub_filter.sql_conditions
53
- sub_sql = "SELECT #{sub_filter.table_name}.id FROM #{sub_filter.table_name} WHERE #{sub_conds[0]}"
54
- sub_conds[0] = " #{condition.full_key} IN (#{sub_sql}) "
60
+
61
+ if sub_conds[0].blank?
62
+ sub_conds[0] = " #{condition.full_key} IN (SELECT #{sub_filter.table_name}.id FROM #{sub_filter.table_name}) "
63
+ else
64
+ sub_conds[0] = " #{condition.full_key} IN (SELECT #{sub_filter.table_name}.id FROM #{sub_filter.table_name} WHERE #{sub_conds[0]}) "
65
+ end
66
+
55
67
  sub_conds
56
68
  end
57
69
  end
@@ -37,7 +37,7 @@ module WillFilter
37
37
  begin
38
38
  wf_current_user = eval(WillFilter::Config.current_user_method)
39
39
  rescue Exception => ex
40
- raise WillFilter::Exception.new("will_filter cannot be initialized because #{WillFilter::Config.current_user_method} failed with: #{ex.message}")
40
+ raise WillFilter::FilterException.new("will_filter cannot be initialized because #{WillFilter::Config.current_user_method} failed with: #{ex.message}")
41
41
  end
42
42
 
43
43
  WillFilter::Config.init(wf_current_user)
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module WillFilter
25
- VERSION = "3.1.6"
25
+ VERSION = "3.1.7"
26
26
  end
@@ -2,7 +2,12 @@ class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
3
 
4
4
  def current_user
5
- @current_user ||= User.new
5
+ # for testing purposes we just create a user and store it in the db
6
+ @current_user ||= begin
7
+ u = User.find_by_id(session[:user_id]) || User.create(:first_name =>"Michael")
8
+ session[:user_id] = u.id
9
+ u
10
+ end
6
11
  end
7
12
 
8
13
  end
@@ -19,7 +19,7 @@ defaults: &defaults
19
19
 
20
20
  save_options:
21
21
  enabled: true
22
- user_filters_enabled: false # if set to true, the filters will be private
22
+ user_filters_enabled: true # if set to true, the filters will be private
23
23
  user_class_name: User
24
24
  current_user_method: current_user
25
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: will_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.6
4
+ version: 3.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-06 00:00:00.000000000Z
12
+ date: 2012-04-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &2164951700 !ruby/object:Gem::Requirement
16
+ requirement: &2152943440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.1.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2164951700
24
+ version_requirements: *2152943440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: kaminari
27
- requirement: &2164948000 !ruby/object:Gem::Requirement
27
+ requirement: &2152940860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2164948000
35
+ version_requirements: *2152940860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sass
38
- requirement: &2164944880 !ruby/object:Gem::Requirement
38
+ requirement: &2152939700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2164944880
46
+ version_requirements: *2152939700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: coffee-script
49
- requirement: &2164941460 !ruby/object:Gem::Requirement
49
+ requirement: &2152938280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2164941460
57
+ version_requirements: *2152938280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &2164936460 !ruby/object:Gem::Requirement
60
+ requirement: &2152936520 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2164936460
68
+ version_requirements: *2152936520
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3
71
- requirement: &2164935220 !ruby/object:Gem::Requirement
71
+ requirement: &2152934600 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2164935220
79
+ version_requirements: *2152934600
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &2164933660 !ruby/object:Gem::Requirement
82
+ requirement: &2152932580 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2164933660
90
+ version_requirements: *2152932580
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec-rails
93
- requirement: &2164931900 !ruby/object:Gem::Requirement
93
+ requirement: &2152931400 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2164931900
101
+ version_requirements: *2152931400
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: factory_girl
104
- requirement: &2164861240 !ruby/object:Gem::Requirement
104
+ requirement: &2152916760 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2164861240
112
+ version_requirements: *2152916760
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rr
115
- requirement: &2164859840 !ruby/object:Gem::Requirement
115
+ requirement: &2152913860 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2164859840
123
+ version_requirements: *2152913860
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: steak
126
- requirement: &2164858760 !ruby/object:Gem::Requirement
126
+ requirement: &2152912020 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2164858760
134
+ version_requirements: *2152912020
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: capybara
137
- requirement: &2164857640 !ruby/object:Gem::Requirement
137
+ requirement: &2152909700 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *2164857640
145
+ version_requirements: *2152909700
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: database_cleaner
148
- requirement: &2164856120 !ruby/object:Gem::Requirement
148
+ requirement: &2152897720 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *2164856120
156
+ version_requirements: *2152897720
157
157
  description: will_filter is a powerful customizable framework for filtering active_record
158
158
  models.
159
159
  email:
@@ -188,7 +188,6 @@ files:
188
188
  - app/assets/stylesheets/will_filter/exporter.css.scss
189
189
  - app/assets/stylesheets/will_filter/filter.css.scss
190
190
  - app/assets/stylesheets/will_filter/results.css.scss
191
- - app/controllers/will_filter/application_controller.rb
192
191
  - app/controllers/will_filter/calendar_controller.rb
193
192
  - app/controllers/will_filter/exporter_controller.rb
194
193
  - app/controllers/will_filter/filter_controller.rb
@@ -363,7 +362,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
363
362
  version: '0'
364
363
  segments:
365
364
  - 0
366
- hash: -509527631151697114
365
+ hash: 3132715724976267421
367
366
  required_rubygems_version: !ruby/object:Gem::Requirement
368
367
  none: false
369
368
  requirements:
@@ -372,7 +371,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
372
371
  version: '0'
373
372
  segments:
374
373
  - 0
375
- hash: -509527631151697114
374
+ hash: 3132715724976267421
376
375
  requirements: []
377
376
  rubyforge_project: will_filter
378
377
  rubygems_version: 1.8.11
@@ -1,27 +0,0 @@
1
- #--
2
- # Copyright (c) 2010-2012 Michael Berkovich
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
23
-
24
- module WillFilter
25
- class ApplicationController < ActionController::Base
26
- end
27
- end