17. _form_custom_fields.html.erb
(編集画面のHTML出力)
<% custom_field_values =
@issue.editable_custom_field_values %>
<% if custom_field_values.present? %>
<div class="splitcontent">
<% split_on = custom_field_values.size %>
<% custom_field_values.each do |value| %>
<% case value.custom_field_id
when 4 %>
<hr><h2>障害現象</h2>
<% when 3 %>
<hr><h2>原因</h2>
<% when 10 %>
<hr><h2>処置</h2>
<% end %>
<% case (0+value.custom_field_id)
when 4,6,3 %>
<p>
<%= custom_field_tag_with_label_nopre :issue,
value , :required =>
@issue.required_attribute?(value.custom_field_id) %>
<% when 5,1,7 %>
<%= custom_field_tag_without_label_nopre :issue,
value , :required =>
@issue.required_attribute?(value.custom_field_id) %>
<% when 13,2,8 %>
<%= custom_field_tag_without_label_nopre :issue,
value , :required =>
@issue.required_attribute?(value.custom_field_id) %>
</p>
<% else %>
<p><%= custom_field_tag_with_label :issue,
value, :required =>
@issue.required_attribute?(value.custom_field_id) %></p
>
<% end %>
<% end %>
</div>
<% end %>
セクション
最初のフィールド
区切り線+見出し
行頭
行末
行途中
1項目1行
CFID場合分け
CFID場合分け
2016/5/15 第10回redmine.tokyo 勉強会 Redminekカスタムフィールド表示改善 @y503unavailable 17
18. custom_fields_helper.rb 追加分
(編集画面の共通処理追加)
# modified from custom_field_label_tag
# remove label tag , field name BOLD tag
def custom_field_nolabel_tag(name, custom_value,
options={})
required = options[:required] ||
custom_value.custom_field.is_required?
title = custom_value.custom_field.description.presence
content = content_tag 'span',
custom_value.custom_field.name, :title => title
content_required= (required ? " <span
class="required">*</span>".html_safe : "")
"<B>"+content + "</B>" + content_required
end
# Return custom field tag with its label, p tag exclude
# Top <p><label -> <label
# Buttom </p> -> None
def custom_field_tag_with_label_nopre(name,
custom_value, options={})
tag_org=(custom_field_label_tag(name, custom_value,
options) + custom_field_tag(name, custom_value)).strip
tag_org.sub(/A<p>/,'').sub(/</p>Z/,'').html_safe
end
# Return custom field tag with its label, p tag exclude
# Top <p><label -> None
# Buttom </p> -> None
# label tag -> None
def custom_field_tag_without_label_nopre(name,
custom_value, options={})
tag_org=(custom_field_nolabel_tag(name, custom_value,
options) + custom_field_tag(name, custom_value)).strip
tag_org.sub(/A<p>/,'').sub(/</p>Z/,'').html_safe
• end
2016/5/15 第10回redmine.tokyo 勉強会 Redminekカスタムフィールド表示改善 @y503unavailable 18
19. issues_helper.rb 追加分(1)
(表示画面のHTML出力)
# modified from render_custom_fields_rows
def render_custom_fields_rows_example(issue)
return if issue.custom_field_values.empty?
# HTML出力文字列の生成(1列化)
s = ""
issue.custom_field_values.compact.each do |value|
css = "cf_#{value.custom_field.id}"
case value.custom_field_id
when 4
s << "n<hr>n"
s << "<tr>nt<th><h2>障害現象
</h2></th><td></td>n</tr>n"
when 3
s << "n<hr>n"
s << "<tr>nt<th><h2>原因
</h2></th><td></td>n</tr>n"
when 10
s << "n<hr>n"
s << "<tr>nt<th><h2>処置
</h2></th><td></td>n</tr>n"
end
case value.custom_field_id
when 4,6,3
# 編集では <p><%=
custom_field_tag_with_label_nopre :issue, value %>
# 1列目(2列目あり)
# 表の行を終わらせない
s <<
"<tr>nt<th><b>#{ h(value.custom_field.name) }</b>:
"
s << "</th>"
s <<
"<td>#{ simple_format_without_paragraph(h(show_value(
value))) } "
2016/5/15 第10回redmine.tokyo 勉強会 Redminekカスタムフィールド表示改善 @y503unavailable 19
20. issues_helper.rb 追加分(2)
(表示画面のHTML出力)
when 13,2,8
# 編集では <%=
custom_field_tag_without_label_nopre :issue,
value %></p>
# 最終列(2列目以降で)
# <td>後の途中から始まるth,tdはSP2つで代替
# 最終列なので</td>以降は変化無し
s << "、<b>#{ h(value.custom_field.name) }</b>:"
s << " "
s <<
"#{ simple_format_without_paragraph(h(show_value(value
))) }</td>n</tr><br>"
when 5,1,7
# 編集では <%=
custom_field_tag_without_label_nopre :issue, value %>
# 3列以上の途中
# <td>後の途中から始まるth,tdはSP2つで代替
# 最終列ではないので</td>以降も省略する。
s << "、<b>#{ h(value.custom_field.name) }</b>:"
s << " "
s <<
"#{ simple_format_without_paragraph(h(show_value(value
))) } "
else
# 編集では <p> <%=
custom_field_tag_with_label :issue, value %> </p>
# 1列のみ項目-オリジナルを基にした。(CSS対応含む)
s << "<tr>n"
s << "t<th
class="#{css}"><b>#{ h(value.custom_field.name) }</
b>:</th><td
class="#{css}">#{ h(show_value(value)) }</td><br>"
end
end
s.html_safe
end
2016/5/15 第10回redmine.tokyo 勉強会 Redminekカスタムフィールド表示改善 @y503unavailable 20