Feature #26525 » 26525-my-page-calendar.patch
| app/helpers/my_helper.rb | ||
|---|---|---|
| 76 | 76 | end | 
| 77 | 77 | |
| 78 | 78 | def render_calendar_block(block, settings) | 
| 79 |     calendar = Redmine::Helpers::Calendar.new(User.current.today, current_language, :week) | |
| 79 |     calendar = Redmine::Helpers::Calendar.new(User.current.today, current_language, :"week#{settings[:weeks]}") | |
| 80 | 80 | calendar.events = Issue.visible. | 
| 81 | 81 | where(:project_id => User.current.projects.pluck(:id)). | 
| 82 | 82 |       where("(start_date>=? and start_date<=?) or (due_date>=? and due_date<=?)", calendar.startdt, calendar.enddt, calendar.startdt, calendar.enddt). | 
| ... | ... | |
| 84 | 84 | references(:project, :tracker, :priority, :assigned_to). | 
| 85 | 85 | to_a | 
| 86 | 86 | |
| 87 |     render :partial => 'my/blocks/calendar', :locals => {:calendar => calendar, :block => block} | |
| 87 |     render :partial => 'my/blocks/calendar', :locals => {:calendar => calendar, :block => block, :settings => settings} | |
| 88 | 88 | end | 
| 89 | 89 | |
| 90 | 90 | def render_documents_block(block, settings) | 
| app/views/my/blocks/_calendar.html.erb | ||
|---|---|---|
| 1 | <div class="contextual"> | |
| 2 |   <%= link_to_function l(:label_options), "$('##{block}-settings').toggle();", :class => 'icon-only icon-settings', :title => l(:label_options) %> | |
| 3 | </div> | |
| 4 | ||
| 1 | 5 | <h3><%= l(:label_calendar) %></h3> | 
| 2 | 6 | |
| 7 | <% | |
| 8 | tag_name = "settings[#{block}][weeks]" | |
| 9 | tag_id = sanitize_to_id(tag_name) | |
| 10 | -%> | |
| 11 | <div id="<%= block %>-settings" style="display:none;"> | |
| 12 | <%= form_tag(my_page_path, :remote => true) do %> | |
| 13 | <div class="box"> | |
| 14 | <%= label_tag tag_id, l(:label_date_range) %> | |
| 15 | <%= select_tag tag_name, | |
| 16 | options_for_select( | |
| 17 |                 (1..5).collect{|ii| [l('datetime.distance_in_words.x_weeks', ii), ii] }, | |
| 18 | settings[:weeks] | |
| 19 | ), | |
| 20 | :id => tag_id, :size => 1 %> | |
| 21 | </div> | |
| 22 | <p> | |
| 23 | <%= submit_tag l(:button_save) %> | |
| 24 |       <%= link_to_function l(:button_cancel), "$('##{block}-settings').toggle();" %> | |
| 25 | </p> | |
| 26 | <% end %> | |
| 27 | </div> | |
| 28 | ||
| 3 | 29 | <%= render :partial => 'common/calendar', :locals => {:calendar => calendar } %> | 
| config/locales/en.yml | ||
|---|---|---|
| 55 | 55 | x_days: | 
| 56 | 56 | one: "1 day" | 
| 57 | 57 |         other: "%{count} days" | 
| 58 | x_weeks: | |
| 59 | one: "1 week" | |
| 60 |         other: "%{count} weeks" | |
| 58 | 61 | about_x_months: | 
| 59 | 62 | one: "about 1 month" | 
| 60 | 63 |         other: "about %{count} months" | 
| lib/redmine/helpers/calendar.rb | ||
|---|---|---|
| 37 | 37 | @startdt = @startdt - (@startdt.cwday - first_wday)%7 | 
| 38 | 38 | # ends on the last day of the week | 
| 39 | 39 | @enddt = @enddt + (last_wday - @enddt.cwday)%7 | 
| 40 | when :week | |
| 41 | @startdt = date - (date.cwday - first_wday)%7 | |
| 42 | @enddt = date + (last_wday - date.cwday)%7 | |
| 43 | 40 | else | 
| 44 | raise 'Invalid period' | |
| 41 |           if "#{period}" =~ /^week(\d*)$/ | |
| 42 | week = ($1.presence || '1').to_i | |
| 43 | week = 1 if week < 1 | |
| 44 | week = 5 if week > 5 | |
| 45 | @startdt = date - (date.cwday - first_wday)%7 | |
| 46 | @enddt = (date + 7 * (week - 1)) + (last_wday - date.cwday)%7 | |
| 47 | else | |
| 48 | raise 'Invalid period' | |
| 49 | end | |
| 45 | 50 | end | 
| 46 | 51 | end | 
| 47 | 52 | |
| test/functional/my_controller_test.rb | ||
|---|---|---|
| 315 | 315 | end | 
| 316 | 316 | end | 
| 317 | 317 | |
| 318 | def test_page_with_calendar_block_should_show_period_of_selected_week | |
| 319 | preference = User.find(2).pref | |
| 320 |     preference.my_page_layout = {'top' => ['calendar']} | |
| 321 |     preference.my_page_settings = {} | |
| 322 | preference.save! | |
| 323 | ||
| 324 | post :update_page, | |
| 325 |       :params => { | |
| 326 |         :settings => { | |
| 327 |           :calendar => {:weeks => '3'}, | |
| 328 | }, | |
| 329 | }, | |
| 330 | :xhr => true | |
| 331 | assert_response :success | |
| 332 |     assert_include '$("#block-calendar").replaceWith(', response.body | |
| 333 |     assert_equal({:weeks => '3'}, preference.reload.my_page_settings('calendar')) | |
| 334 | end | |
| 335 | ||
| 318 | 336 | def test_my_account_should_show_editable_custom_fields | 
| 319 | 337 | get :account | 
| 320 | 338 | assert_response :success | 
- « Previous
- 1
- 2
- Next »