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