Keep calendar toggles per user; bring back New Customer on appointments

- Hide Past Weeks and Show Customer Appointments Only are saved in each user's
  preferences instead of the session, so they stick across logins and devices.
  Show Customer Appointments Only is on by default.
- The new appointment form's New Customer button had no icon since Redmine 6's SVG
  icons, so it didn't show. It has its icon and label again, for users who may add
  customers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-04 12:48:41 -05:00
1 parent be9bd1bac6
commit f09c4caf9a
3 files changed
+40 -10

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
<%= javascript_include_tag("calendar", plugin: :redmine_qbo_calendar) %>
<%
# Toggles: kept in the session by CalendarsControllerPatch, so month links keep them
# Toggles: each user's own, kept in their preferences by CalendarsControllerPatch (always in params here)
only_appointments = params[:only_appointments] == '1'
hide_past_weeks = params[:hide_past_weeks] == '1'
@@ -24,8 +24,12 @@
<p>
<%= f.text_field :customer, label: :label_customer, class: "customer-name", autocomplete: "off", data: { autocomplete_url: "/customers/autocomplete" } %>
<%= f.hidden_field :customer_id, id: "customer_id" %>
<!-- Add Quick Create Button -->
<a href="#" id="inline-create-customer-btn" class="icon-only icon-add" title="<%=l(:label_new_customer)%>"></a>
<%# Creates the customer in a dialog without leaving the appointment (customer-modal.js), for users who
may add customers %>
<% if User.current.allowed_to?(:add_customers, nil, global: true) %>
<%= link_to sprite_icon('add', l(:label_new_customer)), '#', id: 'inline-create-customer-btn',
class: 'icon icon-add', title: l(:label_new_customer) %>
<% end %>
</p>
<p>
@@ -24,14 +24,14 @@ 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}"
# The "Hide past weeks" and "Show customer appointments only" toggles are each user's own setting,
# kept in their preferences (the session for anonymous users), so they stick across logins,
# browsers and month links (which don't carry them)
CALENDAR_TOGGLES.each do |name, default|
if params.key?(name)
session[key] = params[name] == '1'
elsif session[key]
params[name] = '1'
save_calendar_toggle(name, params[name] == '1')
else
params[name] = calendar_toggle(name, default) ? '1' : '0'
end
end
@@ -84,8 +84,34 @@ module RedmineQboCalendar
@calendar.events = events
end
# Toggle => its value until the user changes it: customer appointments only, past weeks shown
CALENDAR_TOGGLES = { 'only_appointments' => true, 'hide_past_weeks' => false }.freeze
private
def calendar_toggle_key(name)
:"qbo_calendar_#{name}"
end
def calendar_toggle(name, default)
key = calendar_toggle_key(name)
stored = User.current.logged? ? User.current.pref[key] : session[key]
stored.nil? ? default : ActiveModel::Type::Boolean.new.cast(stored)
end
def save_calendar_toggle(name, value)
key = calendar_toggle_key(name)
if User.current.logged?
pref = User.current.pref
return if pref[key] == (value ? '1' : '0')
pref[key] = value ? '1' : '0'
pref.save
else
session[key] = value
end
end
def log(msg)
Rails.logger.info "[CalendarsControllerPatch] #{msg}"
end