Project

General

Profile

Feature #12005 » workflow_hidden_field_v0.03.diff

# And, 2012-10-02 12:03

View differences:

app/helpers/issues_helper.rb (working copy)
135 135
  end
136 136

  
137 137
  def render_custom_fields_rows(issue)
138
    return if issue.custom_field_values.empty?
138
    local_viewablecf=issue.viewable_custom_field_values
139
    return if local_viewablecf.empty?
139 140
    ordered_values = []
140
    half = (issue.custom_field_values.size / 2.0).ceil
141
    half = (local_viewablecf.size / 2.0).ceil
141 142
    half.times do |i|
142
      ordered_values << issue.custom_field_values[i]
143
      ordered_values << issue.custom_field_values[i + half]
143
      ordered_values << local_viewablecf[i]
144
      ordered_values << local_viewablecf[i + half]
144 145
    end
145 146
    s = "<tr>\n"
146 147
    n = 0
app/helpers/workflows_helper.rb (working copy)
25 25
  def field_permission_tag(permissions, status, field)
26 26
    name = field.is_a?(CustomField) ? field.id.to_s : field
27 27
    options = [["", ""], [l(:label_readonly), "readonly"]]
28
    options << [l(:label_hidden), "hidden"] unless field_required?(field)
28 29
    options << [l(:label_required), "required"] unless field_required?(field)
29 30

  
30 31
    select_tag("permissions[#{name}][#{status.id}]", options_for_select(options, permissions[status.id][name]))
app/models/workflow_permission.rb (working copy)
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 17

  
18 18
class WorkflowPermission < WorkflowRule
19
  validates_inclusion_of :rule, :in => %w(readonly required)
19
  validates_inclusion_of :rule, :in => %w(readonly required hidden)
20 20
  validate :validate_field_name
21 21

  
22 22
  # Replaces the workflow permissions for the given tracker and role
23 23
  #
24 24
  # Example:
25
  #   WorkflowPermission.replace_permissions role, tracker, {'due_date' => {'1' => 'readonly', '2' => 'required'}}
25
  #   WorkflowPermission.replace_permissions role, tracker, {'due_date' => {'1' => 'readonly', '2' => 'required', '3' => 'hidden'}}
26 26
  def self.replace_permissions(tracker, role, permissions)
27 27
    destroy_all(:tracker_id => tracker.id, :role_id => role.id)
28 28

  
app/models/issue.rb (working copy)
416 416
    end
417 417
  end
418 418

  
419
  # Returns the custom_field_values that can be viewed by the given user
420
  # For now: just exclude Fix Info and RNs, as it is printed seperately below description.
421
  def viewable_custom_field_values(user=nil)
422
    custom_field_values.reject do |value|
423
      hidden_attribute_names(user).include?(value.custom_field_id.to_s)
424
    end
425
  end
426

  
419 427
  # Returns the names of attributes that are read-only for user or the current user
420 428
  # For users with multiple roles, the read-only fields are the intersection of
421 429
  # read-only fields of each role
......
428 436
    workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'readonly'}.keys
429 437
  end
430 438

  
439
  # Same as above, but for hidden fields
440
  def hidden_attribute_names(user=nil)
441
    workflow_rule_by_attribute(user).reject {|attr, rule| rule != 'hidden'}.keys
442
  end
443

  
431 444
  # Returns the names of required attributes for user or the current user
432 445
  # For users with multiple roles, the required fields are the intersection of
433 446
  # required fields of each role
......
445 458
    required_attribute_names(user).include?(name.to_s)
446 459
  end
447 460

  
461
  # Returns true if the attribute should be hidden for user
462
  def hidden_attribute?(name, user=nil)
463
    logger.info("For " + name.to_s + ", It will return " + hidden_attribute_names(user).include?(name.to_s).to_s )
464
    hidden_attribute_names(user).include?(name.to_s)
465
  end
466

  
448 467
  # Returns a hash of the workflow rule by attribute for the given user
449 468
  #
450 469
  # Examples:
app/views/issues/show.html.erb (working copy)
33 33

  
34 34
<table class="attributes">
35 35
<%= issue_fields_rows do |rows|
36
  rows.left l(:field_status), h(@issue.status.name), :class => 'status'
37
  rows.left l(:field_priority), h(@issue.priority.name), :class => 'priority'
36
  unless @issue.hidden_attribute?('status')
37
    rows.left l(:field_status), h(@issue.status.name), :class => 'status'
38
  end
39
  unless @issue.hidden_attribute?('priority')
40
    rows.left l(:field_priority), h(@issue.priority.name), :class => 'priority'
41
  end
38 42

  
39
  unless @issue.disabled_core_fields.include?('assigned_to_id')
43
  unless @issue.disabled_core_fields.include?('assigned_to_id') || @issue.hidden_attribute?('assigned_to_id')
40 44
    rows.left l(:field_assigned_to), avatar(@issue.assigned_to, :size => "14").to_s.html_safe + (@issue.assigned_to ? link_to_user(@issue.assigned_to) : "-"), :class => 'assigned-to'
41 45
  end
42
  unless @issue.disabled_core_fields.include?('category_id')
46
  unless @issue.disabled_core_fields.include?('category_id') || @issue.hidden_attribute?('category_id')
43 47
    rows.left l(:field_category), h(@issue.category ? @issue.category.name : "-"), :class => 'category'
44 48
  end
45
  unless @issue.disabled_core_fields.include?('fixed_version_id')
49
  unless @issue.disabled_core_fields.include?('fixed_version_id') || @issue.hidden_attribute?('fixed_version_id')
46 50
    rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version'
47 51
  end
48 52

  
49
  unless @issue.disabled_core_fields.include?('start_date')
53
  unless @issue.disabled_core_fields.include?('start_date') || @issue.hidden_attribute?('start_date')
50 54
    rows.right l(:field_start_date), format_date(@issue.start_date), :class => 'start-date'
51 55
  end
52
  unless @issue.disabled_core_fields.include?('due_date')
56
  unless @issue.disabled_core_fields.include?('due_date') || @issue.hidden_attribute?('due_date')
53 57
    rows.right l(:field_due_date), format_date(@issue.due_date), :class => 'due-date'
54 58
  end
55
  unless @issue.disabled_core_fields.include?('done_ratio')
59
  unless @issue.disabled_core_fields.include?('done_ratio') || @issue.hidden_attribute?('done_ratio')
56 60
    rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%"), :class => 'progress'
57 61
  end
58
  unless @issue.disabled_core_fields.include?('estimated_hours')
62
  unless @issue.disabled_core_fields.include?('estimated_hours') || @issue.hidden_attribute?('estimated_hours')
59 63
    unless @issue.estimated_hours.nil?
60 64
      rows.right l(:field_estimated_hours), l_hours(@issue.estimated_hours), :class => 'estimated-hours'
61 65
    end
app/views/issues/_form_custom_fields.html.erb (working copy)
1 1
<div class="splitcontent">
2 2
<div class="splitcontentleft">
3 3
<% i = 0 %>
4
<% split_on = (@issue.custom_field_values.size / 2.0).ceil - 1 %>
4
<% split_on = (@issue.editable_custom_field_values.size / 2.0).ceil - 1 %>
5 5
<% @issue.editable_custom_field_values.each do |value| %>
6 6
  <p><%= custom_field_tag_with_label :issue, value, :required => @issue.required_attribute?(value.custom_field_id) %></p>
7 7
<% if i == split_on -%>
config/locales/en.yml (working copy)
867 867
  label_fields_permissions: Fields permissions
868 868
  label_readonly: Read-only
869 869
  label_required: Required
870
  label_hidden: " Hidden "
870 871
  label_attribute_of_project: "Project's %{name}"
871 872
  label_attribute_of_author: "Author's %{name}"
872 873
  label_attribute_of_assigned_to: "Assignee's %{name}"
public/stylesheets/application.css (working copy)
442 442
table.fields_permissions select {font-size:90%}
443 443
table.fields_permissions td.readonly {background:#ddd;}
444 444
table.fields_permissions td.required {background:#d88;}
445
table.fields_permissions td.hidden {background:#6E6E6E;}
445 446

  
446 447
textarea#custom_field_possible_values {width: 99%}
447 448
input#content_comments {width: 99%}
(2-2/13)