From 5a153637b7629e37f89b407279d92d1b09671b17 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 13 Nov 2015 11:43:44 +0800 Subject: [PATCH 01/83] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=BF=81=E7=A7=BB=E9=97=AE=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20151113025341_exercise.rb | 18 ++++++++++++++++++ db/migrate/20151113025459_exercise_question.rb | 14 ++++++++++++++ db/migrate/20151113025524_exercise_choices.rb | 14 ++++++++++++++ .../20151113025549_exercise_standard_answer.rb | 14 ++++++++++++++ db/migrate/20151113025721_exercise_answer.rb | 15 +++++++++++++++ db/migrate/20151113025751_user_exercise.rb | 14 ++++++++++++++ 6 files changed, 89 insertions(+) create mode 100644 db/migrate/20151113025341_exercise.rb create mode 100644 db/migrate/20151113025459_exercise_question.rb create mode 100644 db/migrate/20151113025524_exercise_choices.rb create mode 100644 db/migrate/20151113025549_exercise_standard_answer.rb create mode 100644 db/migrate/20151113025721_exercise_answer.rb create mode 100644 db/migrate/20151113025751_user_exercise.rb diff --git a/db/migrate/20151113025341_exercise.rb b/db/migrate/20151113025341_exercise.rb new file mode 100644 index 000000000..8fdcf0a9e --- /dev/null +++ b/db/migrate/20151113025341_exercise.rb @@ -0,0 +1,18 @@ +class Exercise < ActiveRecord::Migration + def up + create_table :exercise do |t| + t.string :exercise_name + t.text :exercise_description + t.integer :course_id + t.integer :exercise_status + t.integer :user_id + t.datetime :start_at + t.datetime :end_at + t.timestamps + end + end + + def down + drop_table :exercise + end +end diff --git a/db/migrate/20151113025459_exercise_question.rb b/db/migrate/20151113025459_exercise_question.rb new file mode 100644 index 000000000..3ab084f13 --- /dev/null +++ b/db/migrate/20151113025459_exercise_question.rb @@ -0,0 +1,14 @@ +class ExerciseQuestion < ActiveRecord::Migration + def up + create_table :exercise_question do |t| + t.string :question_title + t.integer :question_type + t.integer :exercise_id + t.timestamps + end + end + + def down + drop_table :exercise_question + end +end diff --git a/db/migrate/20151113025524_exercise_choices.rb b/db/migrate/20151113025524_exercise_choices.rb new file mode 100644 index 000000000..782cb5f7d --- /dev/null +++ b/db/migrate/20151113025524_exercise_choices.rb @@ -0,0 +1,14 @@ +class ExerciseChoices < ActiveRecord::Migration + def up + create_table :exercise_choices do |t| + t.integer :exercise_question_id + t.text :choice_text + t.integer :choice_position + t.timestamps + end + end + + def down + drop_table :exercise_choices + end +end diff --git a/db/migrate/20151113025549_exercise_standard_answer.rb b/db/migrate/20151113025549_exercise_standard_answer.rb new file mode 100644 index 000000000..17e59eaf8 --- /dev/null +++ b/db/migrate/20151113025549_exercise_standard_answer.rb @@ -0,0 +1,14 @@ +class ExerciseStandardAnswer < ActiveRecord::Migration + def up + create_table :exercise_standard_answer do |t| + t.integer :exercise_question_id + t.integer :exercise_choices_id + t.text :answer_text + t.timestamps + end + end + + def down + drop_table :exercise_standard_answer + end +end diff --git a/db/migrate/20151113025721_exercise_answer.rb b/db/migrate/20151113025721_exercise_answer.rb new file mode 100644 index 000000000..0a34c15ea --- /dev/null +++ b/db/migrate/20151113025721_exercise_answer.rb @@ -0,0 +1,15 @@ +class ExerciseAnswer < ActiveRecord::Migration + def up + create_table :exercise_answer do |t| + t.integer :user_id + t.integer :exercise_question_id + t.integer :exercise_choices_id + t.text :answer_text + t.timestamps + end + end + + def down + drop_table :exercise_answer + end +end diff --git a/db/migrate/20151113025751_user_exercise.rb b/db/migrate/20151113025751_user_exercise.rb new file mode 100644 index 000000000..b0a003d1d --- /dev/null +++ b/db/migrate/20151113025751_user_exercise.rb @@ -0,0 +1,14 @@ +class UserExercise < ActiveRecord::Migration + def up + create_table :user_exercise do |t| + t.integer :user_id + t.integer :exercise_id + t.integer :score + t.timestamps + end + end + + def down + drop_table :user_exercise + end +end From bbf087fa67452482f07bae27d4bf75ab0fcccdc2 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 13 Nov 2015 14:40:14 +0800 Subject: [PATCH 02/83] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=9A=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A5=E5=8F=8Amodel=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=E7=9A=84=E7=A1=AE=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 7 +++++++ app/models/exercise_answer.rb | 8 ++++++++ app/models/exercise_choices.rb | 7 +++++++ app/models/exercise_question.rb | 8 ++++++++ app/models/exercise_standard_answer.rb | 7 +++++++ app/models/exercise_user.rb | 6 ++++++ app/models/user.rb | 6 ++++++ db/migrate/20151113025341_exercise.rb | 3 +-- db/migrate/20151113025459_exercise_question.rb | 1 + db/migrate/20151113025751_user_exercise.rb | 5 +++-- 10 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 app/models/exercise.rb create mode 100644 app/models/exercise_answer.rb create mode 100644 app/models/exercise_choices.rb create mode 100644 app/models/exercise_question.rb create mode 100644 app/models/exercise_standard_answer.rb create mode 100644 app/models/exercise_user.rb diff --git a/app/models/exercise.rb b/app/models/exercise.rb new file mode 100644 index 000000000..752441947 --- /dev/null +++ b/app/models/exercise.rb @@ -0,0 +1,7 @@ +class Exercise < ActiveRecord::Base + include Redmine::SafeAttributes + belongs_to :user + has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number" + has_many :exercise_users, :dependent => :destroy + has_many :users, :through => :exercise_users #该文件被哪些用户提交答案过 +end diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb new file mode 100644 index 000000000..14b60982a --- /dev/null +++ b/app/models/exercise_answer.rb @@ -0,0 +1,8 @@ +class ExerciseAnswer < ActiveRecord::Base + #学生答题 + include Redmine::SafeAttributes + + belongs_to :user + belongs_to :exercise_question + belongs_to :exercise_choices +end diff --git a/app/models/exercise_choices.rb b/app/models/exercise_choices.rb new file mode 100644 index 000000000..8e67a8c0a --- /dev/null +++ b/app/models/exercise_choices.rb @@ -0,0 +1,7 @@ +class ExerciseChoices < ActiveRecord::Base + include Redmine::SafeAttributes + + belongs_to :exercise_question + has_many :exercise_answers, :dependent => :destroy + has_many :exercise_standard_answers, :dependent => :destroy +end diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb new file mode 100644 index 000000000..64ec53e4c --- /dev/null +++ b/app/models/exercise_question.rb @@ -0,0 +1,8 @@ +class ExerciseQuestion < ActiveRecord::Base + include Redmine::SafeAttributes + + belongs_to :exercise + has_many :exercise_choiceses, :order => "#{ExerciseChoices.table_name}.choice_position",:dependent => :destroy + has_many :exercise_answers, :dependent => :destroy + has_many :exercise_standard_answers, :dependent => :destroy +end diff --git a/app/models/exercise_standard_answer.rb b/app/models/exercise_standard_answer.rb new file mode 100644 index 000000000..2b67a83a2 --- /dev/null +++ b/app/models/exercise_standard_answer.rb @@ -0,0 +1,7 @@ +class ExerciseStandardAnswer < ActiveRecord::Base + #标准答案 + include Redmine::SafeAttributes + + belongs_to :exercise_question + belongs_to :exercise_choices +end diff --git a/app/models/exercise_user.rb b/app/models/exercise_user.rb new file mode 100644 index 000000000..2d5da5d95 --- /dev/null +++ b/app/models/exercise_user.rb @@ -0,0 +1,6 @@ +class ExerciseUser < ActiveRecord::Base + include Redmine::SafeAttributes + + belongs_to :user + belongs_to :exercise +end diff --git a/app/models/user.rb b/app/models/user.rb index edc29c015..9e470380d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -81,6 +81,12 @@ class User < Principal has_many :poll, :dependent => :destroy #用户创建的问卷 has_many :answers, :source => :poll, :through => :poll_users, :dependent => :destroy #用户已经完成问答的问卷 # end + #在线测验相关关系 + has_many :exercise_users, :dependent => :destroy #答卷中间表 + has_many :exercise_answers, :dependent => :destroy #针对每个题目学生的答案 + has_many :exercises, :dependent => :destroy #创建的试卷 + has_many :exercises_answers, :source => :exercises, :through => :exercise_users, :dependent => :destroy #用户已经完成问答的试卷 + #end #作业相关关系 has_many :homework_commons, :dependent => :destroy has_many :student_works, :dependent => :destroy diff --git a/db/migrate/20151113025341_exercise.rb b/db/migrate/20151113025341_exercise.rb index 8fdcf0a9e..696f8d953 100644 --- a/db/migrate/20151113025341_exercise.rb +++ b/db/migrate/20151113025341_exercise.rb @@ -6,8 +6,7 @@ class Exercise < ActiveRecord::Migration t.integer :course_id t.integer :exercise_status t.integer :user_id - t.datetime :start_at - t.datetime :end_at + t.integer :time t.timestamps end end diff --git a/db/migrate/20151113025459_exercise_question.rb b/db/migrate/20151113025459_exercise_question.rb index 3ab084f13..5e83504c5 100644 --- a/db/migrate/20151113025459_exercise_question.rb +++ b/db/migrate/20151113025459_exercise_question.rb @@ -3,6 +3,7 @@ class ExerciseQuestion < ActiveRecord::Migration create_table :exercise_question do |t| t.string :question_title t.integer :question_type + t.integer :question_number t.integer :exercise_id t.timestamps end diff --git a/db/migrate/20151113025751_user_exercise.rb b/db/migrate/20151113025751_user_exercise.rb index b0a003d1d..a49053146 100644 --- a/db/migrate/20151113025751_user_exercise.rb +++ b/db/migrate/20151113025751_user_exercise.rb @@ -1,14 +1,15 @@ class UserExercise < ActiveRecord::Migration def up - create_table :user_exercise do |t| + create_table :exercise_user do |t| t.integer :user_id t.integer :exercise_id t.integer :score + t.datetime :start_at t.timestamps end end def down - drop_table :user_exercise + drop_table :exercise_user end end From 466f3c4cc356afccfce09a055c450b132ac77e02 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 13 Nov 2015 15:47:39 +0800 Subject: [PATCH 03/83] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BB=A5=E5=8F=8A=E4=B8=80=E5=AF=B9=E4=B8=80=EF=BC=8C?= =?UTF-8?q?=E4=B8=80=E5=AF=B9=E5=A4=9A=EF=BC=8C=E5=A4=9A=E5=AF=B9=E5=A4=9A?= =?UTF-8?q?=E7=AD=89=E5=85=B3=E7=B3=BB=E7=9A=84=E7=A1=AE=E7=AB=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 2 +- app/models/exercise_answer.rb | 2 +- ...exercise_choices.rb => exercise_choice.rb} | 2 +- app/models/exercise_question.rb | 2 +- app/models/exercise_standard_answer.rb | 2 +- app/models/user.rb | 6 +- db/migrate/20151113025341_exercise.rb | 2 +- .../20151113025459_exercise_question.rb | 2 +- ...20151113025549_exercise_standard_answer.rb | 4 +- db/migrate/20151113025721_exercise_answer.rb | 4 +- db/migrate/20151113025751_user_exercise.rb | 2 +- db/schema.rb | 56 ++++++++++++++++++- 12 files changed, 70 insertions(+), 16 deletions(-) rename app/models/{exercise_choices.rb => exercise_choice.rb} (81%) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 752441947..cbf3a6e91 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,5 +3,5 @@ class Exercise < ActiveRecord::Base belongs_to :user has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number" has_many :exercise_users, :dependent => :destroy - has_many :users, :through => :exercise_users #该文件被哪些用户提交答案过 + has_many :users, :through => :exercise_users #该测试被哪些用户提交答案过 end diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 14b60982a..c62f5bcd5 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -4,5 +4,5 @@ class ExerciseAnswer < ActiveRecord::Base belongs_to :user belongs_to :exercise_question - belongs_to :exercise_choices + belongs_to :exercise_choice end diff --git a/app/models/exercise_choices.rb b/app/models/exercise_choice.rb similarity index 81% rename from app/models/exercise_choices.rb rename to app/models/exercise_choice.rb index 8e67a8c0a..00d611566 100644 --- a/app/models/exercise_choices.rb +++ b/app/models/exercise_choice.rb @@ -1,4 +1,4 @@ -class ExerciseChoices < ActiveRecord::Base +class ExerciseChoice < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :exercise_question diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 64ec53e4c..5189b0274 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -2,7 +2,7 @@ class ExerciseQuestion < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :exercise - has_many :exercise_choiceses, :order => "#{ExerciseChoices.table_name}.choice_position",:dependent => :destroy + has_many :exercise_choices, :order => "#{ExerciseChoice.table_name}.choice_position",:dependent => :destroy has_many :exercise_answers, :dependent => :destroy has_many :exercise_standard_answers, :dependent => :destroy end diff --git a/app/models/exercise_standard_answer.rb b/app/models/exercise_standard_answer.rb index 2b67a83a2..ce3d08fbf 100644 --- a/app/models/exercise_standard_answer.rb +++ b/app/models/exercise_standard_answer.rb @@ -3,5 +3,5 @@ class ExerciseStandardAnswer < ActiveRecord::Base include Redmine::SafeAttributes belongs_to :exercise_question - belongs_to :exercise_choices + belongs_to :exercise_choice end diff --git a/app/models/user.rb b/app/models/user.rb index 9e470380d..d79ae575a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -82,10 +82,10 @@ class User < Principal has_many :answers, :source => :poll, :through => :poll_users, :dependent => :destroy #用户已经完成问答的问卷 # end #在线测验相关关系 - has_many :exercise_users, :dependent => :destroy #答卷中间表 - has_many :exercise_answers, :dependent => :destroy #针对每个题目学生的答案 + has_many :exercise_user, :dependent => :destroy #答卷中间表 + has_many :exercise_answer, :dependent => :destroy #针对每个题目学生的答案 has_many :exercises, :dependent => :destroy #创建的试卷 - has_many :exercises_answers, :source => :exercises, :through => :exercise_users, :dependent => :destroy #用户已经完成问答的试卷 + has_many :exercises_answers, :source => :exercise, :through => :exercise_user, :dependent => :destroy #用户已经完成问答的试卷 #end #作业相关关系 has_many :homework_commons, :dependent => :destroy diff --git a/db/migrate/20151113025341_exercise.rb b/db/migrate/20151113025341_exercise.rb index 696f8d953..b29bfdb91 100644 --- a/db/migrate/20151113025341_exercise.rb +++ b/db/migrate/20151113025341_exercise.rb @@ -1,6 +1,6 @@ class Exercise < ActiveRecord::Migration def up - create_table :exercise do |t| + create_table :exercises do |t| t.string :exercise_name t.text :exercise_description t.integer :course_id diff --git a/db/migrate/20151113025459_exercise_question.rb b/db/migrate/20151113025459_exercise_question.rb index 5e83504c5..1dd0409f9 100644 --- a/db/migrate/20151113025459_exercise_question.rb +++ b/db/migrate/20151113025459_exercise_question.rb @@ -1,6 +1,6 @@ class ExerciseQuestion < ActiveRecord::Migration def up - create_table :exercise_question do |t| + create_table :exercise_questions do |t| t.string :question_title t.integer :question_type t.integer :question_number diff --git a/db/migrate/20151113025549_exercise_standard_answer.rb b/db/migrate/20151113025549_exercise_standard_answer.rb index 17e59eaf8..8ed1a25be 100644 --- a/db/migrate/20151113025549_exercise_standard_answer.rb +++ b/db/migrate/20151113025549_exercise_standard_answer.rb @@ -1,8 +1,8 @@ class ExerciseStandardAnswer < ActiveRecord::Migration def up - create_table :exercise_standard_answer do |t| + create_table :exercise_standard_answers do |t| t.integer :exercise_question_id - t.integer :exercise_choices_id + t.integer :exercise_choice_id t.text :answer_text t.timestamps end diff --git a/db/migrate/20151113025721_exercise_answer.rb b/db/migrate/20151113025721_exercise_answer.rb index 0a34c15ea..9cc9c5bc7 100644 --- a/db/migrate/20151113025721_exercise_answer.rb +++ b/db/migrate/20151113025721_exercise_answer.rb @@ -1,9 +1,9 @@ class ExerciseAnswer < ActiveRecord::Migration def up - create_table :exercise_answer do |t| + create_table :exercise_answers do |t| t.integer :user_id t.integer :exercise_question_id - t.integer :exercise_choices_id + t.integer :exercise_choice_id t.text :answer_text t.timestamps end diff --git a/db/migrate/20151113025751_user_exercise.rb b/db/migrate/20151113025751_user_exercise.rb index a49053146..d5e521401 100644 --- a/db/migrate/20151113025751_user_exercise.rb +++ b/db/migrate/20151113025751_user_exercise.rb @@ -1,6 +1,6 @@ class UserExercise < ActiveRecord::Migration def up - create_table :exercise_user do |t| + create_table :exercise_users do |t| t.integer :user_id t.integer :exercise_id t.integer :score diff --git a/db/schema.rb b/db/schema.rb index 419b30c3e..418382a64 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151112072948) do +ActiveRecord::Schema.define(:version => 20151113025751) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -572,6 +572,60 @@ ActiveRecord::Schema.define(:version => 20151112072948) do add_index "enumerations", ["id", "type"], :name => "index_enumerations_on_id_and_type" add_index "enumerations", ["project_id"], :name => "index_enumerations_on_project_id" + create_table "exercise_answers", :force => true do |t| + t.integer "user_id" + t.integer "exercise_question_id" + t.integer "exercise_choices_id" + t.text "answer_text" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "exercise_choices", :force => true do |t| + t.integer "exercise_question_id" + t.text "choice_text" + t.integer "choice_position" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "exercise_questions", :force => true do |t| + t.string "question_title" + t.integer "question_type" + t.integer "question_number" + t.integer "exercise_id" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "exercise_standard_answers", :force => true do |t| + t.integer "exercise_question_id" + t.integer "exercise_choices_id" + t.text "answer_text" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "exercise_users", :force => true do |t| + t.integer "user_id" + t.integer "exercise_id" + t.integer "score" + t.datetime "start_at" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + + create_table "exercises", :force => true do |t| + t.string "exercise_name" + t.text "exercise_description" + t.integer "course_id" + t.integer "exercise_status" + t.integer "user_id" + t.integer "time" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "first_pages", :force => true do |t| t.string "web_title" t.string "title" From 70c5b27a437df83d823f1442fa5e945b7cd2ff56 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 13 Nov 2015 16:40:39 +0800 Subject: [PATCH 04/83] =?UTF-8?q?=E7=9B=B8=E5=85=B3=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 39 +++++++++++++++++++++++++ app/helpers/exercise_helper.rb | 3 ++ app/models/course.rb | 1 + app/views/exercise/index.html.erb | 1 + app/views/exercise/new.html.erb | 0 app/views/exercise/show.html.erb | 1 + app/views/layouts/base_courses.html.erb | 5 ++++ config/routes.rb | 9 ++++++ 8 files changed, 59 insertions(+) create mode 100644 app/controllers/exercise_controller.rb create mode 100644 app/helpers/exercise_helper.rb create mode 100644 app/views/exercise/index.html.erb create mode 100644 app/views/exercise/new.html.erb create mode 100644 app/views/exercise/show.html.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb new file mode 100644 index 000000000..96a965f79 --- /dev/null +++ b/app/controllers/exercise_controller.rb @@ -0,0 +1,39 @@ +class ExerciseController < ApplicationController + layout "base_courses" + + before_filter :find_course, :only => [:index,:new,:create] + def index + + end + + def show + + end + + def new + + end + + def create + + end + + def edit + + end + + def update + + end + + def destroy + + end + + private + def find_course + @course = Course.find params[:course_id] + rescue Exception => e + render_404 + end +end \ No newline at end of file diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb new file mode 100644 index 000000000..7fc7b1421 --- /dev/null +++ b/app/helpers/exercise_helper.rb @@ -0,0 +1,3 @@ +# encoding: utf-8 +module ExerciseHelper +end \ No newline at end of file diff --git a/app/models/course.rb b/app/models/course.rb index 7288c3b3b..913449d22 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -39,6 +39,7 @@ class Course < ActiveRecord::Base has_many :course_activities # 课程消息 has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy + has_many :exercises, :dependent => :destroy acts_as_taggable acts_as_nested_set :order => 'name', :dependent => :destroy diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb new file mode 100644 index 000000000..52cfcc97f --- /dev/null +++ b/app/views/exercise/index.html.erb @@ -0,0 +1 @@ +111111111111 \ No newline at end of file diff --git a/app/views/exercise/new.html.erb b/app/views/exercise/new.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/exercise/show.html.erb b/app/views/exercise/show.html.erb new file mode 100644 index 000000000..b23c1c517 --- /dev/null +++ b/app/views/exercise/show.html.erb @@ -0,0 +1 @@ +111111 \ No newline at end of file diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index 39de4faeb..ac8727e21 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -157,6 +157,11 @@ <%= link_to "(#{course_poll_count})", poll_index_path(:polls_type => "Course", :polls_group_id => @course.id), :class => "subnav_num c_orange" %> <%= link_to( "+#{l(:label_new_poll)}", new_poll_path(:polls_type => "Course",:polls_group_id => @course.id), :class => 'subnav_green c_white') if is_teacher %> +
diff --git a/config/routes.rb b/config/routes.rb index 6cf872180..9c557c9a5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,6 +96,15 @@ RedmineApp::Application.routes.draw do end end + #show、index、new、create、edit、update、destroy路由自动生成 + resources :exercise do + member do #生成路径为 /exercise/:id/方法名 + end + + collection do #生成路径为 /exercise/方法名 + end + end + resources :homework_common, :except => [:show]do member do get 'start_anonymous_comment' From e6cd104ead1f32ae3d73cec883173328002bd205 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 13 Nov 2015 17:23:52 +0800 Subject: [PATCH 05/83] =?UTF-8?q?index=E7=95=8C=E9=9D=A2=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BB=9F=E8=AE=A1=E7=9B=B8=E5=85=B3=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 18 +++++- app/models/exercise.rb | 1 + app/views/exercise/_exercise.html.erb | 61 +++++++++++++++++++++ app/views/exercise/_exercises_list.html.erb | 25 +++++++++ app/views/exercise/index.html.erb | 5 +- config/routes.rb | 2 + 6 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 app/views/exercise/_exercise.html.erb create mode 100644 app/views/exercise/_exercises_list.html.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 96a965f79..bed3d9061 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -3,9 +3,18 @@ class ExerciseController < ApplicationController before_filter :find_course, :only => [:index,:new,:create] def index - + @is_teacher = User.current.allowed_to?(:as_teacher,@course) + if @is_teacher + exercises = @course.exercises + else + exercises = @course.exercises.where(:exercise_status => 1) + end + @exercises = paginateHelper exercises,20 #分页 + respond_to do |format| + format.html + end end - + def show end @@ -30,6 +39,11 @@ class ExerciseController < ApplicationController end + #统计结果 + def statistics_result + + end + private def find_course @course = Course.find params[:course_id] diff --git a/app/models/exercise.rb b/app/models/exercise.rb index cbf3a6e91..e4295971e 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -1,4 +1,5 @@ class Exercise < ActiveRecord::Base + #exercise_status: 1,新建;2,发布;3,关闭 include Redmine::SafeAttributes belongs_to :user has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number" diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb new file mode 100644 index 000000000..e469c471c --- /dev/null +++ b/app/views/exercise/_exercise.html.erb @@ -0,0 +1,61 @@ +<%# has_commit = has_commit_poll?(poll.id ,User.current)%> +<% exercise_name = exercise.exercise_name.empty? ? l(:label_poll_new) : exercise.exercise_name%> +<% if @is_teacher%> +
  • +
    + <%# if has_commit %> + <%#= link_to poll_name, poll_result_poll_path(poll.id), :class => "polls_title polls_title_w fl c_dblue"%> + <%# else %> + <%#= link_to poll_name, exercise_path(poll.id), :class => "polls_title polls_title_w fl c_dblue" %> + <%# end %> + <%= link_to exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_w fl c_dblue" %> +
    +
  • + + <% if exercise.exercise_status == 1%> +
  • 统计结果
  • + <% else %> +
  • <%= link_to l(:label_statistical_results), statistics_result_exercise_path(exercise.id), :class => "pollsbtn fl ml10"%>
  • + <% end%> + + <% if exercise.exercise_status == 1 %> +
  • 发布试卷
  • + <% elsif exercise.exercise_status == 2%> +
  • 取消发布
  • + <% else%> +
  • 发布试卷
  • + <% end%> + + <%= link_to(l(:button_delete), exercise,:method => :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml5 mr10") %> + + <% if exercise.exercise_status == 1 %> +
  • <%= link_to l(:button_edit), edit_exercise_path(exercise.id), :class => "polls_de fr ml5"%>
  • + <% else%> +
  • 编辑
  • + <% end%> + + <% if exercise.exercise_status == 2 %> +
  • 关闭
  • + <% else %> +
  • 关闭
  • + <% end%> + + <% if exercise.exercise_status == 1%> +
  • 导出
  • + <% elsif exercise.exercise_status == 2 || exercise.exercise_status == 3 %> +
  • <%= link_to "导出", export_exercise_exercise_path(exercise.id,:format => "xls"), :class => "polls_de fr ml5"%>
  • + <% end%> + + +
  • <%= format_date exercise.created_at.to_date%>
  • +<% else%> + <% if exercise.exercise_status == 2%> + <%# if has_commit%> + + <%#else%> + <%= link_to exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_st fl c_dblue"%> + <%#end%> + <% end%> +
  • <%= format_date exercise.created_at.to_date%>
  • +<% 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 new file mode 100644 index 000000000..16fa24b0e --- /dev/null +++ b/app/views/exercise/_exercises_list.html.erb @@ -0,0 +1,25 @@ +
    +

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

    + <% if @is_teacher%> + <%#= link_to "导入", other_poll_poll_index_path(:polls_group_id => @course.id), :remote=>true,:class => "newbtn"%> + <%= link_to "新建试卷 ", new_exercise_path(:course_id => @course.id), :class => "newbtn" %> + <% end%> +
    +
    +
    + + <% @exercises.each do |exercise|%> + +
    + <% end%> + + + +
    +
    \ No newline at end of file diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb index 52cfcc97f..1a8d15181 100644 --- a/app/views/exercise/index.html.erb +++ b/app/views/exercise/index.html.erb @@ -1 +1,4 @@ -111111111111 \ No newline at end of file +<%= stylesheet_link_tag 'polls', :media => 'all' %> +
    + <%= render :partial => 'exercises_list'%> +
    \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9c557c9a5..f1c41f65f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -99,6 +99,8 @@ RedmineApp::Application.routes.draw do #show、index、new、create、edit、update、destroy路由自动生成 resources :exercise do member do #生成路径为 /exercise/:id/方法名 + get 'statistics_result' + get 'export_exercise' end collection do #生成路径为 /exercise/方法名 From ee8d9d7b4ecef7c35dc6efb9270642c66177fc5a Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 13 Nov 2015 17:47:29 +0800 Subject: [PATCH 06/83] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/schema.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/schema.rb b/db/schema.rb index 418382a64..19bd05677 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -575,7 +575,7 @@ ActiveRecord::Schema.define(:version => 20151113025751) do create_table "exercise_answers", :force => true do |t| t.integer "user_id" t.integer "exercise_question_id" - t.integer "exercise_choices_id" + t.integer "exercise_choice_id" t.text "answer_text" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false @@ -600,7 +600,7 @@ ActiveRecord::Schema.define(:version => 20151113025751) do create_table "exercise_standard_answers", :force => true do |t| t.integer "exercise_question_id" - t.integer "exercise_choices_id" + t.integer "exercise_choice_id" t.text "answer_text" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false From 5400b907e6a491cea534d9e7575c6a29e423f3e9 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 17 Nov 2015 09:33:40 +0800 Subject: [PATCH 07/83] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E6=B5=8B=E9=AA=8C?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 19 ++- app/views/exercise/_exercise.html.erb | 2 +- app/views/exercise/_student_exercise.html.erb | 46 ++++++ .../exercise/student_exercise_list.html.erb | 138 ++++++++++++++++++ config/routes.rb | 1 + ...4_add_publish_time_end_time_to_exercise.rb | 6 + db/schema.rb | 4 +- 7 files changed, 213 insertions(+), 3 deletions(-) create mode 100644 app/views/exercise/_student_exercise.html.erb create mode 100644 app/views/exercise/student_exercise_list.html.erb create mode 100644 db/migrate/20151116065904_add_publish_time_end_time_to_exercise.rb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index bed3d9061..296c744b6 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1,7 +1,7 @@ class ExerciseController < ApplicationController layout "base_courses" - before_filter :find_course, :only => [:index,:new,:create] + before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list] def index @is_teacher = User.current.allowed_to?(:as_teacher,@course) if @is_teacher @@ -44,6 +44,23 @@ class ExerciseController < ApplicationController end + def student_exercise_list + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? + @exercise = Exercise.find params[:id] + @all_exercises = @course.exercises.order("created_at desc") + @exercise_count = @exercise.exercise_users.where('score is not NULL').count + if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && Time.parse(@exercise.end_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") <= Time.now.strftime("%Y-%m-%d-%H-%M-%S")) + @exercise_users_list = @exercise.exercise_users.where('score is not NULL') + elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && Time.parse(@exercise.end_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") > Time.now.strftime("%Y-%m-%d-%H-%M-%S") + @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id) + else + @exercise_users_list = [] + end + respond_to do |format| + format.html + end + end + private def find_course @course = Course.find params[:course_id] diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb index e469c471c..15a684a62 100644 --- a/app/views/exercise/_exercise.html.erb +++ b/app/views/exercise/_exercise.html.erb @@ -15,7 +15,7 @@ <% if exercise.exercise_status == 1%>
  • 统计结果
  • <% else %> -
  • <%= link_to l(:label_statistical_results), statistics_result_exercise_path(exercise.id), :class => "pollsbtn fl ml10"%>
  • +
  • <%= link_to l(:label_statistical_results), student_exercise_list_exercise_path(exercise.id,:course_id => @course.id), :class => "pollsbtn fl ml10"%>
  • <% end%> <% if exercise.exercise_status == 1 %> diff --git a/app/views/exercise/_student_exercise.html.erb b/app/views/exercise/_student_exercise.html.erb new file mode 100644 index 000000000..b133baa04 --- /dev/null +++ b/app/views/exercise/_student_exercise.html.erb @@ -0,0 +1,46 @@ +
    + + 测验 + + (<%= @exercise_count%>人已交) + + <% if !@is_teacher && @exercise_users_list.empty?%> + 您尚未提交 + <% elsif !@is_teacher && !@exercise_users_list.empty?%> + 您已提交 + <% end %> + + <%if @is_teacher || @exercise.exercise_status == 3%> +
    + + +
    + <%#= select_tag(:student_work_in_group,options_for_select(course_group_list(@course),@group), {:class => "classSplit"}) unless course_group_list(@course).empty? %> + <% end%> + +
    +
    + +
    + <%= render :partial => "evaluation_un_title"%> +
    +
    + +<% @stundet_works.each do |student_work|%> + <% if @is_evaluation%> + <%= render :partial => "evaluation_work", :locals => {:student_work => student_work}%> + <% else%> + <%= render :partial => "evaluation_un_work", :locals => {:student_work => student_work}%> + <% end%> +
    +
    + <% if student_work.user == User.current && !@is_evaluation %> + <% if @homework.homework_type == 2%> + <%=render :partial => 'programing_work_show', :locals=> {:work => student_work, :score =>student_work_score(student_work,User.current),:student_work_scores => student_work.student_works_scores.order("updated_at desc")} %> + <% else %> + <%=render :partial => 'show' , :locals=> {:work => student_work, :score =>student_work_score(student_work,User.current),:student_work_scores => student_work.student_works_scores.order("updated_at desc")} %> + <% end %> + <% end %> +
    +
    +<% end%> \ No newline at end of file diff --git a/app/views/exercise/student_exercise_list.html.erb b/app/views/exercise/student_exercise_list.html.erb new file mode 100644 index 000000000..8653836ca --- /dev/null +++ b/app/views/exercise/student_exercise_list.html.erb @@ -0,0 +1,138 @@ + + +
    +
    +
    + + +
    +
    + +
    +
    + + <% if @exercise.exercise_status == 1 %> + 未发布 + <% elsif @exercise.exercise_status == 2 %> + 已发布 + <% elsif @exercise.exercise_status == 3 %> + 已截止 + <% end%> + [ 隐藏测验信息 ] +
    +
    发布者:<%= @exercise.user.show_name %>
    +
    +
    <%= @exercise.exercise_description.html_safe %>
    +
    + + +
    +
    +
    截止时间:<%= format_time @exercise.end_time %>
    + <% if @exercise.exercise_status == 1 %> +
    发布时间:<%= format_time @exercise.publish_time %>
    + <% end %> + <% end_time = @exercise.end_time.to_time.to_i %> + <% if end_time > Time.now.to_i %> +
    提交剩余时间: <%= (end_time - Time.now.to_i) / (24*60*60) %> 天 + <%= ((end_time - Time.now.to_i) % (24*60*60)) / (60*60)%> 小时 + <%= (((end_time - Time.now.to_i) % (24*60*60)) % (60*60)) / 60%>
    + <% else %> +
    提交已截止
    + <% end %> +
    +
    +
    +
    + +
    +
    +
    + <%= render :partial => "exercise/student_exercise"%> +
    +
    +
    + +
    +
    +
    +
    \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3f1ca2ba0..f1073381f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -150,6 +150,7 @@ RedmineApp::Application.routes.draw do resources :exercise do member do #生成路径为 /exercise/:id/方法名 get 'statistics_result' + get 'student_exercise_list' get 'export_exercise' end diff --git a/db/migrate/20151116065904_add_publish_time_end_time_to_exercise.rb b/db/migrate/20151116065904_add_publish_time_end_time_to_exercise.rb new file mode 100644 index 000000000..90aec321f --- /dev/null +++ b/db/migrate/20151116065904_add_publish_time_end_time_to_exercise.rb @@ -0,0 +1,6 @@ +class AddPublishTimeEndTimeToExercise < ActiveRecord::Migration + def change + add_column :exercises, :publish_time, :timestamp + add_column :exercises, :end_time, :timestamp + end +end diff --git a/db/schema.rb b/db/schema.rb index 272db1944..3feb43adb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151113025751) do +ActiveRecord::Schema.define(:version => 20151116065904) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -624,6 +624,8 @@ ActiveRecord::Schema.define(:version => 20151113025751) do t.integer "time" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.datetime "publish_time" + t.datetime "end_time" end create_table "first_pages", :force => true do |t| From 0316bf698f10087a747988ba193b55a01399c7e6 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 17 Nov 2015 11:25:17 +0800 Subject: [PATCH 08/83] =?UTF-8?q?exercise=E6=96=B0=E5=A2=9E=E3=80=81update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 59 ++++++++++++++++++++++++-- app/helpers/exercise_helper.rb | 11 +++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 296c744b6..87854619c 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -16,11 +16,42 @@ class ExerciseController < ApplicationController end def show - + @exercise = Exercise.find params[:id] + if @exercise.exercise_status != 2 && (!User.current.allowed_to?(:as_teacher,@course) || User.current.admin?) + render_403 + return + end + # 问卷消息状态更新 + # REDO:问卷添加消息 + #已提交问卷的用户不能再访问该界面 + if has_commit_exercise?(@poll.id,User.current.id) && (!User.current.admin?) + redirect_to poll_index_url(:polls_type => "Course", :polls_group_id => @course.id) + else + @can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin? + @percent = get_percent(@poll,User.current) + poll_questions = @poll.poll_questions + @poll_questions = paginateHelper poll_questions,5 #分页 + respond_to do |format| + format.html {render :layout => 'base_courses'} + end + end + end end def new - + option = { + :exercise_name => "", + :exercise_description => "", + :course_id => @course.id, + :exercise_status => 1, + :user_id => User.current.id, + :start_at => "", + :end_at => "" + } + @exercise = Exercise.create option + if @exercise + redirect_to edit_exercise_url @exercise.id + end end def create @@ -32,11 +63,31 @@ class ExerciseController < ApplicationController end def update - + @exercise.exercise_name = params[:exercise_name] + @exercise.exercise_description = params[:exercise_name] + @exercise.start_at = params[:start_at] + @exercise.end_at = params[:end_at] + if @exercise.save + respond_to do |format| + format.js + end + else + render_404 + end end def destroy - + if @exercise && @exercise.destroy + if @is_teacher + polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}") + else + polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2") + end + @polls = paginateHelper polls,20 #分页 + respond_to do |format| + format.js + end + end end #统计结果 diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 7fc7b1421..844cff1c1 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -1,3 +1,14 @@ # encoding: utf-8 module ExerciseHelper + + #判断用户是否已经提交了问卷 + def has_commit_exercise?(poll_id,user_id) + pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id) + if pu.nil? + false + else + true + end + end + end \ No newline at end of file From 034a92bb7b45d4a3b23b6bf0724c966cfcdc4e32 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 17 Nov 2015 15:18:07 +0800 Subject: [PATCH 09/83] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E6=B5=8B=E9=AA=8C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 10 +- app/views/exercise/_edit_head.html.erb | 24 ++ app/views/exercise/_exercise_content.html.erb | 23 ++ app/views/exercise/_exercise_form.html.erb | 333 ++++++++++++++++++ app/views/exercise/_new_MC.html.erb | 38 ++ app/views/exercise/_new_MCQ.html.erb | 39 ++ app/views/exercise/_new_single.html.erb | 28 ++ app/views/exercise/_student_exercise.html.erb | 71 ++-- app/views/exercise/_student_table.html.erb | 22 ++ app/views/exercise/edit.html.erb | 1 + app/views/exercise/new.html.erb | 1 + public/stylesheets/courses.css | 15 + 12 files changed, 581 insertions(+), 24 deletions(-) create mode 100644 app/views/exercise/_edit_head.html.erb create mode 100644 app/views/exercise/_exercise_content.html.erb create mode 100644 app/views/exercise/_exercise_form.html.erb create mode 100644 app/views/exercise/_new_MC.html.erb create mode 100644 app/views/exercise/_new_MCQ.html.erb create mode 100644 app/views/exercise/_new_single.html.erb create mode 100644 app/views/exercise/_student_table.html.erb create mode 100644 app/views/exercise/edit.html.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 296c744b6..ce3412caa 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -20,7 +20,10 @@ class ExerciseController < ApplicationController end def new - + @exercise = Exercise.new + respond_to do |format| + format.html{render :layout => 'base_courses'} + end end def create @@ -28,7 +31,9 @@ class ExerciseController < ApplicationController end def edit - + respond_to do |format| + format.html{render :layout => 'base_courses'} + end end def update @@ -51,6 +56,7 @@ class ExerciseController < ApplicationController @exercise_count = @exercise.exercise_users.where('score is not NULL').count if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && Time.parse(@exercise.end_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") <= Time.now.strftime("%Y-%m-%d-%H-%M-%S")) @exercise_users_list = @exercise.exercise_users.where('score is not NULL') + @show_all = true; elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && Time.parse(@exercise.end_time.to_s).strftime("%Y-%m-%d-%H-%M-%S") > Time.now.strftime("%Y-%m-%d-%H-%M-%S") @exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id) else diff --git a/app/views/exercise/_edit_head.html.erb b/app/views/exercise/_edit_head.html.erb new file mode 100644 index 000000000..b315d343c --- /dev/null +++ b/app/views/exercise/_edit_head.html.erb @@ -0,0 +1,24 @@ +
    +
    + +
    + <%# if edit_mode %> + + <%# end %> +
    + + <%= calendar_for('homework_end_time')%> +
    + <%# if edit_mode %> + + <%# end %> +
    + + <%= calendar_for('homework_publish_time')%> +
    +
    考试时长:分钟
    +
    + + 保存 取消 +
    +
    \ No newline at end of file diff --git a/app/views/exercise/_exercise_content.html.erb b/app/views/exercise/_exercise_content.html.erb new file mode 100644 index 000000000..76bad6a83 --- /dev/null +++ b/app/views/exercise/_exercise_content.html.erb @@ -0,0 +1,23 @@ + +<% poll.exercise_questions.each do |poll_question|%> +
    + + +
    +<% end %> \ No newline at end of file diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb new file mode 100644 index 000000000..a062f1d80 --- /dev/null +++ b/app/views/exercise/_exercise_form.html.erb @@ -0,0 +1,333 @@ +<%= stylesheet_link_tag 'polls', :media => 'all' %> + +
    +
    + + +
    + <%= render :partial => 'edit_head', :locals => {:poll => @exercise}%> +
    + + +
    + <%= render :partial => 'exercise_content', :locals => {:poll => @exercise}%> +
    + + + +
    发布 +
    + + +
    +
    +
    + +
    +
    diff --git a/app/views/exercise/_new_MC.html.erb b/app/views/exercise/_new_MC.html.erb new file mode 100644 index 000000000..0ff662b3f --- /dev/null +++ b/app/views/exercise/_new_MC.html.erb @@ -0,0 +1,38 @@ +
    +
    + + + +
    +
    +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    +
    + +
    +
    \ No newline at end of file diff --git a/app/views/exercise/_new_MCQ.html.erb b/app/views/exercise/_new_MCQ.html.erb new file mode 100644 index 000000000..0ba2a0133 --- /dev/null +++ b/app/views/exercise/_new_MCQ.html.erb @@ -0,0 +1,39 @@ +
    +
    + + + +
    +
    +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    +
    + +
    +
    \ No newline at end of file diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb new file mode 100644 index 000000000..0082303b7 --- /dev/null +++ b/app/views/exercise/_new_single.html.erb @@ -0,0 +1,28 @@ +
    +
    + + + +
    +
    +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    • + + +
    • +
      +
    +
    + +
    +
    \ No newline at end of file diff --git a/app/views/exercise/_student_exercise.html.erb b/app/views/exercise/_student_exercise.html.erb index b133baa04..25bf3f7cd 100644 --- a/app/views/exercise/_student_exercise.html.erb +++ b/app/views/exercise/_student_exercise.html.erb @@ -10,37 +10,64 @@ 您已提交 <% end %> - <%if @is_teacher || @exercise.exercise_status == 3%> -
    - + <%#if @is_teacher || @exercise.exercise_status == 3%> + <%#= select_tag(:student_work_in_group,options_for_select(course_group_list(@course),@group), {:class => "classSplit"}) unless course_group_list(@course).empty? %> - <% end%> + <%# end%>
    - <%= render :partial => "evaluation_un_title"%> + <%= render :partial => "student_table"%>
    -<% @stundet_works.each do |student_work|%> - <% if @is_evaluation%> - <%= render :partial => "evaluation_work", :locals => {:student_work => student_work}%> - <% else%> - <%= render :partial => "evaluation_un_work", :locals => {:student_work => student_work}%> - <% end%> -
    -
    - <% if student_work.user == User.current && !@is_evaluation %> - <% if @homework.homework_type == 2%> - <%=render :partial => 'programing_work_show', :locals=> {:work => student_work, :score =>student_work_score(student_work,User.current),:student_work_scores => student_work.student_works_scores.order("updated_at desc")} %> - <% else %> - <%=render :partial => 'show' , :locals=> {:work => student_work, :score =>student_work_score(student_work,User.current),:student_work_scores => student_work.student_works_scores.order("updated_at desc")} %> - <% end %> - <% end %> -
    +<% @exercise_users_list.each do |exercise|%> + +
      +
    • +
        +
      • + <%= link_to(image_tag(url_to_avatar(exercise.user),:width =>"40",:height => "40"),user_activities_path(exercise.user)) %> +
      • +
        +
      • +
          +
        • + <%= exercise.user.show_name%> +
        • +
        • + <%= exercise.user.user_extensions.nil? ? "--" : exercise.user.user_extensions.student_id%> +
        • +
        • + -- +
        • +
        +
      • +
        +
      +
    • +
    • + <% if exercise.created_at%> + <%= Time.parse(format_time(exercise.created_at)).strftime("%m-%d %H:%M")%>  + <% end %> +
    • + +
    • + <%= exercise.score.nil? ? "--" : format("%.1f",exercise.score)%> +
    • + +
    +
    <% end%> \ No newline at end of file diff --git a/app/views/exercise/_student_table.html.erb b/app/views/exercise/_student_table.html.erb new file mode 100644 index 000000000..719667973 --- /dev/null +++ b/app/views/exercise/_student_table.html.erb @@ -0,0 +1,22 @@ +
      +
    • +    + 姓名 + 学号 + 班级 +
    • + +
    • + <%= link_to "时间",'',:class => "c_dark f14 fb fl ml50" ,:remote => true%> + <%# if @show_all && @order == "created_at"%> + <%#= link_to "", student_work_index_path(:homework => @homework.id,:order => "created_at", :sort => @score, :name => @name, :group => @group) ,:class => "#{@score == 'desc' ? 'st_up' : 'st_down'} mt10",:remote => true%> + <%# end%> +
    • + +
    • + <%= link_to "成绩",'',:class => "c_dark f14 fb fl ml10",:remote => true%> + <%# if @show_all && @order == "score"%> + <%#= link_to "", student_work_index_path(:homework => @homework.id,:order => "score", :sort => @score, :name => @name, :group => @group) ,:class => "#{@score == 'desc' ? 'st_up' : 'st_down'} mt10",:remote => true%> + <%# end%> +
    • +
    \ No newline at end of file diff --git a/app/views/exercise/edit.html.erb b/app/views/exercise/edit.html.erb new file mode 100644 index 000000000..0b20dc90e --- /dev/null +++ b/app/views/exercise/edit.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'exercise_form'%> \ No newline at end of file diff --git a/app/views/exercise/new.html.erb b/app/views/exercise/new.html.erb index e69de29bb..3d983d64f 100644 --- a/app/views/exercise/new.html.erb +++ b/app/views/exercise/new.html.erb @@ -0,0 +1 @@ +<%= render :partial => 'exercise_form'%> diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index 5469078a5..fdba7426a 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -83,6 +83,7 @@ a.hworkSearchIcon:hover {background:url(../images/nav_icon.png) -49px -1px no-re .width180{width: 180px;} .width525{width: 525px;} .width285{width: 285px;} +.width530{width: 530px;} .mr95{margin-right: 95px;} .mr140 {margin-right: 140px;} .ml100{margin-left: 100px;} @@ -1141,3 +1142,17 @@ input.sendSourceText { width: 50px; height: 25px; } + +/*20151117在线测验byTim*/ +.testContainer {width:698px; border:1px solid #cbcbcb;background:#eeeeee; padding:10px; margin-bottom:10px;} +.testTitle{ width:678px; height:40px; padding:0 10px; text-align:center; font-size:16px; font-weight:bold; background:#fff;border-style:solid; border:1px solid #CBCBCB;} +.testDes{ width:678px; height:120px; padding:10px; margin-bottom:10px; background:#fff; border-style:solid; border:1px solid #CBCBCB; resize:none;} +.btn_submit{ width:56px; height:24px; padding-top:4px;background:#269ac9; color:#fff; text-align:center; display:block; float:left; margin-right:10px;} +a:hover.btn_submit{background:#297fb8;} +.btn_cancel{width:54px; height:22px; padding-top:4px;background:#fff; color:#999; border:1px solid #999; text-align:center; display:block; float:left; } +a:hover.btn_cancel{ color:#666;} +.testQuestion{ width:708px; height: auto; border:1px solid #cbcbcb; padding:10px 0 0 10px; margin-bottom:10px;} +.mr118 {margin-right:118px !important;} +.questionContainer {width:698px; border:1px solid #cbcbcb;background:#eeeeee; padding:10px; margin-bottom:10px;} +.questionTitle{ width:644px; height:30px; border:1px solid #cbcbcb; padding-left:5px; background:#fff;} +.examTime {width:40px; border:1px solid #cbcbcb; outline:none; height:28px; text-align:center; padding-left:0px; } \ No newline at end of file From 23ca20692fe6a10358c05422dafaa53e02e5d1c3 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 17 Nov 2015 15:20:59 +0800 Subject: [PATCH 10/83] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 71 ++++++++++++++++++++++---- app/helpers/exercise_helper.rb | 4 +- db/schema.rb | 54 +------------------- 3 files changed, 65 insertions(+), 64 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 87854619c..e29ae8176 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -21,21 +21,18 @@ class ExerciseController < ApplicationController render_403 return end - # 问卷消息状态更新 - # REDO:问卷添加消息 #已提交问卷的用户不能再访问该界面 - if has_commit_exercise?(@poll.id,User.current.id) && (!User.current.admin?) - redirect_to poll_index_url(:polls_type => "Course", :polls_group_id => @course.id) + if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?) + redirect_to poll_index_url(:course_id=> @course.id) else - @can_edit_poll = (!has_commit_poll?(@poll.id,User.current.id)) || User.current.admin? - @percent = get_percent(@poll,User.current) + @can_edit_poll = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin? + @percent = get_percent(@exercise,User.current) poll_questions = @poll.poll_questions @poll_questions = paginateHelper poll_questions,5 #分页 respond_to do |format| format.html {render :layout => 'base_courses'} end end - end end def new @@ -45,8 +42,8 @@ class ExerciseController < ApplicationController :course_id => @course.id, :exercise_status => 1, :user_id => User.current.id, - :start_at => "", - :end_at => "" + :time => "", + :end_time => "" } @exercise = Exercise.create option if @exercise @@ -92,7 +89,63 @@ class ExerciseController < ApplicationController #统计结果 def statistics_result + @exercise = Exercise.find(params[:id]) + exercise_questions = @exercise.poll_questions + @exercise_questions = paginateHelper exercise_questions, 5 + respond_to do |format| + format.html{render :layout => 'base_courses'} + end + end + #添加题目 + #question_type 1:单选 2:多选 3:填空题 + def create_exercise_question + question_title = params[:exercise_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title] + option = { + :is_necessary => (params[:is_necessary]=="true" ? 1 : 0), + :question_title => question_title, + :question_type => params[:question_type] || 1, + :question_number => @poll.poll_questions.count + 1 + } + @poll_questions = @poll.poll_questions.new option + if params[:question_answer] + for i in 1..params[:question_answer].count + answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + question_option = { + :answer_position => i, + :answer_text => answer + } + @poll_questions.poll_answers.new question_option + end + end + # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 + if params[:quest_id] + @is_insert = true + @poll.poll_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1") + @poll_question_num = params[:quest_num].to_i + @poll_questions.question_number = params[:quest_num].to_i + 1 + end + if @poll_questions.save + respond_to do |format| + format.js + end + end + + end + + #发布问卷 + def publish_excercise + @exercise.exercise_status = 2 + @exercise.publish_time = Time.now + if @exercise.save + if params[:is_remote] + redirect_to poll_index_url(:course_id => @course.id) + else + respond_to do |format| + format.js + end + end + end end def student_exercise_list diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 844cff1c1..410a9936b 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -2,8 +2,8 @@ module ExerciseHelper #判断用户是否已经提交了问卷 - def has_commit_exercise?(poll_id,user_id) - pu = PollUser.find_by_poll_id_and_user_id(poll_id,user_id) + def has_commit_exercise?(exercise_id, user_id) + pu = PollUser.find_by_poll_id_and_user_id(excercise_id, user_id) if pu.nil? false else diff --git a/db/schema.rb b/db/schema.rb index 3feb43adb..25d561e86 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151116065904) do +ActiveRecord::Schema.define(:version => 20151116071721) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -241,58 +241,6 @@ ActiveRecord::Schema.define(:version => 20151116065904) do add_index "changesets_issues", ["changeset_id", "issue_id"], :name => "changesets_issues_ids", :unique => true - create_table "code_review_assignments", :force => true do |t| - t.integer "issue_id" - t.integer "change_id" - t.integer "attachment_id" - t.string "file_path" - t.string "rev" - t.string "rev_to" - t.string "action_type" - t.integer "changeset_id" - end - - create_table "code_review_project_settings", :force => true do |t| - t.integer "project_id" - t.integer "tracker_id" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "updated_by" - t.boolean "hide_code_review_tab", :default => false - t.integer "auto_relation", :default => 1 - t.integer "assignment_tracker_id" - t.text "auto_assign" - t.integer "lock_version", :default => 0, :null => false - t.boolean "tracker_in_review_dialog", :default => false - end - - create_table "code_review_user_settings", :force => true do |t| - t.integer "user_id", :default => 0, :null => false - t.integer "mail_notification", :default => 0, :null => false - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "code_reviews", :force => true do |t| - t.integer "project_id" - t.integer "change_id" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "line" - t.integer "updated_by_id" - t.integer "lock_version", :default => 0, :null => false - t.integer "status_changed_from" - t.integer "status_changed_to" - t.integer "issue_id" - t.string "action_type" - t.string "file_path" - t.string "rev" - t.string "rev_to" - t.integer "attachment_id" - t.integer "file_count", :default => 0, :null => false - t.boolean "diff_all" - end - create_table "comments", :force => true do |t| t.string "commented_type", :limit => 30, :default => "", :null => false t.integer "commented_id", :default => 0, :null => false From 4a0865ab76a55b9aa36da8109b9509a846ec14d8 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 17 Nov 2015 18:20:47 +0800 Subject: [PATCH 11/83] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=92=8C=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E9=A2=98=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 84 +++++++++++++++++++------- 1 file changed, 62 insertions(+), 22 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 3870fe9c5..2237a9cfe 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -21,7 +21,7 @@ class ExerciseController < ApplicationController render_403 return end - #已提交问卷的用户不能再访问该界面 + # 已提交问卷的用户不能再访问该界面 if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?) redirect_to poll_index_url(:course_id=> @course.id) else @@ -67,20 +67,10 @@ class ExerciseController < ApplicationController end def destroy - if @exercise && @exercise.destroy - if @is_teacher - polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id}") - else - polls = Poll.where("polls_type = 'Course' and polls_group_id = #{@course.id} and polls_status = 2") - end - @polls = paginateHelper polls,20 #分页 - respond_to do |format| - format.js - end - end + end - #统计结果 + # 统计结果 def statistics_result @exercise = Exercise.find(params[:id]) exercise_questions = @exercise.poll_questions @@ -90,17 +80,16 @@ class ExerciseController < ApplicationController end end - #添加题目 - #question_type 1:单选 2:多选 3:填空题 + # 添加题目 + # question_type 1:单选 2:多选 3:填空题 def create_exercise_question question_title = params[:exercise_questions_title].nil? || params[:poll_questions_title].empty? ? l(:label_enter_single_title) : params[:poll_questions_title] option = { - :is_necessary => (params[:is_necessary]=="true" ? 1 : 0), :question_title => question_title, :question_type => params[:question_type] || 1, - :question_number => @poll.poll_questions.count + 1 + :question_number => @exercise.exercise_questions.count + 1 } - @poll_questions = @poll.poll_questions.new option + @exercise_questions = @exercise.exercise_questions.new option if params[:question_answer] for i in 1..params[:question_answer].count answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] @@ -108,15 +97,15 @@ class ExerciseController < ApplicationController :answer_position => i, :answer_text => answer } - @poll_questions.poll_answers.new question_option + @exercise_questions.poll_answers.new question_option end end # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 if params[:quest_id] @is_insert = true - @poll.poll_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1") - @poll_question_num = params[:quest_num].to_i - @poll_questions.question_number = params[:quest_num].to_i + 1 + @exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1") + # @exercise_question_num = params[:quest_num].to_i + @exercise_questions.question_number = params[:quest_num].to_i + 1 end if @poll_questions.save respond_to do |format| @@ -126,6 +115,57 @@ class ExerciseController < ApplicationController end + # 修改题目 + # params[:exercise_question] The id of exercise_question + # params[:question_answer] eg:A、B、C选项 + def update_exercise_question + @exercise_question = ExerciseQuestion.find params[:exercise_question] + @exercise_questions.question_title = params[:exercise_questions_title].nil? || params[:exercise_questions_title].empty? ? l(:label_enter_single_title) : params[:exercise_questions_title] + ################处理选项 + if params[:question_answer] + @exercise_question.exercise_answers.each do |answer| + answer.destroy unless params[:question_answer].keys.include? answer.id.to_s + end + # 界面需要判断选择题至少有一个选项 + for i in 1..params[:question_answer].count + question = @exercise_question.exercise_answers.find_by_id params[:question_answer].keys[i-1] + answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + if question + question.exercise_choices_id = i + question.answer_text = answer + question.save + else + question_option = { + :exercise_choices_id => i, + :answer_text => answer + } + @exercise_question.exercise_answers.new question_option + end + end + end + @exercise_question.save + respond_to do |format| + format.js + end + end + + # 删除题目 + def delete_exercise_question + @exercise_question = ExerciseQuestion.find params[:exercise_question] + @exercise = @exercise_question.exercise + exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}") + poll_questions.each do |question| + question.question_number -= 1 + question.save + end + if @poll_question && @poll_question.destroy + respond_to do |format| + format.js + end + end + end + + #发布问卷 def publish_excercise @exercise.exercise_status = 2 From cc08e5e32e47bb8118c07deccd299454945f7441 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 17 Nov 2015 18:22:31 +0800 Subject: [PATCH 12/83] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=B5=8B=E9=AA=8C?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 22 ++++++- app/views/exercise/_edit_head.html.erb | 62 ++++++++++++------- app/views/exercise/_exercise_content.html.erb | 2 +- app/views/exercise/_exercise_form.html.erb | 31 +++++++--- app/views/exercise/_new_single.html.erb | 8 +-- app/views/exercise/_show_head.html.erb | 6 ++ app/views/exercise/create.js.erb | 4 ++ app/views/exercise/edit.html.erb | 3 +- public/stylesheets/courses.css | 3 +- 9 files changed, 101 insertions(+), 40 deletions(-) create mode 100644 app/views/exercise/_show_head.html.erb create mode 100644 app/views/exercise/create.js.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index ce3412caa..6f275530e 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1,7 +1,7 @@ class ExerciseController < ApplicationController layout "base_courses" - before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list] + before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list,:edit] def index @is_teacher = User.current.allowed_to?(:as_teacher,@course) if @is_teacher @@ -27,10 +27,28 @@ class ExerciseController < ApplicationController end def create - + if params[:exercise] + exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id] + exercise ||= Exercise.new + exercise.exercise_name = params[:exercise][:exercise_name] + exercise.exercise_description = params[:exercise][:exercise_description] + exercise.end_time = params[:exercise][:end_time] + 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 + @exercise = exercise + respond_to do |format| + format.js + end + end + end end def edit + @exercise = Exercise.find params[:id] respond_to do |format| format.html{render :layout => 'base_courses'} end diff --git a/app/views/exercise/_edit_head.html.erb b/app/views/exercise/_edit_head.html.erb index b315d343c..a66d9dbb2 100644 --- a/app/views/exercise/_edit_head.html.erb +++ b/app/views/exercise/_edit_head.html.erb @@ -1,24 +1,38 @@ -
    -
    - -
    - <%# if edit_mode %> - - <%# end %> -
    - - <%= calendar_for('homework_end_time')%> -
    - <%# if edit_mode %> - - <%# end %> -
    - - <%= calendar_for('homework_publish_time')%> -
    -
    考试时长:分钟
    -
    - - 保存 取消 -
    -
    \ No newline at end of file +<%= form_for(@exercise, + :html => { :multipart => true }, + :url => {:controller => 'exercise', + :action => 'create', + :course_id => @course.id + },:remote=>true ) do |f| %> +
    +
    + +
    + <%# if edit_mode %> + + <%# end %> +
    + + <%= calendar_for('exercise_publish_time')%> +
    + <%# if edit_mode %> + + <%# end %> +
    + + <%= calendar_for('exercise_end_time')%> +
    +
    考试时长:分钟
    +
    + + +
    +
    +<% end %> \ No newline at end of file diff --git a/app/views/exercise/_exercise_content.html.erb b/app/views/exercise/_exercise_content.html.erb index 76bad6a83..bffd7e221 100644 --- a/app/views/exercise/_exercise_content.html.erb +++ b/app/views/exercise/_exercise_content.html.erb @@ -1,5 +1,5 @@ -<% poll.exercise_questions.each do |poll_question|%> +<% exercise.exercise_questions.each do |poll_question|%>
    - <%= render :partial => 'edit_head', :locals => {:poll => @exercise}%> + <%= render :partial => 'edit_head', :locals => {:exercise => @exercise}%>
    - <%= render :partial => 'exercise_content', :locals => {:poll => @exercise}%> + <%= render :partial => 'exercise_content', :locals => {:exercise => @exercise}%>
    @@ -321,7 +334,11 @@
    -
    发布 + +
    +
    + +
    提交
    diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index 0082303b7..8ef1e1e04 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -2,23 +2,23 @@
    - +
    • - +
    • - +
    • - +
    diff --git a/app/views/exercise/_show_head.html.erb b/app/views/exercise/_show_head.html.erb new file mode 100644 index 000000000..f7d2b9295 --- /dev/null +++ b/app/views/exercise/_show_head.html.erb @@ -0,0 +1,6 @@ +
    + +

    <%= exercise.exercise_name%>

    + <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%> +
    +
    \ No newline at end of file diff --git a/app/views/exercise/create.js.erb b/app/views/exercise/create.js.erb new file mode 100644 index 000000000..65b8dd327 --- /dev/null +++ b/app/views/exercise/create.js.erb @@ -0,0 +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(); \ No newline at end of file diff --git a/app/views/exercise/edit.html.erb b/app/views/exercise/edit.html.erb index 0b20dc90e..aef506ad8 100644 --- a/app/views/exercise/edit.html.erb +++ b/app/views/exercise/edit.html.erb @@ -1 +1,2 @@ -<%= render :partial => 'exercise_form'%> \ No newline at end of file +<%#= render :partial => 'exercise_form'%> +111 \ No newline at end of file diff --git a/public/stylesheets/courses.css b/public/stylesheets/courses.css index fdba7426a..da393afaa 100644 --- a/public/stylesheets/courses.css +++ b/public/stylesheets/courses.css @@ -713,6 +713,7 @@ img.ui-datepicker-trigger { width:16px; height:15px; float:left; + margin: 7px; } .label{ width:80px; text-align:right; font-size:14px; display:block; float:left;} @@ -1146,7 +1147,7 @@ input.sendSourceText { /*20151117在线测验byTim*/ .testContainer {width:698px; border:1px solid #cbcbcb;background:#eeeeee; padding:10px; margin-bottom:10px;} .testTitle{ width:678px; height:40px; padding:0 10px; text-align:center; font-size:16px; font-weight:bold; background:#fff;border-style:solid; border:1px solid #CBCBCB;} -.testDes{ width:678px; height:120px; padding:10px; margin-bottom:10px; background:#fff; border-style:solid; border:1px solid #CBCBCB; resize:none;} +.testDes{ width:678px; height:60px; padding:10px; margin-bottom:10px; background:#fff; border-style:solid; border:1px solid #CBCBCB; resize:none;} .btn_submit{ width:56px; height:24px; padding-top:4px;background:#269ac9; color:#fff; text-align:center; display:block; float:left; margin-right:10px;} a:hover.btn_submit{background:#297fb8;} .btn_cancel{width:54px; height:22px; padding-top:4px;background:#fff; color:#999; border:1px solid #999; text-align:center; display:block; float:left; } From f68ffc99ec9e8fa51a43c62a491dd4c9d65095a1 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 17 Nov 2015 18:26:39 +0800 Subject: [PATCH 13/83] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=8D=95=E9=80=89?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_new_MC.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/exercise/_new_MC.html.erb b/app/views/exercise/_new_MC.html.erb index 0ff662b3f..db61316fe 100644 --- a/app/views/exercise/_new_MC.html.erb +++ b/app/views/exercise/_new_MC.html.erb @@ -1,3 +1,4 @@ +<%= form_for ExerciseQuestion.new,:url =>create_exercise_question_exercise_path(@exercise.id),:remote => true do |f|%>
    @@ -35,4 +36,5 @@
    -
    \ No newline at end of file +
    +<% end %> \ No newline at end of file From b635fdaeb775b8f7aaa5fb719c72c0b8d50ecde0 Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 17 Nov 2015 18:33:42 +0800 Subject: [PATCH 14/83] =?UTF-8?q?=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index 1a66d2424..b1e4725e6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -152,6 +152,7 @@ RedmineApp::Application.routes.draw do get 'statistics_result' get 'student_exercise_list' get 'export_exercise' + post 'create_exercise_question' end collection do #生成路径为 /exercise/方法名 From 99f4483a161f2600d04081e50dec105e51f4c21a Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 17 Nov 2015 18:34:01 +0800 Subject: [PATCH 15/83] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=97=AE=E5=8D=B7?= =?UTF-8?q?=EF=BC=88=E6=9C=AA=E5=AE=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 2237a9cfe..46173c499 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -158,7 +158,7 @@ class ExerciseController < ApplicationController question.question_number -= 1 question.save end - if @poll_question && @poll_question.destroy + if @exercise_question && @exercise_question.destroy respond_to do |format| format.js end From 3cdda2a60a02ce2c9668ff94b8a6a0f5cb9801d1 Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 17 Nov 2015 19:29:25 +0800 Subject: [PATCH 16/83] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 33 ++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index f58abc53f..8fa5e0230 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1,7 +1,9 @@ class ExerciseController < ApplicationController layout "base_courses" + before_filter :find_exercise_and_course, :only => [:create_exercise_question] before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list,:edit] + def index @is_teacher = User.current.allowed_to?(:as_teacher,@course) if @is_teacher @@ -36,9 +38,19 @@ class ExerciseController < ApplicationController end def new - @exercise = Exercise.new - respond_to do |format| - format.html{render :layout => 'base_courses'} + option = { + :exercise_name => "", + :course_id => @course.id, + :exercise_status => 1, + :user_id => User.current.id, + :time => Time.now, + :end_time => Time.now, + :publish_time => Time.now, + :polls_description => "" + } + @exercise = Exercise.create option + if @exercise + redirect_to edit_exercise_url @exercise.id end end @@ -71,10 +83,10 @@ class ExerciseController < ApplicationController end def update - @exercise.exercise_name = params[:exercise_name] - @exercise.exercise_description = params[:exercise_name] - @exercise.start_at = params[:start_at] - @exercise.end_at = params[:end_at] + @exercise.exercise_name = params[:exercise][:exercise_name] + @exercise.exercise_description = params[:exercise][:exercise_description] + @exercise.time = params[:exercise][:time] + @exercise.end_time = params[:exercise][:end_time] if @exercise.save respond_to do |format| format.js @@ -218,6 +230,13 @@ class ExerciseController < ApplicationController end private + def find_exercise_and_course + @exercise = Exercise.find params[:id] + @course = Course.find @exercise.course_id + rescue Exception => e + render_404 + end + def find_course @course = Course.find params[:course_id] rescue Exception => e From 631418a01242b80adc4f3b81e951d2af6c412a6b Mon Sep 17 00:00:00 2001 From: cxt Date: Tue, 17 Nov 2015 19:33:14 +0800 Subject: [PATCH 17/83] =?UTF-8?q?=E5=8D=95=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_edit_head.html.erb | 2 +- app/views/exercise/_new_MC.html.erb | 39 ++++++++++++++++++-------- app/views/exercise/_new_MCQ.html.erb | 4 +-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/app/views/exercise/_edit_head.html.erb b/app/views/exercise/_edit_head.html.erb index a66d9dbb2..14a67bd29 100644 --- a/app/views/exercise/_edit_head.html.erb +++ b/app/views/exercise/_edit_head.html.erb @@ -1,7 +1,7 @@ <%= form_for(@exercise, :html => { :multipart => true }, :url => {:controller => 'exercise', - :action => 'create', + :action => 'update', :course_id => @course.id },:remote=>true ) do |f| %>
    diff --git a/app/views/exercise/_new_MC.html.erb b/app/views/exercise/_new_MC.html.erb index db61316fe..87cd22d81 100644 --- a/app/views/exercise/_new_MC.html.erb +++ b/app/views/exercise/_new_MC.html.erb @@ -1,31 +1,45 @@ -<%= form_for ExerciseQuestion.new,:url =>create_exercise_question_exercise_path(@exercise.id),:remote => true do |f|%> +<%#= form_for ExerciseQuestion.new,:url =>create_exercise_question_exercise_path(@exercise.id),:remote => true do |f|%> +<%= form_for(ExerciseQuestion.new, + :html => { :multipart => true }, + :url => {:controller => 'exercise', + :action => 'create_exercise_question', + :course_id => @course.id + },:remote=>true ) do |f| %>
    - +
    • - -
    • + + + +
    • - -
    • + + + +
    • - -
    • + + + +
    • - -
    • + + + +
    • @@ -34,7 +48,10 @@
    - +
    <% end %> \ No newline at end of file diff --git a/app/views/exercise/_new_MCQ.html.erb b/app/views/exercise/_new_MCQ.html.erb index 0ba2a0133..cabd9bf57 100644 --- a/app/views/exercise/_new_MCQ.html.erb +++ b/app/views/exercise/_new_MCQ.html.erb @@ -1,8 +1,8 @@
    - - + +
    - <%#= link_to("", delete_poll_question_poll_index_path(:poll_question => poll_question.id), + <%= link_to("", delete_exercise_question_exercise_index_path(:exercise_question => exercise_question.id), method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> @@ -32,9 +32,7 @@ diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index e69de29bb..07ecce94d 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -0,0 +1,25 @@ +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %> +
    + <%= link_to("", delete_exercise_question_exercise_index_path(:exercise_question => exercise_question.id), + method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> + + +
    +
    + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + 候选答案:<%= exercise_choice.choice_text%>
    + <% end %> +
    +
    + +
    +
    + \ No newline at end of file diff --git a/app/views/exercise/delete_exercise_question.js.erb b/app/views/exercise/delete_exercise_question.js.erb new file mode 100644 index 000000000..eb6300eb5 --- /dev/null +++ b/app/views/exercise/delete_exercise_question.js.erb @@ -0,0 +1 @@ +$("#poll_content").html("<%= escape_javascript(render :partial => 'exercise_content', :locals => {:exercise => @exercise}) %>"); \ No newline at end of file diff --git a/app/views/exercise/update_exercise_question.js.erb b/app/views/exercise/update_exercise_question.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/config/routes.rb b/config/routes.rb index b1e4725e6..8dba79d2c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -156,6 +156,7 @@ RedmineApp::Application.routes.draw do end collection do #生成路径为 /exercise/方法名 + delete 'delete_exercise_question' end end From ac95e1584ccbac1cfb5ea645d91f6a0c14044fbe Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 18 Nov 2015 17:23:57 +0800 Subject: [PATCH 34/83] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 14 ++++++++++++-- app/views/exercise/destroy.js.erb | 1 + app/views/exercise/index.html.erb | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 app/views/exercise/destroy.js.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 2bc8612a4..89a5c195e 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1,7 +1,7 @@ class ExerciseController < ApplicationController layout "base_courses" - before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show] + before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy] before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list] include ExerciseHelper @@ -102,7 +102,17 @@ class ExerciseController < ApplicationController end def destroy - + 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 + end end # 统计结果 diff --git a/app/views/exercise/destroy.js.erb b/app/views/exercise/destroy.js.erb new file mode 100644 index 000000000..c17b5a0f6 --- /dev/null +++ b/app/views/exercise/destroy.js.erb @@ -0,0 +1 @@ +$("#exercise").html("<%= escape_javascript(render :partial => 'exercises_list') %>"); \ No newline at end of file diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb index 1a8d15181..bbe4dd707 100644 --- a/app/views/exercise/index.html.erb +++ b/app/views/exercise/index.html.erb @@ -1,4 +1,4 @@ <%= stylesheet_link_tag 'polls', :media => 'all' %> -
    +
    <%= render :partial => 'exercises_list'%>
    \ No newline at end of file From 3d3d50f1eaa64bcf57ffe6173ed423da48fbba9b Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 18 Nov 2015 17:56:01 +0800 Subject: [PATCH 35/83] =?UTF-8?q?=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 4 +- app/views/exercise/_edit_MC.html.erb | 63 +++++++++++++++++++++++++ app/views/exercise/_new_single.html.erb | 6 +-- config/routes.rb | 1 + 4 files changed, 69 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 2bc8612a4..ebd3d9d2b 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -166,7 +166,7 @@ class ExerciseController < ApplicationController # params[:question_answer] eg:A、B、C选项 def update_exercise_question @exercise_question = ExerciseQuestion.find params[:exercise_question] - @exercise_questions.question_title = params[:exercise_questions_title].nil? || params[:exercise_questions_title].empty? ? l(:label_enter_single_title) : params[:exercise_questions_title] + @exercise_question.question_title = params[:exercise_questions_title].nil? || params[:exercise_questions_title].empty? ? l(:label_enter_single_title) : params[:exercise_questions_title] ################处理选项 if params[:question_answer] @exercise_question.exercise_answers.each do |answer| @@ -182,7 +182,7 @@ class ExerciseController < ApplicationController question.save else question_option = { - :exercise_choices_id => i, + :exercise_choice_id => i, :answer_text => answer } @exercise_question.exercise_answers.new question_option diff --git a/app/views/exercise/_edit_MC.html.erb b/app/views/exercise/_edit_MC.html.erb index e69de29bb..5a406537b 100644 --- a/app/views/exercise/_edit_MC.html.erb +++ b/app/views/exercise/_edit_MC.html.erb @@ -0,0 +1,63 @@ +<%= form_for("",:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%> + + + +
    +
    + + + +
    +
    +
      +
    • + + 分 +
    • +
      +
      + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> +
    • + + + + +
    • +
      + <% end %> +
      +
    • + + +
    • +
      +
    +
    + +
    +
    + +<% end%> \ No newline at end of file diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index e4e1db695..4d9baf729 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -19,17 +19,17 @@
  • - +
  • - +
  • - +
  • diff --git a/config/routes.rb b/config/routes.rb index 8dba79d2c..422f470d5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -157,6 +157,7 @@ RedmineApp::Application.routes.draw do collection do #生成路径为 /exercise/方法名 delete 'delete_exercise_question' + post 'update_exercise_question' end end From 1606e9ddab70950b194a7a5fc2d5c9a535580bcd Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 18 Nov 2015 18:28:17 +0800 Subject: [PATCH 36/83] 0 --- app/controllers/exercise_controller.rb | 4 +++- app/helpers/exercise_helper.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 89a5c195e..f83e31a56 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -136,6 +136,7 @@ class ExerciseController < ApplicationController :question_score => params[:question_score] } @exercise_questions = @exercise.exercise_questions.new option + # params[:question_answer] 题目选项 if params[:question_answer] for i in 1..params[:question_answer].count answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] @@ -154,6 +155,7 @@ class ExerciseController < ApplicationController @exercise_questions.question_number = params[:quest_num].to_i + 1 end if @exercise_questions.save + # params[:exercise_choice] 标准答案参数 standart_answer = ExerciseStandardAnswer.new standart_answer.exercise_question_id = @exercise_questions.id if @exercise_questions.question_type == 1 @@ -161,7 +163,7 @@ class ExerciseController < ApplicationController elsif @exercise_questions.question_type == 2 standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) else - standart_answer.answer_text = sigle_selection_standard_answer(params[:exercise_choice]) + standart_answer.answer_text = fill_standart_answer(params[:exercise_choice]) end standart_answer.save respond_to do |format| diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index c1bf07407..3a7c0a00a 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -27,6 +27,10 @@ module ExerciseHelper answer.to_i end + def fill_standart_answer(params) + + end + #判断用户是否已经提交了问卷 def has_commit_exercise?(exercise_id, user_id) pu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id, user_id) From 8cf22767f9d75046fd8a1010771d17b21b53d201 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 18 Nov 2015 19:58:00 +0800 Subject: [PATCH 37/83] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E9=97=AE=E7=AD=94?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 39 ++++++++++++++++---------- app/helpers/exercise_helper.rb | 7 +++-- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index f363b9297..0afc9dfda 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -156,16 +156,24 @@ class ExerciseController < ApplicationController end if @exercise_questions.save # params[:exercise_choice] 标准答案参数 - standart_answer = ExerciseStandardAnswer.new - standart_answer.exercise_question_id = @exercise_questions.id - if @exercise_questions.question_type == 1 - standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice]) - elsif @exercise_questions.question_type == 2 - standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) + # 问答题标准答案有三个,单独处理 + if @exercise_questions.question_type == 3 + for i in 1..params[:exercise_choice].count + standart_answer = ExerciseStandardAnswer.new + standart_answer.exercise_question_id = @exercise_questions.id + standart_answer.answer_text = params[:exercise_choice].values[i-1] + standart_answer.save + end else - standart_answer.answer_text = fill_standart_answer(params[:exercise_choice]) + standart_answer = ExerciseStandardAnswer.new + standart_answer.exercise_question_id = @exercise_questions.id + if @exercise_questions.question_type == 1 + standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice]) + else + standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice]) + end + standart_answer.save end - standart_answer.save respond_to do |format| format.js end @@ -178,16 +186,17 @@ class ExerciseController < ApplicationController # params[:question_answer] eg:A、B、C选项 def update_exercise_question @exercise_question = ExerciseQuestion.find params[:exercise_question] - @exercise_question.question_title = params[:exercise_questions_title].nil? || params[:exercise_questions_title].empty? ? l(:label_enter_single_title) : params[:exercise_questions_title] + @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] + @exercise_question.question_score = params[:question_score] ################处理选项 if params[:question_answer] - @exercise_question.exercise_answers.each do |answer| - answer.destroy unless params[:question_answer].keys.include? answer.id.to_s - end + # @exercise_question.exercise_choices.each do |answer| + # answer.destroy unless params[:question_answer].keys.include? answer.id.to_s + # end # 界面需要判断选择题至少有一个选项 - for i in 1..params[:question_answer].count - question = @exercise_question.exercise_answers.find_by_id params[:question_answer].keys[i-1] - answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + for i in 1..@exercise_question.exercise_choices.count + question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] + # answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] if question question.exercise_choices_id = i question.answer_text = answer diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 3a7c0a00a..7f3d1862e 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -27,8 +27,11 @@ module ExerciseHelper answer.to_i end - def fill_standart_answer(params) - + def fill_standart_answer(params, standart_answer) + params.each do |param| + standart_answer.answer_text = param.value + standart_answer.save + end end #判断用户是否已经提交了问卷 From 368fc339c0a4a47b1c358a2bb4cb896ecb5dd622 Mon Sep 17 00:00:00 2001 From: cxt Date: Wed, 18 Nov 2015 20:14:19 +0800 Subject: [PATCH 38/83] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_edit_MCQ.html.erb | 63 ++++++++++++++ app/views/exercise/_edit_single.html.erb | 58 +++++++++++++ app/views/exercise/_exercise_content.html.erb | 83 ++++++++++++++----- app/views/exercise/_exercise_form.html.erb | 2 +- app/views/exercise/_show_MC.html.erb | 2 +- app/views/exercise/_show_MCQ.html.erb | 2 +- app/views/exercise/_show_single.html.erb | 4 +- .../exercise/create_exercise_question.js.erb | 72 +++++++++++----- .../exercise/update_exercise_question.js.erb | 19 +++++ 9 files changed, 259 insertions(+), 46 deletions(-) diff --git a/app/views/exercise/_edit_MCQ.html.erb b/app/views/exercise/_edit_MCQ.html.erb index e69de29bb..bd7270688 100644 --- a/app/views/exercise/_edit_MCQ.html.erb +++ b/app/views/exercise/_edit_MCQ.html.erb @@ -0,0 +1,63 @@ +<%= form_for("",:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%> + + + +
    +
    + + + +
    +
    +
      +
    • + + 分 +
    • +
      +
      + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> +
    • + + + + +
    • +
      + <% end %> +
      +
    • + + +
    • +
      +
    +
    + +
    +
    + +<% end%> \ No newline at end of file diff --git a/app/views/exercise/_edit_single.html.erb b/app/views/exercise/_edit_single.html.erb index e69de29bb..070e99343 100644 --- a/app/views/exercise/_edit_single.html.erb +++ b/app/views/exercise/_edit_single.html.erb @@ -0,0 +1,58 @@ +<%= form_for("",:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%> + + + +
    +
    + + + +
    +
    +
      +
    • + + 分 +
    • +
      +
      + <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> +
    • + + + + +
    • +
      + <% end %> +
      +
      +
    +
    + +
    +
    + +<% end%> \ No newline at end of file diff --git a/app/views/exercise/_exercise_content.html.erb b/app/views/exercise/_exercise_content.html.erb index 9e139fe32..c5f8f3c94 100644 --- a/app/views/exercise/_exercise_content.html.erb +++ b/app/views/exercise/_exercise_content.html.erb @@ -1,22 +1,65 @@ -<% exercise.exercise_questions.each do |exercise_question|%> -
    -
    - <% if exercise_question.question_type == 1%> - <%= render :partial => 'show_MC', :locals => {:exercise_question => exercise_question} %> - <% elsif exercise_question.question_type == 2%> - <%= render :partial => 'show_MCQ', :locals => {:exercise_question => exercise_question} %> - <% elsif exercise_question.question_type == 3%> - <%= render :partial => 'show_single', :locals => {:exercise_question => exercise_question} %> - <% end%> +<% mc_question_list = exercise.exercise_questions.where("question_type=1") %> +<% mcq_question_list = exercise.exercise_questions.where("question_type=2") %> +<% single_question_list = exercise.exercise_questions.where("question_type=3") %> +
    "> +

    单选题

    + <% mc_question_list.each do |exercise_question| %> +
    +
    + <%= render :partial => 'show_MC', :locals => {:exercise_question => exercise_question} %> +
    +
    - +
    "> +

    多选题

    + <% mcq_question_list.each do |exercise_question| %> +
    +
    + <%= render :partial => 'show_MCQ', :locals => {:exercise_question => exercise_question} %> +
    +
    -
    -<% end %> \ No newline at end of file + <% end %> +
    +
    "> +

    填空题

    + <% single_question_list.each do |exercise_question| %> +
    +
    + <%= render :partial => 'show_single', :locals => {:exercise_question => exercise_question} %> +
    + +
    + <% end %> +
    +<%# exercise.exercise_questions.each do |exercise_question|%> + +<%# end %> \ No newline at end of file diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index 1d78fb435..4ac594d76 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -335,7 +335,7 @@ <%= render :partial => 'edit_head', :locals => {:exercise => @exercise}%>
    <% current_score = get_current_score @exercise %> -
    ">目前试卷总分:<%=current_score %>分
    +
    " id="current_score_div">目前试卷总分:<%=current_score %>分
    <%= render :partial => 'exercise_content', :locals => {:exercise => @exercise}%> diff --git a/app/views/exercise/_show_MC.html.erb b/app/views/exercise/_show_MC.html.erb index e7bf20206..d44652603 100644 --- a/app/views/exercise/_show_MC.html.erb +++ b/app/views/exercise/_show_MC.html.erb @@ -10,7 +10,7 @@
    - +
    <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> diff --git a/app/views/exercise/_show_MCQ.html.erb b/app/views/exercise/_show_MCQ.html.erb index f69b855bd..db9fa2dd4 100644 --- a/app/views/exercise/_show_MCQ.html.erb +++ b/app/views/exercise/_show_MCQ.html.erb @@ -9,7 +9,7 @@
    -
    +
    <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 07ecce94d..591848d76 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -8,8 +8,8 @@
    - <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> - 候选答案:<%= exercise_choice.choice_text%>
    + <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> + 候选答案:<%= exercise_choice.answer_text%>
    <% end %>
    diff --git a/app/views/exercise/create_exercise_question.js.erb b/app/views/exercise/create_exercise_question.js.erb index 224dc0a95..db9468350 100644 --- a/app/views/exercise/create_exercise_question.js.erb +++ b/app/views/exercise/create_exercise_question.js.erb @@ -1,27 +1,57 @@ <% if @is_insert %> -$("#poll_content").html('<%= escape_javascript(render :partial => 'exercise_content', :locals => {:exercise => @exercise})%>'); + $("#poll_content").html('<%= escape_javascript(render :partial => 'exercise_content', :locals => {:exercise => @exercise})%>'); <% else %> -$("#new_poll_question").html(""); - -$("#poll_content").append("
    " + - "
    " + - "<% if @exercise_questions.question_type == 1%>" + - "<%= escape_javascript(render :partial => 'show_MC', :locals => {:exercise_question => @exercise_questions}) %>" + - "<% elsif @exercise_questions.question_type == 2%>" + - "<%= escape_javascript(render :partial => 'show_MCQ', :locals => {:exercise_question => @exercise_questions}) %>" + - "<% elsif @exercise_questions.question_type == 3%>" + - "<%= escape_javascript(render :partial => 'show_single', :locals => {:exercise_question => @exercise_questions}) %>" + - "<% end%>" + + $("#new_poll_question").html(""); + <%if @exercise_questions.question_type == 1%> + $("#mc_question_list").show().append("
    " + + "
    " + + "<%= escape_javascript(render :partial => 'show_MC', :locals => {:exercise_question => @exercise_questions}) %>" + + "
    " + + "" + + "
    "); + <% end %> + <%if @exercise_questions.question_type == 2%> + $("#mcq_question_list").show().append("
    " + + "
    " + + "<%= escape_javascript(render :partial => 'show_MCQ', :locals => {:exercise_question => @exercise_questions}) %>" + + "
    " + + "" + + "
    "); + <% end %> + <%if @exercise_questions.question_type == 3%> + $("#single_question_list").show().append("
    " + + "
    " + + "<%= escape_javascript(render :partial => 'show_single', :locals => {:exercise_question => @exercise_questions}) %>" + + "
    " + + "" + + "
    "); + <% end %> +/*$("#poll_content").append("
    " + + "
    " + + "<%# if @exercise_questions.question_type == 1%>" + + "<%#= escape_javascript(render :partial => 'show_MC', :locals => {:exercise_question => @exercise_questions}) %>" + + "<%# elsif @exercise_questions.question_type == 2%>" + + "<%#= escape_javascript(render :partial => 'show_MCQ', :locals => {:exercise_question => @exercise_questions}) %>" + + "<%# elsif @exercise_questions.question_type == 3%>" + + "<%#= escape_javascript(render :partial => 'show_single', :locals => {:exercise_question => @exercise_questions}) %>" + + "<%# end%>" + "
    " + - ""); + "
    ");*/ $("#current_score").html("<%=get_current_score @exercise %>分"); +$("#current_score_div").show(); <% end %> diff --git a/app/views/exercise/update_exercise_question.js.erb b/app/views/exercise/update_exercise_question.js.erb index e69de29bb..0f0a23cec 100644 --- a/app/views/exercise/update_exercise_question.js.erb +++ b/app/views/exercise/update_exercise_question.js.erb @@ -0,0 +1,19 @@ +$("#poll_questions_<%= @exercise_question.id%>").html("
    " + + "<% if @exercise_question.question_type == 1%>" + + "<%= escape_javascript(render :partial => 'show_MC', :locals => {:exercise_question => @exercise_question}) %>" + + "<% elsif @exercise_question.question_type == 2%>" + + "<%= escape_javascript(render :partial => 'show_MCQ', :locals => {:exercise_question => @exercise_question}) %>" + + "<% elsif @exercise_question.question_type == 3%>" + + "<%= escape_javascript(render :partial => 'show_single', :locals => {:exercise_question => @exercise_question}) %>" + + "<% end%>" + + "
    " + + ""); +$("#current_score").html("<%=get_current_score @exercise %>分"); From 2296a2f50ce95774e15f7b0cf7011c9309182825 Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 18 Nov 2015 21:16:24 +0800 Subject: [PATCH 39/83] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BD=9C=E4=B8=9A=20=E8=80=81=E5=B8=88?= =?UTF-8?q?=E5=8F=91=E5=B8=83=E4=BD=9C=E4=B8=9A=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 159 ++++++++++++++++++++++++- config/routes.rb | 2 + 2 files changed, 158 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 0afc9dfda..a291a2229 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1,7 +1,7 @@ class ExerciseController < ApplicationController layout "base_courses" - before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy] + before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer] before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list] include ExerciseHelper @@ -265,10 +265,163 @@ class ExerciseController < ApplicationController end end + # 学生提交答卷 + def commit_answer + eq = ExerciseQuestion.find(params[:poll_question_id]) + if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) + render :json => {:text => "failure"} + return + end + if eq.question_type == 1 + # 单选题 + ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id) + if ea.nil? + # 尚未答该题,添加答案 + ea = ExerciseAnswer.new + ea.user_id = User.current.id + ea.exercise_question_id = params[:exercise_question_id] + end + #修改该题对应答案 + ea.exercise_choice_id = params[:exercise_choice_id] + if ea.save + # 保存成功返回成功信息及当前以答题百分比 + @percent = get_percent(@exercise,User.current) + render :json => {:text => "ok" ,:percent => format("%.2f" ,@percent)} + else + #返回失败信息 + render :json => {:text => "failure"} + end + elsif eq.question_type == 2 + #多选题 + ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id) + if ea.nil? + #尚未答该题,添加答案 + ea = ExerciseAnswer.new + ea.user_id = User.current.id + ea.exercise_question_id = params[:exercise_question_id] + ea.exercise_choice_id = params[:exercise_choice_id] + if ea.save + @percent = get_percent(@exercise,User.current) + render :json => {:text => "true",:percent => format("%.2f" ,@percent)} + else + render :json => {:text => "failure"} + end + else + #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案 + if pv.delete + @percent = get_percent(@exercise, User.current) + render :json => {:text => "false" ,:percent => format("%.2f" , @percent)} + else + render :json => {:text => "failure"} + end + end + elsif eq.question_type == 3 + #单行文本,多行文本题 + ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id) + if ea.nil? + # ea为空之前尚未答题,添加答案 + if params[:answer_text].nil? || params[:answer_text].blank? + #用户提交空答案,视作不作答 + @percent = get_percent(@exercise,User.current) + render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)} + else + #添加答案 + ea = ExerciseAnswer.new + ea.user_id = User.current.id + ea.exercise_question_id = params[:exercise_question_id] + ea.answer_text = params[:answer_text] + if ea.save + @percent = get_percent(@exercise,User.current) + render :json => {:text => pv.vote_text,:percent => format("%.2f",@percent)} + else + render :json => {:text => "failure"} + end + end + else + # ea不为空说明用户之前已作答 + if params[:answer_text].nil? || params[:answer_text].blank? + # 用户提交空答案,视为删除答案 + if ea.delete + @percent = get_percent(@exercise,User.current) + render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)} + else + render :json => {:text => "failure"} + end + else + #用户修改答案 + ea.answer_text = params[:answer_text] + if ea.save + @percent = get_percent(@exercise,User.current) + render :json => {:text => pv.vote_text,:percent => format("%.2f", @percent)} + else + render :json => {:text => "failure"} + end + end + end + + else + render :json => {:text => "failure"} + end + end + + # 提交问卷 + def commit_exercise + # 老师不需要提交 + if User.current.allowed_to?(:as_teacher,@course) + redirect_to exercise_url(@exercise) + else + # 答题过程中需要统计完成量 + @uncomplete_question = get_uncomplete_question(@exercise, User.current) + # 获取改学生的考试得分 + score = get_answer_score(@exercise) + if @uncomplete_question.count < 1 + # 查看是否有已提交记录 + eu = get_exercise_user(@exercise.id, User.current.id) + eu.user_id = User.current.id + eu.exercise_id = @exercise.id + eu.score = score + if eu.save + #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course') + @status = 0 #提交成功 + else + @status = 2 #未知错误 + end + else + @status = 1 #有未做得必答题 + end + respond_to do |format| + format.js + end + end + end + + private + # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 + def get_exercise_user exercise_id,user_id + eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id) + if eu.nil? + eu = ExerciseUser.new + end + eu + end + + #获取未完成的题目 + def get_uncomplete_question exercise,user + all_questions = exercise.exercise_questions + uncomplete_question = [] + all_questions.each do |question| + answers = get_user_answer(question, user) + if answers.nil? || answers.count < 1 + uncomplete_question << question + end + end + uncomplete_question + end + # 获取问题的答案 def get_user_answer(question,user) - user_answer = question.poll_votes.where("#{PollVote.table_name}.user_id = #{user.id}") + user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") user_answer end @@ -285,7 +438,7 @@ class ExerciseController < ApplicationController complete_question end - + # 获取答题百分比 def get_percent exercise,user complete_count = get_complete_question(exercise,user).count if exercise.exercise_questions.count == 0 diff --git a/config/routes.rb b/config/routes.rb index 422f470d5..516b8977f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -153,6 +153,8 @@ RedmineApp::Application.routes.draw do get 'student_exercise_list' get 'export_exercise' post 'create_exercise_question' + post 'commit_answer' + post 'commit_exercise' end collection do #生成路径为 /exercise/方法名 From a173e924d00d60c7fed10238a6a93f8ed046654a Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 19 Nov 2015 09:13:46 +0800 Subject: [PATCH 40/83] =?UTF-8?q?=E6=8F=92=E5=85=A5=E9=A2=98=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_edit_MC.html.erb | 2 +- app/views/exercise/_edit_MCQ.html.erb | 2 +- app/views/exercise/_edit_single.html.erb | 2 +- app/views/exercise/_exercise_form.html.erb | 331 ++++++++++++--------- app/views/exercise/_new_single.html.erb | 12 +- app/views/exercise/_show_MC.html.erb | 9 +- app/views/exercise/_show_MCQ.html.erb | 2 +- app/views/exercise/_show_single.html.erb | 9 +- 8 files changed, 207 insertions(+), 162 deletions(-) diff --git a/app/views/exercise/_edit_MC.html.erb b/app/views/exercise/_edit_MC.html.erb index 5a406537b..c769fe634 100644 --- a/app/views/exercise/_edit_MC.html.erb +++ b/app/views/exercise/_edit_MC.html.erb @@ -18,7 +18,7 @@ } -
    +
    diff --git a/app/views/exercise/_edit_MCQ.html.erb b/app/views/exercise/_edit_MCQ.html.erb index bd7270688..01e63cb24 100644 --- a/app/views/exercise/_edit_MCQ.html.erb +++ b/app/views/exercise/_edit_MCQ.html.erb @@ -18,7 +18,7 @@ } -
    +
    diff --git a/app/views/exercise/_edit_single.html.erb b/app/views/exercise/_edit_single.html.erb index 070e99343..1048b2145 100644 --- a/app/views/exercise/_edit_single.html.erb +++ b/app/views/exercise/_edit_single.html.erb @@ -17,7 +17,7 @@ } -
    +
    diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index 4ac594d76..863f68a72 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -60,60 +60,74 @@ } function insert_MC(quest_type,quest_num,quest_id){ - $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new, - :html => { :multipart => true }, - :url => {:controller => 'exercise', - :action => 'create_exercise_question', - :course_id => @course.id - },:remote=>true ) do |f|%>'+ - '
    '+ - '
    '+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '<% end%>' - ); + if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == "") { + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( + '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ + '
    '+ + '
    '+ + ''+ + ''+ + ''+ + ''+ + ''+ + '
    '+ + '
    '+ + '
      '+ + '
    • '+ + ''+ + '分'+ + '
    • '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    '+ + '
    '+ + ''+ + '
    '+ + '
    '+ + '<% end%>' + ); + } + else { + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(""); + } $("#poll_questions_title").focus(); } @@ -123,60 +137,73 @@ } function insert_MCQ(quest_type,quest_num,quest_id){ - $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new, - :html => { :multipart => true }, - :url => {:controller => 'exercise', - :action => 'create_exercise_question', - :course_id => @course.id - },:remote=>true ) do |f|%>'+ - '
    '+ - '
    '+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '<% end%>' - ); + if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == ""){ + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( + '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ + '
    '+ + '
    '+ + ''+ + ''+ + ''+ + ''+ + ''+ + '
    '+ + '
    '+ + '
      '+ + '
    • '+ + ''+ + '分'+ + '
    • '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    '+ + '
    '+ + ''+ + '
    '+ + '
    '+ + '<% end%>' + ); + } else { + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(""); + } $("#poll_questions_title").focus(); } @@ -186,35 +213,61 @@ } function insert_SINGLE(quest_type,quest_num,quest_id){ - $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new, - :html => { :multipart => true }, - :url => {:controller => 'exercise', - :action => 'create_exercise_question', - :course_id => @course.id - },:remote=>true ) do |f|%>'+ - '
    '+ - '
    '+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '<% end%>' - ); + if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == "") { + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( + '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ + '
    '+ + '
    '+ + ''+ + ''+ + ''+ + ''+ + ''+ + '
    '+ + '
    '+ + '
      '+ + '
    • '+ + ''+ + '分'+ + '
    • '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    • '+ + ''+ + ''+ + ''+ + ''+ + '
    • '+ + '
      '+ + '
    '+ + '
    '+ + ''+ + '
    '+ + '
    '+ + '<% end%>' + ); + } else { + $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(""); + } $("#poll_questions_title").focus(); } @@ -247,13 +300,13 @@ function add_poll_question(doc) { var title = $.trim($("#poll_questions_title").val()); - if(title.length == 0){alert("标题不能为空");}else{doc.parent().parent().parent().submit();} + if(title.length == 0){alert("题目标题不能为空");}else{doc.parent().parent().parent().submit();} } //修改标题时确定按钮 function edit_poll_question(doc,id) { var title = $.trim($("#poll_questions_title_" + id).val()); - if(title.length == 0){alert("标题不能为空");}else{doc.parent().parent().parent().submit();} + if(title.length == 0){alert("题目标题不能为空");}else{doc.parent().parent().parent().submit();} } //问卷头 diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index 4d9baf729..a8c6f57ea 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -20,17 +20,23 @@
  • -
  • + + +
  • -
  • + + +
  • -
  • + + +
    diff --git a/app/views/exercise/_show_MC.html.erb b/app/views/exercise/_show_MC.html.erb index d44652603..241cc6009 100644 --- a/app/views/exercise/_show_MC.html.erb +++ b/app/views/exercise/_show_MC.html.erb @@ -7,7 +7,7 @@ <%= link_to("", delete_exercise_question_exercise_index_path(:exercise_question => exercise_question.id), method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> - +
    @@ -28,11 +28,4 @@
    -
    - \ No newline at end of file diff --git a/app/views/exercise/_show_MCQ.html.erb b/app/views/exercise/_show_MCQ.html.erb index db9fa2dd4..7dd52b30a 100644 --- a/app/views/exercise/_show_MCQ.html.erb +++ b/app/views/exercise/_show_MCQ.html.erb @@ -6,7 +6,7 @@ <%= link_to("", delete_exercise_question_exercise_index_path(:exercise_question => exercise_question.id), method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> - +
    diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 591848d76..452a14bc4 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -5,7 +5,7 @@ <%= link_to("", delete_exercise_question_exercise_index_path(:exercise_question => exercise_question.id), method: :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "ur_icon_de") %> - +
    <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> @@ -15,11 +15,4 @@
    -
    - \ No newline at end of file From 4cd9f6a50278a9f513f31c335d6ee3341e75973b Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 19 Nov 2015 11:37:49 +0800 Subject: [PATCH 41/83] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E9=A2=98=E7=9B=AE?= =?UTF-8?q?=E6=97=B6=E5=88=86=E6=95=B0=E8=87=AA=E5=8A=A8=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=90=8C=E4=B8=80=E7=B1=BB=E5=9E=8B=E9=A2=98=E7=9B=AE=E7=9A=84?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E4=B8=AA=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_exercise_form.html.erb | 237 +----------------- app/views/exercise/_new_MC.html.erb | 3 +- app/views/exercise/_new_MCQ.html.erb | 3 +- app/views/exercise/_new_question.html.erb | 24 ++ app/views/exercise/_new_single.html.erb | 3 +- app/views/exercise/_show_MC.html.erb | 77 +++++- app/views/exercise/_show_MCQ.html.erb | 83 +++++- app/views/exercise/_show_single.html.erb | 64 ++++- .../exercise/create_exercise_question.js.erb | 1 + 9 files changed, 254 insertions(+), 241 deletions(-) create mode 100644 app/views/exercise/_new_question.html.erb diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index 863f68a72..4bb2c31ab 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -54,223 +54,6 @@ } } - function add_MC(){ - $("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_MC') %>"); - $("#poll_questions_title").focus(); - } - - function insert_MC(quest_type,quest_num,quest_id){ - if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == "") { - $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ - '
    '+ - '
    '+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - '
      '+ - '
    • '+ - ''+ - '分'+ - '
    • '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '<% end%>' - ); - } - else { - $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(""); - } - $("#poll_questions_title").focus(); - } - - function add_MCQ(){ - $("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_MCQ') %>"); - $("#poll_questions_title").focus(); - } - - function insert_MCQ(quest_type,quest_num,quest_id){ - if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == ""){ - $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ - '
    '+ - '
    '+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - '
      '+ - '
    • '+ - ''+ - '分'+ - '
    • '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '<% end%>' - ); - } else { - $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(""); - } - $("#poll_questions_title").focus(); - } - - function add_single(){ - $("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_single') %>"); - $("#poll_questions_title").focus(); - } - - function insert_SINGLE(quest_type,quest_num,quest_id){ - if($.trim($("#insert_new_poll_question_"+quest_type+"_"+quest_id).html()) == "") { - $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ - '
    '+ - '
    '+ - ''+ - ''+ - ''+ - ''+ - ''+ - '
    '+ - '
    '+ - '
      '+ - '
    • '+ - ''+ - '分'+ - '
    • '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    • '+ - ''+ - ''+ - ''+ - ''+ - '
    • '+ - '
      '+ - '
    '+ - '
    '+ - ''+ - '
    '+ - '
    '+ - '<% end%>' - ); - } else { - $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(""); - } - $("#poll_questions_title").focus(); - } - //选择导入调查问卷 function importPoll(){ importPollPopWindow = $("#import_poll"); @@ -297,10 +80,15 @@ } //添加标题时确定按钮 - function add_poll_question(doc) + function add_poll_question(doc,quest_type,quest_id) { - var title = $.trim($("#poll_questions_title").val()); - if(title.length == 0){alert("题目标题不能为空");}else{doc.parent().parent().parent().submit();} + if(arguments[1] && arguments[2]){ + var title = $.trim($("#poll_questions_title_"+quest_type+"_"+quest_id)); + if(title.length == 0){alert("题目标题不能为空");}else{doc.parent().parent().parent().submit();} + } else { + var title = $.trim($("#poll_questions_title").val()); + if(title.length == 0){alert("题目标题不能为空");}else{doc.parent().parent().parent().submit();} + } } //修改标题时确定按钮 function edit_poll_question(doc,id) @@ -394,13 +182,8 @@ <%= render :partial => 'exercise_content', :locals => {:exercise => @exercise}%> -
    - -
    +
    + <%= render :partial => 'new_question', :locals => {:exercise => @exercise} %>
    diff --git a/app/views/exercise/_new_MC.html.erb b/app/views/exercise/_new_MC.html.erb index 158f8be96..3da0021ce 100644 --- a/app/views/exercise/_new_MC.html.erb +++ b/app/views/exercise/_new_MC.html.erb @@ -13,8 +13,9 @@
    • + <% score = exercise.exercise_questions.where("question_type=1").last.nil? ? "": exercise.exercise_questions.where("question_type=1").last.question_score %> - 分 +
    • diff --git a/app/views/exercise/_new_MCQ.html.erb b/app/views/exercise/_new_MCQ.html.erb index 6e58d620e..044ecd629 100644 --- a/app/views/exercise/_new_MCQ.html.erb +++ b/app/views/exercise/_new_MCQ.html.erb @@ -13,8 +13,9 @@
      • + <% score = exercise.exercise_questions.where("question_type=2").last.nil? ? "": exercise.exercise_questions.where("question_type=2").last.question_score %> - 分 +
      • diff --git a/app/views/exercise/_new_question.html.erb b/app/views/exercise/_new_question.html.erb new file mode 100644 index 000000000..d41ad1ca7 --- /dev/null +++ b/app/views/exercise/_new_question.html.erb @@ -0,0 +1,24 @@ + +
        + + \ No newline at end of file diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index a8c6f57ea..ad5af1937 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -13,8 +13,9 @@
        • + <% score = exercise.exercise_questions.where("question_type=3").last.nil? ? "": exercise.exercise_questions.where("question_type=3").last.question_score %> - 分 +
        • diff --git a/app/views/exercise/_show_MC.html.erb b/app/views/exercise/_show_MC.html.erb index 241cc6009..1c90f6908 100644 --- a/app/views/exercise/_show_MC.html.erb +++ b/app/views/exercise/_show_MC.html.erb @@ -28,4 +28,79 @@
        -
        \ No newline at end of file +
      + + \ No newline at end of file diff --git a/app/views/exercise/_show_MCQ.html.erb b/app/views/exercise/_show_MCQ.html.erb index 7dd52b30a..08a012fd3 100644 --- a/app/views/exercise/_show_MCQ.html.erb +++ b/app/views/exercise/_show_MCQ.html.erb @@ -28,12 +28,77 @@
      - \ No newline at end of file + + \ No newline at end of file diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 452a14bc4..8232e68f3 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -15,4 +15,66 @@
    -
    \ No newline at end of file +
    + + \ 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 db9468350..37199a70e 100644 --- a/app/views/exercise/create_exercise_question.js.erb +++ b/app/views/exercise/create_exercise_question.js.erb @@ -1,6 +1,7 @@ <% if @is_insert %> $("#poll_content").html('<%= escape_javascript(render :partial => 'exercise_content', :locals => {:exercise => @exercise})%>'); <% else %> + $("#new_exercise_question").html('<%= escape_javascript(render :partial => 'new_question', :locals => {:exercise => @exercise}) %>'); $("#new_poll_question").html(""); <%if @exercise_questions.question_type == 1%> $("#mc_question_list").show().append("
    " + From bc47382115689c4cfdddc93717b9e7c53c564e31 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 11:38:44 +0800 Subject: [PATCH 42/83] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E7=AD=94=E5=8D=B7=E5=90=8E=EF=BC=8C=E7=BB=99=E5=87=BA=E5=BE=97?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 42 +++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index a291a2229..58c6f772b 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -190,9 +190,9 @@ class ExerciseController < ApplicationController @exercise_question.question_score = params[:question_score] ################处理选项 if params[:question_answer] - # @exercise_question.exercise_choices.each do |answer| - # answer.destroy unless params[:question_answer].keys.include? answer.id.to_s - # end + @exercise_question.exercise_choices.each do |answer| + answer.destroy unless params[:question_answer].keys.include? answer.id.to_s + end # 界面需要判断选择题至少有一个选项 for i in 1..@exercise_question.exercise_choices.count question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] @@ -265,9 +265,10 @@ class ExerciseController < ApplicationController end end - # 学生提交答卷 + # 学生提交答卷,选着答案的课程中提交 def commit_answer - eq = ExerciseQuestion.find(params[:poll_question_id]) + eq = ExerciseQuestion.find(params[:exercise_question_id]) + # 已提交过的则不允许答题 if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) render :json => {:text => "failure"} return @@ -369,11 +370,12 @@ class ExerciseController < ApplicationController # 老师不需要提交 if User.current.allowed_to?(:as_teacher,@course) redirect_to exercise_url(@exercise) + # REDO: 提示提交成功 else # 答题过程中需要统计完成量 @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 - score = get_answer_score(@exercise) + score = calculate_student_score(@exercise, User.current) if @uncomplete_question.count < 1 # 查看是否有已提交记录 eu = get_exercise_user(@exercise.id, User.current.id) @@ -395,6 +397,26 @@ class ExerciseController < ApplicationController end end + # 计算学生得分 + def calculate_student_score(exercise, user) + score = 0 + exercise_qustions = exercise.exercise_questions + exercise_qustions.each do |question| + answer = get_user_answer(question, user) + standard_answer = get_user_standard_answer(question, user) + # 问答题有多个答案 + if question.question_type == 3 + if standard_answer.exercise_choice_id.include?(answer.exercise_choice_id) + score = score + question.question_score + end + else + if answer.exercise_choice_id == standard_answer.exercise_choice_id + score = score + question.question_score + end + end + end + score + end private # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 @@ -419,12 +441,18 @@ class ExerciseController < ApplicationController uncomplete_question end - # 获取问题的答案 + # 获取当前学生回答问题的答案 def get_user_answer(question,user) user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") user_answer end + # 获取问题的标准答案 + def get_user_standard_answer(question,user) + standard_answer = question.exercise_standard_answers + standard_answer + end + # 是否完成了答题 def get_complete_question(exercise,user) questions = exercise.exercise_questions From 3929aa6dded402df31197c038d00d25875cc713f Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 19 Nov 2015 13:06:17 +0800 Subject: [PATCH 43/83] =?UTF-8?q?=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_edit_MC.html.erb | 4 ++-- app/views/exercise/_edit_MCQ.html.erb | 4 ++-- app/views/exercise/_edit_head.html.erb | 2 +- app/views/exercise/_new_MC.html.erb | 1 + app/views/exercise/_new_MCQ.html.erb | 1 + app/views/exercise/_new_single.html.erb | 1 + 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/views/exercise/_edit_MC.html.erb b/app/views/exercise/_edit_MC.html.erb index c769fe634..ef46e47a8 100644 --- a/app/views/exercise/_edit_MC.html.erb +++ b/app/views/exercise/_edit_MC.html.erb @@ -1,4 +1,4 @@ -<%= form_for("",:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%> +<%= form_for("",:class => 'new_or_edit_question',:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%> \ No newline at end of file diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index 06b8939c3..ad5af1937 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -1,6 +1,5 @@ <%= form_for(ExerciseQuestion.new, :html => { :multipart => true }, - :class => 'new_or_edit_question', :url => {:controller => 'exercise', :action => 'create_exercise_question', :course_id => @course.id diff --git a/app/views/exercise/_show_MC.html.erb b/app/views/exercise/_show_MC.html.erb index 1c90f6908..21d6ef4bb 100644 --- a/app/views/exercise/_show_MC.html.erb +++ b/app/views/exercise/_show_MC.html.erb @@ -32,75 +32,80 @@ \ No newline at end of file diff --git a/app/views/exercise/_show_MCQ.html.erb b/app/views/exercise/_show_MCQ.html.erb index 08a012fd3..a6ffbeb82 100644 --- a/app/views/exercise/_show_MCQ.html.erb +++ b/app/views/exercise/_show_MCQ.html.erb @@ -31,74 +31,79 @@ \ No newline at end of file diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 8232e68f3..4e36530ed 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -19,62 +19,67 @@ \ No newline at end of file From 841ebb78468d1ec0198d03e4cd9ce05f89139feb Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 16:21:31 +0800 Subject: [PATCH 46/83] =?UTF-8?q?=E7=AE=80=E5=8D=95=E9=A2=98=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=EF=BC=8C=E6=9C=AA=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 54 ++++++++++++++++++------ app/views/exercise/_edit_MC.html.erb | 2 +- app/views/exercise/_edit_MCQ.html.erb | 4 +- app/views/exercise/_edit_single.html.erb | 2 +- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index dd4e543ff..faaae4997 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -188,30 +188,43 @@ class ExerciseController < ApplicationController @exercise_question = ExerciseQuestion.find params[:exercise_question] @exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title] @exercise_question.question_score = params[:question_score] - # 处理选项 + # 处理选项:如果选了某个选项,那么则要删除之前的选项 if params[:question_answer] - @exercise_question.exercise_choices.each do |answer| - answer.destroy unless params[:question_answer].keys.include? answer.id.to_s - end + # @exercise_question.exercise_choices.each do |answer| + # answer.destroy unless params[:question_answer].keys.include? answer.id.to_s + # end for i in 1..params[:question_answer].count question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] if question - question.exercise_choices_id = i - question.answer_text = answer + question.choice_position = i + question.choice_text = answer question.save else question_option = { - :exercise_choice_id => i, - :answer_text => answer + :choice_position => i, + :choice_text => answer } - @exercise_question.exercise_answers.new question_option + @exercise_question.exercise_choices.new question_option end end end - @exercise_question.save - respond_to do |format| - format.js + # 更新标准答案 + if params[:exercise_choice] + if @exercise_question.question_type == 3 + for i in 1..params[:exercise_choice].count + question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i] + answer_standart = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + end + else + answer_standart = @exercise_question.exercise_standard_answers.first + answer_standart.exercise_choice_id = params[:exercise_choice] + answer_standart.save + end + @exercise_question.save + respond_to do |format| + format.js + end end end @@ -231,7 +244,7 @@ class ExerciseController < ApplicationController end end - #发布问卷 + # 发布试卷 def publish_excercise @exercise.exercise_status = 2 @exercise.publish_time = Time.now @@ -246,6 +259,19 @@ class ExerciseController < ApplicationController end end + # 重新发布试卷 + def republish_excercise + @exercise.exercise_questions.each do |exercise_question| + exercise_question.exercise_ansers.destroy_all + end + # @poll.poll_users.destroy_all + # @poll.polls_status = 1 + # @poll.save + # respond_to do |format| + # format.js + # end + end + def student_exercise_list @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? @exercise = Exercise.find params[:id] @@ -264,7 +290,7 @@ class ExerciseController < ApplicationController end end - # 学生提交答卷,选着答案的课程中提交 + # 学生提交答卷,选中答案的过程中提交 def commit_answer eq = ExerciseQuestion.find(params[:exercise_question_id]) # 已提交过的则不允许答题 diff --git a/app/views/exercise/_edit_MC.html.erb b/app/views/exercise/_edit_MC.html.erb index 9c6f3c396..76bad697c 100644 --- a/app/views/exercise/_edit_MC.html.erb +++ b/app/views/exercise/_edit_MC.html.erb @@ -35,7 +35,7 @@ <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
  • - +
  • diff --git a/app/views/exercise/_edit_MCQ.html.erb b/app/views/exercise/_edit_MCQ.html.erb index 0186b3041..a3ae74324 100644 --- a/app/views/exercise/_edit_MCQ.html.erb +++ b/app/views/exercise/_edit_MCQ.html.erb @@ -9,7 +9,7 @@ $("#poll_answers_<%=exercise_question.id%>").html("<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>" + "
  • " + "" + - "" + + "" + "" + "" + "
  • " + @@ -35,7 +35,7 @@ <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
  • - +
  • diff --git a/app/views/exercise/_edit_single.html.erb b/app/views/exercise/_edit_single.html.erb index 1048b2145..647ab02de 100644 --- a/app/views/exercise/_edit_single.html.erb +++ b/app/views/exercise/_edit_single.html.erb @@ -34,7 +34,7 @@ <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %>
  • - +
  • From f3614999da1927e565b550f79889f0ac4bebf2a6 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 16:38:46 +0800 Subject: [PATCH 47/83] gi --- app/controllers/exercise_controller.rb | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index faaae4997..5510b1539 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -213,8 +213,19 @@ class ExerciseController < ApplicationController if params[:exercise_choice] if @exercise_question.question_type == 3 for i in 1..params[:exercise_choice].count - question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i] - answer_standart = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] + # 找到对应的标准答案 + question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1] + # 标准答案值 + answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1] + if question_standart + question_standart.answer_text = answer_standart + question_standart.save + else + standart_answer_option = { + :answer_text => question_standart + } + @exercise_question.exercise_standard_answers.new standart_answer_option + end end else answer_standart = @exercise_question.exercise_standard_answers.first From 02f6b636cd4f963d5bea0f985b18eafed71c4f2f Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 17:09:59 +0800 Subject: [PATCH 48/83] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 5510b1539..8561b112a 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -190,9 +190,9 @@ class ExerciseController < ApplicationController @exercise_question.question_score = params[:question_score] # 处理选项:如果选了某个选项,那么则要删除之前的选项 if params[:question_answer] - # @exercise_question.exercise_choices.each do |answer| - # answer.destroy unless params[:question_answer].keys.include? answer.id.to_s - # end + @exercise_question.exercise_choices.each do |answer| + answer.destroy unless params[:question_answer].keys.include? answer.id.to_s + end for i in 1..params[:question_answer].count question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1] @@ -229,7 +229,7 @@ class ExerciseController < ApplicationController end else answer_standart = @exercise_question.exercise_standard_answers.first - answer_standart.exercise_choice_id = params[:exercise_choice] + answer_standart.exercise_choice_id = @exercise_question.question_type == 1 ? sigle_selection_standard_answer(params[:exercise_choice]) : multiselect_standard_answer(params[:exercise_choice]) answer_standart.save end @exercise_question.save From 2c1b03079b04c2c8056538fde19a703c6789dbe4 Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 19 Nov 2015 17:18:58 +0800 Subject: [PATCH 49/83] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E6=B5=8B=E9=AA=8C?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 1 + app/views/exercise/_edit_head.html.erb | 2 +- app/views/exercise/_edit_single.html.erb | 4 +- app/views/exercise/_exercise_content.html.erb | 25 +--- app/views/exercise/_exercise_form.html.erb | 39 ++---- app/views/exercise/_exercise_student.html.erb | 127 ++++++++++++++++++ app/views/exercise/_exercise_submit.html.erb | 35 +++++ .../exercise/_exercise_submit_info.html.erb | 35 +++++ app/views/exercise/_new_single.html.erb | 6 +- app/views/exercise/_show_head.html.erb | 2 +- app/views/exercise/_show_single.html.erb | 6 +- .../exercise/create_exercise_question.js.erb | 22 +-- .../exercise/delete_exercise_question.js.erb | 4 +- app/views/exercise/show.html.erb | 6 +- app/views/exercise/update.js.erb | 3 +- .../exercise/update_exercise_question.js.erb | 1 + 16 files changed, 230 insertions(+), 88 deletions(-) create mode 100644 app/views/exercise/_exercise_student.html.erb create mode 100644 app/views/exercise/_exercise_submit.html.erb create mode 100644 app/views/exercise/_exercise_submit_info.html.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index dd4e543ff..f1b90dba8 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -22,6 +22,7 @@ class ExerciseController < ApplicationController def show @exercise = Exercise.find params[:id] + @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? if @exercise.exercise_status != 2 && (!User.current.allowed_to?(:as_teacher,@course) || User.current.admin?) render_403 return diff --git a/app/views/exercise/_edit_head.html.erb b/app/views/exercise/_edit_head.html.erb index 9868a4465..3090cc2c5 100644 --- a/app/views/exercise/_edit_head.html.erb +++ b/app/views/exercise/_edit_head.html.erb @@ -17,7 +17,7 @@ " > <%= calendar_for('exercise_end_time')%>
    -
    考试时长:分钟
    +
    测验时长:分钟
    <% end %> - -<%# exercise.exercise_questions.each do |exercise_question|%> - -<%# end %> \ No newline at end of file + \ No newline at end of file diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index 934e51b71..6e0953e74 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -134,6 +134,12 @@ ""+ "
    "); } + function add_candidate_answer(doc) + { + doc.parent().after("
  • " + + ""+ + "
  • "); + } function remove_single_answer(doc) { if(doc.parent().siblings("li").length == 0) @@ -145,32 +151,6 @@ doc.parent().remove(); } } - - function poll_submit() - { - var head_form = $("form.edit_exercise"); - var question_form = $("form.new_exercise_question"); - <% current_score = get_current_score @exercise %> - var score = <%=current_score %>; - if(head_form.length > 0){ - alert("请先保存测验标题及测验基本信息。"); - } else if(question_form.length > 0) { - alert("请先保存正在编辑的题目。"); - } else if( score < 100) { - alert(""); - } - else{ - $('#ajax-modal').html('<%#= escape_javascript(render :partial => 'poll_submit', locals: { :poll => @exercise,:is_remote => false}) %>'); - showModal('ajax-modal', '310px'); - $('#ajax-modal').css('height','120px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before("" + - ""); - $('#ajax-modal').parent().removeClass("alert_praise"); - $('#ajax-modal').parent().css("top","").css("left",""); - $('#ajax-modal').parent().addClass("popbox_polls"); - } - }
    @@ -196,11 +176,8 @@
    -
    提交 -
    - - -
    +
    + <%= render :partial => 'exercise_submit', :locals => {:exercise => @exercise} %>
    diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb new file mode 100644 index 000000000..5a139fd5d --- /dev/null +++ b/app/views/exercise/_exercise_student.html.erb @@ -0,0 +1,127 @@ + +
    +
    +
    +

    <%= exercise.exercise_name%>

    +
    开始时间:<%=format_time(exercise_student.start_at.to_s) %>测验时长:<%=exercise.time %>分钟 +
    剩余时长:1 小时 30 分钟 0 秒
    +
    +
    <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
    +
    +
    +
    + <% mc_question_list = exercise_questions.where("question_type=1") %> + <% mcq_question_list = exercise_questions.where("question_type=2") %> + <% single_question_list = exercise_questions.where("question_type=3") %> +
    "> +

    单选题

    + <% mc_question_list.each do |exercise_question| %> +
    +
    +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %> +
    +
    +
    +
    + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
    + +
    +
    +
    +
    +
    + <% end %> +
    +
    "> +

    多选题

    + <% mcq_question_list.each do |exercise_question| %> +
    +
    +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %> +
    +
    +
    + + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
    + +
    +
    +
    +
    +
    + <% end %> +
    +
    "> +

    填空题

    + <% single_question_list.each do |exercise_question| %> +
    +
    +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %> +
    +
    +
    + +
    +
    +
    +
    + <% end %> +
    + +
    + +
    + +
    \ No newline at end of file diff --git a/app/views/exercise/_exercise_submit.html.erb b/app/views/exercise/_exercise_submit.html.erb new file mode 100644 index 000000000..e242eacc7 --- /dev/null +++ b/app/views/exercise/_exercise_submit.html.erb @@ -0,0 +1,35 @@ +<%= form_for("", + :html => { :multipart => true }, + :url => {:controller => 'exercise', + :action => 'commit_exercise' + },:remote=>true ) do |f| %> +
    + 提交 +
    + + +
    +
    +<% end %> + + \ No newline at end of file diff --git a/app/views/exercise/_exercise_submit_info.html.erb b/app/views/exercise/_exercise_submit_info.html.erb new file mode 100644 index 000000000..66d8da985 --- /dev/null +++ b/app/views/exercise/_exercise_submit_info.html.erb @@ -0,0 +1,35 @@ + + + + + + + +
    +
    +
    +

    当前测验分数为<%=score %>分, +
    + 是否确定提交该测验? +

    + +
    +
    +
    +
    + + + diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index ad5af1937..6e088cd74 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -21,21 +21,21 @@
  • - +
  • - +
  • - +
  • diff --git a/app/views/exercise/_show_head.html.erb b/app/views/exercise/_show_head.html.erb index ec9f06035..ac7c1c162 100644 --- a/app/views/exercise/_show_head.html.erb +++ b/app/views/exercise/_show_head.html.erb @@ -5,7 +5,7 @@
    发布时间:<%=Time.parse(format_time(exercise.publish_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.publish_time%> 截止时间:<%=Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.end_time %> - 考试时长:<%= exercise.time %>分钟
    + 测验时长:<%= exercise.time %>分钟
    <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
    diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 4e36530ed..30a0e354c 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -44,21 +44,21 @@ '
  • '+ ''+ ''+ - ''+ + ''+ ''+ '
  • '+ '
    '+ '
  • '+ ''+ ''+ - ''+ + ''+ ''+ '
  • '+ '
    '+ '
  • '+ ''+ ''+ - ''+ + ''+ ''+ '
  • '+ '
    '+ diff --git a/app/views/exercise/create_exercise_question.js.erb b/app/views/exercise/create_exercise_question.js.erb index 37199a70e..9047cfeda 100644 --- a/app/views/exercise/create_exercise_question.js.erb +++ b/app/views/exercise/create_exercise_question.js.erb @@ -1,8 +1,10 @@ <% if @is_insert %> $("#poll_content").html('<%= escape_javascript(render :partial => 'exercise_content', :locals => {:exercise => @exercise})%>'); + $("#exercise_submit").html("<%= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise}) %>"); <% 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}) %>"); <%if @exercise_questions.question_type == 1%> $("#mc_question_list").show().append("
    " + "
    " + @@ -33,26 +35,6 @@ "
    " + "
    "); <% end %> -/*$("#poll_content").append("
    " + - "
    " + - "<%# if @exercise_questions.question_type == 1%>" + - "<%#= escape_javascript(render :partial => 'show_MC', :locals => {:exercise_question => @exercise_questions}) %>" + - "<%# elsif @exercise_questions.question_type == 2%>" + - "<%#= escape_javascript(render :partial => 'show_MCQ', :locals => {:exercise_question => @exercise_questions}) %>" + - "<%# elsif @exercise_questions.question_type == 3%>" + - "<%#= escape_javascript(render :partial => 'show_single', :locals => {:exercise_question => @exercise_questions}) %>" + - "<%# end%>" + - "
    " + - "" + - "
    ");*/ $("#current_score").html("<%=get_current_score @exercise %>分"); $("#current_score_div").show(); <% end %> diff --git a/app/views/exercise/delete_exercise_question.js.erb b/app/views/exercise/delete_exercise_question.js.erb index eb6300eb5..d07a80b47 100644 --- a/app/views/exercise/delete_exercise_question.js.erb +++ b/app/views/exercise/delete_exercise_question.js.erb @@ -1 +1,3 @@ -$("#poll_content").html("<%= escape_javascript(render :partial => 'exercise_content', :locals => {:exercise => @exercise}) %>"); \ No newline at end of file +$("#poll_content").html("<%= escape_javascript(render :partial => 'exercise_content', :locals => {:exercise => @exercise}) %>"); +$("#current_score").html("<%=get_current_score @exercise %>分"); +$("#exercise_submit").html("<%= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise}) %>"); \ No newline at end of file diff --git a/app/views/exercise/show.html.erb b/app/views/exercise/show.html.erb index b23c1c517..6638020d1 100644 --- a/app/views/exercise/show.html.erb +++ b/app/views/exercise/show.html.erb @@ -1 +1,5 @@ -111111 \ No newline at end of file +<% if @is_teacher %> + +<% else %> + <%=render :partial => 'exercise_student', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_student => @exercise_student} %> +<% end %> \ No newline at end of file diff --git a/app/views/exercise/update.js.erb b/app/views/exercise/update.js.erb index 65b8dd327..9724b2bd1 100644 --- a/app/views/exercise/update.js.erb +++ b/app/views/exercise/update.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 +$("#polls_head_show").show(); +$("#exercise_submit").html("<%= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise}) %>"); \ No newline at end of file diff --git a/app/views/exercise/update_exercise_question.js.erb b/app/views/exercise/update_exercise_question.js.erb index 0f0a23cec..73aea3140 100644 --- a/app/views/exercise/update_exercise_question.js.erb +++ b/app/views/exercise/update_exercise_question.js.erb @@ -17,3 +17,4 @@ $("#poll_questions_<%= @exercise_question.id%>").html("
    {:exercise => @exercise}) %>"); From 7ab0f4764aa308c8bd858dde1f4af80ac5c8d6fa Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 17:31:26 +0800 Subject: [PATCH 50/83] =?UTF-8?q?=E4=B8=BB=E7=AE=A1=E9=A2=98=E6=8F=92?= =?UTF-8?q?=E5=85=A5=E5=88=A0=E9=99=A4=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 9b09a28d9..a48298a83 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -223,7 +223,7 @@ class ExerciseController < ApplicationController question_standart.save else standart_answer_option = { - :answer_text => question_standart + :answer_text => answer_standart } @exercise_question.exercise_standard_answers.new standart_answer_option end From 87e7a51278a847747f1dbf841d193dfcee4ff390 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 17:36:58 +0800 Subject: [PATCH 51/83] =?UTF-8?q?=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index a48298a83..18248331c 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -213,6 +213,10 @@ class ExerciseController < ApplicationController # 更新标准答案 if params[:exercise_choice] if @exercise_question.question_type == 3 + # 删除不合理的选项 + @exercise_question.exercise_standard_answers.each do |answer| + answer.destroy unless params[:exercise_choice].keys.include? answer.id.to_s + end for i in 1..params[:exercise_choice].count # 找到对应的标准答案 question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1] From d91a6c03b1f44d989621b4378bf3123cbcd16e9d Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 19 Nov 2015 17:50:24 +0800 Subject: [PATCH 52/83] =?UTF-8?q?=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_edit_MC.html.erb | 2 +- app/views/exercise/_edit_single.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/exercise/_edit_MC.html.erb b/app/views/exercise/_edit_MC.html.erb index 76bad697c..a1c8aa8b1 100644 --- a/app/views/exercise/_edit_MC.html.erb +++ b/app/views/exercise/_edit_MC.html.erb @@ -9,7 +9,7 @@ $("#poll_answers_<%=exercise_question.id%>").html("<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>" + "
  • " + "" + - "" + + "" + "" + "" + "
  • " + diff --git a/app/views/exercise/_edit_single.html.erb b/app/views/exercise/_edit_single.html.erb index feeb3715d..d22747457 100644 --- a/app/views/exercise/_edit_single.html.erb +++ b/app/views/exercise/_edit_single.html.erb @@ -5,10 +5,10 @@ { $("#poll_questions_title_<%=exercise_question.id%>").val("<%= exercise_question.question_title%>") $("#poll_question_score_<%=exercise_question.id %>").val("<%= exercise_question.question_score%>") - $("#poll_answers_<%=exercise_question.id%>").html("<% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> %>" + + $("#poll_answers_<%=exercise_question.id%>").html("<% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %>" + "
  • " + "" + - "" + + "" + "" + "" + From 74343a49299ab500a1685fe254b3d7c4a94d92c2 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 20:35:08 +0800 Subject: [PATCH 53/83] =?UTF-8?q?=E5=8F=91=E5=B8=83=E9=97=AE=E5=8D=B7?= =?UTF-8?q?=E3=80=81=E5=8F=96=E6=B6=88=E9=97=AE=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 19 ++-- app/views/exercise/_alert.html.erb | 27 ++++++ app/views/exercise/_exercise.html.erb | 4 +- .../exercise/_exercise_republish.html.erb | 0 app/views/exercise/index.html.erb | 87 +++++++++++++++++++ app/views/exercise/publish_exercise.js.erb | 10 +++ app/views/exercise/republish_exercise.js.erb | 10 +++ config/routes.rb | 2 + 8 files changed, 148 insertions(+), 11 deletions(-) create mode 100644 app/views/exercise/_alert.html.erb create mode 100644 app/views/exercise/_exercise_republish.html.erb create mode 100644 app/views/exercise/publish_exercise.js.erb create mode 100644 app/views/exercise/republish_exercise.js.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 18248331c..d13c02d27 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -1,7 +1,7 @@ class ExerciseController < ApplicationController layout "base_courses" - before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer] + before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise] before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list] include ExerciseHelper @@ -261,7 +261,7 @@ class ExerciseController < ApplicationController end # 发布试卷 - def publish_excercise + def publish_exercise @exercise.exercise_status = 2 @exercise.publish_time = Time.now if @exercise.save @@ -276,16 +276,17 @@ class ExerciseController < ApplicationController end # 重新发布试卷 - def republish_excercise + # 重新发布的时候会删除所有的答题 + def republish_exercise @exercise.exercise_questions.each do |exercise_question| exercise_question.exercise_ansers.destroy_all end - # @poll.poll_users.destroy_all - # @poll.polls_status = 1 - # @poll.save - # respond_to do |format| - # format.js - # end + @exercise.exercise_users.destroy_all + @exercise.exercise_status = 1 + @exercise.save + respond_to do |format| + format.js + end end def student_exercise_list diff --git a/app/views/exercise/_alert.html.erb b/app/views/exercise/_alert.html.erb new file mode 100644 index 000000000..b3de53d1f --- /dev/null +++ b/app/views/exercise/_alert.html.erb @@ -0,0 +1,27 @@ + + + + + + + +
    +
    +
    +

    + <%= message%> +

    + +
    +
    +
    +
    + + + diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb index 15a684a62..e44cd69c6 100644 --- a/app/views/exercise/_exercise.html.erb +++ b/app/views/exercise/_exercise.html.erb @@ -19,9 +19,9 @@ <% end%> <% if exercise.exercise_status == 1 %> -
  • 发布试卷
  • +
  • 发布试卷
  • <% elsif exercise.exercise_status == 2%> -
  • 取消发布
  • +
  • 取消发布
  • <% else%>
  • 发布试卷
  • <% end%> diff --git a/app/views/exercise/_exercise_republish.html.erb b/app/views/exercise/_exercise_republish.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb index bbe4dd707..8e8940f33 100644 --- a/app/views/exercise/index.html.erb +++ b/app/views/exercise/index.html.erb @@ -1,4 +1,91 @@ <%= stylesheet_link_tag 'polls', :media => 'all' %> +
    <%= render :partial => 'exercises_list'%>
    \ No newline at end of file diff --git a/app/views/exercise/publish_exercise.js.erb b/app/views/exercise/publish_exercise.js.erb new file mode 100644 index 000000000..ac2899402 --- /dev/null +++ b/app/views/exercise/publish_exercise.js.erb @@ -0,0 +1,10 @@ +$("#exercises_<%= @exercise.id %>").html("<%= escape_javascript(render :partial => 'exercise',:locals => {:exercise => @exercise}) %>"); +$('#ajax-modal').html("<%= escape_javascript(render :partial => 'alert', locals: { :message => l(:label_memo_create_succ)}) %>"); +showModal('ajax-modal', '250px'); +//$('#ajax-modal').css('height','111px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("" + + ""); +$('#ajax-modal').parent().removeClass("alert_praise"); +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("poll_alert_form"); \ No newline at end of file diff --git a/app/views/exercise/republish_exercise.js.erb b/app/views/exercise/republish_exercise.js.erb new file mode 100644 index 000000000..320cd3cf0 --- /dev/null +++ b/app/views/exercise/republish_exercise.js.erb @@ -0,0 +1,10 @@ +$("#exercises_<%= @exercise.id %>").html("<%= escape_javascript(render :partial => 'exercise_content',:locals => {:exercise => @exercise}) %>"); +$('#ajax-modal').html("<%= escape_javascript(render :partial => 'alert', locals: { :message => l(:label_poll_republish_success)}) %>"); +showModal('ajax-modal', '250px'); +//$('#ajax-modal').css('height','80px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("" + + ""); +$('#ajax-modal').parent().removeClass("alert_praise"); +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("poll_alert_form"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 516b8977f..559bf4376 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -152,6 +152,8 @@ RedmineApp::Application.routes.draw do get 'statistics_result' get 'student_exercise_list' get 'export_exercise' + get 'publish_exercise' + get 'republish_exercise' post 'create_exercise_question' post 'commit_answer' post 'commit_exercise' From 20a80fe6eb2b250f91885a132c3b5b3e3e81f10a Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 20:38:03 +0800 Subject: [PATCH 54/83] =?UTF-8?q?=E4=BF=AE=E6=94=B9JS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/index.html.erb | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb index 8e8940f33..14db03e09 100644 --- a/app/views/exercise/index.html.erb +++ b/app/views/exercise/index.html.erb @@ -57,34 +57,6 @@ } } - function close_poll(poll_id) - { - $('#ajax-modal').html("
    " + - "
    " + - "
    " + - "

    问卷关闭后学生将不能继续提交问卷,
    是否确定关闭该问卷?

    " + - "
    " + - "确  定" + - "取  消" + - "
    " + - "
    " + - "
    " + - "
    " + - "
    "); - showModal('ajax-modal', '310px'); - $('#ajax-modal').css('height','120px'); - $('#ajax-modal').siblings().remove(); - $('#ajax-modal').before("" + - ""); - $('#ajax-modal').parent().removeClass("alert_praise"); - $('#ajax-modal').parent().css("top","").css("left",""); - $('#ajax-modal').parent().addClass("popbox_polls"); - } - - function closeModal() - { - hideModal($("#popbox_upload")); - }
    <%= render :partial => 'exercises_list'%> From 7dc16775dcaa7902a145007a899bf02bdf7e9366 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 20:44:01 +0800 Subject: [PATCH 55/83] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...51119124148_add_end_at_to_exercise_user.rb | 5 ++ db/schema.rb | 55 +------------------ 2 files changed, 7 insertions(+), 53 deletions(-) create mode 100644 db/migrate/20151119124148_add_end_at_to_exercise_user.rb diff --git a/db/migrate/20151119124148_add_end_at_to_exercise_user.rb b/db/migrate/20151119124148_add_end_at_to_exercise_user.rb new file mode 100644 index 000000000..db4cc4c47 --- /dev/null +++ b/db/migrate/20151119124148_add_end_at_to_exercise_user.rb @@ -0,0 +1,5 @@ +class AddEndAtToExerciseUser < ActiveRecord::Migration + def change + add_column :exercise_users, :end_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 07dac5706..042058c5a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20151118015638) do +ActiveRecord::Schema.define(:version => 20151119124148) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -241,58 +241,6 @@ ActiveRecord::Schema.define(:version => 20151118015638) do add_index "changesets_issues", ["changeset_id", "issue_id"], :name => "changesets_issues_ids", :unique => true - create_table "code_review_assignments", :force => true do |t| - t.integer "issue_id" - t.integer "change_id" - t.integer "attachment_id" - t.string "file_path" - t.string "rev" - t.string "rev_to" - t.string "action_type" - t.integer "changeset_id" - end - - create_table "code_review_project_settings", :force => true do |t| - t.integer "project_id" - t.integer "tracker_id" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "updated_by" - t.boolean "hide_code_review_tab", :default => false - t.integer "auto_relation", :default => 1 - t.integer "assignment_tracker_id" - t.text "auto_assign" - t.integer "lock_version", :default => 0, :null => false - t.boolean "tracker_in_review_dialog", :default => false - end - - create_table "code_review_user_settings", :force => true do |t| - t.integer "user_id", :default => 0, :null => false - t.integer "mail_notification", :default => 0, :null => false - t.datetime "created_at" - t.datetime "updated_at" - end - - create_table "code_reviews", :force => true do |t| - t.integer "project_id" - t.integer "change_id" - t.datetime "created_at" - t.datetime "updated_at" - t.integer "line" - t.integer "updated_by_id" - t.integer "lock_version", :default => 0, :null => false - t.integer "status_changed_from" - t.integer "status_changed_to" - t.integer "issue_id" - t.string "action_type" - t.string "file_path" - t.string "rev" - t.string "rev_to" - t.integer "attachment_id" - t.integer "file_count", :default => 0, :null => false - t.boolean "diff_all" - end - create_table "comments", :force => true do |t| t.string "commented_type", :limit => 30, :default => "", :null => false t.integer "commented_id", :default => 0, :null => false @@ -614,6 +562,7 @@ ActiveRecord::Schema.define(:version => 20151118015638) do t.datetime "start_at" t.datetime "created_at", :null => false t.datetime "updated_at", :null => false + t.datetime "end_at" end create_table "exercises", :force => true do |t| From 9aee23507c43df0fca15bd5de423b8803795bed3 Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 19 Nov 2015 21:19:18 +0800 Subject: [PATCH 56/83] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E7=AD=94=E9=A2=98?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E3=80=81=E7=AD=94=E9=A2=98=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E3=80=81=E8=80=81=E5=B8=88=E7=9A=84=E8=AF=95?= =?UTF-8?q?=E5=8D=B7=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 6 +- app/helpers/exercise_helper.rb | 19 +++ app/views/exercise/_commit_alert.html.erb | 12 ++ app/views/exercise/_exercise_student.html.erb | 103 +++++++++---- .../_exercise_student_result.html.erb | 135 ++++++++++++++++++ app/views/exercise/_exercise_submit.html.erb | 3 +- app/views/exercise/_exercise_teacher.html.erb | 117 +++++++++++++++ app/views/exercise/_new_MC.html.erb | 6 +- app/views/exercise/_new_MCQ.html.erb | 6 +- app/views/exercise/_new_single.html.erb | 6 +- app/views/exercise/_show_MC.html.erb | 2 +- app/views/exercise/_show_MCQ.html.erb | 2 +- app/views/exercise/_show_single.html.erb | 2 +- app/views/exercise/commit_exercise.js.erb | 9 ++ app/views/exercise/show.html.erb | 8 +- .../exercise/update_exercise_question.js.erb | 2 +- 16 files changed, 390 insertions(+), 48 deletions(-) create mode 100644 app/views/exercise/_commit_alert.html.erb create mode 100644 app/views/exercise/_exercise_student_result.html.erb create mode 100644 app/views/exercise/_exercise_teacher.html.erb create mode 100644 app/views/exercise/commit_exercise.js.erb diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 18248331c..69e8ebd80 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -374,7 +374,7 @@ class ExerciseController < ApplicationController ea.answer_text = params[:answer_text] if ea.save @percent = get_percent(@exercise,User.current) - render :json => {:text => pv.vote_text,:percent => format("%.2f",@percent)} + render :json => {:text => ea.answer_text,:percent => format("%.2f",@percent)} else render :json => {:text => "failure"} end @@ -416,13 +416,13 @@ class ExerciseController < ApplicationController # 答题过程中需要统计完成量 @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 - score = calculate_student_score(@exercise, User.current) + @score = calculate_student_score(@exercise, User.current) if @uncomplete_question.count < 1 # 查看是否有已提交记录 eu = get_exercise_user(@exercise.id, User.current.id) eu.user_id = User.current.id eu.exercise_id = @exercise.id - eu.score = score + eu.score = @score if eu.save #redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course') @status = 0 #提交成功 diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 7f3d1862e..5b28234e8 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -72,4 +72,23 @@ module ExerciseHelper return score end + def answer_be_selected?(answer,user) + pv = answer.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id} ") + if !pv.nil? && pv.count > 0 + true + else + false + end + end + + #获取文本题答案 + def get_anwser_vote_text(question_id,user_id) + pv = ExerciseAnswer.find_by_exercise_question_id_and_user_id(question_id,user_id) + if pv.nil? + '' + else + pv.answer_text + end + end + end \ No newline at end of file diff --git a/app/views/exercise/_commit_alert.html.erb b/app/views/exercise/_commit_alert.html.erb new file mode 100644 index 000000000..d92ca51fb --- /dev/null +++ b/app/views/exercise/_commit_alert.html.erb @@ -0,0 +1,12 @@ +
    + <% if status == 0 %> +

    提交成功!您的分数是:<%=@score %>分。

    + <%= link_to "确定", exercise_path(),:class => 'commit'%> + <% elsif status == 1 %> +

    您还有尚未作答的题目请完成后再提交!

    + <%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%> + <% else %> +

    发生未知错误,请检查您的网络。

    + <%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%> + <% end %> +
    diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb index 5a139fd5d..0cc34958f 100644 --- a/app/views/exercise/_exercise_student.html.erb +++ b/app/views/exercise/_exercise_student.html.erb @@ -4,33 +4,15 @@ $("#homework_page_right").css("min-height",$("#LSide").height()-30); $("#Container").css("width","1000px"); }); - function click_<%= pa.id %>(obj) - { - $.ajax({ - type: "post", - url: "<%= commit_answer_poll_path(@poll) %>", - data: { - poll_answer_id: <%= pa.id %>, - poll_question_id: <%= pq.id %> - }, - success: function (data) { - var dataObj = eval(data); - obj.checked = true; - var span = $('#percent'); - span.html(dataObj.percent); - } - }); - } - function student_submit_exercise(){ - - }

    <%= exercise.exercise_name%>

    -
    开始时间:<%=format_time(exercise_student.start_at.to_s) %>测验时长:<%=exercise.time %>分钟 -
    剩余时长:1 小时 30 分钟 0 秒
    +
    + 开始时间:<%=format_time(exercise_user.start_at.to_s) %> + 测验时长:<%=exercise.time %>分钟 + 剩余时长:1 小时 30 分钟 0 秒
    <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
    @@ -56,7 +38,31 @@ @@ -87,7 +93,31 @@ @@ -112,14 +142,35 @@
    - + + >
    <% end %>
    - +
    + <%= link_to l(:button_submit),commit_exercise_exercise_path(exercise), :method => :post,:class => "ur_button_submit",:style => "margin-left:80px;",:format => 'js',:remote=>true %> +
    diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb new file mode 100644 index 000000000..40f9b953b --- /dev/null +++ b/app/views/exercise/_exercise_student_result.html.erb @@ -0,0 +1,135 @@ + +
    +
    +
    +

    <%= exercise.exercise_name%>

    +
    + 开始时间:<%=format_time(exercise_user.start_at.to_s) %> + 测验时长:<%=exercise.time %>分钟 + <% time = exercise_user.end_at - exercise_user.start_at %> + 测验用时:<%= (time % (24*60*60)) / (60*60)%> 小时 <%= ((time % (24*60*60)) % (60*60)) / 60%> 分钟 <%= ((time % (24*60*60)) % (60*60)) % 60%> 秒 +
    +
    <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
    +
    +
    +
    得分:<%=exercise_user.score %>分
    + <% mc_question_list = exercise_questions.where("question_type=1") %> + <% mcq_question_list = exercise_questions.where("question_type=2") %> + <% single_question_list = exercise_questions.where("question_type=3") %> +
    "> +

    单选题

    + <% mc_question_list.each do |exercise_question| %> +
    +
    +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %> + + <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> + √ + <% else %> + × + <% end %>
    + 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
    +
    +
    + + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
    + +
    +
    +
    +
    +
    + <% end %> +
    +
    "> +

    多选题

    + <% mcq_question_list.each do |exercise_question| %> +
    +
    +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %> + + <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> + √ + <% else %> + × + <% end %>
    + 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
    +
    +
    + + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
    + +
    +
    +
    +
    +
    + <% end %> +
    +
    "> +

    填空题

    + <% single_question_list.each do |exercise_question| %> +
    +
    +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %> + + <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> + √ + <% else %> + × + <% end %>
    + 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
    +
    +
    + <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> + 候选答案:<%= exercise_choice.answer_text%>
    + <% end %> +
    +
    + > +
    +
    +
    +
    + <% end %> +
    +
    + +
    + +
    \ No newline at end of file diff --git a/app/views/exercise/_exercise_submit.html.erb b/app/views/exercise/_exercise_submit.html.erb index e242eacc7..a8892b27e 100644 --- a/app/views/exercise/_exercise_submit.html.erb +++ b/app/views/exercise/_exercise_submit.html.erb @@ -1,7 +1,8 @@ <%= form_for("", :html => { :multipart => true }, :url => {:controller => 'exercise', - :action => 'commit_exercise' + :action => 'commit_exercise', + :id => exercise.id },:remote=>true ) do |f| %>
    提交 diff --git a/app/views/exercise/_exercise_teacher.html.erb b/app/views/exercise/_exercise_teacher.html.erb new file mode 100644 index 000000000..18f62e403 --- /dev/null +++ b/app/views/exercise/_exercise_teacher.html.erb @@ -0,0 +1,117 @@ + +
    +
    +
    +

    <%= exercise.exercise_name%>

    +
    + 发布时间:<%=format_time(exercise.publish_time.to_s) %> + 截止时间:<%=format_time(exercise.end_time.to_s) %> + <% time = exercise_user.end_at - exercise_user.start_at %> + 测验时长:<%=exercise.time %>分钟 +
    +
    <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
    +
    +
    + <% mc_question_list = exercise_questions.where("question_type=1") %> + <% mcq_question_list = exercise_questions.where("question_type=2") %> + <% single_question_list = exercise_questions.where("question_type=3") %> +
    "> +

    单选题

    + <% mc_question_list.each do |exercise_question| %> +
    +
    +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %>
    + 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
    +
    +
    + + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
    + +
    +
    +
    +
    +
    + <% end %> +
    +
    "> +

    多选题

    + <% mcq_question_list.each do |exercise_question| %> +
    +
    +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %>
    + 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
    +
    +
    + + + <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> + + + + <% end %> + +
    + +
    +
    +
    +
    +
    + <% end %> +
    +
    "> +

    填空题

    + <% single_question_list.each do |exercise_question| %> +
    +
    +
    +
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    + <%= exercise_question.question_title %>
    + 标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %> +
    +
    +
    + <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> + 候选答案:<%= exercise_choice.answer_text%>
    + <% end %> +
    +
    +
    +
    + <% end %> +
    +
    + <%= link_to l(:button_submit),exercise_index_path(:course_id => @course.id),:class => "ur_button_submit" %> + <%= link_to l(:button_edit), edit_exercise_path(exercise.id), :class => "ur_button_submit fr"%> +
    +
    + +
    + +
    \ 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 3da0021ce..0b9543009 100644 --- a/app/views/exercise/_new_MC.html.erb +++ b/app/views/exercise/_new_MC.html.erb @@ -1,9 +1,7 @@ <%= form_for(ExerciseQuestion.new, :html => { :multipart => true }, - :url => {:controller => 'exercise', - :action => 'create_exercise_question', - :course_id => @course.id - },:remote=>true ) do |f| %> + :url=>create_exercise_question_exercise_path(exercise_question.id), + :remote=>true ) do |f| %>
    diff --git a/app/views/exercise/_new_MCQ.html.erb b/app/views/exercise/_new_MCQ.html.erb index 044ecd629..2f1f28395 100644 --- a/app/views/exercise/_new_MCQ.html.erb +++ b/app/views/exercise/_new_MCQ.html.erb @@ -1,9 +1,7 @@ <%= form_for(ExerciseQuestion.new, :html => { :multipart => true }, - :url => {:controller => 'exercise', - :action => 'create_exercise_question', - :course_id => @course.id - },:remote=>true ) do |f| %> + :url=>create_exercise_question_exercise_path(exercise_question.id), + :remote=>true ) do |f| %>
    diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index 6e088cd74..ec52fbcad 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -1,9 +1,7 @@ <%= form_for(ExerciseQuestion.new, :html => { :multipart => true }, - :url => {:controller => 'exercise', - :action => 'create_exercise_question', - :course_id => @course.id - },:remote=>true ) do |f| %> + :url=>create_exercise_question_exercise_path(exercise_question.id), + :remote=>true ) do |f| %>
    diff --git a/app/views/exercise/_show_MC.html.erb b/app/views/exercise/_show_MC.html.erb index 21d6ef4bb..0883995dc 100644 --- a/app/views/exercise/_show_MC.html.erb +++ b/app/views/exercise/_show_MC.html.erb @@ -39,7 +39,7 @@ } else{ <% score =exercise_question.question_score %> $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ + '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>create_exercise_question_exercise_path(exercise_question.id),:remote=>true) do |f|%>'+ '
    '+ '
    '+ ''+ diff --git a/app/views/exercise/_show_MCQ.html.erb b/app/views/exercise/_show_MCQ.html.erb index a6ffbeb82..52f01e6c7 100644 --- a/app/views/exercise/_show_MCQ.html.erb +++ b/app/views/exercise/_show_MCQ.html.erb @@ -38,7 +38,7 @@ } else { <% score =exercise_question.question_score %> $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ + '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>create_exercise_question_exercise_path(exercise_question.id),:remote=>true) do |f|%>'+ '
    '+ '
    '+ ''+ diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 30a0e354c..933f2edcc 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -26,7 +26,7 @@ } else { <% score =exercise_question.question_score %> $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html( - '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>{:controller=> 'exercise',:action=>'create_exercise_question',:course_id=>@course.id},:remote=>true) do |f|%>'+ + '<%= form_for(ExerciseQuestion.new,:html=>{:multipart=>true},:url=>create_exercise_question_exercise_path(exercise_question.id),:remote=>true) do |f|%>'+ '
    '+ '
    '+ ''+ diff --git a/app/views/exercise/commit_exercise.js.erb b/app/views/exercise/commit_exercise.js.erb new file mode 100644 index 000000000..2a40df2a5 --- /dev/null +++ b/app/views/exercise/commit_exercise.js.erb @@ -0,0 +1,9 @@ +$('#ajax-modal').html('<%= escape_javascript(render :partial => 'commit_alert',:locals => {:status => @status}) %>'); +showModal('ajax-modal', '270px'); +$('#ajax-modal').css('height','110px'); +$('#ajax-modal').siblings().remove(); +$('#ajax-modal').before("" + + ""); +$('#ajax-modal').parent().removeClass("alert_praise"); +$('#ajax-modal').parent().css("top","").css("left",""); +$('#ajax-modal').parent().addClass("alert_box"); \ No newline at end of file diff --git a/app/views/exercise/show.html.erb b/app/views/exercise/show.html.erb index 6638020d1..cee9b084c 100644 --- a/app/views/exercise/show.html.erb +++ b/app/views/exercise/show.html.erb @@ -1,5 +1,9 @@ <% if @is_teacher %> - + <%= render :partial => 'exercise_teacher', :locals =>{:exercise =>@exercise, :exercise_questions => @exercise_questions} %> <% else %> - <%=render :partial => 'exercise_student', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_student => @exercise_student} %> + <% if @can_edit_excercise %> + <%=render :partial => 'exercise_student', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_user => @exercise_user} %> + <% else %> + <%=render :partial => 'exercise_student_result', :locals => {:exercise =>@exercise, :exercise_questions => @exercise_questions,:exercise_user => @exercise_user} %> + <% end %> <% end %> \ No newline at end of file diff --git a/app/views/exercise/update_exercise_question.js.erb b/app/views/exercise/update_exercise_question.js.erb index 73aea3140..ef9004c06 100644 --- a/app/views/exercise/update_exercise_question.js.erb +++ b/app/views/exercise/update_exercise_question.js.erb @@ -17,4 +17,4 @@ $("#poll_questions_<%= @exercise_question.id%>").html("
    {:exercise => @exercise}) %>"); +$("#exercise_submit").html("<%= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise_question.exercise}) %>"); From 81e28272774ef3f0455dce8a93757bdb66bd1a8f Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Nov 2015 21:21:02 +0800 Subject: [PATCH 57/83] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 4 ++-- app/helpers/exercise_helper.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index d13c02d27..4941e63ac 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -449,11 +449,11 @@ class ExerciseController < ApplicationController # 问答题有多个答案 if question.question_type == 3 if standard_answer.exercise_choice_id.include?(answer.exercise_choice_id) - score = score + question.question_score + score += question.question_score unless question.question_score.empty? end else if answer.exercise_choice_id == standard_answer.exercise_choice_id - score = score + question.question_score + score += question.question_score unless question.question_score.empty? end end end diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 7f3d1862e..6cf89cdb8 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -65,7 +65,9 @@ module ExerciseHelper score = 0 unless exercise.nil? exercise.exercise_questions.each do |exercise_question| - score += exercise_question.question_score + unless exercise_question.question_score.nil? + score += exercise_question.question_score + end end return score end From d583ca1d7073ea034fb39444935e171f89c338a7 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 20 Nov 2015 09:54:46 +0800 Subject: [PATCH 58/83] =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_exercise_submit.html.erb | 7 +++---- app/views/exercise/_exercise_submit_info.html.erb | 14 ++++++++++++-- app/views/exercise/_exercise_teacher.html.erb | 11 +++++------ app/views/exercise/_new_MC.html.erb | 2 +- app/views/exercise/_new_MCQ.html.erb | 2 +- app/views/exercise/_new_single.html.erb | 2 +- app/views/exercise/show.html.erb | 1 + 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/views/exercise/_exercise_submit.html.erb b/app/views/exercise/_exercise_submit.html.erb index a8892b27e..a28c8917b 100644 --- a/app/views/exercise/_exercise_submit.html.erb +++ b/app/views/exercise/_exercise_submit.html.erb @@ -16,15 +16,14 @@
    @@ -50,7 +53,7 @@ }, success: function (data) { var dataObj = eval(data); - if(dataObj.text == "true") + if(dataObj.text == "ok") { obj.checked = true; } @@ -105,7 +108,7 @@ }, success: function (data) { var dataObj = eval(data); - if(dataObj.text == "true") + if(dataObj.text == "ok") { obj.checked = true; } @@ -117,7 +120,7 @@ }); } - <%= @can_edit_poll?"":"disabled=disabled" %> > + <%= @can_edit_excercise?"":"disabled=disabled" %> > <%= convert_to_char((index+1).to_s)%>  <%= exercise_choice.choice_text%> diff --git a/app/views/exercise/_exercise_submit.html.erb b/app/views/exercise/_exercise_submit.html.erb index a28c8917b..e9c26a0b5 100644 --- a/app/views/exercise/_exercise_submit.html.erb +++ b/app/views/exercise/_exercise_submit.html.erb @@ -7,7 +7,7 @@
    提交
    - +
    diff --git a/db/schema.rb b/db/schema.rb index 14f4f5eea..ca4e1cad0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -241,6 +241,58 @@ ActiveRecord::Schema.define(:version => 20151120021958) do add_index "changesets_issues", ["changeset_id", "issue_id"], :name => "changesets_issues_ids", :unique => true + create_table "code_review_assignments", :force => true do |t| + t.integer "issue_id" + t.integer "change_id" + t.integer "attachment_id" + t.string "file_path" + t.string "rev" + t.string "rev_to" + t.string "action_type" + t.integer "changeset_id" + end + + create_table "code_review_project_settings", :force => true do |t| + t.integer "project_id" + t.integer "tracker_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "updated_by" + t.boolean "hide_code_review_tab", :default => false + t.integer "auto_relation", :default => 1 + t.integer "assignment_tracker_id" + t.text "auto_assign" + t.integer "lock_version", :default => 0, :null => false + t.boolean "tracker_in_review_dialog", :default => false + end + + create_table "code_review_user_settings", :force => true do |t| + t.integer "user_id", :default => 0, :null => false + t.integer "mail_notification", :default => 0, :null => false + t.datetime "created_at" + t.datetime "updated_at" + end + + create_table "code_reviews", :force => true do |t| + t.integer "project_id" + t.integer "change_id" + t.datetime "created_at" + t.datetime "updated_at" + t.integer "line" + t.integer "updated_by_id" + t.integer "lock_version", :default => 0, :null => false + t.integer "status_changed_from" + t.integer "status_changed_to" + t.integer "issue_id" + t.string "action_type" + t.string "file_path" + t.string "rev" + t.string "rev_to" + t.integer "attachment_id" + t.integer "file_count", :default => 0, :null => false + t.boolean "diff_all" + end + create_table "comments", :force => true do |t| t.string "commented_type", :limit => 30, :default => "", :null => false t.integer "commented_id", :default => 0, :null => false From 13af6e64b272d141729386877a15c19fe5bae4e5 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 12:55:23 +0800 Subject: [PATCH 63/83] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=81=E8=AE=B8?= =?UTF-8?q?=E5=AD=A6=E7=94=9F=E6=9F=A5=E7=9C=8B=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index c3e5d9a67..77302c5db 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -419,7 +419,7 @@ class ExerciseController < ApplicationController def commit_exercise # 老师不需要提交 if User.current.allowed_to?(:as_teacher,@course) - + @exercise.update_attributes(:show_result => params[:exercise][:show_result]) redirect_to exercise_url(@exercise) # REDO: 提示提交成功 else From 302dfaf93380ef24179f3ff0fd1b8522063e5b01 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 13:04:51 +0800 Subject: [PATCH 64/83] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E4=B8=87=E5=8D=B7?= =?UTF-8?q?=E5=88=9D=E5=A7=8Bshowresult?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 54f8309ea..3d6b4794f 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -59,7 +59,8 @@ class ExerciseController < ApplicationController :end_time => "", :publish_time => "", :exercise_description => "", - :show_result => "" + :show_result => "", + :show_result => 1 } @exercise = Exercise.create option if @exercise From 07ee81937056274fd0a1b38c68408673bce1511d Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 13:39:40 +0800 Subject: [PATCH 65/83] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E7=AD=94=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 3d6b4794f..9efcfc19d 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -345,7 +345,7 @@ class ExerciseController < ApplicationController end elsif eq.question_type == 2 #多选题 - ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id) + ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id) if ea.nil? #尚未答该题,添加答案 ea = ExerciseAnswer.new @@ -360,7 +360,7 @@ class ExerciseController < ApplicationController end else #pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案 - if pv.delete + if ea.delete @percent = get_percent(@exercise, User.current) render :json => {:text => "false" ,:percent => format("%.2f" , @percent)} else From cb3f0d1c97844d2a7fb62053be688425be185aea Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 14:28:47 +0800 Subject: [PATCH 66/83] =?UTF-8?q?=E6=8C=89=E7=B1=BB=E5=9E=8B=E5=88=86?= =?UTF-8?q?=E7=B1=BB=EF=BC=8C=E5=BA=8F=E5=8F=B7=E9=80=92=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 9efcfc19d..cf78cbc05 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -142,7 +142,9 @@ class ExerciseController < ApplicationController option = { :question_title => question_title, :question_type => params[:question_type] || 1, - :question_number => @exercise.exercise_questions.count + 1, + :question_number => params[:question_type] == "1"? @exercise.exercise_questions.where("question_type = 1").count + 1 : + (params[:question_type] == "2" ? (@exercise.exercise_questions.where("question_type = 2").count + 1) : + @exercise.exercise_questions.where("question_type = 3").count + 1), :question_score => params[:question_score] } @exercise_questions = @exercise.exercise_questions.new option @@ -160,7 +162,14 @@ class ExerciseController < ApplicationController # 如果是插入的话,那么从插入的这个id以后的question_num都将要+1 if params[:quest_id] @is_insert = true - @exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i}").update_all(" question_number = question_number + 1") + if @exercise_questions.question_type == 1 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1") + #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1") + elsif @exercise_questions.question_type == 2 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number + 1") + else + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number + 1") + end # @exercise_question_num = params[:quest_num].to_i @exercise_questions.question_number = params[:quest_num].to_i + 1 end From 863d7ed4b55ab286aea776bf4a7dabc6972f2348 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 20 Nov 2015 14:34:09 +0800 Subject: [PATCH 67/83] =?UTF-8?q?=E5=8D=95=E9=80=89=E5=92=8C=E5=A1=AB?= =?UTF-8?q?=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_exercise_student.html.erb | 37 +++++++++++++------ app/views/exercise/_exercise_submit.html.erb | 8 ++-- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb index 0b12b917e..68222f8bd 100644 --- a/app/views/exercise/_exercise_student.html.erb +++ b/app/views/exercise/_exercise_student.html.erb @@ -3,9 +3,24 @@ $("#RSide").removeAttr("id"); $("#homework_page_right").css("min-height",$("#LSide").height()-30); $("#Container").css("width","1000px"); + var time = <%=exercise.time %>; + var total_seconds = time * 60; + getTime(total_seconds); }); - function getTime() { - + function getTime(total_seconds) { + var total_seconds = total_seconds - 1; + var hours = total_seconds / 60 / 60; + var hoursRound = Math.floor(hours); + var minutes = total_seconds /60 - (60 * hoursRound); + var minutesRound = Math.floor(minutes); + var seconds = total_seconds - (60 * 60 * hoursRound) - (60 * minutesRound); + var secondsRound = Math.round(seconds); + $("#rest_hours").html(hoursRound); + $("#rest_minutes").html(minutesRound); + $("#rest_seconds").html(secondsRound); + if(total_seconds >0) { + setTimeout("getTime("+total_seconds+");", 1000); + } }
    @@ -15,7 +30,7 @@
    开始时间:<%=format_time(exercise_user.start_at.to_s) %> 测验时长:<%=exercise.time %>分钟 - 剩余时长:1 小时 30 分钟 0 秒 + 剩余时长: 小时  分钟  秒
    <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
    @@ -26,11 +41,11 @@ <% single_question_list = exercise.exercise_questions.where("question_type=3") %>
    ">

    单选题

    - <% mc_question_list.each do |exercise_question| %> + <% mc_question_list.each_with_index do |exercise_question, list_index| %>
    -
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    +
    第<%= list_index+1%>题.(<%= exercise_question.question_score %>分)
    <%= exercise_question.question_title %>
    @@ -65,7 +80,7 @@ }); } - <%= radio_button "poll_vote","poll_answer_id",exercise_choice.id,:class=>"ur_radio",:onclick =>"click_#{exercise_choice.id}(this);return false;",:checked => answer_be_selected?(exercise_choice,User.current),:disabled => !@can_edit_excercise %> + <%= radio_button "exercise",exercise_question.id.to_s+"exercise_choice_id",exercise_choice.id,:class=>"ur_radio",:onclick =>"click_#{exercise_choice.id}(this);return false;",:checked => answer_be_selected?(exercise_choice,User.current),:disabled => !@can_edit_excercise %> <%= convert_to_char((index+1).to_s)%>  <%= exercise_choice.choice_text%> @@ -81,11 +96,11 @@
    ">

    多选题

    - <% mcq_question_list.each do |exercise_question| %> + <% mcq_question_list.each_with_index do |exercise_question,list_index| %>
    -
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    +
    第<%= list_index + 1 %>题.(<%= exercise_question.question_score %>分)
    <%= exercise_question.question_title %>
    @@ -136,11 +151,11 @@
    ">

    填空题

    - <% single_question_list.each do |exercise_question| %> + <% single_question_list.each_with_index do |exercise_question, list_index| %>
    -
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    +
    第<%= list_index + 1%>题.(<%= exercise_question.question_score %>分)
    <%= exercise_question.question_title %>
    @@ -164,7 +179,7 @@ } - > + >
    diff --git a/app/views/exercise/_exercise_submit.html.erb b/app/views/exercise/_exercise_submit.html.erb index e9c26a0b5..acbbea244 100644 --- a/app/views/exercise/_exercise_submit.html.erb +++ b/app/views/exercise/_exercise_submit.html.erb @@ -1,4 +1,4 @@ -<%= form_for("", +<%= form_for(exercise, :html => { :multipart => true }, :url => {:controller => 'exercise', :action => 'commit_exercise', @@ -7,8 +7,10 @@
    提交
    - - + <%= f.check_box :show_result, :value => exercise.show_result%> + <%= label_tag 'exercise_show_result', '允许学生查看测验结果' %> +
    <% end %> From b0730dfb818ec5a441912839ca966d543998a271 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 20 Nov 2015 15:12:07 +0800 Subject: [PATCH 68/83] =?UTF-8?q?=E6=B5=8B=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_exercise_student.html.erb | 25 +++++++++++-------- .../_exercise_student_result.html.erb | 15 +++++------ app/views/exercise/_exercise_teacher.html.erb | 18 ++++++------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb index 68222f8bd..af9896b01 100644 --- a/app/views/exercise/_exercise_student.html.erb +++ b/app/views/exercise/_exercise_student.html.erb @@ -8,6 +8,11 @@ getTime(total_seconds); }); function getTime(total_seconds) { + start_time = new Date($("#start_time").html()); + end_time = start_time + 60*60*<%=exercise.time %>; + now = new Date(); + //start = new Date(start_time); + //end_time = start_time; var total_seconds = total_seconds - 1; var hours = total_seconds / 60 / 60; var hoursRound = Math.floor(hours); @@ -27,8 +32,9 @@

    <%= exercise.exercise_name%>

    +
    - 开始时间:<%=format_time(exercise_user.start_at.to_s) %> + 开始时间:<%=format_time(exercise_user.start_at.to_s)%> 测验时长:<%=exercise.time %>分钟 剩余时长: 小时  分钟  秒
    @@ -36,17 +42,16 @@
    - <% mc_question_list = exercise.exercise_questions.where("question_type=1") %> - <% mcq_question_list = exercise.exercise_questions.where("question_type=2") %> - <% single_question_list = exercise.exercise_questions.where("question_type=3") %> + <% mc_question_list = exercise.exercise_questions.where("question_type=1").shuffle %> + <% mcq_question_list = exercise.exercise_questions.where("question_type=2").shuffle %> + <% single_question_list = exercise.exercise_questions.where("question_type=3").shuffle %>
    ">

    单选题

    <% mc_question_list.each_with_index do |exercise_question, list_index| %>
    -
    第<%= list_index+1%>题.(<%= exercise_question.question_score %>分)
    - <%= exercise_question.question_title %> +
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分)
    @@ -100,8 +105,7 @@
    -
    第<%= list_index + 1 %>题.(<%= exercise_question.question_score %>分)
    - <%= exercise_question.question_title %> +
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分)
    @@ -155,8 +159,7 @@
    -
    第<%= list_index + 1%>题.(<%= exercise_question.question_score %>分)
    - <%= exercise_question.question_title %> +
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分)
    @@ -173,7 +176,7 @@ }, success: function (data) { var dataObj = eval(data); -// obj.value = dataObj.text; + obj.value = dataObj.text; } }); diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb index 8a723d75c..9ce136667 100644 --- a/app/views/exercise/_exercise_student_result.html.erb +++ b/app/views/exercise/_exercise_student_result.html.erb @@ -24,12 +24,11 @@ <% single_question_list = exercise.exercise_questions.where("question_type=3") %>
    ">

    单选题

    - <% mc_question_list.each do |exercise_question| %> + <% mc_question_list.each_with_index do |exercise_question, list_index| %>
    -
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    - <%= exercise_question.question_title %> +
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> √ @@ -62,12 +61,11 @@
    ">

    多选题

    - <% mcq_question_list.each do |exercise_question| %> + <% mcq_question_list.each_wtih_index do |exercise_question, list_index| %>
    -
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    - <%= exercise_question.question_title %> +
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> √ @@ -100,12 +98,11 @@
    ">

    填空题

    - <% single_question_list.each do |exercise_question| %> + <% single_question_list.each_with_index do |exercise_question,list_index| %>
    -
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    - <%= exercise_question.question_title %> +
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> √ diff --git a/app/views/exercise/_exercise_teacher.html.erb b/app/views/exercise/_exercise_teacher.html.erb index b803519ce..606b14aae 100644 --- a/app/views/exercise/_exercise_teacher.html.erb +++ b/app/views/exercise/_exercise_teacher.html.erb @@ -22,12 +22,12 @@ <% single_question_list = exercise.exercise_questions.where("question_type=3") %>
    ">

    单选题

    - <% mc_question_list.each do |exercise_question| %> + <% mc_question_list.each_with_index do |exercise_question, list_index| %>
    -
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    - <%= exercise_question.question_title %>
    +
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) +
    标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %>
    @@ -54,12 +54,12 @@
    ">

    多选题

    - <% mcq_question_list.each do |exercise_question| %> + <% mcq_question_list.each_with_index do |exercise_question, index| %>
    -
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    - <%= exercise_question.question_title %>
    +
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) +
    标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %>
    @@ -86,12 +86,12 @@
    ">

    填空题

    - <% single_question_list.each do |exercise_question| %> + <% single_question_list.each_with_index do |exercise_question, list_index| %>
    -
    第<%= exercise_question.question_number%>题.(<%= exercise_question.question_score %>分)
    - <%= exercise_question.question_title %>
    +
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) +
    标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %>
    From db46e5e4afb172cd5499f1bbc3bdcfe3628b71a5 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 15:13:53 +0800 Subject: [PATCH 69/83] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E5=BE=97=E5=88=86?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 11 +++++++++-- app/helpers/exercise_helper.rb | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index cf78cbc05..04189af6a 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -467,7 +467,7 @@ class ExerciseController < ApplicationController standard_answer = get_user_standard_answer(question, user) # 问答题有多个答案 if question.question_type == 3 - if standard_answer.exercise_choice_id.include?(answer.exercise_choice_id) + if standard_answer.include?(answer.exercise_choice_id) score += question.question_score unless question.question_score.empty? end else @@ -510,7 +510,14 @@ class ExerciseController < ApplicationController # 获取问题的标准答案 def get_user_standard_answer(question,user) - standard_answer = question.exercise_standard_answers + if question.question_type == 3 + standard_answer =[] + question.exercise_standard_answers.each do |answer| + standard_answer << answer.answer_text + end + else + standard_answer = question.exercise_standard_answers + end standard_answer end diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index ec7421533..d67f4443f 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -28,6 +28,7 @@ module ExerciseHelper answer.join("") end + # def fill_standart_answer(params, standart_answer) params.each do |param| standart_answer.answer_text = param.value From ed86e3ee5a6a8e3b1002eed90a7865bcf5b23d11 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 17:18:57 +0800 Subject: [PATCH 70/83] =?UTF-8?q?=E4=B8=89=E7=A7=8D=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E9=A2=98=E7=9B=AE=E8=AE=A1=E7=AE=97=E6=80=BB=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 40 ++++++++++++++----- app/views/exercise/_exercise_teacher.html.erb | 2 +- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 04189af6a..2c70757fa 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -437,6 +437,7 @@ class ExerciseController < ApplicationController @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 @score = calculate_student_score(@exercise, User.current) + # @score = 100 if @uncomplete_question.count < 1 # 查看是否有已提交记录 eu = get_exercise_user(@exercise.id, User.current.id) @@ -461,22 +462,38 @@ class ExerciseController < ApplicationController # 计算学生得分 def calculate_student_score(exercise, user) score = 0 + score1 = 0 + score2 = 0 + score3 = 0 exercise_qustions = exercise.exercise_questions exercise_qustions.each do |question| answer = get_user_answer(question, user) standard_answer = get_user_standard_answer(question, user) - # 问答题有多个答案 - if question.question_type == 3 - if standard_answer.include?(answer.exercise_choice_id) - score += question.question_score unless question.question_score.empty? - end - else - if answer.exercise_choice_id == standard_answer.exercise_choice_id - score += question.question_score unless question.question_score.empty? + unless answer.nil? + # 问答题有多个答案 + if question.question_type == 3 + if standard_answer.include?(answer.first.answer_text) + score1 = score+ question.question_score unless question.question_score.nil? + end + elsif question.question_type == 1 + if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id + score2 = score + question.question_score unless question.question_score.nil? + end + else + ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + arr = [] + ecs.each do |ec| + arr << ec.exercise_choice.choice_position + end + arr.sort + arr = arr.join("") + if arr.to_i == standard_answer.exercise_choice_id + score3 = score + question.question_score unless question.question_score.nil? + end end end end - score + score = score1 + score2 + score3 end private @@ -495,7 +512,7 @@ class ExerciseController < ApplicationController uncomplete_question = [] all_questions.each do |question| answers = get_user_answer(question, user) - if answers.nil? || answers.count < 1 + if answers.nil? uncomplete_question << question end end @@ -504,6 +521,7 @@ class ExerciseController < ApplicationController # 获取当前学生回答问题的答案 def get_user_answer(question,user) + # user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") user_answer end @@ -516,7 +534,7 @@ class ExerciseController < ApplicationController standard_answer << answer.answer_text end else - standard_answer = question.exercise_standard_answers + standard_answer = question.exercise_standard_answers.first end standard_answer end diff --git a/app/views/exercise/_exercise_teacher.html.erb b/app/views/exercise/_exercise_teacher.html.erb index 606b14aae..a3f6380cf 100644 --- a/app/views/exercise/_exercise_teacher.html.erb +++ b/app/views/exercise/_exercise_teacher.html.erb @@ -54,7 +54,7 @@
    ">

    多选题

    - <% mcq_question_list.each_with_index do |exercise_question, index| %> + <% mcq_question_list.each_with_index do |exercise_question, list_index| %>
    From eee63b2495766cb7699717878025c5a8c7eba279 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 20 Nov 2015 17:25:03 +0800 Subject: [PATCH 71/83] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=89=8D=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E6=95=B0=E6=8D=AE=E4=B8=8D=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 18 ------------ app/helpers/exercise_helper.rb | 19 ++++++++++++ app/views/exercise/_exercise_form.html.erb | 19 +++++++----- app/views/exercise/_exercise_student.html.erb | 29 ++++++++++++------- .../_exercise_student_result.html.erb | 12 ++++++-- app/views/exercise/_exercise_teacher.html.erb | 2 +- app/views/exercise/_new_MC.html.erb | 4 +-- app/views/exercise/_new_MCQ.html.erb | 4 +-- app/views/exercise/_new_single.html.erb | 2 +- app/views/exercise/_show_MC.html.erb | 10 +++---- app/views/exercise/_show_MCQ.html.erb | 10 +++---- app/views/exercise/_show_single.html.erb | 8 ++--- 12 files changed, 78 insertions(+), 59 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 04189af6a..8ef6e8d72 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -502,24 +502,6 @@ class ExerciseController < ApplicationController uncomplete_question end - # 获取当前学生回答问题的答案 - def get_user_answer(question,user) - user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") - user_answer - end - - # 获取问题的标准答案 - def get_user_standard_answer(question,user) - if question.question_type == 3 - standard_answer =[] - question.exercise_standard_answers.each do |answer| - standard_answer << answer.answer_text - end - else - standard_answer = question.exercise_standard_answers - end - standard_answer - end # 是否完成了答题 def get_complete_question(exercise,user) diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index d67f4443f..21c0144b9 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -106,4 +106,23 @@ module ExerciseHelper end end + # 获取当前学生回答问题的答案 + def get_user_answer(question,user) + user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") + user_answer + end + + # 获取问题的标准答案 + def get_user_standard_answer(question,user) + if question.question_type == 3 + standard_answer =[] + question.exercise_standard_answers.each do |answer| + standard_answer << answer.answer_text + end + else + standard_answer = question.exercise_standard_answers + end + standard_answer + end + end \ No newline at end of file diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index 6e0953e74..69f55f3d7 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -82,19 +82,22 @@ //添加标题时确定按钮 function add_poll_question(doc,quest_type,quest_id) { - if(arguments[1] && arguments[2]){ - var title = $.trim($("#poll_questions_title_"+quest_type+"_"+quest_id)); - if(title.length == 0){alert("题目标题不能为空");}else{doc.parent().parent().parent().submit();} - } else { - var title = $.trim($("#poll_questions_title").val()); - if(title.length == 0){alert("题目标题不能为空");}else{doc.parent().parent().parent().submit();} - } + var title = $.trim($("#poll_questions_title").val()); + var score = $.trim($("#questions_score").val()); + if(title.length == 0 || score.length == 0){ + alert("题目标题/分数+不能为空"); + }else{ + doc.parent().parent().parent().submit();} } //修改标题时确定按钮 function edit_poll_question(doc,id) { var title = $.trim($("#poll_questions_title_" + id).val()); - if(title.length == 0){alert("题目标题不能为空");}else{doc.parent().parent().parent().submit();} + var score = $.trim($("#poll_question_score_"+ id).val()); + if(title.length == 0 || score.length == 0){ + alert("题目标题不能为空"); + }else{ + doc.parent().parent().parent().submit();} } //问卷头 diff --git a/app/views/exercise/_exercise_student.html.erb b/app/views/exercise/_exercise_student.html.erb index af9896b01..0f51dfeb7 100644 --- a/app/views/exercise/_exercise_student.html.erb +++ b/app/views/exercise/_exercise_student.html.erb @@ -3,17 +3,24 @@ $("#RSide").removeAttr("id"); $("#homework_page_right").css("min-height",$("#LSide").height()-30); $("#Container").css("width","1000px"); - var time = <%=exercise.time %>; - var total_seconds = time * 60; - getTime(total_seconds); + /*start_time = new Date(); + start_time.setFullYear(<%#=exercise_user.start_at.year%>); + start_time.setMonth(<%#=exercise_user.start_at.month%>); + start_time.setDate(<%#=exercise_user.start_at.day%>); + start_time.setHours(<%#=exercise_user.start_at.hour%>); + start_time.setMinutes(<%#=exercise_user.start_at.min%>); + start_time.setSeconds(<%#=exercise_user.start_at.sec%>); + //alert(start_time); + end_time = start_time.getTime() + 1000*60*<%#=exercise.time %>; + getTime(end_time);*/ }); - function getTime(total_seconds) { - start_time = new Date($("#start_time").html()); - end_time = start_time + 60*60*<%=exercise.time %>; + function getTime(end_time) { + //alert(end_time); now = new Date(); + var total_seconds = (now.getTime() - end_time)/1000; //start = new Date(start_time); //end_time = start_time; - var total_seconds = total_seconds - 1; + //var total_seconds = total_seconds - 1; var hours = total_seconds / 60 / 60; var hoursRound = Math.floor(hours); var minutes = total_seconds /60 - (60 * hoursRound); @@ -23,9 +30,9 @@ $("#rest_hours").html(hoursRound); $("#rest_minutes").html(minutesRound); $("#rest_seconds").html(secondsRound); - if(total_seconds >0) { - setTimeout("getTime("+total_seconds+");", 1000); - } + //if(total_seconds >0) { + setTimeout("getTime("+end_time+");", 1000); + //} }
    @@ -36,7 +43,9 @@
    开始时间:<%=format_time(exercise_user.start_at.to_s)%> 测验时长:<%=exercise.time %>分钟 +
    <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
    diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb index 9ce136667..c6b9a251c 100644 --- a/app/views/exercise/_exercise_student_result.html.erb +++ b/app/views/exercise/_exercise_student_result.html.erb @@ -30,7 +30,9 @@
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) - <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> + <% answer = get_user_answer(exercise_question, User.current)%> + <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> + <% if answer.exercise_choice_id == standard_answer.exercise_choice_id %> √ <% else %> × @@ -67,7 +69,9 @@
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) - <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> + <% answer = get_user_answer(exercise_question, User.current)%> + <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> + <% if answer.exercise_choice_id == standard_answer.exercise_choice_id %> √ <% else %> × @@ -104,7 +108,9 @@
    第<%= list_index+1%>题:<%= exercise_question.question_title %>  (<%= exercise_question.question_score %>分) - <% if exercise_question.exercise_standard_answers.first.exercise_choice_id == exercise_question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{User.current.id}.first.exercise_choice_id ") %> + <% answer = get_user_answer(exercise_question, User.current)%> + <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> + <% if standard_answer.include?(answer.exercise_choice_id) %> √ <% else %> × diff --git a/app/views/exercise/_exercise_teacher.html.erb b/app/views/exercise/_exercise_teacher.html.erb index 606b14aae..a3f6380cf 100644 --- a/app/views/exercise/_exercise_teacher.html.erb +++ b/app/views/exercise/_exercise_teacher.html.erb @@ -54,7 +54,7 @@
    ">

    多选题

    - <% mcq_question_list.each_with_index do |exercise_question, index| %> + <% mcq_question_list.each_with_index do |exercise_question, list_index| %>
    diff --git a/app/views/exercise/_new_MC.html.erb b/app/views/exercise/_new_MC.html.erb index 5d5170562..b749c4374 100644 --- a/app/views/exercise/_new_MC.html.erb +++ b/app/views/exercise/_new_MC.html.erb @@ -13,7 +13,7 @@
  • <% score = exercise.exercise_questions.where("question_type=1").last.nil? ? "": exercise.exercise_questions.where("question_type=1").last.question_score %> - 分 +
  • @@ -46,7 +46,7 @@
  • - +
  • diff --git a/app/views/exercise/_new_MCQ.html.erb b/app/views/exercise/_new_MCQ.html.erb index 96b1476ad..a7029d3ea 100644 --- a/app/views/exercise/_new_MCQ.html.erb +++ b/app/views/exercise/_new_MCQ.html.erb @@ -13,7 +13,7 @@
  • <% score = exercise.exercise_questions.where("question_type=2").last.nil? ? "": exercise.exercise_questions.where("question_type=2").last.question_score %> - 分 +
  • @@ -46,7 +46,7 @@
  • - +
  • diff --git a/app/views/exercise/_new_single.html.erb b/app/views/exercise/_new_single.html.erb index c97483bce..1ee79e198 100644 --- a/app/views/exercise/_new_single.html.erb +++ b/app/views/exercise/_new_single.html.erb @@ -13,7 +13,7 @@
  • <% score = exercise.exercise_questions.where("question_type=3").last.nil? ? "": exercise.exercise_questions.where("question_type=3").last.question_score %> - 分 +
  • diff --git a/app/views/exercise/_show_MC.html.erb b/app/views/exercise/_show_MC.html.erb index 183e8d190..b932eac1e 100644 --- a/app/views/exercise/_show_MC.html.erb +++ b/app/views/exercise/_show_MC.html.erb @@ -46,13 +46,13 @@ ''+ ''+ ''+ - ''+ + ''+ '
  • '+ '
    '+ '
      '+ '
    • '+ ''+ - '分'+ + '分'+ '
    • '+ '
    • '+ ''+ @@ -84,13 +84,13 @@ '
      '+ '
    • '+ ''+ - ''+ + ''+ '
    • '+ '
      '+ '
    '+ '
    '+ ''+ '<% end%>' ); - $("#poll_questions_title_"+quest_type+"_"+quest_id).focus(); + $("#poll_questions_title").focus(); } } else { diff --git a/app/views/exercise/_show_MCQ.html.erb b/app/views/exercise/_show_MCQ.html.erb index af2b0facb..2a91afab5 100644 --- a/app/views/exercise/_show_MCQ.html.erb +++ b/app/views/exercise/_show_MCQ.html.erb @@ -45,13 +45,13 @@ ''+ ''+ ''+ - ''+ + ''+ '
    '+ '
    '+ '
      '+ '
    • '+ ''+ - '分'+ + '分'+ '
    • '+ '
    • '+ ''+ @@ -83,13 +83,13 @@ '
      '+ '
    • '+ ''+ - ''+ + ''+ '
    • '+ '
      '+ '
    '+ '
    '+ '
    '+ '<% end%>' ); - $("#poll_questions_title_"+quest_type+"_"+quest_id).focus(); + $("#poll_questions_title").focus(); } }else { $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(""); diff --git a/app/views/exercise/_show_single.html.erb b/app/views/exercise/_show_single.html.erb index 9c7936e6d..5f36a931e 100644 --- a/app/views/exercise/_show_single.html.erb +++ b/app/views/exercise/_show_single.html.erb @@ -33,13 +33,13 @@ ''+ ''+ ''+ - ''+ + ''+ '
    '+ '
    '+ '
      '+ '
    • '+ ''+ - '分'+ + '分'+ '
    • '+ '
    • '+ ''+ @@ -65,7 +65,7 @@ '
    '+ '
    '+ '
    '+ '<% end%>' ); - $("#poll_questions_title_"+quest_type+"_"+quest_id).focus(); + $("#poll_questions_title").focus(); } } else { $("#insert_new_poll_question_"+quest_type+"_"+quest_id).html(""); From 87285578130fe52a93d0f7c85640f4a609ab44e5 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 17:29:15 +0800 Subject: [PATCH 72/83] =?UTF-8?q?=E8=80=81=E5=B8=88=E5=92=8C=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E7=BB=9F=E8=AE=A1=E6=95=B0=E7=9B=AE=E5=8C=BA=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_courses.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index ac8727e21..9c119f37a 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -159,7 +159,7 @@
    From 332ace0f34c85e5d0a833da755e7b58c254d10ac Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 20 Nov 2015 18:00:11 +0800 Subject: [PATCH 73/83] =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 1 + app/views/exercise/_exercise.html.erb | 24 ++++++++++------------ app/views/exercise/_exercise_form.html.erb | 4 ++-- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index e23560efe..1a8faff55 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -112,6 +112,7 @@ class ExerciseController < ApplicationController end 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) diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb index e44cd69c6..78ca97887 100644 --- a/app/views/exercise/_exercise.html.erb +++ b/app/views/exercise/_exercise.html.erb @@ -20,10 +20,8 @@ <% if exercise.exercise_status == 1 %>
  • 发布试卷
  • - <% elsif exercise.exercise_status == 2%> + <% else %>
  • 取消发布
  • - <% else%> -
  • 发布试卷
  • <% end%> <%= link_to(l(:button_delete), exercise,:method => :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml5 mr10") %> @@ -34,17 +32,17 @@
  • 编辑
  • <% end%> - <% if exercise.exercise_status == 2 %> -
  • 关闭
  • - <% else %> -
  • 关闭
  • - <% end%> + <%# if exercise.exercise_status == 2 %> + + <%# else %> + + <%# end%> - <% if exercise.exercise_status == 1%> -
  • 导出
  • - <% elsif exercise.exercise_status == 2 || exercise.exercise_status == 3 %> -
  • <%= link_to "导出", export_exercise_exercise_path(exercise.id,:format => "xls"), :class => "polls_de fr ml5"%>
  • - <% end%> + <%# if exercise.exercise_status == 1%> + + <%# elsif exercise.exercise_status == 2 || exercise.exercise_status == 3 %> + + <%# end%>
  • <%= format_date exercise.created_at.to_date%>
  • diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index 69f55f3d7..22589097a 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -83,9 +83,9 @@ function add_poll_question(doc,quest_type,quest_id) { var title = $.trim($("#poll_questions_title").val()); - var score = $.trim($("#questions_score").val()); + var score = $.trim($("#question_score").val()); if(title.length == 0 || score.length == 0){ - alert("题目标题/分数+不能为空"); + alert("题目标题/分数不能为空"); }else{ doc.parent().parent().parent().submit();} } From 97485ca2216a9a95de22995e88da23c396e7fec0 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 18:01:50 +0800 Subject: [PATCH 74/83] =?UTF-8?q?=E4=BF=AE=E6=94=B9show=E9=80=BB=E8=BE=91?= =?UTF-8?q?=20=E6=8F=90=E4=BA=A4=E9=97=AE=E5=8D=B7=E5=90=8E=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E9=A1=B5=E9=9D=A2=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 47 +++++++++++++------ .../_exercise_student_result.html.erb | 13 +++-- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index e23560efe..3164235d5 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -27,19 +27,21 @@ class ExerciseController < ApplicationController render_403 return end - + @can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin? + @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first # 学生点击的时候即创建关联,自动保存 #eu = ExerciseUser.create(:user_id => User.current, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) # 已提交问卷的用户不能再访问该界面 if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?) - redirect_to exercise_index_url(:course_id=> @course.id) + respond_to do |format| + format.html {render :layout => 'base_courses'} + end else if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id) eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) end - @can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin? - @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first + # @percent = get_percent(@exercise,User.current) exercise_questions = @exercise.exercise_questions @exercise_questions = paginateHelper exercise_questions,5 #分页 @@ -433,6 +435,8 @@ class ExerciseController < ApplicationController redirect_to exercise_url(@exercise) # REDO: 提示提交成功 else + # 更新提交状态 + @exercise.exercise_users.first.update_attributes(:status => true) # 答题过程中需要统计完成量 @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 @@ -480,16 +484,17 @@ class ExerciseController < ApplicationController score2 = score + question.question_score unless question.question_score.nil? end else - ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) - arr = [] - ecs.each do |ec| - arr << ec.exercise_choice.choice_position - end - arr.sort - arr = arr.join("") - if arr.to_i == standard_answer.exercise_choice_id - score3 = score + question.question_score unless question.question_score.nil? - end + get_mulscore(question, user, standard_answer) + # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + # arr = [] + # ecs.each do |ec| + # arr << ec.exercise_choice.choice_position + # end + # arr.sort + # arr = arr.join("") + # if arr.to_i == standard_answer.exercise_choice_id + # score3 = score + question.question_score unless question.question_score.nil? + # end end end end @@ -497,6 +502,20 @@ class ExerciseController < ApplicationController end private + # 获取多选的得分 + def get_mulscore(question, user, standard_answer) + ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + arr = [] + ecs.each do |ec| + arr << ec.exercise_choice.choice_position + end + arr.sort + arr = arr.join("") + if arr.to_i == standard_answer.exercise_choice_id + score3 = score + question.question_score unless question.question_score.nil? + end + end + # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 def get_exercise_user exercise_id,user_id eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id) diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb index c6b9a251c..95ef022d5 100644 --- a/app/views/exercise/_exercise_student_result.html.erb +++ b/app/views/exercise/_exercise_student_result.html.erb @@ -12,9 +12,8 @@
    开始时间:<%=format_time(exercise_user.start_at.to_s) %> 测验时长:<%=exercise.time %>分钟 - <% time = exercise_user.end_at - exercise_user.start_at %> - 测验用时:<%= (time % (24*60*60)) / (60*60)%> 小时 <%= ((time % (24*60*60)) % (60*60)) / 60%> 分钟 <%= ((time % (24*60*60)) % (60*60)) % 60%> 秒 -
    + <%# time = exercise_user.end_at - exercise_user.start_at %> +
    <%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
    @@ -32,7 +31,7 @@ <% answer = get_user_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> - <% if answer.exercise_choice_id == standard_answer.exercise_choice_id %> + <% if answer.first.exercise_choice.choice_position == standard_answer.first.exercise_choice_id %> √ <% else %> × @@ -63,7 +62,7 @@
    ">

    多选题

    - <% mcq_question_list.each_wtih_index do |exercise_question, list_index| %> + <% mcq_question_list.each_with_index do |exercise_question, list_index| %>
    @@ -71,7 +70,7 @@ <% answer = get_user_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> - <% if answer.exercise_choice_id == standard_answer.exercise_choice_id %> + <% if answer.first.exercise_choice_id == standard_answer.first.exercise_choice_id %> √ <% else %> × @@ -110,7 +109,7 @@ <% answer = get_user_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> - <% if standard_answer.include?(answer.exercise_choice_id) %> + <% if standard_answer.include?(answer.first.answer_text) %> √ <% else %> × From bb726e3475682c509c498ca9bf7179b8b71494a5 Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 18:21:31 +0800 Subject: [PATCH 75/83] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=AD=94=E6=A1=88?= =?UTF-8?q?=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 18 ++++-------------- app/helpers/exercise_helper.rb | 11 +++++++++++ .../exercise/_exercise_student_result.html.erb | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index cbc6009b1..781ea50cd 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -485,7 +485,10 @@ class ExerciseController < ApplicationController score2 = score + question.question_score unless question.question_score.nil? end else - get_mulscore(question, user, standard_answer) + arr = get_mulscore(question, user) + if arr.to_i == standard_answer.exercise_choice_id + score3 = score + question.question_score unless question.question_score.nil? + end # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) # arr = [] # ecs.each do |ec| @@ -503,19 +506,6 @@ class ExerciseController < ApplicationController end private - # 获取多选的得分 - def get_mulscore(question, user, standard_answer) - ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) - arr = [] - ecs.each do |ec| - arr << ec.exercise_choice.choice_position - end - arr.sort - arr = arr.join("") - if arr.to_i == standard_answer.exercise_choice_id - score3 = score + question.question_score unless question.question_score.nil? - end - end # ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个 def get_exercise_user exercise_id,user_id diff --git a/app/helpers/exercise_helper.rb b/app/helpers/exercise_helper.rb index 21c0144b9..bb87f3b82 100644 --- a/app/helpers/exercise_helper.rb +++ b/app/helpers/exercise_helper.rb @@ -36,6 +36,17 @@ module ExerciseHelper end end + # 获取多选的得分 + def get_mulscore(question, user) + ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + arr = [] + ecs.each do |ec| + arr << ec.exercise_choice.choice_position + end + arr.sort + arr = arr.join("") + end + # 判断用户是否已经提交了问卷 # status 为0的时候是用户点击试卷。为1表示用户已经提交 def has_commit_exercise?(exercise_id, user_id) diff --git a/app/views/exercise/_exercise_student_result.html.erb b/app/views/exercise/_exercise_student_result.html.erb index 95ef022d5..32cb556b3 100644 --- a/app/views/exercise/_exercise_student_result.html.erb +++ b/app/views/exercise/_exercise_student_result.html.erb @@ -70,7 +70,7 @@ <% answer = get_user_answer(exercise_question, User.current)%> <% standard_answer = get_user_standard_answer(exercise_question, User.current)%> - <% if answer.first.exercise_choice_id == standard_answer.first.exercise_choice_id %> + <% if get_mulscore(exercise_question, User.current).to_i == standard_answer.first.exercise_choice_id %> √ <% else %> × From c9ba57f64bbfaf23fbd057847a65ca0399f40ddb Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 20 Nov 2015 18:29:26 +0800 Subject: [PATCH 76/83] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E3=80=81=E5=AF=BC=E5=85=A5=E7=AD=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 10 ++-------- app/views/exercise/_exercise.html.erb | 2 +- app/views/exercise/_exercise_submit.html.erb | 6 +++--- app/views/exercise/index.html.erb | 2 +- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 1a8faff55..6f08cb75f 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -284,13 +284,7 @@ class ExerciseController < ApplicationController @exercise.exercise_status = 2 @exercise.publish_time = Time.now if @exercise.save - if params[:is_remote] - redirect_to exercise_index_url(:course_id => @course.id) - else - respond_to do |format| - format.js - end - end + redirect_to exercise_index_url(:course_id=> @course.id) end end @@ -430,7 +424,7 @@ class ExerciseController < ApplicationController def commit_exercise # 老师不需要提交 if User.current.allowed_to?(:as_teacher,@course) - @exercise.update_attributes(:show_result => params[:exercise][:show_result]) + @exercise.update_attributes(:show_result => params[:show_result]) redirect_to exercise_url(@exercise) # REDO: 提示提交成功 else diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb index 78ca97887..dfcc8d3b4 100644 --- a/app/views/exercise/_exercise.html.erb +++ b/app/views/exercise/_exercise.html.erb @@ -21,7 +21,7 @@ <% if exercise.exercise_status == 1 %>
  • 发布试卷
  • <% else %> -
  • 取消发布
  • +
  • 发布试卷
  • <% end%> <%= link_to(l(:button_delete), exercise,:method => :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml5 mr10") %> diff --git a/app/views/exercise/_exercise_submit.html.erb b/app/views/exercise/_exercise_submit.html.erb index acbbea244..8e2ad74a2 100644 --- a/app/views/exercise/_exercise_submit.html.erb +++ b/app/views/exercise/_exercise_submit.html.erb @@ -1,4 +1,4 @@ -<%= form_for(exercise, +<%= form_for('', :html => { :multipart => true }, :url => {:controller => 'exercise', :action => 'commit_exercise', @@ -7,8 +7,8 @@
    提交
    - <%= f.check_box :show_result, :value => exercise.show_result%> - <%= label_tag 'exercise_show_result', '允许学生查看测验结果' %> + <%= f.check_box 'show_result', :value => exercise.show_result%> + <%= label_tag '_show_result', '允许学生查看测验结果' %>
    diff --git a/app/views/exercise/index.html.erb b/app/views/exercise/index.html.erb index 14db03e09..1e2d6ff34 100644 --- a/app/views/exercise/index.html.erb +++ b/app/views/exercise/index.html.erb @@ -37,7 +37,7 @@ $('#ajax-modal').html("
    " + "
    " + "
    " + - "

    问卷发布后将不能对问卷进行修改,
    是否确定发布该问卷?

    " + + "

    测验发布后将不能对测验进行修改,
    是否确定发布该测验?

    " + "
    " + "确  定" + "取  消" + From c07e2fe2d2ef413787abc95b500234f626e568b9 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 20 Nov 2015 18:38:50 +0800 Subject: [PATCH 77/83] =?UTF-8?q?=E5=8F=91=E5=B8=83=E8=AF=95=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index e34e89cb7..c95458a57 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -40,6 +40,7 @@ class ExerciseController < ApplicationController else if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id) eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) + @exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first end # @percent = get_percent(@exercise,User.current) From aa36c927d3c7c0a4ac88fac7741e68ae90c7115b Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 18:39:35 +0800 Subject: [PATCH 78/83] 0 --- app/controllers/exercise_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 781ea50cd..6699702aa 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -41,7 +41,6 @@ class ExerciseController < ApplicationController if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id) eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false) end - # @percent = get_percent(@exercise,User.current) exercise_questions = @exercise.exercise_questions @exercise_questions = paginateHelper exercise_questions,5 #分页 From da55b00da7f1ccaa5662eb01015bb36bd3f0f1bd Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 19:05:39 +0800 Subject: [PATCH 79/83] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 448c9a90a..9c4ce463a 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -269,11 +269,23 @@ class ExerciseController < ApplicationController def delete_exercise_question @exercise_question = ExerciseQuestion.find params[:exercise_question] @exercise = @exercise_question.exercise - exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}") - exercise_questions.each do |question| - question.question_number -= 1 - question.save + + if @exercise_question.question_type == 1 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1") + #@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1") + elsif @exercise_question.question_type == 2 + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number - 1") + else + ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number - 1") end + # @exercise_question_num = params[:quest_num].to_i + # @exercise_questions.question_number = params[:quest_num].to_i - 1 + # + # exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}") + # exercise_questions.each do |question| + # question.question_number -= 1 + # question.save + # end if @exercise_question && @exercise_question.destroy respond_to do |format| format.js @@ -568,7 +580,9 @@ class ExerciseController < ApplicationController exercises = course.exercises.where("exercise_name=?","") unless exercises.empty? exercises.each do |exercise| - exercise.destroy + if exercise.exercise_questions.empty? + exercise.destroy + end end end end From c0dfc17b19e6afd84b76eebbe19ffc391111c57f Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 19:35:32 +0800 Subject: [PATCH 80/83] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 9c4ce463a..28f532db6 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -443,7 +443,8 @@ class ExerciseController < ApplicationController # REDO: 提示提交成功 else # 更新提交状态 - @exercise.exercise_users.first.update_attributes(:status => true) + cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first + cur_exercise_user.update_attributes(:status => 1) # 答题过程中需要统计完成量 @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 From 9ca336a70a926d62ad2fa407fe4c115b238c7354 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 20 Nov 2015 19:59:05 +0800 Subject: [PATCH 81/83] =?UTF-8?q?=E5=8F=91=E5=B8=83=E5=92=8C=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 2 +- app/views/exercise/_exercise.html.erb | 6 ++++-- app/views/exercise/_exercise_form.html.erb | 8 +++++++- app/views/exercise/create_exercise_question.js.erb | 4 +++- app/views/exercise/update_exercise_question.js.erb | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 448c9a90a..94a5a8028 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -294,7 +294,7 @@ class ExerciseController < ApplicationController # 重新发布的时候会删除所有的答题 def republish_exercise @exercise.exercise_questions.each do |exercise_question| - exercise_question.exercise_ansers.destroy_all + exercise_question.exercise_answers.destroy_all end @exercise.exercise_users.destroy_all @exercise.exercise_status = 1 diff --git a/app/views/exercise/_exercise.html.erb b/app/views/exercise/_exercise.html.erb index dfcc8d3b4..f5896c5e3 100644 --- a/app/views/exercise/_exercise.html.erb +++ b/app/views/exercise/_exercise.html.erb @@ -20,8 +20,10 @@ <% if exercise.exercise_status == 1 %>
  • 发布试卷
  • - <% else %> -
  • 发布试卷
  • + <% elsif exercise.exercise_status == 2%> +
  • 取消发布
  • + <% else%> +
  • 发布试卷
  • <% end%> <%= link_to(l(:button_delete), exercise,:method => :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml5 mr10") %> diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index 22589097a..29ccc685d 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -84,8 +84,11 @@ { var title = $.trim($("#poll_questions_title").val()); var score = $.trim($("#question_score").val()); + var standard_ans = $.trim($("#question_standard_ans").val()); if(title.length == 0 || score.length == 0){ alert("题目标题/分数不能为空"); + }else if(standard_ans.length == 0) { + alert("标准答案不能为空"); }else{ doc.parent().parent().parent().submit();} } @@ -94,8 +97,11 @@ { var title = $.trim($("#poll_questions_title_" + id).val()); var score = $.trim($("#poll_question_score_"+ id).val()); + var standard_ans = $.trim($("#poll_question_standard_answer_" + id).val()); if(title.length == 0 || score.length == 0){ - alert("题目标题不能为空"); + alert("题目标题/分数不能为空"); + }else if(standard_ans.length == 0) { + alert("标准答案不能为空"); }else{ doc.parent().parent().parent().submit();} } diff --git a/app/views/exercise/create_exercise_question.js.erb b/app/views/exercise/create_exercise_question.js.erb index 9047cfeda..326a19ec8 100644 --- a/app/views/exercise/create_exercise_question.js.erb +++ b/app/views/exercise/create_exercise_question.js.erb @@ -1,6 +1,8 @@ <% if @is_insert %> $("#poll_content").html('<%= escape_javascript(render :partial => 'exercise_content', :locals => {:exercise => @exercise})%>'); $("#exercise_submit").html("<%= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise}) %>"); + $("#current_score_div").show(); + $("#current_score").html("<%=get_current_score @exercise %>分"); <% else %> $("#new_exercise_question").html('<%= escape_javascript(render :partial => 'new_question', :locals => {:exercise => @exercise}) %>'); $("#new_poll_question").html(""); @@ -35,6 +37,6 @@ "
    " + "
    "); <% end %> -$("#current_score").html("<%=get_current_score @exercise %>分"); $("#current_score_div").show(); +$("#current_score").html("<%=get_current_score @exercise %>分"); <% end %> diff --git a/app/views/exercise/update_exercise_question.js.erb b/app/views/exercise/update_exercise_question.js.erb index ef9004c06..9e7822cb7 100644 --- a/app/views/exercise/update_exercise_question.js.erb +++ b/app/views/exercise/update_exercise_question.js.erb @@ -16,5 +16,5 @@ $("#poll_questions_<%= @exercise_question.id%>").html("
    {:exercise_question => @exercise_question}) %>" + "<% end%>" + "
    "); -$("#current_score").html("<%=get_current_score @exercise %>分"); +$("#current_score").html("<%=get_current_score @exercise_question.exercise %>分"); $("#exercise_submit").html("<%= escape_javascript(render :partial => 'exercise_submit', :locals => {:exercise => @exercise_question.exercise}) %>"); From 8b29002a0fdf30058186869621b7e0bdbc69920b Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 20 Nov 2015 20:02:57 +0800 Subject: [PATCH 82/83] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BE=97=E5=88=86?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_controller.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 28f532db6..c15d5ad23 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -21,6 +21,10 @@ class ExerciseController < ApplicationController end def show + unless User.current.member_of_course?(@course) + render_403 + return + end @exercise = Exercise.find params[:id] @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? if @exercise.exercise_status != 2 && (!User.current.allowed_to?(:as_teacher,@course) || User.current.admin?) @@ -485,16 +489,16 @@ class ExerciseController < ApplicationController # 问答题有多个答案 if question.question_type == 3 if standard_answer.include?(answer.first.answer_text) - score1 = score+ question.question_score unless question.question_score.nil? + score1 = score1+ question.question_score unless question.question_score.nil? end elsif question.question_type == 1 if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id - score2 = score + question.question_score unless question.question_score.nil? + score2 = score2 + question.question_score unless question.question_score.nil? end else arr = get_mulscore(question, user) if arr.to_i == standard_answer.exercise_choice_id - score3 = score + question.question_score unless question.question_score.nil? + score3 = score3 + question.question_score unless question.question_score.nil? end # ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) # arr = [] From cc19c345e1a629a26f6789f7dd38085e499fa036 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 20 Nov 2015 20:23:02 +0800 Subject: [PATCH 83/83] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercise/_exercise_form.html.erb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/exercise/_exercise_form.html.erb b/app/views/exercise/_exercise_form.html.erb index 29ccc685d..0d6b8602d 100644 --- a/app/views/exercise/_exercise_form.html.erb +++ b/app/views/exercise/_exercise_form.html.erb @@ -87,9 +87,9 @@ var standard_ans = $.trim($("#question_standard_ans").val()); if(title.length == 0 || score.length == 0){ alert("题目标题/分数不能为空"); - }else if(standard_ans.length == 0) { + }/*else if(standard_ans.length == 0) { alert("标准答案不能为空"); - }else{ + }*/else{ doc.parent().parent().parent().submit();} } //修改标题时确定按钮 @@ -100,9 +100,9 @@ var standard_ans = $.trim($("#poll_question_standard_answer_" + id).val()); if(title.length == 0 || score.length == 0){ alert("题目标题/分数不能为空"); - }else if(standard_ans.length == 0) { + }/*else if(standard_ans.length == 0) { alert("标准答案不能为空"); - }else{ + }*/else{ doc.parent().parent().parent().submit();} }