redmine_extensions 0.6.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -32
- data/Rakefile +0 -8
- data/app/assets/javascripts/redmine_extensions/blocking.js +0 -3
- data/app/assets/javascripts/redmine_extensions/blocking_namespace.js +1 -2
- data/app/assets/javascripts/redmine_extensions/redmine_extensions.js +1 -33
- data/config/routes.rb +0 -7
- data/lib/redmine_extensions/easy_settings.rb +5 -5
- data/lib/redmine_extensions/engine.rb +12 -32
- data/lib/redmine_extensions/hooks.rb +6 -35
- data/lib/redmine_extensions/version.rb +1 -1
- data/lib/redmine_extensions.rb +5 -2
- data/spec/spec_helper.rb +10 -2
- metadata +3 -76
- data/app/assets/javascripts/redmine_extensions/blocking_render.js +0 -137
- data/app/assets/javascripts/redmine_extensions/blocking_schedule.js +0 -280
- data/app/assets/javascripts/redmine_extensions/event_bus.js +0 -61
- data/app/assets/stylesheets/redmine_extensions/application.css +0 -15
- data/lib/generators/redmine_extensions/entity/USAGE +0 -11
- data/lib/generators/redmine_extensions/entity/entity_generator.rb +0 -418
- data/lib/generators/redmine_extensions/entity/templates/_form.html.erb.erb +0 -51
- data/lib/generators/redmine_extensions/entity/templates/_list.html.erb.erb +0 -70
- data/lib/generators/redmine_extensions/entity/templates/_sidebar.html.erb.erb +0 -9
- data/lib/generators/redmine_extensions/entity/templates/app/models/%model_name_underscored%_query.rb.tt +0 -42
- data/lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/_%model_name_underscored%.api.rsb.tt +0 -18
- data/lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/_form.html.erb.tt +0 -62
- data/lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/edit.html.erb.tt +0 -8
- data/lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/new.html.erb.tt +0 -8
- data/lib/generators/redmine_extensions/entity/templates/context_menu.html.erb.erb +0 -20
- data/lib/generators/redmine_extensions/entity/templates/controller.rb.erb +0 -208
- data/lib/generators/redmine_extensions/entity/templates/custom_field.rb.erb +0 -11
- data/lib/generators/redmine_extensions/entity/templates/easy_query.rb.erb +0 -37
- data/lib/generators/redmine_extensions/entity/templates/edit.html.erb.erb +0 -19
- data/lib/generators/redmine_extensions/entity/templates/edit.js.erb.erb +0 -18
- data/lib/generators/redmine_extensions/entity/templates/en.yml.erb +0 -16
- data/lib/generators/redmine_extensions/entity/templates/entity_attribute_helper_patch.rb.erb +0 -10
- data/lib/generators/redmine_extensions/entity/templates/helper.rb.erb +0 -3
- data/lib/generators/redmine_extensions/entity/templates/hooks.rb.erb +0 -5
- data/lib/generators/redmine_extensions/entity/templates/index.api.rsb.erb +0 -3
- data/lib/generators/redmine_extensions/entity/templates/index.html.erb.erb +0 -30
- data/lib/generators/redmine_extensions/entity/templates/index.js.erb.erb +0 -12
- data/lib/generators/redmine_extensions/entity/templates/mail_added.html.erb.erb +0 -1
- data/lib/generators/redmine_extensions/entity/templates/mail_added.text.erb.erb +0 -2
- data/lib/generators/redmine_extensions/entity/templates/mail_updated.html.erb.erb +0 -1
- data/lib/generators/redmine_extensions/entity/templates/mail_updated.text.erb.erb +0 -2
- data/lib/generators/redmine_extensions/entity/templates/mailer.rb.erb +0 -41
- data/lib/generators/redmine_extensions/entity/templates/migration.rb.erb +0 -16
- data/lib/generators/redmine_extensions/entity/templates/model.rb.erb +0 -143
- data/lib/generators/redmine_extensions/entity/templates/new.html.erb.erb +0 -19
- data/lib/generators/redmine_extensions/entity/templates/new.js.erb.erb +0 -18
- data/lib/generators/redmine_extensions/entity/templates/query.rb.erb +0 -67
- data/lib/generators/redmine_extensions/entity/templates/routes.rb.erb +0 -15
- data/lib/generators/redmine_extensions/entity/templates/show.api.rsb.erb +0 -1
- data/lib/generators/redmine_extensions/entity/templates/show.html.erb.erb +0 -50
- data/lib/generators/redmine_extensions/entity/templates/show.js.erb.erb +0 -12
- data/lib/generators/redmine_extensions/entity/templates/spec/controllers/%model_name_underscored%_controller_spec.rb.tt +0 -94
- data/lib/generators/redmine_extensions/entity/templates/spec/factories.rb.erb +0 -11
- data/lib/generators/redmine_extensions/entity/templates/spec/requests/%model_name_underscored%_spec.rb.tt +0 -19
- data/lib/generators/redmine_extensions/plugin/USAGE +0 -13
- data/lib/generators/redmine_extensions/plugin/plugin_generator.rb +0 -74
- data/lib/generators/redmine_extensions/plugin/templates/Gemfile.erb +0 -1
- data/lib/generators/redmine_extensions/plugin/templates/after_init.rb.erb +0 -23
- data/lib/generators/redmine_extensions/plugin/templates/en.yml.erb +0 -3
- data/lib/generators/redmine_extensions/plugin/templates/gitkeep.erb +0 -0
- data/lib/generators/redmine_extensions/plugin/templates/hooks.rb.erb +0 -5
- data/lib/generators/redmine_extensions/plugin/templates/init.rb.erb +0 -20
- data/lib/generators/redmine_extensions/plugin/templates/internals.rb.erb +0 -4
- data/lib/generators/redmine_extensions/plugin/templates/issue_patch.example.erb +0 -30
- data/lib/generators/redmine_extensions/plugin/templates/issues_controller_patch.example.erb +0 -30
- data/lib/generators/redmine_extensions/plugin/templates/issues_helper_patch.example.erb +0 -30
- data/lib/generators/redmine_extensions/plugin/templates/javascript.js +0 -1
- data/lib/generators/redmine_extensions/plugin/templates/routes.rb.erb +0 -0
- data/lib/generators/redmine_extensions/plugin/templates/stylesheet.css +0 -3
- data/lib/redmine_extensions/core_ext/date_range.rb +0 -152
- data/lib/redmine_extensions/core_ext/object.rb +0 -19
- data/lib/redmine_extensions/core_ext/string.rb +0 -5
- data/lib/redmine_extensions/core_ext.rb +0 -3
- data/lib/redmine_extensions/deprecator.rb +0 -11
- data/lib/redmine_extensions/migration.rb +0 -9
- data/lib/redmine_extensions/patch_manager.rb +0 -440
- data/lib/redmine_extensions/rails_patches/route_set_generator_patch.rb +0 -10
- data/lib/redmine_extensions/redmine_patches/controllers/application_controller_patch.rb +0 -65
- data/lib/redmine_extensions/redmine_patches/models/custom_field_patch.rb +0 -11
- data/lib/redmine_extensions/redmine_patches/models/project_patch.rb +0 -10
- data/lib/tasks/redmine_extensions_tasks.rake +0 -4
- data/spec/init_rails.rb +0 -13
@@ -1,418 +0,0 @@
|
|
1
|
-
module RedmineExtensions
|
2
|
-
class EntityGenerator < Rails::Generators::Base
|
3
|
-
source_root File.expand_path('../templates', __FILE__)
|
4
|
-
|
5
|
-
argument :plugin_name, type: :string, required: true, banner: 'NameOfNewPlugin'
|
6
|
-
argument :model_name, type: :string, required: true, banner: 'Post'
|
7
|
-
argument :attributes, type: :array, required: true, banner: 'field[:type][:index] field[:type][:index]'
|
8
|
-
|
9
|
-
class_option :rys, type: :boolean, default: false, required: false, desc: 'Use in case of RYS'
|
10
|
-
|
11
|
-
class_option :associations, type: :array, required: false, banner: '--associations association_type[:association_name][:association_class]'
|
12
|
-
|
13
|
-
class_option :project, type: :boolean, default: true, banner: '', :desc => 'make model depends on project'
|
14
|
-
class_option :author, type: :boolean, default: true, banner: '', :desc => 'make model depends on project'
|
15
|
-
class_option :mail, type: :boolean, default: true, banner: '', :desc => 'model have mail notifications'
|
16
|
-
class_option :acts_as_activity_provider, type: :boolean, default: true, banner: '', :desc => 'changes in models are visible in user profile'
|
17
|
-
class_option :acts_as_attachable, type: :boolean, default: true, banner: '', :desc => 'model have attachments'
|
18
|
-
class_option :acts_as_customizable, type: :boolean, default: true, banner: '', :desc => 'model have custom fields'
|
19
|
-
class_option :acts_as_event, type: :boolean, default: true, banner: '', :desc => 'model should be visible in a calendar'
|
20
|
-
class_option :acts_as_list, type: :boolean, default: false, banner: '', :desc => 'model is sorted by position'
|
21
|
-
class_option :acts_as_searchable, type: :boolean, default: true, banner: '', :desc => 'model is searchable'
|
22
|
-
class_option :acts_as_tree, type: :boolean, default: false, banner: '', :desc => 'model have hierarchy'
|
23
|
-
class_option :acts_as_versioned, type: :boolean, default: false, banner: '', :desc => 'model is versioned'
|
24
|
-
class_option :acts_as_watchable, type: :boolean, default: false, banner: '', :desc => 'model have watchers'
|
25
|
-
|
26
|
-
attr_reader :plugin_path, :plugin_name_underscored, :plugin_pretty_name, :plugin_title
|
27
|
-
attr_reader :controller_class, :model_name_underscored, :model_name_pluralize_underscored
|
28
|
-
attr_reader :db_columns
|
29
|
-
attr_reader :associations
|
30
|
-
attr_reader :rys
|
31
|
-
def initialize(*args)
|
32
|
-
super
|
33
|
-
@model_name_camelized = model_name.camelize
|
34
|
-
check_existing_const
|
35
|
-
|
36
|
-
@rys = !!options['rys']
|
37
|
-
@plugin_name_underscored = plugin_name.underscore
|
38
|
-
@plugin_pretty_name = @plugin_name_underscored.titleize
|
39
|
-
|
40
|
-
@plugin_path = rys ? '.' : "plugins/#{@plugin_name_underscored}"
|
41
|
-
@plugin_title = @plugin_name_underscored.camelize
|
42
|
-
|
43
|
-
@model_name_underscored = model_name.underscore
|
44
|
-
@model_name_pluralize_underscored = model_name.pluralize.underscore
|
45
|
-
@controller_class = model_name.pluralize
|
46
|
-
|
47
|
-
prepare_columns
|
48
|
-
end
|
49
|
-
|
50
|
-
def check_existing_const
|
51
|
-
begin
|
52
|
-
@model_name_camelized.constantize
|
53
|
-
raise I18n.t(:error_entity_name_is_used, entity_name: @model_name_camelized)
|
54
|
-
rescue LoadError, NameError
|
55
|
-
# OK
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def copy_templates
|
60
|
-
template '_sidebar.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/_sidebar.html.erb"
|
61
|
-
template 'context_menu.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/context_menu.html.erb"
|
62
|
-
template 'controller.rb.erb', "#{plugin_path}/app/controllers/#{model_name_pluralize_underscored}_controller.rb"
|
63
|
-
template('custom_field.rb.erb', "#{plugin_path}/app/models/#{model_name_underscored}_custom_field.rb") if acts_as_customizable?
|
64
|
-
template 'edit.js.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/edit.js.erb"
|
65
|
-
|
66
|
-
tests_root = rys ? './spec' : "#{plugin_path}/test"
|
67
|
-
template 'spec/factories.rb.erb', "#{tests_root}/factories/#{model_name_underscored}.rb"
|
68
|
-
template 'spec/controllers/%model_name_underscored%_controller_spec.rb.tt', "#{tests_root}/controllers/#{model_name_underscored}_controller_spec.rb"
|
69
|
-
template 'spec/requests/%model_name_underscored%_spec.rb.tt', "#{tests_root}/requests/#{model_name_underscored}.rb"
|
70
|
-
|
71
|
-
if File.exists?("#{plugin_path}/config/locales/en.yml")
|
72
|
-
original_langfile = YAML.load_file("#{plugin_path}/config/locales/en.yml")
|
73
|
-
|
74
|
-
template 'en.yml.erb', "#{plugin_path}/tmp/tmp_en.yml", pretend: true
|
75
|
-
if File.exist?("#{plugin_path}/tmp/tmp_en.yml")
|
76
|
-
added_translations = YAML.load_file("#{plugin_path}/tmp/tmp_en.yml")
|
77
|
-
File.delete("#{plugin_path}/tmp/tmp_en.yml")
|
78
|
-
|
79
|
-
merged_langfile = original_langfile.deep_merge(added_translations)
|
80
|
-
File.open("#{plugin_path}/config/locales/en.yml", 'w') do |file|
|
81
|
-
file.write merged_langfile.to_yaml
|
82
|
-
end
|
83
|
-
end
|
84
|
-
else
|
85
|
-
template 'en.yml.erb', "#{plugin_path}/config/locales/en.yml"
|
86
|
-
end
|
87
|
-
|
88
|
-
template 'helper.rb.erb', "#{plugin_path}/app/helpers/#{model_name_pluralize_underscored}_helper.rb"
|
89
|
-
template 'hooks.rb.erb', "#{plugin_path}/lib/#{plugin_name_underscored}/#{model_name_underscored}_hooks.rb"
|
90
|
-
template 'index.api.rsb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/index.api.rsb"
|
91
|
-
template 'index.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/index.html.erb"
|
92
|
-
template 'index.js.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/index.js.erb"
|
93
|
-
template '_list.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/_list.html.erb"
|
94
|
-
|
95
|
-
if mail?
|
96
|
-
template 'mailer.rb.erb', "#{plugin_path}/app/models/#{model_name_underscored}_mailer.rb"
|
97
|
-
template 'mail_added.html.erb.erb', "#{plugin_path}/app/views/#{model_name_underscored}_mailer/#{model_name_underscored}_added.html.erb"
|
98
|
-
template 'mail_added.text.erb.erb', "#{plugin_path}/app/views/#{model_name_underscored}_mailer/#{model_name_underscored}_added.text.erb"
|
99
|
-
template 'mail_updated.html.erb.erb', "#{plugin_path}/app/views/#{model_name_underscored}_mailer/#{model_name_underscored}_updated.html.erb"
|
100
|
-
template 'mail_updated.text.erb.erb', "#{plugin_path}/app/views/#{model_name_underscored}_mailer/#{model_name_underscored}_updated.text.erb"
|
101
|
-
end
|
102
|
-
|
103
|
-
template 'migration.rb.erb', "#{plugin_path}/db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S%L')}_create_#{@model_name_pluralize_underscored}.rb"
|
104
|
-
template 'model.rb.erb', "#{plugin_path}/app/models/#{model_name_underscored}.rb"
|
105
|
-
template 'new.js.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/new.js.erb"
|
106
|
-
|
107
|
-
if easy?
|
108
|
-
easy_model_template '%model_name_underscored%_query.rb'
|
109
|
-
template 'entity_attribute_helper_patch.rb.erb', "#{plugin_path}/extra/easy_patch/easy_extensions/helpers/entity_attribute_helper_patch.rb"
|
110
|
-
|
111
|
-
if File.exists?("#{plugin_path}/extra/easy_patch/easy_extensions/helpers/entity_attribute_helper_patch.rb")
|
112
|
-
|
113
|
-
inject_into_file "#{plugin_path}/extra/easy_patch/easy_extensions/helpers/entity_attribute_helper_patch.rb",
|
114
|
-
"\n def format_html_#{model_name_underscored}_attribute(entity_class, attribute, unformatted_value, options={})" +
|
115
|
-
"\n value = format_entity_attribute(entity_class, attribute, unformatted_value, options)" +
|
116
|
-
"\n case attribute.name" +
|
117
|
-
"\n when :name" +
|
118
|
-
"\n link_to(value, #{model_name_underscored.singularize}_path(options[:entity].id))" +
|
119
|
-
"\n else" +
|
120
|
-
"\n h(value)" +
|
121
|
-
"\n end" +
|
122
|
-
"\n end" +
|
123
|
-
"\n", after: 'base.class_eval do'
|
124
|
-
|
125
|
-
end
|
126
|
-
else
|
127
|
-
template 'query.rb.erb', "#{plugin_path}/app/models/#{model_name_underscored}_query.rb"
|
128
|
-
end
|
129
|
-
|
130
|
-
routes_file = "#{plugin_path}/config/routes.rb"
|
131
|
-
if File.exists?(routes_file)
|
132
|
-
if project?
|
133
|
-
insert_into_file routes_file, before: (rys ? /^end$/ : /\z/) do
|
134
|
-
"\n resources :projects do " +
|
135
|
-
"\n resources :#{model_name_pluralize_underscored}" +
|
136
|
-
"\n end\n"
|
137
|
-
end
|
138
|
-
end
|
139
|
-
insert_into_file routes_file, before: (rys ? /^end$/ : /\z/) do
|
140
|
-
"\n resources :#{model_name_pluralize_underscored} do" +
|
141
|
-
"\n collection do " +
|
142
|
-
"\n get 'autocomplete'" +
|
143
|
-
"\n get 'bulk_edit'" +
|
144
|
-
"\n post 'bulk_update'" +
|
145
|
-
"\n get 'context_menu'" +
|
146
|
-
"\n end" +
|
147
|
-
"\n end\n"
|
148
|
-
end
|
149
|
-
else
|
150
|
-
template 'routes.rb.erb', "#{plugin_path}/config/routes.rb"
|
151
|
-
end
|
152
|
-
|
153
|
-
if File.exists?("#{plugin_path}/after_init.rb")
|
154
|
-
s = "\nActiveSupport.on_load(:easyproject, yield: true) do"
|
155
|
-
s << "\n require '#{plugin_name_underscored}/#{model_name_underscored}_hooks'\n"
|
156
|
-
s << "\n Redmine::AccessControl.map do |map|"
|
157
|
-
s << "\n map.project_module :#{model_name_pluralize_underscored} do |pmap|"
|
158
|
-
s << "\n pmap.permission :view_#{model_name_pluralize_underscored}, { #{model_name_pluralize_underscored}: [:index, :show, :autocomplete, :context_menu] }, read: true"
|
159
|
-
s << "\n pmap.permission :manage_#{model_name_pluralize_underscored}, { #{model_name_pluralize_underscored}: [:new, :create, :edit, :update, :destroy, :bulk_edit, :bulk_update] }"
|
160
|
-
s << "\n end "
|
161
|
-
s << "\n end\n"
|
162
|
-
s << "\n Redmine::MenuManager.map :top_menu do |menu|"
|
163
|
-
s << "\n menu.push :#{model_name_pluralize_underscored}, { controller: '#{model_name_pluralize_underscored}', action: 'index', project_id: nil }, caption: :label_#{model_name_pluralize_underscored}"
|
164
|
-
s << "\n end\n"
|
165
|
-
if project?
|
166
|
-
s << "\n Redmine::MenuManager.map :project_menu do |menu|"
|
167
|
-
s << "\n menu.push :#{model_name_pluralize_underscored}, { controller: '#{model_name_pluralize_underscored}', action: 'index' }, param: :project_id, caption: :label_#{model_name_pluralize_underscored}"
|
168
|
-
s << "\n end\n"
|
169
|
-
end
|
170
|
-
if acts_as_customizable?
|
171
|
-
s << "\n CustomFieldsHelper::CUSTOM_FIELDS_TABS << {name: '#{model_name}CustomField', partial: 'custom_fields/index', label: :label_#{model_name_pluralize_underscored}}\n"
|
172
|
-
end
|
173
|
-
if acts_as_searchable?
|
174
|
-
s << "\n Redmine::Search.map do |search|"
|
175
|
-
s << "\n search.register :#{model_name_pluralize_underscored}"
|
176
|
-
s << "\n end\n"
|
177
|
-
end
|
178
|
-
if acts_as_activity_provider?
|
179
|
-
s << "\n Redmine::Activity.map do |activity|"
|
180
|
-
s << "\n activity.register :#{model_name_pluralize_underscored}, {class_name: %w(#{model_name}), default: false}"
|
181
|
-
s << "\n end\n"
|
182
|
-
end
|
183
|
-
s << "\nend"
|
184
|
-
|
185
|
-
append_to_file "#{plugin_path}/after_init.rb", s
|
186
|
-
elsif rys
|
187
|
-
s = ''
|
188
|
-
s << "\n Redmine::AccessControl.map do |map|"
|
189
|
-
s << "\n map.easy_category :#{model_name_pluralize_underscored} do |pmap|"
|
190
|
-
s << "\n pmap.permission :view_#{model_name_pluralize_underscored}, { #{model_name_pluralize_underscored}: [:index, :show, :autocomplete, :context_menu] }, read: true"
|
191
|
-
s << "\n pmap.permission :manage_#{model_name_pluralize_underscored}, { #{model_name_pluralize_underscored}: [:new, :create, :edit, :update, :destroy, :bulk_edit, :bulk_update] }"
|
192
|
-
s << "\n end "
|
193
|
-
s << "\n end\n"
|
194
|
-
append_to_file './config/initializers/01_access_control.rb', s
|
195
|
-
|
196
|
-
s = ''
|
197
|
-
s << "\n Redmine::MenuManager.map :top_menu do |menu|"
|
198
|
-
s << "\n menu.push :#{model_name_pluralize_underscored}, { controller: '#{model_name_pluralize_underscored}', action: 'index', project_id: nil }, caption: :label_#{model_name_pluralize_underscored}"
|
199
|
-
s << "\n end\n"
|
200
|
-
if project?
|
201
|
-
s << "\n Redmine::MenuManager.map :project_menu do |menu|"
|
202
|
-
s << "\n menu.push :#{model_name_pluralize_underscored}, { controller: '#{model_name_pluralize_underscored}', action: 'index' }, param: :project_id, caption: :label_#{model_name_pluralize_underscored}"
|
203
|
-
s << "\n end\n"
|
204
|
-
end
|
205
|
-
append_to_file './config/initializers/02_menu_manager.rb', s
|
206
|
-
s = ''
|
207
|
-
if acts_as_customizable?
|
208
|
-
s << "\n CustomFieldsHelper::CUSTOM_FIELDS_TABS << {name: '#{model_name}CustomField', partial: 'custom_fields/index', label: :label_#{model_name_pluralize_underscored}}\n"
|
209
|
-
end
|
210
|
-
if acts_as_searchable?
|
211
|
-
s << "\n Redmine::Search.map do |search|"
|
212
|
-
s << "\n search.register :#{model_name_pluralize_underscored}"
|
213
|
-
s << "\n end\n"
|
214
|
-
end
|
215
|
-
if acts_as_activity_provider?
|
216
|
-
s << "\n Redmine::Activity.map do |activity|"
|
217
|
-
s << "\n activity.register :#{model_name_pluralize_underscored}, {class_name: %w(#{model_name}), default: false}"
|
218
|
-
s << "\n end\n"
|
219
|
-
end
|
220
|
-
other_initializer = './config/initializers/06_others.rb'
|
221
|
-
if File.exist?(other_initializer)
|
222
|
-
append_file other_initializer do
|
223
|
-
s
|
224
|
-
end
|
225
|
-
else
|
226
|
-
create_file other_initializer do
|
227
|
-
s
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
end
|
232
|
-
|
233
|
-
|
234
|
-
template 'show.api.rsb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/show.api.rsb"
|
235
|
-
template 'show.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/show.html.erb"
|
236
|
-
template 'show.js.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/show.js.erb"
|
237
|
-
|
238
|
-
# New templates
|
239
|
-
easy_view_template '_%model_name_underscored%.api.rsb'
|
240
|
-
easy_view_template '_form.html.erb'
|
241
|
-
easy_view_template 'new.html.erb'
|
242
|
-
easy_view_template 'edit.html.erb'
|
243
|
-
end
|
244
|
-
|
245
|
-
private
|
246
|
-
|
247
|
-
def easy_model_template(name)
|
248
|
-
template "app/models/#{name}", "#{plugin_path}/app/models/#{name}"
|
249
|
-
end
|
250
|
-
|
251
|
-
def easy_view_template(name)
|
252
|
-
template "app/views/%model_name_pluralize_underscored%/#{name}", "#{plugin_path}/app/views/%model_name_pluralize_underscored%/#{name}"
|
253
|
-
end
|
254
|
-
|
255
|
-
def easy?
|
256
|
-
Redmine::Plugin.installed?(:easy_extensions)
|
257
|
-
end
|
258
|
-
|
259
|
-
def assocs
|
260
|
-
options[:associations]
|
261
|
-
end
|
262
|
-
|
263
|
-
def project?
|
264
|
-
options[:project] == true
|
265
|
-
end
|
266
|
-
|
267
|
-
def author?
|
268
|
-
options[:author] == true
|
269
|
-
end
|
270
|
-
|
271
|
-
def acts_as_customizable?
|
272
|
-
options[:acts_as_customizable] == true
|
273
|
-
end
|
274
|
-
|
275
|
-
def acts_as_searchable?
|
276
|
-
options[:acts_as_searchable] == true
|
277
|
-
end
|
278
|
-
|
279
|
-
def acts_as_activity_provider?
|
280
|
-
options[:acts_as_activity_provider] == true
|
281
|
-
end
|
282
|
-
|
283
|
-
def acts_as_attachable?
|
284
|
-
options[:acts_as_attachable] == true
|
285
|
-
end
|
286
|
-
|
287
|
-
def acts_as_event?
|
288
|
-
options[:acts_as_event] == true
|
289
|
-
end
|
290
|
-
|
291
|
-
def acts_as_list?
|
292
|
-
options[:acts_as_list] == true
|
293
|
-
end
|
294
|
-
|
295
|
-
def acts_as_tree?
|
296
|
-
options[:acts_as_tree] == true
|
297
|
-
end
|
298
|
-
|
299
|
-
def acts_as_versioned?
|
300
|
-
options[:acts_as_versioned] == true
|
301
|
-
end
|
302
|
-
|
303
|
-
def acts_as_watchable?
|
304
|
-
options[:acts_as_watchable] == true
|
305
|
-
end
|
306
|
-
|
307
|
-
def mail?
|
308
|
-
options[:mail] == true
|
309
|
-
end
|
310
|
-
|
311
|
-
def prepare_columns
|
312
|
-
@db_columns = {}
|
313
|
-
prepare_associations
|
314
|
-
|
315
|
-
attributes.each do |attr|
|
316
|
-
attr_name, attr_type, attr_idx = attr.split(':')
|
317
|
-
#lang_key = "field_#{model_name_underscored}_#{attr_name.to_s.sub(/_id$/, '').sub(/^.+\./, '')}"
|
318
|
-
lang_key = "#{attr_name.to_s.sub(/_id$/, '').sub(/^.+\./, '')}"
|
319
|
-
if attr_type == 'timestamp'
|
320
|
-
@timestamp_exist = true
|
321
|
-
else
|
322
|
-
@db_columns[attr_name] = { type: attr_type || 'string', idx: attr_idx, null: true, safe: true, query_type: attr_type || 'string', lang_key: lang_key }
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
@db_columns['project_id'] = { type: 'integer', idx: nil, null: false, safe: false, class: 'Project', list_class_name: 'name', query_type: 'list_optional', query_column_name: 'project', lang_key: "field_#{model_name_underscored}_project" } if project? && !@db_columns.key?('project_id')
|
327
|
-
@db_columns['author_id'] = { type: 'integer', idx: nil, null: false, safe: true, class: 'User', list_class_name: 'name', query_type: 'list', query_column_name: 'author', lang_key: "field_#{model_name_underscored}_author" } if author? && !@db_columns.key?('author_id')
|
328
|
-
|
329
|
-
@db_columns['created_at'] = { type: 'datetime', idx: nil, null: false, safe: false, query_type: 'date', lang_key: "field_#{model_name_underscored}_created_at" }
|
330
|
-
@db_columns['updated_at'] = { type: 'datetime', idx: nil, null: false, safe: false, query_type: 'date', lang_key: "field_#{model_name_underscored}_updated_at" }
|
331
|
-
end
|
332
|
-
|
333
|
-
def prepare_associations
|
334
|
-
@associations = {}
|
335
|
-
|
336
|
-
return true if assocs.nil?
|
337
|
-
|
338
|
-
assocs.each do |assoc|
|
339
|
-
assoc_type, assoc_name, assoc_class = assoc.split(':')
|
340
|
-
next if assoc_type.blank? || assoc_name.blank?
|
341
|
-
|
342
|
-
@associations[assoc_name] = { type: assoc_type, class: assoc_class }
|
343
|
-
|
344
|
-
assoc_model_class = assoc_class.presence || assoc_name.singularize.camelize
|
345
|
-
assoc_model_filename = assoc_model_class.underscore
|
346
|
-
assoc_model_path = "#{plugin_path}/app/models/#{assoc_model_filename}.rb"
|
347
|
-
|
348
|
-
case assoc_type
|
349
|
-
when 'has_many', 'has_one'
|
350
|
-
if File.exists?(assoc_model_path)
|
351
|
-
line = "class #{assoc_model_class} < ActiveRecord::Base"
|
352
|
-
gsub_file assoc_model_path, /(#{Regexp.escape(line)})/mi do |match|
|
353
|
-
"#{match}\n belongs_to :#{model_name.underscore}\n"
|
354
|
-
end
|
355
|
-
end
|
356
|
-
when 'belongs_to'
|
357
|
-
if File.exists?(assoc_model_path)
|
358
|
-
unless File.readlines(assoc_model_path).grep(/has_many\ :#{model_name.underscore.pluralize}/).any?
|
359
|
-
line = "class #{assoc_model_class} < ActiveRecord::Base"
|
360
|
-
gsub_file assoc_model_path, /(#{Regexp.escape(line)})/mi do |match|
|
361
|
-
"#{match}\n has_many :#{model_name.underscore.pluralize}\n"
|
362
|
-
end
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
@db_columns["#{assoc_model_class.underscore.singularize}_id"] = { type: 'integer', idx: true, lang_key: assoc_model_class.underscore, query_type: 'list_optional', null: true }
|
367
|
-
end
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
def safe_columns
|
372
|
-
@db_columns.select { |_, column_options| column_options[:safe] }
|
373
|
-
end
|
374
|
-
|
375
|
-
def string_columns
|
376
|
-
@db_columns.select { |_, column_options| column_options[:safe] && column_options[:type] == 'string' }
|
377
|
-
end
|
378
|
-
|
379
|
-
def text_columns
|
380
|
-
@db_columns.select { |_, column_options| column_options[:safe] && column_options[:type] == 'text' }
|
381
|
-
end
|
382
|
-
|
383
|
-
def form_columns
|
384
|
-
@db_columns.select { |_, column_options| column_options[:safe] }
|
385
|
-
end
|
386
|
-
|
387
|
-
def name_column
|
388
|
-
'name' if string_columns.key?('name')
|
389
|
-
string_columns.keys.first
|
390
|
-
end
|
391
|
-
|
392
|
-
def name_column?
|
393
|
-
!name_column.blank?
|
394
|
-
end
|
395
|
-
|
396
|
-
def description_column
|
397
|
-
'description' if text_columns.key?('description')
|
398
|
-
text_columns.keys.first
|
399
|
-
end
|
400
|
-
|
401
|
-
def description_column?
|
402
|
-
!description_column.blank?
|
403
|
-
end
|
404
|
-
|
405
|
-
def view_permission
|
406
|
-
"view_#{@model_name_pluralize_underscored}"
|
407
|
-
end
|
408
|
-
|
409
|
-
def edit_permission
|
410
|
-
"manage_#{@model_name_pluralize_underscored}"
|
411
|
-
end
|
412
|
-
|
413
|
-
def delete_permission
|
414
|
-
"manage_#{@model_name_pluralize_underscored}"
|
415
|
-
end
|
416
|
-
|
417
|
-
end
|
418
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
<%%= fields_for :<%= model_name_underscored %>, <%= model_name_underscored %> do |f| %>
|
2
|
-
<%- if project? -%>
|
3
|
-
<%% if <%= model_name_underscored %>.safe_attribute?('project_id') && !@project %>
|
4
|
-
<p>
|
5
|
-
<%%= f.label :project_id, ::<%= model_name %>.human_attribute_name(:project_id) %>
|
6
|
-
<%%= f.select :project_id, Project.allowed_to(:manage_<%= model_name_pluralize_underscored %>).collect{|x| [x.name, x.id]}, include_blank: true %>
|
7
|
-
</p>
|
8
|
-
<%% end %>
|
9
|
-
<%- end -%>
|
10
|
-
<%- safe_columns.each do |column_name, column_options| -%>
|
11
|
-
<%% if <%= model_name_underscored %>.safe_attribute?('<%= column_name %>') %>
|
12
|
-
<p>
|
13
|
-
<%%= f.label :<%= column_name %>, ::<%= model_name %>.human_attribute_name(:<%= column_name %>) %>
|
14
|
-
<%- if column_options[:query_type] == 'string' || column_options[:query_type] == 'integer' -%>
|
15
|
-
<%%= f.text_field :<%= column_name %> %>
|
16
|
-
<%- elsif column_options[:query_type] == 'list' || column_options[:query_type] == 'list_optional' -%>
|
17
|
-
<%%= f.select :<%= column_name %>, <%= column_options[:class] %>.all.collect{|x| [x.<%= column_options[:list_class_name] %>, x.id]}.sort, include_blank: true %>
|
18
|
-
<%- elsif column_options[:query_type] == 'text' -%>
|
19
|
-
<%%= f.text_area :<%= column_name %>, cols: 60, rows: (<%= model_name_underscored %>.<%= column_name %>.blank? ? 10 : [[10, <%= model_name_underscored %>.<%= column_name %>.length / 50].max, 100].min), accesskey: accesskey(:edit), class: 'wiki-edit' %>
|
20
|
-
<%%= wikitoolbar_for '<%= model_name_underscored %>_<%= column_name %>' %>
|
21
|
-
<%- elsif column_options[:query_type] == 'boolean' -%>
|
22
|
-
<%%= f.radio_button :<%= column_name %>, false %>
|
23
|
-
<%- else -%>
|
24
|
-
<%%= f.text_field :<%= column_name %> %>
|
25
|
-
<%- end -%>
|
26
|
-
</p>
|
27
|
-
<%% end %>
|
28
|
-
<%- end -%>
|
29
|
-
<% associations.each do |assoc| %>
|
30
|
-
<%- next if assoc[1][:type] == 'has_many' -%>
|
31
|
-
<% association_name = assoc[0] %>
|
32
|
-
<p>
|
33
|
-
<%%= f.label l(:label_<%= association_name %>) %>
|
34
|
-
<%%= f.select :<%= association_name %>_id, <%= association_name.camelcase %>.visible.sorted.map{ |<%= association_name %>| [<%= association_name %>.to_s, <%= association_name %>.id]} %>
|
35
|
-
</p>
|
36
|
-
<% end %>
|
37
|
-
<%- if acts_as_customizable? -%>
|
38
|
-
<%% custom_field_values = <%= model_name_underscored %>.visible_custom_field_values %>
|
39
|
-
<%% custom_field_values.each do |value| %>
|
40
|
-
<p>
|
41
|
-
<%%= custom_field_tag_with_label :<%= model_name_underscored %>, value %>
|
42
|
-
</p>
|
43
|
-
<%% end %>
|
44
|
-
<%- end -%>
|
45
|
-
<%- if acts_as_attachable? -%>
|
46
|
-
<p id="attachments_form">
|
47
|
-
<label><%%= l(:label_attachment_plural) %></label>
|
48
|
-
<%%= render partial: 'attachments/form', locals: { container: <%= model_name_underscored %> } %>
|
49
|
-
</p>
|
50
|
-
<%- end -%>
|
51
|
-
<%% end %>
|
@@ -1,70 +0,0 @@
|
|
1
|
-
<%%= form_tag({}, data: {cm_url: context_menu_<%= model_name_pluralize_underscored %>_path}) do %>
|
2
|
-
<%%= hidden_field_tag 'back_url', url_for(params: request.query_parameters), id: nil %>
|
3
|
-
<div class="autoscroll">
|
4
|
-
<table class="list odd-even entities">
|
5
|
-
<thead>
|
6
|
-
<tr>
|
7
|
-
<th class="checkbox hide-when-print">
|
8
|
-
<%%= check_box_tag 'check_all', '', false, class: 'toggle-selection',
|
9
|
-
title: "#{l(:button_check_all)}/#{l(:button_uncheck_all)}" %>
|
10
|
-
</th>
|
11
|
-
<%% @query.inline_columns.each do |column| %>
|
12
|
-
<%%= column_header(@query, column) %>
|
13
|
-
<%% end %>
|
14
|
-
<th></th>
|
15
|
-
</tr>
|
16
|
-
</thead>
|
17
|
-
<tbody>
|
18
|
-
<%% grouped_query_results(entities, @query) do |entity, group_name, group_count, group_totals| %>
|
19
|
-
<%% if group_name %>
|
20
|
-
<%% reset_cycle %>
|
21
|
-
<tr class="group open">
|
22
|
-
<td colspan="<%%= @query.inline_columns.size + 2 %>">
|
23
|
-
<span class="expander" onclick="toggleRowGroup(this);"> </span>
|
24
|
-
<span class="name"><%%= group_name %></span>
|
25
|
-
<%% if group_count %>
|
26
|
-
<span class="count"><%%= group_count %></span>
|
27
|
-
<%% end %>
|
28
|
-
<span class="totals"><%%= group_totals %></span>
|
29
|
-
<%%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}",
|
30
|
-
'toggleAllRowGroups(this)', class: 'toggle-all') %>
|
31
|
-
</td>
|
32
|
-
</tr>
|
33
|
-
<%% end %>
|
34
|
-
<tr id="entity_id_<%%= entity.id %>" class="entity <%%= cycle('odd', 'even') %> hascontextmenu">
|
35
|
-
<td class="checkbox hide-when-print"><%%= check_box_tag('ids[]', entity.id, false, id: nil) %></td>
|
36
|
-
<%% @query.inline_columns.each do |column| %>
|
37
|
-
<%%= content_tag('td', column_content(column, entity), class: column.css_classes) %>
|
38
|
-
<%% end %>
|
39
|
-
<td class="buttons">
|
40
|
-
<%% if entity.editable_by?(User.current) %>
|
41
|
-
<%%= link_to l(:button_edit), edit_<%= model_name_underscored %>_path(entity),
|
42
|
-
title: l(:button_edit),
|
43
|
-
class: 'icon-only icon-edit' %>
|
44
|
-
<%%= link_to l(:button_delete), <%= model_name_underscored %>_path(entity),
|
45
|
-
data: {confirm: l(:text_are_you_sure)},
|
46
|
-
method: :delete,
|
47
|
-
title: l(:button_delete),
|
48
|
-
class: 'icon-only icon-del' %>
|
49
|
-
<%% end %>
|
50
|
-
</td>
|
51
|
-
</tr>
|
52
|
-
<%% @query.block_columns.each do |column| %>
|
53
|
-
<%% if (text = column_content(column, entity)) && text.present? %>
|
54
|
-
<tr class="<%%= current_cycle %>">
|
55
|
-
<td colspan="<%%= @query.inline_columns.size + 1 %>" class="<%%= column.css_classes %>">
|
56
|
-
<%% if query.block_columns.count > 1 %>
|
57
|
-
<span><%%= column.caption %></span>
|
58
|
-
<%% end %>
|
59
|
-
<%%= text %>
|
60
|
-
</td>
|
61
|
-
</tr>
|
62
|
-
<%% end %>
|
63
|
-
<%% end %>
|
64
|
-
<%% end %>
|
65
|
-
</tbody>
|
66
|
-
</table>
|
67
|
-
</div>
|
68
|
-
<%% end %>
|
69
|
-
|
70
|
-
<%%= context_menu %>
|
@@ -1,9 +0,0 @@
|
|
1
|
-
<ul>
|
2
|
-
<%% if @<%= model_name_underscored %> && !@<%= model_name_underscored %>.new_record? %>
|
3
|
-
<%%= content_tag(:li, link_to(l(:button_edit), edit_polymorphic_path([@project, @<%= model_name_underscored %>]), title: l(:button_edit), class: 'icon icon-edit button')) %>
|
4
|
-
<%% end %>
|
5
|
-
<%% if @<%= model_name_underscored %>.nil? %>
|
6
|
-
<%%= content_tag(:li, link_to(l(:button_<%= model_name_underscored %>_new), new_polymorphic_path([@project, :<%= model_name_underscored %>]), title: l(:title_<%= model_name_underscored %>_new), class: 'icon icon-add button button-positive')) %>
|
7
|
-
<%% end %>
|
8
|
-
<%%= content_tag(:li, link_to(l(:label_<%= model_name_pluralize_underscored %>), polymorphic_path([@project, :<%= model_name_pluralize_underscored %>], set_filter: '1'), title: l(:label_<%= model_name_pluralize_underscored %>), class: 'icon icon-folder button')) %>
|
9
|
-
</ul>
|
@@ -1,42 +0,0 @@
|
|
1
|
-
class <%= model_name %>Query < EasyQuery
|
2
|
-
|
3
|
-
self.queried_class = <%= model_name %>
|
4
|
-
|
5
|
-
def initialize_available_filters
|
6
|
-
on_filter_group(default_group_label) do
|
7
|
-
<%- db_columns.each do |column_name, column_options| -%>
|
8
|
-
<%- if project? && column_name == 'project_id' -%>
|
9
|
-
if project.nil?
|
10
|
-
add_available_filter '<%= column_name %>', name: <%= model_name %>.human_attribute_name(:<%= column_name %>), type: :<%= column_options[:query_type] %>, values: all_projects_values
|
11
|
-
end
|
12
|
-
<%- else -%>
|
13
|
-
add_available_filter '<%= column_name %>', name: <%= model_name %>.human_attribute_name(:<%= column_name %>), type: :<%= column_options[:query_type] %>
|
14
|
-
<%- end -%>
|
15
|
-
<%- end -%>
|
16
|
-
<%- if acts_as_customizable? -%>
|
17
|
-
add_custom_fields_filters(<%= model_name %>CustomField)
|
18
|
-
<%- end -%>
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize_available_columns
|
23
|
-
tbl = entity.table_name
|
24
|
-
<%- author_col = db_columns.delete 'author_id' %>
|
25
|
-
on_filter_group(default_group_label) do
|
26
|
-
<%- db_columns.each do |column_name, column_options| -%>
|
27
|
-
add_available_column '<%= column_options[:query_column_name] || column_name %>', caption: <%= model_name %>.human_attribute_name(:<%= column_name %>), title: <%= model_name %>.human_attribute_name(:<%= column_name %>)#, sortable: "#{tbl}.<%= column_name %>"
|
28
|
-
<%- end -%>
|
29
|
-
<%- if author_col -%>
|
30
|
-
add_available_column 'author', caption: <%= model_name %>.human_attribute_name(:author_id), title: <%= model_name %>.human_attribute_name(:author_id), sortable: proc { User.fields_for_order_statement('authors') }, preload: [author: (Setting.gravatar_enabled? ? :email_addresses : :easy_avatar)]
|
31
|
-
<%- end %>
|
32
|
-
<%- if acts_as_customizable? -%>
|
33
|
-
add_available_columns <%= model_name %>CustomField.sorted.visible.collect { |cf| EasyQueryCustomFieldColumn.new(cf, group: l(:label_filter_group_custom_fields)) }
|
34
|
-
<%- end -%>
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def default_list_columns
|
39
|
-
super.presence || <%= db_columns.collect{|column_name, column_options| (column_options[:query_column_name] || column_name).to_s}[0..3].to_s %>.flat_map { |c| [c.to_s, c.to_sym] }
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
local_assigns[:api].<%= model_name_underscored %> do
|
2
|
-
local_assigns[:api].id <%= model_name_underscored %>.id
|
3
|
-
<%- db_columns.keys.each do |column_name| -%>
|
4
|
-
local_assigns[:api].<%= column_name %> <%= model_name_underscored %>.<%= column_name %>
|
5
|
-
<%- end -%>
|
6
|
-
<%- if acts_as_customizable? -%>
|
7
|
-
render_api_custom_values <%= model_name_underscored %>.visible_custom_field_values, local_assigns[:api]
|
8
|
-
<%- end -%>
|
9
|
-
<%- if acts_as_attachable? -%>
|
10
|
-
local_assigns[:api].array :attachments do
|
11
|
-
<%= model_name_underscored %>.attachments.each do |attachment|
|
12
|
-
render_api_attachment attachment, local_assigns[:api]
|
13
|
-
end
|
14
|
-
end if include_in_api_response?('attachments')
|
15
|
-
<%- end -%>
|
16
|
-
|
17
|
-
call_hook :helper_render_api_<%= model_name_underscored %>, { api: local_assigns[:api], <%= model_name_underscored %>: <%= model_name_underscored %> }
|
18
|
-
end
|