debian-mirror-gitlab/app/helpers/sorting_helper.rb

324 lines
12 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-04-26 12:48:37 +05:30
module SortingHelper
2021-02-22 17:27:13 +05:30
include SortingTitlesValuesHelper
2015-04-26 12:48:37 +05:30
def sort_options_hash
{
2019-09-04 21:01:54 +05:30
sort_value_created_date => sort_title_created_date,
sort_value_downvotes => sort_title_downvotes,
sort_value_due_date => sort_title_due_date,
sort_value_due_date_later => sort_title_due_date_later,
sort_value_due_date_soon => sort_title_due_date_soon,
sort_value_label_priority => sort_title_label_priority,
sort_value_largest_group => sort_title_largest_group,
sort_value_largest_repo => sort_title_largest_repo,
sort_value_milestone => sort_title_milestone,
sort_value_milestone_later => sort_title_milestone_later,
sort_value_milestone_soon => sort_title_milestone_soon,
sort_value_name => sort_title_name,
sort_value_name_desc => sort_title_name_desc,
sort_value_oldest_created => sort_title_oldest_created,
sort_value_oldest_signin => sort_title_oldest_signin,
sort_value_oldest_updated => sort_title_oldest_updated,
sort_value_recently_created => sort_title_recently_created,
sort_value_recently_signin => sort_title_recently_signin,
sort_value_recently_updated => sort_title_recently_updated,
sort_value_popularity => sort_title_popularity,
sort_value_priority => sort_title_priority,
sort_value_upvotes => sort_title_upvotes,
sort_value_contacted_date => sort_title_contacted_date,
2019-12-21 20:55:43 +05:30
sort_value_relative_position => sort_title_relative_position,
sort_value_size => sort_title_size,
2021-01-29 00:20:46 +05:30
sort_value_expire_date => sort_title_expire_date,
sort_value_relevant => sort_title_relevant
2015-04-26 12:48:37 +05:30
}
end
2016-06-02 11:05:42 +05:30
def projects_sort_options_hash
2019-09-30 21:07:59 +05:30
use_old_sorting = Feature.disabled?(:project_list_filter_bar) || current_controller?('admin/projects')
2019-07-31 22:56:46 +05:30
2016-09-13 17:45:13 +05:30
options = {
2018-03-17 18:26:18 +05:30
sort_value_latest_activity => sort_title_latest_activity,
2019-09-30 21:07:59 +05:30
sort_value_recently_created => sort_title_created_date,
2018-03-17 18:26:18 +05:30
sort_value_name => sort_title_name,
2021-02-22 17:27:13 +05:30
sort_value_name_desc => sort_title_name_desc,
2019-09-30 21:07:59 +05:30
sort_value_stars_desc => sort_title_stars
2016-06-02 11:05:42 +05:30
}
2016-09-13 17:45:13 +05:30
2019-09-30 21:07:59 +05:30
if use_old_sorting
options = options.merge({
sort_value_oldest_activity => sort_title_oldest_activity,
sort_value_oldest_created => sort_title_oldest_created,
sort_value_recently_created => sort_title_recently_created,
sort_value_stars_desc => sort_title_most_stars
})
end
2016-09-13 17:45:13 +05:30
if current_controller?('admin/projects')
2017-08-17 22:00:37 +05:30
options[sort_value_largest_repo] = sort_title_largest_repo
2016-09-13 17:45:13 +05:30
end
options
2016-06-02 11:05:42 +05:30
end
2019-07-31 22:56:46 +05:30
def projects_sort_option_titles
2019-09-30 21:07:59 +05:30
# Only used for the project filter search bar
projects_sort_options_hash.merge({
2019-07-31 22:56:46 +05:30
sort_value_oldest_activity => sort_title_latest_activity,
sort_value_oldest_created => sort_title_created_date,
sort_value_name_desc => sort_title_name,
sort_value_stars_asc => sort_title_stars
2019-09-30 21:07:59 +05:30
})
2019-07-31 22:56:46 +05:30
end
def projects_reverse_sort_options_hash
{
sort_value_latest_activity => sort_value_oldest_activity,
sort_value_recently_created => sort_value_oldest_created,
sort_value_name => sort_value_name_desc,
sort_value_stars_desc => sort_value_stars_asc,
sort_value_oldest_activity => sort_value_latest_activity,
sort_value_oldest_created => sort_value_recently_created,
sort_value_name_desc => sort_value_name,
sort_value_stars_asc => sort_value_stars_desc
}
end
2021-01-29 00:20:46 +05:30
def search_reverse_sort_options_hash
{
sort_value_recently_created => sort_value_oldest_created,
sort_value_oldest_created => sort_value_recently_created
}
end
2018-03-17 18:26:18 +05:30
def groups_sort_options_hash
{
2018-12-13 13:39:08 +05:30
sort_value_name => sort_title_name,
sort_value_name_desc => sort_title_name_desc,
2018-03-17 18:26:18 +05:30
sort_value_recently_created => sort_title_recently_created,
2018-12-13 13:39:08 +05:30
sort_value_oldest_created => sort_title_oldest_created,
2021-02-22 17:27:13 +05:30
sort_value_latest_activity => sort_title_recently_updated,
sort_value_oldest_activity => sort_title_oldest_updated
2018-03-17 18:26:18 +05:30
}
end
2018-12-13 13:39:08 +05:30
def subgroups_sort_options_hash
groups_sort_options_hash.merge(
2019-07-31 22:56:46 +05:30
sort_value_stars_desc => sort_title_most_stars
2018-12-13 13:39:08 +05:30
)
end
2018-03-17 18:26:18 +05:30
def admin_groups_sort_options_hash
groups_sort_options_hash.merge(
sort_value_largest_group => sort_title_largest_group
)
end
2017-08-17 22:00:37 +05:30
def milestone_sort_options_hash
{
2018-03-17 18:26:18 +05:30
sort_value_name => sort_title_name_asc,
sort_value_name_desc => sort_title_name_desc,
sort_value_due_date_later => sort_title_due_date_later,
sort_value_due_date_soon => sort_title_due_date_soon,
sort_value_start_date_later => sort_title_start_date_later,
sort_value_start_date_soon => sort_title_start_date_soon
2017-08-17 22:00:37 +05:30
}
end
def branches_sort_options_hash
{
2018-03-17 18:26:18 +05:30
sort_value_name => sort_title_name,
sort_value_oldest_updated => sort_title_oldest_updated,
sort_value_recently_updated => sort_title_recently_updated
2017-08-17 22:00:37 +05:30
}
end
def tags_sort_options_hash
{
2018-03-17 18:26:18 +05:30
sort_value_name => sort_title_name,
sort_value_oldest_updated => sort_title_oldest_updated,
sort_value_recently_updated => sort_title_recently_updated
2017-08-17 22:00:37 +05:30
}
end
2018-12-05 23:21:45 +05:30
def label_sort_options_hash
{
sort_value_name => sort_title_name,
sort_value_name_desc => sort_title_name_desc,
sort_value_recently_created => sort_title_recently_created,
sort_value_oldest_created => sort_title_oldest_created,
sort_value_recently_updated => sort_title_recently_updated,
sort_value_oldest_updated => sort_title_oldest_updated
}
end
2019-02-15 15:39:39 +05:30
def users_sort_options_hash
{
sort_value_name => sort_title_name,
sort_value_recently_signin => sort_title_recently_signin,
sort_value_oldest_signin => sort_title_oldest_signin,
sort_value_recently_created => sort_title_recently_created,
sort_value_oldest_created => sort_title_oldest_created,
sort_value_recently_updated => sort_title_recently_updated,
2019-03-02 22:35:43 +05:30
sort_value_oldest_updated => sort_title_oldest_updated,
sort_value_recently_last_activity => sort_title_recently_last_activity,
sort_value_oldest_last_activity => sort_title_oldest_last_activity
2019-02-15 15:39:39 +05:30
}
end
2019-10-12 21:52:04 +05:30
def starrers_sort_options_hash
{
sort_value_name => sort_title_name,
sort_value_name_desc => sort_title_name_desc,
sort_value_recently_created => sort_title_recently_starred,
sort_value_oldest_created => sort_title_oldest_starred
}
end
2021-02-22 17:27:13 +05:30
def member_sort_options_hash
{
sort_value_access_level_asc => sort_title_access_level_asc,
sort_value_access_level_desc => sort_title_access_level_desc,
sort_value_last_joined => sort_title_last_joined,
sort_value_name => sort_title_name_asc,
sort_value_name_desc => sort_title_name_desc,
sort_value_oldest_joined => sort_title_oldest_joined,
sort_value_oldest_signin => sort_title_oldest_signin,
sort_value_recently_signin => sort_title_recently_signin
}
end
2018-03-17 18:26:18 +05:30
def sortable_item(item, path, sorted_by)
link_to item, path, class: sorted_by == item ? 'is-active' : ''
end
2019-02-15 15:39:39 +05:30
def issuable_sort_option_overrides
{
sort_value_oldest_created => sort_value_created_date,
sort_value_oldest_updated => sort_value_recently_updated,
2019-07-31 22:56:46 +05:30
sort_value_milestone_later => sort_value_milestone,
sort_value_due_date_later => sort_value_due_date,
sort_value_least_popular => sort_value_popularity
2019-02-15 15:39:39 +05:30
}
end
def issuable_reverse_sort_order_hash
{
sort_value_created_date => sort_value_oldest_created,
sort_value_recently_created => sort_value_oldest_created,
sort_value_recently_updated => sort_value_oldest_updated,
2019-07-31 22:56:46 +05:30
sort_value_milestone => sort_value_milestone_later,
sort_value_due_date => sort_value_due_date_later,
sort_value_due_date_soon => sort_value_due_date_later,
sort_value_popularity => sort_value_least_popular,
sort_value_most_popular => sort_value_least_popular
2019-02-15 15:39:39 +05:30
}.merge(issuable_sort_option_overrides)
end
2020-03-13 15:44:24 +05:30
def audit_logs_sort_order_hash
{
sort_value_recently_created => sort_title_recently_created,
sort_value_oldest_created => sort_title_oldest_created
}
end
2019-02-15 15:39:39 +05:30
def issuable_sort_option_title(sort_value)
sort_value = issuable_sort_option_overrides[sort_value] || sort_value
sort_options_hash[sort_value]
end
2021-01-29 00:20:46 +05:30
def search_sort_option_title(sort_value)
sort_options_hash[sort_value]
end
2019-09-30 21:07:59 +05:30
def sort_direction_icon(sort_value)
2019-02-15 15:39:39 +05:30
case sort_value
when sort_value_milestone, sort_value_due_date, /_asc\z/
2019-09-30 21:07:59 +05:30
'sort-lowest'
2019-02-15 15:39:39 +05:30
else
2019-09-30 21:07:59 +05:30
'sort-highest'
2019-02-15 15:39:39 +05:30
end
end
2019-09-30 21:07:59 +05:30
def sort_direction_button(reverse_url, reverse_sort, sort_value)
2019-10-12 21:52:04 +05:30
link_class = 'btn btn-default has-tooltip reverse-sort-btn qa-reverse-sort rspec-reverse-sort'
2019-09-30 21:07:59 +05:30
icon = sort_direction_icon(sort_value)
url = reverse_url
2019-02-15 15:39:39 +05:30
2019-09-30 21:07:59 +05:30
unless reverse_sort
url = '#'
2019-02-15 15:39:39 +05:30
link_class += ' disabled'
end
2019-09-30 21:07:59 +05:30
link_to(url, type: 'button', class: link_class, title: s_('SortOptions|Sort direction')) do
2020-10-24 23:57:45 +05:30
sprite_icon(icon)
2019-07-31 22:56:46 +05:30
end
end
2019-09-30 21:07:59 +05:30
def issuable_sort_direction_button(sort_value)
reverse_sort = issuable_reverse_sort_order_hash[sort_value]
url = page_filter_path(sort: reverse_sort)
sort_direction_button(url, reverse_sort, sort_value)
end
2019-07-31 22:56:46 +05:30
def project_sort_direction_button(sort_value)
reverse_sort = projects_reverse_sort_options_hash[sort_value]
2019-09-30 21:07:59 +05:30
url = filter_projects_path(sort: reverse_sort)
2019-07-31 22:56:46 +05:30
2019-09-30 21:07:59 +05:30
sort_direction_button(url, reverse_sort, sort_value)
2019-02-15 15:39:39 +05:30
end
2021-01-29 00:20:46 +05:30
def search_sort_direction_button(sort_value)
reverse_sort = search_reverse_sort_options_hash[sort_value]
url = page_filter_path(sort: reverse_sort)
sort_direction_button(url, reverse_sort, sort_value)
end
2020-10-24 23:57:45 +05:30
def packages_sort_options_hash
{
sort_value_recently_created => sort_title_created_date,
sort_value_oldest_created => sort_title_created_date,
sort_value_name => sort_title_name,
sort_value_name_desc => sort_title_name,
sort_value_version_desc => sort_title_version,
sort_value_version_asc => sort_title_version,
sort_value_type_desc => sort_title_type,
sort_value_type_asc => sort_title_type,
sort_value_project_name_desc => sort_title_project_name,
sort_value_project_name_asc => sort_title_project_name
}
end
def packages_reverse_sort_order_hash
{
sort_value_recently_created => sort_value_oldest_created,
sort_value_oldest_created => sort_value_recently_created,
sort_value_name => sort_value_name_desc,
sort_value_name_desc => sort_value_name,
sort_value_version_desc => sort_value_version_asc,
sort_value_version_asc => sort_value_version_desc,
sort_value_type_desc => sort_value_type_asc,
sort_value_type_asc => sort_value_type_desc,
sort_value_project_name_desc => sort_value_project_name_asc,
sort_value_project_name_asc => sort_value_project_name_desc
}
end
def packages_sort_option_title(sort_value)
packages_sort_options_hash[sort_value] || sort_title_created_date
end
def packages_sort_direction_button(sort_value)
reverse_sort = packages_reverse_sort_order_hash[sort_value]
url = package_sort_path(sort: reverse_sort)
sort_direction_button(url, reverse_sort, sort_value)
end
2015-04-26 12:48:37 +05:30
end
2020-05-24 23:13:21 +05:30
SortingHelper.prepend_if_ee('::EE::SortingHelper')