Improve actions

This commit is contained in:
Kamil Trzcinski 2016-12-08 10:40:56 +01:00 committed by Grzegorz Bizon
parent 633e64382d
commit 516dc7a5be
5 changed files with 110 additions and 18 deletions

View File

@ -127,6 +127,10 @@ module Ci
end
end
def cancelable?
active?
end
def retryable?
project.builds_enabled? && commands.present? && complete?
end

View File

@ -13,33 +13,23 @@ module Gitlab
@subject.pipeline)
end
def action_type
case
when @subject.playable? then :playable
when @subject.active? then :cancel
when @subject.retryable? then :retry
end
end
def has_action?(current_user)
action_type && can?(current_user, :update_build, @subject)
(subject.cancelable? || subject.retryable?) &&
can?(current_user, :update_build, @subject)
end
def action_icon
case action_type
when :playable then 'remove'
when :cancel then 'icon_play'
when :retry then 'repeat'
case
when subject.cancelable? then 'icon_play'
when subject.retryable? then 'repeat'
end
end
def action_path
case action_type
when :playable
play_namespace_project_build_path(subject.project.namespace, subject.project, subject)
when :cancel
case
when subject.cancelable?
cancel_namespace_project_build_path(subject.project.namespace, subject.project, subject)
when :retry
when subject.retryable?
retry_namespace_project_build_path(subject.project.namespace, subject.project, subject)
end
end

View File

@ -5,6 +5,10 @@ module Gitlab
class Factory < Status::Factory
private
def extended_statuses
[Stop, Play]
end
def core_status
super.extend(Status::Build::Common)
end

View File

@ -0,0 +1,47 @@
module Gitlab
module Ci
module Status
module Status
class Play < SimpleDelegator
extend Status::Extended
def text
'play'
end
def label
'play'
end
def icon
'icon_status_skipped'
end
def to_s
'play'
end
def has_action?(current_user)
can?(current_user, :update_build, subject)
end
def action_icon
:play
end
def action_path
play_namespace_project_build_path(subject.project.namespace, subject.project, subject)
end
def action_method
:post
end
def self.matches?(build)
build.playable? && !build.stops_environment?
end
end
end
end
end
end

View File

@ -0,0 +1,47 @@
module Gitlab
module Ci
module Status
module Status
class Play < SimpleDelegator
extend Status::Extended
def text
'stop'
end
def label
'stop'
end
def icon
'icon_status_skipped'
end
def to_s
'stop'
end
def has_action?(current_user)
can?(current_user, :update_build, subject)
end
def action_icon
:play
end
def action_path
play_namespace_project_build_path(subject.project.namespace, subject.project, subject)
end
def action_method
:post
end
def self.matches?(build)
build.playable? && build.stops_environment?
end
end
end
end
end
end