因项目组2月底正式引进了redmine2.2.1管理从需求到开发到测试到上线的任务跟踪,近期又想将另一个数据变更系统的数据定时导入redmine来跟踪分发管理,以尽可能的避免丢失变更单的情况。
直接带来的一个问题就是自定义些许字段来放置数据变更单审批系统的数据,其中就牵涉到几个长文本字段。如:变更原因及内容、备份脚本、回滚脚本、变更脚本等;这些通过自定义类型为长文本的字段后即可使用,问题来了:
为了处理这个问题,经过google和redmine官方网站仔细查询,没能找到合适的插件来处理,倒是碰上了一些人也有这个需求:
第一个是找插件的,第二个也是国人提交的help,我用自己仅有的几个单词配合google翻译回了帖子。
节选自我回复的帖子。follow this:
代码:http://t.cn/zQPBMtK
文件:issues_helper.rb 地址:app\helpers\issues_helper.rb
文件:show.html.erb 地址:app\views\issues\show.html.erb
文件:pdf.rb 地址:lib\redmine\export\pdf.rb
----------------------
文件:issues_helper.rb 地址:app\helpers\issues_helper.rb
文件:show.html.erb 地址:app\views\issues\show.html.erb
文件:pdf.rb 地址:lib\redmine\export\pdf.rb
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
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 %>
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 ######
----------------------
另,在找插件时,发现两个很好用的插件。不过最终我们没有使用:
--------------------------------------------
由 Gregory S 更新于 3 个月 之前
The active method doesn’t seem to support arguments. You can workaround this bug by changing the first line ofplugins\extended_fields\app\views\custom_fields\_extended.html.erb
from
1 <% projects = Project.all_public.active(:order ⇒ 'name’).collect{ |project| [ project.name, project.id ] } %>
to
1 <% projects = Project.all_public.active.collect{ |project| [ project.name, project.id ] } %>
----------------------