Files
redmine_qbo_vehicles/app/views/vehicles/show.html.erb
T
rickyandClaude Opus 5.5 23f4a25070 Vehicle pages: Customers » customer » vehicle trail, actions under it
The vehicle, edit and new vehicle pages' titles are a trail through the vehicle's customer (Vehicles »
vehicle when it has none), and the vehicle page's actions sit under the title like the customer page's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 17:47:25 -05:00

124 lines
3.8 KiB
ERB

<% html_title @vehicle.to_s %>
<%= render partial: 'vehicles/trail', locals: { vehicle: @vehicle, tail: @vehicle.to_s } %>
<%# Under the title, like the customer page (redmine_qbo's qbo-under-title) %>
<div class="contextual qbo-under-title">
<% if User.current.allowed_to?(:edit_vehicles, nil, global: true) %>
<%= link_to sprite_icon('edit', l(:button_edit)), edit_vehicle_path(@vehicle),
class: 'icon icon-edit', accesskey: accesskey(:edit) %>
<% end %>
<%# Vehicles with issues can't be deleted, to keep their service history %>
<% if User.current.allowed_to?(:delete_vehicles, nil, global: true) && !@vehicle.issues.exists? %>
<%= delete_link vehicle_path(@vehicle) %>
<% end %>
</div>
<% unless @vehicle.vin_decoded? %>
<div id="vin-status" class="flash <%= @vehicle.error ? "error" : "notice" %>">
<% if @vehicle.error%>
<%= @vehicle.error %>
<% else %>
<%= t :notice_decoding_vin %>
<% end %>
</div>
<% end %>
<%= render partial: 'vehicles/details', locals: {vehicle: @vehicle} %>
<div class="splitcontent">
<div class="splitcontentleft">
<h4><%=t(:label_estimates)%>:</h4>
<%= render partial: 'estimates/list', locals: {estimates: @vehicle.estimates} %>
</div>
<div class="splitcontentleft">
<h4><%=t(:label_invoices)%>:</h4>
<%= render partial: 'invoices/list', locals: {invoices: @vehicle.invoices} %>
</div>
</div>
<h3><%=@open_issues.count%> <%=t(:label_open_issues)%></h3>
<%= render partial: 'issues/list_simple', locals: {issues: @open_issues} %>
<h3><%=@closed_issues.count%> <%=t(:label_closed_issues)%></h3>
<%= render partial: 'issues/list_simple', locals: {issues: (@closed_issues)} %>
<script>
(function() {
const statusUrl = <%= raw status_vehicle_path(@vehicle).to_json %>;
const timedOutMessage = <%= raw l(:notice_vin_decode_timed_out).to_json %>;
const checkFailedMessage = <%= raw l(:error_vin_status_check_failed).to_json %>;
const alreadyDecoded = <%= @vehicle.vin_decoded? ? 'true' : 'false' %>;
if (alreadyDecoded) return;
const interval = 3000;
let attempts = 0;
const maxAttempts = 40;
const statusEl = document.getElementById("vin-status");
const checkStatus = () => {
fetch(statusUrl, {
headers: { 'Accept': 'application/json' },
credentials: 'same-origin'
})
.then(res => {
if (!res.ok) throw new Error('HTTP ' + res.status);
return res.json();
})
.then(data => {
// SUCCESS → reload
if (data.decoded) {
window.location.reload();
return;
}
// ERROR → stop + show message
if (data.error) {
clearInterval(timer);
if (statusEl) {
statusEl.classList.remove("notice");
statusEl.classList.add("error");
statusEl.textContent = data.error;
}
console.warn("VIN decode failed:", data.error);
return;
}
// continue polling
attempts++;
if (attempts >= maxAttempts) {
clearInterval(timer);
if (statusEl) {
statusEl.classList.remove("notice");
statusEl.classList.add("warning");
statusEl.textContent = timedOutMessage;
}
console.warn("VIN decode polling timed out");
}
})
.catch(err => {
clearInterval(timer);
if (statusEl) {
statusEl.classList.remove("notice");
statusEl.classList.add("error");
statusEl.textContent = checkFailedMessage;
}
console.error("Polling error:", err);
});
};
const timer = setInterval(checkStatus, interval);
})();
</script>