summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-11-16 11:11:53 +0000
committerRémy Coutable <remy@rymai.me>2016-11-16 11:11:53 +0000
commit0a3cafb2895bef3577e2b9ca09c4eb8bdb8565fa (patch)
tree884ffdb3cf585154a245de36216a60939ee310cb
parentb33791d8b94f5b41699996414e7fa2ce06e2f519 (diff)
parentd54b88260c3cdedd3497c6fa9fa15e3ceedaebcb (diff)
downloadgitlab-ce-0a3cafb2895bef3577e2b9ca09c4eb8bdb8565fa.tar.gz
Merge branch '22680-unlabel-limit-autocomplete-to-selected-items' into 'master'
Limit autocomplete to currently selected items When using the /unlabel command the autocomplete list of labels is now limited to the list of labels currently assigned to the issue. Closes #22680 See merge request !6796
-rw-r--r--app/assets/javascripts/gfm_auto_complete.js.es66
-rw-r--r--app/controllers/projects_controller.rb4
-rw-r--r--app/services/projects/autocomplete_service.rb9
-rw-r--r--changelogs/unreleased/22680-unlabel-limit-autocomplete-to-selected-items.yml4
4 files changed, 21 insertions, 2 deletions
diff --git a/app/assets/javascripts/gfm_auto_complete.js.es6 b/app/assets/javascripts/gfm_auto_complete.js.es6
index 58c1179d250..19bfdf1de8c 100644
--- a/app/assets/javascripts/gfm_auto_complete.js.es6
+++ b/app/assets/javascripts/gfm_auto_complete.js.es6
@@ -51,6 +51,11 @@
if (!GitLab.GfmAutoComplete.dataLoaded) {
return this.at;
} else {
+ if (value.indexOf("unlabel") !== -1) {
+ GitLab.GfmAutoComplete.input.atwho('load', '~', GitLab.GfmAutoComplete.cachedData.unlabels);
+ } else {
+ GitLab.GfmAutoComplete.input.atwho('load', '~', GitLab.GfmAutoComplete.cachedData.labels);
+ }
return value;
}
}
@@ -358,3 +363,4 @@
};
}).call(this);
+
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index a8a18b4fa16..7376c2bfeb7 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -144,13 +144,15 @@ class ProjectsController < Projects::ApplicationController
autocomplete = ::Projects::AutocompleteService.new(@project, current_user)
participants = ::Projects::ParticipantsService.new(@project, current_user).execute(noteable)
+ unlabels = autocomplete.unlabels(noteable)
@suggestions = {
emojis: Gitlab::AwardEmoji.urls,
issues: autocomplete.issues,
milestones: autocomplete.milestones,
mergerequests: autocomplete.merge_requests,
- labels: autocomplete.labels,
+ labels: autocomplete.labels - unlabels,
+ unlabels: unlabels,
members: participants,
commands: autocomplete.commands(noteable, params[:type])
}
diff --git a/app/services/projects/autocomplete_service.rb b/app/services/projects/autocomplete_service.rb
index 015f2828921..223461e88b6 100644
--- a/app/services/projects/autocomplete_service.rb
+++ b/app/services/projects/autocomplete_service.rb
@@ -13,7 +13,14 @@ module Projects
end
def labels
- LabelsFinder.new(current_user, project_id: project.id).execute.select([:title, :color])
+ LabelsFinder.new(current_user, project_id: project.id).execute.
+ pluck(:title, :color).map { |l| { title: l.first, color: l.second } }
+ end
+
+ def unlabels(noteable)
+ return [] unless noteable && noteable.respond_to?(:labels)
+
+ noteable.labels.pluck(:title, :color).map { |l| { title: l.first, color: l.second } }
end
def commands(noteable, type)
diff --git a/changelogs/unreleased/22680-unlabel-limit-autocomplete-to-selected-items.yml b/changelogs/unreleased/22680-unlabel-limit-autocomplete-to-selected-items.yml
new file mode 100644
index 00000000000..95fd07c12e1
--- /dev/null
+++ b/changelogs/unreleased/22680-unlabel-limit-autocomplete-to-selected-items.yml
@@ -0,0 +1,4 @@
+---
+title: Limit autocomplete to currently selected items for unlabel slash command
+merge_request: 22680
+author: Akram Fares