diff --git a/README.md b/README.md
index 02562dd..d432289 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,8 @@ Add appointments to the redmine calanedar with the abiltiy to attach a QBO custo
* An appointment's hours can't be less than its estimate's labor hours (the quantities of its lines with redmine_qbo's labor products/services). Picking an estimate raises the hours to match.
* The appointment page lists the issues linked to its estimate, and **Create Issues from Estimate** opens redmine_qbo's Create issues page with the appointment's dates, technician and vehicle.
* Estimate pages in redmine_qbo get an **Add appointment** link. Other plugins can add to the new appointment through the `:qbo_calendar_appointment_params, { customer:, estimate_id:, custom_fields: }` hook (e.g. redmine_qbo_vehicles: the vehicle with the estimate's VIN).
+* **Appointment statuses** are set up in the plugin's settings (Administration › Plugins › Configure): name, colour, whether the time counts toward the calendar's hours, and order (the first is the default). Renaming a status keeps its appointments; removing one in use asks which status to move them to. Statuses that don't count hours (e.g. Cancelled) stay on the calendar, crossed out.
+* **Call-outs**: an employee off work, added with the button next to each day's add button. They show at the top of the day in red stripes, have no customer or status, and never count toward hours. Upgrading (migration 004) turns appointments with the old Call_Out status into call-outs.
---
diff --git a/app/controllers/customer_appointments_controller.rb b/app/controllers/customer_appointments_controller.rb
index be7da5b..6c2dad4 100644
--- a/app/controllers/customer_appointments_controller.rb
+++ b/app/controllers/customer_appointments_controller.rb
@@ -51,7 +51,12 @@ class CustomerAppointmentsController < ApplicationController
.includes(:customer, :vehicle, :user)
.where('date < ?', Time.zone.now.beginning_of_day)
scope = scope.where(customer_id: @customer.id) if @customer
- scope = scope.where(status: @status) if @status
+ # The status filter also offers call-outs, which have no status
+ if @status == CustomerAppointment::CALL_OUT
+ scope = scope.where(event_type: CustomerAppointment::CALL_OUT)
+ elsif @status
+ scope = scope.where(status: @status).where(event_type: [nil, ''])
+ end
scope = scope.where('date >= ?', @from.in_time_zone.beginning_of_day) if @from
scope = scope.where('date <= ?', @to.in_time_zone.end_of_day) if @to
@@ -72,6 +77,9 @@ class CustomerAppointmentsController < ApplicationController
def new
@appointment = CustomerAppointment.new
@appointment.project = @project
+ # The calendar's "call-out" link makes an employee's call-out instead of a customer appointment
+ @appointment.event_type = CustomerAppointment::CALL_OUT if params[:event_type] == CustomerAppointment::CALL_OUT
+ @appointment.status = RedmineQboCalendar::AppointmentStatus.default.key unless @appointment.call_out?
@appointment.date = (params[:start_date].to_date + 9.hours) if params[:start_date].present?
@appointment.customer_id = params[:customer_id] if params[:customer_id].present?
prefill_estimate_and_vehicle
@@ -137,6 +145,7 @@ class CustomerAppointmentsController < ApplicationController
:vehicle_id,
:description,
:status,
+ :event_type,
:user_id,
:date,
:estimated_hours,
diff --git a/app/models/customer_appointment.rb b/app/models/customer_appointment.rb
index 6583378..f4492a9 100644
--- a/app/models/customer_appointment.rb
+++ b/app/models/customer_appointment.rb
@@ -22,6 +22,11 @@ class CustomerAppointment < ActiveRecord::Base
validates :subject, presence: true
validates :date, presence: true
+ # A call-out is about the employee who's off (checked when set, so older call-outs without one still save)
+ validates :user, presence: true, if: -> { call_out? && (new_record? || will_save_change_to_user_id?) }
+
+ # Call-outs have no customer side; appointments get the default status when none is chosen
+ before_validation :prepare_entry
# Prevent scheduling on non-working days or holidays
validate :validate_working_day
@@ -32,25 +37,32 @@ class CustomerAppointment < ActiveRecord::Base
# Capitalize the first letter only; titleize mangled vehicle names and acronyms (JL -> Jl, LED -> Led)
normalizes :subject, with: ->(subject) { subject.strip.sub(/\A[a-z]/, &:upcase) }
- STATUSES = %w[
- Scheduled
- Checked_In
- In_Progress
- Ready
- Completed
- Cancelled
- Call_Out
- ]
+ # An employee off work (sick, a day off): shown on the calendar, but not an appointment with a customer
+ CALL_OUT = 'call_out'
- # Statuses whose time should not count toward scheduled hours totals
- NON_SCHEDULED_STATUSES = %w[
- Cancelled
- Call_Out
- ]
+ # The statuses set up in the plugin settings (see RedmineQboCalendar::AppointmentStatus)
+ def self.statuses
+ RedmineQboCalendar::AppointmentStatus.all
+ end
- # False for cancelled / call-out appointments, which stay on the calendar but free up their hours
+ # Status keys, for other plugins' settings (e.g. redmine_qbo_reminders' "statuses that get reminders")
+ def self.status_options
+ statuses.map { |s| [s.name, s.key] }
+ end
+
+ def call_out?
+ event_type == CALL_OUT
+ end
+
+ # This appointment's status from the settings; nil for call-outs, which have none
+ def status_record
+ return nil if call_out?
+ RedmineQboCalendar::AppointmentStatus.find(status) || RedmineQboCalendar::AppointmentStatus.default
+ end
+
+ # False for call-outs and statuses like Cancelled, which stay on the calendar but free up their hours
def counts_toward_hours?
- !NON_SCHEDULED_STATUSES.include?(status.to_s)
+ !call_out? && status_record.counts_hours?
end
# Cast datetime to Date for Redmine Calendar compatibility
@@ -97,6 +109,21 @@ class CustomerAppointment < ActiveRecord::Base
Rails.logger.info "[CustomerAppointment] #{msg}"
end
+ def prepare_entry
+ if call_out?
+ self.customer = nil
+ self.vehicle = nil
+ self.estimate = nil
+ self.status = nil
+ self.estimated_hours = 0
+ self.subject = I18n.t(:label_call_out_subject, name: user.name) if subject.blank? && user
+ else
+ self.event_type = nil
+ self.status = RedmineQboCalendar::AppointmentStatus.default.key if status.blank?
+ end
+ self.description = description.to_s
+ end
+
# Checked when the estimate or the hours change, so changing just the status (the quick status buttons)
# never fails on an older appointment
def validate_hours_cover_estimate
diff --git a/app/views/common/_calendar.html.erb b/app/views/common/_calendar.html.erb
index 55b6b4b..fe4f132 100644
--- a/app/views/common/_calendar.html.erb
+++ b/app/views/common/_calendar.html.erb
@@ -102,11 +102,8 @@
end
%>
-<%# Calendar Status Legend Key %>
-<%
- # Collect status keys from CustomerAppointment enum
- statuses = CustomerAppointment::STATUSES
-%>
+<%# Calendar Status Legend Key: the statuses set up in the plugin settings, then call-outs %>
+<% statuses = CustomerAppointment.statuses %>
<% if statuses.any? %>
@@ -114,12 +111,14 @@
<%= l(:label_legend, default: 'Legend') %>:
- <% statuses.each do |status_key| %>
-
- <%= status_key.humanize %>
+ <% statuses.each do |status| %>
+
+ <%= status.name %>
<% end %>
+
+ <%= l(:label_call_out) %>
+
<% end %>
@@ -189,14 +188,17 @@
standard_events = only_appointments ? [] : calendar.events_on(day).reject { |e| e.is_a?(CustomerAppointment) }
matching_appointments = all_appointments.select { |app| appointment_occurs_on.call(app, day) }
+ # Call-outs first (who's off that day), then everything else by time
day_events = (standard_events + matching_appointments).sort_by do |event|
- if event.is_a?(CustomerAppointment) && event.date.present?
- event.date.strftime('%H:%M:%S')
- elsif event.respond_to?(:start_date) && event.start_date.present?
- event.start_date.to_time.strftime('%H:%M:%S')
- else
- '00:00:00'
- end
+ call_out = event.is_a?(CustomerAppointment) && event.call_out? ? 0 : 1
+ time = if event.is_a?(CustomerAppointment) && event.date.present?
+ event.date.strftime('%H:%M:%S')
+ elsif event.respond_to?(:start_date) && event.start_date.present?
+ event.start_date.to_time.strftime('%H:%M:%S')
+ else
+ '00:00:00'
+ end
+ [call_out, time]
end
day_total_hours = day_events.sum { |event| calculate_event_hours.call(event, day) }
@@ -258,6 +260,10 @@
new_customer_appointment_path(start_date: day),
class: 'icon-only icon-add',
title: l(:label_appointment_new, default: 'New Appointment') %>
+ <%= link_to new_customer_appointment_path(start_date: day, event_type: CustomerAppointment::CALL_OUT),
+ class: 'calendar-add-call-out', title: l(:label_new_call_out) do %>
+
+ <% end %>
<% end %>
<% end %>
diff --git a/app/views/customer_appointments/_calendar_event.html.erb b/app/views/customer_appointments/_calendar_event.html.erb
index 47c2568..7e56f9b 100644
--- a/app/views/customer_appointments/_calendar_event.html.erb
+++ b/app/views/customer_appointments/_calendar_event.html.erb
@@ -22,7 +22,11 @@
end
%>
-<%= tag.div class: ['appointment-block', 'tooltip', appointment.status.to_s.parameterize] do %>
+<%
+ status = appointment.status_record
+ css = ['appointment-block', 'tooltip', (appointment.call_out? ? 'call-out' : status.key.parameterize), ('no-hours' if status && !status.counts_hours?)]
+%>
+<%= tag.div class: css.compact, style: status&.style do %>
@@ -51,9 +55,14 @@
(Day <%= day_number %> of <%= duration %>)
<% end %>
-
- <%= number_with_precision(appointment.estimated_hours.to_f, precision: 1) %>h
-
+ <%# Call-outs don't use hours %>
+ <% if appointment.call_out? %>
+
+ <% else %>
+
+ <%= number_with_precision(appointment.estimated_hours.to_f, precision: 1) %>h
+
+ <% end %>
<%# Row 3: Details %>
diff --git a/app/views/customer_appointments/_form.html.erb b/app/views/customer_appointments/_form.html.erb
index b1d0df6..48979be 100644
--- a/app/views/customer_appointments/_form.html.erb
+++ b/app/views/customer_appointments/_form.html.erb
@@ -4,6 +4,21 @@
<%= error_messages_for @appointment %>
+ <%= f.hidden_field :event_type %>
+ <% if @appointment.call_out? %>
+ <%# An employee off work: no customer, vehicle, estimate, hours or status %>
+
+ <%= l(:label_employee) %> *
+ <%= f.collection_select :user_id, User.active.sorted, :id, :name, { include_blank: true }, { label: false } %>
+
+
+
+ <%= f.text_field :subject, style: "width: 95%;", placeholder: l(:text_call_out_subject_placeholder) %>
+
+
+
<%= f.datetime_local_field :date %>
+
<%= f.number_field :duration, step: 1, size: 6, label: :label_duration %>
+ <% else %>
<%= f.text_field :subject, required: true, style: "width: 95%;" %>
@@ -33,7 +48,11 @@
<%= f.number_field :estimated_hours, step: 1, size: 6 %>
<%= f.number_field :duration, step: 1, size: 6, label: :label_duration %>
-
<%= f.select :status, CustomerAppointment::STATUSES, label: :field_status %>
+ <%# The statuses set up in the plugin settings, plus a removed one this appointment still has %>
+ <% status_options = CustomerAppointment.status_options %>
+ <% status_options += [[@appointment.status_record.name, @appointment.status]] if @appointment.status.present? && !@appointment.status_record.known? %>
+
<%= f.select :status, status_options, label: :field_status %>
+ <% end %>
<%= f.text_area :description,
diff --git a/app/views/customer_appointments/_list.html.erb b/app/views/customer_appointments/_list.html.erb
index 6bb1726..7b85e86 100644
--- a/app/views/customer_appointments/_list.html.erb
+++ b/app/views/customer_appointments/_list.html.erb
@@ -60,7 +60,7 @@
-<%= appointment.status %>
+<%= appointment_status_badge(appointment) %>
diff --git a/app/views/customer_appointments/_list_simple.html.erb b/app/views/customer_appointments/_list_simple.html.erb
index 6142a03..1a7c798 100644
--- a/app/views/customer_appointments/_list_simple.html.erb
+++ b/app/views/customer_appointments/_list_simple.html.erb
@@ -19,11 +19,7 @@
<%= link_to appointment.user unless appointment.user.nil? %>
<%= format_date(appointment.date) %>
- <% if appointment.status.present? %>
-
- <%= appointment.status.to_s.humanize %>
-
- <% end %>
+ <%= appointment_status_badge(appointment) %>
<% end %>
diff --git a/app/views/customer_appointments/_tooltip.html.erb b/app/views/customer_appointments/_tooltip.html.erb
index 548b14a..063616b 100644
--- a/app/views/customer_appointments/_tooltip.html.erb
+++ b/app/views/customer_appointments/_tooltip.html.erb
@@ -4,7 +4,7 @@
- <%= appointment.status.to_s.humanize %>
+ <%= appointment.call_out? ? l(:label_call_out) : appointment.status_record.name %>
@@ -38,7 +38,7 @@
<% if appointment.user %>
- <%= l(:label_technician) %>
+ <%= l(appointment.call_out? ? :label_employee : :label_technician) %>
<%= avatar(appointment.user, size: 16) %>
<%= link_to appointment.user %>
@@ -74,10 +74,12 @@
<% end %>
+ <% unless appointment.call_out? %>
<%= l(:label_estimated_hours) %>
<%= number_with_precision(appointment.estimated_hours, precision: 1) %> hrs
+ <% end %>
<%= l(:label_duration) %>
diff --git a/app/views/customer_appointments/edit.html.erb b/app/views/customer_appointments/edit.html.erb
index f335eb6..0796512 100644
--- a/app/views/customer_appointments/edit.html.erb
+++ b/app/views/customer_appointments/edit.html.erb
@@ -1,3 +1,3 @@
-<%=l(:label_edit_appointment)%>
+<%= l(@appointment.call_out? ? :label_edit_call_out : :label_edit_appointment) %>
-<%= render "form" %>
\ No newline at end of file
+<%= render "form" %>
diff --git a/app/views/customer_appointments/history.html.erb b/app/views/customer_appointments/history.html.erb
index 6b67e71..993a1d3 100644
--- a/app/views/customer_appointments/history.html.erb
+++ b/app/views/customer_appointments/history.html.erb
@@ -35,7 +35,7 @@
<%= l(:field_status) %>
<%= select_tag :status,
- options_for_select(CustomerAppointment::STATUSES.map { |s| [s.humanize, s] }, @status),
+ options_for_select(CustomerAppointment.status_options + [[l(:label_call_out_plural), CustomerAppointment::CALL_OUT]], @status),
include_blank: l(:label_all_statuses) %>
<%= l(:label_date_from) %>
@@ -80,11 +80,7 @@
<%= link_to_user(appointment.user) if appointment.user %>
<%= appointment.duration %> <%= l(:label_days) %>
- <% if appointment.status.present? %>
-
- <%= appointment.status.to_s.humanize %>
-
- <% end %>
+ <%= appointment_status_badge(appointment) %>
<% end %>
diff --git a/app/views/customer_appointments/new.html.erb b/app/views/customer_appointments/new.html.erb
index 1477291..2c7dbdc 100644
--- a/app/views/customer_appointments/new.html.erb
+++ b/app/views/customer_appointments/new.html.erb
@@ -1,3 +1,3 @@
-<%=l(:label_new_appointment)%>
+<%= l(@appointment.call_out? ? :label_new_call_out : :label_new_appointment) %>
-<%= render "form" %>
\ No newline at end of file
+<%= render "form" %>
diff --git a/app/views/customer_appointments/show.html.erb b/app/views/customer_appointments/show.html.erb
index 1dd68ff..e6b361e 100644
--- a/app/views/customer_appointments/show.html.erb
+++ b/app/views/customer_appointments/show.html.erb
@@ -8,7 +8,7 @@
<%= l(:label_appointment_history) %>
<% end %>
<% end %>
- <% if User.current.allowed_to?(:add_customer_appointments, nil, global: true) %>
+ <% if !@appointment.call_out? && User.current.allowed_to?(:add_customer_appointments, nil, global: true) %>
<%= link_to new_issue_path(issue: { customer_id: @appointment.customer_id, vehicle_id: @appointment.vehicle_id, estimate_id: @appointment.estimate_id }), target: :_blank do %>
<%= l(:label_new_issue) %>
<% end %>
@@ -53,19 +53,15 @@
-<% if User.current.allowed_to?(:edit_customer_appointments, nil, global: true) %>
- <%# Quick Status Action Buttons %>
- <%
- statuses = CustomerAppointment::STATUSES
- current_status = @appointment.status.to_s.parameterize.underscore
- %>
+<%# Quick status buttons; call-outs have no status %>
+<% if !@appointment.call_out? && User.current.allowed_to?(:edit_customer_appointments, nil, global: true) %>
<%= l(:label_change_status, default: 'Change Status:') %>
- <% statuses.reject { |s| s == current_status }.each do |status_key| %>
- <%= link_to status_key.humanize,
- customer_appointment_path(@appointment, customer_appointment: { status: status_key }),
+ <% CustomerAppointment.statuses.reject { |s| s.key == @appointment.status_record.key }.each do |status| %>
+ <%= link_to status.name,
+ customer_appointment_path(@appointment, customer_appointment: { status: status.key }),
method: :patch,
- class: "quick-status-btn status-#{status_key.parameterize}" %>
+ class: 'quick-status-btn', style: status.style %>
<% end %>
<% end %>
@@ -74,6 +70,13 @@
+ <% if @appointment.call_out? %>
+ <%# A call-out is about the employee who's off, not a customer %>
+
+
<%= l(:label_employee) %>:
+
<%= link_to_user(@appointment.user) %>
+
+ <% else %>
<%= l(:label_customer, default: 'Customer') %>:
<%= link_to_if @appointment.customer, @appointment.customer&.name, @appointment.customer %>
@@ -92,15 +95,14 @@
<%= link_to @appointment.estimate, @appointment.estimate, target: "_blank" %>
<% end %>
+ <% end %>
<%= l(:field_status) %>:
-
- <%= @appointment.status.to_s.humanize %>
-
+ <%= appointment_status_badge(@appointment) %>
@@ -109,18 +111,22 @@
<%= @appointment.date ? @appointment.date.strftime('%I:%M %p') : '-' %>
+ <% unless @appointment.call_out? %>
<%= l(:field_user) %>:
<%= link_to_user(@appointment.user) %>
+ <% end %>
<%= l(:label_duration, default: 'Duration') %>:
<%= @appointment.duration %> <%= l(:label_days) %>
+ <% unless @appointment.call_out? %>
<%= l(:field_estimated_hours) %>:
<%= @appointment.estimated_hours %> <%= l(:label_hours) %>
+ <% end %>
diff --git a/app/views/my/blocks/_upcoming_appointments.html.erb b/app/views/my/blocks/_upcoming_appointments.html.erb
index bf335c3..1645c66 100644
--- a/app/views/my/blocks/_upcoming_appointments.html.erb
+++ b/app/views/my/blocks/_upcoming_appointments.html.erb
@@ -66,8 +66,7 @@
<% expanded_appointments.each do |item| %>
<% appt = item[:appointment] %>
- <% status_slug = appt.status.to_s.parameterize %>
-
+
<%= link_to appt.subject, customer_appointment_path(appt) %>
<% if item[:total_days] > 1 %>
@@ -84,11 +83,7 @@
<%= format_date(item[:date]) %>
- <% if appt.status.present? %>
-
- <%= appt.status.to_s.humanize %>
-
- <% end %>
+ <%= appointment_status_badge(appt, css: 'badge status-badge') %>
<% end %>
diff --git a/app/views/settings/_qbo_calendar.html.erb b/app/views/settings/_qbo_calendar.html.erb
new file mode 100644
index 0000000..bd27cd6
--- /dev/null
+++ b/app/views/settings/_qbo_calendar.html.erb
@@ -0,0 +1,128 @@
+<%
+ statuses = RedmineQboCalendar::AppointmentStatus.all
+ # How many appointments use each status: removing one in use asks where to move them
+ in_use = CustomerAppointment.where(event_type: nil).group(:status).count
+ status_row = lambda do |index, status|
+ count = status ? in_use[status.key].to_i : 0
+ name = "settings[statuses][#{index}]"
+ content_tag(:tr, class: 'appointment-status-row', data: { in_use: count }) do
+ safe_join([
+ content_tag(:td, sprite_icon('reorder'), class: 'appointment-status-handle', title: l(:label_drag_to_reorder_status)),
+ content_tag(:td, safe_join([
+ hidden_field_tag("#{name}[key]", status&.key, id: nil),
+ text_field_tag("#{name}[name]", status&.name, id: nil, size: 24, class: 'appointment-status-name',
+ 'aria-label': l(:field_name))
+ ])),
+ content_tag(:td, color_field_tag("#{name}[color]", status&.color || '#1fc0ff', id: nil,
+ class: 'appointment-status-color', 'aria-label': l(:field_color))),
+ content_tag(:td, safe_join([
+ hidden_field_tag("#{name}[counts_hours]", '0', id: nil),
+ check_box_tag("#{name}[counts_hours]", '1', status.nil? || status.counts_hours?, id: nil,
+ 'aria-label': l(:label_status_counts_hours))
+ ]), class: 'appointment-status-hours'),
+ content_tag(:td, content_tag(:span, status&.name || l(:label_new_status), class: 'status-badge appointment-status-preview',
+ style: "--status-color: #{status&.color || '#1fc0ff'}")),
+ content_tag(:td, count.positive? ? l(:label_status_in_use, count: count) : '', class: 'appointment-status-count'),
+ content_tag(:td, link_to(sprite_icon('del', l(:button_delete)), '#', class: 'icon-only icon-del appointment-status-remove',
+ title: l(:button_delete)), class: 'buttons')
+ ])
+ end
+ end
+%>
+
+
+ <%= l(:label_appointment_statuses) %>
+ <%= l(:text_appointment_statuses) %>
+
+
+
+
+
+ <%= l(:field_name) %>
+ <%= l(:field_color) %>
+ <%= l(:label_status_counts_hours) %>
+ <%= l(:label_preview) %>
+
+
+
+
+
+ <% statuses.each_with_index do |status, index| %>
+ <%= status_row.call(index, status) %>
+ <% end %>
+
+
+
+
+ <%= status_row.call('NEW_STATUS', nil) %>
+
+
+
+ <%= link_to sprite_icon('add', l(:button_add_status)), '#', id: 'appointment-status-add', class: 'icon icon-add' %>
+
+ <%= l(:text_call_outs_not_statuses) %>
+
+
+<%= javascript_tag do %>
+ $(function () {
+ var $body = $('#appointment-statuses');
+ $body.sortable({ handle: '.appointment-status-handle', axis: 'y' });
+
+ // The preview badge follows the name and colour
+ $body.on('input', '.appointment-status-name, .appointment-status-color', function () {
+ var $row = $(this).closest('tr');
+ var $preview = $row.find('.appointment-status-preview');
+ $preview.text($row.find('.appointment-status-name').val() || <%= raw l(:label_new_status).to_json %>);
+ $preview[0].style.setProperty('--status-color', $row.find('.appointment-status-color').val());
+ });
+
+ $('#appointment-status-add').on('click', function (e) {
+ e.preventDefault();
+ var html = $('#appointment-status-template').html().replace(/NEW_STATUS/g, 'new' + Date.now());
+ $body.append(html);
+ $body.find('tr:last .appointment-status-name').focus();
+ });
+
+ // Removing a status its appointments use: its row becomes a choice of status to move them to (done when
+ // the settings are saved), or keeping it (shown grey). Undo puts the row back.
+ $body.on('click', '.appointment-status-remove', function (e) {
+ e.preventDefault();
+ var $row = $(this).closest('tr');
+ var count = parseInt($row.data('in-use'), 10) || 0;
+ var key = $row.find('input[name$="[key]"]').val();
+ if (!count || !key) { $row.remove(); return; }
+
+ var $select = $('').attr('name', 'settings[status_moves][' + key + ']');
+ $body.find('tr.appointment-status-row').not($row).each(function () {
+ var otherKey = $(this).find('input[name$="[key]"]').val();
+ if (otherKey) $select.append($('').val(otherKey).text($(this).find('.appointment-status-name').val()));
+ });
+ $select.append($(' ').val('').text(<%= raw l(:label_keep_removed_status).to_json %>));
+
+ var text = <%= raw l(:text_move_status_appointments).to_json %>
+ .replace('%{count}', count).replace('%{name}', $row.find('.appointment-status-name').val());
+ var $move = $('').append(
+ $(''),
+ $(' ').append($('').text(text + ' '), $select),
+ $(' ').append(
+ $('').text(<%= raw l(:button_undo_remove_status).to_json %>)));
+ $move.data('row', $row);
+ $row.after($move).detach();
+ });
+
+ $body.on('click', '.appointment-status-undo', function (e) {
+ e.preventDefault();
+ var $move = $(this).closest('tr');
+ $move.replaceWith($move.data('row'));
+ });
+ });
+<% end %>
+
+
diff --git a/assets/stylesheets/customer_appointments.css b/assets/stylesheets/customer_appointments.css
index 0f5a1be..ac2fb62 100644
--- a/assets/stylesheets/customer_appointments.css
+++ b/assets/stylesheets/customer_appointments.css
@@ -267,134 +267,41 @@ h2 .appointment-title {
}
/* ==========================================================================
- Custom High-Vibrancy Hex Status Themes & Tinted Tooltips
+ Status colours: each status's colour (set in the plugin settings) arrives as --status-color
========================================================================== */
-/* Scheduled - #1FC0FF */
-.appointment-block.scheduled,
-.appointment-block.scheduled:hover,
-.appointment-block.scheduled.open { background: #e8f8ff !important; border-color: #91e2ff !important; }
-.appointment-block.scheduled .appointment-bar { background-color: #1fc0ff !important; }
-.appointment-block.scheduled .appointment-divider { border-top-color: #b3ebff !important; }
-.appointment-block.scheduled .tip,
-.appointment-block.scheduled:hover .tip,
-.appointment-block.scheduled.open .tip { background: #f2faff !important; border-color: #70d6ff !important; }
+.appointment-block,
+.appointment-block:hover,
+.appointment-block.open {
+ background: color-mix(in srgb, var(--status-color, #1fc0ff) 10%, #fff) !important;
+ border-color: color-mix(in srgb, var(--status-color, #1fc0ff) 50%, #fff) !important;
+}
+.appointment-block .appointment-bar { background-color: var(--status-color, #1fc0ff) !important; }
+.appointment-block .appointment-divider { border-top-color: color-mix(in srgb, var(--status-color, #1fc0ff) 30%, #fff) !important; }
+.appointment-block .tip,
+.appointment-block:hover .tip,
+.appointment-block.open .tip {
+ background: color-mix(in srgb, var(--status-color, #1fc0ff) 5%, #fff) !important;
+ border-color: color-mix(in srgb, var(--status-color, #1fc0ff) 65%, #fff) !important;
+}
-/* Ready - #1FFF1F */
-.appointment-block.ready,
-.appointment-block.ready:hover,
-.appointment-block.ready.open { background: #e8ffe8 !important; border-color: #8bff8b !important; }
-.appointment-block.ready .appointment-bar { background-color: #1fff1f !important; }
-.appointment-block.ready .appointment-divider { border-top-color: #b5ffb5 !important; }
-.appointment-block.ready .tip,
-.appointment-block.ready:hover .tip,
-.appointment-block.ready.open .tip { background: #f2fff2 !important; border-color: #66ff66 !important; }
-
-/* CheckedIn - #CE1FFF */
-.appointment-block.checked-in,
-.appointment-block.checkedin,
-.appointment-block.checked_in,
-.appointment-block.checked-in:hover,
-.appointment-block.checkedin:hover,
-.appointment-block.checked_in:hover,
-.appointment-block.checked-in.open,
-.appointment-block.checkedin.open,
-.appointment-block.checked_in.open { background: #f8e8ff !important; border-color: #e891ff !important; }
-
-.appointment-block.checked-in .appointment-bar,
-.appointment-block.checkedin .appointment-bar,
-.appointment-block.checked_in .appointment-bar { background-color: #ce1fff !important; }
-
-.appointment-block.checked-in .appointment-divider,
-.appointment-block.checkedin .appointment-divider,
-.appointment-block.checked_in .appointment-divider { border-top-color: #f0b3ff !important; }
-
-.appointment-block.checked-in .tip,
-.appointment-block.checkedin .tip,
-.appointment-block.checked_in .tip,
-.appointment-block.checked-in:hover .tip,
-.appointment-block.checkedin:hover .tip,
-.appointment-block.checked_in:hover .tip,
-.appointment-block.checked-in.open .tip,
-.appointment-block.checkedin.open .tip,
-.appointment-block.checked_in.open .tip { background: #fcf2ff !important; border-color: #df70ff !important; }
-
-/* InProgress - #FF5E1F */
-.appointment-block.in-progress,
-.appointment-block.inprogress,
-.appointment-block.in_progress,
-.appointment-block.in-progress:hover,
-.appointment-block.inprogress:hover,
-.appointment-block.in_progress:hover,
-.appointment-block.in-progress.open,
-.appointment-block.inprogress.open,
-.appointment-block.in_progress.open { background: #fff0e8 !important; border-color: #ffb391 !important; }
-
-.appointment-block.in-progress .appointment-bar,
-.appointment-block.inprogress .appointment-bar,
-.appointment-block.in_progress .appointment-bar { background-color: #ff5e1f !important; }
-
-.appointment-block.in-progress .appointment-divider,
-.appointment-block.inprogress .appointment-divider,
-.appointment-block.in_progress .appointment-divider { border-top-color: #ffccb3 !important; }
-
-.appointment-block.in-progress .tip,
-.appointment-block.inprogress .tip,
-.appointment-block.in_progress .tip,
-.appointment-block.in-progress:hover .tip,
-.appointment-block.inprogress:hover .tip,
-.appointment-block.in_progress:hover .tip,
-.appointment-block.in-progress.open .tip,
-.appointment-block.inprogress.open .tip,
-.appointment-block.in_progress.open .tip { background: #fff6f2 !important; border-color: #ff9970 !important; }
-
-/* Completed - #008000 */
-.appointment-block.completed,
-.appointment-block.completed:hover,
-.appointment-block.completed.open { background: #e6f5e6 !important; border-color: #80c080 !important; }
-.appointment-block.completed .appointment-bar { background-color: #008000 !important; }
-.appointment-block.completed .appointment-divider { border-top-color: #a3d9a3 !important; }
-.appointment-block.completed .tip,
-.appointment-block.completed:hover .tip,
-.appointment-block.completed.open .tip { background: #f0fcf0 !important; border-color: #66b366 !important; }
-
-/* Cancelled - #FF1F1F & Strikethrough */
-.appointment-block.cancelled,
-.appointment-block.canceled,
-.appointment-block.cancelled:hover,
-.appointment-block.canceled:hover,
-.appointment-block.cancelled.open,
-.appointment-block.canceled.open { background: #ffe8e8 !important; border-color: #ff9191 !important; }
-
-.appointment-block.cancelled .appointment-bar,
-.appointment-block.canceled .appointment-bar { background-color: #ff1f1f !important; }
-
-.appointment-block.cancelled .appointment-divider,
-.appointment-block.canceled .appointment-divider { border-top-color: #ffb3b3 !important; }
-
-.appointment-block.cancelled .tip,
-.appointment-block.canceled .tip,
-.appointment-block.cancelled:hover .tip,
-.appointment-block.canceled:hover .tip,
-.appointment-block.cancelled.open .tip,
-.appointment-block.canceled.open .tip { background: #fff2f2 !important; border-color: #ff7070 !important; }
-
-.appointment-block.cancelled .appointment-title,
-.appointment-block.cancelled .appointment-link,
-.appointment-block.canceled .appointment-title,
-.appointment-block.canceled .appointment-link {
+/* Statuses that don't count toward the hours (e.g. Cancelled) */
+.appointment-block.no-hours .appointment-title,
+.appointment-block.no-hours .appointment-link {
text-decoration: line-through;
}
-/* Call Out - #FFFF00 */
-.appointment-block.call_out,
-.appointment-block.call_out:hover,
-.appointment-block.call_out.open { background: hsl(60, 100%, 95%) !important; border-color: hsl(60, 100%, 50%) !important; }
-.appointment-block.call_out .appointment-bar { background-color: hsl(60, 100%, 45%) !important; }
-.appointment-block.call_out .appointment-divider { border-top-color: hsl(60, 100%, 80%) !important; }
-.appointment-block.call_out .tip,
-.appointment-block.call_out:hover .tip,
-.appointment-block.call_out.open .tip { background: hsl(60, 100%, 97%) !important; border-color: hsl(60, 100%, 60%) !important; }
+/* Call-outs: an employee off work, not a customer appointment */
+.appointment-block.call-out,
+.appointment-block.call-out:hover,
+.appointment-block.call-out.open {
+ background: repeating-linear-gradient(-45deg, #fdeceb, #fdeceb 6px, #f8d7d4 6px, #f8d7d4 12px) !important;
+ border: 1px dashed #d52b1e !important;
+}
+.appointment-block.call-out .appointment-bar { background-color: #d52b1e !important; }
+.appointment-block.call-out .appointment-divider { border-top-color: #f0b4ae !important; }
+.appointment-block.call-out .tip { background: #fff !important; border-color: #d52b1e !important; }
+.appointment-block.call-out .appointment-call-out-label { color: #b3261b; font-size: .9em; }
/* Table List Alignment */
table.appointments td,
@@ -449,61 +356,22 @@ table.appointments td.status {
}
/* ==========================================================================
- Badges & Quick Action Buttons
+ Badges & Quick Action Buttons, in the status's colour
========================================================================== */
-/* Scheduled - #1FC0FF */
-.status-scheduled {
- background-color: #e8f8ff !important;
- border-color: #91e2ff !important;
- color: #0077a3 !important;
+.status-badge,
+.quick-status-btn,
+.status-key-badge {
+ background-color: color-mix(in srgb, var(--status-color, #8d9096) 12%, #fff) !important;
+ border: 1px solid color-mix(in srgb, var(--status-color, #8d9096) 50%, #fff) !important;
+ color: color-mix(in srgb, var(--status-color, #8d9096) 65%, #000) !important;
}
-/* Ready - #1FFF1F */
-.status-ready {
- background-color: #e8ffe8 !important;
- border-color: #8bff8b !important;
- color: #008f00 !important;
-}
-
-/* CheckedIn - #CE1FFF */
-.status-checked-in,
-.status-checkedin,
-.status-checked_in {
- background-color: #f8e8ff !important;
- border-color: #e891ff !important;
- color: #8300ad !important;
-}
-
-/* InProgress - #FF5E1F */
-.status-in-progress,
-.status-inprogress,
-.status-in_progress {
- background-color: #fff0e8 !important;
- border-color: #ff9191 !important;
- color: #b33000 !important;
-}
-
-/* Completed - #008000 */
-.status-completed {
- background-color: #e6f5e6 !important;
- border-color: #80c080 !important;
- color: #005200 !important;
-}
-
-/* Cancelled - #FF1F1F */
-.status-cancelled,
-.status-canceled {
- background-color: #ffe8e8 !important;
- border-color: #ff9191 !important;
- color: #b30000 !important;
-}
-
-/* Completed - #FFFF00 */
-.status-call_out {
- background-color: hwb(60 0% 0%) !important;
- border-color: lab(0% 0 0) !important;
- color: hwb(60 0% 100%) !important;
+.status-badge.status-call-out,
+.status-key-badge.status-call-out {
+ background: repeating-linear-gradient(-45deg, #fdeceb, #fdeceb 4px, #f8d7d4 4px, #f8d7d4 8px) !important;
+ border: 1px dashed #d52b1e !important;
+ color: #9c1f16 !important;
}
/* Redefine grid column proportions for the calendar layout */
@@ -645,3 +513,14 @@ table.estimate-issues-preview tr.created td {
.estimate-issue-fields .estimate-issue-fields-info {
padding-left: 0;
}
+
+/* Calendar day: add a call-out, next to the add appointment button */
+.calendar-add-call-out {
+ margin-left: 6px;
+ color: #8d9096;
+ font-size: 0.85em;
+ text-decoration: none !important;
+}
+.calendar-add-call-out:hover {
+ color: #393a3d;
+}
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 5c7af1a..6b3146a 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -88,3 +88,31 @@ en:
title_customer_appointments: Customer Appointments
error_hours_less_than_estimate: "The hours can't be less than the %{hours} labor hours on estimate #%{estimate}"
label_estimate_issues: "Issues for estimate #%{estimate}"
+
+ # Call-outs: an employee off work, shown on the calendar (not a customer appointment)
+ label_call_out: "Call-out"
+ label_call_out_plural: "Call-outs"
+ label_call_out_subject: "%{name} called out"
+ label_employee: "Employee"
+ label_new_call_out: "New Call-out"
+ label_edit_call_out: "Edit Call-out"
+ text_call_out_subject_placeholder: "Left blank: \" called out\""
+
+ # Appointment statuses (plugin settings)
+ label_appointment_statuses: "Appointment statuses"
+ text_appointment_statuses: "The first status is the default for new appointments. Drag to reorder. Statuses that don't count toward hours (e.g. Cancelled) stay on the calendar, crossed out, but free up their time."
+ text_call_outs_not_statuses: "Employee call-outs aren't a status: add them from the calendar with the call-out button next to each day's add button."
+ field_color: "Colour"
+ label_status_counts_hours: "Counts toward hours"
+ label_new_status: "New status"
+ label_status_in_use:
+ one: "Used by 1 appointment"
+ other: "Used by %{count} appointments"
+ button_add_status: "Add a status"
+ label_drag_to_reorder_status: "Drag to reorder"
+ text_move_status_appointments: "Removing \"%{name}\": move its %{count} appointment(s) to"
+ label_keep_removed_status: "(keep it, shown in grey)"
+ button_undo_remove_status: "Undo"
+ notice_appointments_moved:
+ one: "Moved 1 appointment from %{from} to %{to}."
+ other: "Moved %{count} appointments from %{from} to %{to}."
diff --git a/db/migrate/004_convert_call_out_appointments.rb b/db/migrate/004_convert_call_out_appointments.rb
new file mode 100644
index 0000000..f2be98e
--- /dev/null
+++ b/db/migrate/004_convert_call_out_appointments.rb
@@ -0,0 +1,25 @@
+#The MIT License (MIT)
+#
+#Copyright (c) 2026 rick barrette
+#
+#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+#
+#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+#
+#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.
+
+# Call-outs (an employee off work) were a status; they're now their own kind of calendar entry, and statuses
+# are set up in the plugin settings
+class ConvertCallOutAppointments < ActiveRecord::Migration[7.0]
+ def up
+ execute <<~SQL
+ UPDATE customer_appointments SET event_type = 'call_out', status = NULL WHERE status = 'Call_Out'
+ SQL
+ end
+
+ def down
+ execute <<~SQL
+ UPDATE customer_appointments SET status = 'Call_Out', event_type = NULL WHERE event_type = 'call_out'
+ SQL
+ end
+end
diff --git a/init.rb b/init.rb
index 75a5cab..1923faa 100644
--- a/init.rb
+++ b/init.rb
@@ -19,8 +19,10 @@ Redmine::Plugin.register :redmine_qbo_calendar do
author_url 'https://barrettefabrication.com'
requires_redmine version_or_higher: '7.0.0'
- # No settings of its own: labor products/services and the issues-from-estimates defaults are set in
- # redmine_qbo's plugin settings
+ # Appointment statuses. Labor products/services and the issues-from-estimates defaults are set in
+ # redmine_qbo's plugin settings.
+ # No saved statuses means the defaults (RedmineQboCalendar::AppointmentStatus::DEFAULTS)
+ settings default: {}, partial: 'settings/qbo_calendar'
# Add Holidays index to the Redmine Administration Menu
menu :admin_menu, :holidays, { controller: 'holidays', action: 'index' }, caption: :label_holiday_plural, html: { class: 'icon icon-list' }
diff --git a/lib/redmine_qbo_calendar.rb b/lib/redmine_qbo_calendar.rb
index c579292..b657051 100644
--- a/lib/redmine_qbo_calendar.rb
+++ b/lib/redmine_qbo_calendar.rb
@@ -15,6 +15,7 @@ module RedmineQboCalendar
User.prepend(RedmineQboCalendar::Patches::UserPatch)
Issue.prepend(RedmineQboCalendar::Patches::IssuePatch)
CalendarsController.prepend(RedmineQboCalendar::Patches::CalendarsControllerPatch)
+ SettingsController.prepend(RedmineQboCalendar::Patches::SettingsControllerPatch)
ApplicationHelper.prepend(RedmineQboCalendar::Patches::ApplicationHelperPatch)
# Hooks
diff --git a/lib/redmine_qbo_calendar/appointment_status.rb b/lib/redmine_qbo_calendar/appointment_status.rb
new file mode 100644
index 0000000..c0b4a72
--- /dev/null
+++ b/lib/redmine_qbo_calendar/appointment_status.rb
@@ -0,0 +1,114 @@
+#The MIT License (MIT)
+#
+#Copyright (c) 2026 rick barrette
+#
+#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+#
+#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+#
+#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
+ # An appointment status, set up in the plugin settings (name, colour, whether its time counts toward the
+ # calendar's hours). Appointments store the status's key, which never changes, so renaming a status
+ # keeps its appointments. The first status is the default for new appointments.
+ class AppointmentStatus
+ # The statuses before they could be set up (an appointment's key is the status it was saved with)
+ DEFAULTS = [
+ { 'key' => 'Scheduled', 'name' => 'Scheduled', 'color' => '#1fc0ff', 'counts_hours' => '1' },
+ { 'key' => 'Checked_In', 'name' => 'Checked in', 'color' => '#ce1fff', 'counts_hours' => '1' },
+ { 'key' => 'In_Progress', 'name' => 'In progress', 'color' => '#ff5e1f', 'counts_hours' => '1' },
+ { 'key' => 'Ready', 'name' => 'Ready', 'color' => '#1fff1f', 'counts_hours' => '1' },
+ { 'key' => 'Completed', 'name' => 'Completed', 'color' => '#008000', 'counts_hours' => '1' },
+ { 'key' => 'Cancelled', 'name' => 'Cancelled', 'color' => '#ff1f1f', 'counts_hours' => '0' }
+ ].freeze
+
+ # Appointments whose status was removed from the settings
+ UNKNOWN_COLOR = '#8d9096'
+
+ attr_reader :key, :name, :color
+
+ def initialize(key:, name:, color:, counts_hours: true, known: true)
+ @key = key
+ @name = name
+ @color = color
+ @counts_hours = counts_hours
+ @known = known
+ end
+
+ # False for statuses like Cancelled: the appointment stays on the calendar but frees up its hours
+ def counts_hours?
+ @counts_hours
+ end
+
+ # False when the status was removed from the settings after appointments used it
+ def known?
+ @known
+ end
+
+ # Sets the colour for the status's badge or calendar block (see customer_appointments.css)
+ def style
+ "--status-color: #{color}"
+ end
+
+ def to_s
+ name
+ end
+
+ def self.all
+ settings = Setting.plugin_redmine_qbo_calendar || {}
+ raw = settings['statuses'] || settings[:statuses]
+ statuses = normalize(raw.presence || DEFAULTS)
+ statuses = normalize(DEFAULTS) if statuses.empty?
+ statuses.map do |s|
+ new(key: s['key'], name: s['name'], color: s['color'], counts_hours: s['counts_hours'] == '1')
+ end
+ end
+
+ def self.default
+ all.first
+ end
+
+ # The status with this key; a removed status keeps showing (grey, with its key as the name)
+ def self.find(key)
+ return nil if key.blank?
+ all.detect { |s| s.key == key.to_s } ||
+ new(key: key.to_s, name: key.to_s.humanize, color: UNKNOWN_COLOR, known: false)
+ end
+
+ # Moves the appointments of removed statuses ({ removed key => new key }), once the settings are saved.
+ # Skipped when the old status is still set up or the new one isn't. Returns what was moved, for the notice
+ # (names: the statuses' names before saving).
+ def self.move_appointments(moves, names: {})
+ statuses = all.index_by(&:key)
+ moves.filter_map do |from, to|
+ next if statuses.key?(from) || !statuses.key?(to)
+
+ count = CustomerAppointment.where(status: from, event_type: [nil, '']).update_all(status: to)
+ Rails.logger.info "[AppointmentStatus] Moved #{count} appointment(s) from #{from} to #{to}"
+ { count: count, from: names[from] || from.humanize, to: statuses[to].name } if count.positive?
+ end
+ end
+
+ # The settings form's rows (a hash by row index, in the order shown, or a list) as a clean list:
+ # rows without a name are dropped, a new row's key comes from its name, and keys are unique
+ def self.normalize(raw)
+ rows = raw.is_a?(Hash) ? raw.values : Array(raw)
+ keys = []
+ rows.filter_map do |row|
+ row = row.to_h.stringify_keys
+ name = row['name'].to_s.strip
+ next if name.empty?
+
+ key = row['key'].to_s.strip.presence || name.gsub(/[^[:alnum:]]+/, '_').gsub(/\A_+|_+\z/, '').presence || 'Status'
+ base = key
+ number = 1
+ key = "#{base}_#{number += 1}" while keys.include?(key)
+ keys << key
+ color = row['color'].to_s.strip
+ color = UNKNOWN_COLOR unless color.match?(/\A#\h{6}\z/)
+ { 'key' => key, 'name' => name, 'color' => color.downcase, 'counts_hours' => row['counts_hours'].to_s == '1' ? '1' : '0' }
+ end
+ end
+ end
+end
diff --git a/lib/redmine_qbo_calendar/patches/application_helper_patch.rb b/lib/redmine_qbo_calendar/patches/application_helper_patch.rb
index 71282f8..99d8a91 100644
--- a/lib/redmine_qbo_calendar/patches/application_helper_patch.rb
+++ b/lib/redmine_qbo_calendar/patches/application_helper_patch.rb
@@ -12,6 +12,15 @@ module RedmineQboCalendar
module Patches
module ApplicationHelperPatch
+ # The appointment's status as a badge in the status's colour, or "Call-out" for an employee's call-out
+ def appointment_status_badge(appointment, css: 'status-badge')
+ if appointment.call_out?
+ content_tag(:span, l(:label_call_out), class: "#{css} status-call-out")
+ elsif (status = appointment.status_record)
+ content_tag(:span, status.name, class: css, style: status.style)
+ end
+ end
+
def favicon
if calendar_or_appointments_view?
tag.link(rel: 'icon', type: 'image/png', href: favicon_path)
diff --git a/lib/redmine_qbo_calendar/patches/settings_controller_patch.rb b/lib/redmine_qbo_calendar/patches/settings_controller_patch.rb
new file mode 100644
index 0000000..8339801
--- /dev/null
+++ b/lib/redmine_qbo_calendar/patches/settings_controller_patch.rb
@@ -0,0 +1,31 @@
+# The MIT License (MIT)
+#
+# Copyright (c) 2026 rick barrette
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+#
+# 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
+ module Patches
+ # Saving this plugin's settings: appointments with a removed status are moved to the status chosen for
+ # them on the settings page (settings[status_moves][removed key] = new key)
+ module SettingsControllerPatch
+
+ def plugin
+ moves = params[:settings]&.delete(:status_moves) if request.post? && params[:id] == 'redmine_qbo_calendar'
+ # The removed statuses' names, for the notice
+ names = RedmineQboCalendar::AppointmentStatus.all.to_h { |s| [s.key, s.name] } if moves.present?
+ super
+ return if moves.blank?
+
+ moved = RedmineQboCalendar::AppointmentStatus.move_appointments(moves.permit!.to_h, names: names)
+ flash[:notice] = [flash[:notice], *moved.map { |m| l(:notice_appointments_moved, **m) }].compact.join(' ') if moved.any?
+ end
+
+ end
+ end
+end