Project

General

Profile

Patch #1081 » _activity.rhtml

Carl Nygard, 2008-04-21 18:32

 
1
<h3><%=l(:label_activity_latest)%></h3>
2

    
3
<%  date_from = Date.today - 1
4
    date_to = Date.today + 1
5

    
6
    events = []
7

    
8
    logger.debug "Gather activity between #{date_from} and #{date_to} ..."
9
    User.current.projects.each { |p| 
10
      logger.debug "Gather activity for #{p.name} ..."
11
      events += p.issues.find(:all, 
12
                               :conditions => ["#{Issue.table_name}.created_on >= ? and #{Issue.table_name}.created_on <= ?", 
13
                                               date_from, date_to])
14
      logger.debug "Gathered issues #{events.size} events..."
15

    
16
      events += p.issues_status_changes(date_from, date_to)
17
      logger.debug "Gathered notes #{events.size} events..."
18

    
19
      events += p.news.find(:all, 
20
                             :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", 
21
                                             date_from, date_to],
22
                             :include => :author )
23
      logger.debug "Gathered news #{events.size} events..."
24

    
25
      events += Attachment.find(:all, 
26
                                 :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", 
27
                                 :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", 
28
                                                 p.id, date_from, date_to], 
29
                                 :include => :author )
30
      logger.debug "Gathered attachments #{events.size} events..."
31

    
32
      select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
33
               "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
34
               "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
35
               "#{WikiContent.versioned_table_name}.id"
36
      joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
37
              "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id "
38
      conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
39
                    p.id, date_from, date_to]
40

    
41
      events += WikiContent.versioned_class.find(:all, 
42
                                                  :select => select, 
43
                                                  :joins => joins, 
44
                                                  :conditions => conditions)
45
      logger.debug "Gathered wiki #{events.size} events..."
46

    
47
      events += Changeset.find(:all, 
48
                                :include => :repository, 
49
                                :conditions => ["#{Repository.table_name}.project_id = ? AND #{Changeset.table_name}.committed_on BETWEEN ? AND ?", 
50
                                                p.id, date_from, date_to])
51
      logger.debug "Gathered SCM #{events.size} events..."
52

    
53
      events += Message.find(:all, 
54
                              :include => [:board, :author], 
55
                              :conditions => ["#{Board.table_name}.project_id=? AND #{Message.table_name}.parent_id IS NULL AND #{Message.table_name}.created_on BETWEEN ? AND ?", 
56
                                              p.id, date_from, date_to])
57
      logger.debug "Gathered messages #{events.size} events..."
58

    
59
    }
60

    
61
    logger.debug "Gathered #{events.size} events between #{date_from} and #{date_to} ..."
62

    
63
    events_by_day = events.group_by(&:event_date)
64
%>
65

    
66
<% events_by_day.keys.sort {|x,y| y <=> x }.each do |day| %>
67

    
68
  <h3><%= day_name(day.cwday) %> <%= day.day %></h3>
69
  <ul>
70

    
71
  <% events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| %>
72
    <li><p><%= format_time(e.event_datetime, false) %> <%= link_to truncate(e.event_title, 100), e.event_url %><br />
73
    <% unless e.event_description.blank? %><em><%= truncate(e.event_description, 500) %></em><br /><% end %>
74
    <span class="author"><%= e.event_author if e.respond_to?(:event_author) %></span></p></li>
75
  <% end %>
76
  </ul>
77
<% end %>
78

    
79
<% if events_by_day.empty? %><p class="nodata"><%= l(:label_no_data) %></p><% end %>
80

    
(2-2/2)