Merge branch '12018-tool-docs'
[arvados.git] / apps / workbench / app / models / pipeline_instance_work_unit.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class PipelineInstanceWorkUnit < ProxyWorkUnit
6   def children
7     return @my_children if @my_children
8
9     items = []
10
11     jobs = {}
12     results = Job.where(uuid: @proxied.job_ids.values).results
13     results.each do |j|
14       jobs[j.uuid] = j
15     end
16
17     components = get(:components)
18     components.each do |name, c|
19       if c.is_a?(Hash)
20         job = c[:job]
21         if job
22           if job[:uuid] and jobs[job[:uuid]]
23             items << jobs[job[:uuid]].work_unit(name)
24           else
25             items << JobWorkUnit.new(job, name, uuid)
26           end
27         else
28           items << JobWorkUnit.new(c, name, uuid)
29         end
30       else
31         @unreadable_children = true
32         break
33       end
34     end
35
36     @my_children = items
37   end
38
39   def outputs
40     items = []
41     components = get(:components)
42     components.each do |name, c|
43       if c.is_a?(Hash)
44         items << c[:output_uuid] if c[:output_uuid]
45       end
46     end
47     items
48   end
49
50   def uri
51     uuid = get(:uuid)
52     "/pipeline_instances/#{uuid}"
53   end
54
55   def title
56     "pipeline"
57   end
58
59   def template_uuid
60     get(:pipeline_template_uuid)
61   end
62 end