3756: do not show 'Show' button in admin user's own row.
[arvados.git] / apps / workbench / app / controllers / jobs_controller.rb
1 class JobsController < ApplicationController
2   include JobsHelper
3
4   def generate_provenance(jobs)
5     return if params['tab_pane'] != "Provenance"
6
7     nodes = {}
8     collections = []
9     hashes = []
10     jobs.each do |j|
11       nodes[j[:uuid]] = j
12       hashes << j[:output]
13       ProvenanceHelper::find_collections(j[:script_parameters]) do |hash, uuid|
14         collections << uuid if uuid
15         hashes << hash if hash
16       end
17       nodes[j[:script_version]] = {:uuid => j[:script_version]}
18     end
19
20     Collection.where(uuid: collections).each do |c|
21       nodes[c[:portable_data_hash]] = c
22     end
23
24     Collection.where(portable_data_hash: hashes).each do |c|
25       nodes[c[:portable_data_hash]] = c
26     end
27
28     @svg = ProvenanceHelper::create_provenance_graph nodes, "provenance_svg", {
29       :request => request,
30       :all_script_parameters => true,
31       :script_version_nodes => true}
32   end
33
34   def index
35     @svg = ""
36     if params[:uuid]
37       @objects = Job.where(uuid: params[:uuid])
38       generate_provenance(@objects)
39       render_index
40     else
41       @limit = 20
42       super
43     end
44   end
45
46   def cancel
47     @object.cancel
48     if params[:return_to]
49       redirect_to params[:return_to]
50     else
51       redirect_to @object
52     end
53   end
54
55   def show
56     generate_provenance([@object])
57     super
58   end
59
60   def logs
61     @logs = Log.select(%w(event_type object_uuid event_at properties))
62                .order('event_at DESC')
63                .filter([["event_type",  "=", "stderr"],
64                         ["object_uuid", "in", [@object.uuid]]])
65                .limit(500)
66                .results
67                .to_a
68                .map{ |e| e.serializable_hash.merge({ 'prepend' => true }) }
69     respond_to do |format|
70       format.json { render json: @logs }
71     end
72   end
73
74   def index_pane_list
75     if params[:uuid]
76       %w(Recent Provenance)
77     else
78       %w(Recent)
79     end
80   end
81
82   def show_pane_list
83     %w(Status Log Details Provenance Advanced)
84   end
85 end