diff --git a/Gemfile b/Gemfile index 57e9d17f7..8033bf210 100644 --- a/Gemfile +++ b/Gemfile @@ -75,7 +75,7 @@ group :development, :test do gem 'pry-byebug' gem "test-unit", "~>3.0" end - # gem 'rspec-rails', '~> 3.0' + gem 'rspec-rails', '~> 3.0' gem 'factory_girl_rails' end diff --git a/app/assets/javascripts/homework_bank.js.coffee b/app/assets/javascripts/homework_bank.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/homework_bank.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/homework_bank.css.scss b/app/assets/stylesheets/homework_bank.css.scss new file mode 100644 index 000000000..d8be9e5ef --- /dev/null +++ b/app/assets/stylesheets/homework_bank.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the HomeworkBank controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/homework_bank_controller.rb b/app/controllers/homework_bank_controller.rb new file mode 100644 index 000000000..208def604 --- /dev/null +++ b/app/controllers/homework_bank_controller.rb @@ -0,0 +1,233 @@ +class HomeworkBankController < ApplicationController + before_filter :require_login, :only => [:index, :show, :new, :create, :edit, :update, :destroy, :destroy_all, :choose_user_course, :send_h_bank_to_course] + before_filter :find_homework_bank, :only => [:show, :edit, :update, :destroy] + + def index + @order,@b_sort = params[:order] || "updated_at",params[:sort] || "desc" + @user = User.current + @r_sort = @b_sort == "desc" ? "asc" : "desc" + @search = params[:search] + if(params[:type].blank? || params[:type] == "1") #我的题库 + @homeworks = @user.homework_banks.where("name like ?", "%#{@search}%") + elsif params[:type] == "2" #公共题库 + @homeworks = HomeworkBank.where(:is_public => true).where("name like ?", "%#{@search}%") + end + if params[:property] + @property = params[:property].to_i + @homeworks = @homeworks.where(:homework_type => params[:property].to_i) + end + @homeworks = @homeworks.reorder("#{@order} #{@b_sort}") + @type = params[:type] ? params[:type] : '1' + @limit = 15 + @is_remote = true + @hw_count = @homeworks.count + @hw_pages = Paginator.new @hw_count, @limit, params['page'] || 1 + @offset ||= @hw_pages.offset + @homeworks = paginateHelper @homeworks,15 + respond_to do |format| + format.js + format.html {render :layout => 'base_edu'} + end + end + + def show + @is_admin = User.current == @homework.user || User.current.admin? + respond_to do |format| + format.html {render :layout => 'base_edu'} + end + end + + def new + @homework_type = params[:homework_type].to_i + @homework = HomeworkBank.new + respond_to do |format| + format.html{render :layout => 'base_edu'} + end + end + + # 新建实训作业 + def shixuns + search = params[:search] + @homework = HomeworkBank.new + @shixuns = Shixun.where(:authentication => 1).where("name like ?", "%#{search}%") + @shixuns_count = @shixuns.count + @limit = 10 + @is_remote = true + @shixun_pages = Paginator.new @shixuns_count, @limit, params['page'] || 1 + @offset ||= @shixun_pages.offset + @shixuns = paginateHelper @shixuns, @limit + respond_to do |format| + format.js + end + end + + def create + if params[:homework_bank] || params[:shixun_homework] + homework = HomeworkBank.new + if params[:shixun_homework] + shixun = Shixun.find(params[:shixun_homework]) + homework.name = shixun.name + homework.description = shixun.description + else + homework.name = params[:homework_bank][:name] + homework.description = params[:homework_bank][:description] + homework.reference_answer = params[:homework_bank][:reference_answer] + homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(homework) + end + homework.is_public = 0 + homework.quotes = 0 + homework.homework_type = params[:shixun_homework] ? 4 : (params[:homework_type].to_i || 1) + homework.user_id = User.current.id + homework.syllabus_id = params[:syllabus_id] if params[:syllabus_id] && params[:syllabus_id] != '0' + + #编程作业相关属性 + if homework.homework_type == 2 + homework.language = params[:language_type].to_i + + sample_inputs = params[:sample][:input] + if Array === sample_inputs + sample_inputs.each_with_index do |val, i| + homework.homework_bank_samples << HomeworkBankSample.new( + input: val, + output: params[:sample][:output][i] + ) + end + end + + inputs = params[:program][:input] + if Array === inputs + inputs.each_with_index do |val, i| + homework.homework_bank_tests << HomeworkBankTest.new( + input: val, + output: params[:program][:output][i] + ) + end + end + end + + #分组作业 + if homework.homework_type == 3 + homework.min_num = params[:min_num].to_i + homework.max_num = params[:max_num].to_i + end + + if homework.save + if homework.homework_type == 4 + HomeworkBankShixun.create(:homework_bank_id => homework.id, :shixun_id => shixun.id) + end + redirect_to homework_bank_path(homework) + end + end + end + + def edit + @homework_type = @homework.homework_type + respond_to do |format| + format.html{render :layout => 'base_edu'} + end + end + + def update + if params[:homework_bank] + @homework.name = params[:homework_bank][:name] + @homework.description = params[:homework_bank][:description] + @homework.reference_answer = params[:homework_bank][:reference_answer] + @homework.syllabus_id = params[:syllabus_id] ? (params[:syllabus_id] == '0' ? nil : params[:syllabus_id].to_i) : nil + @homework.save_attachments(params[:attachments]) + render_attachment_warning_if_needed(@homework) + + #编程作业相关属性 + if @homework.homework_type == 2 + @homework.language = params[:language_type].to_i if params[:language_type] + + @homework.homework_bank_samples.delete_all if params[:sample] + sample_inputs = params[:sample][:input] if params[:sample] + if Array === sample_inputs + sample_inputs.each_with_index do |val, i| + @homework.homework_bank_samples << HomeworkBankSample.new( + input: val, + output: params[:sample][:output][i] + ) + end + end + + @homework.homework_bank_tests.delete_all if params[:program] + inputs = params[:program][:input] if params[:program] + if Array === inputs + inputs.each_with_index do |val, i| + @homework.homework_bank_tests << HomeworkBankTest.new( + input: val, + output: params[:program][:output][i] + ) + end + end + end + + #分组作业 + if @homework.homework_type == 3 + @homework.min_num = params[:min_num].to_i if params[:min_num] + @homework.max_num = params[:max_num].to_i if params[:max_num] + end + + if @homework.save + redirect_to homework_bank_path(@homework) + end + end + end + + def destroy + @homework.homework_commons.update_all(:homework_bank_id => nil) + @homework.destroy + redirect_to homework_bank_index_path() + end + + def destroy_all + if params[:check_homework_bank] && !params[:check_homework_bank].blank? + params[:check_homework_bank].each do |hb_id| + homework = HomeworkBank.find hb_id + if homework && homework.user == User.current + HomeworkCommon.where(:homework_bank_id => homework.id).update_all(:homework_bank_id => nil) + homework.destroy + end + end + end + redirect_to homework_bank_index_path + end + + def choose_user_course + if !params[:search].nil? + search = "%#{params[:search].to_s.strip.downcase}%" + @courses = User.current.courses.where("is_delete = 0 and is_end = 0 and (#{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like :p)",:p=>search).select{ |course| User.current.has_teacher_role(course)} + else + @courses = User.current.courses.where("is_delete = 0 and is_end = 0").select{ |course| User.current.has_teacher_role(course)} + end + @homework_ids = params[:check_homework_bank] if params[:check_homework_bank] + @search = params[:search] + respond_to do |format| + format.js + end + end + + def send_h_bank_to_course + course = Course.find params[:course_id] + if course + params[:homework_id].each do |homework_id| + homework = HomeworkBank.find homework_id + quote_homework_bank homework, course + end + end + end + + def set_public + @homework.update_attributes(:is_public => true) + redirect_to homework_bank_index_path() + end + + private + def find_homework_bank + @homework = HomeworkBank.find params[:id] + rescue ActiveRecord::RecordNotFound + render_404 + end +end diff --git a/app/controllers/homework_common_controller.rb b/app/controllers/homework_common_controller.rb index 52e80f0d1..9c0b2bebe 100644 --- a/app/controllers/homework_common_controller.rb +++ b/app/controllers/homework_common_controller.rb @@ -178,6 +178,8 @@ class HomeworkCommonController < ApplicationController if homework.homework_type != 4 && homework_detail_manual.comment_status == 1 create_works_list homework + elsif homework.homework_type == 4 + HomeworkCommonsShixuns.create(:homework_common_id => homework.id, :shixun_id => shixun.id) end if params[:quotes] && !params[:quotes].blank? @@ -380,7 +382,7 @@ class HomeworkCommonController < ApplicationController def update if params[:homework_common] - is_update = @homework.name != params[:homework_common][:name] || @homework.description != params[:homework_common][:description] + is_update = @homework.name != params[:homework_common][:name] || @homework.description != params[:homework_common][:description] || @homework.reference_answer != params[:homework_common][:reference_answer] if params[:homework_type].to_i == 2 is_update = is_update || params[:language_type] != @homework.homework_detail_programing.language if !is_update && params[:sample] && params[:program] @@ -502,24 +504,25 @@ class HomeworkCommonController < ApplicationController end homework_bank = add_to_homework_bank_f @homework homework_bank.save + if @homework.homework_type == 4 + HomeworkBankShixun.create(:homework_bank_id => homework_bank.id, :shixun_id => @homework.homework_commons_shixuns.shixun_id) + end @homework.update_attributes(:homework_bank_id => homework_bank.id) elsif params[:type].to_i == 2 homework_bank = HomeworkBank.where(:id => @homework.homework_bank_id).first if homework_bank - homework_bank.update_attributes(:name => @homework.name, :description => @homework.description, :homework_type => @homework.homework_type) + homework_bank.update_attributes(:name => @homework.name, :description => @homework.description, :homework_type => @homework.homework_type, :reference_answer => @homework.reference_answer) if @homework.homework_type == 2 && @homework.homework_detail_programing homework_bank.update_attributes(:language => @homework.homework_detail_programing.language) homework_bank.homework_bank_tests.destroy_all @homework.homework_tests.each_with_index do |homework_test| homework_bank.homework_bank_tests << HomeworkBankTest.new( - test_type: 1, input: homework_test.input, output: homework_test.output ) end @homework.homework_samples.each_with_index do |homework_test| - homework_bank.homework_bank_tests << HomeworkBankTest.new( - test_type: 0, + homework_bank.homework_bank_samples << HomeworkBankSample.new( input: homework_test.input, output: homework_test.output ) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index eaf3fa298..eabedeb7a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1775,6 +1775,8 @@ module ApplicationHelper title << "酷得网 - 互联网教学实训平台" elsif @course title << (@course.name.nil? ? "智能课堂" : @course.name) + elsif params[:controller] == "homework_bank" + title << ("智能课堂") elsif params[:controller] == "courses" && params[:action] == "index" title << ("智能课堂") elsif @contest @@ -4569,19 +4571,18 @@ end def add_to_homework_bank_f homework homework_bank = HomeworkBank.new(:name => homework.name, :description => homework.description, :user_id => homework.user_id, :homework_type => homework.homework_type, - :quotes => 1, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.syllabus.title, :homework_common_id => homework.id) + :quotes => 1, :is_public => homework.course.is_public, :applicable_syllabus => homework.course.syllabus.title, :homework_common_id => homework.id, + :reference_answer => homework.reference_answer, :syllabus_id => homework.course.syllabus_id) if homework.homework_type == 2 && homework.homework_detail_programing homework_bank.language = homework.homework_detail_programing.language homework.homework_tests.each_with_index do |homework_test| homework_bank.homework_bank_tests << HomeworkBankTest.new( - test_type: 1, input: homework_test.input, output: homework_test.output ) end homework.homework_samples.each_with_index do |homework_test| - homework_bank.homework_bank_tests << HomeworkBankTest.new( - test_type: 0, + homework_bank.homework_bank_samples << HomeworkBankSample.new( input: homework_test.input, output: homework_test.output ) @@ -4864,3 +4865,75 @@ def set_final_score homework,student_work end end + +def quote_resource_bank resource, course + atta = Attachment.new(:filename => resource.filename, :disk_filename => resource.disk_filename, :filesize => resource.filesize, :digest => resource.digest, :downloads => 0, :is_publish => 0, + :author_id => User.current.id, :description => resource.description, :disk_directory => resource.disk_directory, :is_public => 0, :copy_from => resource.copy_from.nil? ? resource.id : resource.copy_from, + :quotes => 0, :resource_bank_id => resource.id, :created_on => Time.now, :content_type =>resource.content_type) + if course.attachments << atta + # 更新引用次数 + quotes = resource.quotes.to_i + 1 + resource.update_attribute(:quotes, quotes) + end +end + +def quote_homework_bank homework, course + new_homework = HomeworkCommon.new(:name => homework.name, :user_id => User.current.id, :description => homework.description, :homework_type => homework.homework_type, :late_penalty => 0, + :course_id => course.id, :teacher_priority => 1, :anonymous_comment => 1, :quotes => 0, :is_open => 0, :homework_bank_id => homework.id, :score_open => 1, + :anonymous_appeal => 0, :is_public => 0, :reference_answer => homework.reference_answer, :answer_public => 1, :allow_late => 1) + + new_homework.homework_detail_manual = HomeworkDetailManual.new + new_homework_detail_manual = new_homework.homework_detail_manual + new_homework_detail_manual.te_proportion = 1.0 + new_homework_detail_manual.ta_proportion = 0 + new_homework_detail_manual.comment_status = 0 + + new_homework_detail_manual.evaluation_num = 0 + new_homework_detail_manual.absence_penalty = 0 + + if new_homework.homework_type == 2 + new_homework.homework_detail_programing = HomeworkDetailPrograming.new + new_homework.homework_detail_programing.ta_proportion = 0 + new_homework.homework_detail_programing.language = homework.language + homework.homework_bank_tests.each_with_index do |homework_test| + new_homework.homework_tests << HomeworkTest.new( + input: homework_test.input, + output: homework_test.output + ) + end + homework.homework_bank_samples.each_with_index do |homework_test| + new_homework.homework_samples << HomeworkSample.new( + input: homework_test.input, + output: homework_test.output + ) + end + end + + if new_homework.homework_type == 3 + new_homework.homework_detail_group = HomeworkDetailGroup.new + new_homework.homework_detail_group.min_num = homework.min_num + new_homework.homework_detail_group.max_num = homework.max_num + new_homework.homework_detail_group.base_on_project = homework.base_on_project + end + + homework.attachments.each do |attachment| + att = attachment.copy + att.container_id = nil + att.container_type = nil + att.author_id = homework.user_id + att.copy_from = attachment.id + att.save + new_homework.attachments << att + end + + if new_homework.save + if new_homework.homework_type == 4 + HomeworkCommonsShixuns.create(:homework_common_id => new_homework.id, :shixun_id => homework.homework_bank_shixun.shixun_id) + end + new_homework_detail_manual.save if new_homework_detail_manual + new_homework.homework_detail_programing.save if new_homework.homework_detail_programing + new_homework.homework_detail_group.save if new_homework.homework_detail_group + homework.update_column(:quotes, homework.quotes+1) + end +end + diff --git a/app/helpers/homework_bank_helper.rb b/app/helpers/homework_bank_helper.rb new file mode 100644 index 000000000..fbb669ff3 --- /dev/null +++ b/app/helpers/homework_bank_helper.rb @@ -0,0 +1,2 @@ +module HomeworkBankHelper +end diff --git a/app/helpers/owner_type_helper.rb b/app/helpers/owner_type_helper.rb index 56512afcf..9124a4f98 100644 --- a/app/helpers/owner_type_helper.rb +++ b/app/helpers/owner_type_helper.rb @@ -14,4 +14,5 @@ module OwnerTypeHelper CONTEST = 13 HOMEWORKREFERENCEANSWER = 14 STUDENTWORK = 15 + HOMEWORKBANK = 16 end \ No newline at end of file diff --git a/app/helpers/syllabuses_helper.rb b/app/helpers/syllabuses_helper.rb index 70f865ef5..3cf56b047 100644 --- a/app/helpers/syllabuses_helper.rb +++ b/app/helpers/syllabuses_helper.rb @@ -131,60 +131,4 @@ module SyllabusesHelper content end - def quote_resource_bank resource, course - atta = Attachment.new(:filename => resource.filename, :disk_filename => resource.disk_filename, :filesize => resource.filesize, :digest => resource.digest, :downloads => 0, :is_publish => 0, - :author_id => User.current.id, :description => resource.description, :disk_directory => resource.disk_directory, :is_public => 0, :copy_from => resource.copy_from.nil? ? resource.id : resource.copy_from, - :quotes => 0, :resource_bank_id => resource.id, :created_on => Time.now, :content_type =>resource.content_type) - if course.attachments << atta - # 更新引用次数 - quotes = resource.quotes.to_i + 1 - resource.update_attribute(:quotes, quotes) - end - end - - def quote_homework_bank homework, course - new_homework = HomeworkCommon.new(:name => homework.name, :user_id => User.current.id, :description => homework.description, :homework_type => homework.homework_type, :late_penalty => 0, - :course_id => course.id, :teacher_priority => 1, :anonymous_comment => 1, :quotes => 0, :is_open => 0, - :homework_bank_id => homework.id, :score_open => 1, :anonymous_appeal => 0) - - new_homework.homework_detail_manual = HomeworkDetailManual.new - new_homework_detail_manual = new_homework.homework_detail_manual - new_homework_detail_manual.ta_proportion = new_homework.homework_type == 2 ? 0.4 : 1.0 - new_homework_detail_manual.comment_status = 0 - new_homework_detail_manual.evaluation_num = 3 - new_homework_detail_manual.absence_penalty = 0 - - if new_homework.homework_type == 2 - new_homework.homework_detail_programing = HomeworkDetailPrograming.new - new_homework.homework_detail_programing.ta_proportion = 0.6 - new_homework.homework_detail_programing.language = homework.language - homework.homework_bank_tests.each_with_index do |homework_test| - if homework_test.test_type - new_homework.homework_tests << HomeworkTest.new( - input: homework_test.input, - output: homework_test.output - ) - else - new_homework.homework_samples << HomeworkSample.new( - input: homework_test.input, - output: homework_test.output - ) - end - end - end - - if new_homework.homework_type == 3 - new_homework.homework_detail_group = HomeworkDetailGroup.new - new_homework.homework_detail_group.min_num = homework.min_num - new_homework.homework_detail_group.max_num = homework.max_num - new_homework.homework_detail_group.base_on_project = homework.base_on_project - end - - if new_homework.save - new_homework_detail_manual.save if new_homework_detail_manual - new_homework.homework_detail_programing.save if new_homework.homework_detail_programing - new_homework.homework_detail_group.save if new_homework.homework_detail_group - homework.update_column(:quotes, homework.quotes+1) - end - end end diff --git a/app/models/homework_bank.rb b/app/models/homework_bank.rb index 0f89c74d9..6cd699bbd 100644 --- a/app/models/homework_bank.rb +++ b/app/models/homework_bank.rb @@ -2,7 +2,11 @@ class HomeworkBank < ActiveRecord::Base # attr_accessible :title, :body belongs_to :user - has_many :homework_bank_tests + belongs_to :syllabus + has_many :homework_bank_tests, :dependent => :destroy + has_many :homework_bank_samples, :dependent => :destroy + has_many :homework_commons + has_one :homework_bank_shixun acts_as_attachable def language_name diff --git a/app/models/homework_bank_sample.rb b/app/models/homework_bank_sample.rb new file mode 100644 index 000000000..7b64f93a9 --- /dev/null +++ b/app/models/homework_bank_sample.rb @@ -0,0 +1,4 @@ +class HomeworkBankSample < ActiveRecord::Base + belongs_to :homework_bank + attr_accessible :input, :output, :homework_bank_id +end diff --git a/app/models/homework_bank_shixun.rb b/app/models/homework_bank_shixun.rb new file mode 100644 index 000000000..3bec23fcd --- /dev/null +++ b/app/models/homework_bank_shixun.rb @@ -0,0 +1,5 @@ +class HomeworkBankShixun < ActiveRecord::Base + belongs_to :homework_bank + belongs_to :shixun + attr_accessible :homework_bank_id, :shixun_id +end diff --git a/app/models/syllabus.rb b/app/models/syllabus.rb index 80d24ba5a..42af92576 100644 --- a/app/models/syllabus.rb +++ b/app/models/syllabus.rb @@ -20,6 +20,7 @@ class Syllabus < ActiveRecord::Base belongs_to :user has_many :courses + has_many :homework_banks has_many :reference_materials, :dependent => :destroy has_many :syllabus_update_records, :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy diff --git a/app/views/homework_bank/_homework_bank_list.html.erb b/app/views/homework_bank/_homework_bank_list.html.erb new file mode 100644 index 000000000..e47254228 --- /dev/null +++ b/app/views/homework_bank/_homework_bank_list.html.erb @@ -0,0 +1,84 @@ +
+
+ + +
+
+

<%= @hw_count %>个搜索结果

+ <%= link_to '引用次数排序', homework_bank_index_path(:type => @type, :order => "quotes", :search => @search, :sort => @r_sort, :property=>@property), :class => "fr mr15 #{@order == 'quotes' ? 'color-blue' : ''}", :remote => true %> + | + <%= link_to '更新时间排序', homework_bank_index_path(:type => @type, :order => "updated_at", :search => @search, :sort => @r_sort, :property=>@property), :class => "fr #{@order == 'updated_at' ? 'color-blue' : ''}", :remote => true %> +
+
+

+ <%= link_to '全部', homework_bank_index_path(:type => @type), :class => 'edu-filter-cir-grey mr5 active', :id => 'homework_bank_pro_0', :remote => true %> + <%= link_to '编程', homework_bank_index_path(:type => @type, :property => 2), :class => 'edu-filter-cir-grey mr5', :id => 'homework_bank_pro_2', :remote => true %> + <%= link_to '普通', homework_bank_index_path(:type => @type, :property => 1), :class => 'edu-filter-cir-grey mr5', :id => 'homework_bank_pro_1', :remote => true %> + <%= link_to '分组', homework_bank_index_path(:type => @type, :property => 3), :class => 'edu-filter-cir-grey mr5', :id => 'homework_bank_pro_3', :remote => true %> + <%= link_to '实训', homework_bank_index_path(:type => @type, :property => 4), :class => 'edu-filter-cir-grey mr5', :id => 'homework_bank_pro_4', :remote => true %> + <%#= link_to '试卷', homework_bank_path(:type => @type, :property => 5), :class => 'edu-filter-cir-grey mr5', :remote => true %> +

+ 新建 +
+
+
+ <% if @hw_count != 0 %> + <%= form_tag(choose_user_course_homework_bank_index_path(), :id => 'hb_search_course_h_form', :remote => true, :method => 'post') do %> + <% @homeworks.each do |homework| %> +
+
+ + + <%= link_to homework.name, homework_bank_path(homework.id), :class => 'edu-class-inner-list fl ml25', :target => '_blank' %> + <% unless homework.is_public %> + + <% end %> +
+

+ 更新于<%= time_from_now homework.updated_at %> + <%= homework.quotes %> 次引用 + <%= StudentWork.where(:is_delete => 0, :work_status => [1, 2, 3], :homework_common_id => homework.homework_commons.map(&:id)).count %> 次答题 + <% if homework.syllabus_id && homework.syllabus.major_level %> + <% syllabus = homework.syllabus %> + + <%= syllabus.syllabus_major_level %> - <%= syllabus.syllabus_discipline_category %> - <%= syllabus.syllabus_first_level_discipline %> - <%= syllabus.title %> + + <% end %> +

+
+
+ +
    +
  • <%= link_to '预览', homework_bank_path(homework), :target => '_blank' %>
  • +
  • <%= link_to '发送', choose_user_course_homework_bank_index_path(:check_homework_bank => ["#{homework.id}"]), :remote => true %>
  • + <% if @type.to_i == 1 %> +
  • 删除
  • + <% end %> +
+
+
+ <% end %> + <% end %> + <% else %> + <%= render :partial => 'welcome/no_data' %> + <% end %> +
+ + +
\ No newline at end of file diff --git a/app/views/homework_bank/_hw_search_course_list.html.erb b/app/views/homework_bank/_hw_search_course_list.html.erb new file mode 100644 index 000000000..7c00061d9 --- /dev/null +++ b/app/views/homework_bank/_hw_search_course_list.html.erb @@ -0,0 +1,12 @@ +<% if @courses.count > 0 %> + <% @courses.each do |course| %> +
  • + +
  • + <% end %> +<% else %> + +<% end %> diff --git a/app/views/homework_bank/_new_common_homework.html.erb b/app/views/homework_bank/_new_common_homework.html.erb new file mode 100644 index 000000000..2f82919a8 --- /dev/null +++ b/app/views/homework_bank/_new_common_homework.html.erb @@ -0,0 +1,77 @@ +
    +

    <%= edit_mode ? '编辑' : '新建' %>普通作业

    +
    +
    + + 有3 处问题导致无法保存 + +
    +
    +
    +
    +
      + +
    • + + <%= select_tag :syllabus_id,options_for_select(course_syllabus_option,@homework.syllabus_id), {:id=>"new_syllabus_id", :class=>"fl task-height-40 task-form-30"} %> +
      +
      + + +

      课程列表中没有?<%= link_to '创建课程', new_syllabus_path(),:target => '_blank', :class => 'color-blue' %>

      +
      +
      +
      +
    • +
    • + + +
    • +
    • + + <%= hidden_field_tag :asset_id, params[:asset_id], :required => false, :style => 'display:none' %> + + <%= f.kindeditor :description, :editor_id => 'homework_description_editor', + :owner_id => @homework.nil? ? 0: @homework.id, + :owner_type => OwnerTypeHelper::HOMEWORKBANK, + :width => '89.7%', + :height => 200, + :minHeight=>200, + :class => 'talk_text fl', + :input_html => { :id => 'homework_content', + :class => 'talk_text fl', + :maxlength => 5000 } + %> +
    • +
    • + <%= render :partial => 'users/user_homework_attachment', :locals => {:container => @homework} %> +
    • + +
    • + + + <%= f.kindeditor :reference_answer, :editor_id => 'homework_ref_answer_editor', + :owner_id => @homework.nil? ? 0: @homework.id, + :owner_type => OwnerTypeHelper::HOMEWORKBANK, + :width => '89.7%', + :height => 200, + :minHeight=>200, + :class => 'talk_text fl', + :input_html => { :id => 'homework_ref_answer', + :class => 'talk_text fl', + :maxlength => 5000 } + %> +
    • +
    • + 保存 + <% if edit_mode %> + <%= link_to '取消', homework_bank_path(@homework), :class => 'task-btn fr mr10' %> + <% else %> + <%= link_to '取消', homework_bank_index_path(), :class => 'task-btn fr mr10' %> + <% end %> +
    • +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/homework_bank/_new_group_homework.html.erb b/app/views/homework_bank/_new_group_homework.html.erb new file mode 100644 index 000000000..7e3a4523f --- /dev/null +++ b/app/views/homework_bank/_new_group_homework.html.erb @@ -0,0 +1,93 @@ +<% not_allow_select = edit_mode && @homework.student_works.has_committed.count != 0 %> + +
    +

    <%= edit_mode ? '编辑' : '新建' %>分组作业

    +
    +
    + + 有3 处问题导致无法保存 + +
    +
    +
    +
    +
      + +
    • + + <%= select_tag :syllabus_id,options_for_select(course_syllabus_option,@homework.syllabus_id), {:id=>"new_syllabus_id", :class=>"fl task-height-40 task-form-30"} %> +
      +
      + + +

      课程列表中没有?<%= link_to '创建课程', new_syllabus_path(),:target => '_blank', :class => 'color-blue' %>

      +
      +
      +
      +
    • +
    • + + +
    • +
    • + + <%= hidden_field_tag :asset_id, params[:asset_id], :required => false, :style => 'display:none' %> + + <%= f.kindeditor :description, :editor_id => 'homework_description_editor', + :owner_id => @homework.nil? ? 0: @homework.id, + :owner_type => OwnerTypeHelper::HOMEWORKBANK, + :width => '89.7%', + :height => 200, + :minHeight=>200, + :class => 'talk_text fl', + :input_html => { :id => 'homework_content', + :class => 'talk_text fl', + :maxlength => 5000 } + %> +
    • +
    • + <%= render :partial => 'users/user_homework_attachment', :locals => {:container => @homework} %> +
    • +
    • + +
        +
      • + 每组最小人数 + + 每组最大人数 + + + 已有学生提交作品,只能扩大分组范围,原分组人数为<%= @homework.min_num %>-<%= @homework.max_num %>人 + +
      • + 注:任一成员都可以提交作品,提交作品时需要关联同组成员,组内成员作品共享。 +
      +
    • +
    • + + + <%= f.kindeditor :reference_answer, :editor_id => 'homework_ref_answer_editor', + :owner_id => @homework.nil? ? 0: @homework.id, + :owner_type => OwnerTypeHelper::HOMEWORKBANK, + :width => '89.7%', + :height => 200, + :minHeight=>200, + :class => 'talk_text fl', + :input_html => { :id => 'homework_ref_answer', + :class => 'talk_text fl', + :maxlength => 5000 } + %> +
    • +
    • + 保存 + <% if edit_mode %> + <%= link_to '取消', homework_bank_path(@homework), :class => 'task-btn fr mr10' %> + <% else %> + <%= link_to '取消', homework_bank_index_path(), :class => 'task-btn fr mr10' %> + <% end %> +
    • +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/homework_bank/_new_program_homework.html.erb b/app/views/homework_bank/_new_program_homework.html.erb new file mode 100644 index 000000000..c6f6ad623 --- /dev/null +++ b/app/views/homework_bank/_new_program_homework.html.erb @@ -0,0 +1,170 @@ +
    +

    <%= edit_mode ? '编辑' : '新建' %>编程作业

    +
    +
    + + 有3 处问题导致无法保存 + +
    +
    +
    +
    +
      + +
    • + + <%= select_tag :syllabus_id,options_for_select(course_syllabus_option,@homework.syllabus_id), {:id=>"new_syllabus_id", :class=>"fl task-height-40 task-form-30"} %> +
      +
      + + +

      课程列表中没有?<%= link_to '创建课程', new_syllabus_path(),:target => '_blank', :class => 'color-blue' %>

      +
      +
      +
      +
    • +
    • + + +
    • +
    • + + <%= hidden_field_tag :asset_id, params[:asset_id], :required => false, :style => 'display:none' %> + + <%= f.kindeditor :description, :editor_id => 'homework_description_editor', + :owner_id => @homework.nil? ? 0: @homework.id, + :owner_type => OwnerTypeHelper::HOMEWORKBANK, + :width => '89.7%', + :height => 200, + :minHeight=>200, + :class => 'talk_text fl', + :input_html => { :id => 'homework_content', + :class => 'talk_text fl', + :maxlength => 5000 } + %> +
    • +
    • + <%= render :partial => 'users/user_homework_attachment', :locals => {:container => @homework} %> +
    • +
    • + +
        + <% if edit_mode && @homework.homework_bank_samples.count > 0 %> + <% @homework.homework_bank_samples.each_with_index do |sample, index| %> +
      • +

        + 样例<%= index + 1 %> + + <% if index != 0 %> + + <% else %> + 温馨提示:请至少输入一组样例供学生参考。 + <% end %> +

        + + +
      • + <% end %> + <% else %> +
      • +

        + 样例1 + + 温馨提示:请至少输入一组样例供学生参考。 +

        + + +
      • + <% end %> +
      +
    • +
    • + +
        +
      • +

        + + 温馨提示:您可以在发布后,通过"模拟答题"进行标准代码的检测。 +

        +
      • + <% if edit_mode %> + <% @homework.homework_bank_tests.each_with_index do |test, index| %> +
      • +

        + 测试<%= index + 1 %> + + <% if index != 0 %> + + <% end %> +

        + + +
      • + <% end %> + <% else %> +
      • +

        + 测试1 + +

        + + +
      • + <% end %> +
      +
    • +
    • + + + <%= f.kindeditor :reference_answer, :editor_id => 'homework_ref_answer_editor', + :owner_id => @homework.nil? ? 0: @homework.id, + :owner_type => OwnerTypeHelper::HOMEWORKBANK, + :width => '89.7%', + :height => 200, + :minHeight=>200, + :class => 'talk_text fl', + :input_html => { :id => 'homework_ref_answer', + :class => 'talk_text fl', + :maxlength => 5000 } + %> +
    • +
    • + 保存 + <% if edit_mode %> + <%= link_to '取消', homework_bank_path(@homework), :class => 'task-btn fr mr10' %> + <% else %> + <%= link_to '取消', homework_bank_index_path(), :class => 'task-btn fr mr10' %> + <% end %> +
    • +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/app/views/homework_bank/_send_homework_bank.html.erb b/app/views/homework_bank/_send_homework_bank.html.erb new file mode 100644 index 000000000..5f7926f5d --- /dev/null +++ b/app/views/homework_bank/_send_homework_bank.html.erb @@ -0,0 +1,34 @@ +
    +
    +

    发送题库

    + +
    +
    +
    +
    + + 选择的题将会发送到指定班级 +
    +
    + + +
    + <%= form_tag(send_h_bank_to_course_homework_bank_index_path(), :id => 'send_hb_to_course_form', :remote => true, :method => 'post') do %> +
    + <% @homework_ids.each do |id| %> + + <% end %> +
      + <%= render :partial => 'homework_bank/hw_search_course_list' %> +
    +
    + <% end %> +
    + + 确定 + 取消 +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/homework_bank/_shixuns.html.erb b/app/views/homework_bank/_shixuns.html.erb new file mode 100644 index 000000000..1d6fba616 --- /dev/null +++ b/app/views/homework_bank/_shixuns.html.erb @@ -0,0 +1,52 @@ +
    +
    +

    选择实训

    + +
    +
    + <%= labelled_form_for @homework, :url =>{:controller=> 'homework_bank', :action => 'shixuns'}, :id => 'shixun_search_form', :method => "get", :remote => true do |f| %> +
    +
    + + +
    +
    + <% end %> + <%= labelled_form_for @homework, :url =>{:controller=> 'homework_bank', :action => 'create'}, :html => {:id => 'shixun_homework_bank_new'}, :method => "post" do |f| %> + + + + + + + + + 请至少选中一个实训 + + <% @shixuns.each do |shixun| %> + + + + + + <% 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 %>
    + <% end %> +
    +
    + 选择 + 取消 +
    +
    +
      + <%= pagination_links_full @shixun_pages, @shixuns_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %> +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/homework_bank/choose_user_course.js.erb b/app/views/homework_bank/choose_user_course.js.erb new file mode 100644 index 000000000..678680b27 --- /dev/null +++ b/app/views/homework_bank/choose_user_course.js.erb @@ -0,0 +1,6 @@ +<% if params[:is_observe].nil? %> +var htmlvalue = "<%= escape_javascript(render :partial => 'homework_bank/send_homework_bank') %>"; +pop_box_new(htmlvalue, 452, 463); +<% else %> +$("#search_course_list").html("<%= escape_javascript(render :partial => 'homework_bank/hw_search_course_list') %>"); +<% end %> diff --git a/app/views/homework_bank/edit.html.erb b/app/views/homework_bank/edit.html.erb new file mode 100644 index 000000000..3249f77d4 --- /dev/null +++ b/app/views/homework_bank/edit.html.erb @@ -0,0 +1,18 @@ +<% content_for :header_tags do %> + <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> +<% end %> +
    +

    + + <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to '智能课堂', courses_path() %> > <%= link_to '我的题库', homework_bank_index_path() %> > 编辑 +

    + <%= form_for @homework, :html => {:id => 'homework_common_submit_form'} do |f| %> + <% if @homework_type == 1 %> + <%= render :partial => 'new_common_homework', :locals => {:f => f, :edit_mode => true} %> + <% elsif @homework_type == 2 %> + <%= render :partial => 'new_program_homework', :locals => {:f => f, :edit_mode => true} %> + <% elsif @homework_type == 3 %> + <%= render :partial => 'new_group_homework', :locals => {:f => f, :edit_mode => true} %> + <% end %> + <% end %> +
    \ No newline at end of file diff --git a/app/views/homework_bank/index.html.erb b/app/views/homework_bank/index.html.erb new file mode 100644 index 000000000..19b25fd40 --- /dev/null +++ b/app/views/homework_bank/index.html.erb @@ -0,0 +1,33 @@ + + +
    +

    <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to '智能课堂', courses_path() %> > 题库

    +
    +
    +
    + +
    +
    + <%= render :partial => 'homework_bank/homework_bank_list' %> +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/homework_bank/index.js.erb b/app/views/homework_bank/index.js.erb new file mode 100644 index 000000000..4aad8261b --- /dev/null +++ b/app/views/homework_bank/index.js.erb @@ -0,0 +1,20 @@ +$("#edu-tab-con-1").html("<%= j(render :partial => 'homework_bank/homework_bank_list') %>"); +<% if params[:property] %> +$(".edu-filter-cir-grey").removeClass("active"); +<% case params[:property].to_i %> +<% when 1 %> + $("#homework_bank_pro_1").addClass("active"); +<% when 2 %> + $("#homework_bank_pro_2").addClass("active"); +<% when 3 %> + $("#homework_bank_pro_3").addClass("active"); +<% when 4 %> + $("#homework_bank_pro_4").addClass("active"); +<% else %> + $("#homework_bank_pro_0").addClass("active"); +<% end %> +<% end %> +if(<%= params[:type] == '2' %>){ + $("#edu-tab-nav-1").removeClass("edu-new-tab-hover"); + $("#edu-tab-nav-2").addClass("edu-new-tab-hover"); +} \ No newline at end of file diff --git a/app/views/homework_bank/new.html.erb b/app/views/homework_bank/new.html.erb new file mode 100644 index 000000000..614a36255 --- /dev/null +++ b/app/views/homework_bank/new.html.erb @@ -0,0 +1,18 @@ +<% content_for :header_tags do %> + <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> +<% end %> +
    +

    + + <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to '智能课堂', courses_path() %> > <%= link_to '我的题库', homework_bank_index_path() %> > 新建 +

    + <%= labelled_form_for @homework, :url =>{:controller=>'homework_bank',:action => 'create'}, :html => {:id => 'homework_common_submit_form'}, :method => "post" do |f| %> + <% if @homework_type == 1 %> + <%= render :partial => 'new_common_homework', :locals => {:f => f, :edit_mode => false} %> + <% elsif @homework_type == 2 %> + <%= render :partial => 'new_program_homework', :locals => {:f => f, :edit_mode => false} %> + <% elsif @homework_type == 3 %> + <%= render :partial => 'new_group_homework', :locals => {:f => f, :edit_mode => false} %> + <% end %> + <% end %> +
    \ No newline at end of file diff --git a/app/views/homework_bank/send_h_bank_to_course.js.erb b/app/views/homework_bank/send_h_bank_to_course.js.erb new file mode 100644 index 000000000..cd9b51b7b --- /dev/null +++ b/app/views/homework_bank/send_h_bank_to_course.js.erb @@ -0,0 +1 @@ +yes_notice_box("已发送到目标班级的作业列表
    但需要您设置发布和截止时间,以激活相应作业,谢谢!"); \ No newline at end of file diff --git a/app/views/homework_bank/shixuns.js.erb b/app/views/homework_bank/shixuns.js.erb new file mode 100644 index 000000000..873e31a14 --- /dev/null +++ b/app/views/homework_bank/shixuns.js.erb @@ -0,0 +1,2 @@ +var htmlvalue = "<%= escape_javascript(render :partial => 'homework_bank/shixuns') %>"; +pop_box_new(htmlvalue, 680, 454); \ No newline at end of file diff --git a/app/views/homework_bank/show.html.erb b/app/views/homework_bank/show.html.erb new file mode 100644 index 000000000..a78506207 --- /dev/null +++ b/app/views/homework_bank/show.html.erb @@ -0,0 +1,177 @@ +<% content_for :header_tags do %> + <%= javascript_include_tag "/assets/codemirror/codemirror_python_ruby_c" %> + <%= javascript_include_tag "resizeable_table" %> + <%= stylesheet_link_tag "/assets/codemirror/codemirror" %> +<% end %> + + + +
    +

    + + <%= link_to User.current.show_name, user_path(User.current) %> > <%= link_to '智能课堂', courses_path() %> > <%= @homework.user == User.current ? link_to('我的题库', homework_bank_index_path()) : link_to('公共题库', homework_bank_index_path(:type => 2)) %>

    +
    +

    + <% unless @homework.is_public %> + + <% end %> + <%= @homework.name %> +

    + <%= link_to '返回', @homework.user == User.current ? homework_bank_index_path() : homework_bank_index_path(:type => 2), :class => 'fr font-12 mr15 mt3 link-color-grey' %> +
    +
    +
    +
    + +
    +
    +
    + <% if @is_admin %> +
    + +
      + <% if @homework.homework_type != 4 %> +
    • + <%= link_to l(:button_edit), edit_homework_bank_path(@homework) %> +
    • + <% end %> +
    • + <%= link_to "发送", setting_homework_common_path(@homework) %> +
    • + <% unless @homework.is_public %> +
    • + 设为公开 +
    • + <% end %> +
    • + 删除 +
    • +
    +
    + <% elsif @homework.is_public %> +
  • + <%= link_to "发送", setting_homework_common_path(@homework) %> +
  • + <% end %> +
    +
    + <%= @homework.description.html_safe %> +
    +
    +
      + <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => @homework} %> +
    + <% if @homework.homework_type == 3 %> +
    +
    +

    分组要求

    +
    +
    +

    分组人数: <%= @homework.min_num %> - <%= @homework.max_num %> 人

    + 注:任一成员都可以提交作品,提交作品时需要关联同组成员,组内成员作品共享。 +
    +
    + <% end %> + + <% if @homework.homework_type == 2 %> + <% samples = @homework.homework_bank_samples %> + <% unless samples.empty? %> +
    +
    +

    输入输出样例:<%= samples.count %> 组

    +
    +
    + <% samples.each_with_index do |sample, index| %> +
    +
      +
    • + + 样例<%= index + 1 %> +
    • +
    • + +
      +
      <%=sample.input.blank? ? " " : sample.input %>
      +
      +
    • +
    • + +
      +
      <%=sample.output.blank? ? " " : sample.output %>
      +
      +
    • +
    +
    + <% end %> +
    +
    + <% end %> + + <%# if @is_teacher %> +
    +
    +

    测试集:<%=@homework.homework_bank_tests.count %> 组

    +
    +
    + + + + + + + + + + <% @homework.homework_bank_tests.each_with_index do |test, i| %> + + + + + + <% end %> + +
    序号测试集输入测试集输出
    <%=i+1 %> +
    <%=test.input.blank? ? " " : test.input %>
    +
    +
    <%=test.output.blank? ? " " : test.output %>
    +
    +
    +
    + <% end %> + <%# end %> +
    +
    +
    +
    + <% unless @homework.reference_answer.blank? %> + <%= @homework.reference_answer.html_safe %> + <% else %> + +

    暂未设置参考答案 ~

    + <% end %> +
    +
    +
    +
    +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/homework_common/_new_group_homework.html.erb b/app/views/homework_common/_new_group_homework.html.erb index 8b16247bb..5f6b46ed6 100644 --- a/app/views/homework_common/_new_group_homework.html.erb +++ b/app/views/homework_common/_new_group_homework.html.erb @@ -76,8 +76,11 @@
  • 保存 - <%= link_to '取消', homework_common_index_path(:course => @course), :class => 'task-btn fr mr10' %> -
  • + <% if edit_mode %> + <%= link_to '取消', student_work_index_path(:homework => @homework.id), :class => 'task-btn fr mr10' %> + <% else %> + <%= link_to '取消', homework_common_index_path(:course => @course), :class => 'task-btn fr mr10' %> + <% end %> diff --git a/app/views/homework_common/_new_program_homework.html.erb b/app/views/homework_common/_new_program_homework.html.erb index b9ef4f63a..e9085006d 100644 --- a/app/views/homework_common/_new_program_homework.html.erb +++ b/app/views/homework_common/_new_program_homework.html.erb @@ -129,7 +129,11 @@
  • 保存 - <%= link_to '取消', homework_common_index_path(:course => @course), :class => 'task-btn fr mr10' %> + <% if edit_mode %> + <%= link_to '取消', student_work_index_path(:homework => @homework.id), :class => 'task-btn fr mr10' %> + <% else %> + <%= link_to '取消', homework_common_index_path(:course => @course), :class => 'task-btn fr mr10' %> + <% end %>
  • @@ -143,7 +147,7 @@

    - + @@ -156,6 +160,6 @@

    - + \ No newline at end of file diff --git a/app/views/homework_common/_shixuns.html.erb b/app/views/homework_common/_shixuns.html.erb index a568b5cbb..b8ae7b673 100644 --- a/app/views/homework_common/_shixuns.html.erb +++ b/app/views/homework_common/_shixuns.html.erb @@ -1,14 +1,14 @@
    -
    -

    选择实训

    - +
    +

    选择实训

    +
    -
    - <%= labelled_form_for @homework, :url =>{:controller=> 'homework_common', :action => 'shixuns', :course => @course.id}, :method => "get", :remote => true do |f| %> +
    + <%= labelled_form_for @homework, :url =>{:controller=> 'homework_common', :action => 'shixuns', :course => @course.id}, :id => 'shixun_search_form', :method => "get", :remote => true do |f| %>
    - - + +
    <% end %> @@ -37,9 +37,9 @@ <% end %>
    -
    - 取消 - 选择 +
      diff --git a/app/views/layouts/_public_left_info.html.erb b/app/views/layouts/_public_left_info.html.erb index 3cd67d0f4..695788a58 100644 --- a/app/views/layouts/_public_left_info.html.erb +++ b/app/views/layouts/_public_left_info.html.erb @@ -22,8 +22,8 @@
      题库
        -
      • <%= link_to "我的题库", user_homeworks_user_path(User.current, :type => 1), :target => "_blank" %>
      • -
      • <%= link_to "公共题库", user_homeworks_user_path(User.current, :type => 2), :target => "_blank" %>
      • +
      • <%= link_to "我的题库", homework_bank_index_path(), :target => "_blank" %>
      • +
      • <%= link_to "公共题库", homework_bank_index_path(:type => 2), :target => "_blank" %>
      diff --git a/app/views/student_work/index.html.erb b/app/views/student_work/index.html.erb index 01b2dbcd6..94dccd5c7 100644 --- a/app/views/student_work/index.html.erb +++ b/app/views/student_work/index.html.erb @@ -43,9 +43,11 @@
    • 作品列表
    • -
    • - 参考答案 -
    • + <% if @is_teacher || (@homework.answer_public && @homework.homework_detail_manual.comment_status > 2) %> +
    • + 参考答案 +
    • + <% end %>
    @@ -296,18 +298,20 @@
    -
    -
    -
    - <% if @homework.reference_answer %> - <%= @homework.reference_answer.html_safe %> - <% else %> - -

    暂未设置参考答案 ~

    - <% end %> +<% if @is_teacher || (@homework.answer_public && @homework.homework_detail_manual.comment_status > 2) %> +
    +
    +
    + <% unless @homework.reference_answer.blank? %> + <%= @homework.reference_answer.html_safe %> + <% else %> + +

    暂未设置参考答案 ~

    + <% end %> +
    +
    -
    -
    +<% end %>
    diff --git a/app/views/users/_send_homework_to_course_form.html.erb b/app/views/users/_send_homework_to_course_form.html.erb index 5649c90f7..276eba09c 100644 --- a/app/views/users/_send_homework_to_course_form.html.erb +++ b/app/views/users/_send_homework_to_course_form.html.erb @@ -6,7 +6,7 @@ <% courses.each do |course| %>
  • - +
  • <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index f47e38655..c224208a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -432,6 +432,20 @@ RedmineApp::Application.routes.draw do end end + + resources :homework_bank do + member do + get 'set_public' + end + + collection do + match 'shixuns' + post 'destroy_all' + match 'choose_user_course' + post 'send_h_bank_to_course' + end + end + resources :student_work do member do post 'add_score' diff --git a/db/migrate/20170615070234_create_homework_bank_samples.rb b/db/migrate/20170615070234_create_homework_bank_samples.rb new file mode 100644 index 000000000..8104f047d --- /dev/null +++ b/db/migrate/20170615070234_create_homework_bank_samples.rb @@ -0,0 +1,30 @@ +class CreateHomeworkBankSamples < ActiveRecord::Migration + def change + create_table :homework_bank_samples do |t| + t.text :input + t.text :output + t.references :homework_bank + + t.timestamps + end + add_index :homework_bank_samples, :homework_bank_id + + count = HomeworkBank.where(:homework_type => 2).count / 30 + 2 + transaction do + for i in 1 .. count do + HomeworkBank.where(:homework_type => 2).page(i).per(30).each do |homework| + unless homework.homework_common_id.blank? + h_common = HomeworkCommon.find homework.homework_common_id + unless h_common.homework_samples.blank? + h_common.homework_samples.each do |hs| + HomeworkBankSample.create(:input => hs.input, :output => hs.output, :homework_bank_id => homework.id) + end + end + end + end + end + end + + HomeworkBankTest.where(:test_type => 0).destroy_all + end +end diff --git a/db/migrate/20170615080332_add_columns_to_homework_bank.rb b/db/migrate/20170615080332_add_columns_to_homework_bank.rb new file mode 100644 index 000000000..76482e2b6 --- /dev/null +++ b/db/migrate/20170615080332_add_columns_to_homework_bank.rb @@ -0,0 +1,24 @@ +class AddColumnsToHomeworkBank < ActiveRecord::Migration + def change + add_column :homework_banks, :reference_answer, :text + add_column :homework_banks, :syllabus_id, :integer + add_column :homework_banks, :major_level, :text + add_column :homework_banks, :discipline_category_id, :text + add_column :homework_banks, :first_level_discipline_id, :text + + count = HomeworkBank.all.count / 30 + 2 + transaction do + for i in 1 .. count do + HomeworkBank.page(i).per(30).each do |homework| + unless homework.homework_common_id.blank? + h_common = HomeworkCommon.find homework.homework_common_id + if h_common + course = h_common.course + homework.update_attributes(:reference_answer => h_common.reference_answer, :syllabus_id => course.syllabus_id) + end + end + end + end + end + end +end diff --git a/db/migrate/20170615105442_create_homework_bank_shixuns.rb b/db/migrate/20170615105442_create_homework_bank_shixuns.rb new file mode 100644 index 000000000..cab34bf37 --- /dev/null +++ b/db/migrate/20170615105442_create_homework_bank_shixuns.rb @@ -0,0 +1,12 @@ +class CreateHomeworkBankShixuns < ActiveRecord::Migration + def change + create_table :homework_bank_shixuns do |t| + t.references :homework_bank + t.references :shixun + + t.timestamps + end + add_index :homework_bank_shixuns, :homework_bank_id + add_index :homework_bank_shixuns, :shixun_id + end +end diff --git a/public/javascripts/edu/application.js b/public/javascripts/edu/application.js index 27e94b1f6..b31fcb532 100644 --- a/public/javascripts/edu/application.js +++ b/public/javascripts/edu/application.js @@ -209,7 +209,7 @@ function s_op_confirm_box(url, str){ function delete_confirm_box(url, str){ var htmlvalue = '

    提示

    '+ '

    ' + str + '

    '; + '确定
    '; pop_box_new(htmlvalue, 480, 140); } @@ -225,7 +225,7 @@ function delete_confirm_box_2(url, str){ function delete_confirm_box_3(url, str){ var htmlvalue = '

    提示

    '+ '

    ' + str + '

    '; + '确定
    '; pop_box_new(htmlvalue, 480, 140); } diff --git a/public/javascripts/edu/base_edu.js b/public/javascripts/edu/base_edu.js index baf0849ad..ed76112af 100644 --- a/public/javascripts/edu/base_edu.js +++ b/public/javascripts/edu/base_edu.js @@ -832,4 +832,157 @@ function SearchByName_1() success: function(data){ } }); +} + +function choose_course(user_id, hw_id) { + $.ajax({ + type: 'get', + url: '/users/' + user_id + '/choose_user_course?homework='+hw_id + }); +} +function submit_homework_bank_search(url){ + $.get(url, {search: $("#homework_bank_search").val()}, function(data){}) +} +function alert_choose_homework_bank_type(){ + var htmlvalue = '
    ' + + '
    ' + + '

    选择类别

    ' + + '' + + '
    ' + + '
    ' + + '
    ' + + '
    ' + + '类别:' + + '
      ' + + '
    • ' + + '' + + '' + + '
    • ' + + '
    • ' + + '' + + '' + + '
    • ' + + '
    • ' + + '' + + '' + + '
    • ' + + '
    • ' + + '' + + '' + + '
    • ' + + '
    ' + + '
    ' + + '
    ' + + '
    请先选择作业类型
    ' + + '
    ' + + '取消' + + '确定' + + '
    ' + + '
    ' + + '
    ' + + '
    '; + pop_box_new(htmlvalue, 300, 308); +} +function new_homework_bank_type(){ + if($("input[name='homework_type']:checked").length == 0){ + $("#homework_type_notice").show(); + } else{ + var type=$("input[name='homework_type']:checked").val(); + console.log(type == 4); + if(type == 4){ + $.ajax({ + url: '/homework_bank/shixuns', + remote: true + }); + }else{ + window.location.href = '/homework_bank/new?homework_type=' + $("input[name='homework_type']:checked").val(); + } + } +} + +function new_shixun_homework_bank(){ + if($("input[name='shixun_homework']:checked").length == 0){ + $("#homework_type_notice").show(); + } else{ + var type=$("input[name='shixun_homework']:checked").val(); + console.log(type); + $("#shixun_homework_bank_new").submit(); + } +} + +$(function(){ + $("input[name='check_homework_bank[]']").live('click', function(){ + if($("input[name='check_homework_bank[]']:checked").length == $("input[name='check_homework_bank[]']").length){ + $("#homework_bank_all_select").attr("checked", "checked"); + } else{ + $("#homework_bank_all_select").attr("checked", false); + } + }); + $("#homework_bank_all_select").live('click', function(){ + if($("#homework_bank_all_select").is(':checked')){ + $("input[name='check_homework_bank[]']").attr("checked", "checked"); + } else{ + $("input[name='check_homework_bank[]']").attr("checked", false); + } + }); + +}); + +function choose_course_to_send_hb(){ + if($("input[name='check_homework_bank[]']:checked").length >= 1){ + $("#choose_homework_bank_to_send_notice_h").html("").hide(); + $("#hb_search_course_h_form").submit(); + }else{ + $("#choose_homework_bank_to_send_notice_h").html("请先选择题目").show(); + } +} + +function search_hw_course(url){ + $.ajax({ + url: url, + type: 'post', + data: {search: $("#hb_search_course_input").val(), is_observe: true}, + success: function(data){ + } + }); +} + +function submit_send_hb_to_course(){ + if($("input[name='course_id']:checked").length >= 1){ + $("#search_course_notice_h").html("").hide(); + $("#send_hb_to_course_form").submit(); + hideModal(); + }else{ + $("#search_course_notice_h").html("请先选择一个班级").show(); + } +} + +function destroy_all_hb(url){ + if($("input[name='check_homework_bank[]']:checked").length >= 1){ + $("#choose_homework_bank_to_send_notice_h").html("").hide(); + var htmlvalue = '

    提示

    '+ + '

    确定要删除所选题目吗?

    取消'+ + '确定
    '; + pop_box_new(htmlvalue,480,140); + $("#destroy_all_hb_btn").on('click',function(){ + $.ajax({ + url: url, + type: 'post', + data: $("#hb_search_course_h_form").serialize(), + success: function(data){ + } + }); + hideModal(); + }); + }else{ + $("#choose_homework_bank_to_send_notice_h").html("请先选择题目").show(); + } } \ No newline at end of file diff --git a/public/javascripts/edu/homework.js b/public/javascripts/edu/homework.js index e8f047813..ea9d7e839 100644 --- a/public/javascripts/edu/homework.js +++ b/public/javascripts/edu/homework.js @@ -308,7 +308,7 @@ function alert_choose_homework_type(id){ '' + '' + '
    ' + - '
    请先选择作业类型
    ' + + '
    请先选择作业类型
    ' + '
    ' + '取消' + '确定' + diff --git a/public/stylesheets/css/edu-class.css b/public/stylesheets/css/edu-class.css index 38f3479f4..01ee8b809 100644 --- a/public/stylesheets/css/edu-class.css +++ b/public/stylesheets/css/edu-class.css @@ -73,7 +73,7 @@ table.table-pa5 th,table.table-pa5 td{ padding:0 5px;} .edu-class-top-info{ color:#333;} .edu-class-top-img{ width:260px; height: 140px;} /* tab */ -.edu-tab{ width: 100%; background:#fff;} +.edu-tab{ width: 100%; background:#fff; min-height: 600px;} #edu-tab-nav{height:47px;background: #fff; } #edu-tab-nav li {float:left; width: 170px; text-align:center;height: 47px;line-height: 47px; position: relative; } .edu-tab-fa{ position: absolute; top:28px!important; left:81px!important; color: #fff;} @@ -369,3 +369,10 @@ a.uploadIcon {width:100px; height:33px;color:#ffffff;} .mb15 {margin-bottom: 15px} .disable_link a {background-color: #c1c1c1 !important;} .reUploadDetail{border:1px solid #dddddd; float:left; resize:none; width:428px; height:80px; overflow-y:auto;outline: none;} + +.bank_tusi{position:absolute;top:0px;left:62.5%;width:450px;} +.bank_tusi .entry {background-color: #FFFEF4;height: 40px;line-height: 40px;border: 1px solid #F3DDB3;width:400px;margin:0 auto;position:relative; + text-indent:10px;} +.bank_tusi .entry em,.after{display: block;border-width: 9px; + position: absolute;top: 10px;left: -18px;border-style: dashed solid dashed dashed;border-color: transparent #F3DDB3 transparent transparent;font-size: 0;line-height: 0;} +.bank_tusi .entry .after{left: -17px;border-color: transparent #FFFEF4 transparent transparent;} \ No newline at end of file diff --git a/public/stylesheets/css/magic-check.css b/public/stylesheets/css/magic-check.css index a85427f80..0a4689727 100644 --- a/public/stylesheets/css/magic-check.css +++ b/public/stylesheets/css/magic-check.css @@ -29,7 +29,7 @@ .magic-radio + label:before, .magic-checkbox + label:before { position: absolute; - top: 5px; + top: 6px; left: 0; display: inline-block; width: 14px; diff --git a/spec/controllers/homework_bank_controller_spec.rb b/spec/controllers/homework_bank_controller_spec.rb new file mode 100644 index 000000000..2f8f93ecc --- /dev/null +++ b/spec/controllers/homework_bank_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkBankController, :type => :controller do + +end diff --git a/spec/factories/homework_bank_samples.rb b/spec/factories/homework_bank_samples.rb new file mode 100644 index 000000000..8974628bf --- /dev/null +++ b/spec/factories/homework_bank_samples.rb @@ -0,0 +1,8 @@ +FactoryGirl.define do + factory :homework_bank_sample do + input "MyText" +output "MyText" +homework_bank nil + end + +end diff --git a/spec/factories/homework_bank_shixuns.rb b/spec/factories/homework_bank_shixuns.rb new file mode 100644 index 000000000..2eba0c31d --- /dev/null +++ b/spec/factories/homework_bank_shixuns.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :homework_bank_shixun do + homework_bank nil +shixun nil + end + +end diff --git a/spec/models/homework_bank_sample_spec.rb b/spec/models/homework_bank_sample_spec.rb new file mode 100644 index 000000000..38e5f0dcc --- /dev/null +++ b/spec/models/homework_bank_sample_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkBankSample, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/homework_bank_shixun_spec.rb b/spec/models/homework_bank_shixun_spec.rb new file mode 100644 index 000000000..9a9921108 --- /dev/null +++ b/spec/models/homework_bank_shixun_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkBankShixun, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end