competitions
cxt 5 years ago
parent cb23912b1f
commit 7498740e87

@ -1,6 +1,7 @@
class Competitions::CompetitionsController < Competitions::BaseController
skip_before_action :require_login
before_action :allow_visit, except: [:index]
before_action :require_admin, only: [:update]
def index
# 已上架 或者 即将上架
@ -25,10 +26,16 @@ class Competitions::CompetitionsController < Competitions::BaseController
end
def show
@competition = current_competition
end
def common_header
def update
@competition.update_attributes!(introduction: params[:introduction])
normal_status("更新成功")
end
def common_header
@competition = current_competition
end
private
@ -38,9 +45,6 @@ class Competitions::CompetitionsController < Competitions::BaseController
end
def allow_visit
unless current_competition.published? || admin_or_business?
render_forbidden
return
end
render_forbidden unless current_competition.published? || admin_or_business?
end
end

@ -0,0 +1,12 @@
json.extract! @competition, :id, :name, :sub_title, :identifier, :bonus, :mode
json.visits_count @competition.visits
member_count = @competition.team_members.count
json.member_count member_count.zero? ? 268 : member_count
json.start_time @competition.start_time&.strftime("%Y-%m-%d")
json.end_time @competition.end_time&.strftime("%Y-%m-%d")
json.enroll_end_time @competition.enroll_end_time&.strftime("%Y-%m-%d %H:%M:%S")
json.published @competition.published?
json.nearly_published @competition.published_at.present?

@ -1,7 +1,7 @@
json.count @count
json.competitions do
json.array! @competitions.each do |competition|
json.extract! competition, :id, :identifier, :name, :sub_title, :bonus, :description
json.extract! competition, :id, :identifier, :name, :sub_title, :bonus, :description, :mode
json.visits_count competition.visits
member_count = @member_count_map&.fetch(competition.id, 0) || competition.team_members.count
@ -12,18 +12,18 @@ json.competitions do
json.nearly_published competition.published_at.present?
json.single_stage (@stage_count_map&.fetch(competition.id, 0) || competition.competition_stages.count) == 1
json.start_time competition.display_start_time
json.end_time competition.display_end_time
json.enroll_end_time competition.display_enroll_end_time
json.start_time competition.start_time&.strftime("%Y-%m-%d")
json.end_time competition.end_time&.strftime("%Y-%m-%d")
json.enroll_end_time competition.enroll_end_time&.strftime("%Y-%m-%d %H:%M:%S")
section = competition.current_stage_section
if section
json.current_stage do
json.name section.competition_stage.name
json.start_time section.display_start_time
json.end_time section.display_end_time
end
end
# section = competition.current_stage_section
# if section
# json.current_stage do
#
# json.name section.competition_stage.name
# json.start_time section.display_start_time
# json.end_time section.display_end_time
# end
# end
end
end

@ -1,36 +1,2 @@
competition = current_competition
json.extract! competition, :id, :name, :sub_title, :identifier
json.start_time competition.display_start_time
json.end_time competition.display_end_time
json.enroll_end_time competition.display_enroll_end_time
json.images do
json.array! competition.attachments, partial: 'attachments/attachment_simple', as: :attachment
end
json.competition_stages do
stages = competition.competition_stages.includes(competition_stage_sections: :competition_entries)
json.array! stages.each do |stage|
json.extract! stage, :id, :name
json.sections do
json.array! stage.competition_stage_sections.each do |section|
json.extract! section, :id, :name
decorator_section = ActiveDecorator::Decorator.instance.decorate(section)
json.start_time decorator_section.display_start_time
json.end_time decorator_section.display_end_time
is_start = section.start_time > Time.now
json.entries do
json.array! section.competition_entries.each do |entry|
json.extract! entry, :id, :name
json.url is_start ? entry.url : ''
end
end
end
end
end
end
json.extract! @competition, :id, :introduction
json.image_url url_to_avatar(@competition)

@ -781,7 +781,7 @@ Rails.application.routes.draw do
resources :repertoires, only: [:index]
scope module: :competitions do
resources :competitions, only: [:index, :show] do
resources :competitions, only: [:index, :show, :update] do
resources :competition_modules, only: [:index, :show, :update]
resource :competition_staff
resources :competition_teams, only: [:index, :show] do

Loading…
Cancel
Save