Feature #26525 » 26525-my-page-calendar.patch
| app/helpers/my_helper.rb | ||
|---|---|---|
|
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).
|
||
| ... | ... | |
|
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)
|
||
| app/views/my/blocks/_calendar.html.erb | ||
|---|---|---|
|
<div class="contextual">
|
||
|
<%= link_to_function l(:label_options), "$('##{block}-settings').toggle();", :class => 'icon-only icon-settings', :title => l(:label_options) %>
|
||
|
</div>
|
||
|
<h3><%= l(:label_calendar) %></h3>
|
||
|
<%
|
||
|
tag_name = "settings[#{block}][weeks]"
|
||
|
tag_id = sanitize_to_id(tag_name)
|
||
|
-%>
|
||
|
<div id="<%= block %>-settings" style="display:none;">
|
||
|
<%= form_tag(my_page_path, :remote => true) do %>
|
||
|
<div class="box">
|
||
|
<%= 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 %>
|
||
|
</div>
|
||
|
<p>
|
||
|
<%= submit_tag l(:button_save) %>
|
||
|
<%= link_to_function l(:button_cancel), "$('##{block}-settings').toggle();" %>
|
||
|
</p>
|
||
|
<% end %>
|
||
|
</div>
|
||
|
<%= render :partial => 'common/calendar', :locals => {:calendar => calendar } %>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
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"
|
||
| lib/redmine/helpers/calendar.rb | ||
|---|---|---|
|
@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
|
||
| test/functional/my_controller_test.rb | ||
|---|---|---|
|
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
|
||
- « Previous
- 1
- 2
- Next »