diff options
| author | Chantal Rollison <crollison@gitlab.com> | 2018-09-28 06:47:58 -0700 |
|---|---|---|
| committer | Chantal Rollison <crollison@gitlab.com> | 2018-10-03 09:13:42 -0700 |
| commit | df6e9ed38e7fd4c985a4809b09eedc886ebe6a54 (patch) | |
| tree | 8328708b8ac969768bfcbd505d3c51cbc885b3ce /app/controllers/concerns | |
| parent | 274738391b23cb13f0c1be7a6d061a6909beb7a0 (diff) | |
| download | gitlab-ce-df6e9ed38e7fd4c985a4809b09eedc886ebe6a54.tar.gz | |
Create labels_as_hash_ concern, modify params for methodccr/48930_extract_logic_to_concern
Diffstat (limited to 'app/controllers/concerns')
| -rw-r--r-- | app/controllers/concerns/labels_as_hash.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/app/controllers/concerns/labels_as_hash.rb b/app/controllers/concerns/labels_as_hash.rb new file mode 100644 index 00000000000..1171aa9cf44 --- /dev/null +++ b/app/controllers/concerns/labels_as_hash.rb @@ -0,0 +1,28 @@ +# 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]) + + if target&.respond_to?(:labels) + already_set_labels = available_labels & target.labels + if already_set_labels.present? + titles = already_set_labels.map(&:title) + label_hashes.each do |hash| + if titles.include?(hash['title']) + hash[:set] = true + end + end + end + end + + label_hashes + end +end |
