summaryrefslogtreecommitdiff
path: root/app/controllers/admin/jobs_controller.rb
blob: 788693c62c400b26f7c1343fc75cc341ae429f4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Admin::JobsController < Admin::ApplicationController
  # rubocop: disable CodeReuse/ActiveRecord
  def index
    @scope = params[:scope]
    @all_builds = Ci::Build
    @builds = @all_builds.order('id DESC')
    @builds =
      case @scope
      when 'pending'
        @builds.pending.reverse_order
      when 'running'
        @builds.running.reverse_order
      when 'finished'
        @builds.finished
      else
        @builds
      end
    @builds = @builds.page(params[:page]).per(30)
  end
  # rubocop: enable CodeReuse/ActiveRecord

  def cancel_all
    Ci::Build.running_or_pending.each(&:cancel)

    redirect_to admin_jobs_path, status: :see_other
  end
end