1 Star 0 Fork 1

梦回吹角连营 / redmine_custom-_fields_and_export

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Redmine自定义文本域和导出PDF的临时补丁

当年写的博客:[redmine自定义长文本字段显示及导出pdf排版问题临时解决方案](https://my.oschina.net/hexie/blog/142134)

摘要

问题介绍:因项目组2月底正式引进了redmine2.2.1管理从需求到开发到测试到上线的任务跟踪,近期又想将另一个数据变更系统的数据定时导入redmine来跟踪分发管理,以尽可能的避免丢失变更单的情况。 直接带来的一个问题就是自定义些许字段来放置数据变更单审批系统的数据,其中就牵涉到几个长文本字段。如:变更原因及内容、备份脚本、回滚脚本、变更脚本等;这些通过自定义类型为长文本的字段后即可使用,问题来了:

  • 在issue现实页,自定义长文本字段混在自定义的字符串字段中,页面不好看;
  • 在issue页导出pdf时,自定义的长文本字段又仅显示一行,自动隐藏溢出的字符;

附,当年查找参考过的链接:

修订清单

  • 文件:issues_helper.rb 地址:app\helpers\issues_helper.rb
  • 文件:show.html.erb 地址:app\views\issues\show.html.erb
  • 文件:pdf.rb 地址:lib\redmine\export\pdf.rb

修订详情

修订render_custom_fields_rows(issue)函数;判断自定义的长文本字段不显示 新增render_custom_fields_rows2(issue)函数;判断如为自定义的长文本字段则显示;

原函数:

  def render_custom_fields_rows(issue)
    return if issue.custom_field_values.empty?
    ordered_values = []
    half = (issue.custom_field_values.size / 2.0).ceil
    half.times do |i|
      ordered_values << issue.custom_field_values[i]
      ordered_values << issue.custom_field_values[i + half]
    end
    s = "<tr>\n"
    n = 0
    ordered_values.compact.each do |value|
      s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
      #s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
      if h(value.custom_field.name).include?"$"
      	#s << "\t<th>#{ h(value.custom_field.name) }:</th><td colspan=\"3\">#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
      else
      	s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
    	end
      n += 1
    end
    s << "</tr>\n"
    s.html_safe
  end

修订为

  def render_custom_fields_rows(issue)
    return if issue.custom_field_values.empty?
    ordered_values = []
    half = (issue.custom_field_values.size / 2.0).ceil
    half.times do |i|
      ordered_values << issue.custom_field_values[i]
      ordered_values << issue.custom_field_values[i + half]
    end
    s = "<tr>\n"
    n = 0
    ordered_values.compact.each do |value|
      s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
      #s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
      if h(value.custom_field.name).include?"$"
      	#s << "\t<th>#{ h(value.custom_field.name) }:</th><td colspan=\"3\">#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
      else
      	s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
    	end
      n += 1
    end
    s << "</tr>\n"
    s.html_safe
  end

新增自定义文本域函数

render_custom_fields_rows2(issue)函数

  def render_custom_fields_rows2(issue)
    return if issue.custom_field_values.empty?
    ordered_values = []
    half = (issue.custom_field_values.size / 2.0).ceil
    half.times do |i|
      ordered_values << issue.custom_field_values[i]
      ordered_values << issue.custom_field_values[i + half]
    end
    s = "<tr>\n"
    n = 0
    ordered_values.compact.each do |value|
      s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
#######s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
      if h(value.custom_field.name).include?"$"
      	s << "\t<p><strong><th>#{ h(value.custom_field.name) }:</th></p></strong></tr>\n<tr>\n<td colspan=\"3\"><pre>#{ simple_format_without_paragraph(h(show_value(value))) }</pre></td>\n"
      end
#######
      n += 1
    end
    s << "</tr>\n"
    s.html_safe
  end

文件:show.html.erb

新增自定义长文本字段的展现在描述后

变更以下代码

<% if @issue.description? %>
<div class="description">
  <div class="contextual">
  <%= link_to l(:button_quote), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %>
  </div>

  <p><strong><%=l(:field_description)%></strong></p>
  <div class="wiki">
  <%= textilizable @issue, :description, :attachments => @issue.attachments %>
  </div>
</div>
<% end %>

为:

<% if @issue.description? %>
<div class="description">
  <div class="contextual">
  <%= link_to l(:button_quote), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %>
  </div>

  <p><strong><%=l(:field_description)%></strong></p>
  <div class="wiki">
  <%= textilizable @issue, :description, :attachments => @issue.attachments %>
  </div>
</div>
<hr />
<div class="description">
	<div class="wiki">
		<%= render_custom_fields_rows2(@issue) %>
	</div>
</div>
<% end %>

文件:pdf.rb

代码1:修订自定义长文本字段不在属性里显示; 代码2:修订自定义长文本字段在描述后显示;

找到以下代码1:

        half = (issue.custom_field_values.size / 2.0).ceil
        issue.custom_field_values.each_with_index do |custom_value, i|
          	(i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value)]          
        end

修订为:

        half = (issue.custom_field_values.size / 2.0).ceil
        issue.custom_field_values.each_with_index do |custom_value, i|
        	#############
        	if custom_value.custom_field.name.include?"$"
        	else
          	(i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value)]
          end
          #############
        end	

找到以下代码2:

		pdf.SetFontStyle('B',9)
        pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
        pdf.SetFontStyle('',9)
        # Set resize image scale
        pdf.SetImageScale(1.6)
        pdf.RDMwriteHTMLCell(35+155, 5, 0, 0,
              issue.description.to_s, issue.attachments, "LRB")

修订为:

修订为:
        pdf.SetFontStyle('B',9)
        pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
        pdf.SetFontStyle('',9)
        # Set resize image scale
        pdf.SetImageScale(1.6)
        pdf.RDMwriteHTMLCell(35+155, 5, 0, 0,
              issue.description.to_s, issue.attachments, "LRB")
##########
				issue.custom_field_values.each_with_index do |custom_value, i|
        	if custom_value.custom_field.name.include?"$"        		
        		 itemcusname = custom_value.custom_field.name
        		 itemcusvalue = show_value(custom_value)
        		 pdf.SetFontStyle('B',9)
        		 pdf.RDMCell(35+155, 5, (itemcusname.to_s), "LRT", 1)
        		 pdf.SetFontStyle('',8)
        		 pdf.SetImageScale(1.6)
        		 pdf.RDMMultiCell(35+155, 5, itemcusvalue.to_s)
        	else
          	
          end
          pdf.Ln
        end

######

看看效果

系统中自定义多行文本

页面布局效果图(测试)

导出pdf

[工单导出pdf(测试)](screenshoots/datachange-2 (测试).pdf)

自定义多行文本的工单导出PDF

空文件

简介

Redmine自定义文本域和导出PDF的临时补丁 当年写的博客:[redmine自定义长文本字段显示及导出pdf排版问题临时解决方案](https://my.oschina.net/hexie/blog/142134) 摘要 问题介绍:因项目组2月底正式引进了redmine2.2.1管理从需求到开发到测试到上线的任务跟踪,近期又想将另一个数据变更系统的数据定时导入redmine来跟踪分发管理,以尽可能的避免丢失变更单的情况。 直接带来的一个问题就是自定义些许字段来放置数据变更单审批系统的数据,其中就牵涉到几个长文本字段。如:变更原因及内容、备份脚本、回滚脚本、变更脚本等;这些通过自定义类型为长文本的字段后即可使用,问题来了: 在issue现实页,自定义长文本字段... 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Ruby
1
https://gitee.com/DevOpsDreams/redmine_custom-_fields_and_export.git
git@gitee.com:DevOpsDreams/redmine_custom-_fields_and_export.git
DevOpsDreams
redmine_custom-_fields_and_export
redmine_custom-_fields_and_export
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891