代码拉取完成,页面将自动刷新
当年写的博客:[redmine自定义长文本字段显示及导出pdf排版问题临时解决方案](https://my.oschina.net/hexie/blog/142134)
问题介绍:因项目组2月底正式引进了redmine2.2.1管理从需求到开发到测试到上线的任务跟踪,近期又想将另一个数据变更系统的数据定时导入redmine来跟踪分发管理,以尽可能的避免丢失变更单的情况。 直接带来的一个问题就是自定义些许字段来放置数据变更单审批系统的数据,其中就牵涉到几个长文本字段。如:变更原因及内容、备份脚本、回滚脚本、变更脚本等;这些通过自定义类型为长文本的字段后即可使用,问题来了:
- 在issue现实页,自定义长文本字段混在自定义的字符串字段中,页面不好看;
- 在issue页导出pdf时,自定义的长文本字段又仅显示一行,自动隐藏溢出的字符;
附,当年查找参考过的链接:
修订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
新增自定义长文本字段的展现在描述后
<% 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 %>
代码1:修订自定义长文本字段不在属性里显示; 代码2:修订自定义长文本字段在描述后显示;
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
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(测试)](screenshoots/datachange-2 (测试).pdf)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。