Project

General

Profile

Feature #2471 » add-my-activities-to-my-page.patch

Mizuki ISHIKAWA, 2018-06-07 04:18

View differences:

app/controllers/my_controller.rb
28 28
  helper :users
29 29
  helper :custom_fields
30 30
  helper :queries
31
  helper :activities
31 32

  
32 33
  def index
33 34
    page
app/helpers/my_helper.rb
164 164

  
165 165
    render :partial => 'my/blocks/timelog', :locals => {:block => block, :entries => entries, :entries_by_day => entries_by_day, :days => days}
166 166
  end
167

  
168
  def render_my_activity_block(block, settings)
169
    events_by_day = Redmine::Activity::Fetcher.new(User.current, :author => User.current).events(nil, nil, :limit => 10).group_by(&:event_date)
170

  
171
    render :partial => 'my/blocks/my_activity', :locals => {:events_by_day => events_by_day}
172
  end
167 173
end
app/views/activities/_activities.html.erb
1
<div id="activity">
2
<% events_by_day.keys.sort.reverse_each do |day| %>
3
<h3><%= format_activity_day(day) %></h3>
4
<dl>
5
<% sort_activity_events(events_by_day[day]).each do |e, in_group| -%>
6
  <dt class="<%= e.event_type %> icon icon-<%= e.event_type %> <%= "grouped" if in_group %> <%= User.current.logged? && e.respond_to?(:event_author) && User.current == e.event_author ? 'me' : nil %>">
7
  <%= avatar(e.event_author, :size => "24") if e.respond_to?(:event_author) %>
8
  <span class="time"><%= format_time(e.event_datetime, false) %></span>
9
  <%= content_tag('span', e.project, :class => 'project') if @project.nil? || @project != e.project %>
10
  <%= link_to format_activity_title(e.event_title), e.event_url %>
11
  </dt>
12
  <dd class="<%= "grouped" if in_group %>"><span class="description"><%= format_activity_description(e.event_description) %></span>
13
  <span class="author"><%= link_to_user(e.event_author) if e.respond_to?(:event_author) %></span></dd>
14
<% end -%>
15
</dl>
16
<% end -%>
17
</div>
app/views/activities/index.html.erb
1 1
<h2><%= @author.nil? ? l(:label_activity) : l(:label_user_activity, link_to_user(@author)).html_safe %></h2>
2
<p class="subtitle"><%= l(:label_date_from_to, :start => format_date(@date_to - @days), :end => format_date(@date_to-1)) %></p>
3 2

  
4
<div id="activity">
5
<% @events_by_day.keys.sort.reverse_each do |day| %>
6
<h3><%= format_activity_day(day) %></h3>
7
<dl>
8
<% sort_activity_events(@events_by_day[day]).each do |e, in_group| -%>
9
  <dt class="<%= e.event_type %> icon icon-<%= e.event_type %> <%= "grouped" if in_group %> <%= User.current.logged? && e.respond_to?(:event_author) && User.current == e.event_author ? 'me' : nil %>">
10
  <%= avatar(e.event_author, :size => "24") if e.respond_to?(:event_author) %>
11
  <span class="time"><%= format_time(e.event_datetime, false) %></span>
12
  <%= content_tag('span', e.project, :class => 'project') if @project.nil? || @project != e.project %>
13
  <%= link_to format_activity_title(e.event_title), e.event_url %>
14
  </dt>
15
  <dd class="<%= "grouped" if in_group %>"><span class="description"><%= format_activity_description(e.event_description) %></span>
16
  <span class="author"><%= link_to_user(e.event_author) if e.respond_to?(:event_author) %></span></dd>
17
<% end -%>
18
</dl>
19
<% end -%>
20
</div>
3
<p class="subtitle"><%= l(:label_date_from_to, :start => format_date(@date_to - @days), :end => format_date(@date_to-1)) %></p>
21 4

  
5
<%= render :partial => 'activities/activities', :locals => {:events_by_day => @events_by_day} %>
22 6
<%= content_tag('p', l(:label_no_data), :class => 'nodata') if @events_by_day.empty? %>
23 7

  
24 8
<span class="pagination">
app/views/my/blocks/_my_activity.html.erb
1
<h3><%= link_to l(:label_activity), :controller => 'activities',
2
                :action => 'index', :id => nil, :user_id => User.current,
3
                :from => events_by_day.keys.first %></h3>
4

  
5
<%= render :partial => 'activities/activities', :locals => {:events_by_day => events_by_day} %>
app/views/users/show.html.erb
51 51
<h3><%= link_to l(:label_activity), :controller => 'activities',
52 52
                :action => 'index', :id => nil, :user_id => @user,
53 53
                :from => @events_by_day.keys.first %></h3>
54

  
55
<div id="activity">
56
<% @events_by_day.keys.sort.reverse_each do |day| %>
57
<h4><%= format_activity_day(day) %></h4>
58
<dl>
59
<% sort_activity_events(@events_by_day[day]).each do |e, in_group| -%>
60
  <dt class="<%= e.event_type %> icon icon-<%= e.event_type %> <%= "grouped" if in_group %> <%= User.current.logged? && e.respond_to?(:event_author) && User.current == e.event_author ? 'me' : nil %>">
61
  <span class="time"><%= format_time(e.event_datetime, false) %></span>
62
  <%= content_tag('span', e.project, :class => 'project') %>
63
  <%= link_to format_activity_title(e.event_title), e.event_url %></dt>
64
  <dd class="<%= "grouped" if in_group %>"><span class="description"><%= format_activity_description(e.event_description) %></span>
65
<% end -%>
66
</dl>
67
<% end -%>
68
</div>
54
<%= render :partial => 'activities/activities', :locals => {:events_by_day => @events_by_day} %>
69 55

  
70 56
<% other_formats_links do |f| %>
71 57
  <%= f.link_to 'Atom', :url => {:controller => 'activities', :action => 'index', :id => nil, :user_id => @user, :key => User.current.rss_key} %>
config/locales/en.yml
617 617
  label_reported_issues: Reported issues
618 618
  label_assigned_issues: Assigned issues
619 619
  label_assigned_to_me_issues: Issues assigned to me
620
  label_my_activity: My activity
620 621
  label_last_login: Last connection
621 622
  label_registered_on: Registered on
622 623
  label_activity: Activity
lib/redmine/my_page.rb
29 29
        'news' => {:label => :label_news_latest},
30 30
        'calendar' => {:label => :label_calendar},
31 31
        'documents' => {:label => :label_document_plural},
32
        'timelog' => {:label => :label_spent_time}
32
        'timelog' => {:label => :label_spent_time},
33
        'my_activity' => {:label => :label_my_activity}
33 34
      }
34 35

  
35 36
    def self.groups
test/functional/my_controller_test.rb
198 198
    end
199 199
  end
200 200

  
201
  def test_page_with_my_activity
202
    user = User.find(2)
203
    user.pref.my_page_layout = {'top' => ['my_activity']}
204
    user.pref.save!
205

  
206
    get :page
207
    assert_response :success
208

  
209
    assert_select 'div#block-my_activity' do
210
      assert_select 'h3' do
211
        assert_select 'a[href=?]', activity_path(from: Date.today, user_id: user.id),  :text => 'Activity'
212
      end
213
      assert_select 'div#activity' do
214
        assert_select 'dt', 10
215
      end
216
    end
217
  end
218

  
201 219
  def test_page_with_all_blocks
202 220
    blocks = Redmine::MyPage.blocks.keys
203 221
    preferences = User.find(2).pref
(3-3/5)