the_jobbook_admin_data 1.3.0a
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/CHANGELOG.rdoc +284 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +121 -0
- data/Guardfile +14 -0
- data/MIT-LICENSE +20 -0
- data/README.md +37 -0
- data/README.rdoc +3 -0
- data/Rakefile +40 -0
- data/admin_data.gemspec +23 -0
- data/app/assets/images/add.png +0 -0
- data/app/assets/images/admin_data/.gitkeep +0 -0
- data/app/assets/images/no.png +0 -0
- data/app/assets/images/site.png +0 -0
- data/app/assets/images/sort_by_asc.jpg +0 -0
- data/app/assets/images/sort_by_desc.jpg +0 -0
- data/app/assets/images/sort_by_nothing.jpg +0 -0
- data/app/assets/javascripts/admin_data.js +18 -0
- data/app/assets/javascripts/admin_data/application.js +15 -0
- data/app/assets/javascripts/advance_search/act_on_result.js +45 -0
- data/app/assets/javascripts/advance_search/advance_search.js +83 -0
- data/app/assets/javascripts/advance_search/advance_search_structure.js +79 -0
- data/app/assets/javascripts/advance_search/ajaxify_advance_search.js +28 -0
- data/app/assets/javascripts/advance_search/build_first_row.js +8 -0
- data/app/assets/javascripts/advance_search/event_bindings.js +76 -0
- data/app/assets/javascripts/advance_search/global_ajax_setting.js +10 -0
- data/app/assets/javascripts/advance_search/sortby.js +14 -0
- data/app/assets/javascripts/advance_search/trigger_submit_on_domready.js +6 -0
- data/app/assets/javascripts/analytics/report.js +7 -0
- data/app/assets/javascripts/misc/drop_down_change.js +8 -0
- data/app/assets/javascripts/misc/js_util.js +58 -0
- data/app/assets/javascripts/misc/quick_search_input_focus.js +6 -0
- data/app/assets/javascripts/vendor/jquery-1.4.2.js +6240 -0
- data/app/assets/javascripts/vendor/jquery-ui-1.7.2.custom.min.js +298 -0
- data/app/assets/javascripts/vendor/jquery.ba-isjquery.js +21 -0
- data/app/assets/javascripts/vendor/jquery_form.js +814 -0
- data/app/assets/javascripts/vendor/log.js +9 -0
- data/app/assets/javascripts/vendor/rails.js +132 -0
- data/app/assets/stylesheets/admin_data.css +1141 -0
- data/app/assets/stylesheets/admin_data/application.css +13 -0
- data/app/assets/stylesheets/vendor/jquery-ui-1.7.2.custom.css +406 -0
- data/app/controllers/admin_data/application_controller.rb +107 -0
- data/app/controllers/admin_data/crud_controller.rb +100 -0
- data/app/controllers/admin_data/feed_controller.rb +48 -0
- data/app/controllers/admin_data/home_controller.rb +8 -0
- data/app/controllers/admin_data/migration_controller.rb +18 -0
- data/app/controllers/admin_data/public_controller.rb +28 -0
- data/app/controllers/admin_data/search_controller.rb +143 -0
- data/app/controllers/admin_data/table_structure_controller.rb +25 -0
- data/app/helpers/admin_data/application_helper.rb +320 -0
- data/app/views/admin_data/crud/association/_association_info.html.erb +11 -0
- data/app/views/admin_data/crud/association/_belongs_to_info.html.erb +7 -0
- data/app/views/admin_data/crud/association/_habtm_info.html.erb +7 -0
- data/app/views/admin_data/crud/association/_has_many_info.html.erb +7 -0
- data/app/views/admin_data/crud/association/_has_one_info.html.erb +6 -0
- data/app/views/admin_data/crud/edit.html.erb +36 -0
- data/app/views/admin_data/crud/misc/_form.html.erb +38 -0
- data/app/views/admin_data/crud/misc/_modify_record.html.erb +18 -0
- data/app/views/admin_data/crud/new.html.erb +25 -0
- data/app/views/admin_data/crud/show.html.erb +42 -0
- data/app/views/admin_data/feed/index.rss.builder +25 -0
- data/app/views/admin_data/home/index.html.erb +21 -0
- data/app/views/admin_data/migration/index.html.erb +18 -0
- data/app/views/admin_data/migration/jstest.html.erb +51 -0
- data/app/views/admin_data/search/advance_search.html.erb +1 -0
- data/app/views/admin_data/search/quick_search.html.erb +1 -0
- data/app/views/admin_data/search/search/_advance_search_form.html.erb +52 -0
- data/app/views/admin_data/search/search/_errors.html.erb +5 -0
- data/app/views/admin_data/search/search/_listing.html.erb +43 -0
- data/app/views/admin_data/search/search/_search_form.html.erb +27 -0
- data/app/views/admin_data/search/search/_title.html.erb +34 -0
- data/app/views/admin_data/shared/_breadcrum.html.erb +16 -0
- data/app/views/admin_data/shared/_drop_down_klasses.html.erb +4 -0
- data/app/views/admin_data/shared/_flash_message.html.erb +13 -0
- data/app/views/admin_data/shared/_header.html.erb +20 -0
- data/app/views/admin_data/shared/_powered_by.html.erb +6 -0
- data/app/views/admin_data/shared/_secondary_navigation.html.erb +26 -0
- data/app/views/admin_data/table_structure/index.html.erb +54 -0
- data/app/views/layouts/admin_data.html.erb +34 -0
- data/app/views/layouts/admin_data/application.html.erb +14 -0
- data/app/views/layouts/search.html.erb +71 -0
- data/config/routes.rb +32 -0
- data/lib/admin_data.rb +27 -0
- data/lib/admin_data/active_record_util.rb +102 -0
- data/lib/admin_data/analytics.rb +176 -0
- data/lib/admin_data/authenticator.rb +15 -0
- data/lib/admin_data/config.rb +38 -0
- data/lib/admin_data/configuration.rb +127 -0
- data/lib/admin_data/date_util.rb +58 -0
- data/lib/admin_data/engine.rb +17 -0
- data/lib/admin_data/model_finder.rb +15 -0
- data/lib/admin_data/rails_version_check.rb +8 -0
- data/lib/admin_data/search.rb +188 -0
- data/lib/admin_data/setup_config.rb +24 -0
- data/lib/admin_data/util.rb +102 -0
- data/lib/admin_data/version.rb +3 -0
- data/lib/tasks/admin_data_tasks.rake +4 -0
- data/script/rails +8 -0
- data/test/admin_data_test.rb +7 -0
- data/test/dummy/README.md +19 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +5 -0
- data/test/dummy/app/models/user.rb +3 -0
- data/test/dummy/app/models/user/student.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +15 -0
- data/test/dummy/config/boot.rb +13 -0
- data/test/dummy/config/cucumber.yml +9 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/database.yml.mysql +22 -0
- data/test/dummy/config/database.yml.pg +15 -0
- data/test/dummy/config/database.yml.sqlite3 +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +22 -0
- data/test/dummy/config/environments/production.rb +49 -0
- data/test/dummy/config/environments/test.rb +35 -0
- data/test/dummy/config/initializers/admin_data.rb +15 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/empty_spaces_to_nil.rb +10 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +9 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20091030202259_create_tables.rb +72 -0
- data/test/dummy/db/production.sqlite3 +1 -0
- data/test/dummy/db/schema.rb +23 -0
- data/test/dummy/db/seeds.rb +40 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/features/advance_search/boolean.feature +74 -0
- data/test/dummy/features/advance_search/datetime.feature +101 -0
- data/test/dummy/features/advance_search/delete_all.feature +20 -0
- data/test/dummy/features/advance_search/destroy_all.feature +20 -0
- data/test/dummy/features/advance_search/integer.feature +69 -0
- data/test/dummy/features/advance_search/multiple_rows.feature +87 -0
- data/test/dummy/features/advance_search/string.feature +130 -0
- data/test/dummy/features/crud.feature +50 -0
- data/test/dummy/features/crud_show.feature +56 -0
- data/test/dummy/features/feed.feature +13 -0
- data/test/dummy/features/home.feature +42 -0
- data/test/dummy/features/migration.feature +7 -0
- data/test/dummy/features/quick_search.feature +113 -0
- data/test/dummy/features/step_definitions/advance_search_steps.rb +13 -0
- data/test/dummy/features/step_definitions/app_steps.rb +36 -0
- data/test/dummy/features/step_definitions/async.rb +18 -0
- data/test/dummy/features/step_definitions/configuration_steps.rb +61 -0
- data/test/dummy/features/step_definitions/crud_show_steps.rb +37 -0
- data/test/dummy/features/step_definitions/feed_steps.rb +24 -0
- data/test/dummy/features/step_definitions/quick_search_steps.rb +68 -0
- data/test/dummy/features/step_definitions/util.rb +90 -0
- data/test/dummy/features/step_definitions/web_steps.rb +219 -0
- data/test/dummy/features/support/env.rb +66 -0
- data/test/dummy/features/support/hooks.rb +9 -0
- data/test/dummy/features/support/paths.rb +33 -0
- data/test/dummy/features/table_structure.feature +18 -0
- data/test/dummy/lib/tasks/.gitkeep +0 -0
- data/test/dummy/lib/tasks/cucumber.rake +53 -0
- data/test/dummy/lib/tasks/dbs.rake +30 -0
- data/test/dummy/lib/tasks/sample_cars.rake +18 -0
- data/test/dummy/public/.gitkeep +0 -0
- data/test/dummy/script/cucumber +10 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/factories.rb +30 -0
- data/test/dummy/test/test_helper.rb +7 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/admin_data/model_finder_test.rb +16 -0
- data/test/unit/car_test.rb +96 -0
- data/test/unit/user_phone_test.rb +19 -0
- metadata +253 -0
@@ -0,0 +1,8 @@
|
|
1
|
+
unless Rails.version >= '3.0'
|
2
|
+
msg = []
|
3
|
+
msg << "It seems you are not using Rails 3."
|
4
|
+
msg << "Please see documentation at"
|
5
|
+
msg << "http://github.com/neerajdotname/admin_data/wiki"
|
6
|
+
msg << "to find out how to use this gem with rails 2.3.x"
|
7
|
+
raise msg.join(' ')
|
8
|
+
end
|
@@ -0,0 +1,188 @@
|
|
1
|
+
module AdminData
|
2
|
+
module Search
|
3
|
+
|
4
|
+
class Dbbase
|
5
|
+
def initialize(operands, table_name, field_name, operator)
|
6
|
+
@operands = operands
|
7
|
+
@table_name = table_name
|
8
|
+
@field_name = field_name
|
9
|
+
@operator = operator
|
10
|
+
end
|
11
|
+
|
12
|
+
def like_operator
|
13
|
+
'LIKE'
|
14
|
+
end
|
15
|
+
|
16
|
+
def sql_field_name
|
17
|
+
"#{@table_name}.#{@field_name}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def operands
|
21
|
+
@operands
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class PostgresqlSpecific < Dbbase
|
26
|
+
def like_operator
|
27
|
+
'ILIKE'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class OracleSpecific < Dbbase
|
32
|
+
def sql_field_name
|
33
|
+
result = super
|
34
|
+
%w(contains is_exactly does_not_contain).include?(@operator) ? "upper(#{result})" : result
|
35
|
+
end
|
36
|
+
|
37
|
+
def operands
|
38
|
+
result = super
|
39
|
+
%w(contains is_exactly does_not_contain).include?(@operator) ? result.upcase : result
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Term
|
44
|
+
|
45
|
+
attr_accessor :error, :table_name, :field, :operator, :operands, :dbbase
|
46
|
+
|
47
|
+
def initialize(klass, value, search_type)
|
48
|
+
@table_name = klass.table_name
|
49
|
+
compute_search_fields(value)
|
50
|
+
|
51
|
+
adapter = AdminData.config.adapter_name.downcase
|
52
|
+
if adapter =~ /postgresql/
|
53
|
+
self.dbbase = PostgresqlSpecific.new(@operands, table_name, field, operator)
|
54
|
+
elsif adapter =~ /oracle/
|
55
|
+
self.dbbase = OracleSpecific.new(@operands, table_name, field, operator)
|
56
|
+
else
|
57
|
+
self.dbbase = Dbbase.new(@operands, table_name, field, operator)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def attribute_condition
|
62
|
+
return if valid? && operand_required? && operands.blank?
|
63
|
+
case operator
|
64
|
+
when 'contains'
|
65
|
+
["#{sql_field_name} #{like_operator} ?","%#{operands}%"]
|
66
|
+
|
67
|
+
when 'is_exactly'
|
68
|
+
["#{sql_field_name} = ?", operands]
|
69
|
+
|
70
|
+
when 'does_not_contain'
|
71
|
+
["#{sql_field_name} IS NULL OR #{sql_field_name} NOT #{like_operator} ?","%#{operands}%"]
|
72
|
+
|
73
|
+
when 'is_false'
|
74
|
+
["#{sql_field_name} = ?",false]
|
75
|
+
|
76
|
+
when 'is_true'
|
77
|
+
["#{sql_field_name} = ?",true]
|
78
|
+
|
79
|
+
when 'is_null'
|
80
|
+
["#{sql_field_name} IS NULL"]
|
81
|
+
|
82
|
+
when 'is_not_null'
|
83
|
+
["#{sql_field_name} IS NOT NULL"]
|
84
|
+
|
85
|
+
when 'is_on'
|
86
|
+
["#{sql_field_name} >= ? AND #{sql_field_name} < ?", values_after_cast.beginning_of_day,
|
87
|
+
values_after_cast.end_of_day]
|
88
|
+
|
89
|
+
when 'is_on_or_before_date'
|
90
|
+
["#{sql_field_name} <= ?",values_after_cast.end_of_day]
|
91
|
+
|
92
|
+
when 'is_on_or_after_date'
|
93
|
+
["#{sql_field_name} >= ?",values_after_cast.beginning_of_day]
|
94
|
+
|
95
|
+
when 'is_equal_to'
|
96
|
+
["#{sql_field_name} = ?",values_after_cast]
|
97
|
+
|
98
|
+
when 'greater_than'
|
99
|
+
["#{sql_field_name} > ?",values_after_cast]
|
100
|
+
|
101
|
+
when 'less_than'
|
102
|
+
["#{sql_field_name} < ?",values_after_cast]
|
103
|
+
|
104
|
+
else
|
105
|
+
# it means user did not select anything in operator. Ignore it.
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def valid?
|
110
|
+
@error = nil
|
111
|
+
@error = validate
|
112
|
+
@error.blank?
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def like_operator
|
118
|
+
dbbase.like_operator
|
119
|
+
end
|
120
|
+
|
121
|
+
def sql_field_name
|
122
|
+
dbbase.sql_field_name
|
123
|
+
end
|
124
|
+
|
125
|
+
def operands
|
126
|
+
dbbase.operands
|
127
|
+
end
|
128
|
+
|
129
|
+
def operand_required?
|
130
|
+
operator =~ /(contains|is_exactly|does_not_contain|is_on |is_on_or_before_date|is_on_or_after_date |greater_than|less_than|is_equal_to)/
|
131
|
+
end
|
132
|
+
|
133
|
+
def compute_search_fields(value)
|
134
|
+
@field, @operator, @operands = value.values_at(:col1, :col2, :col3)
|
135
|
+
# field value is directly used in the sql statement. So it is important to sanitize it
|
136
|
+
@field = @field.gsub(/\W/,'')
|
137
|
+
@operands = (@operands.blank? ? @operands : @operands.strip)
|
138
|
+
end
|
139
|
+
|
140
|
+
def values_after_cast
|
141
|
+
case operator
|
142
|
+
when /(is_on|is_on_or_before_date|is_on_or_after_date)/
|
143
|
+
AdminData::DateUtil.parse(operands)
|
144
|
+
when /(is_equal_to|greater_than|less_than)/
|
145
|
+
operands.to_i
|
146
|
+
else
|
147
|
+
operands
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def validate
|
152
|
+
case operator
|
153
|
+
when /(is_on|is_on_or_before_date|is_on_or_after_date)/
|
154
|
+
"#{operands} is not a valid date" unless AdminData::DateUtil.valid?(operands)
|
155
|
+
when /(is_equal_to|greater_than|less_than)/
|
156
|
+
unless operands.blank?
|
157
|
+
"#{operands} is not a valid integer" unless operands =~ /^\d+$/
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
end # end of Term
|
163
|
+
|
164
|
+
|
165
|
+
def build_quick_search_condition( klass, search_term )
|
166
|
+
return nil if search_term.blank?
|
167
|
+
str_columns = klass.columns.select { |column| column.type.to_s =~ /(string|text)/i }
|
168
|
+
conditions = str_columns.collect do |column|
|
169
|
+
t = Term.new(klass, {:col1 => column.name, :col2 => 'contains', :col3 => search_term}, 'quick_search')
|
170
|
+
t.attribute_condition
|
171
|
+
end
|
172
|
+
AdminData::Util.or_merge_conditions(klass, *conditions)
|
173
|
+
end
|
174
|
+
|
175
|
+
def build_advance_search_condition(klass, options)
|
176
|
+
values = ( options.blank? ? [] : options.values )
|
177
|
+
terms = values.collect {|value| Term.new(klass, value, 'advance_search') }
|
178
|
+
valid_terms = terms.select{ |t| t.valid? }
|
179
|
+
errors = (terms - valid_terms).collect { |t| t.error }
|
180
|
+
return {:errors => errors} if errors.any?
|
181
|
+
|
182
|
+
r = klass.unscoped
|
183
|
+
valid_terms.each { |t| r = r.where(t.attribute_condition) }
|
184
|
+
{ :cond => r }
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module AdminData
|
2
|
+
|
3
|
+
module SetupConfig
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
|
8
|
+
# See AdminData::Configuration for details.
|
9
|
+
attr_accessor :configuration
|
10
|
+
|
11
|
+
# Call this method to customize the behavior of admin_data .
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# AdminData.config do |config|
|
15
|
+
# config.number_of_records_per_page = 20
|
16
|
+
# end
|
17
|
+
def config
|
18
|
+
self.configuration ||= Configuration.new
|
19
|
+
block_given? ? yield(configuration) : configuration
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module AdminData
|
2
|
+
class Util
|
3
|
+
|
4
|
+
def self.label_values_pair_for(model, view)
|
5
|
+
data = model.class.columns.inject([]) do |sum, column|
|
6
|
+
tmp = view.get_value_for_column(column, model, :limit => nil)
|
7
|
+
sum << [ column.name, (tmp.html_safe? ? tmp : view.send(:h,tmp)) ]
|
8
|
+
end
|
9
|
+
data
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.custom_value_for_column(column, model)
|
13
|
+
# some would say that if I use try method then I will not be raising exception and
|
14
|
+
# I agree. However in this case for clarity I would prefer to not to have try after each call
|
15
|
+
begin
|
16
|
+
column_name = column.respond_to?(:name) ? column.name : column
|
17
|
+
tmp = AdminData.config.column_settings[model.class.name.to_s]
|
18
|
+
_proc = tmp.fetch(column_name.intern)
|
19
|
+
_proc.call(model)
|
20
|
+
rescue
|
21
|
+
model.send(column_name)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.get_serialized_value(html, column_value)
|
26
|
+
html << %{ <i>Cannot edit serialized field.</i> }
|
27
|
+
unless column_value.blank?
|
28
|
+
html << %{ <i>Raw contents:</i><br/> }
|
29
|
+
html << column_value.inspect
|
30
|
+
end
|
31
|
+
html.join
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.pluralize(count, text)
|
35
|
+
count > 1 ? text+'s' : text
|
36
|
+
end
|
37
|
+
|
38
|
+
# Rails method merge_conditions ANDs all the conditions. I need to ORs all the conditions
|
39
|
+
def self.or_merge_conditions(klass, *conditions)
|
40
|
+
s = ') OR ('
|
41
|
+
cond = conditions.inject([]) do |sum, condition|
|
42
|
+
condition.blank? ? sum : sum << klass.send(:sanitize_sql, condition)
|
43
|
+
end.compact.join(s)
|
44
|
+
"(#{cond})" unless cond.blank?
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.camelize_constantize(klassu)
|
48
|
+
klasss = klassu.camelize
|
49
|
+
self.constantize_klass(klasss)
|
50
|
+
end
|
51
|
+
|
52
|
+
# klass_name = model_name.sub(/\.rb$/,'').camelize
|
53
|
+
# constantize_klass(klass_name)
|
54
|
+
def self.constantize_klass(klass_name)
|
55
|
+
klass_name.split('::').inject(Object) do |klass, part|
|
56
|
+
klass.const_get(part)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Usage: write 'hello world' to tmp/hello.txt file
|
61
|
+
# Util.write_to_file('hello world', 'a+', 'tmp', 'hello.txt')
|
62
|
+
def self.write_to_file(data, mode, *path)
|
63
|
+
path = File.expand_path(Rails.root.join(*path.flatten.compact))
|
64
|
+
FileUtils.mkdir_p(File.dirname(path))
|
65
|
+
File.open(path, mode) {|fh| fh.puts(data) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.string_representation_of_data(value)
|
69
|
+
case value
|
70
|
+
when BigDecimal
|
71
|
+
value.to_s
|
72
|
+
when Date, DateTime, Time
|
73
|
+
"'#{value.to_s(:db)}'"
|
74
|
+
else
|
75
|
+
value.inspect
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.build_sort_options(klass, sortby)
|
80
|
+
klass.columns.inject('') do |result, column|
|
81
|
+
name = column.name
|
82
|
+
|
83
|
+
selected_text = (sortby == "#{name} desc") ? "selected='selected'" : ''
|
84
|
+
result << "<option value='#{name} desc' #{selected_text}>#{name} desc</option>"
|
85
|
+
|
86
|
+
selected_text = (sortby == "#{name} asc") ? "selected='selected'" : ''
|
87
|
+
result << "<option value='#{name} asc' #{selected_text}>#{name} asc</option>"
|
88
|
+
end.html_safe
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.associations_for(klass, association_type)
|
92
|
+
klass.name.camelize.constantize.reflections.values.select do |value|
|
93
|
+
value.macro == association_type
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.exception_info(e)
|
98
|
+
"#{e.class}: #{e.message}#$/#{e.backtrace.join($/)}"
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
data/script/rails
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
3
|
+
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/admin_data/engine', __FILE__)
|
6
|
+
|
7
|
+
require 'rails/all'
|
8
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Test setup #
|
2
|
+
|
3
|
+
bundle install
|
4
|
+
rake db:migrate
|
5
|
+
rake db:test:prepare
|
6
|
+
|
7
|
+
# Cucumber test #
|
8
|
+
|
9
|
+
bundle exec cucumber
|
10
|
+
|
11
|
+
# Unit test #
|
12
|
+
|
13
|
+
ruby -I test test/unit/car_test.rb
|
14
|
+
|
15
|
+
# Switch database #
|
16
|
+
|
17
|
+
rake db:use:pg
|
18
|
+
rake db:use:sqlite3
|
19
|
+
rake db:use:mysql
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require File.expand_path('../config/application', __FILE__)
|
5
|
+
require 'rake'
|
6
|
+
|
7
|
+
AdminDataDemo::Application.load_tasks
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# If you have a Gemfile, require the gems listed there, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(:default, Rails.env) if defined?(Bundler)
|
8
|
+
|
9
|
+
module AdminDataDemo
|
10
|
+
class Application < Rails::Application
|
11
|
+
config.time_zone = 'Central Time (US & Canada)'
|
12
|
+
config.encoding = "utf-8"
|
13
|
+
config.filter_parameters += [:password]
|
14
|
+
end
|
15
|
+
end
|