Project

General

Profile

Patch #21705 » option_to_show_fields_under_description.patch

Marius BĂLTEANU, 2016-01-12 22:39

View differences:

app/helpers/issues_helper.rb
223 223
    end
224 224
  end
225 225

  
226
  def render_custom_fields_rows_above_desc(issue)
227
    values = issue.visible_custom_field_values_by_position
228
    return if values.empty?
229
    half = (values.size / 2.0).ceil
230
    issue_fields_rows do |rows|
231
      values.each_with_index do |value, i|
232
        css = "cf_#{value.custom_field.id}"
233
        m = (i < half ? :left : :right)
234
        rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css
235
      end
236
    end
237
  end
238

  
239
  def render_custom_fields_rows_under_desc(issue)
240
    values = issue.visible_custom_field_values_by_position(nil, true)
241
    return if values.empty?
242

  
243
    s = ''
244
    values.each_with_index do |value, i|
245
      content =
246
          content_tag('hr') +
247
          content_tag('p', content_tag('strong', custom_field_name_tag(value.custom_field) )) +
248
          content_tag('div', show_value(value), class: 'value')
249
      s << content_tag('div', content, class: "cf_#{value.custom_field.id}")
250
    end
251
    s.html_safe
252
  end
253

  
226 254
  # Returns the path for updating the issue form
227 255
  # with project as the current project
228 256
  def update_issue_form_path(project, issue)
app/models/issue.rb
230 230
    end
231 231
  end
232 232

  
233
  # Returns the custom fields depending on the attribute
234
  # show_under_description
235
  def visible_custom_field_values_by_position(user=nil, under_description=false)
236
    user_real = user || User.current
237
    custom_field_values.select do |value|
238
      if under_description == false
239
        value.custom_field.visible_by?(project, user_real) unless value.custom_field.show_under_description?
240
      else
241
        value.custom_field.visible_by?(project, user_real) && value.custom_field.show_under_description?
242
      end
243
    end
244
  end
245

  
233 246
  # Copies attributes from another issue, arg can be an id or an Issue
234 247
  def copy_from(arg, options={})
235 248
    issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg)
app/views/custom_fields/formats/_text.html.erb
1 1
<%= render :partial => 'custom_fields/formats/regexp', :locals => {:f => f, :custom_field => custom_field} %>
2 2
<p><%= f.check_box :text_formatting, {:label => :setting_text_formatting}, 'full', '' %></p>
3
<p><%= f.check_box :show_under_description, {:label => :setting_show_under_description}  %></p>
3 4
<p><%= f.text_area(:default_value, :rows => 5) %></p>
app/views/issues/show.html.erb
68 68
    end
69 69
  end
70 70
end %>
71
<%= render_custom_fields_rows(@issue) %>
71
<%= render_custom_fields_rows_above_desc(@issue) %>
72 72
<%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %>
73 73
</div>
74 74

  
......
89 89
<%= link_to_attachments @issue, :thumbnails => true %>
90 90
<% end -%>
91 91

  
92
<%= render_custom_fields_rows_under_desc(@issue) %>
93

  
92 94
<%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %>
93 95

  
94 96
<% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %>
config/locales/en.yml
430 430
  setting_search_results_per_page: Search results per page
431 431
  setting_attachment_extensions_allowed: Allowed extensions
432 432
  setting_attachment_extensions_denied: Disallowed extensions
433
  setting_show_under_description: Show under description
433 434

  
434 435
  permission_add_project: Create project
435 436
  permission_add_subprojects: Create subprojects
436
- 
db/migrate/20160107180443_add_custom_fields_show_under_description.rb
1
class AddCustomFieldsShowUnderDescription < ActiveRecord::Migration
2
  def self.up
3
    add_column :custom_fields, :show_under_description, :boolean, :default => false
4
  end
5

  
6
  def self.down
7
    remove_column :custom_fields, :show_under_description
8
  end
9
end
(3-3/8)