From e3b7637efaf4e7bf4cfeb7b7897fe049c4ce3de3 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Tue, 12 Jan 2016 20:14:10 +0000 Subject: added an option for long text custom fields to be displayed under the description field --- app/helpers/issues_helper.rb | 28 ++++++++++++++++++++++++++ app/models/issue.rb | 13 ++++++++++++ app/views/custom_fields/formats/_text.html.erb | 1 + app/views/issues/show.html.erb | 4 +++- config/locales/en.yml | 1 + 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 497bea3..967b7c0 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -223,6 +223,34 @@ module IssuesHelper end end + def render_custom_fields_rows_above_desc(issue) + values = issue.visible_custom_field_values_by_position + return if values.empty? + half = (values.size / 2.0).ceil + issue_fields_rows do |rows| + values.each_with_index do |value, i| + css = "cf_#{value.custom_field.id}" + m = (i < half ? :left : :right) + rows.send m, custom_field_name_tag(value.custom_field), show_value(value), :class => css + end + end + end + + def render_custom_fields_rows_under_desc(issue) + values = issue.visible_custom_field_values_by_position(nil, true) + return if values.empty? + + s = '' + values.each_with_index do |value, i| + content = + content_tag('hr') + + content_tag('p', content_tag('strong', custom_field_name_tag(value.custom_field) )) + + content_tag('div', show_value(value), class: 'value') + s << content_tag('div', content, class: "cf_#{value.custom_field.id}") + end + s.html_safe + end + # Returns the path for updating the issue form # with project as the current project def update_issue_form_path(project, issue) diff --git a/app/models/issue.rb b/app/models/issue.rb index 707c458..c517755 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -230,6 +230,19 @@ class Issue < ActiveRecord::Base end end + # Returns the custom fields depending on the attribute + # show_under_description + def visible_custom_field_values_by_position(user=nil, under_description=false) + user_real = user || User.current + custom_field_values.select do |value| + if under_description == false + value.custom_field.visible_by?(project, user_real) unless value.custom_field.show_under_description? + else + value.custom_field.visible_by?(project, user_real) && value.custom_field.show_under_description? + end + end + end + # Copies attributes from another issue, arg can be an id or an Issue def copy_from(arg, options={}) issue = arg.is_a?(Issue) ? arg : Issue.visible.find(arg) diff --git a/app/views/custom_fields/formats/_text.html.erb b/app/views/custom_fields/formats/_text.html.erb index e72dcab..e05b863 100644 --- a/app/views/custom_fields/formats/_text.html.erb +++ b/app/views/custom_fields/formats/_text.html.erb @@ -1,3 +1,4 @@ <%= render :partial => 'custom_fields/formats/regexp', :locals => {:f => f, :custom_field => custom_field} %>

<%= f.check_box :text_formatting, {:label => :setting_text_formatting}, 'full', '' %>

+

<%= f.check_box :show_under_description, {:label => :setting_show_under_description} %>

<%= f.text_area(:default_value, :rows => 5) %>

diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 70a7fe1..7f3fcfa 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -68,7 +68,7 @@ end end end %> -<%= render_custom_fields_rows(@issue) %> +<%= render_custom_fields_rows_above_desc(@issue) %> <%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %> @@ -89,6 +89,8 @@ end %> <%= link_to_attachments @issue, :thumbnails => true %> <% end -%> +<%= render_custom_fields_rows_under_desc(@issue) %> + <%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %> <% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 24d5fe7..6ef524e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -430,6 +430,7 @@ en: setting_search_results_per_page: Search results per page setting_attachment_extensions_allowed: Allowed extensions setting_attachment_extensions_denied: Disallowed extensions + setting_show_under_description: Show under description permission_add_project: Create project permission_add_subprojects: Create subprojects -- 2.1.4 From c801e349d0e2d41dfe6feefdcbf81ac639250f28 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Tue, 12 Jan 2016 21:31:20 +0000 Subject: added migration file --- .../20160107180443_add_custom_fields_show_under_description.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 db/migrate/20160107180443_add_custom_fields_show_under_description.rb diff --git a/db/migrate/20160107180443_add_custom_fields_show_under_description.rb b/db/migrate/20160107180443_add_custom_fields_show_under_description.rb new file mode 100644 index 0000000..8aa52b6 --- /dev/null +++ b/db/migrate/20160107180443_add_custom_fields_show_under_description.rb @@ -0,0 +1,9 @@ +class AddCustomFieldsShowUnderDescription < ActiveRecord::Migration + def self.up + add_column :custom_fields, :show_under_description, :boolean, :default => false + end + + def self.down + remove_column :custom_fields, :show_under_description + end +end -- 2.1.4