Feature #1459 » 0003-Show-the-names-of-non-working-dates-in-the-calendar.patch
| app/assets/stylesheets/application.css | ||
|---|---|---|
|
height: 1.5em;
|
||
|
}
|
||
|
.cal .calbody .abbr-day {display:none}
|
||
|
.cal .calbody .non-working-date-name {
|
||
|
float: inline-start;
|
||
|
/* Take the space left by the day number without widening the column */
|
||
|
inline-size: 0;
|
||
|
min-inline-size: calc(100% - 2.5em);
|
||
|
overflow: hidden;
|
||
|
font-size: 0.8em;
|
||
|
line-height: 1.875;
|
||
|
color: var(--oc-gray-6);
|
||
|
text-align: start;
|
||
|
text-overflow: ellipsis;
|
||
|
white-space: nowrap;
|
||
|
}
|
||
|
.cal .calbody.this-month {background-color:var(--oc-white);}
|
||
|
.cal .calbody.other-month {background-color:var(--oc-gray-1);}
|
||
|
.cal .calbody.other-month p.day-num {color: var(--oc-gray-5);}
|
||
| app/assets/stylesheets/responsive.css | ||
|---|---|---|
|
display: inline;
|
||
|
}
|
||
|
.cal .calbody .non-working-date-name {
|
||
|
float: none;
|
||
|
margin-inline-start: 0.5em;
|
||
|
white-space: normal;
|
||
|
}
|
||
|
.cal .week-number {
|
||
|
border: 1px solid var(--oc-gray-4);
|
||
|
text-align: start;
|
||
| app/models/non_working_date.rb | ||
|---|---|---|
|
include Redmine::SafeAttributes
|
||
|
class Current < ActiveSupport::CurrentAttributes
|
||
|
attribute :sorted_dates, :dates
|
||
|
attribute :names_by_date, :sorted_dates
|
||
|
end
|
||
|
after_save {self.class.clear_dates_cache}
|
||
| ... | ... | |
|
safe_attributes 'date', 'name'
|
||
|
# Returns the registered dates as a sorted Array.
|
||
|
# Returns a Hash of the registered dates and their names, ordered by date.
|
||
|
# The result is cached for the duration of the current request.
|
||
|
def self.sorted_dates
|
||
|
Current.sorted_dates ||= order(:date).pluck(:date)
|
||
|
def self.names_by_date
|
||
|
Current.names_by_date ||= order(:date).pluck(:date, :name).to_h
|
||
|
end
|
||
|
# Returns the name registered for the given date
|
||
|
def self.name_for(date)
|
||
|
names_by_date[date].presence
|
||
|
end
|
||
|
# Returns the registered dates as a Set.
|
||
|
# Returns the registered dates as a sorted Array.
|
||
|
# The result is cached for the duration of the current request.
|
||
|
def self.dates
|
||
|
Current.dates ||= sorted_dates.to_set
|
||
|
def self.sorted_dates
|
||
|
Current.sorted_dates ||= names_by_date.keys
|
||
|
end
|
||
|
def self.clear_dates_cache
|
||
| app/views/common/_calendar.html.erb | ||
|---|---|---|
|
<p class="day-num">
|
||
|
<span class="day-value"><%= day.day %></span>
|
||
|
<span class="abbr-day">(<%= abbr_day_name(day.cwday) %>)</span>
|
||
|
<% if (name = NonWorkingDate.name_for(day)) %>
|
||
|
<span class="non-working-date-name" title="<%= name %>"><%= name %></span>
|
||
|
<% end %>
|
||
|
</p>
|
||
|
<% calendar.events_on(day).each do |i| %>
|
||
|
<% if i.is_a? Issue %>
|
||
| lib/redmine/utils/date_calculation.rb | ||
|---|---|---|
|
# Returns true if the given date is a non working day
|
||
|
def non_working_day?(date)
|
||
|
non_working_week_days.include?(date.cwday) || NonWorkingDate.dates.include?(date)
|
||
|
non_working_week_days.include?(date.cwday) || NonWorkingDate.names_by_date.key?(date)
|
||
|
end
|
||
|
# Adds working days to the given date,
|
||
| test/functional/calendars_controller_test.rb | ||
|---|---|---|
|
end
|
||
|
def test_show_calendar_should_mark_non_working_dates
|
||
|
NonWorkingDate.create!(:date => '2016-12-29')
|
||
|
NonWorkingDate.create!(:date => '2016-12-29', :name => 'Year-end Shutdown')
|
||
|
get(
|
||
|
:show,
|
||
|
:params => {
|
||
| ... | ... | |
|
assert_response :success
|
||
|
assert_select 'li.nwday', 11
|
||
|
assert_select 'li.nwday', :text => /^29/
|
||
|
assert_select 'li.nwday', :text => /^29/ do
|
||
|
assert_select 'span.non-working-date-name', :text => 'Year-end Shutdown'
|
||
|
end
|
||
|
assert_select 'span.non-working-date-name', 1
|
||
|
end
|
||
|
end
|
||