diff options
author | Phil Hughes <me@iamphill.com> | 2017-05-08 14:42:42 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-05-08 14:42:44 +0300 |
commit | d891e5f731562fd46948116a4cef30f61748f410 (patch) | |
tree | cddaff28d8a8203ed6a27da31051c257b9416a5d /app | |
parent | 59c9ec5ce6ef5a59fe989a06f0b8fa94aaba31d7 (diff) |
Filter projects by group on search page
After selecting a group, the projects dropdown will now filter by group projects instead
Closes #29489
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/search.js | 34 | ||||
-rw-r--r-- | app/views/search/_filter.html.haml | 2 |
2 files changed, 27 insertions, 9 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); diff --git a/app/views/search/_filter.html.haml b/app/views/search/_filter.html.haml index 938be20c7cf..e43796e9654 100644 --- a/app/views/search/_filter.html.haml +++ b/app/views/search/_filter.html.haml @@ -3,7 +3,7 @@ - if params[:project_id].present? = hidden_field_tag :project_id, params[:project_id] .dropdown - %button.dropdown-menu-toggle.js-search-group-dropdown{ type: "button", data: { toggle: "dropdown", default_label: "Group:" } } + %button.dropdown-menu-toggle.js-search-group-dropdown{ type: "button", data: { toggle: "dropdown", default_label: "Group:", group_id: params[:group_id] } } %span.dropdown-toggle-text Group: - if @group.present? |