Commit 8151efa5 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'feature/improve-weight-filter' into 'master'

Improve weight filter for issues

Adds options: Any, No weight and Everything.

Fixes https://gitlab.com/gitlab-org/gitlab-ee/issues/274

See merge request !172
parents a4145797 9e1c0e90
Please view this file on the master branch, on stable branches it's out of date.
v 8.6.0 (unreleased)
- Improve weight filter for issues
v 8.5.1
- Fix adding pages domain to projects in groups
......
......@@ -280,11 +280,27 @@ class IssuableFinder
end
def by_weight(items)
if params[:weight].present?
items = items.where(weight: params[:weight])
return items unless weights?
if filter_by_no_weight?
items.where(weight: [-1, nil])
elsif filter_by_any_weight?
items.where.not(weight: [-1, nil])
else
items.where(weight: params[:weight])
end
end
items
def weights?
params[:weight].present? && params[:weight] != Issue::WEIGHT_ALL
end
def filter_by_no_weight?
params[:weight] == Issue::WEIGHT_NONE
end
def filter_by_any_weight?
params[:weight] == Issue::WEIGHT_ANY
end
def label_names
......
......@@ -139,13 +139,18 @@ module IssuesHelper
end.to_h
end
def projects_weight_options(selected = nil)
options = (Issue::WEIGHT_RANGE).map do |i|
[i, i]
end
def issues_weight_options(selected = nil, edit: false)
weights = edit ? edit_weights : issue_weights
options_for_select(weights, selected || params[:weight])
end
def issue_weights(weight_array = Issue.weight_options)
weight_array.zip(weight_array)
end
options.unshift(['Any', nil])
options_for_select(options, selected || params[:weight])
def edit_weights
issue_weights([Issue::WEIGHT_NONE] + Issue::WEIGHT_RANGE.to_a)
end
# Required for Banzai::Filter::IssueReferenceFilter
......
......@@ -30,6 +30,9 @@ class Issue < ActiveRecord::Base
include Elastic::IssuesSearch
WEIGHT_RANGE = 1..9
WEIGHT_ALL = 'Everything'
WEIGHT_ANY = 'Any Weight'
WEIGHT_NONE = 'No Weight'
ActsAsTaggableOn.strict_case_match = true
......@@ -123,4 +126,8 @@ class Issue < ActiveRecord::Base
note.all_references(current_user).merge_requests
end.uniq.select { |mr| mr.open? && mr.closes_issue?(self) }
end
def self.weight_options
[WEIGHT_ALL, WEIGHT_ANY, WEIGHT_NONE] + WEIGHT_RANGE.to_a
end
end
......@@ -26,7 +26,7 @@
- if controller.controller_name == 'issues'
.filter-item.inline.weight-filter
= select_tag('weight', projects_weight_options,
= select_tag('weight', issues_weight_options(edit: false),
class: 'select2 trigger-submit', include_blank: true,
data: {placeholder: 'Weight'})
......
......@@ -59,7 +59,7 @@
= f.label :label_ids, class: 'control-label' do
Weight
.col-sm-10
= f.select :weight, projects_weight_options(issuable.weight), { include_blank: true },
= f.select :weight, issues_weight_options(issuable.weight, edit: true), { include_blank: true },
{ class: 'select2 js-select2', data: { placeholder: "Select weight" }}
.form-group
......
......@@ -115,7 +115,7 @@
- else
.light None
.selectbox.hide-collapsed
= f.select :weight, projects_weight_options(issuable.weight), { include_blank: true },
= f.select :weight, issues_weight_options(issuable.weight, edit: true), { include_blank: true },
{ class: 'select2 js-select2', data: { placeholder: "Select weight" }}
= render "shared/issuable/participants", participants: issuable.participants(current_user)
......
require 'rails_helper'
feature 'Issue filtering by Weight', feature: true do
include Select2Helper
let(:project) { create(:project, :public) }
let(:weight_num) { random_weight }
before(:each) do
create(:issue, project: project, weight: nil)
create(:issue, project: project, weight: weight_num)
create(:issue, project: project, weight: weight_num)
end
scenario 'filters by no Weight', js: true do
visit_issues(project)
filter_by_weight(Issue::WEIGHT_NONE)
expect(page).to have_css('.issue', count: 1)
end
scenario 'filters by any Weight', js: true do
visit_issues(project)
filter_by_weight(Issue::WEIGHT_ANY)
expect(page).to have_css('.issue', count: 2)
end
scenario 'filters by a specific Weight', js: true do
visit_issues(project)
filter_by_weight(weight_num)
expect(page).to have_css('.issue', count: 2)
end
scenario 'all weights', js: true do
visit_issues(project)
filter_by_weight(Issue::WEIGHT_ALL)
expect(page).to have_css('.issue', count: 3)
end
def visit_issues(project)
visit namespace_project_issues_path(project.namespace, project)
end
def filter_by_weight(title)
select2(title, from: '#weight')
end
def random_weight
Issue::WEIGHT_RANGE.to_a.sample
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment