Merge branch 'master' into 8876-work-unit
[arvados.git] / apps / workbench / app / models / pipeline_instance_work_unit.rb
1 class PipelineInstanceWorkUnit < ProxyWorkUnit
2   def children
3     return self.my_children if self.my_children
4
5     items = []
6
7     jobs = {}
8     results = Job.where(uuid: self.proxied.job_ids.values).results
9     results.each do |j|
10       jobs[j.uuid] = j
11     end
12
13     components = get(:components)
14     components.each do |name, c|
15       if c.is_a?(Hash)
16         job = c[:job]
17         if job
18           if job[:uuid] and jobs[job[:uuid]]
19             items << jobs[job[:uuid]].work_unit(name)
20           else
21             items << JobWorkUnit.new(job, name)
22           end
23         else
24           items << ProxyWorkUnit.new(c, name)
25         end
26       else
27         self.unreadable_children = true
28         break
29       end
30     end
31
32     self.my_children = items
33   end
34
35   def uri
36     uuid = get(:uuid)
37     "/pipeline_instances/#{uuid}"
38   end
39
40   def title
41     "pipeline"
42   end
43 end