Commit 2fd7261d authored by Felipe Artur's avatar Felipe Artur

Render ordering button for opposite direction

parent d136f84a
......@@ -3,6 +3,9 @@ module EE
module SortingHelper
extend ::Gitlab::Utils::Override
ORDER_ASC = 'asc'.freeze
ORDER_DESC = 'desc'.freeze
override :sort_options_hash
def sort_options_hash
{
......@@ -16,13 +19,38 @@ module EE
def epics_sort_options_hash
{
sort_value_oldest_created => sort_title_created_date,
sort_value_recently_created => sort_title_created_date,
sort_value_oldest_updated => sort_title_recently_updated,
sort_value_recently_updated => sort_title_recently_updated,
sort_value_start_date => sort_title_start_date,
sort_value_start_date_later => sort_title_start_date,
sort_value_start_date_soon => sort_title_start_date,
sort_value_end_date_later => sort_title_end_date,
sort_value_end_date => sort_title_end_date
}
end
# This method is used to find the opposite ordering parameter for the sort button in the UI.
# Hash key is the descending sorting order and the sort value is the opposite of it for the same field.
# For example: created_at_asc => created_at_desc
def epics_ordering_options_hash
{
sort_value_oldest_created => sort_value_recently_created,
sort_value_oldest_updated => sort_value_recently_updated,
sort_value_start_date_soon => sort_value_start_date_later,
sort_value_end_date => sort_value_end_date_later
}
end
# Creates a button with the opposite ordering for the current field in UI.
def sort_order_button(sort)
opposite_sorting_param = epics_ordering_options_hash[sort] || epics_ordering_options_hash.key(sort)
sort_icon = sort.end_with?('desc') ? 'sort-highest' : ' sort-lowest'
link_to sort_icon, page_filter_path(sort: opposite_sorting_param, label: true)
end
def sort_title_start_date
s_('SortOptions|Start date')
end
......
......@@ -58,6 +58,10 @@ module EE
reorder(::Gitlab::Database.nulls_last_order('end_date', 'DESC'), 'id DESC')
end
scope :order_start_date_desc, -> do
reorder(::Gitlab::Database.nulls_last_order('start_date', 'DESC'), 'id DESC')
end
def etag_caching_enabled?
true
end
......@@ -106,6 +110,7 @@ module EE
case method.to_s
when 'start_or_end_date' then order_start_or_end_date_asc
when 'start_date_asc' then order_start_date_asc
when 'start_date_desc' then order_start_date_desc
when 'end_date_asc' then order_end_date_asc
when 'end_date_desc' then order_end_date_desc
else
......
......@@ -9,12 +9,9 @@
%li
= sortable_item(sort_title_created_date, page_filter_path(sort: sort_value_recently_created, label: true), sorted_by)
= sortable_item(sort_title_recently_updated, page_filter_path(sort: sort_value_recently_updated, label: true), sorted_by)
= sortable_item(sort_title_start_date, page_filter_path(sort: sort_value_start_date, label: true), sorted_by)
= sortable_item(sort_title_end_date, page_filter_path(sort: sort_value_end_date, label: true), sorted_by)
= sortable_item(sort_title_start_date, page_filter_path(sort: sort_value_start_date_later, label: true), sorted_by)
= sortable_item(sort_title_end_date, page_filter_path(sort: sort_value_end_date_later, label: true), sorted_by)
%button.dropdown-toggle-split.pt-2{ type: 'button' }
= sprite_icon('sort-highest', size: 16)
-# = sprite_icon('sort-lowest', size: 16)
= sorted_by
= |
= @sort
= sort_order_button(@sort)
-#= sprite_icon('sort-highest', size: 16)
-#= sprite_icon('sort-lowest', size: 16)
......@@ -67,7 +67,6 @@ 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