runners_controller.rb 2.07 KB
Newer Older
1 2
module Ci
  class Admin::RunnersController < Ci::Admin::ApplicationController
Valery Sizov's avatar
Valery Sizov committed
3
    before_action :runner, except: :index
4 5 6 7 8 9 10 11 12 13 14

    def index
      @runners = Ci::Runner.order('id DESC')
      @runners = @runners.search(params[:search]) if params[:search].present?
      @runners = @runners.page(params[:page]).per(30)
      @active_runners_cnt = Ci::Runner.where("contacted_at > ?", 1.minutes.ago).count
    end

    def show
      @builds = @runner.builds.order('id DESC').first(30)
      @projects = Ci::Project.all
15 16 17 18
      if params[:search].present?
        @gl_projects = ::Project.search(params[:search])
        @projects = @projects.where(gitlab_id: @gl_projects.select(:id))
      end
19
      @projects = @projects.where("ci_projects.id NOT IN (?)", @runner.projects.pluck(:id)) if @runner.projects.any?
20 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 60 61 62 63 64 65 66 67 68 69 70 71 72
      @projects = @projects.page(params[:page]).per(30)
    end

    def update
      @runner.update_attributes(runner_params)

      respond_to do |format|
        format.js
        format.html { redirect_to ci_admin_runner_path(@runner) }
      end
    end

    def destroy
      @runner.destroy

      redirect_to ci_admin_runners_path
    end

    def resume
      if @runner.update_attributes(active: true)
        redirect_to ci_admin_runners_path, notice: 'Runner was successfully updated.'
      else
        redirect_to ci_admin_runners_path, alert: 'Runner was not updated.'
      end
    end

    def pause
      if @runner.update_attributes(active: false)
        redirect_to ci_admin_runners_path, notice: 'Runner was successfully updated.'
      else
        redirect_to ci_admin_runners_path, alert: 'Runner was not updated.'
      end
    end

    def assign_all
      Ci::Project.unassigned(@runner).all.each do |project|
        @runner.assign_to(project, current_user)
      end

      redirect_to ci_admin_runner_path(@runner), notice: "Runner was assigned to all projects"
    end

    private

    def runner
      @runner ||= Ci::Runner.find(params[:id])
    end

    def runner_params
      params.require(:runner).permit(:token, :description, :tag_list, :contacted_at, :active)
    end
  end
end