Class: PipelinesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/pipelines_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#block_api_access, #clean_params_from_check, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!

Instance Method Details

#activateObject


80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/pipelines_controller.rb', line 80

def activate
  @pipeline.active = true
  if @pipeline.save
    flash[:notice] = 'Pipeline activated'
    redirect_to pipelines_path
  else
    flash[:notice] = 'Failed to activate pipeline'
    redirect_to pipeline_path(@pipeline)
  end
end

#batchesObject


102
103
104
# File 'app/controllers/pipelines_controller.rb', line 102

def batches
  @batches = @pipeline.batches.order(id: :desc).page(params[:page])
end

#deactivateObject


91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/pipelines_controller.rb', line 91

def deactivate
  @pipeline.active = false
  if @pipeline.save
    flash[:notice] = 'Pipeline deactivated'
    redirect_to pipelines_path
  else
    flash[:notice] = 'Failed to deactivate pipeline'
    redirect_to pipeline_path(@pipeline)
  end
end

#finishObject


63
64
65
66
67
68
# File 'app/controllers/pipelines_controller.rb', line 63

def finish
  ActiveRecord::Base.transaction { @batch.complete!(current_user) }
rescue ActiveRecord::RecordInvalid => e
  flash[:error] = e.record.errors.full_messages
  redirect_to(url_for(controller: 'batches', action: 'show', id: @batch.id))
end

#indexObject


11
12
13
14
15
16
17
18
19
# File 'app/controllers/pipelines_controller.rb', line 11

def index
  @pipelines = Pipeline.active.internally_managed.alphabetical
  @grouping = @pipelines.group_by(&:group_name)

  respond_to do |format|
    format.html
    format.xml { render xml: @pipelines.to_xml }
  end
end

#releaseObject


70
71
72
73
74
75
76
77
78
# File 'app/controllers/pipelines_controller.rb', line 70

def release
  ActiveRecord::Base.transaction do
    @batch = Batch.find(params[:id])
    @batch.release!(current_user)
  end

  flash[:notice] = 'Batch released!'
  redirect_to controller: 'batches', action: 'show', id: @batch.id
end

#showObject


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/pipelines_controller.rb', line 21

def show
  expires_now
  @show_held_requests = (params[:view] == 'all')
  @current_page       = params[:page]

  @pending_batches     = @pipeline.batches.pending_for_ui.includes_for_ui
  @batches_in_progress = @pipeline.batches.in_progress_for_ui.includes_for_ui
  @completed_batches   = @pipeline.batches.completed_for_ui.includes_for_ui
  @released_batches    = @pipeline.batches.released_for_ui.includes_for_ui
  @failed_batches      = @pipeline.batches.failed_for_ui.includes_for_ui

  @batches = @last5_batches = @pipeline.batches.latest_first.includes_for_ui

  @information_types = @pipeline.request_information_types.shown_in_inbox

  if @pipeline.group_by_parent?
    # We use the inbox presenter
    @inbox_presenter = Presenters::GroupedPipelineInboxPresenter.new(@pipeline, current_user, @show_held_requests)
    @requests_waiting = @inbox_presenter.requests_waiting
  elsif @pipeline.group_by_submission?
    # Convert to an array now as otherwise the comments counter attempts to be too clever
    # and treats the requests like a scope. Not only does this result in a more complicated
    # query, but also an invalid one
    @requests_waiting = @pipeline.requests.inbox(@show_held_requests, @current_page, :count)
    requests = @pipeline.requests.inbox(@show_held_requests, @current_page).to_a
    @grouped_requests = requests.group_by(&:submission_id)
    @requests_comment_count = Comment.counts_for(requests)
    @assets_comment_count = Comment.counts_for(requests.map(&:asset))
  else
    @requests_waiting = @pipeline.requests.inbox(@show_held_requests, @current_page, :count)
    @requests = @pipeline.requests.inbox(@show_held_requests, @current_page).to_a
    # We convert to an array here as otherwise tails tries to be smart
    # and use the scope. Not only does it fail, but we may as well cache
    # the result now anyway.
    @requests_comment_count = Comment.counts_for(@requests)
    @assets_comment_count = Comment.counts_for(@requests.map(&:asset))
    @requests_samples_count = Request.where(id: @requests).joins(:samples).group(:id).count
  end
end

#summaryObject


61
# File 'app/controllers/pipelines_controller.rb', line 61

def summary; end

#update_priorityObject

to modify when next_request will be ready


107
108
109
110
111
112
113
114
115
# File 'app/controllers/pipelines_controller.rb', line 107

def update_priority
  request = Request.find(params[:request_id])
  ActiveRecord::Base.transaction do
    request.update_priority
    render plain: '', layout: false
  end
rescue ActiveRecord::RecordInvalid => e
  render plain: '', layout: false, status: :unprocessable_entity
end