diff --git a/app/controllers/ui_job_wizard_controller.rb b/app/controllers/ui_job_wizard_controller.rb index b9ae20f8d..cbfba83d9 100644 --- a/app/controllers/ui_job_wizard_controller.rb +++ b/app/controllers/ui_job_wizard_controller.rb @@ -12,8 +12,14 @@ def categories def template job_template = JobTemplate.authorized.find(params[:id]) + provider_input_values = [] + if params[:jobInvocationId] + job = JobInvocation.authorized.find(params[:jobInvocationId]) + composer = JobInvocationComposer.from_job_invocation(job, params).params + provider_input_values = composer[:template_invocations][0][:provider_input_values] + end advanced_template_inputs, template_inputs = map_template_inputs(job_template.template_inputs_with_foreign).partition { |x| x["advanced"] } - provider_inputs = job_template.provider.provider_inputs.map { |input| input.instance_values.merge({:provider_input => true, default: input.value }) } + provider_inputs = job_template.provider.provider_inputs(provider_input_values).map { |input| input.instance_values.merge({:provider_input => true, :default => input.value }) } render :json => { :job_template => job_template, :effective_user => job_template.effective_user, @@ -63,8 +69,11 @@ def resources def job_invocation job = JobInvocation.authorized.find(params[:id]) composer = JobInvocationComposer.from_job_invocation(job, params).params + job_template_inputs = JobTemplate.authorized.find(composer[:template_invocations][0][:template_id]).template_inputs_with_foreign + job_provider_inputs = composer[:template_invocations][0][:provider_input_values] inputs = Hash[job_template_inputs.map { |input| ["inputs[#{input[:name]}]", {:advanced => input[:advanced], :value => (composer[:template_invocations][0][:input_values].find { |value| value[:template_input_id] == input[:id] }).try(:[], :value)}] }] + provider_inputs = Hash[job_provider_inputs.map { |input| ["provider_inputs[#{input[:name]}]", {:provider_input => input[:provider_input], :value => input[:value]}] }] job_organization = Taxonomy.find_by(id: job.task.input[:current_organization_id]) job_location = Taxonomy.find_by(id: job.task.input[:current_location_id]) render :json => { @@ -72,6 +81,7 @@ def job_invocation :job_organization => job_organization, :job_location => job_location, :inputs => inputs, + :provider_inputs => provider_inputs, } end end diff --git a/app/lib/foreman_remote_execution/provider_input.rb b/app/lib/foreman_remote_execution/provider_input.rb index b8a83f135..7bb2ed3c1 100644 --- a/app/lib/foreman_remote_execution/provider_input.rb +++ b/app/lib/foreman_remote_execution/provider_input.rb @@ -1,12 +1,13 @@ module ForemanRemoteExecution class ProviderInput - attr_reader :name, :label, :description, :options, :value_type, :required + attr_reader :name, :label, :default, :description, :options, :value_type, :required attr_accessor :value - def initialize(name:, label:, value:, description: nil, options: nil, value_type: nil, required: false, hidden: false) + def initialize(name:, label:, value:, default: nil, description: nil, options: nil, value_type: nil, required: false, hidden: false) @name = name @label = label @value = value + @default = default @description = description @options = options @value_type = value_type diff --git a/app/models/job_invocation_composer.rb b/app/models/job_invocation_composer.rb index 3916697e7..185b80a22 100644 --- a/app/models/job_invocation_composer.rb +++ b/app/models/job_invocation_composer.rb @@ -271,6 +271,7 @@ def template_invocations_params job_invocation.pattern_template_invocations.map do |template_invocation| params = template_invocation.attributes.slice('template_id', 'effective_user') params['input_values'] = template_invocation.input_values.map { |v| v.attributes.slice('template_input_id', 'value') } + params['provider_input_values'] = template_invocation.provider_input_values.map { |v| v.attributes.slice('name', 'value') } params end end diff --git a/config/routes.rb b/config/routes.rb index 493d5b937..535b1f1cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -49,7 +49,7 @@ end get 'cockpit/redirect', to: 'cockpit#redirect' get 'ui_job_wizard/categories', to: 'ui_job_wizard#categories' - get 'ui_job_wizard/template/:id', to: 'ui_job_wizard#template' + get 'ui_job_wizard/template/:id(/:jobInvocationId)', to: 'ui_job_wizard#template' get 'ui_job_wizard/resources', to: 'ui_job_wizard#resources' get 'ui_job_wizard/job_invocation', to: 'ui_job_wizard#job_invocation' diff --git a/webpack/JobWizard/JobWizard.js b/webpack/JobWizard/JobWizard.js index 9f329ecd3..a3c185bba 100644 --- a/webpack/JobWizard/JobWizard.js +++ b/webpack/JobWizard/JobWizard.js @@ -160,7 +160,9 @@ export const JobWizard = ({ rerunData }) => { dispatch( get({ key: JOB_TEMPLATE, - url: `/ui_job_wizard/template/${jobTemplateID}`, + url: rerunData + ? `/ui_job_wizard/template/${jobTemplateID}/${rerunData?.reruns}` + : `/ui_job_wizard/template/${jobTemplateID}`, handleSuccess: rerunData ? ({ data: {