4233: ignore negative deltas when charting log stats
[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 push_logs
61     @push_logs = stderr_log_records([@object.uuid])
62   end
63
64   def index_pane_list
65     if params[:uuid]
66       %w(Recent Provenance)
67     else
68       %w(Recent)
69     end
70   end
71
72   def show_pane_list
73     %w(Status Log Details Provenance Advanced)
74   end
75 end