diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 4c6023265..70e06036a 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -4,34 +4,35 @@ class ExerciseController < ApplicationController before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise, :show_student_result,:student_exercise_list, :update_question_num, - :send_to_course, :get_student_uncomplete_question, :edit_question_score] + :send_to_course, :get_student_uncomplete_question, :edit_question_score, :setting, :set_public, + :ex_setting] before_filter :find_course, :only => [:index,:new,:create] include ExerciseHelper def index - publish_exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) - publish_exercises.each do |exercise| - exercise.update_column('exercise_status', 2) - course = exercise.course - course.members.each do |m| - exercise.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 2) - end - end - if @course.is_public == 0 && !(User.current.member_of_course?(@course)||User.current.admin?) render_403 return end - remove_invalid_exercise(@course) - @is_teacher = User.current.allowed_to?(:as_teacher,@course) - if @is_teacher || User.current.admin? - exercises = @course.exercises.order("created_at asc") + #remove_invalid_exercise(@course) + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + if @is_teacher + exercises = @course.exercises.order("created_at desc") else - exercises = @course.exercises.where("exercise_status <> 1").order("created_at asc") + exercises = @course.exercises.where("exercise_status <> 1").order("created_at desc") end - @exercises = paginateHelper exercises,20 #分页 + if params[:type] + @type = params[:type] + exercises = exercises.where(:exercise_status => params[:type]) + end + @search = params[:search] ? params[:search].to_s.strip : "" + if params[:search] + exercises = exercises.where("exercise_name like '%#{@search}%'") + end + @exercises = paginateHelper exercises,15 #分页 @left_nav_type = 8 respond_to do |format| + format.js format.html end end @@ -82,33 +83,29 @@ class ExerciseController < ApplicationController end def new - option = { - :exercise_name => "", - :course_id => @course.id, - :exercise_status => 1, - :user_id => User.current.id, - :time => "", - :end_time => "", - :publish_time => "", - :exercise_description => "", - :show_result => 1 - } - @exercise = Exercise.create option - if @exercise - redirect_to edit_exercise_url @exercise.id + # option = { + # :exercise_name => "", + # :course_id => @course.id, + # :exercise_status => 1, + # :user_id => User.current.id, + # :time => "", + # :end_time => "", + # :publish_time => "", + # :exercise_description => "", + # :show_result => 1 + # } + @exercise = Exercise.new + respond_to do |format| + format.html{render :layout => 'base_edu'} end end def create if params[:exercise] - exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id] - exercise ||= Exercise.new + exercise = Exercise.new exercise.exercise_name = params[:exercise][:exercise_name] exercise.exercise_description = params[:exercise][:exercise_description] - exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1) - exercise.publish_time = params[:exercise][:publish_time] exercise.user_id = User.current.id - exercise.time = params[:exercise][:time] exercise.course_id = params[:course_id] exercise.exercise_status = 1 if exercise.save @@ -123,19 +120,14 @@ class ExerciseController < ApplicationController def edit @left_nav_type = 8 respond_to do |format| - format.html{render :layout => 'base_courses'} + format.html{render :layout => 'base_edu'} end end def update @exercise.exercise_name = params[:exercise][:exercise_name] @exercise.exercise_description = params[:exercise][:exercise_description] - @exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time] - @exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1) - @exercise.publish_time = params[:exercise][:publish_time] - @exercise.show_result = params[:show_result] ? 1 : 0 - @exercise.question_random = params[:question_random] ? 0 : 1 - @exercise.choice_random = params[:choice_random] ? 0 : 1 + if @exercise.save respond_to do |format| format.js @@ -148,15 +140,34 @@ class ExerciseController < ApplicationController def destroy @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? if @exercise && @exercise.destroy - if @is_teacher - exercises = Exercise.where("course_id =?", @course.id) - else - exercises = Exercise.where("course_id =? and exercise_status =?", @course.id, 2) - end - @exercises = paginateHelper exercises,20 #分页 - respond_to do |format| - format.js - end + redirect_to exercise_index_path(:course_id => @course.id) + end + end + + def setting + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + @is_new = params[:is_new] ? true : false + respond_to do |format| + format.html{render :layout => 'base_edu'} + end + end + + def ex_setting + @exercise.publish_time = params[:exercise_publish_time] if params[:exercise_publish_time] + @exercise.end_time = params[:exercise_end_time] if params[:exercise_end_time] + @exercise.time = params[:time] != "" ? params[:time] : -1 + @exercise.question_random = params[:question_random] ? 1 : 0 + @exercise.choice_random = params[:choice_random] ? 1 : 0 + @exercise.score_open = params[:score_open] ? 1 : 0 + @exercise.answer_open = params[:answer_open] ? 1 : 0 + if @exercise.save + redirect_to student_exercise_list_exercise_path(@exercise) + end + end + + def set_public + if User.current.admin? || User.current.allowed_to?(:as_teacher, @course) + @exercise.update_attributes(:is_public => true) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 00891005d..ad90d5132 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -535,7 +535,7 @@ module ApplicationHelper style = 'edu-filter-btn-red' when '评阅中' style = 'edu-filter-btn-green' - when '已结束' + when '已结束', '已截止' style = 'edu-filter-btn-end' when '已开启补交' style = 'edu-filter-btn-late' @@ -606,6 +606,28 @@ module ApplicationHelper result end + # 试卷:该阶段还有多长时间结束/距下一阶段还有多长时间 + def exercise_curr_time exercise + result = {} + status = "" + time = "" + case exercise.exercise_status + when 1 + status = "未发布" + when 2 + if exercise.end_time && exercise.end_time >= Time.now + status = "提交中" + time = how_much_time(exercise.end_time) + end + when 3 + status = "已截止" + time = format_time exercise.end_time + end + result[:status] = status + result[:time] = time + result + end + # 公共分页 def paginator_list objs, objs_count, limit, is_remote @is_remote = is_remote @@ -4750,9 +4772,19 @@ def get_work_index(hw,is_teacher) return index end +def get_ex_index(exercise, course, is_teacher) + if is_teacher + exercises = course.exercises.order("created_at asc") + else + exercises = course.exercises.where("exercise_status > 0").order("created_at asc") + end + ex_ids = exercises.map{|ex| ex.id} if !exercises.blank? + index = ex_ids.index(exercise.id) + return index +end + def get_hw_index(hw,is_teacher,type=0) homework_commons = hw.course.homework_commons - Rails.logger.info("----------------------------------------------"+hw.course.to_s) if is_teacher if type != 0 homeworks = homework_commons.where("homework_commons.homework_type = #{type}").order("created_at asc") @@ -4766,7 +4798,6 @@ def get_hw_index(hw,is_teacher,type=0) homeworks = homework_commons.where("publish_time <= '#{Time.now}'").order("created_at asc") end end - Rails.logger.info("----------------------------------------------"+homeworks.count.to_s) hw_ids = homeworks.map{|hw| hw.id} if !homeworks.blank? index = hw_ids.index(hw.id) return index diff --git a/app/helpers/owner_type_helper.rb b/app/helpers/owner_type_helper.rb index 3239d9d8e..b4fb514c9 100644 --- a/app/helpers/owner_type_helper.rb +++ b/app/helpers/owner_type_helper.rb @@ -16,4 +16,5 @@ module OwnerTypeHelper STUDENTWORK = 15 HOMEWORKBANK = 16 SUBJECT = 17 + EXERCISEQUESTION = 18 end \ No newline at end of file diff --git a/app/views/exercise/_edit_head.html.erb b/app/views/exercise/_edit_head.html.erb index 6c8e165a0..487900208 100644 --- a/app/views/exercise/_edit_head.html.erb +++ b/app/views/exercise/_edit_head.html.erb @@ -1,41 +1,12 @@ -<%= form_for @exercise, :remote=>true do |f| %> -
-
- -
- -
- "/> - <%= calendar_for('exercise_end_time')%> -
-
测验时长:分钟
- -
- "/> - <%= calendar_for('exercise_publish_time')%> -
-
- - -
+<%= form_for(@exercise, :html => {:multipart => true, :id => "exercise_head_form"}, :remote => true) do |f| %> +
+
-<% end %> - \ No newline at end of file +
+ +
+

+ 保存 + 取消 +

+<% end %> \ No newline at end of file diff --git a/app/views/exercise/_edu_edit_form.html.erb b/app/views/exercise/_edu_edit_form.html.erb new file mode 100644 index 000000000..2b873d3a2 --- /dev/null +++ b/app/views/exercise/_edu_edit_form.html.erb @@ -0,0 +1,202 @@ +<% content_for :header_tags do %> + <%= import_ke(enable_at: false, prettify: false, init_activity: true) %> +<% end %> +
+
+ <%= render :partial => 'show_head', :locals => {:exercise => @exercise} %> +
+
+ <% if is_edit %> + <%= render :partial => 'edit_head', :locals => {:exercise => @exercise} %> + <% else %> + <%= render :partial => 'new_head', :locals => {:exercise => @exercise} %> + <% end %> +
+
+ +
+ +
+ +
+ <%= render :partial => "exercise/new_question" %> +
+ +
+ +
+ + + + + + + +
+

+ 单选题 3 题,共 15  + 多选题 5 题,共 25  + 填空题 10 题,共 25  + 简答题 10 题,共 25  +

+ + 合计 10 题,共 100  + +
+ + \ No newline at end of file diff --git a/app/views/exercise/_exercise_index_tab.html.erb b/app/views/exercise/_exercise_index_tab.html.erb new file mode 100644 index 000000000..a9ae2f47a --- /dev/null +++ b/app/views/exercise/_exercise_index_tab.html.erb @@ -0,0 +1,21 @@ +

+ edu-filter-cir-grey mr5 font-12 fl" data-remote="true">全部 + <% if @is_teacher %> + edu-filter-cir-grey mr5 font-12 fl" data-remote="true">未发布 + <% end %> + edu-filter-cir-grey mr5 font-12 fl" data-remote="true">提交中 + edu-filter-cir-grey mr5 font-12 fl" data-remote="true">已截止 + + +

+
+ <%= form_tag(exercise_index_path(:course_id => @course.id, :type => @type), :remote => true , :method => 'get', :id => 'exercise_search_form') do %> +
+
+ + +
+ +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/exercise/_exercises_list.html.erb b/app/views/exercise/_exercises_list.html.erb index 787ef20b7..56897c242 100644 --- a/app/views/exercise/_exercises_list.html.erb +++ b/app/views/exercise/_exercises_list.html.erb @@ -1,28 +1,66 @@ -
-

所有试卷 - (<%= @obj_count%>) -

- <% if @is_teacher%> - <%= link_to "新建试卷 ", new_exercise_path(:course_id => @course.id), :class => "newbtn" %> - <%= link_to "导入试卷", other_exercise_exercise_index_path(:course_id => @course.id), :remote=>true,:class => "newbtn"%> - <% end%> -
-
-
- <% if @exercises.count != 0 %> - <% @exercises.each_with_index do |exercise,index|%> - -
- <% end%> +<% if @exercises.count != 0 %> +
+ <% @exercises.each do |exercise| %> +
+
+ # <%= get_ex_index(exercise, @course, @is_teacher) + 1 %> + <%= link_to exercise.exercise_name, student_exercise_list_exercise_path(exercise), :class => "edu-class-inner-list fl color-grey3" %> + <% unless exercise.is_public %> + + <% end %> + <% ex_curr_status = exercise_curr_time exercise %> + <% if ex_curr_status[:status] != "" %> + <%= ex_curr_status[:status] %> + <% end %> +
+

+ 创建于<%=time_from_now exercise.created_at %> + 更新于<%=time_from_now exercise.updated_at %> + <%= exercise.exercise_users.where("commit_status = 1").count %>已答 + <%= exercise.course.student.count - exercise.exercise_users.where("commit_status = 1").count %>未答 + <% count = exercise.exercise_users.where("commit_status = 1 and subjective_score = -1").count %> + <%= count %>未评 + <%= ex_curr_status[:time] %> + <% if exercise.try(:exercise_status) == 0 && exercise.publish_time %> + 将于 <%= format_time(exercise.publish_time).to_s %> 发布 + <% end %> +

+
+
+ +
    + <% if @is_teacher %> + <% if exercise.exercise_status == 1 %> +
  • <%= link_to "编辑", edit_exercise_path(exercise) %>
  • + <% end %> +
  • <%= link_to "预览", exercise_path(exercise) %>
  • +
  • <%= link_to "设置", setting_exercise_path(exercise) %>
  • +
  • <%= link_to "导出成绩", student_exercise_list_exercise_path(exercise.id,:course_id => @course.id, :format => 'xls') %>
  • + <% unless exercise.is_public %> +
  • + 设为公开 +
  • + <% end %> + +
  • 删除
  • + <% else %> -
      - <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> -
    - -
    - <% else %> - <%= render :partial => "welcome/no_data" %> - <% end %> -
\ No newline at end of file + <% end %> + +
+
+ <% end %> +
+
+
+
    + <%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => true, :flag => true, :is_new => true %> +
+
+
+
+<% else %> +
+ <%= render :partial => "welcome/no_data" %> +
+<% end %> \ No newline at end of file diff --git a/app/views/exercise/_new_MC.html.erb b/app/views/exercise/_new_MC.html.erb index 1ff27f1fc..6a0f34b6c 100644 --- a/app/views/exercise/_new_MC.html.erb +++ b/app/views/exercise/_new_MC.html.erb @@ -1,65 +1,62 @@ -<%= form_for(ExerciseQuestion.new, - :html => { :multipart => true }, - :url=>create_exercise_question_exercise_path(exercise.id), - :remote=>true ) do |f| %> -
-
- <% score = exercise.exercise_questions.where("question_type=1").last.nil? ? "": exercise.exercise_questions.where("question_type=1").last.question_score %> - - 分 - 请点击选项 - 标准答案: -
-
-
- - - -
-
-
    -
    - -
  • - A - - -
  • -
    -
  • - B - - -
  • -
    -
  • - C - - -
  • -
    -
  • - D - - -
  • -
    -
  • - E -
    新建选项
    -
  • -
    -
    -
    -
-
- -
-
+<% if exercise.id %> + <%= form_for(ExerciseQuestion.new, + :html => {:multipart => true}, + :url => create_exercise_question_exercise_path(exercise.id), + :remote => true ) do |f| %> +
+
+

单选题

+ + +
+
  • + + +
  • + +
  • + + + +
  • +
  • + + + +
  • +
  • + + + +
  • +
  • + + +
  • +
  • + <% score = exercise.exercise_questions.where("question_type=1").last.nil? ? "": exercise.exercise_questions.where("question_type=1").last.question_score %> + + + +

    + 温馨提示:[单选题]属于客观题将由系统自动评分,请设置标准答案 + 保存 + 取消 +

    +
  • +
    +
    + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/exercise/create.js.erb b/app/views/exercise/create.js.erb index 65b8dd327..1ad55e671 100644 --- a/app/views/exercise/create.js.erb +++ b/app/views/exercise/create.js.erb @@ -1,4 +1,5 @@ -$("#polls_head_show").html("<%= escape_javascript(render :partial => 'show_head', :locals => {:exercise => @exercise}) %>"); -$("#polls_head_edit").html("<%= escape_javascript(render :partial => 'edit_head', :locals => {:exercise => @exercise}) %>"); -$("#polls_head_edit").hide(); -$("#polls_head_show").show(); \ No newline at end of file +$("#exercise_head_show").html("<%= escape_javascript(render :partial => 'show_head') %>"); +$("#exercise_head_edit").html("<%= escape_javascript(render :partial => 'edit_head') %>"); +$("#exercise_head_edit").hide(); +$("#exercise_head_show").show(); +$("#new_exercise_question").html("<%= escape_javascript(render :partial => 'exercise/new_question') %>"); \ No newline at end of file diff --git a/app/views/exercise/create_exercise_question.js.erb b/app/views/exercise/create_exercise_question.js.erb index 09878440c..188e3c8b9 100644 --- a/app/views/exercise/create_exercise_question.js.erb +++ b/app/views/exercise/create_exercise_question.js.erb @@ -6,10 +6,10 @@ <% else %> $("#new_exercise_question").html('<%= escape_javascript(render :partial => 'new_question', :locals => {:exercise => @exercise}) %>'); $("#new_poll_question").html(""); - $("#exercise_submit").html("<%= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise}) %>"); + //$("#exercise_submit").html("<%#= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise}) %>"); <%if @exercise_questions.question_type == 1%> - $("#mc_question_list>div").last().children().first().addClass("border_b"); - $("#mc_question_list").show().append("
    " + + //$("#mc_question_list>div").last().children().first().addClass("border_b"); + $("#exercise_question_list").append("
    " + "
    " + "<%= escape_javascript(render :partial => 'show_MC', :locals => {:exercise_question => @exercise_questions}) %>" + "
    " + diff --git a/app/views/exercise/destroy.js.erb b/app/views/exercise/destroy.js.erb deleted file mode 100644 index 82fbc95b3..000000000 --- a/app/views/exercise/destroy.js.erb +++ /dev/null @@ -1,2 +0,0 @@ -hideModal(); -$("#exercise").html("<%= escape_javascript(render :partial => 'exercises_list') %>"); \ No newline at end of file diff --git a/app/views/exercise/edit.html.erb b/app/views/exercise/edit.html.erb index 48d307c78..db0cef611 100644 --- a/app/views/exercise/edit.html.erb +++ b/app/views/exercise/edit.html.erb @@ -1,9 +1,14 @@ -<%= render :partial => 'exercise_form'%> - +<%#= render :partial => 'exercise_form'%> +
    +

    + + <%= link_to @course.name, course_path(@course) %> > <%= link_to "试卷列表", exercise_index_path(:course_id => @course.id) %> > <%= link_to @exercise.exercise_name, student_exercise_list_exercise_path(@exercise) %> > 编辑 +

    +
    +

    编辑试卷

    + <%= link_to "返回", student_exercise_list_exercise_path(@exercise), :class => "fr font-12 color-grey mr15 mt5" %> +
    + + <%= render :partial => "exercise/edu_edit_form", :locals => {:is_edit => true} %> +
    + diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb index 6baa14d2e..5816d35d8 100644 --- a/app/views/exercise/index.html.erb +++ b/app/views/exercise/index.html.erb @@ -1,8 +1,12 @@ <%= stylesheet_link_tag 'polls', :media => 'all' %> -
    -
    - <%= render :partial => 'exercises_list'%> -
    + +
    +
    +
    +

    试卷列表

    + <% if @is_teacher %> + + 新建 + + + <% end %> +
    +
    +
    + <%= render :partial => "exercise/exercise_index_tab" %> +
    +
    + <%= render :partial => "exercise/exercises_list" %> +
    +
    +
    \ No newline at end of file diff --git a/app/views/exercise/index.js.erb b/app/views/exercise/index.js.erb new file mode 100644 index 000000000..a64ce1d4a --- /dev/null +++ b/app/views/exercise/index.js.erb @@ -0,0 +1,4 @@ +<% unless params[:page] %> + $("#exercise_index_tab").html("<%= j(render :partial => 'exercise/exercise_index_tab') %>"); +<% end %> +$("#exercise_index_list").html("<%= j(render :partial => 'exercise/exercises_list') %>"); \ No newline at end of file diff --git a/app/views/exercise/new.html.erb b/app/views/exercise/new.html.erb index 3d983d64f..ec179510e 100644 --- a/app/views/exercise/new.html.erb +++ b/app/views/exercise/new.html.erb @@ -1 +1,13 @@ -<%= render :partial => 'exercise_form'%> +<%#= render :partial => 'exercise_form'%> +
    +

    + + <%= link_to @course.name, course_path(@course) %> > <%= link_to "试卷列表", exercise_index_path(:course_id => @course.id) %> > 新建 +

    +
    +

    新建试卷

    + <%= link_to "返回", exercise_index_path(:course_id => @course.id), :class => "fr font-12 color-grey mr15 mt5" %> +
    + + <%= render :partial => "exercise/edu_edit_form", :locals =>{:is_edit => false} %> +
    diff --git a/app/views/exercise/set_public.js.erb b/app/views/exercise/set_public.js.erb new file mode 100644 index 000000000..6881ffb9f --- /dev/null +++ b/app/views/exercise/set_public.js.erb @@ -0,0 +1,2 @@ +$("#set_exercise_public_<%= @exercise.id %>").remove(); +$("#exercise_public_icon_<%= @exercise.id %>").remove(); \ No newline at end of file diff --git a/app/views/exercise/setting.html.erb b/app/views/exercise/setting.html.erb new file mode 100644 index 000000000..fee23afc7 --- /dev/null +++ b/app/views/exercise/setting.html.erb @@ -0,0 +1,376 @@ + +
    +

    + + <%= link_to @course.name, course_path(@course) %> > <%= link_to "试卷列表", exercise_index_path(:course_id => @course.id) %> > #<%= get_ex_index(@exercise, @course, @is_teacher) + 1 %> +

    +
    +

    + + <%= @exercise.exercise_name %> +

    + <%= link_to "返回", student_exercise_list_exercise_path(@exercise), :class => "fr font-12 mr15 mt3 color-grey" %> +
    + +
    +<% edit_mode = @is_new && @is_teacher %> +
    + +
    +
    +
    +
    +

    发布设置

    + 编辑 +
    +
    +
    +
      +
    • + + + +
    • +
    • + + +
      +
    • + + + + + + + + + +
    +
    +
    +
    + +
    +
    +

    答题设置

    +
    +
    +
    +
      +
    • + + + + +
    • +
    • + + > + + (选中则学生答题时,题目顺序按照题型随机显示) +
      + > + + (选中则学生答题时,选项顺序随机显示) +
    • +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + +
    +
    +

    公开设置

    +
    +
    +
    +
      +
    • + + > + + (选中则在截止时间之后对班级学生公开所有成员的成绩,否则不公开) +
    • +
    • + + > + + (选中则在截止时间之后对班级学生公开试卷题目的答案,否则不公开) +
    • +
    +
    +
    +
    +
    + + +
    + <%= form_tag(ex_setting_exercise_path(@exercise), :method => "post", :id => 'exercise_setting_form') do |f| %> +
    +
    +

    发布设置

    +
    +
    +
    +
      +
    • + + 1 ? 'disabled' : '' %> class="fl task-form-15 task-height-40 panel-box-sizing <%= @exercise.try(:exercise_status) > 1 ? 'disabled-bg' : '' %>" placeholder="请选择发布时间"> + + +
    • +
    • + + class="fl task-form-15 task-height-40 panel-box-sizing <%= @exercise.try(:exercise_status) == 3 ? 'disabled-bg' : '' %>" placeholder="请选择截止时间"> + + + + 不能早于发布时间 +
    • + + + + + + + + + + +
    +
    +
    +
    + +
    +
    +

    答题设置

    +
    +
    +
    +
      +
    • + + value="<%= @exercise.time.to_i == -1 ? '' : @exercise.time %>" class="fl task-form-15 task-height-40 panel-box-sizing" placeholder="60"> + + +
    • +
    • + + class="magic-checkbox fl mt5 magic-checkbox_show" id="dt_3" type="checkbox" <%= @exercise.question_random == 1 ? 'checked' : '' %>> + + (选中则学生答题时,题目顺序按照题型随机显示) +
      + class="magic-checkbox fl mt5 magic-checkbox_show" id="dt_4" type="checkbox" <%= @exercise.choice_random == 1 ? 'checked' : '' %>> + + (选中则学生答题时,选项顺序随机显示) +
    • +
    + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + +
    +
    +

    公开设置

    +
    +
    +
    +
      +
    • + + > + + (选中则在截止时间之后对班级学生公开所有成员的成绩,否则不公开) +
    • +
    • + + > + + (选中则在截止时间之后对班级学生公开试卷题目的答案,否则不公开) +
    • +
    +
    +
    +
    + <% end %> +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + 保存 + 取消 +
    +
    +
    +
    \ No newline at end of file diff --git a/app/views/exercise/update.js.erb b/app/views/exercise/update.js.erb index 9724b2bd1..edfb7a7e6 100644 --- a/app/views/exercise/update.js.erb +++ b/app/views/exercise/update.js.erb @@ -1,5 +1,4 @@ -$("#polls_head_show").html("<%= escape_javascript(render :partial => 'show_head', :locals => {:exercise => @exercise}) %>"); -$("#polls_head_edit").html("<%= escape_javascript(render :partial => 'edit_head', :locals => {:exercise => @exercise}) %>"); -$("#polls_head_edit").hide(); -$("#polls_head_show").show(); -$("#exercise_submit").html("<%= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise}) %>"); \ No newline at end of file +$("#exercise_head_show").html("<%= escape_javascript(render :partial => 'show_head') %>"); +$("#exercise_head_edit").html("<%= escape_javascript(render :partial => 'edit_head') %>"); +$("#exercise_head_edit").hide(); +$("#exercise_head_show").show(); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 0e6481557..ea06c7764 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -531,6 +531,9 @@ RedmineApp::Application.routes.draw do post 'send_to_course' get 'get_student_uncomplete_question' post 'edit_question_score' + get 'setting' + post 'ex_setting' + get 'set_public' end collection do #生成路径为 /exercise/方法名 @@ -543,7 +546,18 @@ RedmineApp::Application.routes.draw do end end - resources :homework_common, :except => [:show]do + resources :exercise_question do + member do + + end + + collection do + + end + end + + + resources :homework_common, :except => [:show]do member do get 'start_anonymous_comment' get 'stop_anonymous_comment' diff --git a/db/migrate/20170927015114_add_new_column_to_exercises.rb b/db/migrate/20170927015114_add_new_column_to_exercises.rb new file mode 100644 index 000000000..f9f44bd9b --- /dev/null +++ b/db/migrate/20170927015114_add_new_column_to_exercises.rb @@ -0,0 +1,7 @@ +class AddNewColumnToExercises < ActiveRecord::Migration + def change + add_column :exercises, :is_public, :boolean, :default => false + add_column :exercises, :score_open, :boolean, :default => true + add_column :exercises, :answer_open, :boolean, :default => true + end +end diff --git a/public/javascripts/edu/course.js b/public/javascripts/edu/course.js index de7d7b773..aa271bbdf 100644 --- a/public/javascripts/edu/course.js +++ b/public/javascripts/edu/course.js @@ -562,3 +562,131 @@ function delete_students(type, id, group_id){ return; } } + +function show_ex_edit_setting(){ + $("#show_exercise_setting").hide(); + $("#edit_exercise_setting").show(); + $("#exam_setting_submit_block").show(); + $("input[name='exercise_publish_time']").datetimepicker({ + allowBlank:true, + lang:'ch', + format:'Y-m-d H:i', + validateOnBlur:false, + onSelectDate:function() { + if($.trim($("input[name='exercise_end_time']").val()) == ""){ + var date = new Date(Date.parse($("input[name='exercise_publish_time']").val().replace(/-/g, "/"))); + $("input[name='exercise_end_time']").val(formate_time(new Date(date.setDate(date.getDate()+14)))); + } +// if($.trim($("input[name='homework_archive_time']").val()) == ""){ +// var date = new Date(Date.parse($("input[name='homework_end_time']").val().replace(/-/g, "/"))); +// $("input[name='homework_archive_time']").val(formate_time(new Date(date.setMonth(date.getMonth()+1)))); +// } + }, + onSelectTime:function() { + if($.trim($("input[name='exercise_end_time']").val()) == ""){ + var date = new Date(Date.parse($("input[name='exercise_publish_time']").val().replace(/-/g, "/"))); + $("input[name='exercise_end_time']").val(formate_time(new Date(date.setDate(date.getDate()+14)))); + } +// if($.trim($("input[name='homework_archive_time']").val()) == ""){ +// var date = new Date(Date.parse($("input[name='homework_end_time']").val().replace(/-/g, "/"))); +// $("input[name='homework_archive_time']").val(formate_time(new Date(date.setMonth(date.getMonth()+1)))); +// } + } + }); + + $("input[name='exercise_end_time']").datetimepicker({ + allowBlank:true, + lang:'ch', + format:'Y-m-d H:i', + validateOnBlur:false, +// onSelectDate:function() { +// if($.trim($("input[name='homework_archive_time']").val()) == ""){ +// var date = new Date(Date.parse($("input[name='homework_end_time']").val().replace(/-/g, "/"))); +// $("input[name='homework_archive_time']").val(formate_time(new Date(date.setMonth(date.getMonth()+1)))); +// } +// }, +// onSelectTime:function() { +// if($.trim($("input[name='homework_archive_time']").val()) == ""){ +// var date = new Date(Date.parse($("input[name='homework_end_time']").val().replace(/-/g, "/"))); +// $("input[name='homework_archive_time']").val(formate_time(new Date(date.setMonth(date.getMonth()+1)))); +// } +// } + }); +} + +function ex_setting_form_submit(){ + var myDate = new Date(); + var result = true; + if($("input[name='exercise_publish_time']").prop("disabled")==false && $.trim($("input[name='exercise_publish_time']").val()) != ""){ + var publish_time = Date.parse($("input[name='exercise_publish_time']").val()); + if(publish_time < myDate){ + $("#exercise_publish_time_notice").html("发布时间应晚于当前时间").show(); + result = false; + } else{ + $("#exercise_publish_time_notice").hide(); + } + if($.trim($("input[name='exercise_end_time']").val()) == ""){ + $("#exercise_end_time_notice").html("截止时间不能为空").show(); + result = false; + } + } + if($("input[name='exercise_end_time']").prop("disabled")==false && $.trim($("input[name='exercise_end_time']").val()) != ""){ + if($.trim($("input[name='exercise_publish_time']").val()) == ""){ + $("#exercise_publish_time").val(formate_time(myDate)); + } + var publish_time = Date.parse($("input[name='exercise_publish_time']").val()); + var end_time = Date.parse($("input[name='exercise_end_time']").val()); + if(end_time <= publish_time){ + $("#exercise_end_time_notice").html("截止时间应晚于发布时间").show(); + result = false; + } else if(end_time <= myDate) { + $("#exercise_end_time_notice").html("截止时间应晚于当前时间").show(); + result = false; + } else{ + $("#exercise_end_time_notice").hide(); + } + } + if(result){ + $("#exercise_setting_form").submit(); + } +} + +//添加标题时确定按钮 +function add_poll_question(doc,quest_type) +{ + var title = $.trim($("#poll_questions_title").val()); + var score = $.trim($("#question_score").val()); + var standard_ans = $.trim($("#exercise_choice_" + quest_type).val()); + if(title.length == 0 || score.length == 0){ + notice_box("题目标题/分数不能为空"); + doc.one('click', function(){ + add_poll_question($(this),quest_type); + }); + }else if(!/^[1-9][0-9]*$/.test(score)) { + notice_box("分数必须是非零开头的数字"); + doc.one('click', function(){ + add_poll_question($(this),quest_type); + }); + }else if(quest_type !=3 && quest_type !=4 && standard_ans.length == 0) { + notice_box("标准答案不能为空"); + doc.one('click', function(){ + add_poll_question($(this),quest_type); + }); + }else{ + doc.parent().parent().parent().parent().submit(); + } +} + +function pollsSubmit(doc){ + var title = $.trim($("#exercise_name").val()); + if(title.length == 0){ + notice_box("试卷标题不能为空"); + } else { + doc.parent().parent().submit(); + } +} + +function pollsCancel(){ + $("#exercise_head_edit").hide(); + $("#exercise_head_show").show(); +} \ No newline at end of file