edgarj 0.01.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,322 @@
|
|
|
1
|
+
# coding: UTF-8
|
|
2
|
+
|
|
3
|
+
module Edgarj
|
|
4
|
+
module FormDrawer
|
|
5
|
+
# Edgarj::FormDrawer::Base draws HTML table tag based data entry form.
|
|
6
|
+
# This also provides default methods for SearchFormDrawer search condition
|
|
7
|
+
# entry form.
|
|
8
|
+
#
|
|
9
|
+
# === How to Customize
|
|
10
|
+
# 1. First, it may be enough to just redefine @options
|
|
11
|
+
# 1. Next, when draw_ATTR() is defined, it is called. See ModelPermissionControllerHelper for example.
|
|
12
|
+
# 1. Then, consider to overwrite draw_ATTR() method.
|
|
13
|
+
class Base
|
|
14
|
+
|
|
15
|
+
# === INPUTS
|
|
16
|
+
# drawer:: Edgarj::Drawer instance
|
|
17
|
+
# record:: instance of AR
|
|
18
|
+
# f:: FormBuilder
|
|
19
|
+
def initialize(drawer, record, f)
|
|
20
|
+
@drawer = drawer
|
|
21
|
+
@vc = drawer.vc # just short-cut
|
|
22
|
+
@record = record
|
|
23
|
+
@f = f
|
|
24
|
+
|
|
25
|
+
# define default options for draw_X() method, where X is :flags, :kind,
|
|
26
|
+
# and so on. @options can be redefined at derived class.
|
|
27
|
+
@options = {
|
|
28
|
+
:flags => {},
|
|
29
|
+
:kind => {},
|
|
30
|
+
:boolean => {},
|
|
31
|
+
:default => {
|
|
32
|
+
:date => {:use_month_numbers=>true},
|
|
33
|
+
:integer => {:size=>16},
|
|
34
|
+
:text => {:size=>20},
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# draw form
|
|
40
|
+
#
|
|
41
|
+
# I18n for label is:
|
|
42
|
+
#
|
|
43
|
+
# 1. usual column uses model.human_attribute_name()
|
|
44
|
+
# 1. 'belongs_to' column uses:
|
|
45
|
+
# ** I18n.t('activerecord.attributes.MODEL.EXT_ID')
|
|
46
|
+
# ** parent.human_name
|
|
47
|
+
def draw()
|
|
48
|
+
adrs_field = {}
|
|
49
|
+
@vc.content_tag(:table) do
|
|
50
|
+
@left = true
|
|
51
|
+
html = ''
|
|
52
|
+
for col in columns do
|
|
53
|
+
draw_method = "draw_#{col.name}"
|
|
54
|
+
html << if self.class.method_defined?(draw_method) then
|
|
55
|
+
send(draw_method, col)
|
|
56
|
+
#elsif edgarj_address?(col)
|
|
57
|
+
# draw_address(col)
|
|
58
|
+
#elsif edgarj_file?(col)
|
|
59
|
+
# draw_file(col)
|
|
60
|
+
elsif (enum = get_enum(col))
|
|
61
|
+
draw_enum(col, enum)
|
|
62
|
+
elsif (bitset = get_bitset(col))
|
|
63
|
+
draw_bitset(col, bitset)
|
|
64
|
+
else
|
|
65
|
+
parent_model = @vc.model.belongs_to_AR(col)
|
|
66
|
+
if parent_model
|
|
67
|
+
_draw_belongs_to_field(parent_model, col)
|
|
68
|
+
else
|
|
69
|
+
_draw_field(col)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
html << '<td colspan=3></td>'.html_safe if !@left
|
|
74
|
+
html.html_safe
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def columns
|
|
79
|
+
drawer = @vc.drawer
|
|
80
|
+
drawer.columns_for(drawer.form_columns)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# base method for derived class
|
|
84
|
+
def edgarj_address?(col)
|
|
85
|
+
@record.class.edgarj_address?(col)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# base method for derived class
|
|
89
|
+
def edgarj_file?(col)
|
|
90
|
+
@record.class.edgarj_file?(col)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# return enum of the column
|
|
94
|
+
#
|
|
95
|
+
# Derived class must overwrite to return expected enum
|
|
96
|
+
def get_enum(col)
|
|
97
|
+
@vc.get_enum(@f.object.class, col)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# return bitset of the column
|
|
101
|
+
#
|
|
102
|
+
# Derived class must overwrite to return expected bitset
|
|
103
|
+
def get_bitset(col)
|
|
104
|
+
@vc.get_bitset(@f.object.class, col)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# flip field to left-lane or right-lane
|
|
108
|
+
def _draw_2_lane(&block)
|
|
109
|
+
result = @left ? '<tr>' : ''
|
|
110
|
+
result += yield
|
|
111
|
+
result += '</tr>' if !@left
|
|
112
|
+
@left = !@left # flip it
|
|
113
|
+
result
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# draw head(label). SearchFormDrawer will overwrite to insert operator.
|
|
117
|
+
#
|
|
118
|
+
# === INPUTS
|
|
119
|
+
# col:: column info
|
|
120
|
+
# label:: if not-nil, label is used rather than human_attribute_name of col.name for field-label
|
|
121
|
+
# block:: wrapped field-drawing logic
|
|
122
|
+
#
|
|
123
|
+
def _draw_head(col, label=nil, &block)
|
|
124
|
+
_draw_2_lane{
|
|
125
|
+
html = @vc.content_tag(:th, label || @record.class.human_attribute_name(col.name))
|
|
126
|
+
html << @vc.content_tag(:td, '')
|
|
127
|
+
html << (@vc.content_tag(:td) do yield end)
|
|
128
|
+
html
|
|
129
|
+
}
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def draw_id(col)
|
|
133
|
+
''
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def draw_type(col)
|
|
137
|
+
''
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def draw_created_at(col)
|
|
141
|
+
''
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def draw_updated_at(col)
|
|
145
|
+
''
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# draw address fields
|
|
149
|
+
def draw_address(col)
|
|
150
|
+
_draw_head(col){ @vc.draw_address(@f, col) }
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
# draw bitset checkboxes field
|
|
154
|
+
def draw_bitset(col, bitset)
|
|
155
|
+
_draw_head(col){ @vc.draw_bitset(@f, col, bitset, @options[:flags]) }
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# draw 'belongs_to' field for AR
|
|
159
|
+
def _draw_belongs_to_field(parent_model, col)
|
|
160
|
+
_draw_head(col, @vc.draw_belongs_to_label(@f, @drawer.popup_path(col), col.name)){
|
|
161
|
+
@vc.draw_belongs_to_field(@f, col.name)
|
|
162
|
+
}
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def draw_boolean(col)
|
|
166
|
+
_draw_head(col){ @vc.draw_boolean(@f, col, @options[:boolean]) }
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def draw_file(col)
|
|
170
|
+
_draw_head(col){ @vc.draw_file(@f, col) }
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def draw_enum(col, enum)
|
|
174
|
+
_draw_head(col){ @vc.draw_enum(@f, col, enum) }
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# draw general field
|
|
178
|
+
def _draw_field(col)
|
|
179
|
+
case col.type
|
|
180
|
+
when :boolean
|
|
181
|
+
draw_boolean(col)
|
|
182
|
+
else
|
|
183
|
+
_draw_head(col){ @vc.draw_field(@f, col, @options[:default]) }
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# Search-class differs from Base-class as follows:
|
|
189
|
+
# * draws the fields of ID, created_at, and updated_at for search
|
|
190
|
+
# * 'kind' selection has blank-option.
|
|
191
|
+
# * boolean is not checkbox. Rather, it is selection of [nil,false,true]
|
|
192
|
+
# * edgarj_file column is not drawn.
|
|
193
|
+
class Search < Base
|
|
194
|
+
# === INPUTS
|
|
195
|
+
# drawer:: Edgarj::Drawer instance
|
|
196
|
+
# model:: SearchForm object
|
|
197
|
+
# f:: FormBuilder object
|
|
198
|
+
# operator_builder:: FormBuilder object for operator
|
|
199
|
+
def initialize(drawer, model, f, operator_builder)
|
|
200
|
+
super(drawer, model, f)
|
|
201
|
+
@operator_builder = operator_builder
|
|
202
|
+
|
|
203
|
+
# merge options
|
|
204
|
+
@options[:kind].merge!(:include_blank=>true)
|
|
205
|
+
@options[:default][:date].merge!(:include_blank=>true)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# overwrite
|
|
209
|
+
def columns
|
|
210
|
+
drawer = @vc.drawer
|
|
211
|
+
drawer.columns_for(drawer.search_form_columns)
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# overwrite
|
|
215
|
+
def edgarj_address?(col)
|
|
216
|
+
@record._klass_str.constantize.edgarj_address?(col)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# overwrite
|
|
220
|
+
def edgarj_file?(col)
|
|
221
|
+
@record._klass_str.constantize.edgarj_file?(col)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# overwrite to insert operator
|
|
225
|
+
#
|
|
226
|
+
def _draw_head(col, label=nil, &block)
|
|
227
|
+
_draw_2_lane{
|
|
228
|
+
sprintf("<th>%s</th><td>", label || @record.class.human_attribute_name(col.name)) +
|
|
229
|
+
|
|
230
|
+
# add operator for appropreate data type.
|
|
231
|
+
if col.name == 'id'
|
|
232
|
+
@vc.draw_search_operator(@operator_builder, '_id')
|
|
233
|
+
else
|
|
234
|
+
case col.type
|
|
235
|
+
when :date, :datetime, :integer
|
|
236
|
+
@vc.draw_search_operator(@operator_builder, col.name)
|
|
237
|
+
else
|
|
238
|
+
''
|
|
239
|
+
end
|
|
240
|
+
end + '</td><td>' + yield + '</td>'
|
|
241
|
+
}
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# overwrite to draw 'id' search field
|
|
245
|
+
def draw_id(col)
|
|
246
|
+
_draw_head(col){ @f.text_field('_id', @options[:default][:integer]) }
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
# overwrite to draw created_at
|
|
250
|
+
def draw_created_at(col)
|
|
251
|
+
_draw_head(col){ @vc.draw_date(@f, col, @options[:default]) }
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
# overwrite to draw updated_at
|
|
255
|
+
def draw_updated_at(col)
|
|
256
|
+
_draw_head(col){ @vc.draw_date(@f, col, @options[:default]) }
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# overwrite to draw address fields: TBD
|
|
260
|
+
def draw_address(col)
|
|
261
|
+
_draw_head(col){
|
|
262
|
+
'TBD'
|
|
263
|
+
}
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# overwrite to draw 'belongs_to' field for SearchForm
|
|
267
|
+
#
|
|
268
|
+
# This is similar to Base class 'belongs_to field', but
|
|
269
|
+
# * add parent 'name' hidden field at drawing.
|
|
270
|
+
# * no link on parent name
|
|
271
|
+
def _draw_belongs_to_field(parent_model, col)
|
|
272
|
+
model = @f.object._klass_str.constantize
|
|
273
|
+
parent_name = @f.object._parent && @f.object._parent[col.name]
|
|
274
|
+
_draw_head(col, @vc.draw_belongs_to_label(@f, @drawer.popup_path_on_search(col), col.name, model)){
|
|
275
|
+
popup_field = Edgarj::PopupHelper::PopupField.new_builder(
|
|
276
|
+
@f.object_name, col.name)
|
|
277
|
+
|
|
278
|
+
@vc.content_tag(:span, parent_name, id: popup_field.label_target) +
|
|
279
|
+
@vc.hidden_field_tag(
|
|
280
|
+
'edgarj_search_form[search_form_parent][%s]' % col.name,
|
|
281
|
+
parent_name.blank? ? '' : parent_name,
|
|
282
|
+
id: popup_field.label_hidden_field) +
|
|
283
|
+
@vc.draw_belongs_to_clear_link(@f, col.name, popup_field, parent_name)
|
|
284
|
+
}
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
# overwrite because it is totally different from checkbox on search.
|
|
288
|
+
def draw_boolean(col)
|
|
289
|
+
_draw_head(col){
|
|
290
|
+
@f.select(col.name, [
|
|
291
|
+
['(both)', ''],
|
|
292
|
+
['', 'false'],
|
|
293
|
+
['√', 'true']])
|
|
294
|
+
}
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
# overwrite to return enum of the column in SearchForm
|
|
298
|
+
#
|
|
299
|
+
# see overwritten draw_enum() also.
|
|
300
|
+
def get_enum(col)
|
|
301
|
+
@vc.get_enum(@record._klass_str.constantize, col)
|
|
302
|
+
end
|
|
303
|
+
|
|
304
|
+
# overwrite to add '(all)' at top of enum selection for search.
|
|
305
|
+
#
|
|
306
|
+
# see overwritten get_enum() also.
|
|
307
|
+
def draw_enum(col, enum)
|
|
308
|
+
_draw_head(col){
|
|
309
|
+
@vc.draw_enum(@f, col, enum,
|
|
310
|
+
:choice_1st => ['(all)',''],
|
|
311
|
+
:class => @record._klass_str.constantize
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
# overwrite to disable file upload column
|
|
317
|
+
def draw_file(col)
|
|
318
|
+
''
|
|
319
|
+
end
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
end
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# coding: UTF-8
|
|
2
|
+
|
|
3
|
+
module Edgarj
|
|
4
|
+
module ListDrawer
|
|
5
|
+
# Base for popup-list and normal-list column drawer
|
|
6
|
+
#
|
|
7
|
+
# Sub class of Drawer to draw list
|
|
8
|
+
class Base
|
|
9
|
+
include ERB::Util
|
|
10
|
+
|
|
11
|
+
# * options
|
|
12
|
+
# * namespace - namespace for path (ex: :admin)
|
|
13
|
+
#
|
|
14
|
+
# TODO: enum_cache は止め、グローバルに1つのキャッシュを作る。
|
|
15
|
+
def initialize(drawer, options = {})
|
|
16
|
+
@drawer = drawer
|
|
17
|
+
@options = options.dup
|
|
18
|
+
@vc = drawer.vc
|
|
19
|
+
@enum_cache = {}
|
|
20
|
+
@bitset_cache = {}
|
|
21
|
+
@parent_rec = nil
|
|
22
|
+
@belongs_to_link = false # doesn't make link on belongs_to
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def draw_column(rec, col)
|
|
26
|
+
@parent_rec = rec.belongs_to_AR(col)
|
|
27
|
+
@vc.content_tag(:td, td_options(rec, col)) do
|
|
28
|
+
# edgarj_address column is prior to draw_belongs_to() because of
|
|
29
|
+
# avoiding link_to process on the 'belongs_to' column.
|
|
30
|
+
=begin
|
|
31
|
+
if rec.class.edgarj_address?(col)
|
|
32
|
+
col_name = rec.class.get_column_name(col)
|
|
33
|
+
adrs = Edgarj::Address.find_by_id(rec.send(col_name))
|
|
34
|
+
adrs ? draw_trimmed_str(adrs.name) : ''
|
|
35
|
+
=end
|
|
36
|
+
if @parent_rec then
|
|
37
|
+
if @belongs_to_link
|
|
38
|
+
@vc.link_to(@parent_rec.name, @drawer.popup_path(col), remote: true)
|
|
39
|
+
else
|
|
40
|
+
h(@parent_rec.name)
|
|
41
|
+
end
|
|
42
|
+
else
|
|
43
|
+
draw_normal_column(rec, col)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
# <td> options
|
|
50
|
+
def td_options(rec, col)
|
|
51
|
+
if @enum_cache[col.name]
|
|
52
|
+
{}
|
|
53
|
+
elsif @bitset_cache[col.name]
|
|
54
|
+
{}
|
|
55
|
+
elsif @parent_rec
|
|
56
|
+
{}
|
|
57
|
+
else
|
|
58
|
+
if @vc.get_enum(rec.class, col)
|
|
59
|
+
{}
|
|
60
|
+
# elsif @vc.get_bitset(rec.class, col)
|
|
61
|
+
# {}
|
|
62
|
+
else
|
|
63
|
+
case col.type
|
|
64
|
+
when :datetime
|
|
65
|
+
{}
|
|
66
|
+
when :date
|
|
67
|
+
{}
|
|
68
|
+
when :integer
|
|
69
|
+
{align: 'right'}
|
|
70
|
+
when :boolean
|
|
71
|
+
{align: 'center'}
|
|
72
|
+
else
|
|
73
|
+
{}
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# trim string when too long
|
|
80
|
+
def draw_trimmed_str(str)
|
|
81
|
+
s = str.split(//)
|
|
82
|
+
if s.size > Edgarj::LIST_TEXT_MAX_LEN
|
|
83
|
+
s = s[0..Edgarj::LIST_TEXT_MAX_LEN] << '...'
|
|
84
|
+
end
|
|
85
|
+
s.join('')
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# draw rec.col other than 'belongs_to'
|
|
90
|
+
# 1. DateTime format is YYYY-MM-DD hh:mm:ss.
|
|
91
|
+
# 1. if col.name == 'flags', it is assumed bitset.
|
|
92
|
+
# 1. if col is edgarj_file, it is assumed file.
|
|
93
|
+
#
|
|
94
|
+
# === INPUTS
|
|
95
|
+
# rec:: AR instance
|
|
96
|
+
# col:: ActiveRecord::ConnectionAdapters::Column type which rec.class.columns returns
|
|
97
|
+
def draw_normal_column(rec, col)
|
|
98
|
+
=begin
|
|
99
|
+
if rec.class.edgarj_file?(col)
|
|
100
|
+
file_info = FileInfo.safe_find(rec.send(col.name))
|
|
101
|
+
file_info ? file_info.filename : ''
|
|
102
|
+
elsif (enum = @enum_cache[col.name])
|
|
103
|
+
@vc.draw_column_enum(rec, col, enum)
|
|
104
|
+
elsif (bitset = @bitset_cache[col.name])
|
|
105
|
+
@vc.draw_column_bitset(rec, col, bitset)
|
|
106
|
+
else
|
|
107
|
+
=end
|
|
108
|
+
if (enum = @vc.get_enum(rec.class, col))
|
|
109
|
+
@enum_cache[col.name] = enum
|
|
110
|
+
@vc.draw_column_enum(rec, col, enum)
|
|
111
|
+
=begin
|
|
112
|
+
elsif (bitset = @vc.get_bitset(rec.class, col))
|
|
113
|
+
@bitset_cache[col.name] = bitset
|
|
114
|
+
@vc.draw_column_bitset(rec, col, bitset)
|
|
115
|
+
=end
|
|
116
|
+
else
|
|
117
|
+
case col.type
|
|
118
|
+
when :datetime
|
|
119
|
+
@vc.datetime_fmt(rec.send(col.name))
|
|
120
|
+
when :date
|
|
121
|
+
@vc.date_fmt(rec.send(col.name))
|
|
122
|
+
when :integer
|
|
123
|
+
h(rec.send(col.name))
|
|
124
|
+
when :boolean
|
|
125
|
+
rec.send(col.name) ? '√' : ''
|
|
126
|
+
else
|
|
127
|
+
# NOTE: rec.send(col.name) is not used since sssn.send(:data)
|
|
128
|
+
# becomes hash rather than actual string-data so that following
|
|
129
|
+
# split() fails for Hash.
|
|
130
|
+
if str = rec.attributes[col.name]
|
|
131
|
+
draw_trimmed_str(str)
|
|
132
|
+
else
|
|
133
|
+
''
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
#end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Drawer for record list in Edgarj CRUD view.
|
|
142
|
+
#
|
|
143
|
+
class Normal < Base
|
|
144
|
+
def initialize(edgarj_drawer, options = {})
|
|
145
|
+
super(edgarj_drawer, options)
|
|
146
|
+
#@belongs_to_link = true # make link on belongs_to
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# prepare path for the rec, which will be drawn later.
|
|
150
|
+
def set_path(rec)
|
|
151
|
+
@path = @vc.polymorphic_path([@options[:namespace], rec], format: :js)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# <td> options
|
|
155
|
+
#
|
|
156
|
+
# add Edgarj.click_listCB() with base result.
|
|
157
|
+
# When the column is parent, do nothing.
|
|
158
|
+
def td_options(rec, col)
|
|
159
|
+
result = super.merge(
|
|
160
|
+
style: 'cursor:pointer;',
|
|
161
|
+
class: '_edgarj_list_column')
|
|
162
|
+
#if !@parent_rec
|
|
163
|
+
result[:'data-url'] = @path
|
|
164
|
+
#end
|
|
165
|
+
result
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# draw Edgarj menu based on application's menu configuration
|
|
2
|
+
# at config/edgarj/menu_config.rb.
|
|
3
|
+
#
|
|
4
|
+
# Edgarj::MenuConfig should have 'top' module-function which returns arrays each
|
|
5
|
+
# entry is one of the followings:
|
|
6
|
+
#
|
|
7
|
+
# * item which contains link_to arg
|
|
8
|
+
# * controller menu list which contains controller name
|
|
9
|
+
# * special entry is '_separator' which is not controller name, rather
|
|
10
|
+
# generates just menu separator.
|
|
11
|
+
#
|
|
12
|
+
# See test/dummy/config/edgarj/menu_config.rb as an example.
|
|
13
|
+
#
|
|
14
|
+
# === SEE ALSO
|
|
15
|
+
# draw_menu:: method to draw menu
|
|
16
|
+
#
|
|
17
|
+
# === FILE
|
|
18
|
+
# config/initializer/menu.rb:: menu configuration at application
|
|
19
|
+
module Edgarj::MenuHelper
|
|
20
|
+
require File.join(Rails.root, 'config/edgarj/menu_config.rb')
|
|
21
|
+
include Edgarj::MenuConfig
|
|
22
|
+
|
|
23
|
+
def draw_menu
|
|
24
|
+
content_tag(:ul, :id=>'edgarj_menu', :class=>'edgarj_menu') do
|
|
25
|
+
out = ''
|
|
26
|
+
for menu in Edgarj::MenuConfig.top
|
|
27
|
+
out += content_tag(:li) do
|
|
28
|
+
case menu[0]
|
|
29
|
+
when :item
|
|
30
|
+
draw_item(*menu[1])
|
|
31
|
+
when :controller
|
|
32
|
+
draw_controller_menu(menu[1], menu[2], menu[3])
|
|
33
|
+
else
|
|
34
|
+
"unknown menu type: #{menu[0]}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
out.html_safe
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
# draw menu item
|
|
44
|
+
#
|
|
45
|
+
# === INPUTS
|
|
46
|
+
# link_to_args:: link_to args
|
|
47
|
+
def draw_item(*link_to_args)
|
|
48
|
+
content_tag(:li) do
|
|
49
|
+
link_to(
|
|
50
|
+
v(link_to_args[0]),
|
|
51
|
+
*link_to_args[1, link_to_args.size - 1])
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# draw controller menu for arg
|
|
56
|
+
#
|
|
57
|
+
# @param [string] name menu name
|
|
58
|
+
# @param [ActionDispatch::Routing::RouteSet] route_proxy routes for url_for() method calling
|
|
59
|
+
# @param [Array] menu_items array of string(menu item name)
|
|
60
|
+
def draw_controller_menu(name, route_proxy, menu_items)
|
|
61
|
+
link_to(v(name.to_s), '#') +
|
|
62
|
+
content_tag(:ul) do
|
|
63
|
+
out = ''
|
|
64
|
+
for menu_item in menu_items do
|
|
65
|
+
out += content_tag(:li) do
|
|
66
|
+
case menu_item
|
|
67
|
+
when '_separator'
|
|
68
|
+
'<hr>'.html_safe
|
|
69
|
+
# <hr> background doesn't work as I expected so that
|
|
70
|
+
# use <div> with border color
|
|
71
|
+
#'<div class=separator>x</div>'.html_safe
|
|
72
|
+
else
|
|
73
|
+
ctrl_str = menu_item
|
|
74
|
+
if permitted_on?(ctrl_str)
|
|
75
|
+
# NOTE: controller string begins with '/' below. This ensures
|
|
76
|
+
# top name space. See Rails API url_for(). For example,
|
|
77
|
+
# Album::Book page, url is like /PREFIX/album/books/....
|
|
78
|
+
# If there is no beginning '/', User controler page means Album::User.
|
|
79
|
+
# This is not expected behavior at menu.
|
|
80
|
+
link_to(
|
|
81
|
+
"#{ctrl_str.camelize}Controller".constantize.new.send(:human_name),
|
|
82
|
+
route_proxy.url_for(
|
|
83
|
+
controller: '/' + ctrl_str,
|
|
84
|
+
only_path: true))
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
out.html_safe
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# coding: UTF-8
|
|
2
|
+
module Edgarj
|
|
3
|
+
module PopupHelper
|
|
4
|
+
# handle popup related fields to simplify params[] passing
|
|
5
|
+
# from browser to server.
|
|
6
|
+
#
|
|
7
|
+
# === SEE ALSO
|
|
8
|
+
# Edgarj.Popup.Field:: same logic at js side
|
|
9
|
+
class PopupField
|
|
10
|
+
attr_accessor(
|
|
11
|
+
:id_target,
|
|
12
|
+
:label_target,
|
|
13
|
+
|
|
14
|
+
# NOTE: This is search-form specific hidden field
|
|
15
|
+
# to store parent name. This will be used when re-drawing
|
|
16
|
+
# search-form.
|
|
17
|
+
:label_hidden_field,
|
|
18
|
+
:clear_link)
|
|
19
|
+
|
|
20
|
+
# new from object_name and col_name
|
|
21
|
+
def self.new_builder(object_name, col_name)
|
|
22
|
+
new(object_name.to_s + '_' + col_name.to_s)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def initialize(id_target)
|
|
26
|
+
raise Edgarj::NoPopupTarget if id_target.blank?
|
|
27
|
+
|
|
28
|
+
@id_target = id_target
|
|
29
|
+
# Using id_target as suffix rather than prefix is to avoid
|
|
30
|
+
# DOM-id conflict. For example, if id_target is 'author_id' and
|
|
31
|
+
# use it as prefix, then label_target would be something like
|
|
32
|
+
# 'author_id_label_target' and it would be conflict with actual
|
|
33
|
+
# author.id_label_target DB column.
|
|
34
|
+
@label_target = '__edgarj_label_target_for_' + @id_target
|
|
35
|
+
@label_hidden_field = '__edgarj_label_hidden_field_for_' + @id_target
|
|
36
|
+
@clear_link = @label_target + '_clear_link'
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# coding: UTF-8
|
|
2
|
+
|
|
3
|
+
module Edgarj
|
|
4
|
+
module SearchHelper
|
|
5
|
+
# === INPUTS
|
|
6
|
+
# o:: operator form builder
|
|
7
|
+
# method:: column name
|
|
8
|
+
def draw_search_operator(o, method)
|
|
9
|
+
render '/edgarj/edgarj/search_operator',
|
|
10
|
+
o: o,
|
|
11
|
+
method: method
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|