@@ -1,39 +1,41 | |||||
1 | class CalendarsController < ApplicationController |
|
1 | class CalendarsController < ApplicationController | |
2 | menu_item :calendar |
|
2 | menu_item :calendar | |
3 | before_filter :find_optional_project |
|
3 | before_filter :find_optional_project | |
4 |
|
4 | |||
5 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
|
5 | rescue_from Query::StatementInvalid, :with => :query_statement_invalid | |
6 |
|
6 | |||
7 | helper :issues |
|
7 | helper :issues | |
8 | helper :projects |
|
8 | helper :projects | |
9 | helper :queries |
|
9 | helper :queries | |
10 | include QueriesHelper |
|
10 | include QueriesHelper | |
|
11 | helper :sort | |||
|
12 | include SortHelper | |||
11 |
|
13 | |||
12 | def show |
|
14 | def show | |
13 | if params[:year] and params[:year].to_i > 1900 |
|
15 | if params[:year] and params[:year].to_i > 1900 | |
14 | @year = params[:year].to_i |
|
16 | @year = params[:year].to_i | |
15 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 |
|
17 | if params[:month] and params[:month].to_i > 0 and params[:month].to_i < 13 | |
16 | @month = params[:month].to_i |
|
18 | @month = params[:month].to_i | |
17 | end |
|
19 | end | |
18 | end |
|
20 | end | |
19 | @year ||= Date.today.year |
|
21 | @year ||= Date.today.year | |
20 | @month ||= Date.today.month |
|
22 | @month ||= Date.today.month | |
21 |
|
23 | |||
22 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) |
|
24 | @calendar = Redmine::Helpers::Calendar.new(Date.civil(@year, @month, 1), current_language, :month) | |
23 | retrieve_query |
|
25 | retrieve_query | |
24 | @query.group_by = nil |
|
26 | @query.group_by = nil | |
25 | if @query.valid? |
|
27 | if @query.valid? | |
26 | events = [] |
|
28 | events = [] | |
27 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], |
|
29 | events += @query.issues(:include => [:tracker, :assigned_to, :priority], | |
28 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] |
|
30 | :conditions => ["((start_date BETWEEN ? AND ?) OR (due_date BETWEEN ? AND ?))", @calendar.startdt, @calendar.enddt, @calendar.startdt, @calendar.enddt] | |
29 | ) |
|
31 | ) | |
30 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) |
|
32 | events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @calendar.startdt, @calendar.enddt]) | |
31 |
|
33 | |||
32 | @calendar.events = events |
|
34 | @calendar.events = events | |
33 | end |
|
35 | end | |
34 |
|
36 | |||
35 | render :layout => false if request.xhr? |
|
37 | render :layout => false if request.xhr? | |
36 | end |
|
38 | end | |
37 |
|
39 | |||
38 |
|
40 | |||
39 | end |
|
41 | end |
@@ -1,64 +1,74 | |||||
1 | require File.dirname(__FILE__) + '/../test_helper' |
|
1 | require File.dirname(__FILE__) + '/../test_helper' | |
2 |
|
2 | |||
3 | class CalendarsControllerTest < ActionController::TestCase |
|
3 | class CalendarsControllerTest < ActionController::TestCase | |
4 | fixtures :all |
|
4 | fixtures :all | |
5 |
|
5 | |||
6 | def test_calendar |
|
6 | def test_calendar | |
7 | get :show, :project_id => 1 |
|
7 | get :show, :project_id => 1 | |
8 | assert_response :success |
|
8 | assert_response :success | |
9 | assert_template 'calendar' |
|
9 | assert_template 'calendar' | |
10 | assert_not_nil assigns(:calendar) |
|
10 | assert_not_nil assigns(:calendar) | |
11 | end |
|
11 | end | |
12 |
|
12 | |||
13 | def test_cross_project_calendar |
|
13 | def test_cross_project_calendar | |
14 | get :show |
|
14 | get :show | |
15 | assert_response :success |
|
15 | assert_response :success | |
16 | assert_template 'calendar' |
|
16 | assert_template 'calendar' | |
17 | assert_not_nil assigns(:calendar) |
|
17 | assert_not_nil assigns(:calendar) | |
18 | end |
|
18 | end | |
19 |
|
19 | |||
|
20 | context "GET :show" do | |||
|
21 | should "run custom queries" do | |||
|
22 | @query = Query.generate_default! | |||
|
23 | ||||
|
24 | get :show, :query_id => @query.id | |||
|
25 | assert_response :success | |||
|
26 | end | |||
|
27 | ||||
|
28 | end | |||
|
29 | ||||
20 | def test_week_number_calculation |
|
30 | def test_week_number_calculation | |
21 | Setting.start_of_week = 7 |
|
31 | Setting.start_of_week = 7 | |
22 |
|
32 | |||
23 | get :show, :month => '1', :year => '2010' |
|
33 | get :show, :month => '1', :year => '2010' | |
24 | assert_response :success |
|
34 | assert_response :success | |
25 |
|
35 | |||
26 | assert_tag :tag => 'tr', |
|
36 | assert_tag :tag => 'tr', | |
27 | :descendant => {:tag => 'td', |
|
37 | :descendant => {:tag => 'td', | |
28 | :attributes => {:class => 'week-number'}, :content => '53'}, |
|
38 | :attributes => {:class => 'week-number'}, :content => '53'}, | |
29 | :descendant => {:tag => 'td', |
|
39 | :descendant => {:tag => 'td', | |
30 | :attributes => {:class => 'odd'}, :content => '27'}, |
|
40 | :attributes => {:class => 'odd'}, :content => '27'}, | |
31 | :descendant => {:tag => 'td', |
|
41 | :descendant => {:tag => 'td', | |
32 | :attributes => {:class => 'even'}, :content => '2'} |
|
42 | :attributes => {:class => 'even'}, :content => '2'} | |
33 |
|
43 | |||
34 | assert_tag :tag => 'tr', |
|
44 | assert_tag :tag => 'tr', | |
35 | :descendant => {:tag => 'td', |
|
45 | :descendant => {:tag => 'td', | |
36 | :attributes => {:class => 'week-number'}, :content => '1'}, |
|
46 | :attributes => {:class => 'week-number'}, :content => '1'}, | |
37 | :descendant => {:tag => 'td', |
|
47 | :descendant => {:tag => 'td', | |
38 | :attributes => {:class => 'odd'}, :content => '3'}, |
|
48 | :attributes => {:class => 'odd'}, :content => '3'}, | |
39 | :descendant => {:tag => 'td', |
|
49 | :descendant => {:tag => 'td', | |
40 | :attributes => {:class => 'even'}, :content => '9'} |
|
50 | :attributes => {:class => 'even'}, :content => '9'} | |
41 |
|
51 | |||
42 |
|
52 | |||
43 | Setting.start_of_week = 1 |
|
53 | Setting.start_of_week = 1 | |
44 | get :show, :month => '1', :year => '2010' |
|
54 | get :show, :month => '1', :year => '2010' | |
45 | assert_response :success |
|
55 | assert_response :success | |
46 |
|
56 | |||
47 | assert_tag :tag => 'tr', |
|
57 | assert_tag :tag => 'tr', | |
48 | :descendant => {:tag => 'td', |
|
58 | :descendant => {:tag => 'td', | |
49 | :attributes => {:class => 'week-number'}, :content => '53'}, |
|
59 | :attributes => {:class => 'week-number'}, :content => '53'}, | |
50 | :descendant => {:tag => 'td', |
|
60 | :descendant => {:tag => 'td', | |
51 | :attributes => {:class => 'even'}, :content => '28'}, |
|
61 | :attributes => {:class => 'even'}, :content => '28'}, | |
52 | :descendant => {:tag => 'td', |
|
62 | :descendant => {:tag => 'td', | |
53 | :attributes => {:class => 'even'}, :content => '3'} |
|
63 | :attributes => {:class => 'even'}, :content => '3'} | |
54 |
|
64 | |||
55 | assert_tag :tag => 'tr', |
|
65 | assert_tag :tag => 'tr', | |
56 | :descendant => {:tag => 'td', |
|
66 | :descendant => {:tag => 'td', | |
57 | :attributes => {:class => 'week-number'}, :content => '1'}, |
|
67 | :attributes => {:class => 'week-number'}, :content => '1'}, | |
58 | :descendant => {:tag => 'td', |
|
68 | :descendant => {:tag => 'td', | |
59 | :attributes => {:class => 'even'}, :content => '4'}, |
|
69 | :attributes => {:class => 'even'}, :content => '4'}, | |
60 | :descendant => {:tag => 'td', |
|
70 | :descendant => {:tag => 'td', | |
61 | :attributes => {:class => 'even'}, :content => '10'} |
|
71 | :attributes => {:class => 'even'}, :content => '10'} | |
62 |
|
72 | |||
63 | end |
|
73 | end | |
64 | end |
|
74 | end |
General Comments 0
You need to be logged in to leave comments.
Login now