diff --git a/app/helpers/my_helper.rb b/app/helpers/my_helper.rb
index a4b35d890..d60d2ab15 100644
--- a/app/helpers/my_helper.rb
+++ b/app/helpers/my_helper.rb
@@ -76,7 +76,7 @@ module MyHelper
end
def render_calendar_block(block, settings)
- calendar = Redmine::Helpers::Calendar.new(User.current.today, current_language, :week)
+ calendar = Redmine::Helpers::Calendar.new(User.current.today, current_language, :"week#{settings[:weeks]}")
calendar.events = Issue.visible.
where(:project_id => User.current.projects.pluck(:id)).
where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", calendar.startdt, calendar.enddt, calendar.startdt, calendar.enddt).
@@ -84,7 +84,7 @@ module MyHelper
references(:project, :tracker, :priority, :assigned_to).
to_a
- render :partial => 'my/blocks/calendar', :locals => {:calendar => calendar, :block => block}
+ render :partial => 'my/blocks/calendar', :locals => {:calendar => calendar, :block => block, :settings => settings}
end
def render_documents_block(block, settings)
diff --git a/app/views/my/blocks/_calendar.html.erb b/app/views/my/blocks/_calendar.html.erb
index c85190f2a..fe623e290 100644
--- a/app/views/my/blocks/_calendar.html.erb
+++ b/app/views/my/blocks/_calendar.html.erb
@@ -1,3 +1,29 @@
+
+ <%= link_to_function l(:label_options), "$('##{block}-settings').toggle();", :class => 'icon-only icon-settings', :title => l(:label_options) %>
+
+
<%= l(:label_calendar) %>
+<%
+tag_name = "settings[#{block}][weeks]"
+tag_id = sanitize_to_id(tag_name)
+-%>
+
+ <%= form_tag(my_page_path, :remote => true) do %>
+
+ <%= label_tag tag_id, l(:label_date_range) %>
+ <%= select_tag tag_name,
+ options_for_select(
+ (1..5).collect{|ii| [l('datetime.distance_in_words.x_weeks', ii), ii] },
+ settings[:weeks]
+ ),
+ :id => tag_id, :size => 1 %>
+
+
+ <%= submit_tag l(:button_save) %>
+ <%= link_to_function l(:button_cancel), "$('##{block}-settings').toggle();" %>
+
+ <% end %>
+
+
<%= render :partial => 'common/calendar', :locals => {:calendar => calendar } %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 36d2099c8..f6d0a400f 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -55,6 +55,9 @@ en:
x_days:
one: "1 day"
other: "%{count} days"
+ x_weeks:
+ one: "1 week"
+ other: "%{count} weeks"
about_x_months:
one: "about 1 month"
other: "about %{count} months"
diff --git a/lib/redmine/helpers/calendar.rb b/lib/redmine/helpers/calendar.rb
index 3641097ba..b80921fdd 100644
--- a/lib/redmine/helpers/calendar.rb
+++ b/lib/redmine/helpers/calendar.rb
@@ -37,11 +37,16 @@ module Redmine
@startdt = @startdt - (@startdt.cwday - first_wday)%7
# ends on the last day of the week
@enddt = @enddt + (last_wday - @enddt.cwday)%7
- when :week
- @startdt = date - (date.cwday - first_wday)%7
- @enddt = date + (last_wday - date.cwday)%7
else
- raise 'Invalid period'
+ if "#{period}" =~ /^week(\d*)$/
+ week = ($1.presence || '1').to_i
+ week = 1 if week < 1
+ week = 5 if week > 5
+ @startdt = date - (date.cwday - first_wday)%7
+ @enddt = (date + 7 * (week - 1)) + (last_wday - date.cwday)%7
+ else
+ raise 'Invalid period'
+ end
end
end
diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb
index d8db74ff6..5b2c6e0f3 100644
--- a/test/functional/my_controller_test.rb
+++ b/test/functional/my_controller_test.rb
@@ -315,6 +315,24 @@ class MyControllerTest < Redmine::ControllerTest
end
end
+ def test_page_with_calendar_block_should_show_period_of_selected_week
+ preference = User.find(2).pref
+ preference.my_page_layout = {'top' => ['calendar']}
+ preference.my_page_settings = {}
+ preference.save!
+
+ post :update_page,
+ :params => {
+ :settings => {
+ :calendar => {:weeks => '3'},
+ },
+ },
+ :xhr => true
+ assert_response :success
+ assert_include '$("#block-calendar").replaceWith(', response.body
+ assert_equal({:weeks => '3'}, preference.reload.my_page_settings('calendar'))
+ end
+
def test_my_account_should_show_editable_custom_fields
get :account
assert_response :success