Project

General

Profile

Patch #30919 » GCF-3.4-final1.patch

Frederico Camara, 2019-03-01 17:22

View differences:

app/controllers/projects_controller.rb
178 178
    @version_name = params[:version_name]
179 179
    @versions = @project.shared_versions.status(@version_status).like(@version_name)
180 180
    @wiki ||= @project.wiki || Wiki.new(:project => @project)
181
    @cfs=AttributeGroup.joins(:custom_fields).joins(:tracker).
182
      where(project_id: @project, tracker_id: @trackers, :custom_fields => {id: @project.all_issue_custom_fields.pluck(:id)}).
183
      pluck("trackers.id", "id", "name", "position","attribute_group_fields.id", "attribute_group_fields.position",
184
            "custom_fields.id", "custom_fields.name", "custom_fields.position").sort_by{|x| [x[3], x[5]]}
181 185
  end
182 186

  
183 187
  def edit
......
210 214
    redirect_to settings_project_path(@project, :tab => 'modules')
211 215
  end
212 216

  
217
  def groupissuescustomfields
218
    # clean invalid values: invalid cfs, empty cf lists, empty groups
219
    group_issues_custom_fields = (JSON.parse params[:group_issues_custom_fields]).
220
      each{|tid,v| v.replace(v.select{|k,v| v["cfs"] ? v["cfs"].delete_if{|k,v| @project.all_issue_custom_fields.pluck(:id).include?(v)} : v})}.
221
      each{|tid,v| v.delete_if{|k,v| v["cfs"].blank?}}.
222
      delete_if{|k,v| v.blank?}
223

  
224
    groups = AttributeGroup.where(project_id: @project.id).collect(&:id)
225
    fields = AttributeGroupField.where(attribute_group_id: groups).collect(&:id) 
226
    group_issues_custom_fields.each do |tid,v|
227
      v.each do |gp, g|
228
        gid = groups.shift
229
        if gid.nil?
230
          gid=AttributeGroup.create(project_id: @project.id, tracker_id: tid, name: g["name"].nil? ? nil : g["name"], position: gp).id
231
        else
232
          AttributeGroup.update(gid, project_id: @project.id, tracker_id: tid, name: g["name"].nil? ? nil : g["name"], position: gp)
233
        end
234
        g['cfs'].each do |cfp, cf|
235
          cfid = fields.shift
236
          if cfid.nil?
237
            AttributeGroupField.create(attribute_group_id: gid, custom_field_id: cf, position: cfp)
238
          else
239
            AttributeGroupField.update(cfid, attribute_group_id: gid, custom_field_id: cf, position: cfp)
240
          end
241
        end
242
      end
243
    end
244
    AttributeGroupField.where(id: fields).delete_all
245
    AttributeGroup.where(id: groups).destroy_all
246
    flash[:notice] = l(:notice_successful_update)
247
    redirect_to settings_project_path(@project, :tab => 'groupissuescustomfields')
248
  end
249

  
213 250
  def archive
214 251
    unless @project.archive
215 252
      flash[:error] = l(:error_can_not_archive_project)
app/helpers/issues_helper.rb
239 239
    r.to_html
240 240
  end
241 241

  
242
  def render_half_width_custom_fields_rows(issue)
243
    values = issue.visible_custom_field_values.reject {|value| value.custom_field.full_width_layout?}
244
    return if values.empty?
245
    half = (values.size / 2.0).ceil
246
    issue_fields_rows do |rows|
247
      values.each_with_index do |value, i|
248
        css = "cf_#{value.custom_field.id}"
249
        attr_value = show_value(value)
250
        if value.custom_field.text_formatting == 'full'
251
          attr_value = content_tag('div', attr_value, class: 'wiki')
252
        end
253
        m = (i < half ? :left : :right)
254
        rows.send m, custom_field_name_tag(value.custom_field), attr_value, :class => css
255
      end
256
    end
242
  def group_by_keys(project_id, tracker_id, custom_field_values)
243
    keys_grouped = AttributeGroupField.joins(:attribute_group).
244
      where(:attribute_groups => {project_id: project_id, tracker_id: tracker_id}).
245
      order("attribute_groups.position", :position).pluck(:name, :custom_field_id).group_by(&:shift)
246
    custom_fields_grouped = { nil => (keys_grouped[nil].nil? ? [] : keys_grouped[nil].map{|n| custom_field_values.select{|x| x.custom_field[:id] == n[0]}}.flatten) |
247
      custom_field_values.select{|y| ! keys_grouped.values.flatten.include?(y.custom_field[:id])}}
248
    keys_grouped.reject{|k,v| k == nil}.each{|k,v| custom_fields_grouped[k] = v.map{|n| custom_field_values.select{|x| x.custom_field[:id] == n[0]}}.flatten}
249
    custom_fields_grouped
257 250
  end
258 251

  
259
  def render_full_width_custom_fields_rows(issue)
260
    values = issue.visible_custom_field_values.select {|value| value.custom_field.full_width_layout?}
261
    return if values.empty?
262

  
252
  def render_custom_fields_rows(issue)
263 253
    s = ''.html_safe
264
    values.each_with_index do |value, i|
265
      attr_value = show_value(value)
266
      next if attr_value.blank?
267

  
268
      if value.custom_field.text_formatting == 'full'
269
        attr_value = content_tag('div', attr_value, class: 'wiki')
254
    group_by_keys(issue.project_id, issue.tracker_id, issue.visible_custom_field_values).each do |title, values|
255
      if values.present?
256
        s += content_tag('h4', title, :style => 'background: #0001; padding: 0.3em;') unless title.nil?
257
        while values.present?
258
          if values[0].custom_field.full_width_layout?
259
            while values.present? && values[0].custom_field.full_width_layout?
260
              value=values.shift
261
              attr_value = show_value(value)
262
              if value.custom_field.text_formatting == 'full'
263
                attr_value = content_tag('div', attr_value, class: 'wiki')
264
              end
265
              content = content_tag('div', custom_field_name_tag(value.custom_field) + ":", :class => 'label') +
266
                        content_tag('div', attr_value, :class => 'value')
267
              content = content_tag('div', content, :class => "cf_#{value.custom_field.id} attribute")
268
              s += content_tag('div', content, :class => 'splitcontent')
269
            end
270
          else
271
            lr_values = []
272
            while values.present? && ! values[0].custom_field.full_width_layout?
273
              lr_values += [ values.shift ]
274
            end
275
            half = (lr_values.size / 2.0).ceil
276
            s += issue_fields_rows do |rows|
277
              lr_values.each_with_index do |value, i|
278
                attr_value = show_value(value)
279
                if value.custom_field.text_formatting == 'full'
280
                  attr_value = content_tag('div', attr_value, class: 'wiki')
281
                end
282
                m = (i < half ? :left : :right)
283
                rows.send m, custom_field_name_tag(value.custom_field), attr_value, :class => "cf_#{value.custom_field.id}" 
284
              end
285
            end
286
          end
287
        end
270 288
      end
271

  
272
      content =
273
          content_tag('hr') +
274
          content_tag('p', content_tag('strong', custom_field_name_tag(value.custom_field) )) +
275
          content_tag('div', attr_value, class: 'value')
276
      s << content_tag('div', content, class: "cf_#{value.custom_field.id} attribute")
277 289
    end
278 290
    s
279 291
  end
......
332 344
        end
333 345
      end
334 346
    end
335
    issue.visible_custom_field_values(user).each do |value|
336
      if html
337
        items << content_tag('strong', "#{value.custom_field.name}: ") + show_value(value, false)
338
      else
339
        items << "#{value.custom_field.name}: #{show_value(value, false)}"
347
    group_by_keys(issue.project_id, issue.tracker_id, issue.visible_custom_field_values(user)).each do |title, values|
348
      if values.present?
349
        item = [ (html ? content_tag('strong', "#{title}") : "#{title}") ] unless title.nil?
350
        values.each do |value|
351
          (title.nil? ? items : item) << (html ?
352
            content_tag('strong', "#{value.custom_field.name}: ") + show_value(value, false) :
353
            "#{value.custom_field.name}: #{show_value(value, false)}")
354
        end
355
        items << item unless title.nil?
340 356
      end
341 357
    end
342 358
    items
......
345 361
  def render_email_issue_attributes(issue, user, html=false)
346 362
    items = email_issue_attributes(issue, user, html)
347 363
    if html
348
      content_tag('ul', items.map{|s| content_tag('li', s)}.join("\n").html_safe, :class => "details")
364
      content_tag('ul', items.select{|s| s.is_a? String}.map{|s| content_tag('li', s)}.join("\n").html_safe, :class => "details") + "\n" +
365
        items.select{|s| !s.is_a? String}.map{|item| content_tag('div', item.shift) + "\n" +
366
        content_tag('ul', item.map{|s| content_tag('li', s)}.join("\n").html_safe, :class => "details")}.join("\n").html_safe
349 367
    else
350
      items.map{|s| "* #{s}"}.join("\n")
368
      items.select{|s| s.is_a? String}.map{|s| "* #{s}"}.join("\n") + "\n" +
369
      items.select{|s| !s.is_a? String}.map{|item| "#{item.shift}\n" + item.map{|s| "* #{s}"}.join("\n")}.join("\n")
351 370
    end
352 371
  end
353 372

  
app/helpers/projects_helper.rb
28 28
            {:name => 'wiki', :action => :manage_wiki, :partial => 'projects/settings/wiki', :label => :label_wiki},
29 29
            {:name => 'repositories', :action => :manage_repository, :partial => 'projects/settings/repositories', :label => :label_repository_plural},
30 30
            {:name => 'boards', :action => :manage_boards, :partial => 'projects/settings/boards', :label => :label_board_plural},
31
            {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities}
31
            {:name => 'activities', :action => :manage_project_activities, :partial => 'projects/settings/activities', :label => :enumeration_activities},
32
            {:name => 'groupissuescustomfields', :action => :edit_project, :partial => 'projects/settings/groupissuescustomfields', :label => :grouped_cf}
32 33
            ]
33 34
    tabs.select {|tab| User.current.allowed_to?(tab[:action], @project)}
34 35
  end
app/models/attribute_group.rb
1
class AttributeGroup < ActiveRecord::Base
2
  belongs_to :project
3
  belongs_to :tracker
4
  has_many :attribute_group_fields, :dependent => :delete_all
5
  has_many :custom_fields, :through => :attribute_group_fields
6
  acts_as_list
7

  
8
  scope :sorted, lambda { order(:position) }
9
end
app/models/attribute_group_field.rb
1
class AttributeGroupField < ActiveRecord::Base
2
  belongs_to :attribute_group
3
  belongs_to :custom_field
4
  acts_as_list
5

  
6
  scope :sorted, lambda { order(:position) }
7
end
app/models/custom_field.rb
24 24
           :class_name => 'CustomFieldEnumeration',
25 25
           :dependent => :delete_all
26 26
  has_many :custom_values, :dependent => :delete_all
27
  has_many :attribute_group_fields, :dependent => :delete_all
27 28
  has_and_belongs_to_many :roles, :join_table => "#{table_name_prefix}custom_fields_roles#{table_name_suffix}", :foreign_key => "custom_field_id"
28 29
  acts_as_positioned
29 30
  serialize :possible_values
app/models/project.rb
51 51
  has_many :changesets, :through => :repository
52 52
  has_one :wiki, :dependent => :destroy
53 53
  # Custom field for the project issues
54
  has_many :attribute_groups, :dependent => :destroy
55
  has_many :attribute_group_fields, :through => :attribute_groups
54 56
  has_and_belongs_to_many :issue_custom_fields,
55 57
                          lambda {order(:position)},
56 58
                          :class_name => 'IssueCustomField',
app/models/tracker.rb
35 35
  end
36 36
  has_and_belongs_to_many :projects
37 37
  has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
38
  has_many :attribute_groups, :dependent => :destroy
39
  has_many :attribute_group_fields, :through => :attribute_groups
38 40
  acts_as_positioned
39 41

  
40 42
  attr_protected :fields_bits
app/views/issues/_form_custom_fields.html.erb
1
<% custom_field_values = @issue.editable_custom_field_values %>
2
<% custom_field_values_full_width = custom_field_values.select { |value| value.custom_field.full_width_layout? } %>
3
<% custom_field_values -= custom_field_values_full_width %>
4

  
5
<% if custom_field_values.present? %>
1
<% group_by_keys(@issue.project_id, @issue.tracker_id, @issue.editable_custom_field_values).each do |title,values| %>
2
<% if values.present? %>
3
<%= content_tag('h4', title, :style => 'background: #0001; padding: 0.3em;') unless title.nil? %>
4
<% while values.present? %>
6 5
<div class="splitcontent">
6
<% if values[0].custom_field.full_width_layout? %>
7
<% while values.present? && values[0].custom_field.full_width_layout? %>
8
<% value = values.shift %>
9
 <p><%= custom_field_tag_with_label :issue, value, :required => @issue.required_attribute?(value.custom_field_id) %></p>
10
<% end %>
11
<% else %>
12
<% lr_values = [] %>
13
<% while values.present? && ! values[0].custom_field.full_width_layout? %>
14
<% lr_values += [ values.shift ] %>
15
<% end %>
7 16
<div class="splitcontentleft">
8 17
<% i = 0 %>
9
<% split_on = (custom_field_values.size / 2.0).ceil - 1 %>
10
<% custom_field_values.each do |value| %>
11
  <p><%= custom_field_tag_with_label :issue, value, :required => @issue.required_attribute?(value.custom_field_id) %></p>
12
<% if i == split_on -%>
18
<% split_on = (lr_values.size / 2.0).ceil - 1 %>
19
<% lr_values.each do |value| %>
20
 <p><%= custom_field_tag_with_label :issue, value, :required => @issue.required_attribute?(value.custom_field_id) %></p>
21
<% if i == split_on %>
13 22
</div><div class="splitcontentright">
14
<% end -%>
15
<% i += 1 -%>
16
<% end -%>
23
<% end %>
24
<% i += 1 %>
25
<% end %>
17 26
</div>
27
<% end %>
18 28
</div>
19 29
<% end %>
20

  
21
<% custom_field_values_full_width.each do |value| %>
22
  <p><%= custom_field_tag_with_label :issue, value, :required => @issue.required_attribute?(value.custom_field_id) %></p>
30
<% end %>
23 31
<% end %>
app/views/issues/show.html.erb
71 71
    rows.right l(:label_spent_time), issue_spent_hours_details(@issue), :class => 'spent-time'
72 72
  end
73 73
end %>
74
<%= render_half_width_custom_fields_rows(@issue) %>
74
<%= render_custom_fields_rows(@issue) %>
75 75
<%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %>
76 76
</div>
77 77

  
......
92 92
<%= link_to_attachments @issue, :thumbnails => true %>
93 93
<% end -%>
94 94

  
95
<%= render_full_width_custom_fields_rows(@issue) %>
96

  
97 95
<%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %>
98 96

  
99 97
<% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %>
app/views/projects/settings/_groupissuescustomfields.html.erb
1
<p><%= select_tag "tracker_id", options_from_collection_for_select(@project.trackers.collect, "id", "name"), {:required => true, :onchange => "refresh_trackers(this);"} %><p>
2

  
3
<div id='custom_fields_form'>
4
  <% @project.trackers.each do |t| %>
5
  <div id='tracker_<%= t.id %>' class='tracker'>
6
    <span style="color: #888;"><%= l(:changed_cf_position) %></span>
7
    <ul class='sortable_items sortable_tracker-<%= t.id %> nil not_a_group'>
8
      <% @cfs.select{|x| x[0]==t.id && x[2]==nil}.each do |x| %>
9
      <li id="<%= x[6] %>" pos="<%= x[8] %>"><%= x[7] %></li>
10
      <% end %>
11
    </ul>
12
    <span style="color: #888;"><%= l(:global_cf_position) %></span>
13
    <ul class="sortable_items sortable_tracker-<%= t.id %> unsorted not_a_group">
14
      <% Issue.new(project_id: @project.id, tracker_id: t.id).custom_field_values.
15
           select{|x| ! @cfs.select{|c| c[0]==t.id}.map{|c| c[6]}.include?(x.custom_field_id)}.
16
           collect{|x| [x.custom_field.id, x.custom_field.name, x.custom_field.position]}.each do |x| %>
17
      <li id="<%= x[0] %>" pos="<%= x[2] %>"><%= x[1] %></li>
18
      <% end %>
19
    </ul>
20
    <span style="color: #888;"><%= l(:grouped_cf) %></span>
21
    <div class='sortable_groups groups_tracker-<%= t.id %>'>
22
      <% @cfs.select{|x| x[0]==t.id && x[2]!=nil}.map{|x| x[2]}.uniq.each do |g| %>
23
      <div class="sortable_group">
24
        <input type="text" value="<%= g %>" style="background: #ddf; padding: 5px; width: 360px"/>
25
        <img src="/images/delete.png" onclick="remove_label(this, 'tracker-<%= t.id %>');"/>
26
        <ul class='sortable_items sortable_tracker-<%= t.id %>'>
27
          <% @cfs.select{|x| x[0]==t.id && x[2]==g}.each do |x| %>
28
          <li id="<%= x[6] %>" pos="<%= x[8] %>"><%= x[7] %></li>
29
          <% end %>
30
        </ul>
31
      </div>
32
      <% end %>
33
      <div>
34
        <input type="text" value="" style="background: #ddf; padding: 5px; width: 370px"/>
35
        <img src="/images/add.png" style="" onclick="add_label(this, 'tracker-<%= t.id %>');"/>
36
      </div>
37
    </div>
38
  </div>
39
  <% end %>
40
<%= form_for @project, :url => { :action => 'groupissuescustomfields', :id => @project },
41
            :html => {:id => 'groupissuescustomfields-form',
42
                      :method => :post} do |f| %>
43

  
44
<%= hidden_field :group_issues_custom_fields, '', :id => 'group_issues_custom_fields', :name => 'group_issues_custom_fields' %>
45
<p><%= submit_tag l(:button_save), :onclick => "fill_json_data();" %></p>
46
<% end %>
47
</div>
48

  
49
<script>
50
function init_sortables(labelclass) {
51
  $( '.groups_' + labelclass ).sortable({
52
    items: 'div.sortable_group',
53
    connectWith: '.groups_' + labelclass,
54
    start: function(event, ui) {
55
      ui.placeholder.height(ui.item.height());
56
    },
57
    axis: 'y'
58
  });
59
  $( '.sortable_' + labelclass ).sortable({
60
    connectWith: '.sortable_' + labelclass,
61
    update: function(event, ui) {
62
      if (ui.item.parent().hasClass('unsorted')) {
63
        ui.item.parent().prepend(ui.item);
64
        ui.item.parent().children('li').each(function () {
65
          if (parseInt($(this).attr('pos')) < parseInt(ui.item.attr('pos'))) {
66
            ui.item.insertAfter(this);
67
          }
68
        });
69
      }
70
    },
71
    axis: 'y'
72
  }).disableSelection();
73
}
74
function refresh_trackers(tracker) {
75
  $('.tracker').hide();
76
  $('#tracker_' + tracker.value).show();
77
}
78
function add_label(label, labelclass) {
79
  var old_label = $(label), new_label = $(label).parent().clone();
80
  new_label.children().first().val('').trigger('change');
81
  old_label.attr('src','/images/delete.png').attr('onclick','remove_label(this, "' + labelclass + '");');
82
  old_label.prev().width('360px');
83
  old_label.parent().addClass('ui-sortable-handle sortable_group');
84
  old_label.parent().sortable({
85
    connectWith: '.groups_' + labelclass
86
  }).disableSelection();
87
  old_label.parent().append('<ul id="' + labelclass + '_" class="sortable_items sortable_' + labelclass + '"/>');
88
  old_label.next().sortable({
89
    connectWith: '.sortable_' + labelclass
90
  }).disableSelection();
91
  old_label.parent().parent().append(new_label);
92
}
93
function remove_label(label, labelclass) {
94
  $(label).next().children().each(function () {
95
    var item = this;
96
    $('.unsorted.sortable_' + labelclass).prepend(this);
97
    $('.unsorted.sortable_' + labelclass).children('li').each(function () {
98
      if (parseInt($(this).attr('pos')) < parseInt($(item).attr('pos'))) {
99
        $(item).insertAfter(this);
100
      }
101
    });
102
  });
103
  $(label).parent().hide();
104
}
105
function fill_json_data() {
106
  var r = {}, gp = 0, cp = 0;
107
  $('#custom_fields_form').children('div').each(function () {
108
    var tracker_id = this.id.split('_').pop();
109
    gp = 0, cp = 0;
110

  
111
    // Group 'nil'
112
    r[tracker_id] = {};
113
    r[tracker_id][++gp] = {'cfs': {}};
114
    $(this).children('.nil').children().each(function () {
115
      cp++;
116
      r[tracker_id][gp]['cfs'][cp] = this.id;
117
    });
118
    if (! r[tracker_id][gp]['cfs'][1]) { delete r[tracker_id][gp]; }
119
    $(this).children('.sortable_groups').children().each(function () {
120
      if ($(this).children('ul').length) {
121
        r[tracker_id][++gp] = {
122
          'name': $(this).children('input').val(),
123
          'cfs': {}
124
        };
125
        cp = 0;
126
        $(this).children('ul').children().each(function () {
127
          r[tracker_id][gp]['cfs'][++cp] = this.id;
128
        });
129
        if (! r[tracker_id][gp]['cfs'][1]) { r[tracker_id][gp] = ''; }
130
      }
131
    });
132
    if ( ! r[tracker_id] ) { r[tracker_id] = ''; }
133
  });
134
  console.log(r);
135
  $('#group_issues_custom_fields').val(JSON.stringify(r)); }
136
$('#tracker_id').change();
137
<% @project.trackers.each do |t| %>
138
init_sortables('tracker-<%= t.id %>');
139
<% end %>
140
</script>
config/locales/en.yml
1209 1209
  description_issue_category_reassign: Choose issue category
1210 1210
  description_wiki_subpages_reassign: Choose new parent page
1211 1211
  text_repository_identifier_info: 'Only lower case letters (a-z), numbers, dashes and underscores are allowed.<br />Once saved, the identifier cannot be changed.'
1212

  
1213
  grouped_cf: Grouped Custom Fields
1214
  global_cf_position: Global Custom Fields Position
1215
  changed_cf_position: Changed Custom Fields Position
config/locales/pt-BR.yml
1242 1242
  permission_view_news: Ver notícias
1243 1243
  label_no_preview_alternative_html: Visualização não disponível. Faça o %{link} do arquivo.
1244 1244
  label_no_preview_download: download
1245

  
1246
  grouped_cf: Agrupar campos personalizados
1247
  global_cf_position: Posição global de campos personalizados
1248
  changed_cf_position: Alterar posição de campos personalizados
config/routes.rb
108 108
    member do
109 109
      get 'settings(/:tab)', :action => 'settings', :as => 'settings'
110 110
      post 'modules'
111
      post 'groupissuescustomfields'
111 112
      post 'archive'
112 113
      post 'unarchive'
113 114
      post 'close'
db/migrate/20180913211420_create_attribute_groups.rb
1
class CreateAttributeGroups < ActiveRecord::Migration
2
  def change
3
    create_table :attribute_groups do |t|
4
      t.references :project, index: true, foreign_key: true
5
      t.references :tracker, index: true, foreign_key: true
6
      t.string :name
7
      t.integer :position, :default => 1, :null => false
8

  
9
      t.timestamps null: false
10
    end
11
  end
12
end
db/migrate/20180913212008_create_attribute_group_fields.rb
1
class CreateAttributeGroupFields < ActiveRecord::Migration
2
  def change
3
    create_table :attribute_group_fields do |t|
4
      t.references :attribute_group, index: true, foreign_key: true
5
      t.references :custom_field, index: true, foreign_key: true
6
      t.integer :position
7

  
8
      t.timestamps null: false
9
    end
10
  end
11
end
db/migrate/20190301162408_change_group_position_attributes.rb
1
class ChangeGroupPositionAttributes < ActiveRecord::Migration
2
  def change
3
    change_column_null :attribute_groups, :position, true
4
    change_column_default :attribute_groups, :position, nil
5
  end
6
end
lib/redmine.rb
78 78
  map.permission :view_project, {:projects => [:show], :activities => [:index]}, :public => true, :read => true
79 79
  map.permission :search_project, {:search => :index}, :public => true, :read => true
80 80
  map.permission :add_project, {:projects => [:new, :create]}, :require => :loggedin
81
  map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
81
  map.permission :edit_project, {:projects => [:settings, :edit, :update, :groupissuescustomfields]}, :require => :member
82 82
  map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true
83 83
  map.permission :select_project_modules, {:projects => :modules}, :require => :member
84 84
  map.permission :view_members, {:members => [:index, :show]}, :public => true, :read => true
lib/redmine/export/pdf/issues_pdf_helper.rb
45 45
          pdf.SetFontStyle('',8)
46 46
          pdf.RDMMultiCell(190, 5, "#{format_time(issue.created_on)} - #{issue.author}")
47 47
          pdf.ln
48
  
48

  
49 49
          left = []
50 50
          left << [l(:field_status), issue.status]
51 51
          left << [l(:field_priority), issue.priority]
52 52
          left << [l(:field_assigned_to), issue.assigned_to] unless issue.disabled_core_fields.include?('assigned_to_id')
53 53
          left << [l(:field_category), issue.category] unless issue.disabled_core_fields.include?('category_id')
54 54
          left << [l(:field_fixed_version), issue.fixed_version] unless issue.disabled_core_fields.include?('fixed_version_id')
55
  
55

  
56 56
          right = []
57 57
          right << [l(:field_start_date), format_date(issue.start_date)] unless issue.disabled_core_fields.include?('start_date')
58 58
          right << [l(:field_due_date), format_date(issue.due_date)] unless issue.disabled_core_fields.include?('due_date')
59 59
          right << [l(:field_done_ratio), "#{issue.done_ratio}%"] unless issue.disabled_core_fields.include?('done_ratio')
60 60
          right << [l(:field_estimated_hours), l_hours(issue.estimated_hours)] unless issue.disabled_core_fields.include?('estimated_hours')
61 61
          right << [l(:label_spent_time), l_hours(issue.total_spent_hours)] if User.current.allowed_to?(:view_time_entries, issue.project)
62
  
62

  
63 63
          rows = left.size > right.size ? left.size : right.size
64 64
          while left.size < rows
65 65
            left << nil
......
68 68
            right << nil
69 69
          end
70 70

  
71
          custom_field_values = issue.visible_custom_field_values.reject {|value| value.custom_field.full_width_layout?}
72
          half = (custom_field_values.size / 2.0).ceil
73
          custom_field_values.each_with_index do |custom_value, i|
74
            (i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value, false)]
75
          end
76
  
77 71
          if pdf.get_rtl
78 72
            border_first_top = 'RT'
79 73
            border_last_top  = 'LT'
......
85 79
            border_first = 'L'
86 80
            border_last  = 'R'
87 81
          end
88
  
82
          border_middle_top  = 'T'
83

  
89 84
          rows = left.size > right.size ? left.size : right.size
90 85
          rows.times do |i|
91 86
            heights = []
......
100 95
            item = right[i]
101 96
            heights << pdf.get_string_height(60, item ? item.last.to_s  : "")
102 97
            height = heights.max
103
  
98

  
104 99
            item = left[i]
105 100
            pdf.SetFontStyle('B',9)
106 101
            pdf.RDMMultiCell(35, height, item ? "#{item.first}:" : "", (i == 0 ? border_first_top : border_first), '', 0, 0)
107 102
            pdf.SetFontStyle('',9)
108
            pdf.RDMMultiCell(60, height, item ? item.last.to_s : "", (i == 0 ? border_last_top : border_last), '', 0, 0)
109
  
103
            pdf.RDMMultiCell(60, height, item ? item.last.to_s : "", (i == 0 ? border_middle_top : ""), '', 0, 0)
104

  
110 105
            item = right[i]
111 106
            pdf.SetFontStyle('B',9)
112
            pdf.RDMMultiCell(35, height, item ? "#{item.first}:" : "",  (i == 0 ? border_first_top : border_first), '', 0, 0)
107
            pdf.RDMMultiCell(35, height, item ? "#{item.first}:" : "",  (i == 0 ? border_middle_top : ""), '', 0, 0)
113 108
            pdf.SetFontStyle('',9)
114 109
            pdf.RDMMultiCell(60, height, item ? item.last.to_s : "", (i == 0 ? border_last_top : border_last), '', 0, 2)
115
  
110

  
116 111
            pdf.set_x(base_x)
117 112
          end
118
  
113

  
114
          group_by_keys(issue.project_id, issue.tracker_id, issue.visible_custom_field_values).each do |title, values|
115
            if values.present?
116
              unless title.nil?
117
                pdf.RDMCell(35+155, 5, title, "LRT", 1)
118
              end
119

  
120
              while values.present?
121
                if values[0].custom_field.full_width_layout?
122
                  while values.present? && values[0].custom_field.full_width_layout?
123
                    value = values.shift
124
                    pdf.SetFontStyle('B',9)
125
                    pdf.RDMCell(35, 5, "#{value.custom_field.name}:", 'L', 0)
126
                    pdf.SetFontStyle('',9)
127
                    pdf.RDMCell(155, 5, show_value(value, false).to_s, 'R', 1)
128
                  end
129
                else
130
                  lr_values = []
131
                  while values.present? && ! values[0].custom_field.full_width_layout?
132
                    lr_values += [ values.shift ]
133
                  end
134

  
135
                  half = (lr_values.size / 2.0).ceil
136
                  left = []
137
                  right = []
138
                  lr_values.each_with_index do |custom_value, i|
139
                    (i < half ? left : right) << [custom_value.custom_field.name, show_value(custom_value, false)]
140
                  end
141

  
142
                  rows = left.size > right.size ? left.size : right.size
143
                  rows.times do |i|
144
                    heights = []
145
                    pdf.SetFontStyle('B',9)
146
                    item = left[i]
147
                    heights << pdf.get_string_height(35, item ? "#{item.first}:" : "")
148
                    item = right[i]
149
                    heights << pdf.get_string_height(35, item ? "#{item.first}:" : "")
150
                    pdf.SetFontStyle('',9)
151
                    item = left[i]
152
                    heights << pdf.get_string_height(60, item ? item.last.to_s  : "")
153
                    item = right[i]
154
                    heights << pdf.get_string_height(60, item ? item.last.to_s  : "")
155
                    height = heights.max
156

  
157
                    item = left[i]
158
                    pdf.SetFontStyle('B',9)
159
                    pdf.RDMMultiCell(35, height, item ? "#{item.first}:" : "", border_first, '', 0, 0)
160
                    pdf.SetFontStyle('',9)
161
                    pdf.RDMMultiCell(60, height, item ? item.last.to_s : "", "", '', 0, 0)
162

  
163
                    item = right[i]
164
                    pdf.SetFontStyle('B',9)
165
                    pdf.RDMMultiCell(35, height, item ? "#{item.first}:" : "",  "", '', 0, 0)
166
                    pdf.SetFontStyle('',9)
167
                    pdf.RDMMultiCell(60, height, item ? item.last.to_s : "", border_last, '', 0, 2)
168

  
169
                    pdf.set_x(base_x)
170
                  end
171
                end
172
              end
173
            end
174
          end
175

  
119 176
          pdf.SetFontStyle('B',9)
120 177
          pdf.RDMCell(35+155, 5, l(:field_description), "LRT", 1)
121 178
          pdf.SetFontStyle('',9)
122
  
179

  
123 180
          # Set resize image scale
124 181
          pdf.set_image_scale(1.6)
125 182
          text = textilizable(issue, :description,
......
130 187
          )
131 188
          pdf.RDMwriteFormattedCell(35+155, 5, '', '', text, issue.attachments, "LRB")
132 189

  
133
          custom_field_values = issue.visible_custom_field_values.select {|value| value.custom_field.full_width_layout?}
134
          custom_field_values.each do |value|
135
            text = show_value(value, false)
136
            next if text.blank?
137

  
138
            pdf.SetFontStyle('B',9)
139
            pdf.RDMCell(35+155, 5, value.custom_field.name, "LRT", 1)
140
            pdf.SetFontStyle('',9)
141
            pdf.RDMwriteHTMLCell(35+155, 5, '', '', text, issue.attachments, "LRB")
142
          end
143

  
144 190
          unless issue.leaf?
145 191
            truncate_length = (!is_cjk? ? 90 : 65)
146 192
            pdf.SetFontStyle('B',9)
......
157 203
              pdf.ln
158 204
            end
159 205
          end
160
  
206

  
161 207
          relations = issue.relations.select { |r| r.other_issue(issue).visible? }
162 208
          unless relations.empty?
163 209
            truncate_length = (!is_cjk? ? 80 : 60)
......
185 231
          end
186 232
          pdf.RDMCell(190,5, "", "T")
187 233
          pdf.ln
188
  
234

  
189 235
          if issue.changesets.any? &&
190 236
               User.current.allowed_to?(:view_changesets, issue.project)
191 237
            pdf.SetFontStyle('B',9)
......
205 251
              pdf.ln
206 252
            end
207 253
          end
208
  
254

  
209 255
          if assoc[:journals].present?
210 256
            pdf.SetFontStyle('B',9)
211 257
            pdf.RDMCell(190,5, l(:label_history), "B")
......
234 280
              pdf.ln
235 281
            end
236 282
          end
237
  
283

  
238 284
          if issue.attachments.any?
239 285
            pdf.SetFontStyle('B',9)
240 286
            pdf.RDMCell(190,5, l(:label_attachment_plural), "B")
......
261 307
          pdf.footer_date = format_date(User.current.today)
262 308
          pdf.set_auto_page_break(false)
263 309
          pdf.add_page("L")
264
  
310

  
265 311
          # Landscape A4 = 210 x 297 mm
266 312
          page_height   = pdf.get_page_height # 210
267 313
          page_width    = pdf.get_page_width  # 297
......
269 315
          right_margin  = pdf.get_original_margins['right'] # 10
270 316
          bottom_margin = pdf.get_footer_margin
271 317
          row_height    = 4
272
  
318

  
273 319
          # column widths
274 320
          table_width = page_width - right_margin - left_margin
275 321
          col_width = []
......
277 323
            col_width = calc_col_width(issues, query, table_width, pdf)
278 324
            table_width = col_width.inject(0, :+)
279 325
          end
280
  
326

  
281 327
          # use full width if the description or last_notes are displayed
282 328
          if table_width > 0 && (query.has_column?(:description) || query.has_column?(:last_notes))
283 329
            col_width = col_width.map {|w| w * (page_width - right_margin - left_margin) / table_width}
284 330
            table_width = col_width.inject(0, :+)
285 331
          end
286
  
332

  
287 333
          # title
288 334
          pdf.SetFontStyle('B',11)
289 335
          pdf.RDMCell(190, 8, title)
......
317 363
              end
318 364
              previous_group = group
319 365
            end
320
  
366

  
321 367
            # fetch row values
322 368
            col_values = fetch_row_values(issue, query, level)
323
  
369

  
324 370
            # make new page if it doesn't fit on the current one
325 371
            base_y     = pdf.get_y
326 372
            max_height = get_issues_to_pdf_write_cells(pdf, col_values, col_width)
......
330 376
              render_table_header(pdf, query, col_width, row_height, table_width)
331 377
              base_y = pdf.get_y
332 378
            end
333
  
379

  
334 380
            # write the cells on page
335 381
            issues_to_pdf_write_cells(pdf, col_values, col_width, max_height)
336 382
            pdf.set_y(base_y + max_height)
337
  
383

  
338 384
            if query.has_column?(:description) && issue.description?
339 385
              pdf.set_x(10)
340 386
              pdf.set_auto_page_break(true, bottom_margin)
......
349 395
              pdf.set_auto_page_break(false)
350 396
          end
351 397
          end
352
  
398

  
353 399
          if issues.size == Setting.issues_export_limit.to_i
354 400
            pdf.SetFontStyle('B',10)
355 401
            pdf.RDMCell(0, row_height, '...')
public/stylesheets/application.css
459 459
div.issue span.private, div.journal span.private { position:relative; bottom: 2px; text-transform: uppercase; background: #d22; color: #fff; font-weight:bold; padding: 0px 2px 0px 2px; font-size: 60%; margin-right: 2px; border-radius: 2px;}
460 460
div.issue .next-prev-links {color:#999;}
461 461
div.issue .attributes {margin-top: 2em;}
462
div.issue .attributes .attribute {padding-left:180px; clear:left; min-height: 1.8em;}
463
div.issue .attributes .attribute .label {width: 170px; margin-left:-180px; font-weight:bold; float:left;  overflow:hidden; text-overflow: ellipsis;}
462
div.issue .attributes .attribute {padding-left:225px; clear:left; min-height: 1.8em;}
463
div.issue .attributes .attribute .label {width: 215px; margin-left:-225px; font-weight:bold; float:left; overflow:hidden; text-overflow: ellipsis;}
464 464
div.issue .attribute .value {overflow:auto; text-overflow: ellipsis;}
465
div.issue .attribute .value p {margin: 0 0 0.8em 0;}
465 466
div.issue.overdue .due-date .value { color: #c22; }
466 467

  
467 468
#issue_tree table.issues, #relations table.issues { border: 0; }
......
1499 1500
  height:1px;
1500 1501
  overflow:hidden;
1501 1502
}
1503

  
1504
/* Custom Field Groups */
1505
.sortable_groups {
1506
  background: #eee;
1507
  border: 1px solid #888;
1508
  width: 445px;
1509
  min-height: 30px;
1510
  margin: 5px;
1511
  padding: 5px;
1512
}
1513
.sortable_groups div {
1514
  background: #ddf;
1515
  border: 1px solid #888;
1516
  min-height: 30px;
1517
  margin: 5px;
1518
  padding: 5px;
1519
}
1520
.sortable_items {
1521
  background: #eee;
1522
  border: 1px solid #888;
1523
  width: 400px;
1524
  min-height: 30px;
1525
  margin: 5px;
1526
  padding: 5px;
1527
}
1528
.sortable_items li {
1529
  background: #ffffff;
1530
  border: 1px solid #888;
1531
  margin: 5px;
1532
  padding: 5px;
1533
  list-style-type: none;
1534
  font-size: 1.2em;
1535
}
1536
.not_a_group {
1537
  padding: 5px 27px;
1538
}
1539
.ui-sortable-handle:before {
1540
  content:url('/images/reorder.png');
1541
  margin-right: 5px;
1542
}
1543
.ui-sortable-placeholder {
1544
  background: #8888ff;
1545
  border: 1px solid #888;
1546
  visibility: visible;
1547
}
test/fixtures/attribute_group_fields.yml
1
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2

  
3
one:
4
  attribute_group_id: 
5
  custom_field_id: 
6
  position: 1
7

  
8
two:
9
  attribute_group_id: 
10
  custom_field_id: 
11
  position: 1
test/fixtures/attribute_groups.yml
1
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2

  
3
one:
4
  project_id: 
5
  tracker_id: 
6
  name: MyString
7
  position: 1
8

  
9
two:
10
  project_id: 
11
  tracker_id: 
12
  name: MyString
13
  position: 1
(11-11/24)