金课公告栏的调整

dev_hs
cxt 6 years ago
parent c71842f700
commit f4d19f9ec6

@ -26,14 +26,14 @@ class CoursesController < ApplicationController
:base_info, :get_historical_courses, :create_group_by_importing_file, :base_info, :get_historical_courses, :create_group_by_importing_file,
:attahcment_category_list,:export_member_scores_excel, :duplicate_course, :attahcment_category_list,:export_member_scores_excel, :duplicate_course,
:switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course, :switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course,
:informs, :update_informs, :online_learning, :update_task_position, :tasks_list, :join_excellent_course] :informs, :update_informs, :new_informs, :online_learning, :update_task_position, :tasks_list, :join_excellent_course]
before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course, before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course,
:search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list] :search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list]
before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate, before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate,
:transfer_to_course_group, :delete_from_course, :transfer_to_course_group, :delete_from_course,
:search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher] :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher]
before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin, before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin,
:set_course_group, :create_group_by_importing_file, :update_informs, :set_course_group, :create_group_by_importing_file, :update_informs, :new_informs,
:update_task_position, :tasks_list] :update_task_position, :tasks_list]
before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group, before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group,
:change_course_teacher, :export_member_scores_excel, :course_group_list, :change_course_teacher, :export_member_scores_excel, :course_group_list,
@ -42,6 +42,7 @@ class CoursesController < ApplicationController
before_action :find_board, only: :board_list before_action :find_board, only: :board_list
before_action :validate_page_size, only: :mine before_action :validate_page_size, only: :mine
before_action :course_tasks, only: [:tasks_list, :update_task_position] before_action :course_tasks, only: [:tasks_list, :update_task_position]
before_action :validate_inform_params, only: [:update_informs, :new_informs]
if RUBY_PLATFORM =~ /linux/ if RUBY_PLATFORM =~ /linux/
require 'simple_xlsx_reader' require 'simple_xlsx_reader'
@ -159,7 +160,7 @@ class CoursesController < ApplicationController
CourseMember.create!(course_id: @course.id, user_id: s_member.user_id, role: 2) CourseMember.create!(course_id: @course.id, user_id: s_member.user_id, role: 2)
end end
Inform.create(container: @course, description: @subject.learning_notes) Inform.create(container: @course, description: @subject.learning_notes, name: "学习须知")
end end
course_module_types = params[:course_module_types] course_module_types = params[:course_module_types]
@ -234,14 +235,20 @@ class CoursesController < ApplicationController
end end
def informs def informs
@informs = @course.informs
end end
def update_informs def new_informs
tip_exception("公告内容不能为空") if params[:description].blank? inform = Inform.new(container: @course)
inform = @course.inform || Inform.new(container: @course) inform.name = params[:name]
inform.description = params[:description] inform.description = params[:description]
inform.save! inform.save!
normal_status("创建成功")
end
def update_informs
inform = @course.informs.find_by(id: params[:inform_id])
inform.update_attributes!(name: params[:name], description: params[:description])
normal_status("更新成功") normal_status("更新成功")
end end
@ -1259,6 +1266,11 @@ class CoursesController < ApplicationController
end end
end end
def validate_inform_params
tip_exception("公告标题不能为空") if params[:name].blank?
tip_exception("公告内容不能为空") if params[:description].blank?
end
# def find_container # def find_container
# case params[:container_type] # case params[:container_type]
# when 'shixun_homework', 'common_homework', 'group_homework' # when 'shixun_homework', 'common_homework', 'group_homework'

@ -9,7 +9,7 @@ class Course < ApplicationRecord
# 所属实践课程 # 所属实践课程
belongs_to :subject, optional: true belongs_to :subject, optional: true
has_one :inform, as: :container, dependent: :destroy has_many :informs, as: :container, dependent: :destroy
has_many :course_infos, dependent: :destroy has_many :course_infos, dependent: :destroy
# 课堂左侧导航栏的模块 # 课堂左侧导航栏的模块

@ -1,3 +1,6 @@
class Inform < ApplicationRecord class Inform < ApplicationRecord
belongs_to :container, polymorphic: true, optional: true belongs_to :container, polymorphic: true, optional: true
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 5000 }
end end

@ -1 +1,5 @@
json.description @course.inform&.description json.informs @informs do |inform|
json.id inform.id
json.name inform.name
json.description inform.description
end

@ -349,6 +349,7 @@ Rails.application.routes.draw do
post 'exit_course' post 'exit_course'
get 'informs' get 'informs'
post 'update_informs' post 'update_informs'
post 'new_informs'
get 'online_learning' get 'online_learning'
post 'join_excellent_course' post 'join_excellent_course'
get 'tasks_list' get 'tasks_list'

Loading…
Cancel
Save