forked from Trustie/forgeplus
竞赛配置增加属性,通知管理
This commit is contained in:
parent
f0bc08cd47
commit
a72a0de2b9
|
|
@ -330,9 +330,9 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
# if !User.current.logged? && Rails.env.development?
|
||||
# User.current = User.find 1
|
||||
# end
|
||||
if !User.current.logged? && Rails.env.development?
|
||||
User.current = User.find 4
|
||||
end
|
||||
|
||||
|
||||
# 测试版前端需求
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
class CompetitionInfosController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_action :find_competition, only: [:show, :enroll, :upload, :enroll_status, :statistics]
|
||||
# before_action :require_admin, only: [:index, :new, :edit, :create, :update]
|
||||
before_action :manager_competition, only: [:enroll_list]
|
||||
before_action :find_competition, only: [:show, :enroll, :upload, :enroll_status, :statistics, :enroll_list]
|
||||
before_action :require_admin, only: [:index, :new, :edit, :create, :update]
|
||||
|
||||
def index
|
||||
@competition_infos = CompetitionInfo.all
|
||||
|
|
@ -48,7 +47,8 @@ class CompetitionInfosController < ApplicationController
|
|||
end
|
||||
|
||||
def enroll_list
|
||||
competition_users = CompetitionUser.all.order("updated_at desc")
|
||||
competition_users = CompetitionUser.where(competition_info: @competition_info.id).order("updated_at desc")
|
||||
competition_users = competition_users.where(zone: manager_competition_zones)
|
||||
if params[:zone].present?
|
||||
competition_users = competition_users.where(zone: params[:zone].to_s)
|
||||
end
|
||||
|
|
@ -133,7 +133,7 @@ class CompetitionInfosController < ApplicationController
|
|||
|
||||
def competition_info_params
|
||||
params.require(:competition_info).permit(:title, :zones, :zones_local, :sub_competitions, :identifier, :content,
|
||||
:video_url, :is_local, :upload_date, :enroll_date)
|
||||
:video_url, :is_local, :manager_ids, :upload_date, :enroll_date, :guide, :about_us)
|
||||
end
|
||||
|
||||
def find_competition
|
||||
|
|
@ -144,9 +144,11 @@ class CompetitionInfosController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def manager_competition
|
||||
def manager_competition_zones
|
||||
if current_user.admin?
|
||||
|
||||
@competition_info.competition_zones
|
||||
else
|
||||
@competition_info.manager_zones(current_user.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
class CompetitionNoticesController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_action :find_competition, only: [:show, :index, :update, :destroy, :create]
|
||||
# before_action :require_admin, only: [:show, :index, :update, :destroy, :create]
|
||||
before_action :manager_competition_zones, only: [:enroll_list]
|
||||
|
||||
def index
|
||||
competition_notices = CompetitionNotice.where(competition_info_id: @competition_info.id).order("created_at desc")
|
||||
@competition_notices_count = competition_notices.size
|
||||
@competition_notices = paginate(competition_notices)
|
||||
end
|
||||
|
||||
def create
|
||||
@competition_notice = CompetitionNotice.new(competition_notice_params)
|
||||
@competition_notice.user = current_user
|
||||
@competition_notice.competition_info = @competition_info
|
||||
@competition_notice.save
|
||||
if params[:attachment_ids].present?
|
||||
params[:attachment_ids].each do |id|
|
||||
attachment = Attachment.find_by_id(id)
|
||||
unless attachment.blank?
|
||||
attachment.container = @competition_notice
|
||||
attachment.author_id = current_user.id
|
||||
attachment.description = ""
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
# PATCH/PUT /competition_infos/1.json
|
||||
def update
|
||||
@competition_notice = CompetitionNotice.find params[:id]
|
||||
@competition_notice.update(competition_notice_params)
|
||||
@competition_notice.attachments.update_all(container_id: nil, container_type: nil)
|
||||
if params[:attachment_ids].present?
|
||||
params[:attachment_ids].each do |id|
|
||||
attachment = Attachment.find_by_id(id)
|
||||
unless attachment.blank?
|
||||
attachment.container = @competition_notice
|
||||
attachment.author_id = current_user.id
|
||||
attachment.description = ""
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def show
|
||||
@competition_notice = CompetitionNotice.find params[:id]
|
||||
end
|
||||
|
||||
def upload
|
||||
competition_user = CompetitionUser.find_by(competition_info: @competition_notice.id, user_id: current_user.id)
|
||||
tip_exception "未报名,请先报名" if competition_user.blank?
|
||||
tip_exception "附件参数attachment_ids不能为空" if params[:attachment_ids].blank?
|
||||
# tip_exception "您已经提交作品!" if competition_user.present? && competition_user.attachments.present?
|
||||
competition_user.attachments.update_all(container_id: nil, container_type: nil)
|
||||
|
||||
render_ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
@competition_notice = CompetitionNotice.find params[:id]
|
||||
@competition_notice.destroy
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def competition_notice_params
|
||||
params.permit(:title, :content)
|
||||
end
|
||||
|
||||
def find_competition
|
||||
if CompetitionInfo.where(:identifier => params[:competition_info_id]).exists?
|
||||
@competition_info = CompetitionInfo.where(:identifier => params[:competition_info_id]).first
|
||||
else
|
||||
@competition_info = CompetitionInfo.find(params[:competition_info_id])
|
||||
end
|
||||
end
|
||||
|
||||
def manager_competition_zones
|
||||
if current_user.admin?
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -33,5 +33,16 @@ class CompetitionInfo < ApplicationRecord
|
|||
self.sub_competitions.to_s.split(",")
|
||||
end
|
||||
|
||||
# 管理员配置方式:id:赛区名称,id:赛区名称
|
||||
def manager_zones(user_id)
|
||||
return [] if self.manager_ids.blank?
|
||||
zones = []
|
||||
managers = manager_ids.split(",")
|
||||
managers.each do |u|
|
||||
zones.push(u.split(":")[1]) if u.split(":")[0].to_s == user_id.to_s
|
||||
end
|
||||
zones
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: competition_notices
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# competition_info_id :integer
|
||||
# user_id :integer
|
||||
# title :string(255)
|
||||
# content :text(4294967295)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_competition_notices_on_competition_info_id (competition_info_id)
|
||||
# index_competition_notices_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class CompetitionNotice < ApplicationRecord
|
||||
belongs_to :competition_info
|
||||
belongs_to :user
|
||||
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
|
||||
end
|
||||
|
|
@ -59,6 +59,20 @@
|
|||
<%= form.text_field :upload_date , :style=>'width:200px;' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :guide, "赛事指南" %>
|
||||
<%= form.text_field :guide, :style=>'width:1200px;' %>
|
||||
</div>
|
||||
<div class="field">
|
||||
<%= form.label :about_us, "关于我们" %>
|
||||
<%= form.text_field :about_us, :style=>'width:1200px;' %>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<%= form.label :manager_ids, "管理员配置(配置方式:用户id:赛区名称,用户id:赛区名称)" %>
|
||||
<%= form.text_field :manager_ids, :style=>'width:1200px;' %>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit("保存赛事")%>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<!--<p id="notice"><%#= notice %></p>-->
|
||||
|
||||
<h1>EduCoder公共配置</h1>
|
||||
<p>说明:该界面适用于存储全局变量</p>
|
||||
<h1>竞赛配置</h1>
|
||||
<p>说明:该界面适用于竞赛参数配置</p>
|
||||
|
||||
<table border="1">
|
||||
<thead>
|
||||
|
|
@ -9,7 +9,8 @@
|
|||
<th>ID</th>
|
||||
<th>唯一标识</th>
|
||||
<th>赛事标题</th>
|
||||
<th>赛事说明</th>
|
||||
<th>报名截止时间</th>
|
||||
<th>提案截止时间</th>
|
||||
<th>赛区配置</th>
|
||||
<th>赛项配置</th>
|
||||
<th>是否内网环境</th>
|
||||
|
|
@ -23,7 +24,8 @@
|
|||
<td><%= info.id %></td>
|
||||
<td><%= info.identifier %></td>
|
||||
<td><%= info.title %></td>
|
||||
<td><%= info.content %></td>
|
||||
<td><%= info.enroll_date&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td><%= info.upload_date&.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td><%= info.is_local? ? info.zones_local : info.zones %></td>
|
||||
<td><%= info.sub_competitions %></td>
|
||||
<td><%= info.is_local? %></td>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
json.status 0
|
||||
json.message "success"
|
||||
json.data do
|
||||
json.extract! @competition_info, :id, :identifier, :title, :content, :video_url, :is_local, :enroll_date, :upload_date
|
||||
json.extract! @competition_info, :id, :identifier, :title, :content, :video_url, :is_local, :enroll_date, :upload_date, :guide, :about_us
|
||||
json.zones @competition_info.competition_zones
|
||||
json.sub_competitions @competition_info.sub_competitions.to_s.split(",")
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
json.status 0
|
||||
json.message "success"
|
||||
json.count @competition_notices_count
|
||||
json.data do
|
||||
json.array! @competition_notices.to_a do | notice |
|
||||
json.extract! notice, :title, :content, :created_at, :updated_at
|
||||
json.user_id notice.user_id
|
||||
json.user_real_name notice.user&.real_name
|
||||
json.attachments notice.attachments do |attachment|
|
||||
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
json.status 0
|
||||
json.message "success"
|
||||
json.data do
|
||||
json.extract! @competition_notice, :title, :content, :created_at, :updated_at
|
||||
json.user_id @competition_notice.user_id
|
||||
json.user_real_name @competition_notice.user&.real_name
|
||||
json.attachments @competition_notice.attachments do |attachment|
|
||||
json.partial! "attachments/attachment_simple", locals: {attachment: attachment}
|
||||
end
|
||||
end
|
||||
|
|
@ -335,6 +335,7 @@ Rails.application.routes.draw do
|
|||
post :enroll
|
||||
post :upload
|
||||
end
|
||||
resources :competition_notices, only: [:show, :index, :update, :destroy, :create]
|
||||
end
|
||||
|
||||
namespace :weapps do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
class CreateCompetitionNotices < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :competition_notices do |t|
|
||||
t.references :competition_info
|
||||
t.references :user
|
||||
t.string :title
|
||||
t.longtext :content
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_column :competition_infos, :guide, :text
|
||||
add_column :competition_infos, :about_us, :text
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue