Class: JobTemplatesController
- Inherits:
-
TemplatesController
- Object
- TemplatesController
- JobTemplatesController
- Defined in:
- app/controllers/job_templates_controller.rb
Instance Method Summary collapse
- #auto_complete_job_category ⇒ Object
- #export ⇒ Object
- #import ⇒ Object
- #load_vars_from_template ⇒ Object
- #preview ⇒ Object
Instance Method Details
#auto_complete_job_category ⇒ Object
9 10 11 12 |
# File 'app/controllers/job_templates_controller.rb', line 9 def auto_complete_job_category @job_categories = resource_base.where(['job_category LIKE ?', "%#{params[:search]}%"]).pluck(:job_category).uniq render :json => @job_categories.map { |name| { 'completed' => '', 'part' => name, 'label' => name, 'category' => '' } }.to_json end |
#export ⇒ Object
42 43 44 45 |
# File 'app/controllers/job_templates_controller.rb', line 42 def export find_resource unless @template.present? send_data @template.to_erb, :type => 'text/plain', :disposition => 'attachment', :filename => @template.filename end |
#import ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/job_templates_controller.rb', line 27 def import contents = params.fetch(:imported_template, {}).fetch(:template, nil).try(:read) @template = JobTemplate.import(contents, :update => Foreman::Cast.to_bool(params[:imported_template][:overwrite])) if @template && @template.save flash[:notice] = _('Job template imported successfully.') redirect_to job_templates_path(:search => "name = \"#{@template.name}\"") else @template ||= JobTemplate.import(contents, :build_new => true) @template.valid? flash[:warning] = _('Unable to save template. Correct highlighted errors') render :action => 'new' end end |
#load_vars_from_template ⇒ Object
2 3 4 5 6 7 |
# File 'app/controllers/job_templates_controller.rb', line 2 def load_vars_from_template return unless @template @locations = @template.locations @organizations = @template.organizations end |
#preview ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/job_templates_controller.rb', line 14 def preview find_resource unless @template.present? base = Host.(:view_hosts, Host) host = params[:preview_host_id].present? ? base.find(params[:preview_host_id]) : base.first @template.template = params[:template] renderer = InputTemplateRenderer.new(@template, host) if (output = renderer.preview) render :text => output else render :status => 406, :text => _('Problem with previewing the template: %{error}. Note that you must save template input changes before you try to preview it.' % {:error => renderer.}) end end |