From f62f35a7062ac4a09bcdadb9ade160bedd667287 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 15 Jul 2019 16:26:24 +0800 Subject: [PATCH] competition list add category filter --- app/controllers/competitions_controller.rb | 2 +- .../competitions/_competition_list.html.erb | 100 +++++++++++++++ app/views/competitions/index.html.erb | 114 ++---------------- app/views/competitions/index.js.erb | 1 + 4 files changed, 113 insertions(+), 104 deletions(-) create mode 100644 app/views/competitions/_competition_list.html.erb create mode 100644 app/views/competitions/index.js.erb diff --git a/app/controllers/competitions_controller.rb b/app/controllers/competitions_controller.rb index c0862dc2..86ea9e08 100644 --- a/app/controllers/competitions_controller.rb +++ b/app/controllers/competitions_controller.rb @@ -30,7 +30,7 @@ class CompetitionsController < ApplicationController case params[:category] when 'progressing' then competitions = competitions.where('end_time > NOW()') - when 'end' then + when 'ended' then competitions = competitions.where('end_time < NOW()') end @competitions = competitions.reorder("published_at desc, online_time desc") diff --git a/app/views/competitions/_competition_list.html.erb b/app/views/competitions/_competition_list.html.erb new file mode 100644 index 00000000..13e8d3c8 --- /dev/null +++ b/app/views/competitions/_competition_list.html.erb @@ -0,0 +1,100 @@ +<% if @competitions.count > 0 %> +
+ <% @competitions.each do |competition| %> + <% if competition.status? %> +
+
+ <% if competition.enroll_end_time.present? && competition.enroll_end_time > Time.now %> +
报名中
+ <% end %> + + <%= image_tag(url_to_avatar(competition), :width => "100%", :height => "100%") %> + +
+ <%= [competition.name, competition.sub_title.presence].compact.join('——') %> + <% if competition.start_time > Time.now %> + <% unless competition.enroll_end_time.present? && competition.enroll_end_time < Time.now %> +
+ + 报名中 +
+ <% else %> +
+ + 即将开始 +
+ <% end %> + <% elsif competition.end_time < Time.now %> +
+ + 已结束 +
+ <% else %> + <% max_min_stage = max_min_stage_time competition %> + <% if max_min_stage.count == 1 %> +
+ + 距离结束还剩<%= how_much_day competition.end_time %> +
+ <% else %> + <% max_min_stage.each do |stage| %> + <% if stage.min_start_time > Time.now %> +
+ + <%= stage.competition_stage.name %>即将开始 +
+ <% break %> + <% elsif stage.max_end_time > Time.now %> +
+ + <%= stage.competition_stage.name %>正在进行 +
+ <% break %> + <% end %> + <% end %> + <% end %> + <% end %> +
+

+ <%= format_date competition.start_time %> ~ <%= com_end_date competition.end_time %> + + <%= competition.visits %> + <% if competition.member_count > 0 %> + + + <%= competition.identifier == "hn" ? 1125 : competition.member_count %> + + + <% end %> + +

+
+
+ <% elsif competition.published_at.present? %> + <% url = admin_or_business? ? competition_path(competition) : 'javascript:void(0)' %> + + <% end %> + <% end %> +
+<% else %> + <%= render :partial => "welcome/no_data" %> +<% end %> \ No newline at end of file diff --git a/app/views/competitions/index.html.erb b/app/views/competitions/index.html.erb index 06f0bef6..36743613 100644 --- a/app/views/competitions/index.html.erb +++ b/app/views/competitions/index.html.erb @@ -1,111 +1,19 @@
- 全部 - 进行中 - 往期比赛 + <%= link_to '全部', competitions_path(category: ''), remote: true, + class: "fl mr20 font-16 bestChoose shixun_repertoire #{params[:category].blank? ? 'active' : ''}" %> + <%= link_to '进行中', competitions_path(category: 'progressing'), remote: true, + class: "fl mr20 font-16 bestChoose shixun_repertoire #{params[:category] == 'progressing' ? 'active' : ''}" %> + <%= link_to '往期比赛', competitions_path(category: 'ended'), remote: true, + class: "fl mr20 font-16 bestChoose shixun_repertoire #{params[:category] == 'ended' ? 'active' : ''}" %>
- <% if @competitions.count > 0 %> -
- <% @competitions.each do |competition| %> - <% if competition.status? %> -
-
- <% if competition.enroll_end_time.present? && competition.enroll_end_time > Time.now %> -
报名中
- <% end %> - - <%= image_tag(url_to_avatar(competition), :width => "100%", :height => "100%") %> - -
- <%= [competition.name, competition.sub_title.presence].compact.join('——') %> - <% if competition.start_time > Time.now %> - <% unless competition.enroll_end_time.present? && competition.enroll_end_time < Time.now %> -
- - 报名中 -
- <% else %> -
- - 即将开始 -
- <% end %> - <% elsif competition.end_time < Time.now %> -
- - 已结束 -
- <% else %> - <% max_min_stage = max_min_stage_time competition %> - <% if max_min_stage.count == 1 %> -
- - 距离结束还剩<%= how_much_day competition.end_time %> -
- <% else %> - <% max_min_stage.each do |stage| %> - <% if stage.min_start_time > Time.now %> -
- - <%= stage.competition_stage.name %>即将开始 -
- <% break %> - <% elsif stage.max_end_time > Time.now %> -
- - <%= stage.competition_stage.name %>正在进行 -
- <% break %> - <% end %> - <% end %> - <% end %> - <% end %> -
-

- <%= format_date competition.start_time %> ~ <%= com_end_date competition.end_time %> - - <%= competition.visits %> - <% if competition.member_count > 0 %> - - - <%= competition.identifier == "hn" ? 1125 : competition.member_count %> - - - <% end %> - -

-
-
- <% elsif competition.published_at.present? %> - <% url = admin_or_business? ? competition_path(competition) : 'javascript:void(0)' %> - - <% end %> - <% end %> -
- <% else %> - <%= render :partial => "welcome/no_data" %> - <% end %> +
+ <%= render 'competitions/competition_list' %> +
+ +