show_assignee_on_gantt.patch

Mizuki ISHIKAWA, 2017-07-28 03:12

Download (14 KB)

View differences:

app/models/issue_query.rb
73 73
    options[:draw_progress_line] = (arg == '1' ? '1' : nil)
74 74
  end
75
  def draw_assigned_to_names
76
    r = options[:draw_assigned_to_names]
77
    r == '1'
78
  end
79

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

  
75 84
  def build_from_params(params, defaults={})
76 85
    super
77 86
    self.draw_relations = params[:draw_relations] || (params[:query] && params[:query][:draw_relations])
78 87
    self.draw_progress_line = params[:draw_progress_line] || (params[:query] && params[:query][:draw_progress_line])
88
    self.draw_assigned_to_names = params[:draw_assigned_to_names] || (params[:query] && params[:query][:draw_assigned_to_names])
79 89
    self
80 90
  end
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
  subject_width = 330
93 102
  header_height = 18
103
  assigned_to_width = 100
94 104
  headers_height = header_height
95 105
  show_weeks = false
......
125 135
  <p class="warning"><%= l(:notice_gantt_chart_truncated, :max => @gantt.max_rows) %></p>
126 136
<% end %>
127
<table style="width:100%; border:0; border-collapse: collapse;">
137
<table style="width:100%; border:0; border-collapse: collapse;", class="gantt_container">
128 138
<tr>
129 139
<td style="width:<%= subject_width %>px; padding:0px;" class="gantt_subjects_column">
130 140
  <%
......
155 165
    <% end %>
156 166
  <% end %>
157 167
</td>
158

  
168
<td style="width:<%= assigned_to_width %>px; padding:0px; display:none;" class="gantt_assigned_to_names_column">
169
  <%
170
    style  = ""
171
    style += "position:relative;"
172
    style += "height: #{t_height + 24}px;"
173
    style += "width: #{assigned_to_width + 1}px;"
174
  %>
175
  <%= content_tag(:div, :style => style, :class => "gantt_assigned_to_names_container") do %>
176
    <%
177
      style  = ""
178
      style += "width: #{assigned_to_width}px;"
179
      style += "height: #{headers_height}px;"
180
      style += 'background: #eee;'
181
    %>
182
    <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %>
183
    <%
184
      style  = ""
185
      style += "width: #{assigned_to_width}px;"
186
      style += "height: #{t_height}px;"
187
      style += 'border-left: 1px solid #c0c0c0;'
188
      style += 'overflow: hidden;'
189
    %>
190
    <%= content_tag(:div, "", :style => style, :class => "gantt_hdr") %>
191
    <%= content_tag(:div, :class => "gantt_assigned_to_names") do %>
192
      <%= @gantt.assigned_to_names.html_safe %>
193
    <% end %>
194
  <% end %>
195
</td>
159 196
<td>
160 197
<div style="position:relative;height:<%= t_height + 24 %>px;overflow:auto;" id="gantt_area">
161 198
<%
......
370 407
  $(function() {
371 408
    drawGanttHandler();
372 409
    resizableSubjectColumn();
373
    $("#draw_relations").change(drawGanttHandler);
374
    $("#draw_progress_line").change(drawGanttHandler);
410
    $("#draw_relations, #draw_progress_line, #draw_assigned_to_names").change(drawGanttHandler);
375 411
  });
376 412
  $(window).resize(function() {
377 413
    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
138
      # Renders the assigned_to_names of the Gantt chart, the right side of subjects.
139
      def assigned_to_names(options={})
140
        render(options.merge(:only => :assigned_to_names)) unless @assigned_to_names_rendered
141
        @assigned_to_names
142
      end
143

  
137 144
      # Returns issues that will be rendered
138 145
      def issues
139 146
        @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
......
254 263
      def render_object_row(object, options)
255 264
        class_name = object.class.name.downcase
256
        send("subject_for_#{class_name}", object, options) unless options[:only] == :lines
257
        send("line_for_#{class_name}", object, options) unless options[:only] == :subjects
265
        send("subject_for_#{class_name}", object, options) unless options[:only] == :lines || options[:only] == :assigned_to_names
266
        send("line_for_#{class_name}", object, options) unless options[:only] == :subjects || options[:only] == :assigned_to_names
267
        assigned_to_name(object, options) unless options[:only] == :lines || options[:only] == :subjects
258 268
        options[:top] += options[:top_increment]
259 269
        @number_of_rows += 1
260 270
        if @max_rows && @number_of_rows >= @max_rows
......
323 333
        end
324 334
      end
335
      def assigned_to_name(issue, options)
336
        if issue.is_a?(Issue) && options[:format] == :html && issue.assigned_to.present?
337
          style = "position: absolute;top: #{options[:top]}px;"
338
          assigned_to_name = view.content_tag(:div, view.content_tag(:span, issue.try(:assigned_to).try(:name)), :style => style, :class => 'issue-assigned-name')
339
          @assigned_to_names << assigned_to_name
340
          assigned_to_name
341
        end
342
      end
343

  
325 344
      def subject(label, options, object=nil)
326 345
        send "#{options[:format]}_subject", options, label, object
327 346
      end
public/javascripts/gantt.js
161 161
  }
162 162
}
163
function drawAssignedToNames(){
164
  if ($("#draw_assigned_to_names").prop('checked')){
165
    $('td.gantt_assigned_to_names_column').show();
166
    $('td.gantt_assigned_to_names_column').resizable({
167
      alsoResize: ".gantt_assigned_to_names_container, .gantt_assigned_to_names_container>.gantt_hdr, .issue-assigned-name",
168
      minWidth: 20,
169
      handles: "e",
170
      containment: "#content",
171
      create: function( event, ui ) {
172
        $(".ui-resizable-e").css("cursor","ew-resize");
173
      }
174
    }).on('resize', function (e) {
175
        e.stopPropagation();
176
    });
177
    if(isMobile()) {
178
      var width = Math.round($('.gantt_container').width()*0.15)
179
      $('.gantt_assigned_to_names_container>.gantt_hdr').width(width-2);
180
      $('.gantt_assigned_to_names_container, .gantt_assigned_to_names_column').width(width);
181
      $('.issue-assigned-name').each(function(){
182
        $(this).width($(".gantt_assigned_to_names_column").width());
183
      });
184
      $('td.gantt_assigned_to_names_column').resizable('disable');
185
    }else{
186
      $('td.gantt_assigned_to_names_column').resizable('enable');
187
    };
188
  }else{
189
    $('td.gantt_assigned_to_names_column').hide();
190
  }
191
}
192

  
163 193
function drawGanttHandler() {
164 194
  var folder = document.getElementById('gantt_draw_area');
165 195
  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
1155 1155
.gantt_hdr.nwday {background-color:#f1f1f1; color:#999;}
1156
.gantt_subjects { font-size: 0.8em; }
1157
.gantt_subjects div { line-height:16px;height:16px;overflow:hidden;white-space:nowrap;text-overflow: ellipsis; }
1156
.gantt_subjects, .issue-assigned-name { font-size: 0.8em; }
1157
.gantt_subjects div, .issue-assigned-name { line-height:16px;height:16px;overflow:hidden;white-space:nowrap;text-overflow: ellipsis; }
1158
.issue-assigned-name { padding: 0px 3px; width: 100px; }
1158 1159
.task {
1159 1160
  position: absolute;
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
  .gantt_subjects_container {
......
843 843
  #login-form {width:100%; margin-top:2em;}
844 844
}
845

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

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

  
239 249
  test "#subject_for_project" do
240 250
    create_gantt
241 251
    @output_buffer = @gantt.subject_for_project(@project, :format => :html)
......
418 428
    assert_select "div.label", :text => 'line'
419 429
  end
430
  test "#assigned_to_name" do
431
    create_gantt
432
    options = {:top => 64, :format => :html}
433
    issue = Issue.generate!
434
    issue.assigned_to_id = issue.assignable_users.first.id
435
    @output_buffer = @gantt.assigned_to_name(issue, options)
436

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

  
420 442
  def test_sort_issues_no_date
421 443
    project = Project.generate!
422 444
    issue1 = Issue.generate!(:subject => "test", :project => project)