Module: SortingHelper

Instance Method Summary collapse

Methods included from SortingTitlesValuesHelper

#sort_title_closed_date, #sort_title_closed_earlier, #sort_title_closed_recently, #sort_title_contacted_date, #sort_title_created_date, #sort_title_downvotes, #sort_title_due_date, #sort_title_due_date_later, #sort_title_due_date_soon, #sort_title_expire_date, #sort_title_label_priority, #sort_title_largest_group, #sort_title_largest_repo, #sort_title_latest_activity, #sort_title_merged_date, #sort_title_merged_earlier, #sort_title_merged_recently, #sort_title_milestone, #sort_title_milestone_later, #sort_title_milestone_soon, #sort_title_most_stars, #sort_title_name, #sort_title_name_asc, #sort_title_name_desc, #sort_title_oldest_activity, #sort_title_oldest_created, #sort_title_oldest_last_activity, #sort_title_oldest_signin, #sort_title_oldest_starred, #sort_title_oldest_updated, #sort_title_popularity, #sort_title_priority, #sort_title_recently_created, #sort_title_recently_last_activity, #sort_title_recently_signin, #sort_title_recently_starred, #sort_title_recently_updated, #sort_title_relative_position, #sort_title_size, #sort_title_stars, #sort_title_start_date_later, #sort_title_start_date_soon, #sort_title_title, #sort_title_upvotes, #sort_value_closed_date, #sort_value_closed_earlier, #sort_value_closed_recently, #sort_value_contacted_date, #sort_value_created_date, #sort_value_downvotes, #sort_value_due_date, #sort_value_due_date_later, #sort_value_due_date_soon, #sort_value_expire_date, #sort_value_label_priority, #sort_value_largest_group, #sort_value_largest_repo, #sort_value_latest_activity, #sort_value_least_popular, #sort_value_merged_date, #sort_value_merged_earlier, #sort_value_merged_recently, #sort_value_milestone, #sort_value_milestone_later, #sort_value_milestone_soon, #sort_value_most_popular, #sort_value_name, #sort_value_name_desc, #sort_value_oldest_activity, #sort_value_oldest_created, #sort_value_oldest_last_activity, #sort_value_oldest_signin, #sort_value_oldest_updated, #sort_value_popularity, #sort_value_priority, #sort_value_recently_created, #sort_value_recently_last_activity, #sort_value_recently_signin, #sort_value_recently_updated, #sort_value_relative_position, #sort_value_size, #sort_value_stars_asc, #sort_value_stars_desc, #sort_value_start_date_later, #sort_value_start_date_soon, #sort_value_title, #sort_value_title_desc, #sort_value_upvotes

Instance Method Details

#admin_groups_sort_options_hashObject


131
132
133
134
135
# File 'app/helpers/sorting_helper.rb', line 131

def admin_groups_sort_options_hash
  groups_sort_options_hash.merge(
    sort_value_largest_group => sort_title_largest_group
  )
end

#admin_users_sort_options(path_params) ⇒ Object


385
386
387
388
389
390
391
392
393
# File 'app/helpers/sorting_helper.rb', line 385

def admin_users_sort_options(path_params)
  users_sort_options_hash.map do |value, text|
    {
      value: value,
      text: text,
      href: admin_users_path(sort: value, **path_params)
    }
  end
end

#audit_logs_sort_order_hashObject


240
241
242
243
244
245
# File 'app/helpers/sorting_helper.rb', line 240

def audit_logs_sort_order_hash
  {
    sort_value_recently_created => sort_title_recently_created,
    sort_value_oldest_created   => sort_title_oldest_created
  }
end

#branches_sort_options_hashObject


148
149
150
151
152
153
154
# File 'app/helpers/sorting_helper.rb', line 148

def branches_sort_options_hash
  {
    sort_value_name             => sort_title_name,
    sort_value_oldest_updated   => sort_title_oldest_updated,
    sort_value_recently_updated => sort_title_recently_updated
  }
end

#can_sort_by_issue_weight?(_viewing_issues) ⇒ Boolean

Returns:

  • (Boolean)

271
272
273
# File 'app/helpers/sorting_helper.rb', line 271

def can_sort_by_issue_weight?(_viewing_issues)
  false
end

#due_date_optionObject


275
276
277
# File 'app/helpers/sorting_helper.rb', line 275

def due_date_option
  { value: sort_value_due_date, text: sort_title_due_date, href: page_filter_path(sort: sort_value_due_date) }
end

#forks_reverse_sort_options_hashObject


105
106
107
108
109
110
111
112
# File 'app/helpers/sorting_helper.rb', line 105

def forks_reverse_sort_options_hash
  {
    sort_value_recently_created => sort_value_oldest_created,
    sort_value_oldest_created   => sort_value_recently_created,
    sort_value_latest_activity  => sort_value_oldest_activity,
    sort_value_oldest_activity  => sort_value_latest_activity
  }
end

#forks_sort_direction_button(sort_value, without = [:state, :scope, :label_name, :milestone_id, :assignee_id, :author_id]) ⇒ Object


378
379
380
381
382
383
# File 'app/helpers/sorting_helper.rb', line 378

def forks_sort_direction_button(sort_value, without = [:state, :scope, :label_name, :milestone_id, :assignee_id, :author_id])
  reverse_sort = forks_reverse_sort_options_hash[sort_value]
  url = page_filter_path(sort: reverse_sort, without: without)

  sort_direction_button(url, reverse_sort, sort_value)
end

#forks_sort_options_hashObject


73
74
75
76
77
78
79
80
# File 'app/helpers/sorting_helper.rb', line 73

def forks_sort_options_hash
  {
    sort_value_recently_created => sort_title_created_date,
    sort_value_oldest_created   => sort_title_created_date,
    sort_value_latest_activity  => sort_title_latest_activity,
    sort_value_oldest_activity  => sort_title_latest_activity
  }
end

#groups_sort_options_hashObject


114
115
116
117
118
119
120
121
122
123
# File 'app/helpers/sorting_helper.rb', line 114

def groups_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_latest_activity  => sort_title_recently_updated,
    sort_value_oldest_activity  => sort_title_oldest_updated
  }
end

#issuable_reverse_sort_order_hashObject


222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'app/helpers/sorting_helper.rb', line 222

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,
    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_merged_date => sort_value_merged_recently,
    sort_value_merged_earlier => sort_value_merged_recently,
    sort_value_closed_date => sort_value_closed_recently,
    sort_value_closed_earlier => sort_value_closed_recently,
    sort_value_popularity => sort_value_least_popular,
    sort_value_most_popular => sort_value_least_popular,
    sort_value_title => sort_value_title_desc
  }.merge(issuable_sort_option_overrides)
end

#issuable_sort_direction_button(sort_value) ⇒ Object


323
324
325
326
327
328
# File 'app/helpers/sorting_helper.rb', line 323

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

#issuable_sort_option_overridesObject


209
210
211
212
213
214
215
216
217
218
219
220
# File 'app/helpers/sorting_helper.rb', line 209

def issuable_sort_option_overrides
  {
    sort_value_oldest_created => sort_value_created_date,
    sort_value_oldest_updated => sort_value_recently_updated,
    sort_value_milestone_later => sort_value_milestone,
    sort_value_due_date_later => sort_value_due_date,
    sort_value_merged_recently => sort_value_merged_date,
    sort_value_closed_recently => sort_value_closed_date,
    sort_value_least_popular => sort_value_popularity,
    sort_value_title_desc => sort_value_title
  }
end

#issuable_sort_option_title(sort_value) ⇒ Object


247
248
249
250
251
# File 'app/helpers/sorting_helper.rb', line 247

def issuable_sort_option_title(sort_value)
  sort_value = issuable_sort_option_overrides[sort_value] || sort_value

  sort_options_hash[sort_value]
end

#issuable_sort_options(viewing_issues, viewing_merge_requests) ⇒ Object


253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'app/helpers/sorting_helper.rb', line 253

def issuable_sort_options(viewing_issues, viewing_merge_requests)
  options = [
    { value: sort_value_priority, text: sort_title_priority, href: page_filter_path(sort: sort_value_priority) },
    { value: sort_value_created_date, text: sort_title_created_date, href: page_filter_path(sort: sort_value_created_date) },
    { value: sort_value_closed_date, text: sort_title_closed_date, href: page_filter_path(sort: sort_value_closed_date) },
    { value: sort_value_recently_updated, text: sort_title_recently_updated, href: page_filter_path(sort: sort_value_recently_updated) },
    { value: sort_value_milestone, text: sort_title_milestone, href: page_filter_path(sort: sort_value_milestone) }
  ]

  options.concat([due_date_option]) if viewing_issues

  options.concat([popularity_option, label_priority_option])
  options.concat([merged_option]) if viewing_merge_requests
  options.concat([relative_position_option]) if viewing_issues

  options.concat([title_option])
end

#label_priority_optionObject


283
284
285
# File 'app/helpers/sorting_helper.rb', line 283

def label_priority_option
  { value: sort_value_label_priority, text: sort_title_label_priority, href: page_filter_path(sort: sort_value_label_priority) }
end

#label_sort_options_hashObject


164
165
166
167
168
169
170
171
172
173
# File 'app/helpers/sorting_helper.rb', line 164

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

#merged_optionObject


287
288
289
# File 'app/helpers/sorting_helper.rb', line 287

def merged_option
  { value: sort_value_merged_date, text: sort_title_merged_date, href: page_filter_path(sort: sort_value_merged_date) }
end

#milestones_sort_options_hashObject


137
138
139
140
141
142
143
144
145
146
# File 'app/helpers/sorting_helper.rb', line 137

def milestones_sort_options_hash
  {
    sort_value_due_date_soon    => sort_title_due_date_soon,
    sort_value_due_date_later   => sort_title_due_date_later,
    sort_value_start_date_soon  => sort_title_start_date_soon,
    sort_value_start_date_later => sort_title_start_date_later,
    sort_value_name             => sort_title_name_asc,
    sort_value_name_desc        => sort_title_name_desc
  }
end

#packages_reverse_sort_order_hashObject


352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'app/helpers/sorting_helper.rb', line 352

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

#packages_sort_direction_button(sort_value) ⇒ Object


371
372
373
374
375
376
# File 'app/helpers/sorting_helper.rb', line 371

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

#packages_sort_option_title(sort_value) ⇒ Object


367
368
369
# File 'app/helpers/sorting_helper.rb', line 367

def packages_sort_option_title(sort_value)
  packages_sort_options_hash[sort_value] || sort_title_created_date
end

#packages_sort_options_hashObject


337
338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'app/helpers/sorting_helper.rb', line 337

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

#popularity_optionObject


279
280
281
# File 'app/helpers/sorting_helper.rb', line 279

def popularity_option
  { value: sort_value_popularity, text: sort_title_popularity, href: page_filter_path(sort: sort_value_popularity) }
end

#project_sort_direction_button(sort_value) ⇒ Object


330
331
332
333
334
335
# File 'app/helpers/sorting_helper.rb', line 330

def project_sort_direction_button(sort_value)
  reverse_sort = projects_reverse_sort_options_hash[sort_value]
  url = filter_projects_path(sort: reverse_sort)

  sort_direction_button(url, reverse_sort, sort_value)
end

#projects_reverse_sort_options_hashObject


92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/helpers/sorting_helper.rb', line 92

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

#projects_sort_option_titlesObject


82
83
84
85
86
87
88
89
90
# File 'app/helpers/sorting_helper.rb', line 82

def projects_sort_option_titles
  # Only used for the project filter search bar
  projects_sort_options_hash.merge({
    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
  })
end

#projects_sort_options_hashObject

rubocop: enable Metrics/AbcSize


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/helpers/sorting_helper.rb', line 46

def projects_sort_options_hash
  use_old_sorting = Feature.disabled?(:project_list_filter_bar) || current_controller?('admin/projects')

  options = {
    sort_value_latest_activity  => sort_title_latest_activity,
    sort_value_recently_created => sort_title_created_date,
    sort_value_name             => sort_title_name,
    sort_value_name_desc        => sort_title_name_desc,
    sort_value_stars_desc       => sort_title_stars
  }

  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

  if current_controller?('admin/projects')
    options[sort_value_largest_repo] = sort_title_largest_repo
  end

  options
end

#relative_position_optionObject


291
292
293
# File 'app/helpers/sorting_helper.rb', line 291

def relative_position_option
  { value: sort_value_relative_position, text: sort_title_relative_position, href: page_filter_path(sort: sort_value_relative_position) }
end

#runners_sort_options_hashObject


189
190
191
192
193
194
# File 'app/helpers/sorting_helper.rb', line 189

def runners_sort_options_hash
  {
    sort_value_created_date => sort_title_created_date,
    sort_value_contacted_date => sort_title_contacted_date
  }
end

#sort_direction_button(reverse_url, reverse_sort, sort_value) ⇒ Object


308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'app/helpers/sorting_helper.rb', line 308

def sort_direction_button(reverse_url, reverse_sort, sort_value)
  link_class = 'gl-button btn btn-default btn-icon has-tooltip reverse-sort-btn qa-reverse-sort rspec-reverse-sort'
  icon = sort_direction_icon(sort_value)
  url = reverse_url

  unless reverse_sort
    url = '#'
    link_class += ' disabled'
  end

  link_to(url, type: 'button', class: link_class, title: s_('SortOptions|Sort direction')) do
    sprite_icon(icon)
  end
end

#sort_direction_icon(sort_value) ⇒ Object


299
300
301
302
303
304
305
306
# File 'app/helpers/sorting_helper.rb', line 299

def sort_direction_icon(sort_value)
  case sort_value
  when sort_value_milestone, sort_value_due_date, sort_value_merged_date, sort_value_closed_date, /_asc\z/
    'sort-lowest'
  else
    'sort-highest'
  end
end

#sort_options_hashObject

rubocop: disable Metrics/AbcSize


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/sorting_helper.rb', line 7

def sort_options_hash
  {
    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_updated    => sort_title_oldest_updated,
    sort_value_recently_created  => sort_title_recently_created,
       => ,
    sort_value_recently_updated  => sort_title_recently_updated,
    sort_value_popularity        => sort_title_popularity,
    sort_value_priority          => sort_title_priority,
    sort_value_merged_date       => sort_title_merged_date,
    sort_value_merged_recently   => sort_title_merged_recently,
    sort_value_merged_earlier    => sort_title_merged_earlier,
    sort_value_closed_date       => sort_title_closed_date,
    sort_value_closed_recently   => sort_title_closed_recently,
    sort_value_closed_earlier    => sort_title_closed_earlier,
    sort_value_upvotes           => sort_title_upvotes,
    sort_value_contacted_date    => sort_title_contacted_date,
    sort_value_relative_position => sort_title_relative_position,
    sort_value_size              => sort_title_size,
    sort_value_expire_date       => sort_title_expire_date,
    sort_value_title             => sort_title_title
  }
end

#sortable_item(item, path, sorted_by) ⇒ Object


205
206
207
# File 'app/helpers/sorting_helper.rb', line 205

def sortable_item(item, path, sorted_by)
  link_to item, path, class: sorted_by == item ? 'is-active' : ''
end

#starrers_sort_options_hashObject


196
197
198
199
200
201
202
203
# File 'app/helpers/sorting_helper.rb', line 196

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

#subgroups_sort_options_hashObject


125
126
127
128
129
# File 'app/helpers/sorting_helper.rb', line 125

def subgroups_sort_options_hash
  groups_sort_options_hash.merge(
    sort_value_stars_desc => sort_title_most_stars
  )
end

#tags_sort_options_hashObject


156
157
158
159
160
161
162
# File 'app/helpers/sorting_helper.rb', line 156

def tags_sort_options_hash
  {
    sort_value_name             => sort_title_name,
    sort_value_oldest_updated   => sort_title_oldest_updated,
    sort_value_recently_updated => sort_title_recently_updated
  }
end

#title_optionObject


295
296
297
# File 'app/helpers/sorting_helper.rb', line 295

def title_option
  { value: sort_value_title, text: sort_title_title, href: page_filter_path(sort: sort_value_title) }
end

#users_sort_options_hashObject


175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'app/helpers/sorting_helper.rb', line 175

def users_sort_options_hash
  {
    sort_value_name => sort_title_name,
     => ,
     => ,
    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,
    sort_value_recently_last_activity => sort_title_recently_last_activity,
    sort_value_oldest_last_activity => sort_title_oldest_last_activity
  }
end