Project

General

Profile

Patch #30421 » add-issue-tracking-table-on-profile-page.diff

Go MAEDA, 2019-01-14 03:31

View differences:

app/controllers/users_controller.rb (working copy)
78 78
    # show projects based on current user visibility
79 79
    @memberships = @user.memberships.preload(:roles, :project).where(Project.visible_condition(User.current)).to_a
80 80

  
81
    @issue_counts = {}
82
    @issue_counts[:assigned] = {
83
      :total  => Issue.visible.assigned_to(@user).count,
84
      :open   => Issue.visible.open.assigned_to(@user).count
85
    }
86
    @issue_counts[:reported] = {
87
      :total  => Issue.visible.where(:author_id => @user.id).count,
88
      :open   => Issue.visible.open.where(:author_id => @user.id).count
89
    }
90

  
81 91
    respond_to do |format|
82 92
      format.html {
83 93
        events = Redmine::Activity::Fetcher.new(User.current, :author => @user).events(nil, nil, :limit => 10)
app/views/users/show.html.erb (working copy)
23 23
</ul>
24 24

  
25 25
<h3><%=l(:label_issue_plural)%></h3>
26
<ul>
27
  <li><%= link_to l(:label_assigned_issues),
28
        issues_path(:set_filter => 1, :assigned_to_id => ([@user.id] + @user.group_ids).join("|"), :sort => 'priority:desc,updated_on:desc') %>:
29
      <%= Issue.visible.open.assigned_to(@user).count %>
30
  <li><%= link_to l(:label_reported_issues),
31
        issues_path(:set_filter => 1, :status_id => '*', :author_id => @user.id) %>:
32
      <%= Issue.visible.where(:author_id => @user.id).count %>
33
</ul>
34 26

  
27
<table class="list issue-report">
28
<thead>
29
  <tr>
30
    <th></th>
31
    <th><%=l(:label_open_issues_plural)%></th>
32
    <th><%=l(:label_closed_issues_plural)%></th>
33
    <th><%=l(:label_total)%></th>
34
  </tr>
35
</thead>
36
<tbody>
37
  <% assigned_to_ids = ([@user.id] + @user.group_ids).join("|") %>
38
  <% sort_cond = 'priority:desc,updated_on:desc' %>
39
  <tr>
40
    <td class="name">
41
      <%= link_to l(:label_assigned_issues),
42
        issues_path(:set_filter => 1, :assigned_to_id => assigned_to_ids, :sort => sort_cond) %>
43
    </td>
44
    <td>
45
      <%= link_to @issue_counts[:assigned][:open],
46
        issues_path(:set_filter => 1, :assigned_to_id => assigned_to_ids, :sort => sort_cond) %>
47
    </td>
48
    <td>
49
      <%= link_to @issue_counts[:assigned][:total] - @issue_counts[:assigned][:open],
50
        issues_path(:set_filter => 1, :status_id => 'c', :assigned_to_id => assigned_to_ids, :sort => sort_cond) %>
51
    </td>
52
    <td class="total">
53
      <%= link_to @issue_counts[:assigned][:total],
54
        issues_path(:set_filter => 1, :status_id => '*', :assigned_to_id => assigned_to_ids, :sort => sort_cond) %>
55
    </td>
56
  </tr>
57
  <tr>
58
    <td class="name">
59
      <%= link_to l(:label_reported_issues),
60
        issues_path(:set_filter => 1, :author_id => @user.id, :sort => sort_cond) %>
61
    </td>
62
    <td>
63
      <%= link_to @issue_counts[:reported][:open],
64
        issues_path(:set_filter => 1, :author_id => @user.id, :sort => sort_cond) %>
65
    </td>
66
    <td>
67
      <%= link_to @issue_counts[:reported][:total] - @issue_counts[:reported][:open],
68
        issues_path(:set_filter => 1, :status_id => 'c', :author_id => @user.id, :sort => sort_cond) %>
69
    </td>
70
    <td class="total">
71
      <%= link_to @issue_counts[:reported][:total],
72
        issues_path(:set_filter => 1, :status_id => '*', :author_id => @user.id, :sort => sort_cond) %>
73
    </td>
74
  </tr>
75
</tbody>
76
</table>
77

  
35 78
<% unless @memberships.empty? %>
36 79
<h3><%=l(:label_project_plural)%></h3>
37 80
<ul>
test/functional/users_controller_test.rb (working copy)
185 185
    assert_select 'h2', :text => /John Smith/
186 186
  end
187 187

  
188
  def test_show_issues_counts
189
    @request.session[:user_id] = 2
190
    get :show, :params => {:id => 2}
191
    assert_select 'table.list.issue-report>tbody' do
192
      assert_select 'tr:nth-of-type(1)' do
193
        assert_select 'td:nth-of-type(1)>a', :text => 'Assigned issues'
194
        assert_select 'td:nth-of-type(2)>a', :text => '1'
195
        assert_select 'td:nth-of-type(3)>a', :text => '0'
196
        assert_select 'td:nth-of-type(4)>a', :text => '1'
197
      end
198
      assert_select 'tr:nth-of-type(2)' do
199
        assert_select 'td:nth-of-type(1)>a', :text => 'Reported issues'
200
        assert_select 'td:nth-of-type(2)>a', :text => '11'
201
        assert_select 'td:nth-of-type(3)>a', :text => '2'
202
        assert_select 'td:nth-of-type(4)>a', :text => '13'
203
      end
204
    end
205
  end
206

  
188 207
  def test_new
189 208
    get :new
190 209
    assert_response :success
(3-3/3)