2659: show job cancel button only when user is_active.
[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     if name.to_s == "components"
56       (ever or %w(New Ready).include?(state)) and super
57     else
58       super
59     end
60   end
61
62   def attributes_for_display
63     super.reject { |k,v| k == 'components' }
64   end
65
66   def self.creatable?
67     false
68   end
69
70   def component_input_title(component_name, input_name)
71     component = components[component_name]
72     return nil if component.nil?
73     param_info = component[:script_parameters].andand[input_name.to_sym]
74     if param_info.is_a?(Hash) and param_info[:title]
75       param_info[:title]
76     else
77       "\"#{input_name.to_s}\" parameter for #{component[:script]} script in #{component_name} component"
78     end
79   end
80
81   def textile_attributes
82     [ 'description' ]
83   end
84 end