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 @@
-
-
- - -
-
- - - - - - - - - - <% @shixus.each do |shixun| %> + <%= labelled_form_for @homework, :url =>{:controller=> 'homework_common', :action => 'shixuns', :course => @course.id}, :method => "post", :remote => true do |f| %> +
+
+ + +
+
+ <% end %> + <%= labelled_form_for @homework, :url =>{:controller=> 'homework_common', :action => 'create', :course => @course.id}, :method => "post" do |f| %> +
实训名称导师姓名学员数
+ - - - + + + - <% end %> - -
- - <%= link_to shixun.name, shixun_path(shixun), :class => "edu-info-dark task-hide fl" %> - <%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "edu-txt-w140 task-hide" %><%= shixun.myshixuns.count %>实训名称导师姓名学员数
+ + 请至少选中一个实训 + + <% @shixuns.each do |shixun| %> + + + + <%= link_to shixun.name, shixun_path(shixun), :class => "edu-info-dark task-hide fl" %> + + <%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "edu-txt-w140 task-hide" %> + <%= shixun.myshixuns.count %> + + <% end %> + + + <% end %>
    - <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %> + <%= pagination_links_full @shixun_pages, @shixuns_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %>
diff --git a/config/routes.rb b/config/routes.rb index 7ef185ba7..4e0cc91b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -409,7 +409,7 @@ RedmineApp::Application.routes.draw do end collection do - get 'shixuns' + match 'shixuns' post 'next_step' post 'programing_test' end diff --git a/db/migrate/20170522130310_create_homework_commons_shixuns.rb b/db/migrate/20170522130310_create_homework_commons_shixuns.rb new file mode 100644 index 000000000..444cffe7d --- /dev/null +++ b/db/migrate/20170522130310_create_homework_commons_shixuns.rb @@ -0,0 +1,10 @@ +class CreateHomeworkCommonsShixuns < ActiveRecord::Migration + def change + create_table :homework_commons_shixuns do |t| + t.integer :shixun_id + t.integer :homework_common_id + + t.timestamps + end + end +end diff --git a/public/javascripts/edu/homework.js b/public/javascripts/edu/homework.js index 524603d21..01570db2e 100644 --- a/public/javascripts/edu/homework.js +++ b/public/javascripts/edu/homework.js @@ -63,3 +63,14 @@ function new_homework_type(id){ } } } + +function new_shixun_homework(id){ + + if($("input[name='shixun_homework']:checked").length == 0){ + $("#homework_type_notice").show(); + } else{ + var type=$("input[name='shixun_homework']:checked").val(); + console.log(type); + $("#new_homework_common").submit(); + } +}