Add duration field to appointments and enhance calendar tooltip functionality

This commit is contained in:
ricky committed 2026-08-06 21:24:54 -04:00
1 parent 83cdbe7c7c
commit c481879dd8
7 files changed
+187 -34

No files matched your search

@@ -93,6 +93,7 @@ class CustomerAppointmentsController < ApplicationController
:end_date,
:estimated_hours,
:estimate_id,
:duration
)
end
+49 -1
View File
@@ -1,3 +1,43 @@
<%
# Get Redmine's configured non-working week days (e.g., ["6", "7"] for Sat/Sun)
non_working_days = Setting.non_working_week_days || []
# Safely collect all unique CustomerAppointments across the entire calendar date range
all_appointments = (calendar.startdt..calendar.enddt).flat_map { |date|
calendar.events_on(date)
}.select { |e| e.is_a?(CustomerAppointment) }.uniq
# Lambda to determine if an appointment should render on a specific calendar day
appointment_occurs_on = lambda do |appointment, current_day|
return false if appointment.start_date.nil?
start_date = appointment.start_date.to_date
target_date = current_day.to_date
return false if target_date < start_date
# Skip rendering on Redmine non-working days
return false if non_working_days.include?(target_date.cwday.to_s)
duration = [appointment.duration.to_i, 1].max
date_cursor = start_date
working_days_count = 0
while date_cursor <= target_date
unless non_working_days.include?(date_cursor.cwday.to_s)
working_days_count += 1
end
if date_cursor == target_date
return working_days_count <= duration
end
date_cursor += 1 # Pure Ruby Date increment stays a Date object
end
false
end
%>
<%= form_tag({}, data: { cm_url: issues_context_menu_path }) do %>
<%= hidden_field_tag 'back_url', url_for(params: request.query_parameters), id: nil %>
@@ -31,7 +71,15 @@
title: l(:label_appointment_new, default: 'New Appointment') %>
</p>
<% calendar.events_on(day).each do |event| %>
<%
# Non-appointment events (Issues, Versions, etc.)
standard_events = calendar.events_on(day).reject { |e| e.is_a?(CustomerAppointment) }
# Appointments matching duration on this working day
matching_appointments = all_appointments.select { |app| appointment_occurs_on.call(app, day) }
%>
<% (standard_events + matching_appointments).each do |event| %>
<% if event.is_a?(Issue) %>
@@ -4,28 +4,28 @@
</h3>
<p class="subtitle">
<strong><%= appointment.status %></strong>
<strong><%= appointment.status.to_s.humanize %></strong>
</p>
<table class="attributes">
<% if appointment.customer %>
<tr>
<th><%= l(:label_customer) rescue "Customer" %></th>
<td><%= link_to appointment.customer %></td>
<th><%= l(:label_customer, default: "Customer") %></th>
<td><%= link_to appointment.customer.name, appointment.customer %></td>
</tr>
<% end %>
<% if appointment.vehicle %>
<tr>
<th>Vehicle</th>
<td><%= link_to appointment.vehicle %></td>
<th><%= l(:label_vehicle, default: "Vehicle") %></th>
<td><%= link_to appointment.vehicle.name, appointment.vehicle %></td>
</tr>
<% end %>
<% if appointment.user %>
<tr>
<th>Technician</th>
<th><%= l(:label_technician, default: "Technician") %></th>
<td>
<%= avatar(appointment.user, size: 16) %>
<%= appointment.user.name %>
@@ -42,7 +42,7 @@
<% if appointment.estimate %>
<tr>
<th>Estimate</th>
<th><%= l(:label_estimate, default: "Estimate") %></th>
<td>
<%= link_to "##{appointment.estimate.id}",
appointment.estimate %>
@@ -51,20 +51,25 @@
<% end %>
<tr>
<th>Start</th>
<th><%= l(:label_start_date) %></th>
<td><%= format_date(appointment.start_date) %></td>
</tr>
<tr>
<th>Finish</th>
<th><%= l(:label_end_date) %></th>
<td><%= format_date(appointment.end_date || appointment.start_date) %></td>
</tr>
<tr>
<th>Estimated Time</th>
<th><%= l(:label_estimated_hours) %></th>
<td><%= number_with_precision(appointment.estimated_hours, precision: 1) %> hrs</td>
</tr>
<tr>
<th><%= l(:label_duration) %></th>
<td><%= number_with_precision(appointment.duration, precision: 1) %> days</td>
</tr>
</table>
<% if appointment.description.present? %>
@@ -80,7 +85,7 @@
<hr>
<p class="buttons">
<%= link_to "Open Appointment",
<%= link_to l(:label_open_appointment, default: "Open Appointment"),
customer_appointment_path(appointment),
class: "icon icon-edit" %>
</p>