3149: Merge branch 'master' into 3149-server-side-search
[arvados.git] / apps / workbench / app / models / pipeline_instance.rb
1 class PipelineInstance < ArvadosBase
2   attr_accessor :pipeline_template
3
4   def self.goes_in_projects?
5     true
6   end
7
8   def content_summary
9     begin
10       PipelineTemplate.find(pipeline_template_uuid).name
11     rescue
12       super
13     end
14   end
15
16   def update_job_parameters(new_params)
17     self.components[:steps].each_with_index do |step, i|
18       step[:params].each do |param|
19         if new_params.has_key?(new_param_name = "#{i}/#{param[:name]}") or
20             new_params.has_key?(new_param_name = "#{step[:name]}/#{param[:name]}") or
21             new_params.has_key?(new_param_name = param[:name])
22           param_type = :value
23           %w(hash data_locator).collect(&:to_sym).each do |ptype|
24             param_type = ptype if param.has_key? ptype
25           end
26           param[param_type] = new_params[new_param_name]
27         end
28       end
29     end
30   end
31
32   def attribute_editable? attr, *args
33     super && (attr.to_sym == :name ||
34               (attr.to_sym == :components and
35                (self.state == 'New' || self.state == 'Ready')))
36   end
37
38   def attributes_for_display
39     super.reject { |k,v| k == 'components' }
40   end
41
42   def self.creatable?
43     false
44   end
45
46   def component_input_title(component_name, input_name)
47     component = components[component_name]
48     return nil if component.nil?
49     param_info = component[:script_parameters].andand[input_name.to_sym]
50     if param_info.is_a?(Hash) and param_info[:title]
51       param_info[:title]
52     else
53       "\"#{input_name.to_s}\" parameter for #{component[:script]} script in #{component_name} component"
54     end
55   end
56 end