diff options
author | Phil Hughes <me@iamphill.com> | 2017-05-08 12:42:42 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-05-08 12:42:44 +0100 |
commit | d891e5f731562fd46948116a4cef30f61748f410 (patch) | |
tree | cddaff28d8a8203ed6a27da31051c257b9416a5d /app/assets | |
parent | 59c9ec5ce6ef5a59fe989a06f0b8fa94aaba31d7 (diff) | |
download | gitlab-ce-d891e5f731562fd46948116a4cef30f61748f410.tar.gz |
Filter projects by group on search pagesearch-restrict-projects-to-group
After selecting a group, the projects dropdown will now filter by group projects instead
Closes #29489
Diffstat (limited to 'app/assets')
-rw-r--r-- | app/assets/javascripts/search.js | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/app/assets/javascripts/search.js b/app/assets/javascripts/search.js index 15f5963353a..39e4006ac4e 100644 --- a/app/assets/javascripts/search.js +++ b/app/assets/javascripts/search.js @@ -1,4 +1,5 @@ /* eslint-disable func-names, space-before-function-paren, wrap-iife, no-var, one-var, one-var-declaration-per-line, object-shorthand, prefer-arrow-callback, comma-dangle, prefer-template, quotes, no-else-return, max-len */ +/* global Flash */ /* global Api */ (function() { @@ -7,6 +8,7 @@ var $groupDropdown, $projectDropdown; $groupDropdown = $('.js-search-group-dropdown'); $projectDropdown = $('.js-search-project-dropdown'); + this.groupId = $groupDropdown.data('group-id'); this.eventListeners(); $groupDropdown.glDropdown({ selectable: true, @@ -46,14 +48,18 @@ search: { fields: ['name'] }, - data: function(term, callback) { - return Api.projects(term, { order_by: 'id' }, function(data) { - data.unshift({ - name_with_namespace: 'Any' - }); - data.splice(1, 0, 'divider'); - return callback(data); - }); + data: (term, callback) => { + this.getProjectsData(term) + .then((data) => { + data.unshift({ + name_with_namespace: 'Any' + }); + data.splice(1, 0, 'divider'); + + return data; + }) + .then(data => callback(data)) + .catch(() => new Flash('Error fetching projects')); }, id: function(obj) { return obj.id; @@ -95,6 +101,18 @@ return $('.js-search-input').val('').trigger('keyup').focus(); }; + Search.prototype.getProjectsData = function(term) { + return new Promise((resolve) => { + if (this.groupId) { + Api.groupProjects(this.groupId, term, resolve); + } else { + Api.projects(term, { + order_by: 'id', + }, resolve); + } + }); + }; + return Search; })(); }).call(window); |