admin_assistant 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +3 -28
- data/Rakefile +18 -10
- data/init.rb +1 -0
- data/install.rb +5 -1
- data/lib/admin_assistant/active_record_column.rb +211 -0
- data/lib/admin_assistant/association_target.rb +35 -0
- data/lib/admin_assistant/belongs_to_column.rb +186 -0
- data/lib/admin_assistant/builder.rb +222 -35
- data/lib/admin_assistant/column.rb +266 -297
- data/lib/admin_assistant/default_search_column.rb +41 -0
- data/lib/admin_assistant/file_column_column.rb +73 -0
- data/lib/admin_assistant/form_view.rb +7 -68
- data/lib/admin_assistant/helper.rb +4 -2
- data/lib/admin_assistant/index.rb +101 -81
- data/lib/admin_assistant/paperclip_column.rb +45 -0
- data/lib/admin_assistant/polymorphic_belongs_to_column.rb +102 -0
- data/lib/admin_assistant/request/autocomplete.rb +47 -0
- data/lib/admin_assistant/request/base.rb +176 -0
- data/lib/admin_assistant/request/create.rb +27 -0
- data/lib/admin_assistant/request/destroy.rb +15 -0
- data/lib/admin_assistant/request/edit.rb +11 -0
- data/lib/admin_assistant/request/index.rb +26 -0
- data/lib/admin_assistant/request/new.rb +19 -0
- data/lib/admin_assistant/request/show.rb +24 -0
- data/lib/admin_assistant/request/update.rb +44 -0
- data/lib/admin_assistant/search.rb +82 -0
- data/lib/admin_assistant/show_view.rb +20 -0
- data/lib/admin_assistant/virtual_column.rb +61 -0
- data/lib/admin_assistant.rb +190 -85
- data/lib/javascripts/admin_assistant.js +253 -0
- data/lib/stylesheets/activescaffold.css +219 -0
- data/lib/stylesheets/default.css +119 -0
- data/lib/views/_polymorphic_field_search.html.erb +89 -0
- data/lib/views/_restricted_autocompleter.html.erb +53 -0
- data/lib/views/autocomplete.html.erb +11 -0
- data/lib/views/form.html.erb +6 -3
- data/lib/views/index.html.erb +53 -46
- data/lib/views/show.html.erb +19 -0
- data/vendor/ar_query/MIT-LICENSE +20 -0
- data/vendor/ar_query/README +0 -0
- data/vendor/ar_query/init.rb +1 -0
- data/vendor/ar_query/install.rb +1 -0
- data/vendor/ar_query/lib/ar_query.rb +137 -0
- data/vendor/ar_query/spec/ar_query_spec.rb +253 -0
- data/vendor/ar_query/tasks/ar_query_tasks.rake +0 -0
- data/vendor/ar_query/uninstall.rb +1 -0
- metadata +39 -16
- data/lib/admin_assistant/request.rb +0 -183
- data/lib/stylesheets/admin_assistant.css +0 -75
@@ -1,83 +1,163 @@
|
|
1
1
|
class AdminAssistant
|
2
2
|
class Column
|
3
|
-
|
3
|
+
def blank?(search)
|
4
|
+
search.params["#{name}(blank)"] == '1'
|
5
|
+
end
|
4
6
|
|
5
|
-
def
|
6
|
-
|
7
|
-
klass.new self, action_view, opts
|
7
|
+
def comparator(search)
|
8
|
+
search.params["#{name}(comparator)"]
|
8
9
|
end
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
|
11
|
+
def form_view(action_view, admin_assistant, opts = {})
|
12
|
+
view 'FormView', action_view, admin_assistant, opts
|
13
|
+
end
|
14
|
+
|
15
|
+
def index_view(action_view, admin_assistant, opts = {})
|
16
|
+
view 'IndexView', action_view, admin_assistant, opts
|
17
|
+
end
|
18
|
+
|
19
|
+
def search_view(action_view, admin_assistant, opts = {})
|
20
|
+
view 'SearchView', action_view, admin_assistant, opts
|
21
|
+
end
|
22
|
+
|
23
|
+
def show_view(action_view, admin_assistant, opts = {})
|
24
|
+
view 'ShowView', action_view, admin_assistant, opts
|
25
|
+
end
|
26
|
+
|
27
|
+
def verify_for_search
|
28
|
+
# nothing here, maybe implemented in subclasses
|
29
|
+
end
|
30
|
+
|
31
|
+
def view(view_class_name, action_view, admin_assistant, opts)
|
32
|
+
klass = begin
|
33
|
+
self.class.const_get view_class_name
|
34
|
+
rescue NameError
|
35
|
+
AdminAssistant::Column.const_get view_class_name
|
20
36
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
37
|
+
klass.new self, action_view, admin_assistant, opts
|
38
|
+
end
|
39
|
+
|
40
|
+
module FormViewMethods
|
41
|
+
def description
|
42
|
+
@description
|
24
43
|
end
|
25
44
|
|
26
|
-
def
|
27
|
-
|
45
|
+
def after_html(rails_form)
|
46
|
+
after = render_from_custom_template("_after_#{name}_input", rails_form)
|
47
|
+
if after
|
48
|
+
after
|
49
|
+
else
|
50
|
+
helper_method = "after_#{name}_input"
|
51
|
+
if @action_view.respond_to?(helper_method)
|
52
|
+
@action_view.send(helper_method, rails_form.object)
|
53
|
+
end
|
54
|
+
end
|
28
55
|
end
|
29
|
-
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
56
|
+
|
57
|
+
def controller
|
58
|
+
@action_view.controller
|
59
|
+
end
|
60
|
+
|
61
|
+
def html(rails_form)
|
62
|
+
record = rails_form.object
|
63
|
+
hff = render_from_custom_template "_#{name}_input", rails_form
|
64
|
+
hff ||= html_from_helper_method(record)
|
65
|
+
hff ||= if @read_only
|
66
|
+
value record
|
67
|
+
elsif @write_once && @action_view.action_name == 'edit'
|
68
|
+
value record
|
34
69
|
else
|
35
|
-
|
70
|
+
default_html rails_form
|
71
|
+
end
|
72
|
+
if ah = after_html(rails_form)
|
73
|
+
hff << ah
|
74
|
+
end
|
75
|
+
hff
|
76
|
+
end
|
77
|
+
|
78
|
+
def html_from_helper_method(record)
|
79
|
+
html_method = "#{name}_input"
|
80
|
+
if @action_view.respond_to?(html_method)
|
81
|
+
@action_view.send(html_method, record)
|
36
82
|
end
|
37
83
|
end
|
38
84
|
|
39
|
-
def
|
85
|
+
def render_from_custom_template(slug, rails_form)
|
86
|
+
abs_template_file = File.join(
|
87
|
+
RAILS_ROOT, 'app/views', controller.controller_path,
|
88
|
+
"#{slug}.html.erb"
|
89
|
+
)
|
90
|
+
if File.exist?(abs_template_file)
|
91
|
+
template = if RAILS_GEM_VERSION == '2.1.0'
|
92
|
+
File.join(controller.controller_path, "#{slug}.html.erb")
|
93
|
+
else
|
94
|
+
abs_template_file
|
95
|
+
end
|
96
|
+
varname = @model_class.name.underscore
|
97
|
+
@action_view.instance_variable_set(
|
98
|
+
"@#{varname}".to_sym, rails_form.object
|
99
|
+
)
|
100
|
+
@action_view.render(
|
101
|
+
:file => template,
|
102
|
+
:locals => {
|
103
|
+
varname.to_sym => rails_form.object,
|
104
|
+
:form => rails_form
|
105
|
+
}
|
106
|
+
)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def set_instance_variables_from_options(admin_assistant, opts)
|
111
|
+
setting = admin_assistant.form_settings[name.to_sym]
|
112
|
+
@clear_link = setting.clear_link
|
113
|
+
@description = setting.description
|
114
|
+
@datetime_select_options = setting.datetime_select_options || {}
|
115
|
+
@date_select_options = setting.date_select_options || {}
|
116
|
+
fum_name = name + '_url'
|
117
|
+
if @action_view.respond_to?(fum_name)
|
118
|
+
@file_url_method = @action_view.method(fum_name)
|
119
|
+
end
|
120
|
+
@image_size = setting.image_size
|
121
|
+
@input = setting.input
|
122
|
+
@polymorphic_types = admin_assistant[name.to_sym].polymorphic_types
|
123
|
+
@read_only = setting.read_only?
|
124
|
+
@select_options = setting.select_options || {}
|
125
|
+
unless @select_options.has_key?(:include_blank)
|
126
|
+
@select_options[:include_blank] = true
|
127
|
+
end
|
128
|
+
@text_area_options = setting.text_area_options || {}
|
129
|
+
@write_once = setting.write_once?
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
module IndexViewMethods
|
134
|
+
def header_css_class
|
40
135
|
"sort #{sort_order}" if sort_order
|
41
136
|
end
|
42
137
|
|
43
|
-
def
|
138
|
+
def td_css_class
|
44
139
|
'sort' if sort_order
|
45
140
|
end
|
46
141
|
|
47
|
-
def
|
142
|
+
def unconfigured_html(record)
|
143
|
+
@action_view.send(:h, string(record))
|
144
|
+
end
|
145
|
+
|
146
|
+
def html(record)
|
48
147
|
html_for_index_method = "#{name}_html_for_index"
|
49
148
|
html = if @action_view.respond_to?(html_for_index_method)
|
50
149
|
@action_view.send html_for_index_method, record
|
51
150
|
elsif @link_to_args
|
52
151
|
@action_view.link_to(
|
53
|
-
@action_view.send(:h,
|
152
|
+
@action_view.send(:h, string(record)),
|
54
153
|
@link_to_args.call(record)
|
55
154
|
)
|
56
155
|
else
|
57
|
-
|
156
|
+
unconfigured_html(record)
|
58
157
|
end
|
59
158
|
html = ' ' if html.blank?
|
60
159
|
html
|
61
160
|
end
|
62
|
-
|
63
|
-
def index_value(record)
|
64
|
-
value_method = "#{@column.name}_value"
|
65
|
-
if @action_view.respond_to?(value_method)
|
66
|
-
@action_view.send value_method, record
|
67
|
-
else
|
68
|
-
field_value record
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
def label
|
73
|
-
if @column.custom_label
|
74
|
-
@column.custom_label
|
75
|
-
elsif @column.name.to_s == 'id'
|
76
|
-
'ID'
|
77
|
-
else
|
78
|
-
@column.name.to_s.capitalize.gsub(/_/, ' ')
|
79
|
-
end
|
80
|
-
end
|
81
161
|
|
82
162
|
def next_sort_params
|
83
163
|
name_for_sort = name
|
@@ -90,294 +170,183 @@ class AdminAssistant
|
|
90
170
|
next_sort_order = nil
|
91
171
|
end
|
92
172
|
end
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
def paperclip?
|
97
|
-
@column.is_a?(PaperclipColumn)
|
173
|
+
@action_view.params.merge(
|
174
|
+
:sort => name_for_sort, :sort_order => next_sort_order
|
175
|
+
)
|
98
176
|
end
|
99
177
|
|
100
|
-
def
|
101
|
-
|
178
|
+
def set_instance_variables_from_options(admin_assistant, opts)
|
179
|
+
index = opts[:index]
|
180
|
+
setting = admin_assistant.index_settings[name.to_sym]
|
181
|
+
@link_to_args = setting.link_to_args
|
182
|
+
@sort_order = index.sort_order if name == index.sort
|
183
|
+
@image_size = setting.image_size
|
184
|
+
@ajax_toggle_allowed = admin_assistant.update?
|
102
185
|
end
|
103
186
|
end
|
104
|
-
end
|
105
|
-
|
106
|
-
class ActiveRecordColumn < Column
|
107
|
-
attr_accessor :search_terms
|
108
187
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
unless @search_terms.blank?
|
115
|
-
ar_query.boolean_join = :and
|
116
|
-
case sql_type
|
117
|
-
when :boolean
|
118
|
-
ar_query.condition_sqls << "#{name} = ?"
|
119
|
-
ar_query.bind_vars << search_value
|
120
|
-
else
|
121
|
-
ar_query.condition_sqls << "#{name} like ?"
|
122
|
-
ar_query.bind_vars << "%#{@search_terms}%"
|
188
|
+
module SearchViewMethods
|
189
|
+
def set_instance_variables_from_options(admin_assistant, opts)
|
190
|
+
setting = admin_assistant.search_settings[name.to_sym]
|
191
|
+
unless setting.comparators == false
|
192
|
+
@comparators = :all
|
123
193
|
end
|
194
|
+
@search = opts[:search]
|
195
|
+
@blank_checkbox = setting.blank_checkbox
|
124
196
|
end
|
125
197
|
end
|
126
198
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
def search_value
|
136
|
-
case sql_type
|
137
|
-
when :boolean
|
138
|
-
@search_terms.blank? ? nil : (@search_terms == 'true')
|
199
|
+
module SimpleColumnSearchViewMethods
|
200
|
+
include SearchViewMethods
|
201
|
+
|
202
|
+
def boolean_input(form)
|
203
|
+
opts = [['', nil]]
|
204
|
+
if @boolean_labels
|
205
|
+
opts << [@boolean_labels.first, true]
|
206
|
+
opts << [@boolean_labels.last, false]
|
139
207
|
else
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
def sql_type
|
145
|
-
@ar_column.type
|
146
|
-
end
|
147
|
-
|
148
|
-
class View < AdminAssistant::Column::View
|
149
|
-
def initialize(column, action_view, opts)
|
150
|
-
super
|
151
|
-
@boolean_labels = opts[:boolean_labels]
|
208
|
+
opts << ['true', true]
|
209
|
+
opts << ['false', false]
|
210
|
+
end
|
211
|
+
form.select(name, opts)
|
152
212
|
end
|
153
213
|
|
154
|
-
def
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
when :datetime
|
161
|
-
form.datetime_select name, :include_blank => true
|
162
|
-
when :date
|
163
|
-
form.date_select name, :include_blank => true
|
164
|
-
when :us_state
|
165
|
-
form.select(
|
166
|
-
name, ordered_us_state_names_and_codes, :include_blank => true
|
167
|
-
)
|
168
|
-
else
|
169
|
-
form.text_field name
|
214
|
+
def comparator_html(search)
|
215
|
+
selected_comparator = @column.comparator(search) || '='
|
216
|
+
option_tags = comparator_opts.map { |text, value|
|
217
|
+
opt = "<option value=\"#{value}\""
|
218
|
+
if selected_comparator == value
|
219
|
+
opt << " selected=\"selected\""
|
170
220
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
def index_value(record)
|
178
|
-
value = super
|
179
|
-
if @boolean_labels
|
180
|
-
value = value ? @boolean_labels.first : @boolean_labels.last
|
181
|
-
end
|
182
|
-
value
|
221
|
+
opt << ">#{text}</option>"
|
222
|
+
}.join("\n")
|
223
|
+
@action_view.select_tag(
|
224
|
+
"search[#{name}(comparator)]", option_tags
|
225
|
+
)
|
183
226
|
end
|
184
227
|
|
185
|
-
def
|
186
|
-
|
187
|
-
'
|
188
|
-
'
|
189
|
-
'
|
190
|
-
|
191
|
-
'Hawaii' => 'HI', 'Idaho' => 'ID', 'Illinois' => 'IL',
|
192
|
-
'Indiana' => 'IN', 'Iowa' => 'IA', 'Kansas' => 'KS',
|
193
|
-
'Kentucky' => 'KY', 'Louisiana' => 'LA', 'Maine' => 'ME',
|
194
|
-
'Maryland' => 'MD', 'Massachusetts' => 'MA', 'Michigan' => 'MI',
|
195
|
-
'Minnesota' => 'MN', 'Mississippi' => 'MS', 'Missouri' => 'MO',
|
196
|
-
'Montana' => 'MT', 'Nebraska' => 'NE', 'Nevada' => 'NV',
|
197
|
-
'New Hampshire' => 'NH', 'New Jersey' => 'NJ', 'New Mexico' => 'NM',
|
198
|
-
'New York' => 'NY', 'North Carolina' => 'NC', 'North Dakota' => 'ND',
|
199
|
-
'Ohio' => 'OH', 'Oklahoma' => 'OK', 'Oregon' => 'OR',
|
200
|
-
'Pennsylvania' => 'PA', 'Puerto Rico' => 'PR',
|
201
|
-
'Rhode Island' => 'RI', 'South Carolina' => 'SC',
|
202
|
-
'South Dakota' => 'SD', 'Tennessee' => 'TN', 'Texas' => 'TX',
|
203
|
-
'Utah' => 'UT', 'Vermont' => 'VT', 'Virginia' => 'VA',
|
204
|
-
'Washington' => 'WA', 'West Virginia' => 'WV', 'Wisconsin' => 'WI',
|
205
|
-
'Wyoming' => 'WY'
|
206
|
-
}.sort_by { |name, code| name }
|
228
|
+
def comparator_opts
|
229
|
+
[
|
230
|
+
['greater than', '>'], ['greater than or equal to', '>='],
|
231
|
+
['equal to', '='], ['less than or equal to', '<='],
|
232
|
+
['less than', '<']
|
233
|
+
]
|
207
234
|
end
|
208
235
|
|
209
|
-
def
|
210
|
-
input =
|
236
|
+
def html(form)
|
237
|
+
input = ''
|
238
|
+
case @column.field_type
|
211
239
|
when :boolean
|
212
|
-
|
213
|
-
if @boolean_labels
|
214
|
-
opts << [@boolean_labels.first, true]
|
215
|
-
opts << [@boolean_labels.last, false]
|
216
|
-
else
|
217
|
-
opts << ['true', true]
|
218
|
-
opts << ['false', false]
|
219
|
-
end
|
220
|
-
@action_view.select("search", name, opts)
|
240
|
+
input = boolean_input form
|
221
241
|
else
|
222
|
-
@
|
242
|
+
if @column.field_type == :integer && @comparators == :all
|
243
|
+
input << comparator_html(form.object) << ' '
|
244
|
+
end
|
245
|
+
input << form.text_field(name)
|
246
|
+
if @blank_checkbox
|
247
|
+
input << check_box_and_hidden_tags(
|
248
|
+
"search[#{name}(blank)]", @column.blank?(form.object)
|
249
|
+
)
|
250
|
+
input << "is blank"
|
251
|
+
end
|
223
252
|
end
|
224
253
|
"<p><label>#{label}</label> <br/>#{input}</p>"
|
225
254
|
end
|
226
255
|
end
|
227
|
-
end
|
228
|
-
|
229
|
-
class AdminAssistantColumn < Column
|
230
|
-
attr_reader :name
|
231
|
-
|
232
|
-
def initialize(name)
|
233
|
-
@name = name.to_s
|
234
|
-
end
|
235
|
-
|
236
|
-
def contains?(column_name)
|
237
|
-
column_name.to_s == @name
|
238
|
-
end
|
239
|
-
|
240
|
-
class View < AdminAssistant::Column::View
|
241
|
-
def field_value(record)
|
242
|
-
nil
|
243
|
-
end
|
244
|
-
end
|
245
|
-
end
|
246
|
-
|
247
|
-
class BelongsToColumn < Column
|
248
|
-
def initialize(belongs_to_assoc)
|
249
|
-
@belongs_to_assoc = belongs_to_assoc
|
250
|
-
end
|
251
|
-
|
252
|
-
def associated_class
|
253
|
-
@belongs_to_assoc.klass
|
254
|
-
end
|
255
|
-
|
256
|
-
def association_foreign_key
|
257
|
-
@belongs_to_assoc.association_foreign_key
|
258
|
-
end
|
259
256
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
def default_name_method
|
265
|
-
[:name, :title, :login, :username].detect { |m|
|
266
|
-
associated_class.columns.any? { |column| column.name.to_s == m.to_s }
|
267
|
-
}
|
268
|
-
end
|
269
|
-
|
270
|
-
def name
|
271
|
-
@belongs_to_assoc.name.to_s
|
272
|
-
end
|
273
|
-
|
274
|
-
def order_sql_field
|
275
|
-
sql = "#{@belongs_to_assoc.table_name}. "
|
276
|
-
sql << if default_name_method
|
277
|
-
default_name_method.to_s
|
278
|
-
else
|
279
|
-
@belongs_to_assoc.association_foreign_key
|
257
|
+
module ShowViewMethods
|
258
|
+
def html(record)
|
259
|
+
@action_view.send(:h, value(record))
|
280
260
|
end
|
281
261
|
end
|
282
|
-
|
283
|
-
class View
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
262
|
+
|
263
|
+
class View
|
264
|
+
attr_reader :sort_order
|
265
|
+
|
266
|
+
def initialize(column, action_view, admin_assistant, opts = {})
|
267
|
+
@column, @action_view, @opts = column, action_view, opts
|
268
|
+
@model_class = admin_assistant.model_class
|
269
|
+
base_setting = admin_assistant[name]
|
270
|
+
@boolean_labels = base_setting.boolean_labels
|
271
|
+
fem_name = name + '_exists?'
|
272
|
+
if @action_view.respond_to?(fem_name)
|
273
|
+
@file_exists_method = @action_view.method(fem_name)
|
274
|
+
end
|
275
|
+
@label = base_setting.label
|
276
|
+
@polymorphic_types = base_setting.polymorphic_types
|
277
|
+
if respond_to?(:set_instance_variables_from_options)
|
278
|
+
set_instance_variables_from_options(admin_assistant, opts)
|
279
|
+
end
|
292
280
|
end
|
293
|
-
|
294
|
-
def
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
281
|
+
|
282
|
+
def check_box_and_hidden_tags(input_name, value)
|
283
|
+
# Rails 2.3 wants the hidden tag to come before the checkbox, but it's
|
284
|
+
# the opposite for Rails 2.2 and 2.1
|
285
|
+
if RAILS_GEM_VERSION =~ /^2.3/
|
286
|
+
@action_view.send(:hidden_field_tag, input_name, '0') +
|
287
|
+
@action_view.send(:check_box_tag, input_name, '1', value)
|
288
|
+
else
|
289
|
+
@action_view.send(:check_box_tag, input_name, '1', value) +
|
290
|
+
@action_view.send(:hidden_field_tag, input_name, '0')
|
300
291
|
end
|
301
292
|
end
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
end
|
311
|
-
|
312
|
-
def add_to_query(ar_query)
|
313
|
-
unless @terms.blank?
|
314
|
-
ar_query.boolean_join = :or
|
315
|
-
searchable_columns.each do |column|
|
316
|
-
ar_query.condition_sqls << "#{column.name} like ?"
|
317
|
-
ar_query.bind_vars << "%#{@terms}%"
|
293
|
+
|
294
|
+
def label
|
295
|
+
if @label
|
296
|
+
@label
|
297
|
+
elsif @column.name.to_s == 'id'
|
298
|
+
'ID'
|
299
|
+
else
|
300
|
+
@column.name.to_s.capitalize.gsub(/_/, ' ')
|
318
301
|
end
|
319
302
|
end
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
@model_class.columns.select { |column|
|
324
|
-
[:string, :text].include?(column.type)
|
325
|
-
}
|
326
|
-
end
|
327
|
-
|
328
|
-
class View < AdminAssistant::Column::View
|
329
|
-
def search_html
|
330
|
-
@action_view.text_field_tag("search", @column.terms)
|
303
|
+
|
304
|
+
def name
|
305
|
+
@column.name
|
331
306
|
end
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
class FileColumnColumn < Column
|
336
|
-
attr_reader :name
|
337
|
-
|
338
|
-
def initialize(name)
|
339
|
-
@name = name.to_s
|
340
|
-
end
|
341
|
-
|
342
|
-
def contains?(column_name)
|
343
|
-
column_name.to_s == @name
|
344
|
-
end
|
345
|
-
|
346
|
-
class View < AdminAssistant::Column::View
|
347
|
-
def add_to_form(form)
|
348
|
-
form.file_field name
|
307
|
+
|
308
|
+
def paperclip?
|
309
|
+
@column.is_a?(PaperclipColumn)
|
349
310
|
end
|
350
311
|
|
351
|
-
def
|
352
|
-
@
|
353
|
-
|
354
|
-
|
355
|
-
|
312
|
+
def sort_possible?(total_entries)
|
313
|
+
@column.is_a?(ActiveRecordColumn) ||
|
314
|
+
(@column.is_a?(BelongsToColumn) && total_entries < 100_000)
|
315
|
+
end
|
316
|
+
|
317
|
+
def string(record)
|
318
|
+
string_method = "#{@column.name}_string"
|
319
|
+
if @action_view.respond_to?(string_method)
|
320
|
+
@action_view.send string_method, record
|
321
|
+
else
|
322
|
+
value = value(record)
|
323
|
+
if @boolean_labels
|
324
|
+
value ? @boolean_labels.first : @boolean_labels.last
|
325
|
+
else
|
326
|
+
value.to_s
|
327
|
+
end
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
def value(record)
|
332
|
+
record.send(name) if record.respond_to?(name)
|
356
333
|
end
|
357
334
|
end
|
358
|
-
end
|
359
|
-
|
360
|
-
class PaperclipColumn < Column
|
361
|
-
attr_reader :name
|
362
335
|
|
363
|
-
|
364
|
-
|
336
|
+
class FormView < View
|
337
|
+
include IndexViewMethods
|
338
|
+
end
|
339
|
+
|
340
|
+
class IndexView < View
|
341
|
+
include IndexViewMethods
|
365
342
|
end
|
366
343
|
|
367
|
-
|
368
|
-
|
369
|
-
column_name.to_s =~
|
370
|
-
/^#{@name}_(file_name|content_type|file_size|updated_at)$/
|
344
|
+
class SearchView < View
|
345
|
+
include SearchViewMethods
|
371
346
|
end
|
372
347
|
|
373
|
-
class
|
374
|
-
|
375
|
-
form.file_field name
|
376
|
-
end
|
377
|
-
|
378
|
-
def index_html(record)
|
379
|
-
@action_view.image_tag record.send(@column.name).url
|
380
|
-
end
|
348
|
+
class ShowView < View
|
349
|
+
include ShowViewMethods
|
381
350
|
end
|
382
351
|
end
|
383
352
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class AdminAssistant
|
2
|
+
class DefaultSearchColumn < Column
|
3
|
+
def initialize(model_class, opts)
|
4
|
+
@model_class = model_class
|
5
|
+
@fields_to_include = opts[:fields_to_include] || []
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_to_query_condition(ar_query_condition, search)
|
9
|
+
unless search.params.blank?
|
10
|
+
ar_query_condition.ar_query.boolean_join = :and
|
11
|
+
ar_query_condition.boolean_join = :or
|
12
|
+
names_to_search = Model.new(@model_class).searchable_columns.map(
|
13
|
+
&:name
|
14
|
+
)
|
15
|
+
names_to_search.concat @fields_to_include
|
16
|
+
names_to_search.uniq.each do |field_name|
|
17
|
+
ar_query_condition.sqls << "LOWER(#{field_name}) like LOWER(?)"
|
18
|
+
ar_query_condition.bind_vars << "%#{search.params}%"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def attributes_for_search_object(search_params)
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
|
27
|
+
def search_view(action_view, admin_assistant, opts={})
|
28
|
+
View.new self, action_view
|
29
|
+
end
|
30
|
+
|
31
|
+
class View
|
32
|
+
def initialize(column, action_view)
|
33
|
+
@column, @action_view = column, action_view
|
34
|
+
end
|
35
|
+
|
36
|
+
def html(form)
|
37
|
+
@action_view.text_field_tag("search", form.object.params)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|