sorting_helper.rb 10.7 KB
Newer Older
1 2
# frozen_string_literal: true

3
module SortingHelper
4 5
  def sort_options_hash
    {
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
      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,
22
      sort_value_recently_created => sort_title_recently_created,
23 24 25 26
      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,
27 28
      sort_value_upvotes          => sort_title_upvotes,
      sort_value_contacted_date   => sort_title_contacted_date
29 30 31
    }
  end

32
  def projects_sort_options_hash
33
    options = {
34 35 36 37
      sort_value_latest_activity  => sort_title_latest_activity,
      sort_value_name             => sort_title_name,
      sort_value_oldest_activity  => sort_title_oldest_activity,
      sort_value_oldest_created   => sort_title_oldest_created,
38 39
      sort_value_recently_created => sort_title_recently_created,
      sort_value_most_stars       => sort_title_most_stars
40
    }
41 42

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

    options
47 48
  end

49
  def groups_sort_options_hash
50
    {
51 52
      sort_value_name             => sort_title_name,
      sort_value_name_desc        => sort_title_name_desc,
53
      sort_value_recently_created => sort_title_recently_created,
54
      sort_value_oldest_created   => sort_title_oldest_created,
55
      sort_value_recently_updated => sort_title_recently_updated,
56
      sort_value_oldest_updated   => sort_title_oldest_updated
57
    }
58
  end
59

60 61 62 63 64 65
  def subgroups_sort_options_hash
    groups_sort_options_hash.merge(
      sort_value_most_stars => sort_title_most_stars
    )
  end

66 67 68 69
  def admin_groups_sort_options_hash
    groups_sort_options_hash.merge(
      sort_value_largest_group => sort_title_largest_group
    )
70 71
  end

72 73
  def member_sort_options_hash
    {
74
      sort_value_access_level_asc  => sort_title_access_level_asc,
75
      sort_value_access_level_desc => sort_title_access_level_desc,
76 77 78 79 80 81
      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
82 83 84
    }
  end

85 86
  def milestone_sort_options_hash
    {
87 88 89 90 91 92
      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
93 94 95
    }
  end

96 97
  def branches_sort_options_hash
    {
98 99 100
      sort_value_name             => sort_title_name,
      sort_value_oldest_updated   => sort_title_oldest_updated,
      sort_value_recently_updated => sort_title_recently_updated
101 102 103
    }
  end

104 105
  def tags_sort_options_hash
    {
106 107 108
      sort_value_name             => sort_title_name,
      sort_value_oldest_updated   => sort_title_oldest_updated,
      sort_value_recently_updated => sort_title_recently_updated
109 110 111
    }
  end

112 113 114 115 116 117 118 119 120 121 122
  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

123 124 125 126 127 128 129 130 131 132 133 134
  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,
      sort_value_oldest_updated => sort_title_oldest_updated
    }
  end

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

139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
  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
    }
  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,
      sort_value_milestone => sort_value_milestone_later
    }.merge(issuable_sort_option_overrides)
  end

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

    sort_options_hash[sort_value]
  end

  def issuable_sort_direction_button(sort_value)
    link_class = 'btn btn-default has-tooltip reverse-sort-btn qa-reverse-sort'
    reverse_sort = issuable_reverse_sort_order_hash[sort_value]

    if reverse_sort
167
      reverse_url = page_filter_path(sort: reverse_sort, label: true)
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    else
      reverse_url = '#'
      link_class += ' disabled'
    end

    link_to(reverse_url, type: 'button', class: link_class, title: 'Sort direction') do
      icon_suffix =
        case sort_value
        when sort_value_milestone, sort_value_due_date, /_asc\z/
          'lowest'
        else
          'highest'
        end

      sprite_icon("sort-#{icon_suffix}", size: 16)
    end
  end

186 187 188
  # Titles.
  def sort_title_access_level_asc
    s_('SortOptions|Access level, ascending')
Thijs Wouters's avatar
Thijs Wouters committed
189 190
  end

191 192
  def sort_title_access_level_desc
    s_('SortOptions|Access level, descending')
193 194
  end

195 196
  def sort_title_created_date
    s_('SortOptions|Created date')
197 198
  end

199 200
  def sort_title_downvotes
    s_('SortOptions|Least popular')
201 202
  end

203 204
  def sort_title_due_date
    s_('SortOptions|Due date')
205 206
  end

207 208
  def sort_title_due_date_later
    s_('SortOptions|Due later')
209 210
  end

211 212
  def sort_title_due_date_soon
    s_('SortOptions|Due soon')
213
  end
214

215 216
  def sort_title_label_priority
    s_('SortOptions|Label priority')
217 218
  end

219 220
  def sort_title_largest_group
    s_('SortOptions|Largest group')
221 222
  end

223 224
  def sort_title_largest_repo
    s_('SortOptions|Largest repository')
225 226
  end

227 228
  def sort_title_last_joined
    s_('SortOptions|Last joined')
229 230
  end

231 232
  def sort_title_latest_activity
    s_('SortOptions|Last updated')
233 234
  end

235 236 237 238 239 240 241 242 243 244
  def sort_title_milestone
    s_('SortOptions|Milestone')
  end

  def sort_title_milestone_later
    s_('SortOptions|Milestone due later')
  end

  def sort_title_milestone_soon
    s_('SortOptions|Milestone due soon')
245 246
  end

247
  def sort_title_name
248
    s_('SortOptions|Name')
249 250
  end

251 252
  def sort_title_name_asc
    s_('SortOptions|Name, ascending')
253 254
  end

255 256
  def sort_title_name_desc
    s_('SortOptions|Name, descending')
257 258
  end

259 260
  def sort_title_oldest_activity
    s_('SortOptions|Oldest updated')
261 262
  end

263 264
  def sort_title_oldest_created
    s_('SortOptions|Oldest created')
265 266
  end

267 268
  def sort_title_oldest_joined
    s_('SortOptions|Oldest joined')
269 270
  end

271 272
  def sort_title_oldest_signin
    s_('SortOptions|Oldest sign in')
273 274
  end

275 276
  def sort_title_oldest_updated
    s_('SortOptions|Oldest updated')
277 278
  end

279 280
  def sort_title_popularity
    s_('SortOptions|Popularity')
281 282
  end

283 284
  def sort_title_priority
    s_('SortOptions|Priority')
285 286
  end

287 288
  def sort_title_recently_created
    s_('SortOptions|Last created')
289 290
  end

291 292
  def sort_title_recently_signin
    s_('SortOptions|Recent sign in')
293 294
  end

295 296
  def sort_title_recently_updated
    s_('SortOptions|Last updated')
297 298
  end

299 300
  def sort_title_start_date_later
    s_('SortOptions|Start later')
301 302
  end

303 304
  def sort_title_start_date_soon
    s_('SortOptions|Start soon')
305 306
  end

307 308 309 310
  def sort_title_upvotes
    s_('SortOptions|Most popular')
  end

311 312 313 314
  def sort_title_contacted_date
    s_('SortOptions|Last Contact')
  end

315 316 317 318
  def sort_title_most_stars
    s_('SortOptions|Most stars')
  end

319
  # Values.
320 321 322 323 324 325 326 327
  def sort_value_access_level_asc
    'access_level_asc'
  end

  def sort_value_access_level_desc
    'access_level_desc'
  end

328 329
  def sort_value_created_date
    'created_date'
330 331
  end

332 333 334 335 336 337 338 339 340 341 342 343 344 345
  def sort_value_downvotes
    'downvotes_desc'
  end

  def sort_value_due_date
    'due_date'
  end

  def sort_value_due_date_later
    'due_date_desc'
  end

  def sort_value_due_date_soon
    'due_date_asc'
Thijs Wouters's avatar
Thijs Wouters committed
346 347
  end

348 349 350 351
  def sort_value_label_priority
    'label_priority'
  end

352 353
  def sort_value_largest_group
    'storage_size_desc'
354 355
  end

356 357
  def sort_value_largest_repo
    'storage_size_desc'
358 359
  end

360 361
  def sort_value_last_joined
    'last_joined'
362 363 364 365 366 367
  end

  def sort_value_latest_activity
    'latest_activity_desc'
  end

368 369
  def sort_value_milestone
    'milestone'
370 371
  end

372 373
  def sort_value_milestone_later
    'milestone_due_desc'
374 375 376 377 378 379
  end

  def sort_value_milestone_soon
    'milestone_due_asc'
  end

380 381
  def sort_value_name
    'name_asc'
382 383
  end

384 385
  def sort_value_name_desc
    'name_desc'
386 387
  end

388 389
  def sort_value_oldest_activity
    'latest_activity_asc'
390 391
  end

392 393
  def sort_value_oldest_created
    'created_asc'
394 395
  end

396 397
  def sort_value_oldest_signin
    'oldest_sign_in'
398 399
  end

400 401
  def sort_value_oldest_joined
    'oldest_joined'
402 403
  end

404 405
  def sort_value_oldest_updated
    'updated_asc'
406 407
  end

408 409 410 411 412 413 414 415 416 417
  def sort_value_popularity
    'popularity'
  end

  def sort_value_priority
    'priority'
  end

  def sort_value_recently_created
    'created_desc'
418 419 420 421 422 423
  end

  def sort_value_recently_signin
    'recent_sign_in'
  end

424 425
  def sort_value_recently_updated
    'updated_desc'
426
  end
427

428 429 430 431 432 433
  def sort_value_start_date_later
    'start_date_desc'
  end

  def sort_value_start_date_soon
    'start_date_asc'
434 435 436 437 438
  end

  def sort_value_upvotes
    'upvotes_desc'
  end
439 440 441 442

  def sort_value_contacted_date
    'contacted_asc'
  end
443 444 445 446

  def sort_value_most_stars
    'stars_desc'
  end
447
end