Project

General

Profile

Feature #2096 » group-field.patch

Fri Flaj, 2010-03-05 16:51

View differences:

app/helpers/issues_helper.rb (working copy)
43 43
    n = 0
44 44
    ordered_values.compact.each do |value|
45 45
      s << "</tr>\n<tr>\n" if n > 0 && (n % 2) == 0
46
      s << "\t<th>#{ h(value.custom_field.name) }:</th><td>#{ simple_format_without_paragraph(h(show_value(value))) }</td>\n"
46
      s << "\t<th>#{ h(value.custom_field.name) }:</th><td>"
47
      s << value.custom_field.field_format == "group_list" ? show_value_on_view(value) : simple_format_without_paragraph(h(show_value(value)))
48
      s << "</td>\n"
47 49
      n += 1
48 50
    end
49 51
    s << "</tr>\n"
50
    s
52

  
53
    return s
51 54
  end
52 55
  
53 56
  def sidebar_queries
......
115 118
    
116 119
    unless no_html
117 120
      label = content_tag('strong', label)
118
      old_value = content_tag("i", h(old_value)) if detail.old_value
121

  
122
      if !custom_field.nil? && custom_field.field_format == 'group_list'
123
        old_value = content_tag("i", old_value) if detail.old_value
124
      else
125
        old_value = content_tag("i", h(old_value)) if detail.old_value
126
      end
127

  
119 128
      old_value = content_tag("strike", old_value) if detail.old_value and (!detail.value or detail.value.empty?)
129

  
120 130
      if detail.property == 'attachment' && !value.blank? && a = Attachment.find_by_id(detail.prop_key)
121 131
        # Link to the attachment if it has not been removed
122 132
        value = link_to_attachment(a)
133
      elsif !custom_field.nil? && custom_field.field_format == 'group_list'
134
        value = content_tag("i", value) if value
123 135
      else
124 136
        value = content_tag("i", h(value)) if value
125 137
      end
app/helpers/custom_fields_helper.rb (working copy)
49 49
                       (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') : 
50 50
                       '<option></option>'
51 51
      select_tag(field_name, blank_option + options_for_select(custom_field.possible_values, custom_value.value), :id => field_id)
52

  
53
    when 'group_list'
54
      groups = @project.principals
55
      groups.delete_if { |group| group.type != 'Group' }
56

  
57
      custom_field.possible_values.clear()
58
      groups.each { |group| custom_field.possible_values << group if group.type == 'Group' }
59

  
60
      blank_option = custom_field.is_required? ?
61
                        (custom_field.default_value.blank? ? "<option value=\"\">--- #{l(:actionview_instancetag_blank_option)} ---</option>" : '') : 
62
                        '<option></option>'
63

  
64
      select_tag(field_name, blank_option + options_for_select(groups.collect { |x| [x.lastname, x.id] }, custom_value.value), :id => field_id)
65

  
52 66
    else
53 67
      text_field_tag(field_name, custom_value.value, :id => field_id)
54 68
    end
......
101 115
      begin; format_date(value.to_date); rescue; value end
102 116
    when "bool"
103 117
      l(value == "1" ? :general_text_Yes : :general_text_No)
118
    when 'group_list':
119
      link_to_group(Group.find(:first, :conditions => [ 'id = ?', value]))
104 120
    else
105 121
      value
106 122
    end
......
110 126
  def custom_field_formats_for_select
111 127
    CustomField::FIELD_FORMATS.sort {|a,b| a[1][:order]<=>b[1][:order]}.collect { |k| [ l(k[1][:name]), k[0] ] }
112 128
  end
129

  
130
  # Return a string used to display a custom value on the issues view
131
  def format_value_for_view(value, field_format)
132
    return "-" unless value && !value.empty?
133

  
134
    case field_format
135
      when 'group_list'
136
        link_to_group(Group.find(:first, :conditions => [ 'id = ?', value]))
137
      else
138
        format_value(value, field_format)
139
    end
140
  end
141

  
142
  def show_value_on_view(custom_value)
143
    return "" unless custom_value
144
    format_value_for_view(custom_value.value, custom_value.custom_field.field_format)
145
  end
146

  
113 147
end
app/helpers/application_helper.rb (working copy)
58 58
    end
59 59
  end
60 60

  
61
  # Displays a link to the group
62
  def link_to_group(group, options={})
63
    if group.is_a?(Group)
64
      link_to group.lastname, :controller => 'groups', :action => 'show', :id => group
65
    else
66
      h(group.to_s)
67
    end
68
  end
69

  
61 70
  # Displays a link to +issue+ with its subject.
62 71
  # Examples:
63 72
  # 
app/models/issue.rb (working copy)
328 328
    # Author and assignee are always notified unless they have been locked
329 329
    notified << author if author && author.active?
330 330
    notified << assigned_to if assigned_to && assigned_to.active?
331

  
332
    ## EEH: TODO: add Group-email addresses here at some point
333

  
331 334
    notified.uniq!
332 335
    # Remove users that can not view the issue
333 336
    notified.reject! {|user| !visible?(user)}
app/models/custom_field.rb (working copy)
25 25
                    "int" => { :name => :label_integer, :order => 3 },
26 26
                    "float" => { :name => :label_float, :order => 4 },
27 27
                    "list" => { :name => :label_list, :order => 5 },
28
			        "date" => { :name => :label_date, :order => 6 },
29
			        "bool" => { :name => :label_boolean, :order => 7 }
28
                    "date" => { :name => :label_date, :order => 6 },
29
                    "bool" => { :name => :label_boolean, :order => 7 },
30
                    "group_list" => { :name => :label_group_list, :order => 8 },
30 31
  }.freeze
31 32

  
32 33
  validates_presence_of :name, :field_format
app/views/custom_fields/_form.rhtml (working copy)
20 20
      if (p_searchable) Element.show(p_searchable.parentNode);
21 21
      Element.show(p_values);
22 22
      break;
23

  
24
    case 'group_list':
25
      p_default.setAttribute('type','combolist');
26
      Element.hide(p_length.parentNode);
27
      Element.hide(p_regexp.parentNode);
28
      if (p_searchable) Element.show(p_searchable.parentNode);
29
      Element.hide(p_values);
30
      break;
31

  
23 32
    case "bool":
24 33
      p_default.setAttribute('type','checkbox');
25 34
      Element.hide(p_length.parentNode);
app/views/projects/show.rhtml (working copy)
16 16
  <% end %>
17 17
	<% @project.custom_values.each do |custom_value| %>
18 18
	<% if !custom_value.value.blank? %>
19
	   <li><%= custom_value.custom_field.name%>: <%=h show_value(custom_value) %></li>
19
       <li><%= custom_value.custom_field.name%>: <%= custom_value.custom_field.field_format == "group_list" ?  h(show_value_on_view(custom_value)) : h(show_value(custom_value)) %></li>
20 20
	<% end %>
21 21
	<% end %>
22 22
	</ul>	
config/locales/en.yml (working copy)
475 475
  label_and_its_subprojects: "{{value}} and its subprojects"
476 476
  label_min_max_length: Min - Max length
477 477
  label_list: List
478

  
479
  ## EEH: TODO: Translation
480
  label_group_list: Group List
481

  
478 482
  label_date: Date
479 483
  label_integer: Integer
480 484
  label_float: Float
(2-2/5)