Project

General

Profile

Feature #26409 » show_assignee_on_gantt_v3.patch

Mizuki ISHIKAWA, 2017-11-27 03:25

View differences:

app/models/issue_query.rb
73 73
    options[:draw_progress_line] = (arg == '1' ? '1' : nil)
74 74
  end
75 75

  
76
  def draw_assigned_to_names
77
    r = options[:draw_assigned_to_names]
78
    r == '1'
79
  end
80

  
81
  def draw_assigned_to_names=(arg)
82
    options[:draw_assigned_to_names] = (arg == '1' ? '1' : nil)
83
  end
84

  
76 85
  def build_from_params(params, defaults={})
77 86
    super
78 87
    self.draw_relations = params[:draw_relations] || (params[:query] && params[:query][:draw_relations])
79 88
    self.draw_progress_line = params[:draw_progress_line] || (params[:query] && params[:query][:draw_progress_line])
89
    self.draw_assigned_to_names = params[:draw_assigned_to_names] || (params[:query] && params[:query][:draw_assigned_to_names])
80 90
    self
81 91
  end
82 92

  
app/views/gantts/show.html.erb
53 53
              </label>
54 54
            </fieldset>
55 55
          </td>
56
          <td>
57
            <fieldset>
58
              <legend><%= l(:field_assigned_to) %></legend>
59
              <label for="draw_assigned_to_names">
60
                <%= check_box 'query', 'draw_assigned_to_names', :id => 'draw_assigned_to_names' %>
61
                <%= l(:label_display) %>
62
              </label>
63
            </fieldset>
64
          </td>
56 65
        </tr>
57 66
      </table>
58 67
    </div>
......
92 101

  
93 102
  subject_width = 330
94 103
  header_height = 18
104
  assigned_to_width = 100
95 105

  
96 106
  headers_height = header_height
97 107
  show_weeks = false
......
125 135
  <p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p>
126 136
<% end %>
127 137

  
128
<table style="width:100%; border:0; border-collapse: collapse;">
138
<table style="width:100%; border:0; border-collapse: collapse;", class="gantt_container">
129 139
<tr>
130 140
<td style="width:<%= subject_width %>px; padding:0px;" class="gantt_subjects_column">
131 141
  <%
......
157 167
    <% end %>
158 168
  <% end %>
159 169
</td>
160

  
170
<td style="width:<%= assigned_to_width %>px; padding:0px; display:none;" class="gantt_assigned_to_names_column">
171
  <%
172
    style  = ""
173
    style += "position:relative;"
174
    style += "height: #{t_height + 24}px;"
175
    style += "width: #{assigned_to_width + 1}px;"
176
  %>
177
  <%= content_tag(:div, :style => style, :class => "gantt_assigned_to_names_container") do %>
178
    <%
179
      style  = ""
180
      style += "width: #{assigned_to_width}px;"
181
      style += "height: #{headers_height}px;"
182
      style += 'background: #eee;'
183
    %>
184
    <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %>
185
    <%
186
      style  = ""
187
      style += "width: #{assigned_to_width}px;"
188
      style += "height: #{t_height}px;"
189
      style += 'border-left: 1px solid #c0c0c0;'
190
      style += 'overflow: hidden;'
191
    %>
192
    <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %>
193
    <%= content_tag(:div, :class => "gantt_assigned_to_names") do %>
194
      <%= @gantt.assigned_to_names.html_safe %>
195
    <% end %>
196
  <% end %>
197
</td>
161 198
<td>
162 199
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;" id="gantt_area">
163 200
<%
......
374 411
  $(function() {
375 412
    drawGanttHandler();
376 413
    resizableSubjectColumn();
377
    $("#draw_relations").change(drawGanttHandler);
378
    $("#draw_progress_line").change(drawGanttHandler);
414
    $("#draw_relations, #draw_progress_line, #draw_assigned_to_names").change(drawGanttHandler);
379 415
  });
380 416
  $(window).resize(function() {
381 417
    drawGanttHandler();
app/views/queries/_form.html.erb
42 42
  <p><label><%= l(:button_show) %></label>
43 43
  <label class="inline"><%= check_box_tag "query[draw_relations]", "1", @query.draw_relations %> <%= l(:label_related_issues) %></label>
44 44
  <label class="inline"><%= check_box_tag "query[draw_progress_line]", "1", @query.draw_progress_line %> <%= l(:label_gantt_progress_line) %></label>
45
  <label class="inline"><%= check_box_tag "query[draw_assigned_to_names]", "1", @query.draw_assigned_to_names %> <%= l(:label_gantt_assigned_to_names) %></label>
45 46
  </p>
46 47
</fieldset>
47 48
<% end %>
lib/redmine/helpers/gantt.rb
76 76
        @date_to = (@date_from >> @months) - 1
77 77
        @subjects = ''
78 78
        @lines = ''
79
        @assigned_to_names = ''
79 80
        @number_of_rows = nil
80 81
        @truncated = false
81 82
        if options.has_key?(:max_rows)
......
135 136
        @lines
136 137
      end
137 138

  
139
      # Renders the assigned_to_names of the Gantt chart, the right side of subjects.
140
      def assigned_to_names(options={})
141
        render(options.merge(:only => :assigned_to_names)) unless @assigned_to_names_rendered
142
        @assigned_to_names
143
      end
144

  
138 145
      # Returns issues that will be rendered
139 146
      def issues
140 147
        @issues ||= @query.issues(
......
196 203
                   :indent_increment => 20, :render => :subject,
197 204
                   :format => :html}.merge(options)
198 205
        indent = options[:indent] || 4
199
        @subjects = '' unless options[:only] == :lines
200
        @lines = '' unless options[:only] == :subjects
206
        @subjects = '' unless options[:only] == :lines || options[:only] == :assigned_to_names
207
        @lines = '' unless options[:only] == :subjects || options[:only] == :assigned_to_names
208
        @assigned_to_names = '' unless options[:only] == :lines || options[:only] == :subjects
201 209
        @number_of_rows = 0
202 210
        begin
203 211
          Project.project_tree(projects) do |project, level|
......
207 215
        rescue MaxLinesLimitReached
208 216
          @truncated = true
209 217
        end
210
        @subjects_rendered = true unless options[:only] == :lines
211
        @lines_rendered = true unless options[:only] == :subjects
218
        @subjects_rendered = true unless options[:only] == :lines || options[:only] == :assigned_to_names
219
        @lines_rendered = true unless options[:only] == :subjects || options[:only] == :assigned_to_names
220
        @assigned_to_names_rendered = true unless options[:only] == :lines || options[:only] == :subjects
212 221
        render_end(options)
213 222
      end
214 223

  
......
254 263

  
255 264
      def render_object_row(object, options)
256 265
        class_name = object.class.name.downcase
257
        send("subject_for_#{class_name}", object, options) unless options[:only] == :lines
258
        send("line_for_#{class_name}", object, options) unless options[:only] == :subjects
266
        send("subject_for_#{class_name}", object, options) unless options[:only] == :lines || options[:only] == :assigned_to_names
267
        send("line_for_#{class_name}", object, options) unless options[:only] == :subjects || options[:only] == :assigned_to_names
268
        assigned_to_name(object, options) unless options[:only] == :lines || options[:only] == :subjects
259 269
        options[:top] += options[:top_increment]
260 270
        @number_of_rows += 1
261 271
        if @max_rows && @number_of_rows >= @max_rows
......
323 333
        end
324 334
      end
325 335

  
336
      def assigned_to_name(issue, options)
337
        if issue.is_a?(Issue) && options[:format] == :html && issue.assigned_to.present?
338
          style = "position: absolute;top: #{options[:top]}px;"
339
          content = view.avatar(issue.assigned_to,
340
                                 :class => 'gravatar icon-gravatar',
341
                                 :size => 13) + view.link_to_user(issue.assigned_to)
342
          assigned_to_name = view.content_tag(:div, content.html_safe, :style => style, :class => 'issue-assigned-name')
343
          @assigned_to_names << assigned_to_name
344
          assigned_to_name
345
        end
346
      end
347

  
326 348
      def subject(label, options, object=nil)
327 349
        send "#{options[:format]}_subject", options, label, object
328 350
      end
public/javascripts/gantt.js
161 161
  }
162 162
}
163 163

  
164
function drawAssignedToNames(){
165
  if ($("#draw_assigned_to_names").prop('checked')){
166
    $('td.gantt_assigned_to_names_column').show();
167
    $('td.gantt_assigned_to_names_column').resizable({
168
      alsoResize: ".gantt_assigned_to_names_container, .gantt_assigned_to_names_container>.gantt_hdr, .issue-assigned-name",
169
      minWidth: 20,
170
      handles: "e",
171
      containment: "#content",
172
      create: function( event, ui ) {
173
        $(".ui-resizable-e").css("cursor","ew-resize");
174
      }
175
    }).on('resize', function (e) {
176
        e.stopPropagation();
177
    });
178
    if(isMobile()) {
179
      var width = Math.round($('.gantt_container').width()*0.15)
180
      $('.gantt_assigned_to_names_container>.gantt_hdr').width(width-2);
181
      $('.gantt_assigned_to_names_container, .gantt_assigned_to_names_column').width(width);
182
      $('.issue-assigned-name').each(function(){
183
        $(this).width($(".gantt_assigned_to_names_column").width());
184
      });
185
      $('td.gantt_assigned_to_names_column').resizable('disable');
186
    }else{
187
      $('td.gantt_assigned_to_names_column').resizable('enable');
188
    };
189
  }else{
190
    $('td.gantt_assigned_to_names_column').hide();
191
  }
192
}
193

  
164 194
function drawGanttHandler() {
165 195
  var folder = document.getElementById('gantt_draw_area');
166 196
  if(draw_gantt != null)
......
168 198
  else
169 199
    draw_gantt = Raphael(folder);
170 200
  setDrawArea();
201
  drawAssignedToNames();
171 202
  if ($("#draw_progress_line").prop('checked'))
172 203
    drawGanttProgressLines();
173 204
  if ($("#draw_relations").prop('checked'))
public/stylesheets/application.css
1163 1163

  
1164 1164
.gantt_hdr.nwday {background-color:#f1f1f1; color:#999;}
1165 1165

  
1166
.gantt_subjects { font-size: 0.8em; }
1167
.gantt_subjects div { line-height:16px;height:16px;overflow:hidden;white-space:nowrap;text-overflow: ellipsis; }
1166
.gantt_subjects, .issue-assigned-name { font-size: 0.8em; }
1167
.gantt_subjects div, .issue-assigned-name { line-height:16px;height:16px;overflow:hidden;white-space:nowrap;text-overflow: ellipsis; }
1168 1168
.gantt_subjects div.issue-subject:hover { background-color:#ffffdd; }
1169
.issue-assigned-name { padding: 0px 3px; width: 100px; }
1169 1170

  
1170
.gantt_subjects .issue-subject img.icon-gravatar {
1171
.gantt_subjects .issue-subject img.icon-gravatar, .issue-assigned-name img.icon-gravatar {
1171 1172
  margin: 2px 5px 0px 2px;
1172 1173
}
1173 1174

  
public/stylesheets/responsive.css
693 693
   * [4] maintain width due to [3]
694 694
   */
695 695
  .gantt_subjects_column {
696
    width: 60% !important; /* [1] */
696
    width: 50% !important; /* [1] */
697 697
  }
698 698

  
699 699
  .gantt_subjects_container {
......
843 843

  
844 844
  #login-form {width:100%; margin-top:2em;}
845 845
}
846

  
test/functional/queries_controller_test.rb
283 283
          :query => {
284 284
            :name => "test_create_from_gantt",
285 285
            :draw_relations => '1',
286
            :draw_progress_line => '1'
286
            :draw_progress_line => '1',
287
            :draw_assigned_to_names => '1'
287 288
          }
288 289
        }
289 290
      assert_response 302
......
292 293
    assert_redirected_to "/issues/gantt?query_id=#{query.id}"
293 294
    assert_equal true, query.draw_relations
294 295
    assert_equal true, query.draw_progress_line
296
    assert_equal true, query.draw_assigned_to_names
295 297
  end
296 298

  
297 299
  def test_create_project_query_from_gantt
......
309 311
          :query => {
310 312
            :name => "test_create_from_gantt",
311 313
            :draw_relations => '0',
312
            :draw_progress_line => '0'
314
            :draw_progress_line => '0',
315
            :draw_assigned_to_names => '0'
313 316
          }
314 317
        }
315 318
      assert_response 302
......
318 321
    assert_redirected_to "/projects/ecookbook/issues/gantt?query_id=#{query.id}"
319 322
    assert_equal false, query.draw_relations
320 323
    assert_equal false, query.draw_progress_line
324
    assert_equal false, query.draw_assigned_to_names
321 325
  end
322 326

  
323 327
  def test_create_project_public_query_should_force_private_without_manage_public_queries_permission
test/unit/lib/redmine/helpers/gantt_test.rb
237 237
    assert_select "div.tooltip", /#{@issue.subject}/
238 238
  end
239 239

  
240
  test "#assigned_to_names" do
241
    create_gantt
242
    issue = Issue.generate!
243
    issue.update(:assigned_to_id => issue.assignable_users.first.id)
244
    @project.issues << issue
245
    @output_buffer = @gantt.assigned_to_names(:format => :html)
246

  
247
    assert_select "div.issue-assigned-name span", /#{issue.assigned_to.name}/
248
  end
249

  
240 250
  test "#subject_for_project" do
241 251
    create_gantt
242 252
    @output_buffer = @gantt.subject_for_project(@project, :format => :html)
......
418 428
    assert_select "div.label", :text => 'line'
419 429
  end
420 430

  
431
  test "#assigned_to_name" do
432
    create_gantt
433
    options = {:top => 64, :format => :html}
434
    issue = Issue.generate!
435
    issue.assigned_to_id = issue.assignable_users.first.id
436
    @output_buffer = @gantt.assigned_to_name(issue, options)
437

  
438
    assert_select 'div.issue-assigned-name[style*="position: absolute;top: 64px;"]' do
439
      assert_select 'span', issue.assigned_to.name
440
    end
441
  end
442

  
421 443
  def test_sort_issues_no_date
422 444
    project = Project.generate!
423 445
    issue1 = Issue.generate!(:subject => "test", :project => project)
(4-4/4)