debian-mirror-gitlab/app/presenters/label_presenter.rb

65 lines
1.6 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
class LabelPresenter < Gitlab::View::Presenter::Delegated
2021-11-18 22:05:49 +05:30
presents ::Label, as: :label
2022-03-02 08:16:31 +05:30
delegate :name, :full_name, to: :label_subject, prefix: :subject, allow_nil: true
2019-07-31 22:56:46 +05:30
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)
2022-03-02 08:16:31 +05:30
else edit_admin_label_path(label)
2019-07-31 22:56:46 +05:30
end
end
2022-05-07 20:08:51 +05:30
def text_color_class
"gl-label-text-#{label.color.contrast.luminosity}"
end
2019-07-31 22:56:46 +05:30
def destroy_path
case label
when GroupLabel then group_label_path(label.group, label)
when ProjectLabel then project_label_path(label.project, label)
2022-03-02 08:16:31 +05:30
else admin_label_path(label)
2019-07-31 22:56:46 +05:30
end
end
def filter_path(type: :issue)
case context_subject
when Group
2023-05-27 22:25:52 +05:30
send( # rubocop:disable GitlabSecurity/PublicSend
"#{type.to_s.pluralize}_group_path",
context_subject,
label_name: [label.name]
)
2019-07-31 22:56:46 +05:30
when Project
2023-05-27 22:25:52 +05:30
send( # rubocop:disable GitlabSecurity/PublicSend
"namespace_project_#{type.to_s.pluralize}_path",
context_subject.namespace,
context_subject,
label_name: [label.name]
)
2019-07-31 22:56:46 +05:30
end
end
def can_subscribe_to_label_in_different_levels?
issuable_subject.is_a?(Project) && label.is_a?(GroupLabel)
end
def project_label?
label.is_a?(ProjectLabel)
end
2021-01-03 14:25:43 +05:30
def label_subject
2022-03-02 08:16:31 +05:30
@label_subject ||= label.subject if label.respond_to?(:subject)
2019-07-31 22:56:46 +05:30
end
private
def context_subject
issuable_subject || label.try(:subject)
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
LabelPresenter.prepend_mod_with('LabelPresenter')