Merge branch 'master' into 4091-test-infinite-scrolling
[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 editable_attributes
51     %w(name description components)
52   end
53
54   def attribute_editable?(name, ever=nil)
55     (ever or %w(New Ready).include?(state)) and super
56   end
57
58   def attributes_for_display
59     super.reject { |k,v| k == 'components' }
60   end
61
62   def self.creatable?
63     false
64   end
65
66   def component_input_title(component_name, input_name)
67     component = components[component_name]
68     return nil if component.nil?
69     param_info = component[:script_parameters].andand[input_name.to_sym]
70     if param_info.is_a?(Hash) and param_info[:title]
71       param_info[:title]
72     else
73       "\"#{input_name.to_s}\" parameter for #{component[:script]} script in #{component_name} component"
74     end
75   end
76
77   def textile_attributes
78     [ 'description' ]
79   end
80 end