Commit 8803a2f6 authored by Felipe Artur's avatar Felipe Artur

Save filter option to backend

parent 400314c7
class AddEpicsSortToUserPreference < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
add_column :user_preferences, :epics_sort, :string
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20181107054254) do
ActiveRecord::Schema.define(version: 20181114163403) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -2968,6 +2968,7 @@ ActiveRecord::Schema.define(version: 20181107054254) do
t.integer "merge_request_notes_filter", limit: 2, default: 0, null: false
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.string "epics_sort"
end
add_index "user_preferences", ["user_id"], name: "index_user_preferences_on_user_id", unique: true, using: :btree
......
......@@ -18,6 +18,7 @@ module EpicsActions
case value
when 'start_date_asc' then sort_value_start_date
when 'end_date_asc' then sort_value_end_date
when 'end_date_desc' then sort_value_end_date_later
else
super(value)
end
......
module EpicsSorting
def set_epics_sorting
if current_user
set_sort_order_from_user_preference
else
set_sort_order_from_cookie
end
end
def set_sort_order_from_user_preference
return params[:sort] unless current_user
user_preference = current_user.user_preference
sort_param = params[:sort]
sort_param ||= user_preference.epics_sort
if user_preference.epics_sort != sort_param
user_preference.update(epics_sort: sort_param)
end
params[:sort] = sort_param
end
end
......@@ -5,6 +5,7 @@ class Groups::EpicsController < Groups::ApplicationController
include ToggleSubscriptionAction
include RendersNotes
include EpicsActions
include EpicsSorting
before_action :check_epics_available!
before_action :epic, except: [:index, :create]
......@@ -109,7 +110,8 @@ class Groups::EpicsController < Groups::ApplicationController
end
def filter_params
set_sort_order_from_cookie
set_epics_sorting
super.merge(start_date: params[:start_date], end_date: params[:end_date])
end
end
......@@ -2,6 +2,7 @@ module Groups
class RoadmapController < Groups::ApplicationController
include IssuableCollections
include EpicsActions
include EpicsSorting
before_action :check_epics_available!
before_action :group
......@@ -9,7 +10,7 @@ module Groups
def show
# show roadmap for a group
set_sort_order_from_cookie
set_epics_sorting
@sort = params[:sort] || default_sort_order
@epics_count = EpicsFinder.new(current_user, group_id: @group.id).execute.count
end
......
......@@ -42,6 +42,10 @@ module EE
'end_date_asc'
end
def sort_value_end_date_later
'end_date_desc'
end
def sort_value_less_weight
'weight_asc'
end
......
......@@ -54,6 +54,10 @@ module EE
reorder(::Gitlab::Database.nulls_last_order('end_date'), 'id DESC')
end
scope :order_end_date_desc, -> do
reorder(::Gitlab::Database.nulls_last_order('end_date', 'DESC'), 'id DESC')
end
def etag_caching_enabled?
true
end
......@@ -103,6 +107,7 @@ module EE
when 'start_or_end_date' then order_start_or_end_date_asc
when 'start_date_asc' then order_start_date_asc
when 'end_date_asc' then order_end_date_asc
when 'end_date_desc' then order_end_date_desc
else
super
end
......
......@@ -43,23 +43,23 @@ describe 'epics list', :js do
end
end
it 'sorts by end_date ASC by default' do
expect(page).to have_button('Due date')
it 'sorts by created_at DESC by default' do
expect(page).to have_button('Last created')
page.within('.content-wrapper .content') do
expect(find('.top-area')).to have_content('All 3')
page.within(".issuable-list") do
page.within("li:nth-child(1)") do
expect(page).to have_content(epic1.title)
expect(page).to have_content(epic3.title)
end
page.within("li:nth-child(2)") do
expect(page).to have_content(epic3.title)
expect(page).to have_content(epic2.title)
end
page.within("li:nth-child(3)") do
expect(page).to have_content(epic2.title)
expect(page).to have_content(epic1.title)
end
end
end
......@@ -67,6 +67,7 @@ describe 'epics list', :js do
it 'sorts by the selected value and stores the selection for epic list & roadmap' do
page.within('.epics-other-filters') do
live_debug
click_button 'Due date'
sort_options = find('ul.dropdown-menu-sort li').all('a').collect(&:text)
......
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