Calendar review fixes; working day hours setting

- Issues' estimated hours are spread over their working days from start to due date, instead of
  counted in full on both the start and due dates
- Tooltips in the two rightmost columns open leftward again (the rule targeted the old table layout)
- Today scrolls when today is on the page (the check read calendar values that don't exist)
- "Day N of M" on calendar cards and My Page skips holidays; My Page uses the user's date
- Each appointment's working days are worked out once per page (CustomerAppointment#working_days),
  and shared by placement, hours, day numbers and the end date
- The calendar toggles are kept in the session, so changing month loads the page once
- Clicking inside an open tooltip keeps it open; estimates load with the appointments
- Hours in a working day is a plugin setting (default 8)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-02 21:12:31 -05:00
1 parent ae522baf63
commit 3a5d83aa69
12 files changed
+148 -187

No files matched your search

+9
View File
@@ -9,6 +9,15 @@
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module RedmineQboCalendar
DEFAULT_HOURS_PER_DAY = 8.0
# A working day's hours (plugin setting): multi-day appointments use up to this many hours a day on the
# calendar, and one without its own hours takes this many a day
def self.hours_per_day
hours = (Setting.plugin_redmine_qbo_calendar || {})['hours_per_day'].to_f
hours.positive? && hours <= 24 ? hours : DEFAULT_HOURS_PER_DAY
end
def self.setup
# Patches
Customer.prepend(RedmineQboCalendar::Patches::CustomerPatch)
@@ -24,6 +24,17 @@ module RedmineQboCalendar
params[:month] ||= session[:qbo_calendar_month]
end
# The "Hide past weeks" and "Show customer appointments only" toggles stick for the session, so
# month links (which don't carry them) keep them without a second page load
%w[only_appointments hide_past_weeks].each do |name|
key = :"qbo_calendar_#{name}"
if params.key?(name)
session[key] = params[name] == '1'
elsif session[key]
params[name] = '1'
end
end
# 2. Call Redmine core CalendarsController#show
super
@@ -35,7 +46,7 @@ module RedmineQboCalendar
log "events: #{events.inspect}"
# Only users with "View customer appointments" see appointments on the calendar
appointments = CustomerAppointment.visible(User.current).includes(:customer, :vehicle, :user, :project)
appointments = CustomerAppointment.visible(User.current).includes(:customer, :vehicle, :user, :project, :estimate)
# Only load appointments that can appear in the displayed range. Multi-day appointments
# can start before the range, so look back far enough to cover the longest one
+19 -4
View File
@@ -29,17 +29,32 @@ module RedmineQboCalendar
def nth_working_day(start_date, count, holidays: Holiday.all.to_a, week_days: non_working_week_days)
return nil if start_date.nil?
dates(start_date, count, holidays: holidays, week_days: week_days).last || (start_date + MAX_SCAN_DAYS)
end
# The first N working days from start_date (itself included when it's a working day), e.g. a 3-day job
# starting Friday works Fri, Mon and Tue
def dates(start_date, count, holidays: Holiday.all.to_a, week_days: non_working_week_days)
return [] if start_date.nil?
count = [count.to_i, 1].max
cursor = start_date
worked = 0
worked = []
MAX_SCAN_DAYS.times do
worked += 1 unless non_working?(cursor, holidays: holidays, week_days: week_days)
return cursor if worked >= count
worked << cursor unless non_working?(cursor, holidays: holidays, week_days: week_days)
break if worked.size >= count
cursor += 1
end
cursor
worked
end
# The working days from first to last, both included (e.g. the days an issue runs)
def between(first, last, holidays: Holiday.all.to_a, week_days: non_working_week_days)
return [] if first.nil? || last.nil? || last < first
(first..[last, first + MAX_SCAN_DAYS].min).reject { |d| non_working?(d, holidays: holidays, week_days: week_days) }
end
end
end