8ce4b6093a
When rendering a label we want to check 'scoped_label' feature availability on a project/group where label is being used. For this reason a label presenter is used in UI and information about context project/group is passed to this presenter.
32 lines
669 B
Ruby
32 lines
669 B
Ruby
# frozen_string_literal: true
|
|
|
|
class GlobalLabel
|
|
include Presentable
|
|
|
|
attr_accessor :title, :labels
|
|
alias_attribute :name, :title
|
|
|
|
delegate :color, :text_color, :description, :scoped_label?, to: :@first_label
|
|
|
|
def for_display
|
|
@first_label
|
|
end
|
|
|
|
def self.build_collection(labels)
|
|
labels = labels.group_by(&:title)
|
|
|
|
labels.map do |title, labels|
|
|
new(title, labels)
|
|
end
|
|
end
|
|
|
|
def initialize(title, labels)
|
|
@title = title
|
|
@labels = labels
|
|
@first_label = labels.find { |lbl| lbl.description.present? } || labels.first
|
|
end
|
|
|
|
def present(attributes)
|
|
super(attributes.merge(presenter_class: ::LabelPresenter))
|
|
end
|
|
end
|