mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-17 18:20:36 -05:00
Let plugins add fields to the Create issues from estimate page
View hook view_qbo_estimate_issues_form draws plugins' fields in the shared Issue fields box; values posted as issue_plugin_fields[name] override the plugin defaults and reach qbo_billing_build_issue. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
4 files changed
+21
-4
No files matched your search
@@ -155,7 +155,8 @@ class QboEstimatesController < ApplicationController
|
||||
end
|
||||
return render_404 unless @estimate
|
||||
|
||||
@defaults = issue_defaults
|
||||
# Values plugins' fields posted with the form (e.g. redmine_qbo_vehicles' vehicle) override their defaults
|
||||
@defaults = issue_defaults.merge(submitted_plugin_fields)
|
||||
@builder = RedmineQboBilling::EstimateIssueBuilder.new(@estimate, defaults: @defaults)
|
||||
@return_path = @defaults[:return_path].presence || edit_qbo_estimate_path(@estimate.id)
|
||||
@return_label = @defaults[:return_label].presence || "#{l(:label_estimate)} ##{@estimate.doc_number}"
|
||||
@@ -185,6 +186,15 @@ class QboEstimatesController < ApplicationController
|
||||
(results.detect { |r| r.is_a?(Hash) && r.any? } || {}).symbolize_keys
|
||||
end
|
||||
|
||||
# Plugins' own fields on the preview form (issue_plugin_fields[...], drawn by :view_qbo_estimate_issues_form),
|
||||
# only when the form was posted: { vehicle_id: "5" }
|
||||
def submitted_plugin_fields
|
||||
return {} unless request.post?
|
||||
|
||||
values = params[:issue_plugin_fields]
|
||||
values.respond_to?(:to_unsafe_h) ? values.to_unsafe_h.to_h.transform_keys(&:to_sym).transform_values(&:to_s) : {}
|
||||
end
|
||||
|
||||
# The shared custom field values from the preview form: { custom_field_id => value }
|
||||
def submitted_custom_field_values
|
||||
values = params.dig(:issue, :custom_field_values)
|
||||
|
||||
@@ -136,12 +136,15 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%# Custom fields for the chosen trackers, entered once and applied to every issue that uses them %>
|
||||
<% if @field_set&.any? %>
|
||||
<%# Fields entered once and applied to every issue: plugins' own (e.g. redmine_qbo_vehicles' vehicle, posted as
|
||||
issue_plugin_fields[...]) and the custom fields for the chosen trackers %>
|
||||
<% plugin_fields = call_hook(:view_qbo_estimate_issues_form, { estimate: @estimate, defaults: @defaults, project: @target_project }) %>
|
||||
<% if @field_set&.any? || plugin_fields.present? %>
|
||||
<fieldset class="box tabular estimate-issue-fields" id="estimate-issue-fields">
|
||||
<legend><%= l(:label_estimate_issue_fields) %></legend>
|
||||
<p class="estimate-issue-fields-info"><em class="info"><%= l(:text_estimate_issue_fields_info) %></em></p>
|
||||
<% @field_set.fields.each do |field| %>
|
||||
<%= plugin_fields %>
|
||||
<% Array(@field_set&.fields).each do |field| %>
|
||||
<p class="estimate-issue-field"
|
||||
data-tracker-ids="<%= field.tracker_ids.join(',') %>"
|
||||
data-required-tracker-ids="<%= field.required_tracker_ids.join(',') %>">
|
||||
|
||||
Reference in new issue
Block a user