2019-04-23 15:58:20 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class LabelPresenter < Gitlab::View::Presenter::Delegated
|
|
|
|
presents :label
|
2020-10-13 02:09:09 -04:00
|
|
|
delegate :name, :full_name, to: :label_subject, prefix: :subject
|
2019-04-23 15:58:20 -04:00
|
|
|
|
|
|
|
def edit_path
|
|
|
|
case label
|
|
|
|
when GroupLabel then edit_group_label_path(label.group, label)
|
|
|
|
when ProjectLabel then edit_project_label_path(label.project, label)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_path
|
|
|
|
case label
|
|
|
|
when GroupLabel then group_label_path(label.group, label)
|
|
|
|
when ProjectLabel then project_label_path(label.project, label)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def filter_path(type: :issue)
|
|
|
|
case context_subject
|
|
|
|
when Group
|
|
|
|
send("#{type.to_s.pluralize}_group_path", # rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
context_subject,
|
|
|
|
label_name: [label.name])
|
|
|
|
when Project
|
|
|
|
send("namespace_project_#{type.to_s.pluralize}_path", # rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
context_subject.namespace,
|
|
|
|
context_subject,
|
|
|
|
label_name: [label.name])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_subscribe_to_label_in_different_levels?
|
|
|
|
issuable_subject.is_a?(Project) && label.is_a?(GroupLabel)
|
|
|
|
end
|
|
|
|
|
2019-05-28 06:05:20 -04:00
|
|
|
def project_label?
|
|
|
|
label.is_a?(ProjectLabel)
|
|
|
|
end
|
|
|
|
|
2020-10-13 02:09:09 -04:00
|
|
|
def label_subject
|
|
|
|
@label_subject ||= label.subject
|
2019-05-28 06:05:20 -04:00
|
|
|
end
|
|
|
|
|
2019-04-23 15:58:20 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def context_subject
|
|
|
|
issuable_subject || label.try(:subject)
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
LabelPresenter.prepend_if_ee('EE::LabelPresenter')
|