VIN click-to-copy: shared snippet, last 8 bold only for 17-char VINs

- New vehicles/_vin partial used on the issue page, vehicle page and
  vehicle lists (replaces three copies of the markup, inline onclick
  handlers and a fixed id="copyLink")
- 17-character VINs show the last 8 in bold (what dealerships ask for
  when ordering parts); older or short VINs are shown plain
- Copies the VIN from a data attribute, restores the exact display
  afterwards, shows "Copied!" or "Couldn't copy", falls back when the
  Clipboard API isn't available, and supports Enter/Space; pointer
  cursor and "Click to copy" tooltip
- The copy script is written into the page by the layout hook instead
  of served as copy.js, so it can't 404 when Redmine's asset manifest
  is out of date; one listener handles every VIN on the page
- Issue PDFs split 17-character VINs before the last 8; others whole

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-29 20:09:27 -04:00
1 parent d4684b8ae9
commit 129a9f668c
11 files changed
+111 -53

No files matched your search

@@ -19,8 +19,8 @@ module Vehicles
context[:controller].send(:render_to_string, {
partial: 'issues/show_issue_view_right',
locals: {
vehicle: context[:issue].vehicle ? link_to(context[:issue].vehicle) : nil,
split_vin: context[:issue].vehicle ? context[:issue].vehicle.vin.to_s.scan(/.{1,9}/) : nil
vehicle: context[:issue].vehicle ? link_to(context[:issue].vehicle) : nil,
vin: context[:issue].vehicle&.vin
}
})
end
+9 -1
View File
@@ -20,10 +20,18 @@ module Vehicles
def pdf_left(context={})
output = []
output << [l(:field_vehicles), context[:issue].vehicle ? context[:issue].vehicle.to_s : nil]
output << [l(:field_vin), context[:issue].vehicle ? context[:issue].vehicle.vin.gsub(/(.{9})/, '\1 ') : nil]
output << [l(:field_vin), context[:issue].vehicle ? pdf_vin(context[:issue].vehicle.vin) : nil]
output << [l(:field_notes), context[:issue].vehicle ? context[:issue].vehicle.notes : nil]
return output
end
private
# 17-character VINs are split before the last 8 (what dealerships ask for); others stay whole
def pdf_vin(vin)
vin = vin.to_s
vin.length == 17 ? "#{vin[0, 9]} #{vin[9, 8]}" : vin
end
end
end
+2 -1
View File
@@ -15,7 +15,8 @@ module Vehicles
def view_layouts_base_html_head(context = {})
safe_join([
stylesheet_link_tag('style', plugin: :redmine_qbo_vehicles, media: :all),
javascript_include_tag('copy', plugin: :redmine_qbo_vehicles)
# VIN click-to-copy, written into the page (see vehicles/_copy_vin_script)
context[:hook_caller].render(partial: 'vehicles/copy_vin_script')
])
end