diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb
index 7da2e11a9..466616949 100644
--- a/app/controllers/homework_common_controller.rb
+++ b/app/controllers/homework_common_controller.rb
@@ -75,13 +75,16 @@ class HomeworkCommonController < ApplicationController
# 新建实训作业
def shixuns
- @shixus = Shixun.where(:authentication => 1)
- @shixus_count = shixuns.count
- @limit = 2
+ search = params[:search]
+ @course = Course.find(params[:course])
+ @homework = HomeworkCommon.new
+ @shixuns = Shixun.where(:authentication => 1).where("name like ?", "%#{search}%")
+ @shixuns_count = @shixuns.count
+ @limit = 10
@is_remote = true
- @shixun_pages = Paginator.new @shixus_count, @limit, params['page'] || 1
+ @shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1
@offset ||= @shixun_pages.offset
- @shixus = paginateHelper @shixus, @limit
+ @shixuns = paginateHelper @shixuns, @limit
respond_to do |format|
format.js
end
@@ -89,20 +92,26 @@ class HomeworkCommonController < ApplicationController
#新建作业,在个人作业列表创建作业
def create
- if params[:homework_common]
+ if params[:homework_common] || params[:shixun_homework]
homework = HomeworkCommon.new
- homework.name = params[:homework_common][:name]
- homework.description = params[:homework_common][:description]
+ if params[:shixun_homework]
+ shixun = Shixun.find(params[:shixun_homework])
+ homework.name = shixun.name
+ homework.description = shixun.description
+ else
+ homework.name = params[:homework_common][:name]
+ homework.description = params[:homework_common][:description]
+ homework.reference_answer = params[:homework_common][:reference_answer]
+ homework.save_attachments(params[:attachments])
+ render_attachment_warning_if_needed(homework)
+ end
homework.anonymous_comment = 1
- homework.homework_type = params[:homework_type].to_i || 1
+ homework.homework_type = params[:shixun_homework] ? 4 : (params[:homework_type].to_i || 1)
homework.late_penalty = 0
homework.teacher_priority = 1
homework.user_id = User.current.id
homework.course_id = params[:course]
- homework.reference_answer = params[:homework_common][:reference_answer]
- homework.save_attachments(params[:attachments])
- render_attachment_warning_if_needed(homework)
homework_detail_manual = HomeworkDetailManual.new
homework_detail_manual.te_proportion = 1.0
@@ -155,7 +164,7 @@ class HomeworkCommonController < ApplicationController
homework_detail_programing.save if homework_detail_programing
homework_detail_group.save if homework_detail_group
- if homework.homework_type != 3 && homework_detail_manual.comment_status == 1
+ if homework.homework_type != 4 && homework_detail_manual.comment_status == 1
create_works_list homework
end
diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb
index 440eff661..3df296aac 100644
--- a/app/models/homework_common.rb
+++ b/app/models/homework_common.rb
@@ -24,6 +24,7 @@ class HomeworkCommon < ActiveRecord::Base
has_many :praise_tread, as: :praise_tread_object, dependent: :destroy
has_one :praise_tread_cache, as: :object, dependent: :destroy
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
+ has_and_belongs_to_many :shixuns
# 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy
# 课程消息
diff --git a/app/models/homework_commons_shixuns.rb b/app/models/homework_commons_shixuns.rb
new file mode 100644
index 000000000..8400ca31d
--- /dev/null
+++ b/app/models/homework_commons_shixuns.rb
@@ -0,0 +1,3 @@
+class HomeworkCommonsShixuns < ActiveRecord::Base
+ attr_accessible :homework_common_id, :shixun_id
+end
diff --git a/app/models/shixun.rb b/app/models/shixun.rb
index 2a2cc1b3f..41a7b1db7 100644
--- a/app/models/shixun.rb
+++ b/app/models/shixun.rb
@@ -7,6 +7,7 @@ class Shixun < ActiveRecord::Base
has_one :repository
has_many :challenges, :dependent => :destroy, :order => "challenges.id ASC"
has_many :myshixuns
+ has_and_belongs_to_many :homework_commons
# id 转换成 identifier
def to_param
diff --git a/app/views/homework_common/_shixuns.html.erb b/app/views/homework_common/_shixuns.html.erb
index 327c63baf..6f36d6478 100644
--- a/app/views/homework_common/_shixuns.html.erb
+++ b/app/views/homework_common/_shixuns.html.erb
@@ -4,41 +4,46 @@