debian-mirror-gitlab/app/controllers/concerns/labels_as_hash.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
627 B
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
module LabelsAsHash
extend ActiveSupport::Concern
def labels_as_hash(target = nil, params = {})
available_labels = LabelsFinder.new(
current_user,
params
).execute
label_hashes = available_labels.as_json(only: [:title, :color])
2021-04-29 21:17:54 +05:30
if target.respond_to?(:labels)
2018-12-05 23:21:45 +05:30
already_set_labels = available_labels & target.labels
if already_set_labels.present?
titles = already_set_labels.map(&:title)
label_hashes.each do |hash|
2023-03-04 22:38:38 +05:30
hash[:set] = true if titles.include?(hash['title'])
2018-12-05 23:21:45 +05:30
end
end
end
label_hashes
end
end