Merge branch 'master' into 3889-functional-testing
[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 friendly_link_name
9     pipeline_name = self.name
10     if pipeline_name.nil? or pipeline_name.empty?
11       template = PipelineTemplate.where(uuid: self.pipeline_template_uuid).first
12       if template
13         template.name
14       else
15         self.uuid
16       end
17     else
18       pipeline_name
19     end
20   end
21
22   def content_summary
23     begin
24       PipelineTemplate.find(pipeline_template_uuid).name
25     rescue
26       super
27     end
28   end
29
30   def update_job_parameters(new_params)
31     self.components[:steps].each_with_index do |step, i|
32       step[:params].each do |param|
33         if new_params.has_key?(new_param_name = "#{i}/#{param[:name]}") or
34             new_params.has_key?(new_param_name = "#{step[:name]}/#{param[:name]}") or
35             new_params.has_key?(new_param_name = param[:name])
36           param_type = :value
37           %w(hash data_locator).collect(&:to_sym).each do |ptype|
38             param_type = ptype if param.has_key? ptype
39           end
40           param[param_type] = new_params[new_param_name]
41         end
42       end
43     end
44   end
45
46   def attribute_editable? attr, *args
47     super && (attr.to_sym == :name || attr.to_sym == :description ||
48               (attr.to_sym == :components and
49                (self.state == 'New' || self.state == 'Ready')))
50   end
51
52   def attributes_for_display
53     super.reject { |k,v| k == 'components' }
54   end
55
56   def self.creatable?
57     false
58   end
59
60   def component_input_title(component_name, input_name)
61     component = components[component_name]
62     return nil if component.nil?
63     param_info = component[:script_parameters].andand[input_name.to_sym]
64     if param_info.is_a?(Hash) and param_info[:title]
65       param_info[:title]
66     else
67       "\"#{input_name.to_s}\" parameter for #{component[:script]} script in #{component_name} component"
68     end
69   end
70
71   def textile_attributes
72     [ 'description' ]
73   end
74 end