the_jobbook_admin_data 1.3.0a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. data/.gitignore +19 -0
  2. data/CHANGELOG.rdoc +284 -0
  3. data/Gemfile +22 -0
  4. data/Gemfile.lock +121 -0
  5. data/Guardfile +14 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +37 -0
  8. data/README.rdoc +3 -0
  9. data/Rakefile +40 -0
  10. data/admin_data.gemspec +23 -0
  11. data/app/assets/images/add.png +0 -0
  12. data/app/assets/images/admin_data/.gitkeep +0 -0
  13. data/app/assets/images/no.png +0 -0
  14. data/app/assets/images/site.png +0 -0
  15. data/app/assets/images/sort_by_asc.jpg +0 -0
  16. data/app/assets/images/sort_by_desc.jpg +0 -0
  17. data/app/assets/images/sort_by_nothing.jpg +0 -0
  18. data/app/assets/javascripts/admin_data.js +18 -0
  19. data/app/assets/javascripts/admin_data/application.js +15 -0
  20. data/app/assets/javascripts/advance_search/act_on_result.js +45 -0
  21. data/app/assets/javascripts/advance_search/advance_search.js +83 -0
  22. data/app/assets/javascripts/advance_search/advance_search_structure.js +79 -0
  23. data/app/assets/javascripts/advance_search/ajaxify_advance_search.js +28 -0
  24. data/app/assets/javascripts/advance_search/build_first_row.js +8 -0
  25. data/app/assets/javascripts/advance_search/event_bindings.js +76 -0
  26. data/app/assets/javascripts/advance_search/global_ajax_setting.js +10 -0
  27. data/app/assets/javascripts/advance_search/sortby.js +14 -0
  28. data/app/assets/javascripts/advance_search/trigger_submit_on_domready.js +6 -0
  29. data/app/assets/javascripts/analytics/report.js +7 -0
  30. data/app/assets/javascripts/misc/drop_down_change.js +8 -0
  31. data/app/assets/javascripts/misc/js_util.js +58 -0
  32. data/app/assets/javascripts/misc/quick_search_input_focus.js +6 -0
  33. data/app/assets/javascripts/vendor/jquery-1.4.2.js +6240 -0
  34. data/app/assets/javascripts/vendor/jquery-ui-1.7.2.custom.min.js +298 -0
  35. data/app/assets/javascripts/vendor/jquery.ba-isjquery.js +21 -0
  36. data/app/assets/javascripts/vendor/jquery_form.js +814 -0
  37. data/app/assets/javascripts/vendor/log.js +9 -0
  38. data/app/assets/javascripts/vendor/rails.js +132 -0
  39. data/app/assets/stylesheets/admin_data.css +1141 -0
  40. data/app/assets/stylesheets/admin_data/application.css +13 -0
  41. data/app/assets/stylesheets/vendor/jquery-ui-1.7.2.custom.css +406 -0
  42. data/app/controllers/admin_data/application_controller.rb +107 -0
  43. data/app/controllers/admin_data/crud_controller.rb +100 -0
  44. data/app/controllers/admin_data/feed_controller.rb +48 -0
  45. data/app/controllers/admin_data/home_controller.rb +8 -0
  46. data/app/controllers/admin_data/migration_controller.rb +18 -0
  47. data/app/controllers/admin_data/public_controller.rb +28 -0
  48. data/app/controllers/admin_data/search_controller.rb +143 -0
  49. data/app/controllers/admin_data/table_structure_controller.rb +25 -0
  50. data/app/helpers/admin_data/application_helper.rb +320 -0
  51. data/app/views/admin_data/crud/association/_association_info.html.erb +11 -0
  52. data/app/views/admin_data/crud/association/_belongs_to_info.html.erb +7 -0
  53. data/app/views/admin_data/crud/association/_habtm_info.html.erb +7 -0
  54. data/app/views/admin_data/crud/association/_has_many_info.html.erb +7 -0
  55. data/app/views/admin_data/crud/association/_has_one_info.html.erb +6 -0
  56. data/app/views/admin_data/crud/edit.html.erb +36 -0
  57. data/app/views/admin_data/crud/misc/_form.html.erb +38 -0
  58. data/app/views/admin_data/crud/misc/_modify_record.html.erb +18 -0
  59. data/app/views/admin_data/crud/new.html.erb +25 -0
  60. data/app/views/admin_data/crud/show.html.erb +42 -0
  61. data/app/views/admin_data/feed/index.rss.builder +25 -0
  62. data/app/views/admin_data/home/index.html.erb +21 -0
  63. data/app/views/admin_data/migration/index.html.erb +18 -0
  64. data/app/views/admin_data/migration/jstest.html.erb +51 -0
  65. data/app/views/admin_data/search/advance_search.html.erb +1 -0
  66. data/app/views/admin_data/search/quick_search.html.erb +1 -0
  67. data/app/views/admin_data/search/search/_advance_search_form.html.erb +52 -0
  68. data/app/views/admin_data/search/search/_errors.html.erb +5 -0
  69. data/app/views/admin_data/search/search/_listing.html.erb +43 -0
  70. data/app/views/admin_data/search/search/_search_form.html.erb +27 -0
  71. data/app/views/admin_data/search/search/_title.html.erb +34 -0
  72. data/app/views/admin_data/shared/_breadcrum.html.erb +16 -0
  73. data/app/views/admin_data/shared/_drop_down_klasses.html.erb +4 -0
  74. data/app/views/admin_data/shared/_flash_message.html.erb +13 -0
  75. data/app/views/admin_data/shared/_header.html.erb +20 -0
  76. data/app/views/admin_data/shared/_powered_by.html.erb +6 -0
  77. data/app/views/admin_data/shared/_secondary_navigation.html.erb +26 -0
  78. data/app/views/admin_data/table_structure/index.html.erb +54 -0
  79. data/app/views/layouts/admin_data.html.erb +34 -0
  80. data/app/views/layouts/admin_data/application.html.erb +14 -0
  81. data/app/views/layouts/search.html.erb +71 -0
  82. data/config/routes.rb +32 -0
  83. data/lib/admin_data.rb +27 -0
  84. data/lib/admin_data/active_record_util.rb +102 -0
  85. data/lib/admin_data/analytics.rb +176 -0
  86. data/lib/admin_data/authenticator.rb +15 -0
  87. data/lib/admin_data/config.rb +38 -0
  88. data/lib/admin_data/configuration.rb +127 -0
  89. data/lib/admin_data/date_util.rb +58 -0
  90. data/lib/admin_data/engine.rb +17 -0
  91. data/lib/admin_data/model_finder.rb +15 -0
  92. data/lib/admin_data/rails_version_check.rb +8 -0
  93. data/lib/admin_data/search.rb +188 -0
  94. data/lib/admin_data/setup_config.rb +24 -0
  95. data/lib/admin_data/util.rb +102 -0
  96. data/lib/admin_data/version.rb +3 -0
  97. data/lib/tasks/admin_data_tasks.rake +4 -0
  98. data/script/rails +8 -0
  99. data/test/admin_data_test.rb +7 -0
  100. data/test/dummy/README.md +19 -0
  101. data/test/dummy/Rakefile +7 -0
  102. data/test/dummy/app/controllers/application_controller.rb +3 -0
  103. data/test/dummy/app/helpers/application_helper.rb +5 -0
  104. data/test/dummy/app/models/user.rb +3 -0
  105. data/test/dummy/app/models/user/student.rb +2 -0
  106. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  107. data/test/dummy/config.ru +4 -0
  108. data/test/dummy/config/application.rb +15 -0
  109. data/test/dummy/config/boot.rb +13 -0
  110. data/test/dummy/config/cucumber.yml +9 -0
  111. data/test/dummy/config/database.yml +25 -0
  112. data/test/dummy/config/database.yml.mysql +22 -0
  113. data/test/dummy/config/database.yml.pg +15 -0
  114. data/test/dummy/config/database.yml.sqlite3 +25 -0
  115. data/test/dummy/config/environment.rb +5 -0
  116. data/test/dummy/config/environments/development.rb +22 -0
  117. data/test/dummy/config/environments/production.rb +49 -0
  118. data/test/dummy/config/environments/test.rb +35 -0
  119. data/test/dummy/config/initializers/admin_data.rb +15 -0
  120. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  121. data/test/dummy/config/initializers/empty_spaces_to_nil.rb +10 -0
  122. data/test/dummy/config/initializers/inflections.rb +10 -0
  123. data/test/dummy/config/initializers/mime_types.rb +5 -0
  124. data/test/dummy/config/initializers/secret_token.rb +7 -0
  125. data/test/dummy/config/initializers/session_store.rb +8 -0
  126. data/test/dummy/config/locales/en.yml +5 -0
  127. data/test/dummy/config/routes.rb +9 -0
  128. data/test/dummy/db/development.sqlite3 +0 -0
  129. data/test/dummy/db/migrate/20091030202259_create_tables.rb +72 -0
  130. data/test/dummy/db/production.sqlite3 +1 -0
  131. data/test/dummy/db/schema.rb +23 -0
  132. data/test/dummy/db/seeds.rb +40 -0
  133. data/test/dummy/db/test.sqlite3 +0 -0
  134. data/test/dummy/features/advance_search/boolean.feature +74 -0
  135. data/test/dummy/features/advance_search/datetime.feature +101 -0
  136. data/test/dummy/features/advance_search/delete_all.feature +20 -0
  137. data/test/dummy/features/advance_search/destroy_all.feature +20 -0
  138. data/test/dummy/features/advance_search/integer.feature +69 -0
  139. data/test/dummy/features/advance_search/multiple_rows.feature +87 -0
  140. data/test/dummy/features/advance_search/string.feature +130 -0
  141. data/test/dummy/features/crud.feature +50 -0
  142. data/test/dummy/features/crud_show.feature +56 -0
  143. data/test/dummy/features/feed.feature +13 -0
  144. data/test/dummy/features/home.feature +42 -0
  145. data/test/dummy/features/migration.feature +7 -0
  146. data/test/dummy/features/quick_search.feature +113 -0
  147. data/test/dummy/features/step_definitions/advance_search_steps.rb +13 -0
  148. data/test/dummy/features/step_definitions/app_steps.rb +36 -0
  149. data/test/dummy/features/step_definitions/async.rb +18 -0
  150. data/test/dummy/features/step_definitions/configuration_steps.rb +61 -0
  151. data/test/dummy/features/step_definitions/crud_show_steps.rb +37 -0
  152. data/test/dummy/features/step_definitions/feed_steps.rb +24 -0
  153. data/test/dummy/features/step_definitions/quick_search_steps.rb +68 -0
  154. data/test/dummy/features/step_definitions/util.rb +90 -0
  155. data/test/dummy/features/step_definitions/web_steps.rb +219 -0
  156. data/test/dummy/features/support/env.rb +66 -0
  157. data/test/dummy/features/support/hooks.rb +9 -0
  158. data/test/dummy/features/support/paths.rb +33 -0
  159. data/test/dummy/features/table_structure.feature +18 -0
  160. data/test/dummy/lib/tasks/.gitkeep +0 -0
  161. data/test/dummy/lib/tasks/cucumber.rake +53 -0
  162. data/test/dummy/lib/tasks/dbs.rake +30 -0
  163. data/test/dummy/lib/tasks/sample_cars.rake +18 -0
  164. data/test/dummy/public/.gitkeep +0 -0
  165. data/test/dummy/script/cucumber +10 -0
  166. data/test/dummy/script/rails +6 -0
  167. data/test/dummy/test/factories.rb +30 -0
  168. data/test/dummy/test/test_helper.rb +7 -0
  169. data/test/integration/navigation_test.rb +10 -0
  170. data/test/test_helper.rb +15 -0
  171. data/test/unit/admin_data/model_finder_test.rb +16 -0
  172. data/test/unit/car_test.rb +96 -0
  173. data/test/unit/user_phone_test.rb +19 -0
  174. metadata +253 -0
@@ -0,0 +1,176 @@
1
+ require "active_support/all"
2
+
3
+ module AdminData
4
+ module Analytics
5
+
6
+ # a utility class to handle date interpolation for different databases
7
+ class Dater
8
+ attr_accessor :adapter, :type
9
+
10
+ def initialize(adapter, type = 'daily')
11
+ @adapter = adapter
12
+ @type = type
13
+ end
14
+
15
+ def date_select_key
16
+ "date_data"
17
+ end
18
+
19
+ def group_by_key
20
+ if adapter =~ /postgresql/i
21
+ self.type == 'monthly' ? "date_part('year', created_at), date_part('month', created_at)" : "date_data"
22
+ elsif adapter =~ /mysql/i
23
+ self.type == 'monthly' ? "YEAR(created_at), MONTH(created_at)" : "date_data"
24
+ else
25
+ self.type == 'monthly' ? "strftime('%Y', created_at), strftime('%m', created_at)" : "date_data"
26
+ end
27
+ end
28
+
29
+ def count_select_key
30
+ "count_data"
31
+ end
32
+
33
+ def count_function
34
+ "count(*) as count_data"
35
+ end
36
+
37
+ def date_select_function
38
+ self.type == 'monthly' ? date_select_function_monthly : date_select_function_daily
39
+ end
40
+
41
+ private
42
+
43
+ def date_select_function_monthly
44
+ if adapter =~ /mysql/i
45
+ "MONTH(created_at) as date_data"
46
+ elsif adapter =~ /postgresql/i
47
+ "date_part('month', created_at) as date_data"
48
+ else
49
+ "strftime('%m', created_at) as date_data"
50
+ end
51
+ end
52
+
53
+ def date_select_function_daily
54
+ if adapter =~ /mysql/i
55
+ "date_format(created_at, '%Y-%m-%d') as date_data"
56
+ else
57
+ "date(created_at) as date_data"
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ def self.monthly_report(klass, end_date)
64
+ begin_date = end_date.ago(1.year)
65
+ raise "begin_date should not be after end_date" if begin_date > end_date
66
+ raise AdminData::NoCreatedAtColumnException unless klass.columns.find {|r| r.name == 'created_at'}
67
+
68
+ begin_date = begin_date.beginning_of_day
69
+ end_date = end_date.end_of_day
70
+
71
+ dater = Dater.new(ActiveRecord::Base.connection.adapter_name, 'monthly')
72
+
73
+ query = klass.unscoped
74
+ query = query.where(["created_at >= ?", begin_date])
75
+ query = query.where(["created_at <= ?", end_date])
76
+ query = query.group(dater.group_by_key)
77
+ query = query.select(dater.date_select_function)
78
+ query = query.select(dater.count_function)
79
+ debug "sql: " + query.to_sql
80
+ result = query.all
81
+ debug "sql result: #{result.inspect}"
82
+
83
+ extract_data_from_result_set_monthly(result, dater, begin_date, end_date)
84
+ end
85
+
86
+ def self.extract_data_from_result_set_monthly(result, dater, begin_date, end_date)
87
+ debug "extracting from result set now"
88
+ result_hash = {}
89
+ result.each do |record|
90
+ result_hash.merge!(record[dater.date_select_key].to_i => record[dater.count_select_key])
91
+ end
92
+
93
+ debug "result_hash.inspect is #{result_hash.inspect}"
94
+
95
+ current_month = begin_date.strftime('%m').to_i
96
+ months_order = (1..current_month).to_a.reverse + (current_month..12).to_a.reverse
97
+ months_order.uniq!.reverse!
98
+
99
+ debug "months order is #{months_order.inspect}"
100
+
101
+ final_hash = ActiveSupport::OrderedHash.new
102
+ months_order.each do |month|
103
+ month = month.to_i #sqlite3 has months as 03 instead of 3
104
+ m = Time.now.change(:month => month)
105
+ m = m.ago(1.year) if month > current_month
106
+
107
+ key = m.strftime('%b-%Y')
108
+ key = "'#{key}'"
109
+ if dater.adapter =~ /postgresql/i
110
+ value = result_hash[month]
111
+ elsif dater.adapter =~ /mysql/i
112
+ value = result_hash[month]
113
+ else
114
+ value = result_hash[month]
115
+ end
116
+ value = value.to_i
117
+ debug "month: #{month} key: #{key} value: #{value}"
118
+ final_hash.merge!(key => value)
119
+ end
120
+
121
+ final_hash.to_a.tap {|e| debug e.inspect }
122
+ end
123
+
124
+ def self.daily_report(klass, end_date)
125
+ begin_date = end_date.ago(1.month)
126
+ raise "begin_date should not be after end_date" if begin_date > end_date
127
+ raise AdminData::NoCreatedAtColumnException unless klass.columns.find {|r| r.name == 'created_at'}
128
+
129
+ begin_date = begin_date.beginning_of_day
130
+ end_date = end_date.end_of_day
131
+
132
+ dater = Dater.new(ActiveRecord::Base.connection.adapter_name)
133
+
134
+ query = klass.unscoped
135
+ query = query.where(["created_at >= ?", begin_date])
136
+ query = query.where(["created_at <= ?", end_date])
137
+ query = query.group(dater.group_by_key)
138
+ query = query.select(dater.date_select_function)
139
+ query = query.select(dater.count_function)
140
+ debug "sql: " + query.to_sql
141
+ result = query.all
142
+ debug "sql result: #{result.inspect}"
143
+
144
+ extract_data_from_result_set_daily(result, dater, begin_date, end_date).tap {|e| debug "formatted output: "+e.inspect}
145
+ end
146
+
147
+ def self.extract_data_from_result_set_daily(result, dater, begin_date, end_date)
148
+ count = result.map {|r| r[dater.count_select_key] }
149
+ dates = result.map {|r| r[dater.date_select_key] }
150
+
151
+ debug "count is: #{count.inspect}"
152
+ debug "dates is: #{dates.inspect}"
153
+
154
+ final_output= []
155
+
156
+ while(begin_date) do
157
+ s = begin_date.strftime('%Y-%m-%d')
158
+ final_count = if index = dates.index(s)
159
+ count[index].to_i
160
+ else
161
+ 0
162
+ end
163
+ final_output << ["'#{s}'", final_count]
164
+ begin_date = begin_date.tomorrow
165
+ break if begin_date > end_date
166
+ end
167
+ final_output
168
+ end
169
+
170
+ def self.debug(msg)
171
+ puts msg
172
+ end
173
+
174
+ end
175
+
176
+ end
@@ -0,0 +1,15 @@
1
+ # HttpBasic authenticator for feed authentication
2
+ module AdminData
3
+ class Authenticator
4
+
5
+ def initialize(userid, password)
6
+ @userid = userid
7
+ @password = password
8
+ end
9
+
10
+ def verify(controller)
11
+ controller.authenticate_or_request_with_http_basic { |_u, _p| (_u == @userid) && (_p == @password) }
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,38 @@
1
+ # Following code takes care of providing a nice error
2
+ # message to users who are using old API
3
+ module AdminData
4
+
5
+ class Config
6
+ cattr_accessor :setting
7
+
8
+ def self.set=(input = {})
9
+
10
+ msg=<<EOF
11
+
12
+ AdminData API has changed in version 1.1 .
13
+
14
+ The changes are very minor.
15
+
16
+ Instead of
17
+
18
+ AdminData::Config.set = {
19
+ :find_conditions => ....
20
+ }
21
+
22
+ Now you need to write in following style
23
+
24
+ AdminData.config do |config|
25
+ config.find_conditions = ...
26
+ end
27
+
28
+ Please refer to documentation at
29
+ https://github.com/neerajdotname/admin_data/wiki/Customizing-admin_data-for-a-Rails-3-application
30
+ for more information.
31
+
32
+ EOF
33
+
34
+ raise msg
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,127 @@
1
+ module AdminData
2
+
3
+ class Configuration
4
+
5
+ # Number of recores displayed while listing records
6
+ attr_accessor :number_of_records_per_page
7
+
8
+ # Default value is false .
9
+ # Set this value to true if you want admin_data to ignored
10
+ # the column_limit returned by ActiveRecord .
11
+ attr_accessor :ignore_column_limit
12
+
13
+ # By default this value is true .
14
+ # Set this value to false if you do not want all the belongs_to
15
+ # ids to be populated. If set to false then instead of a dropdown
16
+ # user will get a text field where the id can be entered. It matters
17
+ # only while editing or creating a new record.
18
+ attr_accessor :drop_down_for_associations
19
+
20
+ # Holds a proc which should be called. If the returned value is
21
+ # true then user is granted the access. Otherwise access is denied.
22
+ attr_writer :is_allowed_to_view
23
+
24
+ # Holds a proc which should be called. If the returned value is
25
+ # true then user is granted the access. Otherwise access is denied.
26
+ attr_writer :is_allowed_to_update
27
+
28
+ # Holds a proc which should be called. If the returned value is
29
+ # true then user is granted the access. Otherwise access is denied.
30
+ attr_writer :is_allowed_to_view_feed
31
+
32
+ # For feed authentication a combination of user_id and password is used.
33
+ # This attribute sets the user_id .
34
+ attr_accessor :feed_authentication_user_id
35
+
36
+ # For feed authentication a combination of user_id and password is used.
37
+ # This attribute sets the password .
38
+ attr_accessor :feed_authentication_password
39
+
40
+ # Tell AdminData to not to use id for models like given below.
41
+ #
42
+ # class City < ActiveRecord::Base
43
+ # def to_param
44
+ # self.permanent_name
45
+ # end
46
+ # end
47
+ #
48
+ # AdminData.config do |config|
49
+ # proc = lambda {|params| {:conditions => ["permanent_name = ?", params[:id] ] } }
50
+ # config.find_conditions = {'City' => proc }
51
+ # end
52
+ #
53
+ attr_accessor :find_conditions
54
+
55
+ # Tell AdminData how to display the value for a column
56
+ #
57
+ # AdminData.config do |config|
58
+ # proc = lambda {|model| model.send(:data).inspect}
59
+ # config.column_settings = {'City' => {:data => proc } }
60
+ # end
61
+ #
62
+ attr_accessor :column_settings
63
+
64
+ # Tell AdminData how to order the columns for a model.
65
+ #
66
+ # AdminData.config do |config|
67
+ # config.column_order = {'City' => [:id, :title, :body, :published_at, :author_name]}
68
+ # end
69
+ #
70
+ attr_accessor :columns_order
71
+
72
+ def is_allowed_to_view
73
+ return lambda {|controller| return true } if Rails.env.development?
74
+ @is_allowed_to_view || lambda {|_| nil }
75
+ end
76
+
77
+ def is_allowed_to_update
78
+ return lambda {|controller| return true } if Rails.env.development?
79
+ @is_allowed_to_update || lambda {|_| nil }
80
+ end
81
+
82
+ def is_allowed_to_view_feed
83
+ return lambda {|controller| return true } if Rails.env.development?
84
+ @is_allowed_to_view_feed || lambda {|_| nil }
85
+ end
86
+
87
+ # TODO explain why it is needed
88
+ attr_reader :adapter_name
89
+
90
+ # Tell AdminData how to name a column in a listing
91
+ # Example:
92
+ #
93
+ # config.column_headers = {'Timesheet' => {:id => 'ID'}
94
+ #
95
+ attr_accessor :column_headers
96
+
97
+ def initialize
98
+ @number_of_records_per_page = 50
99
+ @is_allowed_to_view = nil
100
+ @is_allowed_to_update = nil
101
+ @is_allowed_to_view_feed = nil
102
+ @find_conditions = {}
103
+ @drop_down_for_associations = true
104
+ @columns_order = {}
105
+ @column_headers = {}
106
+ @column_settings = {}
107
+ @adapter_name = ActiveRecord::Base.connection.adapter_name
108
+ @ignore_column_limit = false
109
+ end
110
+
111
+ def display_assoc?( class_name )
112
+ case @drop_down_for_associations
113
+ when Hash
114
+ return @drop_down_for_associations[ class_name ]
115
+ when TrueClass, FalseClass
116
+ return @drop_down_for_associations
117
+ when NilClass
118
+ return false
119
+ else
120
+ raise "Configuration Error. #{@drop_down_for_associations} " \
121
+ "must be true, false or a Hash."
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+ end
@@ -0,0 +1,58 @@
1
+ require 'date'
2
+
3
+ module AdminData
4
+ class DateUtil
5
+
6
+ # returns a time object for the given input.
7
+ # validation is not done. It is assumed that client
8
+ # has done validation using .valid? method.
9
+ def self.valid?(input)
10
+ !!parse(input)
11
+ end
12
+
13
+ # Usage:
14
+ #
15
+ # parase('13-feb-2008') # => time object
16
+ # parse('13-February-2008') # => time object
17
+ # parse('13-February-2008') # => time object
18
+ # parse('99-Feb-2008') #=> false
19
+ #
20
+ def self.parse(input)
21
+ return false if input.blank?
22
+
23
+ input.strip!
24
+
25
+ # remove all the white space characters
26
+ input.gsub!(/\s/,'')
27
+
28
+ return false if input.length < 9
29
+
30
+ dd,mm,yyyy = input.split('-')
31
+ return false if dd.nil? || mm.nil? || yyyy.nil?
32
+
33
+ # month must be of atleast three characters
34
+ return false if mm.length < 3
35
+
36
+ mm = mm.downcase[0,3]
37
+
38
+ months = {'jan' => 1, 'feb' => 2, 'mar' => 3, 'apr' => 4, 'may' => 5, 'jun' => 6,
39
+ 'jul' => 7, 'aug' => 8, 'sep' => 9, 'oct' => 10, 'nov' => 11, 'dec' => 12 }
40
+
41
+ return false unless months.keys.include? mm
42
+
43
+ mm = months[mm].to_i
44
+ yyyy = yyyy.to_i
45
+ dd = dd.to_i
46
+
47
+ # validate date values
48
+ begin
49
+ Date.new(yyyy,mm,dd)
50
+ rescue
51
+ return false
52
+ end
53
+
54
+ Time.now.change(:year => yyyy, :month => mm, :day => dd, :hour => 0)
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ module AdminData
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace AdminData
4
+
5
+ initializer "admin_data precompile hook" do |app|
6
+ app.config.assets.precompile += [
7
+ 'advance_search/*',
8
+ 'analytics/*',
9
+ 'misc/*',
10
+ 'vendor/*',
11
+ 'vendor/jquery-ui-1.7.2.custom.css',
12
+ 'admin_data.js',
13
+ 'admin_data.css'
14
+ ]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module AdminData
2
+ module ModelFinder
3
+ extend self
4
+
5
+ def models
6
+ ActiveRecord::Base.send(:subclasses).map do | klass |
7
+ namespaced_models(klass).push(klass.name)
8
+ end.flatten.sort
9
+ end
10
+
11
+ def namespaced_models(model_klass)
12
+ model_klass.subclasses.map(&:name)
13
+ end
14
+ end
15
+ end