diff options
author | Stan Hu <stanhu@gmail.com> | 2015-10-06 09:57:13 -0700 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2015-10-07 07:21:50 -0700 |
commit | dfbbc80611fbdafe6f5ed809f98fc63987d104a6 (patch) | |
tree | 00a5f131e4b54c14162fc2a89cc2cca1a73512c9 /app/finders | |
parent | cc8c91a1183ebfc5bb252f5e7f3f09fc20546476 (diff) | |
download | gitlab-ce-dfbbc80611fbdafe6f5ed809f98fc63987d104a6.tar.gz |
Support filtering by "Any" milestone or issue and fix "No Milestone" and "No Label" filters
Closes #2619
Closes https://github.com/gitlabhq/gitlabhq/issues/9631
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/issuable_finder.rb | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index 6aa16673d63..97c7e74c294 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -72,11 +72,15 @@ class IssuableFinder params[:milestone_title].present? end + def no_milestones? + milestones? && params[:milestone_title] == Milestone::None.title + end + def milestones return @milestones if defined?(@milestones) @milestones = - if milestones? && params[:milestone_title] != Milestone::None.title + if milestones? Milestone.where(title: params[:milestone_title]) else nil @@ -183,7 +187,11 @@ class IssuableFinder def by_milestone(items) if milestones? - items = items.where(milestone_id: milestones.try(:pluck, :id)) + if no_milestones? + items = items.where(milestone_id: [-1, nil]) + else + items = items.where(milestone_id: milestones.try(:pluck, :id)) + end end items @@ -207,13 +215,19 @@ class IssuableFinder def by_label(items) if params[:label_name].present? - label_names = params[:label_name].split(",") + if params[:label_name] == Label::None.title + item_ids = LabelLink.where(target_type: klass.name).pluck(:target_id) - item_ids = LabelLink.joins(:label). - where('labels.title in (?)', label_names). - where(target_type: klass.name).pluck(:target_id) + items = items.where('id NOT IN (?)', item_ids) + else + label_names = params[:label_name].split(",") + + item_ids = LabelLink.joins(:label). + where('labels.title in (?)', label_names). + where(target_type: klass.name).pluck(:target_id) - items = items.where(id: item_ids) + items = items.where(id: item_ids) + end end items |