redmine_extensions 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (17) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/redmine_extensions/entity/entity_generator.rb +39 -29
  3. data/lib/generators/redmine_extensions/entity/templates/app/models/%model_name_underscored%_query.rb.tt +42 -0
  4. data/lib/generators/redmine_extensions/entity/templates/{_%model_name_underscored%.api.rsb.tt → app/views/%model_name_pluralize_underscored%/_%model_name_underscored%.api.rsb.tt} +0 -0
  5. data/lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/_form.html.erb.tt +62 -0
  6. data/lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/edit.html.erb.tt +8 -0
  7. data/lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/new.html.erb.tt +8 -0
  8. data/lib/generators/redmine_extensions/entity/templates/controller.rb.erb +4 -6
  9. data/lib/generators/redmine_extensions/entity/templates/easy_query.rb.erb +15 -14
  10. data/lib/generators/redmine_extensions/entity/templates/migration.rb.erb +4 -0
  11. data/lib/generators/redmine_extensions/entity/templates/model.rb.erb +10 -17
  12. data/lib/generators/redmine_extensions/entity/templates/routes.rb.erb +9 -7
  13. data/lib/generators/redmine_extensions/entity/templates/spec/controllers/%model_name_underscored%_controller_spec.rb.tt +94 -0
  14. data/lib/generators/redmine_extensions/entity/templates/{factories.rb.erb → spec/factories.rb.erb} +1 -1
  15. data/lib/redmine_extensions/version.rb +1 -1
  16. metadata +14 -10
  17. data/lib/generators/redmine_extensions/entity/templates/controller_spec.rb.erb +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f91868f692beaaf8a3a69f028088732385f8670b4ff2103334708cf547827ae2
4
- data.tar.gz: aae4b3809dd2ea1b11d8e754853d45e93c9bb1980fd0ee64cc9e1a95fde479b9
3
+ metadata.gz: db4258140f1bd4b853bfd72b8a7c9a315ec0719943440d5c7f8d1182a5e5a81f
4
+ data.tar.gz: 45e45ab584f1a1fd838fde047261fe8fb4402c0b496a70c1b9a945167b775a40
5
5
  SHA512:
6
- metadata.gz: f7195001a6d347fed1b5708bfb3820d6dd9378b6a15900a9b740526bb5462f7b6a35ed1a1eac905778cd546269270179162994b14ff40f5bc81943a6cd52b8a7
7
- data.tar.gz: 0d9d725a78e71b4fe08797515e02fc64930c14d4c1b89487684a67fc67d268f107b7994444e4384bb5a65ba65da5e5031ef7584c30bb704fb974fe653c4f801b
6
+ metadata.gz: f46c4283187a9cbcfa66017cf06a2f6f2984efd2a36624fc737b0e0a936c4358251b822110a7a43cf1949347711d0fef0df743161db485b55f6580faa32ec70a
7
+ data.tar.gz: c188d2f7e3f5326e4a3e068cf546d070a679077b0c51b13bac9e728b77426b534f9f815636968e89d7d309a7efbbed4a3bb713b7308e266a90b0223e4537afb2
@@ -6,7 +6,7 @@ module RedmineExtensions
6
6
  argument :model_name, type: :string, required: true, banner: 'Post'
7
7
  argument :attributes, type: :array, required: true, banner: 'field[:type][:index] field[:type][:index]'
8
8
 
9
- class_option :rys, type: :boolean, default: false, required: false, desc: "Use in case of RYS"
9
+ class_option :rys, type: :boolean, default: false, required: false, desc: 'Use in case of RYS'
10
10
 
11
11
  class_option :associations, type: :array, required: false, banner: '--associations association_type[:association_name][:association_class]'
12
12
 
@@ -33,11 +33,11 @@ module RedmineExtensions
33
33
  @model_name_camelized = model_name.camelize
34
34
  check_existing_const
35
35
 
36
- @rys = !!options["rys"]
36
+ @rys = !!options['rys']
37
37
  @plugin_name_underscored = plugin_name.underscore
38
38
  @plugin_pretty_name = @plugin_name_underscored.titleize
39
39
 
40
- @plugin_path = rys ? "." : "plugins/#{@plugin_name_underscored}"
40
+ @plugin_path = rys ? '.' : "plugins/#{@plugin_name_underscored}"
41
41
  @plugin_title = @plugin_name_underscored.camelize
42
42
 
43
43
  @model_name_underscored = model_name.underscore
@@ -65,9 +65,9 @@ module RedmineExtensions
65
65
  template 'edit.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/edit.html.erb"
66
66
  template 'edit.js.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/edit.js.erb"
67
67
 
68
- tests_root = rys ? "./spec" : "#{plugin_path}/test"
69
- template 'controller_spec.rb.erb', "#{tests_root + (!rys && "/spec" || "")}/controllers/#{model_name_pluralize_underscored}_controller_spec.rb"
70
- template 'factories.rb.erb', "#{tests_root}/factories/#{model_name_underscored}.rb"
68
+ tests_root = rys ? './spec' : "#{plugin_path}/test"
69
+ template 'spec/factories.rb.erb', "#{tests_root}/factories/#{model_name_underscored}.rb"
70
+ template 'spec/controllers/%model_name_underscored%_controller_spec.rb.tt', "#{tests_root}/controllers/#{model_name_underscored}_controller_spec.rb"
71
71
  template 'spec/requests/%model_name_underscored%_spec.rb.tt', "#{tests_root}/requests/#{model_name_underscored}.rb"
72
72
 
73
73
  if File.exists?("#{plugin_path}/config/locales/en.yml")
@@ -79,7 +79,7 @@ module RedmineExtensions
79
79
  File.delete("#{plugin_path}/tmp/tmp_en.yml")
80
80
 
81
81
  merged_langfile = original_langfile.deep_merge(added_translations)
82
- File.open("#{plugin_path}/config/locales/en.yml", "w") do |file|
82
+ File.open("#{plugin_path}/config/locales/en.yml", 'w') do |file|
83
83
  file.write merged_langfile.to_yaml
84
84
  end
85
85
  end
@@ -107,7 +107,7 @@ module RedmineExtensions
107
107
  template 'new.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/new.html.erb"
108
108
  template 'new.js.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/new.js.erb"
109
109
 
110
- if Redmine::Plugin.installed?(:easy_extensions)
110
+ if easy?
111
111
  template 'easy_query.rb.erb', "#{plugin_path}/app/models/#{model_name_underscored}_query.rb"
112
112
  template 'entity_attribute_helper_patch.rb.erb', "#{plugin_path}/extra/easy_patch/easy_extensions/helpers/entity_attribute_helper_patch.rb"
113
113
 
@@ -123,7 +123,7 @@ module RedmineExtensions
123
123
  "\n h(value)" +
124
124
  "\n end" +
125
125
  "\n end" +
126
- "\n", after: "base.class_eval do"
126
+ "\n", after: 'base.class_eval do'
127
127
 
128
128
  end
129
129
  else
@@ -133,21 +133,21 @@ module RedmineExtensions
133
133
  routes_file = "#{plugin_path}/config/routes.rb"
134
134
  if File.exists?(routes_file)
135
135
  if project?
136
- insert_into_file routes_file, before: (rys ? /end\z/ : /\z/) do
137
- "\nresources :projects do " +
138
- "\n resources :#{model_name_pluralize_underscored}" +
139
- "\nend\n"
136
+ insert_into_file routes_file, before: (rys ? /^end$/ : /\z/) do
137
+ "\n resources :projects do " +
138
+ "\n resources :#{model_name_pluralize_underscored}" +
139
+ "\n end\n"
140
140
  end
141
141
  end
142
- insert_into_file routes_file, before: (rys ? /end\z/ : /\z/) do
143
- "\nresources :#{model_name_pluralize_underscored} do" +
144
- "\n collection do " +
145
- "\n get 'autocomplete'" +
146
- "\n get 'bulk_edit'" +
147
- "\n post 'bulk_update'" +
148
- "\n get 'context_menu'" +
149
- "\n end" +
150
- "\nend"
142
+ insert_into_file routes_file, before: (rys ? /^end$/ : /\z/) do
143
+ "\n resources :#{model_name_pluralize_underscored} do" +
144
+ "\n collection do " +
145
+ "\n get 'autocomplete'" +
146
+ "\n get 'bulk_edit'" +
147
+ "\n post 'bulk_update'" +
148
+ "\n get 'context_menu'" +
149
+ "\n end" +
150
+ "\n end\n"
151
151
  end
152
152
  else
153
153
  template 'routes.rb.erb', "#{plugin_path}/config/routes.rb"
@@ -187,16 +187,16 @@ module RedmineExtensions
187
187
 
188
188
  append_to_file "#{plugin_path}/after_init.rb", s
189
189
  elsif rys
190
- s = ""
190
+ s = ''
191
191
  s << "\n Redmine::AccessControl.map do |map|"
192
192
  s << "\n map.easy_category :#{model_name_pluralize_underscored} do |pmap|"
193
193
  s << "\n pmap.permission :view_#{model_name_pluralize_underscored}, { #{model_name_pluralize_underscored}: [:index, :show, :autocomplete, :context_menu] }, read: true"
194
194
  s << "\n pmap.permission :manage_#{model_name_pluralize_underscored}, { #{model_name_pluralize_underscored}: [:new, :create, :edit, :update, :destroy, :bulk_edit, :bulk_update] }"
195
195
  s << "\n end "
196
196
  s << "\n end\n"
197
- append_to_file "./config/initializers/01_access_control.rb", s
197
+ append_to_file './config/initializers/01_access_control.rb', s
198
198
 
199
- s = ""
199
+ s = ''
200
200
  s << "\n Redmine::MenuManager.map :top_menu do |menu|"
201
201
  s << "\n menu.push :#{model_name_pluralize_underscored}, { controller: '#{model_name_pluralize_underscored}', action: 'index', project_id: nil }, caption: :label_#{model_name_pluralize_underscored}"
202
202
  s << "\n end\n"
@@ -205,8 +205,8 @@ module RedmineExtensions
205
205
  s << "\n menu.push :#{model_name_pluralize_underscored}, { controller: '#{model_name_pluralize_underscored}', action: 'index' }, param: :project_id, caption: :label_#{model_name_pluralize_underscored}"
206
206
  s << "\n end\n"
207
207
  end
208
- append_to_file "./config/initializers/02_menu_manager.rb", s
209
- s = ""
208
+ append_to_file './config/initializers/02_menu_manager.rb', s
209
+ s = ''
210
210
  if acts_as_customizable?
211
211
  s << "\n CustomFieldsHelper::CUSTOM_FIELDS_TABS << {name: '#{model_name}CustomField', partial: 'custom_fields/index', label: :label_#{model_name_pluralize_underscored}}\n"
212
212
  end
@@ -220,7 +220,7 @@ module RedmineExtensions
220
220
  s << "\n activity.register :#{model_name_pluralize_underscored}, {class_name: %w(#{model_name}), default: false}"
221
221
  s << "\n end\n"
222
222
  end
223
- other_initializer = "./config/initializers/06_others.rb"
223
+ other_initializer = './config/initializers/06_others.rb'
224
224
  if File.exist?(other_initializer)
225
225
  append_file other_initializer do
226
226
  s
@@ -235,13 +235,23 @@ module RedmineExtensions
235
235
 
236
236
 
237
237
  template 'show.api.rsb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/show.api.rsb"
238
- template '_%model_name_underscored%.api.rsb.tt', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/_#{model_name_underscored}.api.rsb"
239
238
  template 'show.html.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/show.html.erb"
240
239
  template 'show.js.erb.erb', "#{plugin_path}/app/views/#{model_name_pluralize_underscored}/show.js.erb"
240
+
241
+ # New templates
242
+ template 'app/models/%model_name_underscored%_query.rb'
243
+ template 'app/views/%model_name_pluralize_underscored%/_%model_name_underscored%.api.rsb'
244
+ template 'app/views/%model_name_pluralize_underscored%/_form.html.erb'
245
+ template 'app/views/%model_name_pluralize_underscored%/new.html.erb'
246
+ template 'app/views/%model_name_pluralize_underscored%/edit.html.erb'
241
247
  end
242
248
 
243
249
  private
244
250
 
251
+ def easy?
252
+ Redmine::Plugin.installed?(:easy_extensions)
253
+ end
254
+
245
255
  def assocs
246
256
  options[:associations]
247
257
  end
@@ -0,0 +1,42 @@
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
@@ -0,0 +1,62 @@
1
+ <%%= labelled_form_for([@project, @<%= model_name_underscored %>], html: { multipart: <%= acts_as_attachable? %>, id: '<%= model_name_underscored %>_form', class: 'tabular', remote: request.xhr? }) do |f| %>
2
+ <%%= error_messages_for @<%= model_name_underscored %> %>
3
+
4
+ <div class="box">
5
+ <%- if project? -%>
6
+ <%% if <%= model_name_underscored %>.safe_attribute?('project_id') && !@project %>
7
+ <p>
8
+ <%%= f.label :project_id, ::<%= model_name %>.human_attribute_name(:project_id) %>
9
+ <%%= f.select :project_id, Project.allowed_to(:manage_<%= model_name_pluralize_underscored %>).collect{|x| [x.name, x.id]}, include_blank: true %>
10
+ </p>
11
+ <%% end %>
12
+ <%- end -%>
13
+ <%- safe_columns.each do |column_name, column_options| -%>
14
+ <%% if <%= model_name_underscored %>.safe_attribute?('<%= column_name %>') %>
15
+ <p>
16
+ <%%= f.label :<%= column_name %>, ::<%= model_name %>.human_attribute_name(:<%= column_name %>) %>
17
+ <%- if column_options[:query_type] == 'string' || column_options[:query_type] == 'integer' -%>
18
+ <%%= f.text_field :<%= column_name %> %>
19
+ <%- elsif column_options[:query_type] == 'list' || column_options[:query_type] == 'list_optional' -%>
20
+ <%%= f.select :<%= column_name %>, <%= column_options[:class] %>.all.collect{|x| [x.<%= column_options[:list_class_name] %>, x.id]}.sort, include_blank: true %>
21
+ <%- elsif column_options[:query_type] == 'text' -%>
22
+ <%%= 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' %>
23
+ <%%= wikitoolbar_for '<%= model_name_underscored %>_<%= column_name %>' %>
24
+ <%- elsif column_options[:query_type] == 'boolean' -%>
25
+ <%%= f.radio_button :<%= column_name %>, false %>
26
+ <%- else -%>
27
+ <%%= f.text_field :<%= column_name %> %>
28
+ <%- end -%>
29
+ </p>
30
+ <%% end %>
31
+ <%- end -%>
32
+ <% associations.each do |assoc| %>
33
+ <%- next if assoc[1][:type] == 'has_many' -%>
34
+ <% association_name = assoc[0] %>
35
+ <p>
36
+ <%%= f.label l(:label_<%= association_name %>) %>
37
+ <%%= f.select :<%= association_name %>_id, <%= association_name.camelcase %>.visible.sorted.map{ |<%= association_name %>| [<%= association_name %>.to_s, <%= association_name %>.id]} %>
38
+ </p>
39
+ <% end %>
40
+ <%- if acts_as_customizable? -%>
41
+ <%% custom_field_values = <%= model_name_underscored %>.visible_custom_field_values %>
42
+ <%% custom_field_values.each do |value| %>
43
+ <p>
44
+ <%%= custom_field_tag_with_label :<%= model_name_underscored %>, value %>
45
+ </p>
46
+ <%% end %>
47
+ <%- end -%>
48
+ <%- if acts_as_attachable? -%>
49
+ <p id="attachments_form"><label><%%= l(:label_attachment_plural) %></label><%%= render :partial => 'attachments/form', :locals => {:container => <%= model_name_underscored %>} %></p>
50
+ <%- end -%>
51
+ </div>
52
+
53
+ <%% if !request.xhr? %>
54
+ <p>
55
+ <%% if f.object.new_record? %>
56
+ <%%= submit_tag l(:button_create), title: l(:button_create), class: "button-positive" %>
57
+ <%% else %>
58
+ <%%= submit_tag l(:button_update), title: l(:button_update), class: "button-positive" %>
59
+ <%% end %>
60
+ </p>
61
+ <%% end %>
62
+ <%% end %>
@@ -0,0 +1,8 @@
1
+ <%%= title l(:heading_<%= model_name_underscored %>_edit) %>
2
+
3
+ <%%= render partial: 'form', locals: { <%= model_name_underscored %>: @<%= model_name_underscored %>n } %>
4
+
5
+ <% ### PAGE CUSTOMS ########################################################## %>
6
+ <% content_for :sidebar do %>
7
+ <%= render partial: '<%= model_name_pluralize_underscored %>/sidebar' %>
8
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%%= title l(:heading_<%= model_name_underscored %>_new) %>
2
+
3
+ <%%= render partial: 'form', locals: { <%= model_name_underscored %>: @<%= model_name_underscored %>n } %>
4
+
5
+ <% ### PAGE CUSTOMS ########################################################## %>
6
+ <% content_for :sidebar do %>
7
+ <%= render partial: '<%= model_name_pluralize_underscored %>/sidebar' %>
8
+ <% end %>
@@ -10,23 +10,20 @@ class <%= controller_class %>Controller < ApplicationController
10
10
  <%- end -%>
11
11
 
12
12
  helper :<%= model_name_pluralize_underscored %>
13
- helper :custom_fields
14
- helper :context_menus
15
- helper :attachments
16
- helper :issues
13
+ helper :custom_fields, :context_menus, :attachments, :issues
17
14
  include_query_helpers
18
15
 
19
16
  accept_api_auth :index, :show, :create, :update, :destroy
20
17
 
21
18
  def index
22
- <% if Redmine::Plugin.installed?(:easy_extensions) %>
19
+ <%- if Redmine::Plugin.installed?(:easy_extensions) %>
23
20
  index_for_easy_query(<%= model_name %>Query)
24
21
  <% else %>
25
22
  retrieve_query(<%= model_name %>Query)
26
23
  @entity_count = @query.<%= model_name_pluralize_underscored %>.count
27
24
  @entity_pages = Paginator.new @entity_count, per_page_option, params['page']
28
25
  @entities = @query.<%= model_name_pluralize_underscored %>(offset: @entity_pages.offset, limit: @entity_pages.per_page)
29
- <% end %>
26
+ <%- end %>
30
27
  end
31
28
 
32
29
  def show
@@ -192,6 +189,7 @@ class <%= controller_class %>Controller < ApplicationController
192
189
  @<%= model_name_underscored %> = @<%= model_name_pluralize_underscored %>.first if @<%= model_name_pluralize_underscored %>.count == 1
193
190
  raise ActiveRecord::RecordNotFound if @<%= model_name_pluralize_underscored %>.empty?
194
191
  raise Unauthorized unless @<%= model_name_pluralize_underscored %>.all?(&:visible?)
192
+
195
193
  @projects = @<%= model_name_pluralize_underscored %>.collect(&:project).compact.uniq
196
194
  @project = @projects.first if @projects.size == 1
197
195
  rescue ActiveRecord::RecordNotFound
@@ -2,35 +2,36 @@ class <%= model_name %>Query < EasyQuery
2
2
 
3
3
  self.queried_class = <%= model_name %>
4
4
 
5
- def initialize_available_filters
5
+ def initialize_available_filters
6
+ on_filter_group(default_group_label) do
6
7
  <%- db_columns.each do |column_name, column_options| -%>
7
- <%- if project? && column_name == 'project_id' -%>
8
+ <%- if project? && column_name == 'project_id' -%>
8
9
  if project.nil?
9
10
  add_available_filter '<%= column_name %>', name: <%= model_name %>.human_attribute_name(:<%= column_name %>), type: :<%= column_options[:query_type] %>, values: all_projects_values
10
11
  end
11
- <%- else -%>
12
+ <%- else -%>
12
13
  add_available_filter '<%= column_name %>', name: <%= model_name %>.human_attribute_name(:<%= column_name %>), type: :<%= column_options[:query_type] %>
13
- <%- end -%>
14
+ <%- end -%>
14
15
  <%- end -%>
15
16
  <%- if acts_as_customizable? -%>
16
17
  add_custom_fields_filters(<%= model_name %>CustomField)
17
18
  <%- end -%>
18
19
  end
20
+ end
19
21
 
20
22
  def initialize_available_columns
21
- group = l("label_filter_group_#{self.class.name.underscore}")
22
-
23
- <%- db_columns.each do |column_name, column_options| -%>
24
- 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 %>), group: group
25
- <%- end -%>
26
- <%- if acts_as_customizable? -%>
27
- add_available_columns <%= model_name %>CustomField.sorted.visible.collect { |cf| EasyQueryCustomFieldColumn.new(cf, group: l(:label_filter_group_custom_fields))}
28
- <%- end -%>
29
-
23
+ on_filter_group(default_group_label) do
24
+ <%- db_columns.each do |column_name, column_options| -%>
25
+ 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 %>)
26
+ <%- end -%>
27
+ <%- if acts_as_customizable? -%>
28
+ add_available_columns <%= model_name %>CustomField.sorted.visible.collect { |cf| EasyQueryCustomFieldColumn.new(cf, group: l(:label_filter_group_custom_fields)) }
29
+ <%- end -%>
30
+ end
30
31
  end
31
32
 
32
33
  def default_list_columns
33
- 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]}
34
+ 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] }
34
35
  end
35
36
 
36
37
  end
@@ -2,9 +2,13 @@ class Create<%= model_name_pluralize_underscored.camelize %> < ActiveRecord::Mig
2
2
  def change
3
3
  create_table :<%= model_name_pluralize_underscored %> do |t|
4
4
  <%- columns = db_columns.reject{|k| k.in?(["created_at", "updated_at"])} -%>
5
+ <%- author_col = db_columns.delete "author_id" %>
6
+ <%- project_col = db_columns.delete "project_id" %>
5
7
  <%- columns.each do |column_name, column_attrs| -%>
6
8
  t.<%= column_attrs[:type] %> :<%= column_name %>, null: <%= column_attrs[:null] %>
7
9
  <%- end -%>
10
+ <%= "t.belongs_to :author" if author_col %>
11
+ <%= "t.belongs_to :project" if project_col %>
8
12
 
9
13
  t.timestamps
10
14
  end
@@ -4,11 +4,9 @@ class <%= model_name %> < ActiveRecord::Base
4
4
  <%= 'belongs_to :project' if project? %>
5
5
  <%= 'belongs_to :author, class_name: \'User\'' if author? %>
6
6
 
7
- scope :visible, lambda { |*args|
8
- where(<%= model_name %>.visible_condition(args.shift || User.current, *args))<%= '.joins(:project)' if project? %>
9
- }
7
+ scope :visible, ->(*args) { where(<%= model_name %>.visible_condition(args.shift || User.current, *args))<%= '.joins(:project)' if project? %> }
10
8
  <% if name_column? %>
11
- scope :sorted, lambda { order("#{table_name}.<%= name_column %> ASC") }
9
+ scope :sorted, -> { order("#{table_name}.<%= name_column %> ASC") }
12
10
  <% end %>
13
11
 
14
12
  <%- if acts_as_searchable? -%>
@@ -35,7 +33,7 @@ class <%= model_name %> < ActiveRecord::Base
35
33
 
36
34
  <%= 'validates :project_id, presence: true' if project? %>
37
35
  <%= 'validates :author_id, presence: true' if author? %>
38
-
36
+ <%= "validates :#{safe_columns.keys.first}, presence: true" if safe_columns.any? %>
39
37
 
40
38
  <%- if associations.any? -%>
41
39
  <%- associations.each do |assoc_name, values| -%>
@@ -48,7 +46,7 @@ class <%= model_name %> < ActiveRecord::Base
48
46
  <%- attributes += safe_columns.keys if safe_columns.any? -%>
49
47
  <%- attributes += ['custom_field_values', 'custom_fields'] if acts_as_customizable? -%>
50
48
  <%-attributes += associations.keys.map{ |assoc| "#{assoc}_id" } -%>
51
- safe_attributes *%w(<%= attributes.join(' ') %>)
49
+ safe_attributes *%w[<%= attributes.join(' ') %>]
52
50
  <%- if project? -%>
53
51
  safe_attributes 'project_id', if: ->(<%= model_name_underscored %>, _user) { <%= model_name_underscored %>.new_record? }
54
52
  <%- end -%>
@@ -71,7 +69,7 @@ class <%= model_name %> < ActiveRecord::Base
71
69
  end
72
70
 
73
71
  def editable_by?(user)
74
- visible?(user)
72
+ editable?(user)
75
73
  end
76
74
 
77
75
  <%- if !project? -%>
@@ -82,17 +80,17 @@ class <%= model_name %> < ActiveRecord::Base
82
80
 
83
81
  def visible?(user = nil)
84
82
  user ||= User.current
85
- user.allowed_to?(:<%= view_permission %>, self.project, global: true)
83
+ user.allowed_to?(:<%= view_permission %>, project, global: true)
86
84
  end
87
85
 
88
86
  def editable?(user = nil)
89
87
  user ||= User.current
90
- user.allowed_to?(:<%= edit_permission %>, self.project, global: true)
88
+ user.allowed_to?(:<%= edit_permission %>, project, global: true)
91
89
  end
92
90
 
93
91
  def deletable?(user = nil)
94
92
  user ||= User.current
95
- user.allowed_to?(:<%= delete_permission %>, self.project, global: true)
93
+ user.allowed_to?(:<%= delete_permission %>, project, global: true)
96
94
  end
97
95
 
98
96
  def attachments_visible?(user = nil)
@@ -113,13 +111,8 @@ class <%= model_name %> < ActiveRecord::Base
113
111
  end
114
112
  <%- end -%>
115
113
 
116
- def created_on
117
- created_at
118
- end
119
-
120
- def updated_on
121
- updated_at
122
- end
114
+ alias_attribute :created_on, :created_at
115
+ alias_attribute :updated_on, :updated_at
123
116
 
124
117
  <%- if mail? -%>
125
118
  def notified_users
@@ -1,13 +1,15 @@
1
+
1
2
  <% if project? %>
2
3
  resources :projects do
3
4
  resources :<%= model_name_pluralize_underscored %>
4
5
  end
5
6
  <% end %>
6
- resources :<%= model_name_pluralize_underscored %> do
7
- collection do
8
- get 'autocomplete'
9
- get 'bulk_edit'
10
- post 'bulk_update'
11
- get 'context_menu'
7
+ resources :<%= model_name_pluralize_underscored %> do
8
+ collection do
9
+ get 'autocomplete'
10
+ get 'bulk_edit'
11
+ post 'bulk_update'
12
+ get 'context_menu'
13
+ end
12
14
  end
13
- end
15
+
@@ -0,0 +1,94 @@
1
+ <%- unless rys %>
2
+ require "easy_extensions/spec_helper"
3
+
4
+ <% end %>
5
+ RSpec.describe <%= controller_class %>Controller, logged: true do
6
+
7
+ describe "#index" do
8
+ before :each do
9
+ role = Role.non_member
10
+ role.add_permission! :view_<%= model_name_pluralize_underscored %>
11
+ end
12
+
13
+ it "html" do
14
+ get :index
15
+ expect(response).to have_http_status :success
16
+ end
17
+
18
+ it "json" do
19
+ get :index, params: { format: "json" }
20
+ expect(response).to have_http_status :ok
21
+ end
22
+ end
23
+
24
+ describe "#show" do
25
+ before :each do
26
+ role = Role.non_member
27
+ role.add_permission! :view_<%= model_name_pluralize_underscored %>
28
+ end
29
+ subject { FactoryBot.create(:<%= model_name_underscored %>) }
30
+
31
+ it "with id" do
32
+ get :show, params: { id: subject.id }
33
+ expect(response).to have_http_status :success
34
+ end
35
+
36
+ it "not found" do
37
+ get :show, params: { id: "invalid" }
38
+ expect(response).to have_http_status :not_found
39
+ end
40
+ end
41
+
42
+ context "manage <%= model_name_pluralize_underscored %>" do
43
+ before :each do
44
+ role = Role.non_member
45
+ role.add_permission! :manage_<%= model_name_pluralize_underscored %>
46
+ end
47
+ describe "#create" do
48
+ it "valid" do
49
+ expect {
50
+ post :create, params: { <%= model_name_underscored %>: FactoryBot.attributes_for(:<%= model_name_underscored %>), format: "json" }
51
+ }.to change(<%= model_name %>, :count).by 1
52
+ expect(response).to have_http_status :success
53
+ end
54
+
55
+ it "invalid" do
56
+ expect {
57
+ post :create, params: { <%= model_name_underscored %>: { <%= safe_columns.first[0] %>: "" }, format: "xml" }
58
+ }.to change(<%= model_name %>, :count).by 0
59
+ expect(response).to have_http_status :unprocessable_entity
60
+ end
61
+ end
62
+
63
+ describe "#update" do
64
+ subject { FactoryBot.create(:<%= model_name_underscored %>, <%= safe_columns.first[0] %>: 'value1') }
65
+ it "valid" do
66
+ expect {
67
+ put :update, params: { id: subject, <%= model_name_underscored %>: FactoryBot.attributes_for(:<%= model_name_underscored %>), format: "json" }; subject.reload
68
+ }.to change(subject, :<%= safe_columns.first[0] %>)
69
+ expect(response).to have_http_status :success
70
+ end
71
+
72
+ it "invalid" do
73
+ expect {
74
+ put :update, params: { id: subject, <%= model_name_underscored %>: { <%= safe_columns.first[0] %>: '' }, format: "xml" }; subject.reload
75
+ }.not_to change(subject, :<%= safe_columns.first[0] %>)
76
+ expect(response).to have_http_status :unprocessable_entity
77
+ end
78
+ end
79
+
80
+ describe "#destroy" do
81
+ before :each do
82
+ Role.non_member.add_permission! :view_<%= model_name_pluralize_underscored %>
83
+ end
84
+ subject! { FactoryBot.create(:<%= model_name_underscored %>) }
85
+ it { expect { delete :destroy, params: { id: subject } }.to change(<%= model_name %>, :count).by -1 }
86
+
87
+ it "record not found" do
88
+ expect { delete :destroy, params: { id: "none", format: "json" } }.to change(<%= model_name %>, :count).by 0
89
+ expect(response).to have_http_status :not_found
90
+ end
91
+ end
92
+ end
93
+
94
+ end
@@ -2,7 +2,7 @@ FactoryBot.define do
2
2
 
3
3
  factory :<%= model_name_underscored %> do
4
4
  <%- string_columns.each_key do |c| -%>
5
- sequence(:<%= c %>) { | n | "<%= c %>-#{n}"}
5
+ sequence(:<%= c %>) { |n| "<%= c %>-#{n}"}
6
6
  <%- end -%>
7
7
  <%= 'association :author, factory: :user' if author? %>
8
8
  <%= 'project' if project? %>
@@ -1,3 +1,3 @@
1
1
  module RedmineExtensions
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Easy Software Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-18 00:00:00.000000000 Z
11
+ date: 2019-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -95,20 +95,22 @@ files:
95
95
  - db/migrate/20190206121100_remove_foreign_key_from_easy_settings.rb
96
96
  - lib/generators/redmine_extensions/entity/USAGE
97
97
  - lib/generators/redmine_extensions/entity/entity_generator.rb
98
- - lib/generators/redmine_extensions/entity/templates/_%model_name_underscored%.api.rsb.tt
99
98
  - lib/generators/redmine_extensions/entity/templates/_form.html.erb.erb
100
99
  - lib/generators/redmine_extensions/entity/templates/_list.html.erb.erb
101
100
  - lib/generators/redmine_extensions/entity/templates/_sidebar.html.erb.erb
101
+ - lib/generators/redmine_extensions/entity/templates/app/models/%model_name_underscored%_query.rb.tt
102
+ - lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/_%model_name_underscored%.api.rsb.tt
103
+ - lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/_form.html.erb.tt
104
+ - lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/edit.html.erb.tt
105
+ - lib/generators/redmine_extensions/entity/templates/app/views/%model_name_pluralize_underscored%/new.html.erb.tt
102
106
  - lib/generators/redmine_extensions/entity/templates/context_menu.html.erb.erb
103
107
  - lib/generators/redmine_extensions/entity/templates/controller.rb.erb
104
- - lib/generators/redmine_extensions/entity/templates/controller_spec.rb.erb
105
108
  - lib/generators/redmine_extensions/entity/templates/custom_field.rb.erb
106
109
  - lib/generators/redmine_extensions/entity/templates/easy_query.rb.erb
107
110
  - lib/generators/redmine_extensions/entity/templates/edit.html.erb.erb
108
111
  - lib/generators/redmine_extensions/entity/templates/edit.js.erb.erb
109
112
  - lib/generators/redmine_extensions/entity/templates/en.yml.erb
110
113
  - lib/generators/redmine_extensions/entity/templates/entity_attribute_helper_patch.rb.erb
111
- - lib/generators/redmine_extensions/entity/templates/factories.rb.erb
112
114
  - lib/generators/redmine_extensions/entity/templates/helper.rb.erb
113
115
  - lib/generators/redmine_extensions/entity/templates/hooks.rb.erb
114
116
  - lib/generators/redmine_extensions/entity/templates/index.api.rsb.erb
@@ -128,6 +130,8 @@ files:
128
130
  - lib/generators/redmine_extensions/entity/templates/show.api.rsb.erb
129
131
  - lib/generators/redmine_extensions/entity/templates/show.html.erb.erb
130
132
  - lib/generators/redmine_extensions/entity/templates/show.js.erb.erb
133
+ - lib/generators/redmine_extensions/entity/templates/spec/controllers/%model_name_underscored%_controller_spec.rb.tt
134
+ - lib/generators/redmine_extensions/entity/templates/spec/factories.rb.erb
131
135
  - lib/generators/redmine_extensions/entity/templates/spec/requests/%model_name_underscored%_spec.rb.tt
132
136
  - lib/generators/redmine_extensions/plugin/USAGE
133
137
  - lib/generators/redmine_extensions/plugin/plugin_generator.rb
@@ -207,17 +211,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
211
  - !ruby/object:Gem::Version
208
212
  version: '0'
209
213
  requirements: []
210
- rubygems_version: 3.0.3
214
+ rubygems_version: 3.0.4
211
215
  signing_key:
212
216
  specification_version: 4
213
217
  summary: Redmine Extensions is set of usefull features for Redmine. Main focus is
214
218
  on development helpers, but many users can find it helpfull
215
219
  test_files:
216
- - spec/presenters/easy_settings/params_wrapper_spec.rb
217
- - spec/support/plugin_generator.rb
220
+ - spec/spec_helper.rb
218
221
  - spec/init_rails.rb
219
- - spec/models/easy_setting_spec.rb
220
222
  - spec/features/jasmine_spec.rb
221
223
  - spec/features/autocomplete_spec.rb
224
+ - spec/models/easy_setting_spec.rb
225
+ - spec/presenters/easy_settings/params_wrapper_spec.rb
226
+ - spec/support/plugin_generator.rb
222
227
  - spec/factories/easy_settings.rb
223
- - spec/spec_helper.rb
@@ -1,75 +0,0 @@
1
- <% unless rys %>
2
- require "easy_extensions/spec_helper"
3
- <% end %>
4
- RSpec.describe <%= controller_class %>Controller, logged: true do
5
- let(:<%= model_name_underscored %>) { FactoryBot.create(:<%= model_name_underscored %>) }
6
- let(:<%= model_name_pluralize_underscored %>) { FactoryBot.create_list(:<%= model_name_underscored %>, 2) }
7
-
8
- before(:each) do
9
- role = Role.non_member
10
- role.add_permission! :view_<%= model_name_pluralize_underscored %>
11
- role.add_permission! :manage_<%= model_name_pluralize_underscored %>
12
- end
13
-
14
- render_views
15
-
16
- it 'index' do
17
- <%= model_name_pluralize_underscored %>
18
-
19
- get :index
20
- expect(response).to have_http_status(:success)
21
- expect(response).to render_template('<%= model_name_pluralize_underscored %>/index')
22
- end
23
-
24
- it 'show' do
25
- get :show, params: { id: <%= model_name_underscored %> }
26
- expect(response).to have_http_status(:success)
27
- expect(response).to render_template('<%= model_name_pluralize_underscored %>/show')
28
- end
29
-
30
- it 'new' do
31
- get :new
32
- expect(response).to have_http_status(:success)
33
- expect(response).to render_template('<%= model_name_pluralize_underscored %>/new')
34
- end
35
-
36
- it 'create with invalid' do
37
- post :create, params: { <%= model_name_underscored %>: { } }
38
- expect(response).to render_template('<%= model_name_pluralize_underscored %>/new')
39
- expect(assigns[:<%= model_name_underscored %>]).to be_a_new(<%= model_name %>)
40
- end
41
-
42
- it 'create with valid' do
43
- post :create, params: { <%= model_name_underscored %>: FactoryBot.attributes_for(:<%= model_name_underscored %>) }
44
- expect(response).to redirect_to(<%= model_name_underscored %>_path(assigns[:<%= model_name_underscored %>]))
45
- expect(assigns[:<%= model_name_underscored %>]).not_to be_a_new(<%= model_name %>)
46
- end
47
-
48
- it 'edit' do
49
- get :edit, params: { id: <%= model_name_underscored %> }
50
- expect(response).to have_http_status(:success)
51
- expect(response).to render_template('<%= model_name_pluralize_underscored %>/edit')
52
- end
53
-
54
- it 'update with invalid' do
55
- put :update, params: { id: <%= model_name_underscored %>, <%= model_name_underscored %>: { <%= safe_columns.first[0] %>: '' } }
56
- expect(response).to render_template('<%= model_name_pluralize_underscored %>/edit')
57
- expect(assigns[:<%= model_name_underscored %>].valid?).to be false
58
- end
59
-
60
- it 'update with valid' do
61
- put :update, params: { id: <%= model_name_underscored %>, <%= model_name_underscored %>: { <%= safe_columns.first[0] %>: 'Tralalala' } }
62
- expect(response).to redirect_to(<%= model_name_underscored %>_path(assigns[:<%= model_name_underscored %>]))
63
- expect(assigns[ :<%= model_name_underscored %>].valid?).to be true
64
- end
65
-
66
- it 'destroy' do
67
- <%= model_name_underscored %>
68
- <%= model_name_pluralize_underscored %>
69
-
70
- expect(<%= model_name %>.count).to eq(3)
71
- expect { delete :destroy, params: { id: <%= model_name_underscored %> } }.to change(<%= model_name %>, :count).by(-1)
72
- expect(response).to redirect_to(<%= model_name_pluralize_underscored %>_path)
73
- expect(response).to redirect_to(<%= model_name_pluralize_underscored %>_path)
74
- end
75
- end