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,27 @@
1
+ <%= form_tag(search_path(klass: klass), method: 'get', class: 'form search_form', id: 'search') do %>
2
+
3
+ <div class='search_box'>
4
+ <div id='quick_search'>
5
+ <label class='label keyword_label'>Search keyword</label>
6
+ <input type="text" id="quick_search_input" name="query" value="<%=params[:query]%>" />
7
+ <div class='clear'></div>
8
+ <%= submit_tag 'Search', :name => nil, :disable_with => 'searching ...', :class => 'submit_search' %>
9
+ </div>
10
+ </div>
11
+
12
+ <% end %>
13
+
14
+ <br />
15
+
16
+ <style>
17
+ .keyword_label {
18
+ float: left;
19
+ padding-right: 10px;
20
+ margin-right: 10px;
21
+ }
22
+ #quick_search_input {
23
+ float: left;
24
+ margin-left: 10px;
25
+ margin-right: 20px;
26
+ }
27
+ </style>
@@ -0,0 +1,34 @@
1
+ <div>
2
+ <h2 class='title' id='search_result_title'>
3
+ <%= search_result_title(total_num_of_children, records) %>
4
+ </h2>
5
+
6
+ <% if is_allowed_to_update? && params[:action] == 'advance_search' %>
7
+ <div class='delete_destroy_box'>
8
+ <span style=''>
9
+ <%= link_to 'Delete All', '#', :id => 'advance_search_delete_all' %>
10
+ </span>
11
+ |
12
+ <span>
13
+ <%= link_to 'Destroy All', '#', :id => 'advance_search_destroy_all' %>
14
+ </span>
15
+ </div>
16
+ <% end %>
17
+
18
+ <div class='clear'></div>
19
+
20
+ </div>
21
+
22
+ <style>
23
+ #search_result_title {
24
+ float: left;
25
+ margin-top: 5px;
26
+ padding-top: 5px;
27
+ }
28
+ .delete_destroy_box {
29
+ float: left;
30
+ margin-top: 6px;
31
+ padding-top: 6px;
32
+ margin-left: 20px;
33
+ }
34
+ </style>
@@ -0,0 +1,16 @@
1
+ <div class='breadcrum rounded'>
2
+ <%= link_to 'Home', root_path %>
3
+
4
+ <% unless data.blank? %>
5
+ >
6
+ <% end %>
7
+
8
+ <%= data %>
9
+
10
+ <% if params[:klass] && !(params[:action] == 'show') %>
11
+ <span class='description'>
12
+ (<%= pluralize(@klass.count, 'record') %> )
13
+ </span>
14
+ <% end %>
15
+
16
+ </div>
@@ -0,0 +1,4 @@
1
+ <select class='drop_down_value_klass' id='drop_down_klasses'>
2
+ <option></option>
3
+ <%= options_for_select(drop_down_for_klasses, @drop_down_url) %>
4
+ </select>
@@ -0,0 +1,13 @@
1
+ <% if model && model.errors.any? %>
2
+ <div class='flash rounded'>
3
+ <div class='message error'>
4
+ <% model.errors.full_messages.each do |message| %>
5
+ <p><%=message%></p>
6
+ <% end %>
7
+ </div>
8
+ </div>
9
+ <% end %>
10
+
11
+ <% if flash[:success] %>
12
+ <div class='flash rounded'><div class='message warning'><p><%= flash[:success] %></p></div></div>
13
+ <% end %>
@@ -0,0 +1,20 @@
1
+ <div id="header">
2
+ <h1> &nbsp; </h1>
3
+
4
+ <ul id='subnav'>
5
+ <li>
6
+ <% label = "Back to Site " + image_tag('site.png', :width => '12') %>
7
+ <%= link_to label.html_safe, '/' %>
8
+ </li>
9
+ <li>
10
+ <%= link_to 'admin_data' , '/admin_data' %>
11
+ </li>
12
+ </ul>
13
+
14
+ <div id='model_drop_down'>
15
+ <%= render '/admin_data/shared/drop_down_klasses', :drop_down_for_klasses => drop_down_for_klasses %>
16
+ </div>
17
+
18
+ <div class='clear'></div>
19
+
20
+ </div>
@@ -0,0 +1,6 @@
1
+ <div id="footer">
2
+ <p> Powered by <%= link_to 'admin_data', 'http://github.com/neerajdotname/admin_data', :class => 'powered_by' %> </p>
3
+ <p> <%= link_to 'Report Bug', 'http://github.com/neerajdotname/admin_data/issues', :class => 'powered_by' %> </p>
4
+ <p> <%= link_to 'Documentation', 'http://github.com/neerajdotname/admin_data/wiki', :class => 'powered_by' %> </p>
5
+ <div class='clear'></div>
6
+ </div>
@@ -0,0 +1,26 @@
1
+ <%
2
+ quick_search_tab_active = params[:action] == 'quick_search' ? 'active' : ''
3
+ advance_search_tab_active = params[:action] == 'advance_search' ? 'active' : ''
4
+ table_structure_tab_active = params[:controller] == 'admin_data/table_structure' ? 'active' : ''
5
+ add_new_record_tab_active = %w(new create).include?(params[:action]) ? 'active' : ''
6
+ %>
7
+ <ul>
8
+
9
+ <li class="first <%=quick_search_tab_active%>">
10
+ <%= link_to 'Quick Search', search_path(:klass => klass.name.underscore) %>
11
+ </li>
12
+
13
+ <li class="<%=advance_search_tab_active%>">
14
+ <%= link_to 'Advance Search', advance_search_path(:klass => klass.name.underscore) %>
15
+ </li>
16
+
17
+ <li class="<%=table_structure_tab_active%>">
18
+ <%= link_to 'Table Structure', table_structure_path(:klass => klass.name.underscore) %>
19
+ </li>
20
+
21
+ <% if is_allowed_to_update? %>
22
+ <li class="<%=add_new_record_tab_active%>">
23
+ <%= link_to '+Add New Record', new_path(:klass => klass.name.underscore) %>
24
+ </li>
25
+ <% end %>
26
+ </ul>
@@ -0,0 +1,54 @@
1
+ <div id="main">
2
+
3
+ <%= breadcrum do %>
4
+ <%= link_to @klass, search_path(:klass => @klass.name) %>
5
+ <% end %>
6
+
7
+ <%= render 'admin_data/shared/flash_message', :model => @model %>
8
+
9
+ <div class="block" id="block-tables">
10
+ <div class="secondary-navigation">
11
+ <%= render 'admin_data/shared/secondary_navigation', :klass => @klass %>
12
+ <div class="clear"></div>
13
+ </div>
14
+ <div class="content rounded">
15
+ <h2 class="title"></h2>
16
+ <div class="inner">
17
+ <h1 class='table_name'>Table name : <%=@klass.send(:table_name)%></h1>
18
+ <table class="table colorize">
19
+ <tr>
20
+ <th>Column Name</th>
21
+ <th>Type</th>
22
+ <th>Null</th>
23
+ <th>Default</th>
24
+ </tr>
25
+ <% @klass.columns.each do |column| %>
26
+ <tr>
27
+ <td><%=column.name%></td>
28
+ <td><%=column.type%></td>
29
+ <td><%=column.null%></td>
30
+ <td><%= AdminData::Util.string_representation_of_data(column.default) if column.has_default?%></td>
31
+ </tr>
32
+ <% end %>
33
+ </table>
34
+
35
+ <h2>Index</h2>
36
+ <% if @indexes.size == 0 %>
37
+ <p>No index was found </p>
38
+ <% else %>
39
+ <table class="table colorize">
40
+ <tr>
41
+ <th>Info</th>
42
+ </tr>
43
+ <% @indexes.each do |index| %>
44
+ <tr>
45
+ <td><%= index %></td>
46
+ </tr>
47
+ <% end %>
48
+ </table>
49
+ <% end %>
50
+
51
+ </div>
52
+ </div>
53
+ </div>
54
+ </div>
@@ -0,0 +1,34 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title>
6
+ <%= @page_title.blank? ? 'admin_data' : "#{@page_title} - admin_data" %>
7
+ </title>
8
+
9
+ <%= stylesheet_link_tag('admin_data') %>
10
+ <%= javascript_include_tag('admin_data') %>
11
+ <%= csrf_meta_tag %>
12
+
13
+ </head>
14
+
15
+ <body>
16
+ <noscript>
17
+ <div id="noscript-warning">JavaScript is disabled. A few things might not work properly.</div>
18
+ <br />
19
+ <br />
20
+ </noscript>
21
+ <div>
22
+ <%= render 'admin_data/shared/header', :drop_down_for_klasses => @drop_down_for_klasses %>
23
+ <div class='clear'></div>
24
+ </div>
25
+ <div id="container">
26
+ <div id="wrapper">
27
+ <%= yield %>
28
+ <div class="clear"></div>
29
+ </div>
30
+ <%= render :partial => 'admin_data/shared/powered_by' %>
31
+ </div>
32
+ </body>
33
+
34
+ </html>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>AdminData</title>
5
+ <%= stylesheet_link_tag "admin_data/application", :media => "all" %>
6
+ <%= javascript_include_tag "admin_data/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,71 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <title>
6
+ <%= @page_title.blank? ? 'admin_data' : "#{@page_title} - admin_data" %>
7
+ </title>
8
+
9
+ <%= stylesheet_link_tag('admin_data') %>
10
+ <%= javascript_include_tag('admin_data') %>
11
+ <%= csrf_meta_tag %>
12
+
13
+ </head>
14
+
15
+ <body>
16
+ <noscript>
17
+ <div id="noscript-warning">JavaScript is disabled. A few things might not work properly.</div>
18
+ <br />
19
+ <br />
20
+ </noscript>
21
+ <div>
22
+ <%= render 'admin_data/shared/header', :drop_down_for_klasses => @drop_down_for_klasses %>
23
+ <div class='clear'></div>
24
+ </div>
25
+ <div id="container">
26
+ <div id="wrapper">
27
+
28
+ <div id='main'>
29
+ <div class="block" id="block-text">
30
+
31
+ <div>
32
+ <h1 class='listing_klass'> Listing <%=@klass.name%></h1>
33
+ <h3 class='total_records_info_klass'><%=total_records_info(@klass)%></h3>
34
+ <div class='clear'></div>
35
+ </div>
36
+
37
+ <div class="secondary-navigation">
38
+ <%= render 'admin_data/shared/secondary_navigation', :klass => @klass %>
39
+ <div class="clear"></div>
40
+ </div>
41
+
42
+ <div class="content">
43
+ <%= yield %>
44
+ </div>
45
+
46
+ <div class='clear'></div>
47
+
48
+ <div class='main2 rounded'>
49
+ <div class="block" id="block-tables">
50
+ <div class="content">
51
+ <div class='inner'>
52
+ <div id='results'>
53
+ <% if params[:action] == 'quick_search' %>
54
+ <%= render 'admin_data/search/search/listing', :klass => @klass, :records => @records %>
55
+ <% end %>
56
+ </div>
57
+ </div>
58
+ </div>
59
+ </div>
60
+ </div>
61
+ </div>
62
+ </div>
63
+
64
+ <div class="clear"></div>
65
+ </div>
66
+ <%= render :partial => 'admin_data/shared/powered_by' %>
67
+ </div>
68
+ </body>
69
+
70
+ </html>
71
+
data/config/routes.rb ADDED
@@ -0,0 +1,32 @@
1
+ AdminData::Engine.routes.draw do
2
+
3
+ controller "crud" do
4
+ match '/klass/(:klass)', to: :index, :as => :index, :via => :get
5
+ match '/klass/(:klass)', to: :create, :as => :index, :via => :post
6
+ match '/klass/:klass/new', to: :new, :as => :new, :via => :get
7
+ match '/klass/:klass/:id/del', to: :del, :as => :del, :via => :delete
8
+ match '/klass/:klass/:id/edit', to: :edit, :as => :edit, :via => :get
9
+ match '/klass/:klass/:id', to: :show, :via => :get
10
+ match '/klass/:klass/:id', to: :update, :via => :put
11
+ match '/klass/:klass/:id', to: :destroy, :via => :delete
12
+ end
13
+
14
+ controller "migration" do
15
+ match '/migration', to: :index, as: :migration_information
16
+ match '/jstest', to: :jstest, as: :jstest
17
+ end
18
+
19
+ match '/table_structure/:klass' => "table_structure#index", :as => :table_structure
20
+
21
+ match '/quick_search/:klass' => "search#quick_search", :as => :search
22
+ match '/quick_search' => "search#quick_search"
23
+
24
+ match '/advance_search/:klass' => "search#advance_search", :as => :advance_search
25
+ match '/advance_search' => "search#advance_search"
26
+
27
+ match '/feed/:klasss' => "feed#index", :defaults => { :format =>'rss' }, :as => :feed
28
+
29
+ match '/public/*file' => "public#serve", :as => :public
30
+
31
+ root :to => "home#index"
32
+ end
data/lib/admin_data.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'admin_data/rails_version_check'
2
+ require 'will_paginate'
3
+
4
+ require 'admin_data/engine'
5
+
6
+ module AdminData
7
+ extend ActiveSupport::Autoload
8
+
9
+ class NoCreatedAtColumnException < Exception
10
+
11
+ end
12
+
13
+ LIBPATH = File.dirname(__FILE__)
14
+
15
+ autoload :Configuration
16
+ autoload :Util
17
+ autoload :Config
18
+ autoload :ActiveRecordUtil
19
+ autoload :SetupConfig
20
+ autoload :DateUtil
21
+ autoload :Authenticator
22
+ autoload :Search
23
+ autoload :Analytics
24
+ autoload :ModelFinder
25
+
26
+ include SetupConfig
27
+ end
@@ -0,0 +1,102 @@
1
+ module AdminData
2
+ class ActiveRecordUtil
3
+
4
+ attr_accessor :klass
5
+
6
+ def initialize(klass)
7
+ @klass = klass
8
+ end
9
+
10
+ # class User
11
+ # has_and_belongs_to_many :clubs
12
+ # end
13
+ #
14
+ # ActiveRecordUtil.new(User).declared_habtm_association_names
15
+ # #=> ['clubs']
16
+ def declared_habtm_association_names
17
+ delcared_association_names_for(:has_and_belongs_to_many).map(&:name).map(&:to_s)
18
+ end
19
+
20
+ # class User
21
+ # belongs_to :club
22
+ # end
23
+ #
24
+ # ActiveRecordUtil.new(User).declared_belongs_to_association_names
25
+ # #=> ['club']
26
+ def declared_belongs_to_association_names
27
+ delcared_association_names_for(:belongs_to).map(&:name).map(&:to_s)
28
+ end
29
+
30
+ # class User
31
+ # has_one :car
32
+ # end
33
+ #
34
+ # ActiveRecordUtil.new(User).declared_has_one_association_names
35
+ # #=> ['car']
36
+ def declared_has_one_association_names
37
+ delcared_association_names_for(:has_one).map(&:name).map(&:to_s)
38
+ end
39
+
40
+ # class User
41
+ # has_many :cars
42
+ # end
43
+ #
44
+ # ActiveRecordUtil.new(User).declared_has_many_association_names
45
+ # #=> ['cars']
46
+ def declared_has_many_association_names
47
+ delcared_association_names_for(:has_many).map(&:name).map(&:to_s)
48
+ end
49
+
50
+ # returns an array of classes
51
+ #
52
+ # class User
53
+ # has_and_belongs_to_many :clubs
54
+ # end
55
+ #
56
+ # ActiveRecordUtil.new(User).habtm_klasses_for
57
+ # #=> [Club]
58
+ def habtm_klasses_for
59
+ declared_habtm_association_names.map do |assoc_name|
60
+ klass_for_association_type_and_name(:has_and_belongs_to_many, assoc_name)
61
+ end
62
+ end
63
+
64
+ # returns a class or nil
65
+ #
66
+ # class User
67
+ # has_many :comments
68
+ # end
69
+ #
70
+ # ActiveRecordUtil.new(User).klass_for_association_type_and_name(:has_many, 'comments')
71
+ # #=> Comment
72
+ #
73
+ def klass_for_association_type_and_name(association_type, association_name)
74
+ data = klass.name.camelize.constantize.reflections.values.detect do |value|
75
+ value.macro == association_type && value.name.to_s == association_name
76
+ end
77
+ data.klass if data # output of detect from hash is an array with key and value
78
+ end
79
+
80
+ # returns false if the given Klass has no association info. Otherwise returns true.
81
+ def has_association_info?
82
+ declared_belongs_to_association_names.any? ||
83
+ declared_has_many_association_names.any? ||
84
+ declared_has_many_association_names.any? ||
85
+ declared_habtm_association_names.any?
86
+ end
87
+
88
+ private
89
+
90
+ # returns declared association names like
91
+ #
92
+ # #=> ['comments']
93
+ # #=> ['positive_comments']
94
+ # #=> ['negative_comments']
95
+ def delcared_association_names_for(association_type)
96
+ klass.name.camelize.constantize.reflections.values.select do |value|
97
+ value.macro == association_type
98
+ end
99
+ end
100
+
101
+ end
102
+ end