Commit a9a338f3 authored by Rémy Coutable's avatar Rémy Coutable

Move weight scopes & sort methods to Issue

This ensure MergeRequest won't try to sort by weight, which would fail
since it doesn't have weight.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 77b42d92
......@@ -45,8 +45,6 @@ module Issuable
scope :order_milestone_due_desc, -> { outer_join_milestone.reorder('milestones.due_date IS NULL ASC, milestones.due_date DESC, milestones.id DESC') }
scope :order_milestone_due_asc, -> { outer_join_milestone.reorder('milestones.due_date IS NULL ASC, milestones.due_date ASC, milestones.id ASC') }
scope :without_label, -> { joins("LEFT OUTER JOIN label_links ON label_links.target_type = '#{name}' AND label_links.target_id = #{table_name}.id").where(label_links: { id: nil }) }
scope :order_weight_desc, -> { reorder('weight IS NOT NULL, weight DESC') }
scope :order_weight_asc, -> { reorder('weight ASC') }
scope :left_joins_milestones, -> { joins("LEFT OUTER JOIN milestones ON #{table_name}.milestone_id = milestones.id") }
scope :order_milestone_due_desc, -> { left_joins_milestones.reorder('milestones.due_date IS NULL, milestones.id IS NULL, milestones.due_date DESC') }
......@@ -122,8 +120,6 @@ module Issuable
when 'milestone_due_desc' then order_milestone_due_desc
when 'downvotes_desc' then order_downvotes_desc
when 'upvotes_desc' then order_upvotes_desc
when 'weight_desc' then order_weight_desc
when 'weight_asc' then order_weight_asc
when 'priority' then order_labels_priority(excluded_labels: excluded_labels)
else
order_by(method)
......
......@@ -37,6 +37,8 @@ class Issue < ActiveRecord::Base
scope :order_due_date_asc, -> { reorder('issues.due_date IS NULL, issues.due_date ASC') }
scope :order_due_date_desc, -> { reorder('issues.due_date IS NULL, issues.due_date DESC') }
scope :order_weight_desc, -> { reorder('weight IS NOT NULL, weight DESC') }
scope :order_weight_asc, -> { reorder('weight ASC') }
state_machine :state, initial: :opened do
event :close do
......@@ -93,6 +95,8 @@ class Issue < ActiveRecord::Base
case method.to_s
when 'due_date_asc' then order_due_date_asc
when 'due_date_desc' then order_due_date_desc
when 'weight_desc' then order_weight_desc
when 'weight_asc' then order_weight_asc
else
super
end
......
......@@ -18,10 +18,11 @@
= sort_title_recently_updated
= link_to page_filter_path(sort: sort_value_oldest_updated) do
= sort_title_oldest_updated
= link_to page_filter_path(sort: sort_value_more_weight) do
= sort_title_more_weight
= link_to page_filter_path(sort: sort_value_less_weight) do
= sort_title_less_weight
- if local_assigns[:type] == :issues
= link_to page_filter_path(sort: sort_value_more_weight) do
= sort_title_more_weight
= link_to page_filter_path(sort: sort_value_less_weight) do
= sort_title_less_weight
= link_to page_filter_path(sort: sort_value_milestone_soon) do
= sort_title_milestone_soon
= link_to page_filter_path(sort: sort_value_milestone_later) do
......
......@@ -26,7 +26,7 @@
.filter-item.inline.labels-filter
= render "shared/issuable/label_dropdown"
- if controller.controller_name == 'issues'
- if local_assigns[:type] == :issues
.filter-item.inline.weight-filter
- if params[:weight]
= hidden_field_tag(:weight, params[:weight])
......@@ -39,7 +39,7 @@
= weight
.pull-right
= render 'shared/sort_dropdown'
= render 'shared/sort_dropdown', type: local_assigns[:type]
- if controller.controller_name == 'issues'
.issues_bulk_update.hide
......
require 'spec_helper'
describe 'Issue sorting by Weight', feature: true do
include SortingHelper
let(:project) { create(:project) }
let(:foo) { create(:issue, title: 'foo', project: project) }
let(:bar) { create(:issue, title: 'bar', project: project) }
before do
login_as :user
end
describe 'sorting by weight' do
before do
foo.update(weight: 5)
bar.update(weight: 10)
end
it 'sorts by more weight' do
visit namespace_project_issues_path(project.namespace, project, sort: sort_value_more_weight)
expect(first_issue).to include('bar')
end
it 'sorts by less weight' do
visit namespace_project_issues_path(project.namespace, project, sort: sort_value_less_weight)
expect(first_issue).to include('foo')
end
end
def first_issue
page.all('ul.issues-list > li').first.text
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