Project

General

Profile

Feature #1459 » 0003-Show-the-names-of-non-working-dates-in-the-calendar.patch

Go MAEDA, 2026-10-07 08:05

View differences:

app/assets/stylesheets/application.css
1695 1695
  height: 1.5em;
1696 1696
}
1697 1697
.cal .calbody .abbr-day {display:none}
1698
.cal .calbody .non-working-date-name {
1699
  float: inline-start;
1700
  /* Take the space left by the day number without widening the column */
1701
  inline-size: 0;
1702
  min-inline-size: calc(100% - 2.5em);
1703
  overflow: hidden;
1704
  font-size: 0.8em;
1705
  line-height: 1.875;
1706
  color: var(--oc-gray-6);
1707
  text-align: start;
1708
  text-overflow: ellipsis;
1709
  white-space: nowrap;
1710
}
1698 1711
.cal .calbody.this-month {background-color:var(--oc-white);}
1699 1712
.cal .calbody.other-month {background-color:var(--oc-gray-1);}
1700 1713
.cal .calbody.other-month p.day-num {color: var(--oc-gray-5);}
app/assets/stylesheets/responsive.css
829 829
    display: inline;
830 830
  }
831 831

  
832
  .cal .calbody .non-working-date-name {
833
    float: none;
834
    margin-inline-start: 0.5em;
835
    white-space: normal;
836
  }
837

  
832 838
  .cal .week-number {
833 839
    border: 1px solid var(--oc-gray-4);
834 840
    text-align: start;
app/models/non_working_date.rb
21 21
  include Redmine::SafeAttributes
22 22

  
23 23
  class Current < ActiveSupport::CurrentAttributes
24
    attribute :sorted_dates, :dates
24
    attribute :names_by_date, :sorted_dates
25 25
  end
26 26

  
27 27
  after_save {self.class.clear_dates_cache}
......
38 38

  
39 39
  safe_attributes 'date', 'name'
40 40

  
41
  # Returns the registered dates as a sorted Array.
41
  # Returns a Hash of the registered dates and their names, ordered by date.
42 42
  # The result is cached for the duration of the current request.
43
  def self.sorted_dates
44
    Current.sorted_dates ||= order(:date).pluck(:date)
43
  def self.names_by_date
44
    Current.names_by_date ||= order(:date).pluck(:date, :name).to_h
45
  end
46

  
47
  # Returns the name registered for the given date
48
  def self.name_for(date)
49
    names_by_date[date].presence
45 50
  end
46 51

  
47
  # Returns the registered dates as a Set.
52
  # Returns the registered dates as a sorted Array.
48 53
  # The result is cached for the duration of the current request.
49
  def self.dates
50
    Current.dates ||= sorted_dates.to_set
54
  def self.sorted_dates
55
    Current.sorted_dates ||= names_by_date.keys
51 56
  end
52 57

  
53 58
  def self.clear_dates_cache
app/views/common/_calendar.html.erb
14 14
      <p class="day-num">
15 15
        <span class="day-value"><%= day.day %></span>
16 16
        <span class="abbr-day">(<%= abbr_day_name(day.cwday) %>)</span>
17
        <% if (name = NonWorkingDate.name_for(day)) %>
18
          <span class="non-working-date-name" title="<%= name %>"><%= name %></span>
19
        <% end %>
17 20
      </p>
18 21
      <% calendar.events_on(day).each do |i| %>
19 22
        <% if i.is_a? Issue %>
lib/redmine/utils/date_calculation.rb
64 64

  
65 65
      # Returns true if the given date is a non working day
66 66
      def non_working_day?(date)
67
        non_working_week_days.include?(date.cwday) || NonWorkingDate.dates.include?(date)
67
        non_working_week_days.include?(date.cwday) || NonWorkingDate.names_by_date.key?(date)
68 68
      end
69 69

  
70 70
      # Adds working days to the given date,
test/functional/calendars_controller_test.rb
279 279
  end
280 280

  
281 281
  def test_show_calendar_should_mark_non_working_dates
282
    NonWorkingDate.create!(:date => '2016-12-29')
282
    NonWorkingDate.create!(:date => '2016-12-29', :name => 'Year-end Shutdown')
283 283
    get(
284 284
      :show,
285 285
      :params => {
......
290 290
    assert_response :success
291 291

  
292 292
    assert_select 'li.nwday', 11
293
    assert_select 'li.nwday', :text => /^29/
293
    assert_select 'li.nwday', :text => /^29/ do
294
      assert_select 'span.non-working-date-name', :text => 'Year-end Shutdown'
295
    end
296
    assert_select 'span.non-working-date-name', 1
294 297
  end
295 298
end
(6-6/8)