edgarj 0.01.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +23 -0
- data/Rakefile +40 -0
- data/app/assets/javascripts/edgarj/base.js +49 -0
- data/app/assets/javascripts/edgarj/menu.js +39 -0
- data/app/assets/javascripts/edgarj/operator_selection.js +133 -0
- data/app/assets/stylesheets/edgarj/base.css +304 -0
- data/app/assets/stylesheets/edgarj/menu.css +65 -0
- data/app/controllers/edgarj/authentication_mixin.rb.sample +30 -0
- data/app/controllers/edgarj/controller_mixin_common.rb +80 -0
- data/app/controllers/edgarj/controller_mixin_for_app.rb +71 -0
- data/app/controllers/edgarj/edgarj_controller.rb +535 -0
- data/app/controllers/edgarj/model_permissions_controller.rb +8 -0
- data/app/controllers/edgarj/permission_mixin.rb +84 -0
- data/app/controllers/edgarj/popup_controller.rb +128 -0
- data/app/controllers/edgarj/rescue_mixin.rb +37 -0
- data/app/controllers/edgarj/user_group_users_controller.rb +8 -0
- data/app/controllers/edgarj/user_groups_controller.rb +9 -0
- data/app/controllers/edgarj/user_groups_popup_controller.rb +8 -0
- data/app/helpers/edgarj/assoc_helper.rb +369 -0
- data/app/helpers/edgarj/common_helper.rb +37 -0
- data/app/helpers/edgarj/edgarj_helper.rb +20 -0
- data/app/helpers/edgarj/field_helper.rb +397 -0
- data/app/helpers/edgarj/form_drawer.rb +322 -0
- data/app/helpers/edgarj/list_drawer.rb +169 -0
- data/app/helpers/edgarj/menu_helper.rb +92 -0
- data/app/helpers/edgarj/model_permissions_helper.rb +9 -0
- data/app/helpers/edgarj/popup_helper.rb +40 -0
- data/app/helpers/edgarj/search_helper.rb +14 -0
- data/app/helpers/edgarj/sessions_helper.rb +9 -0
- data/app/helpers/edgarj/user_group_users_helper.rb +9 -0
- data/app/helpers/edgarj/user_groups_helper.rb +9 -0
- data/app/helpers/edgarj/user_groups_popup_helper.rb +9 -0
- data/app/models/edgarj/drawer/base.rb +234 -0
- data/app/models/edgarj/drawer/normal.rb +6 -0
- data/app/models/edgarj/drawer/popup.rb +47 -0
- data/app/models/edgarj/drawer.rb +13 -0
- data/app/models/edgarj/model_permission.rb +41 -0
- data/app/models/edgarj/page_info.rb +47 -0
- data/app/models/edgarj/search.rb +81 -0
- data/app/models/edgarj/search_form.rb +255 -0
- data/app/models/edgarj/search_popup.rb +44 -0
- data/app/models/edgarj/sssn.rb +120 -0
- data/app/models/edgarj/user_group.rb +67 -0
- data/app/models/edgarj/user_group_user.rb +18 -0
- data/app/models/edgarj.rb +5 -0
- data/app/views/edgarj/edgarj/_form.html.erb +25 -0
- data/app/views/edgarj/edgarj/_list.html.erb +52 -0
- data/app/views/edgarj/edgarj/_message_popup.html.erb +15 -0
- data/app/views/edgarj/edgarj/_search_form.html.erb +64 -0
- data/app/views/edgarj/edgarj/_search_operator.html.erb +17 -0
- data/app/views/edgarj/edgarj/_search_operator_selection.html.erb +12 -0
- data/app/views/edgarj/edgarj/clear.js.erb +1 -0
- data/app/views/edgarj/edgarj/create.js.erb +4 -0
- data/app/views/edgarj/edgarj/destroy.js.erb +2 -0
- data/app/views/edgarj/edgarj/index.html.erb +37 -0
- data/app/views/edgarj/edgarj/index.js.erb +1 -0
- data/app/views/edgarj/edgarj/message_popup.js.erb +3 -0
- data/app/views/edgarj/edgarj/page_info_save.js.erb +1 -0
- data/app/views/edgarj/edgarj/search.js.erb +4 -0
- data/app/views/edgarj/edgarj/search_clear.js.erb +1 -0
- data/app/views/edgarj/edgarj/show.js.erb +1 -0
- data/app/views/edgarj/edgarj/top.html.erb +4 -0
- data/app/views/edgarj/edgarj/update.js.erb +4 -0
- data/app/views/edgarj/popup/_index.html.erb +16 -0
- data/app/views/edgarj/popup/_list.html.erb +42 -0
- data/app/views/edgarj/popup/_message_popup.html.erb +15 -0
- data/app/views/edgarj/popup/_search.html.erb +42 -0
- data/app/views/edgarj/popup/_search_save_popup.html.erb +16 -0
- data/app/views/edgarj/popup/index.js.erb +5 -0
- data/app/views/edgarj/popup/message_popup.js.erb +3 -0
- data/app/views/edgarj/popup/page_info_save.js.erb +1 -0
- data/app/views/edgarj/popup/search.js.erb +15 -0
- data/app/views/edgarj/popup/view_status_save.js.erb +1 -0
- data/config/routes.rb +15 -0
- data/config/settings.yml +5 -0
- data/db/migrate/20131118084600_create_edgar_sssns.rb +14 -0
- data/db/migrate/20131123124730_create_edgar_page_infos.rb +15 -0
- data/db/migrate/20140116062252_create_edgar_user_groups.rb +18 -0
- data/db/migrate/20140116062327_create_edgar_user_group_users.rb +10 -0
- data/db/migrate/20140206222308_create_edgar_model_permissions.rb +14 -0
- data/db/migrate/20141209053055_rename_edgar_to_edgarj.rb +17 -0
- data/lib/core_ext/active_record.rb +123 -0
- data/lib/core_ext/resources.rb +71 -0
- data/lib/edgarj/engine.rb +64 -0
- data/lib/edgarj/enum_cache.rb +46 -0
- data/lib/edgarj/templates/rails/helper/helper.rb +10 -0
- data/lib/edgarj/templates/test_unit/scaffold/functional_test.rb +575 -0
- data/lib/edgarj/version.rb +3 -0
- data/lib/edgarj.rb +14 -0
- data/lib/generators/edgarj/popup_scaffold/USAGE +6 -0
- data/lib/generators/edgarj/popup_scaffold/popup_scaffold_generator.rb +35 -0
- data/lib/generators/edgarj/popup_scaffold/templates/controller.rb +13 -0
- data/lib/generators/edgarj/popup_scaffold/templates/functional_test.rb +197 -0
- data/lib/generators/edgarj/popup_scaffold/templates/helper.rb +9 -0
- data/lib/generators/edgarj/scaffold/USAGE +17 -0
- data/lib/generators/edgarj/scaffold/scaffold_generator.rb +40 -0
- data/lib/generators/edgarj/scaffold/templates/controller.rb +13 -0
- data/lib/tasks/edgarj_tasks.rake +32 -0
- data/lib/tasks/pakcage.rake +18 -0
- data/locale/en.yml +94 -0
- data/locale/ja.yml +100 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +21 -0
- data/test/dummy/app/assets/javascripts/authors.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -0
- data/test/dummy/app/assets/stylesheets/authors.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +15 -0
- data/test/dummy/app/controllers/authors_controller.rb +6 -0
- data/test/dummy/app/controllers/authors_popup_controller.rb +6 -0
- data/test/dummy/app/controllers/books_controller.rb +6 -0
- data/test/dummy/app/controllers/dummy_auth_mixin.rb +36 -0
- data/test/dummy/app/decorators/models/edgarj/user_group_decorator.rb +1 -0
- data/test/dummy/app/helpers/application_helper.rb +3 -0
- data/test/dummy/app/helpers/authors_helper.rb +7 -0
- data/test/dummy/app/helpers/authors_popup_helper.rb +7 -0
- data/test/dummy/app/helpers/books_helper.rb +7 -0
- data/test/dummy/app/models/author.rb +32 -0
- data/test/dummy/app/models/book.rb +5 -0
- data/test/dummy/app/models/user.rb +13 -0
- data/test/dummy/app/views/layouts/application.html.erb +32 -0
- data/test/dummy/app/views/layouts/login.html.erb +20 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +15 -0
- data/test/dummy/config/edgarj/menu_config.rb +28 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +42 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +34 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/strong_parameter.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +26 -0
- data/test/dummy/config/routes.rb +60 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/migrate/20131107120635_create_authors.rb +9 -0
- data/test/dummy/db/migrate/20131218011851_create_books.rb +10 -0
- data/test/dummy/db/migrate/20140201000000_add_user_group_id_to_authors.rb +5 -0
- data/test/dummy/db/migrate/20140807065420_create_users.rb +10 -0
- data/test/dummy/db/schema.rb +93 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test/functional/authors_controller_test.rb +631 -0
- data/test/dummy/test/functional/books_controller_test.rb +516 -0
- data/test/dummy/test/helpers/authors_helper_test.rb +4 -0
- data/test/dummy/test/unit/author_test.rb +7 -0
- data/test/dummy/test/unit/book_test.rb +7 -0
- data/test/edgar_test.rb +7 -0
- data/test/fixtures/authors.yml +32 -0
- data/test/fixtures/books.yml +56 -0
- data/test/fixtures/edgarj/model_permissions.yml +97 -0
- data/test/fixtures/edgarj/page_infos.yml +84 -0
- data/test/fixtures/edgarj/sssns.yml +38 -0
- data/test/fixtures/edgarj/user_group_users.yml +114 -0
- data/test/fixtures/edgarj/user_groups.yml +95 -0
- data/test/fixtures/users.yml +49 -0
- data/test/functional/edgarj/edgarj_controller_test.rb +24 -0
- data/test/functional/edgarj/model_permissions_controller_test.rb +554 -0
- data/test/functional/edgarj/user_group_users_controller_test.rb +567 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/support/edgarj/controller_supporter.rb +23 -0
- data/test/test_helper.rb +23 -0
- data/test/unit/edgarj/model_permission_test.rb +27 -0
- data/test/unit/edgarj/page_info_test.rb +7 -0
- data/test/unit/edgarj/sssn_test.rb +10 -0
- data/test/unit/edgarj/user_group_test.rb +32 -0
- data/test/unit/edgarj/user_group_user_test.rb +9 -0
- data/test/unit/helpers/edgarj/model_permissions_helper_test.rb +6 -0
- data/test/unit/helpers/edgarj/user_group_users_helper_test.rb +6 -0
- 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' -%>"><></li>
|
7
|
+
<li id="<%= id + '_gt' -%>">></li>
|
8
|
+
<li id="<%= id + '_ge' -%>">>=</li>
|
9
|
+
<li id="<%= id + '_lt' -%>"><</li>
|
10
|
+
<li id="<%= id + '_le' -%>"><=</li>
|
11
|
+
</ul>
|
12
|
+
</div>
|
@@ -0,0 +1 @@
|
|
1
|
+
$('#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 @@
|
|
1
|
+
$('#edgarj_list').replaceWith("<%= j(render 'list') %>");
|
@@ -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,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 @@
|
|
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
|
data/config/settings.yml
ADDED
@@ -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,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
|