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