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,30 @@
1
+ module Edgarj
2
+ module AuthenticationMixin
3
+ def self.included(klass)
4
+ klass.helper_method :current_user
5
+ end
6
+
7
+ private
8
+ def access_denied
9
+ flash.now[:error] = v('login_failed')
10
+ #redirect_to login_path
11
+ respond_to do |format|
12
+ format.html {
13
+ render '/edgarj/sssns/new', layout: 'login'
14
+ }
15
+ format.js {
16
+ render '/edgarj/sssns/new'
17
+ }
18
+ end
19
+ end
20
+
21
+ # before_filter to enforce a login requirement.
22
+ def require_login
23
+ !!current_user || access_denied
24
+ end
25
+
26
+ def current_user
27
+ @current_user ||= User.find(session[:user_id]) if session[:user_id]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,80 @@
1
+ module Edgarj
2
+ # Common module for EdgarjController and PopupController.
3
+ module ControllerMixinCommon
4
+ def self.included(klass)
5
+ klass.before_filter :intern_sssn
6
+ end
7
+
8
+ # page is reset to 1 since order and/or lines/page are/is changed.
9
+ def page_info_save
10
+ if (@page_info = @sssn.page_infos.find_by_id(params[:id]))
11
+ @page_info.update_attributes(page_info_params)
12
+ @page_info.update_attribute(:page, 1)
13
+ end
14
+ prepare_list
15
+ end
16
+
17
+ private
18
+ # return page related infomation for each controller x session.
19
+ #
20
+ # search_form may depend on each controller so that search_form
21
+ # method should be defined for each controller.
22
+ def page_info
23
+ @page_info ||= PageInfo.intern(@sssn, controller_name, search_form)
24
+ end
25
+
26
+ # Only allow a trusted parameter "white list" through.
27
+ def page_info_params
28
+ params.require(:edgarj_page_info).permit(
29
+ :view,
30
+ :order_by,
31
+ :dir,
32
+ :page,
33
+ :lines,
34
+ :record_data)
35
+ end
36
+
37
+ # prepare followings:
38
+ # 1. @page_info
39
+ # 1. @count
40
+ # 1. @list (with user_scoped if defined)
41
+ #
42
+ # This private method is called from both EdgarjController and
43
+ # EdgarjPopupController to draw list.
44
+ #
45
+ # You can overwrite prepare_list() to show list at your controller.
46
+ def prepare_list
47
+ page_info
48
+ @list = user_scoped.where(@page_info.record.conditions).
49
+ page(@page_info.page).
50
+ per(@page_info.lines)
51
+ if !@page_info.order_by.blank?
52
+ @list = @list.order(@page_info.order_by + ' ' + @page_info.dir)
53
+ end
54
+
55
+ @count = user_scoped.where(@page_info.record.conditions).count
56
+ end
57
+
58
+ # provide 2nd parameter for Model.user_scoped(user, context).
59
+ # Default is @sssn.
60
+ def scope_context
61
+ @sssn
62
+ end
63
+
64
+ # narrow data scope on model
65
+ #
66
+ # Model's user_scoped parameters are as follows:
67
+ # 1st argument:: current_user
68
+ # 2nd argument:: scope_context method result (default = @sssn)
69
+ # 3rd argument:: target for popup (see below for the detail)
70
+ #
71
+ # === 3rd argument
72
+ # This is used to identify which column the selected value
73
+ # on the popup is populated.
74
+ def user_scoped
75
+ @_user_scoped ||= model.respond_to?(:user_scoped) ?
76
+ model.user_scoped(current_user, scope_context, params[:id_target]) :
77
+ model
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,71 @@
1
+ module Edgarj
2
+ # Mixin for All controllers (not only Edgarj::ControllerMixin include class)
3
+ module ControllerMixinForApp
4
+ def self.included(klass)
5
+ klass.helper_method :v, :url_prefix
6
+ end
7
+
8
+ private
9
+ # Transform the controller name into a more humane format, using I18n.
10
+ # I18n fallbacks work as follows (LeadsController as example):
11
+ #
12
+ # 1. t('activerecord.models.lead')
13
+ # 1. t('controller.leads')
14
+ # 1. t('lead')
15
+ # 1. 'Lead'
16
+ def human_name
17
+ @human_name ||= begin
18
+ str = controller_path
19
+ single = str.singularize
20
+ I18n.t( "activerecord.models.#{model.to_s.underscore}",
21
+ default: I18n.t("controller.#{str}",
22
+ default: I18n.t(single,
23
+ default: single.camelize)))
24
+ end
25
+ end
26
+
27
+ # application-wide rescue to log error info.
28
+ def app_rescue
29
+ logger.error(sprintf("error %s(%s) at %s#%s:\n%s",
30
+ $!.class.to_s,
31
+ $!.to_s,
32
+ self.class.name,
33
+ self.action_name,
34
+ $@.join("\n")))
35
+ end
36
+
37
+ # set @sssn if not exist
38
+ def intern_sssn
39
+ @sssn ||=
40
+ if (sid = request.session_options[:id])
41
+ Edgarj::Sssn.find_by_session_id(sid) ||
42
+ Edgarj::Sssn.new(session_id: sid)
43
+ else
44
+ Edgarj::Sssn.new
45
+ end
46
+ end
47
+
48
+ # convenient t() for view. v(KEY) fallback works as follows:
49
+ #
50
+ # 1. t('view.CONTROLLER.KEY') if exists. Where, CONTROLLER
51
+ # is controller name.
52
+ # 1. t('edgarj.view.CONTROLLER.KEY') if exists.
53
+ # 1. t('edgarj.default.KEY') if exists.
54
+ # 1. Key
55
+ #
56
+ def v(key)
57
+ t(key,
58
+ scope: "view.#{controller_name}",
59
+ default: I18n.t(key,
60
+ scope: "edgarj.view.#{controller_name}",
61
+ default: I18n.t(key,
62
+ scope: 'edgarj.default',
63
+ default: key.camelize)))
64
+ end
65
+
66
+ # TODO: dirty solution to support url namespace
67
+ def url_prefix
68
+ @url_prefix ||= '/'
69
+ end
70
+ end
71
+ end