edgarj 0.01.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +23 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/edgarj/base.js +49 -0
  6. data/app/assets/javascripts/edgarj/menu.js +39 -0
  7. data/app/assets/javascripts/edgarj/operator_selection.js +133 -0
  8. data/app/assets/stylesheets/edgarj/base.css +304 -0
  9. data/app/assets/stylesheets/edgarj/menu.css +65 -0
  10. data/app/controllers/edgarj/authentication_mixin.rb.sample +30 -0
  11. data/app/controllers/edgarj/controller_mixin_common.rb +80 -0
  12. data/app/controllers/edgarj/controller_mixin_for_app.rb +71 -0
  13. data/app/controllers/edgarj/edgarj_controller.rb +535 -0
  14. data/app/controllers/edgarj/model_permissions_controller.rb +8 -0
  15. data/app/controllers/edgarj/permission_mixin.rb +84 -0
  16. data/app/controllers/edgarj/popup_controller.rb +128 -0
  17. data/app/controllers/edgarj/rescue_mixin.rb +37 -0
  18. data/app/controllers/edgarj/user_group_users_controller.rb +8 -0
  19. data/app/controllers/edgarj/user_groups_controller.rb +9 -0
  20. data/app/controllers/edgarj/user_groups_popup_controller.rb +8 -0
  21. data/app/helpers/edgarj/assoc_helper.rb +369 -0
  22. data/app/helpers/edgarj/common_helper.rb +37 -0
  23. data/app/helpers/edgarj/edgarj_helper.rb +20 -0
  24. data/app/helpers/edgarj/field_helper.rb +397 -0
  25. data/app/helpers/edgarj/form_drawer.rb +322 -0
  26. data/app/helpers/edgarj/list_drawer.rb +169 -0
  27. data/app/helpers/edgarj/menu_helper.rb +92 -0
  28. data/app/helpers/edgarj/model_permissions_helper.rb +9 -0
  29. data/app/helpers/edgarj/popup_helper.rb +40 -0
  30. data/app/helpers/edgarj/search_helper.rb +14 -0
  31. data/app/helpers/edgarj/sessions_helper.rb +9 -0
  32. data/app/helpers/edgarj/user_group_users_helper.rb +9 -0
  33. data/app/helpers/edgarj/user_groups_helper.rb +9 -0
  34. data/app/helpers/edgarj/user_groups_popup_helper.rb +9 -0
  35. data/app/models/edgarj/drawer/base.rb +234 -0
  36. data/app/models/edgarj/drawer/normal.rb +6 -0
  37. data/app/models/edgarj/drawer/popup.rb +47 -0
  38. data/app/models/edgarj/drawer.rb +13 -0
  39. data/app/models/edgarj/model_permission.rb +41 -0
  40. data/app/models/edgarj/page_info.rb +47 -0
  41. data/app/models/edgarj/search.rb +81 -0
  42. data/app/models/edgarj/search_form.rb +255 -0
  43. data/app/models/edgarj/search_popup.rb +44 -0
  44. data/app/models/edgarj/sssn.rb +120 -0
  45. data/app/models/edgarj/user_group.rb +67 -0
  46. data/app/models/edgarj/user_group_user.rb +18 -0
  47. data/app/models/edgarj.rb +5 -0
  48. data/app/views/edgarj/edgarj/_form.html.erb +25 -0
  49. data/app/views/edgarj/edgarj/_list.html.erb +52 -0
  50. data/app/views/edgarj/edgarj/_message_popup.html.erb +15 -0
  51. data/app/views/edgarj/edgarj/_search_form.html.erb +64 -0
  52. data/app/views/edgarj/edgarj/_search_operator.html.erb +17 -0
  53. data/app/views/edgarj/edgarj/_search_operator_selection.html.erb +12 -0
  54. data/app/views/edgarj/edgarj/clear.js.erb +1 -0
  55. data/app/views/edgarj/edgarj/create.js.erb +4 -0
  56. data/app/views/edgarj/edgarj/destroy.js.erb +2 -0
  57. data/app/views/edgarj/edgarj/index.html.erb +37 -0
  58. data/app/views/edgarj/edgarj/index.js.erb +1 -0
  59. data/app/views/edgarj/edgarj/message_popup.js.erb +3 -0
  60. data/app/views/edgarj/edgarj/page_info_save.js.erb +1 -0
  61. data/app/views/edgarj/edgarj/search.js.erb +4 -0
  62. data/app/views/edgarj/edgarj/search_clear.js.erb +1 -0
  63. data/app/views/edgarj/edgarj/show.js.erb +1 -0
  64. data/app/views/edgarj/edgarj/top.html.erb +4 -0
  65. data/app/views/edgarj/edgarj/update.js.erb +4 -0
  66. data/app/views/edgarj/popup/_index.html.erb +16 -0
  67. data/app/views/edgarj/popup/_list.html.erb +42 -0
  68. data/app/views/edgarj/popup/_message_popup.html.erb +15 -0
  69. data/app/views/edgarj/popup/_search.html.erb +42 -0
  70. data/app/views/edgarj/popup/_search_save_popup.html.erb +16 -0
  71. data/app/views/edgarj/popup/index.js.erb +5 -0
  72. data/app/views/edgarj/popup/message_popup.js.erb +3 -0
  73. data/app/views/edgarj/popup/page_info_save.js.erb +1 -0
  74. data/app/views/edgarj/popup/search.js.erb +15 -0
  75. data/app/views/edgarj/popup/view_status_save.js.erb +1 -0
  76. data/config/routes.rb +15 -0
  77. data/config/settings.yml +5 -0
  78. data/db/migrate/20131118084600_create_edgar_sssns.rb +14 -0
  79. data/db/migrate/20131123124730_create_edgar_page_infos.rb +15 -0
  80. data/db/migrate/20140116062252_create_edgar_user_groups.rb +18 -0
  81. data/db/migrate/20140116062327_create_edgar_user_group_users.rb +10 -0
  82. data/db/migrate/20140206222308_create_edgar_model_permissions.rb +14 -0
  83. data/db/migrate/20141209053055_rename_edgar_to_edgarj.rb +17 -0
  84. data/lib/core_ext/active_record.rb +123 -0
  85. data/lib/core_ext/resources.rb +71 -0
  86. data/lib/edgarj/engine.rb +64 -0
  87. data/lib/edgarj/enum_cache.rb +46 -0
  88. data/lib/edgarj/templates/rails/helper/helper.rb +10 -0
  89. data/lib/edgarj/templates/test_unit/scaffold/functional_test.rb +575 -0
  90. data/lib/edgarj/version.rb +3 -0
  91. data/lib/edgarj.rb +14 -0
  92. data/lib/generators/edgarj/popup_scaffold/USAGE +6 -0
  93. data/lib/generators/edgarj/popup_scaffold/popup_scaffold_generator.rb +35 -0
  94. data/lib/generators/edgarj/popup_scaffold/templates/controller.rb +13 -0
  95. data/lib/generators/edgarj/popup_scaffold/templates/functional_test.rb +197 -0
  96. data/lib/generators/edgarj/popup_scaffold/templates/helper.rb +9 -0
  97. data/lib/generators/edgarj/scaffold/USAGE +17 -0
  98. data/lib/generators/edgarj/scaffold/scaffold_generator.rb +40 -0
  99. data/lib/generators/edgarj/scaffold/templates/controller.rb +13 -0
  100. data/lib/tasks/edgarj_tasks.rake +32 -0
  101. data/lib/tasks/pakcage.rake +18 -0
  102. data/locale/en.yml +94 -0
  103. data/locale/ja.yml +100 -0
  104. data/test/dummy/README.rdoc +28 -0
  105. data/test/dummy/Rakefile +6 -0
  106. data/test/dummy/app/assets/javascripts/application.js +21 -0
  107. data/test/dummy/app/assets/javascripts/authors.js +2 -0
  108. data/test/dummy/app/assets/stylesheets/application.css +16 -0
  109. data/test/dummy/app/assets/stylesheets/authors.css +4 -0
  110. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  111. data/test/dummy/app/controllers/application_controller.rb +15 -0
  112. data/test/dummy/app/controllers/authors_controller.rb +6 -0
  113. data/test/dummy/app/controllers/authors_popup_controller.rb +6 -0
  114. data/test/dummy/app/controllers/books_controller.rb +6 -0
  115. data/test/dummy/app/controllers/dummy_auth_mixin.rb +36 -0
  116. data/test/dummy/app/decorators/models/edgarj/user_group_decorator.rb +1 -0
  117. data/test/dummy/app/helpers/application_helper.rb +3 -0
  118. data/test/dummy/app/helpers/authors_helper.rb +7 -0
  119. data/test/dummy/app/helpers/authors_popup_helper.rb +7 -0
  120. data/test/dummy/app/helpers/books_helper.rb +7 -0
  121. data/test/dummy/app/models/author.rb +32 -0
  122. data/test/dummy/app/models/book.rb +5 -0
  123. data/test/dummy/app/models/user.rb +13 -0
  124. data/test/dummy/app/views/layouts/application.html.erb +32 -0
  125. data/test/dummy/app/views/layouts/login.html.erb +20 -0
  126. data/test/dummy/bin/bundle +3 -0
  127. data/test/dummy/bin/rails +4 -0
  128. data/test/dummy/bin/rake +4 -0
  129. data/test/dummy/config/application.rb +59 -0
  130. data/test/dummy/config/boot.rb +10 -0
  131. data/test/dummy/config/database.yml +15 -0
  132. data/test/dummy/config/edgarj/menu_config.rb +28 -0
  133. data/test/dummy/config/environment.rb +5 -0
  134. data/test/dummy/config/environments/development.rb +42 -0
  135. data/test/dummy/config/environments/production.rb +79 -0
  136. data/test/dummy/config/environments/test.rb +34 -0
  137. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  138. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  139. data/test/dummy/config/initializers/inflections.rb +16 -0
  140. data/test/dummy/config/initializers/mime_types.rb +5 -0
  141. data/test/dummy/config/initializers/secret_token.rb +12 -0
  142. data/test/dummy/config/initializers/session_store.rb +3 -0
  143. data/test/dummy/config/initializers/strong_parameter.rb +3 -0
  144. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  145. data/test/dummy/config/locales/en.yml +26 -0
  146. data/test/dummy/config/routes.rb +60 -0
  147. data/test/dummy/config.ru +4 -0
  148. data/test/dummy/db/migrate/20131107120635_create_authors.rb +9 -0
  149. data/test/dummy/db/migrate/20131218011851_create_books.rb +10 -0
  150. data/test/dummy/db/migrate/20140201000000_add_user_group_id_to_authors.rb +5 -0
  151. data/test/dummy/db/migrate/20140807065420_create_users.rb +10 -0
  152. data/test/dummy/db/schema.rb +93 -0
  153. data/test/dummy/public/404.html +58 -0
  154. data/test/dummy/public/422.html +58 -0
  155. data/test/dummy/public/500.html +57 -0
  156. data/test/dummy/public/favicon.ico +0 -0
  157. data/test/dummy/script/rails +6 -0
  158. data/test/dummy/test/functional/authors_controller_test.rb +631 -0
  159. data/test/dummy/test/functional/books_controller_test.rb +516 -0
  160. data/test/dummy/test/helpers/authors_helper_test.rb +4 -0
  161. data/test/dummy/test/unit/author_test.rb +7 -0
  162. data/test/dummy/test/unit/book_test.rb +7 -0
  163. data/test/edgar_test.rb +7 -0
  164. data/test/fixtures/authors.yml +32 -0
  165. data/test/fixtures/books.yml +56 -0
  166. data/test/fixtures/edgarj/model_permissions.yml +97 -0
  167. data/test/fixtures/edgarj/page_infos.yml +84 -0
  168. data/test/fixtures/edgarj/sssns.yml +38 -0
  169. data/test/fixtures/edgarj/user_group_users.yml +114 -0
  170. data/test/fixtures/edgarj/user_groups.yml +95 -0
  171. data/test/fixtures/users.yml +49 -0
  172. data/test/functional/edgarj/edgarj_controller_test.rb +24 -0
  173. data/test/functional/edgarj/model_permissions_controller_test.rb +554 -0
  174. data/test/functional/edgarj/user_group_users_controller_test.rb +567 -0
  175. data/test/integration/navigation_test.rb +10 -0
  176. data/test/support/edgarj/controller_supporter.rb +23 -0
  177. data/test/test_helper.rb +23 -0
  178. data/test/unit/edgarj/model_permission_test.rb +27 -0
  179. data/test/unit/edgarj/page_info_test.rb +7 -0
  180. data/test/unit/edgarj/sssn_test.rb +10 -0
  181. data/test/unit/edgarj/user_group_test.rb +32 -0
  182. data/test/unit/edgarj/user_group_user_test.rb +9 -0
  183. data/test/unit/helpers/edgarj/model_permissions_helper_test.rb +6 -0
  184. data/test/unit/helpers/edgarj/user_group_users_helper_test.rb +6 -0
  185. metadata +456 -0
@@ -0,0 +1,12 @@
1
+ <%# operator selection menu items %>
2
+ <% id = 'edgarj_search_operator_selection' %>
3
+ <div class="contextMenu" id="<%= id -%>" style='display: none;'> <!-- edgarj/edgarj/_search_operator_selection.html.erb -->
4
+ <ul>
5
+ <li id="<%= id + '_eq' -%>">=</li>
6
+ <li id="<%= id + '_ne' -%>">&lt;&gt;</li>
7
+ <li id="<%= id + '_gt' -%>">&gt;</li>
8
+ <li id="<%= id + '_ge' -%>">&gt;=</li>
9
+ <li id="<%= id + '_lt' -%>">&lt;</li>
10
+ <li id="<%= id + '_le' -%>">&lt;=</li>
11
+ </ul>
12
+ </div>
@@ -0,0 +1 @@
1
+ $('#edgarj_form').replaceWith("<%= j(render 'form') %>");
@@ -0,0 +1,4 @@
1
+ <% if !@record.errors.any? %>
2
+ $('#edgarj_list').replaceWith("<%= j(render 'list') %>");
3
+ <% end %>
4
+ $('#edgarj_form').replaceWith("<%= j(render 'form') %>");
@@ -0,0 +1,2 @@
1
+ $('#edgarj_list').replaceWith("<%= j(render 'list') %>");
2
+ $('#edgarj_form').replaceWith("<%= j(render 'form') %>");
@@ -0,0 +1,37 @@
1
+ <!-- edgarj/index.html.erb -->
2
+ <table>
3
+ <tr>
4
+ <td id=page_title><h2><%= controller.send(:human_name) %></h2></td>
5
+ </tr>
6
+ </table>
7
+ <%= render 'list' %>
8
+ <%= render 'form' %>
9
+ <%= render 'search_form' %>
10
+ <%= render 'search_operator_selection' %>
11
+
12
+ <div id=edgarj_message_popup></div>
13
+ <%= javascript_tag do %>
14
+ $(function(){
15
+ $('#edgarj_search_form').hide();
16
+
17
+ /* init message-dialog, which will be mainly used to display error message */
18
+ $('#edgarj_message_popup').dialog({
19
+ autoOpen: false,
20
+ modal: true,
21
+ title: '<%= t('edgarj.message_popup.title') %>',
22
+ width: 800,
23
+ });
24
+ });
25
+ <% end %>
26
+
27
+ <div id=edgarj_form_popup></div>
28
+ <%= javascript_tag do %>
29
+ $(function(){
30
+ /* init popup-dialog, but don't show */
31
+ $('#edgarj_form_popup').dialog({
32
+ autoOpen: false,
33
+ modal: true,
34
+ width: 800,
35
+ });
36
+ });
37
+ <% end %>
@@ -0,0 +1 @@
1
+ $('#edgarj_list').replaceWith("<%= j(render 'list') %>");
@@ -0,0 +1,3 @@
1
+ $('#edgarj_message_popup').html("<%= j(render 'message_popup') %>");
2
+ $('#edgarj_message_popup').dialog('open');
3
+
@@ -0,0 +1 @@
1
+ $('#edgarj_list').replaceWith("<%= j(render 'list') %>");
@@ -0,0 +1,4 @@
1
+ <% if !@search.errors.any? %>
2
+ $('#edgarj_list').replaceWith("<%= j(render 'list') %>");
3
+ <% end %>
4
+ $('#edgarj_search_form').replaceWith("<%= j(render 'search_form') %>");
@@ -0,0 +1 @@
1
+ $('#edgarj_search_form').replaceWith("<%= j(render 'search_form') %>");
@@ -0,0 +1 @@
1
+ $('#edgarj_form').replaceWith("<%= j(render 'form') %>");
@@ -0,0 +1,4 @@
1
+ <!-- edgarj/edgarj/top.html.erb -->
2
+ <h2><%= t('top_screen') %></h2>
3
+
4
+ (TBD)
@@ -0,0 +1,4 @@
1
+ <% if @record && !@record.errors.any? %>
2
+ $('#edgarj_list').replaceWith("<%= j(render 'list') %>");
3
+ <% end %>
4
+ $('#edgarj_form').replaceWith("<%= j(render 'form') %>");
@@ -0,0 +1,16 @@
1
+ <!-- edgarj_popup/_index.html.erb -->
2
+ <%#
3
+ popup template.
4
+
5
+ see EdgarjPopupController for more detail.
6
+ %>
7
+ <%= render 'search' %>
8
+ <%= render 'list' %>
9
+ <hr>
10
+ <center>
11
+ <%= button_tag t('close'),
12
+ type: 'button',
13
+ id: 'edgarj_popup_close',
14
+ onClick: "$('#edgarj_form_popup').dialog('close');"
15
+ %>
16
+ </center>
@@ -0,0 +1,42 @@
1
+ <%#
2
+ popup list.
3
+
4
+ = INPUTS
5
+
6
+ @list:: popup model list
7
+ params[:id_target]:: target DOM id for 'belongs_to' id (hidden)
8
+
9
+ = OUTPUTS
10
+
11
+ * paginate:
12
+ /edgarj_popup/index?update=...&template=
13
+ * on click item, update id_target DOM by rec.id
14
+ %>
15
+ <% popup_field = Edgarj::PopupHelper::PopupField.new(params[:id_target]) %>
16
+ <div id=edgarj_popup_list> <!-- edgarj/popup/_list.html.erb -->
17
+ <table width="100%">
18
+ <tr>
19
+ <td><%= t('edgarj.default.total_records') % @count %></td>
20
+ <td><%= paginate @list,
21
+ remote: true,
22
+ params: {
23
+ action: 'index',
24
+ #model: model.to_s,
25
+ id_target: popup_field.id_target}%></td>
26
+ </tr>
27
+ </table>
28
+ <%= popup_drawer.draw_list(@list) %>
29
+
30
+ <%= javascript_tag do %>
31
+ $(function(){
32
+ /* invoke select-callback on popup list */
33
+ $('.edgarj_popup_list_row').click(function(){
34
+ $('#<%= popup_field.id_target %>').val($(this).attr('data-id'));
35
+ $('#<%= popup_field.label_target %>').text($(this).attr('data-name'));
36
+ $('#<%= popup_field.label_hidden_field %>').val($(this).attr('data-name'));
37
+ $('#<%= popup_field.clear_link %>').show();
38
+ $('#edgarj_form_popup').dialog('close');
39
+ });
40
+ });
41
+ <% end %>
42
+ </div>
@@ -0,0 +1,15 @@
1
+ <!-- edgarj/_message_popup.html.erb -->
2
+ <%#
3
+ message popup template.
4
+ %>
5
+
6
+ <center>
7
+ <div id=edgarj_message_error ><%= flash[:error] || '' %></div>
8
+ <div id=edgarj_message_notice><%= flash[:notice] || '' %></div>
9
+ <hr>
10
+ <%= button_tag t('close'),
11
+ type: 'button',
12
+ id: 'edgarj_message_popup_close',
13
+ onClick: "$('#edgarj_message_popup').dialog('close');"
14
+ %>
15
+ </center>
@@ -0,0 +1,42 @@
1
+ <%#
2
+ popup search form.
3
+
4
+ = INPUTS
5
+
6
+ @search:: search model
7
+ params[:id_target]:: target DOM id for hidden 'belongs_to' id
8
+
9
+ %>
10
+ <div id=edgarj_popup_search> <!-- edgarj/popup/_search.html.erb -->
11
+ <% pf = Edgarj::PopupHelper::PopupField.new(params[:id_target]) %>
12
+ <%= form_for(@search,
13
+ as: 'search_form',
14
+ remote: true,
15
+ method: :get,
16
+ url: {action: 'search'}) do |f| %>
17
+ <table>
18
+ <tr>
19
+ <td><%= v('search') %></td>
20
+ <td>
21
+ <%= f.select("col",
22
+ popup_drawer.columns_for(popup_drawer.list_columns).map{|col|
23
+ [model.human_attribute_name(col.name), col.name]}) %>
24
+ </td>
25
+ <td><%= f.text_field("val") %></td>
26
+ <td>
27
+ <% if @search.errors.any? %>
28
+ <div class="error_explanation">
29
+ <ul>
30
+ <% @search.errors.full_messages.each do |msg| %>
31
+ <li><%= msg %></li>
32
+ <% end %>
33
+ </ul>
34
+ </div>
35
+ <% end %>
36
+ </td>
37
+ </tr>
38
+ </table>
39
+ <%= hidden_field_tag :model, model.to_s %>
40
+ <%= hidden_field_tag :id_target, pf.id_target %>
41
+ <% end %>
42
+ </div>
@@ -0,0 +1,16 @@
1
+ <!-- edgarj/_search_save_popup.html.erb -->
2
+ <div id=search_save_popup style='display:none'>
3
+ <center>
4
+ <h3><%= t('search_save_dialog') %></h3>
5
+
6
+ <p id=search_save_popup_flash_error style="color: red"
7
+ ><%= @flash_error || '' %></p>
8
+
9
+ <%= t('name') %><input type=text_field id=view_status_name>
10
+ <%= url = url_for(:action=>'search_save');
11
+ button_to_function t('save'),
12
+ sprintf("Edgarj.SearchSavePopup.submit('%s')", url) %>
13
+ <hr>
14
+ <%= button_to_function t('close'), 'Edgarj.SearchSavePopup.close()' %>
15
+ </center>
16
+ </div>
@@ -0,0 +1,5 @@
1
+ $('#edgarj_form_popup').html("<%= j(render 'index') %>");
2
+ $('#edgarj_form_popup').dialog('option', 'title',
3
+ '<%= t('edgarj.form.popup.title') % model.human_name %>');
4
+ $('#edgarj_form_popup').dialog('open');
5
+
@@ -0,0 +1,3 @@
1
+ $('#edgarj_message_popup').html("<%= j(render 'message_popup') %>");
2
+ $('#edgarj_message_popup').dialog('open');
3
+
@@ -0,0 +1 @@
1
+ $('#edgarj_popup_list').replaceWith("<%= j(render 'list') %>");
@@ -0,0 +1,15 @@
1
+ <%#
2
+ index.js.erb needs to draw whole popup elements(list, search, close-button)
3
+ while search.js.erb does only:
4
+
5
+ * draw search form
6
+ * draw list if @search is valid
7
+ %>
8
+ <% if !@search.errors.any? %>
9
+ $('#edgarj_popup_list').replaceWith("<%= j(render 'list') %>");
10
+ <% end %>
11
+ $('#edgarj_popup_search').replaceWith("<%= j(render 'search') %>");
12
+ $('#edgarj_form_popup').dialog('option', 'title',
13
+ '<%= t('edgarj.form.popup.title') % model.human_name %>');
14
+ $('#edgarj_form_popup').dialog('open');
15
+
@@ -0,0 +1 @@
1
+ $('#edgarj_popup_list').replaceWith("<%= j(render 'list') %>");
data/config/routes.rb ADDED
@@ -0,0 +1,15 @@
1
+ Rails.application.routes.draw do
2
+ edgarj_resources :user_group_users
3
+
4
+ namespace :edgarj do
5
+ edgarj_popup_resources :users_popup
6
+ edgarj_popup_resources :user_groups_popup
7
+
8
+ edgarj_resources :model_permissions
9
+ edgarj_resources :sssns
10
+ edgarj_resources :user_groups
11
+ edgarj_resources :user_group_users
12
+ end
13
+
14
+ get :top, to: 'edgarj/edgarj#top'
15
+ end
@@ -0,0 +1,5 @@
1
+ edgarj:
2
+ base:
3
+ time_zone_for_timestamp_comparison: '9'
4
+ work_dir: <%= Rails.root + 'tmp/edgarj' %>
5
+ csv_dir: <%= Rails.root + 'tmp/edgarj/csv_download' %>
@@ -0,0 +1,14 @@
1
+ class CreateEdgarSssns < ActiveRecord::Migration
2
+ def change
3
+ create_table :edgar_sssns do |t|
4
+ t.string :session_id, null: false
5
+ t.text :data
6
+ t.integer :user_id
7
+
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :edgar_sssns, :session_id
12
+ add_index :edgar_sssns, :updated_at
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ class CreateEdgarPageInfos < ActiveRecord::Migration
2
+ def change
3
+ create_table :edgar_page_infos do |t|
4
+ t.integer :sssn_id
5
+ t.string :view
6
+ t.string :order_by
7
+ t.string :dir
8
+ t.integer :page
9
+ t.integer :lines
10
+ t.text :record_data
11
+
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ class CreateEdgarUserGroups < ActiveRecord::Migration
2
+ def change
3
+ create_table :edgar_user_groups do |t|
4
+ t.integer :kind
5
+ t.string :name
6
+ t.integer :parent_id
7
+ t.integer :lft
8
+ t.integer :rgt
9
+
10
+ t.timestamps
11
+ end
12
+
13
+ add_index :edgar_user_groups, :kind
14
+ add_index :edgar_user_groups, :parent_id
15
+ add_index :edgar_user_groups, :lft
16
+ add_index :edgar_user_groups, :rgt
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ class CreateEdgarUserGroupUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :edgar_user_group_users do |t|
4
+ t.integer :user_group_id
5
+ t.integer :user_id
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ class CreateEdgarModelPermissions < ActiveRecord::Migration
2
+ def change
3
+ create_table :edgar_model_permissions do |t|
4
+ t.integer "user_group_id"
5
+ t.string "name"
6
+ t.integer "flags"
7
+ t.datetime "created_at", :null => false
8
+ t.datetime "updated_at", :null => false
9
+ t.string "model"
10
+ end
11
+
12
+ add_index :edgar_model_permissions, :model
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ class RenameEdgarToEdgarj < ActiveRecord::Migration
2
+ def up
3
+ rename_table :edgar_sssns, :edgarj_sssns
4
+ rename_table :edgar_page_infos, :edgarj_page_infos
5
+ rename_table :edgar_user_groups, :edgarj_user_groups
6
+ rename_table :edgar_user_group_users, :edgarj_user_group_users
7
+ rename_table :edgar_model_permissions, :edgarj_model_permissions
8
+ end
9
+
10
+ def down
11
+ rename_table :edgarj_sssns, :edgar_sssns
12
+ rename_table :edgarj_page_infos, :edgar_page_infos
13
+ rename_table :edgarj_user_groups, :edgar_user_groups
14
+ rename_table :edgarj_user_group_users, :edgar_user_group_users
15
+ rename_table :edgarj_model_permissions, :edgar_model_permissions
16
+ end
17
+ end
@@ -0,0 +1,123 @@
1
+ # Add Edgarj specific methods.
2
+ class ActiveRecord::Base
3
+ # cache several kind of information for each (class x kind) during runtime,
4
+ # for example, result of edgarj_address? method.
5
+ @@_edgarj_cache = {}
6
+
7
+ # Fallback is as follows (Author model is an example):
8
+ # 1. t('activerecord.author')
9
+ # 1. t('edgarj.default.author')
10
+ # 1. human()
11
+ def self.human_name
12
+ name = self.model_name
13
+ I18n.t(name.i18n_key,
14
+ scope: :activerecord,
15
+ default: I18n.t(name.i18n_key,
16
+ scope: 'edgarj.default',
17
+ default: name.human))
18
+ end
19
+
20
+ # return AR assoc which the column belongs to. nil if not exist
21
+ def self.belongs_to_AR_assoc(column)
22
+ parent_assoc_cache = edgarj_cache(:parent_assoc)
23
+ if (parent_assoc = parent_assoc_cache[column])
24
+ return parent_assoc
25
+ end
26
+
27
+ for parent_assoc in reflect_on_all_associations(:belongs_to) do
28
+ if !parent_assoc.options[:polymorphic] &&
29
+ parent_assoc.foreign_key.to_sym == column.name.to_sym
30
+ parent_assoc_cache[column] = parent_assoc
31
+ return parent_assoc
32
+ end
33
+ end
34
+ nil
35
+ end
36
+
37
+ # return AR class which the column belongs to. nil if not exist
38
+ def self.belongs_to_AR(column)
39
+ if (parent_assoc = belongs_to_AR_assoc(column))
40
+ parent_assoc.klass
41
+ else
42
+ nil
43
+ end
44
+ end
45
+
46
+ # Human name for 'const' in namespace of the '_module'.
47
+ #
48
+ # I18n fallbacks is as follows (Question::Priority::HIGH as example):
49
+ #
50
+ # 1. t('activerecord.enums.question/priority.HIGH')
51
+ # 1. t('high')
52
+ # 1. 'High'
53
+ #
54
+ def self.human_const_name(_module, const)
55
+ lower = const.downcase
56
+ I18n.t(const,
57
+ scope: "activerecord.enums.#{_module.name.underscore}",
58
+ default: I18n.t(lower,
59
+ scope: 'edgarj.default',
60
+ default: lower.to_s.humanize))
61
+ end
62
+
63
+ # short-cut of:
64
+ # errors.add(attr, I18n.t(message_key, :scope=>'activerecord.errors.messages')
65
+ def err_on(attr, message_key)
66
+ errors.add(
67
+ attr,
68
+ I18n.t(message_key, :scope=>'activerecord.errors.messages'))
69
+ end
70
+
71
+ # get belongs_to association name from column.
72
+ #
73
+ # Example: get_assoc_name(:adrs_id) -> :adrs
74
+ def self.get_belongs_to_name(col_or_sym)
75
+ cache = edgarj_cache(:belongs_to_name)
76
+ col_name = get_column_name(col_or_sym).to_s
77
+ if !cache[col_name].nil?
78
+ return cache[col_name]
79
+ end
80
+
81
+ for reflection in reflect_on_all_associations(:belongs_to) do
82
+ if reflection.foreign_key.to_sym == col_name.to_sym
83
+ cache[col_name] = reflection.name
84
+ return reflection.name
85
+ end
86
+ end
87
+ nil
88
+ end
89
+
90
+ # initialize cache per (class x kind) on the fly
91
+ def self.edgarj_cache(kind)
92
+ @@_edgarj_cache[self] = {} if !@@_edgarj_cache[self]
93
+ @@_edgarj_cache[self][kind] = {} if !@@_edgarj_cache[self][kind]
94
+ @@_edgarj_cache[self][kind]
95
+ end
96
+
97
+ # just for dump purpose
98
+ def self._edgarj_cache
99
+ @@_edgarj_cache
100
+ end
101
+
102
+ # get column name from column object or symbol
103
+ def self.get_column_name(col_or_sym)
104
+ case col_or_sym
105
+ when String, Symbol
106
+ col_or_sym
107
+ else
108
+ col_or_sym.name
109
+ end
110
+ end
111
+
112
+ # return AR object which the column belongs to.
113
+ # return nil if the column is not 'belongs_to'
114
+ #
115
+ # @see self.belongs_to_AR
116
+ def belongs_to_AR(column)
117
+ if (parent_assoc = self.class.belongs_to_AR_assoc(column))
118
+ send(parent_assoc.name)
119
+ else
120
+ nil
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,71 @@
1
+ module ActionDispatch::Routing::Mapper::Resources
2
+ # add followings to work on Edgarj::EdgarjController derived class to
3
+ # default resource routing:
4
+ #
5
+ # collection do
6
+ # get :clear
7
+ # get :csv_download
8
+ # get :search
9
+ # get :search_clear
10
+ # get :search_save
11
+ # get :search_load
12
+ # end
13
+ #
14
+ # member do
15
+ # put :page_info_save
16
+ # end
17
+ #
18
+ def edgarj_resources(*symbols, &block)
19
+ resources *symbols do
20
+ yield if block_given?
21
+
22
+ collection do
23
+ get :clear
24
+ get :csv_download
25
+ get :search
26
+ get :search_clear
27
+ get :search_save
28
+ get :search_load
29
+ get :zip_complete
30
+ end
31
+
32
+ member do
33
+ put :page_info_save
34
+ end
35
+ end
36
+
37
+ self
38
+ end
39
+
40
+ # add followings to work on Edgarj::PopupController derived class to
41
+ # default resource routing:
42
+ #
43
+ # collection do
44
+ # get :clear
45
+ # get :csv_download
46
+ # get :search
47
+ # get :search_clear
48
+ # get :search_save
49
+ # get :search_load
50
+ # end
51
+ #
52
+ # member do
53
+ # put :page_info_save
54
+ # end
55
+ #
56
+ def edgarj_popup_resources(*symbols, &block)
57
+ resources *symbols, only: [:index] do
58
+ yield if block_given?
59
+
60
+ collection do
61
+ get :search
62
+ end
63
+
64
+ member do
65
+ put :page_info_save
66
+ end
67
+ end
68
+
69
+ self
70
+ end
71
+ end
@@ -0,0 +1,64 @@
1
+ module Edgarj
2
+ class Engine < ::Rails::Engine
3
+ require 'core_ext/active_record'
4
+ require 'core_ext/resources'
5
+ require 'edgarj/enum_cache'
6
+
7
+ config.app_generators do |g|
8
+ g.templates.unshift File::expand_path('../templates', __FILE__)
9
+ end
10
+
11
+ # load this engine's config
12
+ # (rails_config default loads from only Rails.root/config/...)
13
+ def self.load_config
14
+ engine_config_dir = Pathname.new(File.expand_path('../../../config', __FILE__))
15
+ Settings.add_source!((engine_config_dir + 'settings.yml').to_s)
16
+ Settings.add_source!((engine_config_dir + "settings/#{Rails.env}.yml").to_s)
17
+ Settings.reload!
18
+ end
19
+
20
+ # Require/load application side edgarj config in RAILS_ROOT/config/edgarj/
21
+ def self.load_edgarj_conf_in_app
22
+ [
23
+ Dir.glob(File.join(Rails.root, "config/edgarj/**/*.rb"))
24
+ ].flatten.each do |edgarj_conf|
25
+ Rails.application.config.cache_classes ?
26
+ require(edgarj_conf) :
27
+ load(edgarj_conf)
28
+ end
29
+ end
30
+
31
+ # Require/load (based on config) all decorators from app/decorators/
32
+ #
33
+ # thanks:
34
+ # * http://edgeguides.rubyonrails.org/engines.html#overriding-models-and-controllers
35
+ # * https://github.com/resolve/refinerycms/commit/3387b547f8e58c9fced9eee78ca1bd2acd2588c2
36
+ def self.load_decorators
37
+ [
38
+ Dir.glob(File.join(Rails.root, "app/decorators/**/*_decorator.rb"))
39
+ ].flatten.each do |decorator|
40
+ Rails.application.config.cache_classes ?
41
+ require(decorator) :
42
+ load(decorator)
43
+ end
44
+ end
45
+
46
+ # make edgarj related work directories
47
+ def self.make_work_dir
48
+ for dir in [Settings.edgarj.work_dir, Settings.edgarj.csv_dir] do
49
+ FileUtils.mkdir_p(dir) if !File.directory?(dir)
50
+ end
51
+ end
52
+
53
+ initializer "edgarj" do
54
+ ActiveRecord::SessionStore::Session.table_name = 'edgarj_sssns'
55
+ Engine::load_config
56
+ Engine::load_edgarj_conf_in_app
57
+ Engine::load_decorators
58
+ for file in Dir.glob(File.join(File.dirname(__FILE__), "../../locale/*.yml")) do
59
+ I18n.load_path << file
60
+ end
61
+ Engine::make_work_dir
62
+ end
63
+ end
64
+ end