##// END OF EJS Templates
Added issues status changes on the activity view (initial patch by Cyril Mougel)....
Jean-Philippe Lang -
r879:fa95501fe5e8
parent child
Show More
@@ -0,0 +1,39
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19
20 class JournalTest < Test::Unit::TestCase
21 fixtures :issues, :issue_statuses, :journals, :journal_details
22
23 def setup
24 @journal = Journal.find 1
25 end
26
27 def test_journalized_is_an_issue
28 issue = @journal.issue
29 assert_kind_of Issue, issue
30 assert_equal 1, issue.id
31 end
32
33 def test_new_status
34 status = @journal.new_status
35 assert_not_nil status
36 assert_kind_of IssueStatus, status
37 assert_equal 2, status.id
38 end
39 end
@@ -405,6 +405,7 class ProjectsController < ApplicationController
405
405
406 if @scope.include?('issues')
406 if @scope.include?('issues')
407 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
407 @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
408 @events += @project.issues_status_changes(@date_from, @date_to)
408 end
409 end
409
410
410 if @scope.include?('news')
411 if @scope.include?('news')
@@ -29,12 +29,19 class Journal < ActiveRecord::Base
29 :project_key => "#{Issue.table_name}.project_id",
29 :project_key => "#{Issue.table_name}.project_id",
30 :date_column => "#{Issue.table_name}.created_on"
30 :date_column => "#{Issue.table_name}.created_on"
31
31
32 acts_as_event :title => Proc.new {|o| "#{o.issue.tracker.name} ##{o.issue.id}: #{o.issue.subject}"},
32 acts_as_event :title => Proc.new {|o| "#{o.issue.tracker.name} ##{o.issue.id}: #{o.issue.subject}" + ((s = o.new_status) ? " (#{s})" : '') },
33 :description => :notes,
33 :description => :notes,
34 :author => :user,
34 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id}}
35 :url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id}}
35
36
36 def save
37 def save
37 # Do not save an empty journal
38 # Do not save an empty journal
38 (details.empty? && notes.blank?) ? false : super
39 (details.empty? && notes.blank?) ? false : super
39 end
40 end
41
42 # Returns the new status if the journal contains a status change, otherwise nil
43 def new_status
44 c = details.detect {|detail| detail.prop_key == 'status_id'}
45 (c && c.value) ? IssueStatus.find_by_id(c.value.to_i) : nil
46 end
40 end
47 end
@@ -76,6 +76,16 class Project < ActiveRecord::Base
76 end
76 end
77 end
77 end
78
78
79 # Return all issues status changes for the project between the 2 given dates
80 def issues_status_changes(from, to)
81 Journal.find(:all, :include => [:issue, :details, :user],
82 :conditions => ["#{Journal.table_name}.journalized_type = 'Issue'" +
83 " AND #{Issue.table_name}.project_id = ?" +
84 " AND #{JournalDetail.table_name}.prop_key = 'status_id'" +
85 " AND #{Journal.table_name}.created_on BETWEEN ? AND ?",
86 id, from, to+1])
87 end
88
79 # returns latest created projects
89 # returns latest created projects
80 # non public projects will be returned only if user is a member of those
90 # non public projects will be returned only if user is a member of those
81 def self.latest(user=nil, count=5)
91 def self.latest(user=nil, count=5)
@@ -6,7 +6,7
6 <% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| %>
6 <% @events_by_day[day].sort {|x,y| y.event_datetime <=> x.event_datetime }.each do |e| %>
7 <li><p><%= e.event_datetime.strftime("%H:%M") %> <%= link_to truncate(e.event_title, 100), e.event_url %><br />
7 <li><p><%= e.event_datetime.strftime("%H:%M") %> <%= link_to truncate(e.event_title, 100), e.event_url %><br />
8 <% unless e.event_description.blank? %><em><%= truncate(e.event_description, 500) %></em><br /><% end %>
8 <% unless e.event_description.blank? %><em><%= truncate(e.event_description, 500) %></em><br /><% end %>
9 <span class="author"><%= e.event_author if e.respond_to?(:author) %></span></p></li>
9 <span class="author"><%= e.event_author if e.respond_to?(:event_author) %></span></p></li>
10 <% end %>
10 <% end %>
11 </ul>
11 </ul>
12 <% end %>
12 <% end %>
@@ -1,8 +1,8
1 ---
1 ---
2 issues_001:
2 issues_001:
3 created_on: 2006-07-19 21:02:17 +02:00
3 created_on: <%= 3.days.ago.to_date.to_s(:db) %>
4 project_id: 1
4 project_id: 1
5 updated_on: 2006-07-19 21:04:30 +02:00
5 updated_on: <%= 1.day.ago.to_date.to_s(:db) %>
6 priority_id: 4
6 priority_id: 4
7 subject: Can't print recipes
7 subject: Can't print recipes
8 id: 1
8 id: 1
@@ -1,6 +1,6
1 ---
1 ---
2 journals_001:
2 journals_001:
3 created_on: 2007-01-26 19:58:40 +01:00
3 created_on: <%= 2.days.ago.to_date.to_s(:db) %>
4 notes: "Journal notes"
4 notes: "Journal notes"
5 id: 1
5 id: 1
6 journalized_type: Issue
6 journalized_type: Issue
@@ -22,7 +22,7 require 'projects_controller'
22 class ProjectsController; def rescue_action(e) raise e end; end
22 class ProjectsController; def rescue_action(e) raise e end; end
23
23
24 class ProjectsControllerTest < Test::Unit::TestCase
24 class ProjectsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :roles, :members, :issues, :enabled_modules, :enumerations
25 fixtures :projects, :users, :roles, :members, :issues, :journals, :journal_details, :trackers, :issue_statuses, :enabled_modules, :enumerations
26
26
27 def setup
27 def setup
28 @controller = ProjectsController.new
28 @controller = ProjectsController.new
@@ -93,6 +93,24 class ProjectsControllerTest < Test::Unit::TestCase
93 assert_response :success
93 assert_response :success
94 assert_template 'activity'
94 assert_template 'activity'
95 assert_not_nil assigns(:events_by_day)
95 assert_not_nil assigns(:events_by_day)
96
97 assert_tag :tag => "h3",
98 :content => /#{2.days.ago.to_date.day}/,
99 :sibling => { :tag => "ul",
100 :child => { :tag => "li",
101 :child => { :tag => "p",
102 :content => /(#{IssueStatus.find(2).name})/,
103 }
104 }
105 }
106 assert_tag :tag => "h3",
107 :content => /#{3.day.ago.to_date.day}/,
108 :sibling => { :tag => "ul", :child => { :tag => "li",
109 :child => { :tag => "p",
110 :content => /#{Issue.find(1).subject}/,
111 }
112 }
113 }
96 end
114 end
97
115
98 def test_archive
116 def test_archive
@@ -18,7 +18,7
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19
19
20 class ProjectTest < Test::Unit::TestCase
20 class ProjectTest < Test::Unit::TestCase
21 fixtures :projects
21 fixtures :projects, :issues, :issue_statuses, :journals, :journal_details
22
22
23 def setup
23 def setup
24 @ecookbook = Project.find(1)
24 @ecookbook = Project.find(1)
@@ -104,4 +104,13 class ProjectTest < Test::Unit::TestCase
104 sub.parent = Project.find(2)
104 sub.parent = Project.find(2)
105 assert !sub.save
105 assert !sub.save
106 end
106 end
107
108 def test_issues_status_changes
109 journals = @ecookbook.issues_status_changes 3.days.ago.to_date, Date.today
110 assert_equal 1, journals.size
111 assert_kind_of Journal, journals.first
112
113 journals = @ecookbook.issues_status_changes 30.days.ago.to_date, 10.days.ago.to_date
114 assert_equal 0, journals.size
115 end
107 end
116 end
General Comments 0
You need to be logged in to leave comments. Login now