Skip to content

Commit

Permalink
Fixes #21704 - Make it work for categories containing more templates
Browse files Browse the repository at this point in the history
  • Loading branch information
adamruzicka committed Aug 2, 2018
1 parent ca7982f commit b575f80
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 7 additions & 1 deletion app/models/job_invocation_composer.rb
Expand Up @@ -306,11 +306,11 @@ def initialize(params, set_defaults = false)
@set_defaults = set_defaults
@job_invocation = JobInvocation.new
@job_invocation.task_group = JobInvocationTaskGroup.new
@reruns = params[:reruns]
compose

@host_ids = validate_host_ids(params[:host_ids])
@search_query = job_invocation.targeting.search_query if job_invocation.targeting.bookmark_id.blank?
@reruns = params[:reruns]
end

def self.from_job_invocation(job_invocation, params = {})
Expand Down Expand Up @@ -345,6 +345,8 @@ def compose
job_invocation.key_passphrase = params[:key_passphrase]
job_invocation.sudo_password = params[:sudo_password]

job_invocation.job_category = nil unless rerun_possible?

self
end
# rubocop:enable Metrics/AbcSize
Expand Down Expand Up @@ -473,6 +475,10 @@ def job_template_ids
job_invocation.pattern_template_invocations.map(&:template_id)
end

def rerun_possible?
!(@reruns && job_invocation.pattern_template_invocations.empty?)
end

private

# builds input values for a given templates id based on params
Expand Down
6 changes: 4 additions & 2 deletions app/views/job_invocations/_form.html.erb
Expand Up @@ -6,13 +6,15 @@

<%= form_for @composer.job_invocation, :html => {'data-refresh-url' => refresh_job_invocations_path, :id => 'job_invocation_form'} do |f| %>
<% if @composer.reruns && @composer.job_invocation.pattern_template_invocations.empty? %>
<% unless @composer.rerun_possible? %>
<%= alert :text => _('Could not rerun job %{id} because its template could not be found') % { :id => @composer.reruns },
:class => 'alert alert-block alert-danger has-error',
:close => false %>
<% end %>
<%= selectable_f f, :job_category, @composer.available_job_categories, {:selected => @composer.job_invocation.job_category, :include_blank => @composer.job_invocation.job_category.nil?}, :label => _('Job category') %>
<%= selectable_f f, :job_category, @composer.available_job_categories,
{ :selected => @composer.job_invocation.job_category, :include_blank => @composer.job_invocation.job_category.nil? },
:label => _('Job category') %>
<%= f.hidden_field(:remote_execution_feature_id, :value => @composer.remote_execution_feature_id) %>
<% selected_templates_per_provider = {} %>
Expand Down

0 comments on commit b575f80

Please sign in to comment.