2015-12-04 06:55:23 -05:00
|
|
|
class Admin::RunnersController < Admin::ApplicationController
|
|
|
|
before_action :runner, except: :index
|
|
|
|
|
|
|
|
def index
|
2017-10-03 11:08:29 -04:00
|
|
|
sort = params[:sort] == 'contacted_asc' ? { contacted_at: :asc } : { id: :desc }
|
|
|
|
@runners = Ci::Runner.order(sort)
|
2015-12-04 06:55:23 -05:00
|
|
|
@runners = @runners.search(params[:search]) if params[:search].present?
|
|
|
|
@runners = @runners.page(params[:page]).per(30)
|
|
|
|
@active_runners_cnt = Ci::Runner.online.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2016-05-19 15:27:52 -04:00
|
|
|
assign_builds_and_projects
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-01-20 08:57:01 -05:00
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(runner_params)
|
2016-05-19 15:27:52 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
format.html { redirect_to admin_runner_path(@runner) }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
assign_builds_and_projects
|
|
|
|
render 'show'
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@runner.destroy
|
|
|
|
|
2017-06-06 18:45:16 -04:00
|
|
|
redirect_to admin_runners_path, status: 302
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def resume
|
2017-01-20 08:57:01 -05:00
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(active: true)
|
2015-12-04 06:55:23 -05:00
|
|
|
redirect_to admin_runners_path, notice: 'Runner was successfully updated.'
|
|
|
|
else
|
|
|
|
redirect_to admin_runners_path, alert: 'Runner was not updated.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def pause
|
2017-01-20 08:57:01 -05:00
|
|
|
if Ci::UpdateRunnerService.new(@runner).update(active: false)
|
2015-12-04 06:55:23 -05:00
|
|
|
redirect_to admin_runners_path, notice: 'Runner was successfully updated.'
|
|
|
|
else
|
|
|
|
redirect_to admin_runners_path, alert: 'Runner was not updated.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def runner
|
|
|
|
@runner ||= Ci::Runner.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def runner_params
|
2016-05-09 07:07:10 -04:00
|
|
|
params.require(:runner).permit(Ci::Runner::FORM_EDITABLE)
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|
2016-05-18 11:23:26 -04:00
|
|
|
|
2016-05-19 15:27:52 -04:00
|
|
|
def assign_builds_and_projects
|
2016-05-18 11:23:26 -04:00
|
|
|
@builds = runner.builds.order('id DESC').first(30)
|
|
|
|
@projects =
|
|
|
|
if params[:search].present?
|
|
|
|
::Project.search(params[:search])
|
|
|
|
else
|
|
|
|
Project.all
|
|
|
|
end
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2016-05-18 11:23:26 -04:00
|
|
|
@projects = @projects.where.not(id: runner.projects.select(:id)) if runner.projects.any?
|
|
|
|
@projects = @projects.page(params[:page]).per(30)
|
|
|
|
end
|
2015-12-04 06:55:23 -05:00
|
|
|
end
|