|
|
|
@ -54,39 +54,29 @@ class ContestsController < ApplicationController
|
|
|
|
|
case params[:contest_sort_type]
|
|
|
|
|
when '0'
|
|
|
|
|
# modified by longjun
|
|
|
|
|
# never use unless and else
|
|
|
|
|
# never use unless and else, 将下面重复操作模块化,放在private下
|
|
|
|
|
# unless @offset == 0
|
|
|
|
|
if @offset != 0
|
|
|
|
|
@contests = @contests.reorder('contests.commit').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @contest_count % @limit
|
|
|
|
|
limit = @limit if limit == 0
|
|
|
|
|
@contests = @contests.reorder('contests.commit').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
# if @offset != 0
|
|
|
|
|
# @contests = @contests.reorder('contests.commit').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
# else
|
|
|
|
|
# limit = @contest_count % @limit
|
|
|
|
|
# limit = @limit if limit == 0
|
|
|
|
|
# @contests = @contests.reorder('contests.commit').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
|
|
|
|
|
@contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.commit')
|
|
|
|
|
# end
|
|
|
|
|
@s_state = 0
|
|
|
|
|
when '1'
|
|
|
|
|
# modified by longjun
|
|
|
|
|
# never use unless and else
|
|
|
|
|
# unless @offset == 0
|
|
|
|
|
if @offset != 0
|
|
|
|
|
@contests = @contests.reorder('contests.created_on').offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = @contest_count % @limit
|
|
|
|
|
limit = @limit if limit == 0
|
|
|
|
|
@contests = @contests.reorder('contests.created_on').offset(@offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@contests = index_page_sort(@offset, @limit, @contest_count, @contests, 'contests.created_on')
|
|
|
|
|
@s_state = 1
|
|
|
|
|
when '2'
|
|
|
|
|
# modified by longjun
|
|
|
|
|
# never use unless and else
|
|
|
|
|
# unless @offset == 0
|
|
|
|
|
if @offset != 0
|
|
|
|
|
@contests = @contests.offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
# 目前只有 0, 1 两个sort_type
|
|
|
|
|
# when '2'
|
|
|
|
|
else
|
|
|
|
|
limit = @contest_count % @limit
|
|
|
|
|
limit = @limit if limit == 0
|
|
|
|
|
@contests = @contests.offset(@offset).limit(@limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
# end longjun
|
|
|
|
|
|
|
|
|
|
@contests = index_page_sort(@offset, @limit, @contest_count, @contests, '')
|
|
|
|
|
@s_state = 0
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
@ -723,5 +713,20 @@ class ContestsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# added by longjun
|
|
|
|
|
# 将index页面中分页排序的方法抽离出来
|
|
|
|
|
def index_page_sort(offset, limit, contest_count, contests, contest_sort_by)
|
|
|
|
|
# modified by longjun
|
|
|
|
|
# never use unless and else
|
|
|
|
|
# unless @offset == 0
|
|
|
|
|
if offset != 0
|
|
|
|
|
contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse
|
|
|
|
|
else
|
|
|
|
|
limit = contest_count % limit
|
|
|
|
|
limit = limit if limit == 0
|
|
|
|
|
contests = contests.reorder(contest_sort_by).offset(offset).limit(limit).all.reverse
|
|
|
|
|
end
|
|
|
|
|
contests
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|