diff --git a/app/controllers/admins/competition_settings_controller.rb b/app/controllers/admins/competition_settings_controller.rb
new file mode 100644
index 000000000..390ad17e8
--- /dev/null
+++ b/app/controllers/admins/competition_settings_controller.rb
@@ -0,0 +1,20 @@
+class Admins::CompetitionSettingsController < Admins::BaseController
+ def show
+ @competition = current_competition
+ end
+
+ def update
+ Admins::SaveLaboratorySettingService.call(current_competition, form_params)
+ render_ok
+ end
+
+ private
+
+ def current_competition
+ @_current_competition ||= Competition.find(params[:competition_id])
+ end
+
+ def form_params
+ params.permit(:identifier, :name, :nav_logo, :login_logo, :tab_logo, :footer, navbar: %i[name link hidden])
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/admins/competitions_controller.rb b/app/controllers/admins/competitions_controller.rb
index 3d6bef819..3b9b63243 100644
--- a/app/controllers/admins/competitions_controller.rb
+++ b/app/controllers/admins/competitions_controller.rb
@@ -1,4 +1,6 @@
class Admins::CompetitionsController < Admins::BaseController
+ include CustomSortable
+ before_action :find_competition, except: [:index]
def index
params[:sort_by] = params[:sort_by].presence || 'created_on'
@@ -6,10 +8,39 @@ class Admins::CompetitionsController < Admins::BaseController
@competitions = custom_sort Competition.all, params[:sort_by], params[:sort_direction]
@params_page = params[:page] || 1
@competitions = paginate @competitions
+ ids = @competitions.map(&:id)
+ @member_count_map = TeamMember.where(competition_id: ids).group(:competition_id).count
respond_to do |format|
format.js
format.html
end
end
+
+ def publish
+ @competition.update_attributes!(:published_at, Time.now)
+ end
+
+ def unpublish
+ @competition.update_attributes!(:published_at, nil)
+ end
+
+ def online_switch
+ if @competition.status
+ @competition.update_attributes!(status: false)
+ else
+ @competition.update_attributes!(status: true, online_time: Time.now)
+ end
+ end
+
+ def enroll_list
+
+ end
+
+ private
+
+ def find_competition
+ @competition = Competition.find_by(id: params[:id])
+ end
+
end
\ No newline at end of file
diff --git a/app/models/competition.rb b/app/models/competition.rb
index 024478ad6..9055adefc 100644
--- a/app/models/competition.rb
+++ b/app/models/competition.rb
@@ -18,6 +18,29 @@ class Competition < ApplicationRecord
after_create :create_competition_modules
+ def mode_type
+ case mode
+ when 1
+ "课堂"
+ when 2
+ "实训"
+ when 3
+ "教学"
+ when 4
+ "托管"
+ else
+ "--"
+ end
+ end
+
+ def teacher_staff_num
+ teacher_staff ? "#{teacher_staff.minimum}~#{teacher_staff.maximum}" : "--"
+ end
+
+ def member_staff_num
+ member_staff ? "#{member_staff.minimum}~#{member_staff.maximum}" : "--"
+ end
+
# 是否上架
def published?
status?
diff --git a/app/views/admins/competition_settings/show.html.erb b/app/views/admins/competition_settings/show.html.erb
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/views/admins/competitions/enroll_list.html.erb b/app/views/admins/competitions/enroll_list.html.erb
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/views/admins/competitions/index.html.erb b/app/views/admins/competitions/index.html.erb
index 8fa238181..b97e26f94 100644
--- a/app/views/admins/competitions/index.html.erb
+++ b/app/views/admins/competitions/index.html.erb
@@ -3,5 +3,7 @@
<% end %>
- <%= render partial: 'admins/shixuns/shared/list', locals: { shixuns: @shixuns } %>
+ <%= render partial: 'admins/competitions/shared/list', locals: { competitions: @competitions } %>
+
+<%= render partial: 'admins/shared/modal/upload_file_modal', locals: { title: '上传图片' } %>
\ No newline at end of file
diff --git a/app/views/admins/competitions/online_switch.js.erb b/app/views/admins/competitions/online_switch.js.erb
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/views/admins/competitions/publish.js.erb b/app/views/admins/competitions/publish.js.erb
new file mode 100644
index 000000000..e69de29bb
diff --git a/app/views/admins/competitions/shared/_list.html.erb b/app/views/admins/competitions/shared/_list.html.erb
new file mode 100644
index 000000000..8f215d54c
--- /dev/null
+++ b/app/views/admins/competitions/shared/_list.html.erb
@@ -0,0 +1,30 @@
+
+
+ 序号 |
+ 竞赛主标题 |
+ 竞赛副标题 |
+ 模式 |
+ 报名人数 |
+ 指导老师 |
+ 参赛者 |
+ 主题图片796*397 |
+ 创建时间 |
+
+ 操作
+ |
+
+
+ <% if competitions.present? %>
+ <% competitions.each_with_index do |competition, index| %>
+
+ <% page_no = list_index_no(@params_page.to_i, index) %>
+ <%= render partial: "admins/competitions/shared/td",locals: {competition: competition, page_no: page_no} %>
+
+ <% end %>
+ <% else %>
+ <%= render 'admins/shared/no_data_for_table' %>
+ <% end %>
+
+
+
+<%= render partial: 'admins/shared/paginate', locals: { objects: competitions } %>
\ No newline at end of file
diff --git a/app/views/admins/competitions/shared/_td.html.erb b/app/views/admins/competitions/shared/_td.html.erb
new file mode 100644
index 000000000..d05974c86
--- /dev/null
+++ b/app/views/admins/competitions/shared/_td.html.erb
@@ -0,0 +1,27 @@
+<%= page_no %> |
+
+ <%= link_to competition.name, enroll_list_admins_competition_path(competition), :target => "_blank", :title => competition.name %>
+ |
+<%= competition.sub_title %> |
+<%= competition.mode_type %> |
+<%= @member_count_map&.fetch(competition.id, 0) || competition.team_members.count %> |
+<%= competition.teacher_staff_num %> |
+<%= competition.member_staff_num %> |
+
+ <% imageExists = File.exist?(disk_filename("Competition", competition.id)) %>
+ <% imageUrl = imageExists ? '/' + url_to_avatar(competition) + "?#{Time.now.to_i}" : '' %>
+ <%= image_tag(imageUrl, width: 60, height: 40, class: "preview-image competition-image-#{competition.id}", data: { toggle: 'tooltip', title: '点击预览' }, style: imageExists ? '' : 'display:none') %>
+ <%= javascript_void_link imageExists ? '重新上传' : '上传图片', class: 'action upload-competition-image-action', data: { source_id: competition.id, source_type: 'Competition', toggle: 'modal', target: '.admin-upload-file-modal' } %>
+ |
+<%= competition.created_at.strftime('%Y-%m-%d %H:%M') %> |
+
+ <%= link_to '配置', admins_competition_competition_setting_path(competition), class: 'action edit-action' %>
+
+ <% if !competition.status? && competition.published_at.blank? %>
+ <%= link_to '发布', publish_admins_competition_path(competition), class: 'action publish-action', method: :post, remote: true %>
+ <% else %>
+ <%= link_to '取消发布', unpublish_admins_competition_path(competition), class: 'action unpublish-action', method: :post, remote: true %>
+ <% end %>
+
+ <%= link_to competition.published? ? "下架" : "上架", online_switch_admins_competition_path(competition), class: 'action online-action', method: :post, remote: true %>
+ |
\ No newline at end of file
diff --git a/app/views/admins/competitions/unpublish.js.erb b/app/views/admins/competitions/unpublish.js.erb
new file mode 100644
index 000000000..e69de29bb
diff --git a/config/routes.rb b/config/routes.rb
index f6f8db066..605ae4194 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -981,7 +981,15 @@ Rails.application.routes.draw do
resource :laboratory_user, only: [:create, :destroy]
end
- resources :competitions, only: [:index, :destroy]
+ resources :competitions, only: [:index, :destroy] do
+ member do
+ post :publish
+ post :unpublish
+ post :online_switch
+ get :enroll_list
+ end
+ resource :competition_setting, only: [:show, :update]
+ end
end
resources :colleges, only: [] do