From a6baf21c2c7565ce73aeca358d1fb9e531f31804 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 26 Aug 2019 14:45:26 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E6=99=AE=E9=80=9A=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=92=8C=E5=88=86=E7=BB=84=E4=BD=9C=E4=B8=9A=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/homework_banks.js | 2 + app/assets/stylesheets/homework_banks.scss | 3 + app/controllers/homework_banks_controller.rb | 63 +++++++++++++++++++ app/helpers/homework_banks_helper.rb | 2 + app/views/homework_banks/show.json.jbuilder | 9 +++ config/routes.rb | 22 ++++--- .../homework_banks_controller_spec.rb | 5 ++ spec/helpers/homework_banks_helper_spec.rb | 15 +++++ 8 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/homework_banks.js create mode 100644 app/assets/stylesheets/homework_banks.scss create mode 100644 app/controllers/homework_banks_controller.rb create mode 100644 app/helpers/homework_banks_helper.rb create mode 100644 app/views/homework_banks/show.json.jbuilder create mode 100644 spec/controllers/homework_banks_controller_spec.rb create mode 100644 spec/helpers/homework_banks_helper_spec.rb diff --git a/app/assets/javascripts/homework_banks.js b/app/assets/javascripts/homework_banks.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/homework_banks.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/homework_banks.scss b/app/assets/stylesheets/homework_banks.scss new file mode 100644 index 000000000..0cfbbd32d --- /dev/null +++ b/app/assets/stylesheets/homework_banks.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the homework_banks controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/homework_banks_controller.rb b/app/controllers/homework_banks_controller.rb new file mode 100644 index 000000000..8c4d607a9 --- /dev/null +++ b/app/controllers/homework_banks_controller.rb @@ -0,0 +1,63 @@ +class HomeworkBanksController < ApplicationController + before_action :require_login + before_action :find_bank + before_action :bank_params, only: [:update] + before_action :bank_admin, only: [:update, :destroy, :set_public] + + def show + @bank_attachments = @bank.attachments.where(attachtype: 1) + @reference_attachments = @bank.attachments.where(attachtype: 2) + end + + def update + ActiveRecord::Base.transaction do + @bank.update_attributes(name: params[:name], description: params[:description], reference_answer: params[:reference_answer]) + + # 作业描述的附件 + Attachment.associate_container(params[:attachment_ids], @bank.id, @bank.class) if params[:attachment_ids] + # 作业参考答案的附件 + Attachment.associate_container(params[:reference_attachment_ids], @bank.id, @bank.class, 2) if params[:reference_attachment_ids] + + normal_status(0, "更新成功") + end + end + + def destroy + ActiveRecord::Base.transaction do + @bank.homework_commons.update_all(homework_bank_id: nil) + @bank.destroy! + normal_status("删除成功") + end + end + + def set_public + @bank.update_attributes(is_public: 1) + normal_status("更新成功") + end + + private + + def find_bank + @bank = HomeworkBank.find_by!(id: params[:id]) + tip_exception(403, "无权限") unless (current_user.certification_teacher? && (@bank.is_public || @bank.user_id == current_user.id)) || current_user.admin? + end + + def bank_admin + tip_exception(403, "无权限") unless (current_user.certification_teacher? && @bank.user_id == current_user.id) || current_user.admin? + end + + def bank_params + tip_exception("name参数不能为空") if params[:homework_bank][:name].blank? + tip_exception("description参数不能为空") if params[:homework_bank][:description].blank? + if @bank.homework_type == 3 + tip_exception("base_on_project参数不能为空") if params[:homework_bank][:base_on_project].nil? + tip_exception("min_num参数不能为空") if params[:homework_bank][:min_num].blank? + tip_exception("max_num参数不能为空") if params[:homework_bank][:max_num].blank? + tip_exception("最小人数不能小于1") if params[:homework_bank][:min_num].to_i < 1 + tip_exception("最大人数不能小于最小人数") if params[:homework_bank][:max_num].to_i < params[:homework_bank][:min_num].to_i + end + params.require(:homework_bank).permit(:name, :description, :reference_answer) if @bank.homework_type == 1 + params.require(:homework_bank).permit(:name, :description, :reference_answer, :min_num, :max_num, :base_on_project) if @bank.homework_type == 3 + end + +end diff --git a/app/helpers/homework_banks_helper.rb b/app/helpers/homework_banks_helper.rb new file mode 100644 index 000000000..805479c79 --- /dev/null +++ b/app/helpers/homework_banks_helper.rb @@ -0,0 +1,2 @@ +module HomeworkBanksHelper +end diff --git a/app/views/homework_banks/show.json.jbuilder b/app/views/homework_banks/show.json.jbuilder new file mode 100644 index 000000000..34ca5ec25 --- /dev/null +++ b/app/views/homework_banks/show.json.jbuilder @@ -0,0 +1,9 @@ +json.(@bank, :id, :name, :description, :homework_type, :is_public, :min_num, :max_num, :base_on_project, :reference_answer) + +json.attachments @bank_attachments do |attachment| + json.partial! "attachments/attachment_simple", locals: {attachment: attachment} +end + +json.reference_attachments @reference_attachments do |attachment| + json.partial! "attachments/attachment_simple", locals: {attachment: attachment} +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index de4f46a40..61d59a1a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -568,14 +568,6 @@ Rails.application.routes.draw do resource :poll_votes,only:[:create,:destroy] end - resources :question_banks do - collection do - get :bank_list - post :save_banks - end - end - - resources :exercises do member do get :choose_shixun @@ -630,6 +622,20 @@ Rails.application.routes.draw do end end + + resources :question_banks do + collection do + get :bank_list + post :save_banks + end + end + + resources :homework_banks do + member do + post :set_public + end + end + resources :attachments resources :schools do diff --git a/spec/controllers/homework_banks_controller_spec.rb b/spec/controllers/homework_banks_controller_spec.rb new file mode 100644 index 000000000..ada01ad8b --- /dev/null +++ b/spec/controllers/homework_banks_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkBanksController, type: :controller do + +end diff --git a/spec/helpers/homework_banks_helper_spec.rb b/spec/helpers/homework_banks_helper_spec.rb new file mode 100644 index 000000000..bd54e5d8f --- /dev/null +++ b/spec/helpers/homework_banks_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the HomeworkBanksHelper. For example: +# +# describe HomeworkBanksHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe HomeworkBanksHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end From 90afe491b439f0d978a350cd9d5fba9a963c9574 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 26 Aug 2019 14:57:00 +0800 Subject: [PATCH 02/24] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E3=80=81=E9=97=AE?= =?UTF-8?q?=E5=8D=B7=E3=80=81=E4=BD=9C=E4=B8=9A=E5=88=97=E8=A1=A8=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=80=81=E5=B8=88=E5=A7=93=E5=90=8D=E7=9A=84=E5=B1=95?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercises/index.json.jbuilder | 1 + app/views/homework_commons/index.json.jbuilder | 1 + app/views/polls/index.json.jbuilder | 1 + 3 files changed, 3 insertions(+) diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index e5da76786..c8f6cd380 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -7,6 +7,7 @@ if @exercises_count > 0 second_left = get_exercise_left_time(exercise,@current_user_) json.time second_left.present? ? (second_left / 60) : nil end + json.author exercise.user.real_name ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) json.exercise_status ex_index[:ex_status] json.lock_status ex_index[:lock_icon] diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index daf7d9df2..9f0f9fdfd 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -17,6 +17,7 @@ json.homeworks @homework_commons.each do |homework| json.status_time curr_status[:time] json.time_status curr_status[:time_status] json.allow_late homework.allow_late + json.author homework.user.real_name # 只有在主目录才显示 json.upper_category_name homework.course_second_category&.name unless params[:category] diff --git a/app/views/polls/index.json.jbuilder b/app/views/polls/index.json.jbuilder index 0face0966..f3501cfd6 100644 --- a/app/views/polls/index.json.jbuilder +++ b/app/views/polls/index.json.jbuilder @@ -5,6 +5,7 @@ if @polls_count > 0 json.array! @polls do |poll| poll_index_array = poll_index_show(poll,@course,@is_teacher_or,@current_user_) json.extract! poll, :id, :polls_name,:is_public,:created_at + json.author poll.user.real_name json.polls_status poll_index_array[:polls_status] json.lock_status poll_index_array[:lock_icon] json.publish_time poll_index_array[:publish_time] # 问卷的发布时间 From 1ab76321d4f03f1f93b238407f808fbc28a9416c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 26 Aug 2019 16:31:47 +0800 Subject: [PATCH 03/24] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=88=90=E7=BB=A9=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 207 ++++++++++-------- .../courses/export_course_info.xlsx.axlsx | 29 +++ .../export_member_act_score.xlsx.axlsx | 25 +++ .../export_member_scores_excel.xlsx.axlsx | 38 ---- config/routes.rb | 2 + 5 files changed, 175 insertions(+), 126 deletions(-) create mode 100644 app/views/courses/export_course_info.xlsx.axlsx create mode 100644 app/views/courses/export_member_act_score.xlsx.axlsx diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 470315bdc..87a89653d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -26,17 +26,19 @@ class CoursesController < ApplicationController :base_info, :get_historical_courses, :create_group_by_importing_file, :attahcment_category_list,:export_member_scores_excel, :duplicate_course, :switch_to_teacher, :switch_to_assistant, :switch_to_student, :exit_course, - :informs, :update_informs, :online_learning, :update_task_position, :tasks_list, :join_excellent_course] + :informs, :update_informs, :online_learning, :update_task_position, :tasks_list, + :join_excellent_course, :export_couser_info, :export_member_act_score] before_action :user_course_identity, except: [:join_excellent_course, :index, :create, :new, :apply_to_join_course, :search_course_list, :get_historical_course_students, :mine, :search_slim, :board_list] before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate, - :transfer_to_course_group, :delete_from_course, - :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher] + :transfer_to_course_group, :delete_from_course, :export_member_scores_excel, + :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, + :add_teacher, :export_couser_info, :export_member_act_score] before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin, :set_course_group, :create_group_by_importing_file, :update_informs, :update_task_position, :tasks_list] before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group, - :change_course_teacher, :export_member_scores_excel, :course_group_list, + :change_course_teacher, :course_group_list, :teacher_application_review, :apply_teachers, :delete_course_teacher] before_action :validate_course_name, only: [:create, :update] before_action :find_board, only: :board_list @@ -1074,44 +1076,64 @@ class CoursesController < ApplicationController @courses= @courses.page(@page).per(@page_size) end + # 导出课堂信息 + def export_couser_info + set_export_cookies + course_info_to_xlsx @course + filename_ = "#{current_user.real_name}_#{@course.name}_课堂信息_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{format_sheet_name filename_.strip}",template: "courses/export_course_info.xlsx.axlsx", + locals: {course_info: @course_info} + end + + # 导出活跃度 + def export_member_act_score + search = params[:search] ? "#{params[:search].strip}" : "" #用户名或学生学号id搜索 + group_id = params[:group_id] #分班的班级id + @all_members = student_act_score group_id, search + if @all_members.size == 0 + normal_status(-1,"课堂暂时没有学生") + elsif params[:export].present? && params[:export] + normal_status(0,"正在下载中") + else + set_export_cookies + act_score_to_xlsx(@all_members) + filename_ = "#{current_user.real_name}_#{@course.name}_活跃度_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{format_sheet_name filename_.strip}",template: "courses/export_member_act_score.xlsx.axlsx", + locals: {activity_level:@user_activity_level} + end + end + + # 导出学生成绩 def export_member_scores_excel ActiveRecord::Base.transaction do begin + @all_members = @course.students search = params[:search] ? "#{params[:search].strip}" : "" #用户名或学生学号id搜索 group_id = params[:group_id] #分班的班级id - # if group_id && group_id != "0" && group_id != "-1" - # @all_members = @course.students.course_find_by_ids("course_group_id",group_id) - # elsif group_id && group_id == "0" # 未分班 - # @all_members = @course.course_members.ungroup_students - # else - # @all_members = @course.students - # end - # if name.present? - # @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{name}%","%#{name}%") - # end - - @all_members = student_act_score group_id, search + @all_members = @all_members.where(course_group_id: group_id) unless group_id.blank? + unless search.blank? + @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{search}%","%#{search}%") + end - @c_homeworks = @course.homework_commons.homework_published.order("homework_commons.publish_time asc, homework_commons.created_at asc") - @c_exercises = @course.exercises.is_exercise_published.order("exercises.publish_time asc, exercises.created_at asc") - # @c_polls = @course.polls.publish_or_not.order("polls.publish_time asc, polls.created_at asc") - @c_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.created_at asc") - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - elsif @all_members.size == 0 + if @all_members.length == 0 normal_status(-1,"课堂暂时没有学生") elsif params[:export].present? && params[:export] - normal_status(0,"正在下载中") + normal_status(0,"正在下载中") else + @c_homeworks = @course.homework_commons.homework_published.order("homework_commons.publish_time asc, homework_commons.created_at asc") + @c_exercises = @course.exercises.is_exercise_published.order("exercises.publish_time asc, exercises.created_at asc") + # @c_polls = @course.polls.publish_or_not.order("polls.publish_time asc, polls.created_at asc") + @c_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.created_at asc") + set_export_cookies member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks) - filename_ = "#{current_user.real_name}_#{@course.name}_全部成绩_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + filename_ = "#{current_user.real_name}_#{@course.name}_总成绩_#{Time.now.strftime('%Y%m%d_%H%M%S')}" render xlsx: "#{format_sheet_name filename_.strip}",template: "courses/export_member_scores_excel.xlsx.axlsx", - locals: {course_info:@course_info, activity_level:@user_activity_level, - course_scores:@course_user_scores,shixun_works:@shixun_work_arrays, + locals: {course_scores:@course_user_scores,shixun_works:@shixun_work_arrays, common_works:@common_work_arrays,group_works:@group_work_arrays,task_works:@task_work_arrays, exercise_works:@exercise_work_arrays} end + rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) @@ -1279,13 +1301,7 @@ class CoursesController < ApplicationController # end def student_act_score group_id, search - sql_select = %Q{SELECT cm.*,( - SELECT SUM(student_works.work_score) - FROM student_works,homework_commons - WHERE student_works.homework_common_id = homework_commons.id - AND homework_commons.course_id = #{@course.id} - AND student_works.user_id = cm.user_id - ) AS score, + sql_select = %Q{SELECT cm.*, (SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id, (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, @@ -1306,52 +1322,25 @@ class CoursesController < ApplicationController FROM course_members cm} if search.present? && group_id.present? sql_select += %Q{ join users on cm.user_id = users.id - joins user_extensions ue on ue.user_id = users.id + join user_extensions ue on ue.user_id = users.id WHERE cm.role = 4 and cm.course_id = #{@course.id} and cm.course_group_id = #{group_id} and - (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc} + (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%')} elsif search.present? sql_select += %Q{ join users on cm.user_id = users.id - joins user_extensions ue on ue.user_id = users.id + join user_extensions ue on ue.user_id = users.id WHERE cm.role = 4 and - (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc} + (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%')} elsif group_id.present? - sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id} and cm.course_group_id = #{group_id} ORDER BY score desc} + sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id} and cm.course_group_id = #{group_id}} else - sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id} ORDER BY score desc} + sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id}} end act_scores = CourseMember.find_by_sql(sql_select) act_scores end - def member_to_xlsx(course,all_members,homeworks,exercises,tasks) - #课堂的作业信息 - shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 - shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] - - # 更新实训作业成绩 - shixun_homeworks.includes(:homework_challenge_settings, :published_settings, :homework_commons_shixun).each do |homework| - homework.update_homework_work_score - end - - shixun_homeworks = shixun_homeworks&.includes(score_student_works: :user) - - common_homeworks = homeworks.search_homework_type(1) #全部普通作业 - common_titles = common_homeworks.pluck(:name)+ ["总得分"] - common_homeworks = common_homeworks&.includes(score_student_works: :user) - - group_homeworks = homeworks.search_homework_type(3) #全部分组作业 - group_titles = group_homeworks.pluck(:name)+ ["总得分"] - group_homeworks = group_homeworks&.includes(score_student_works: :user) - - task_titles = tasks.pluck(:name) + ["总得分"] - tasks = tasks&.includes(user: :user_extension, score_graduation_works: :user) - - exercise_titles = exercises.pluck(:exercise_name) + ["总得分"] - exercises = exercises&.includes(user: :user_extension, score_exercise_users: :user) - - total_user_score_array = [] #学生总成绩集合 - + def course_info_to_xlsx course #课堂信息 @course_info = [] course_info_title = "课堂信息概要" @@ -1399,7 +1388,9 @@ class CoursesController < ApplicationController end course_group_info = [course_group_info_head,course_group_info_body] @course_info += [course_info_title,course_main_info,course_group_info] + end + def act_score_to_xlsx all_members #课堂活跃度 @user_activity_level = [] course_user_level = [] @@ -1414,8 +1405,6 @@ class CoursesController < ApplicationController user_stu_id = u.student_id.present? ? (u.student_id.to_s + "\t") : "--" user_school = user.school_name user_course_group = u.course_group_name - user_info_array = [user_login,user_name,user_mail,user_stu_id,user_school,user_course_group] #用户的信息集合 - user_work_scores = [] #课堂活跃度统计 user_homeworks_num = u.homework_num.to_i #完成的作业数 @@ -1434,23 +1423,69 @@ class CoursesController < ApplicationController c_reply_num = user_reply_num user_activity_levels = c_works_num + c_exercise_num + c_poll_num + c_file_num + c_message_num + c_reply_num + user_work_reply_num user_ac_level = { - u_1: user_name, - u_2: user_login, - u_2_1: user_mail, - u_3: user_stu_id, - u_4: user_school, - u_5: user_course_group, - u_6: c_works_num, - u_7: c_exercise_num, - u_8: c_poll_num, - u_9: c_file_num, - u_10: c_message_num, - u_11: c_reply_num, - u_12: user_work_reply_num, - u_13: user_activity_levels + u_1: user_name, + u_2: user_login, + u_2_1: user_mail, + u_3: user_stu_id, + u_4: user_school, + u_5: user_course_group, + u_6: c_works_num, + u_7: c_exercise_num, + u_8: c_poll_num, + u_9: c_file_num, + u_10: c_message_num, + u_11: c_reply_num, + u_12: user_work_reply_num, + u_13: user_activity_levels } course_user_level.push(user_ac_level) + #.课堂活跃度统计的集合 + course_user_level = course_user_level.sort_by {|k| k[:u_13]}.reverse + @user_activity_level = [course_activity_title,user_cell_head,course_user_level] + end + end + + def member_to_xlsx(course,all_members,homeworks,exercises,tasks) + #课堂的作业信息 + shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 + shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] + + # 更新实训作业成绩 + shixun_homeworks.includes(:homework_challenge_settings, :published_settings, :homework_commons_shixun).each do |homework| + homework.update_homework_work_score + end + + shixun_homeworks = shixun_homeworks&.includes(score_student_works: :user) + + common_homeworks = homeworks.search_homework_type(1) #全部普通作业 + common_titles = common_homeworks.pluck(:name)+ ["总得分"] + common_homeworks = common_homeworks&.includes(score_student_works: :user) + + group_homeworks = homeworks.search_homework_type(3) #全部分组作业 + group_titles = group_homeworks.pluck(:name)+ ["总得分"] + group_homeworks = group_homeworks&.includes(score_student_works: :user) + + task_titles = tasks.pluck(:name) + ["总得分"] + tasks = tasks&.includes(user: :user_extension, score_graduation_works: :user) + + exercise_titles = exercises.pluck(:exercise_name) + ["总得分"] + exercises = exercises&.includes(user: :user_extension, score_exercise_users: :user) + + total_user_score_array = [] #学生总成绩集合 + + all_members.each do |u| + #用户的基本信息 + user = u.user + user_login = user.login + user_name = user.real_name + user_mail = user.mail + user_stu_id = user.student_id.present? ? (user.student_id.to_s + "\t") : "--" + user_school = user.school_name + user_course_group = u.course_group_name + user_info_array = [user_name,user_login,user_mail,user_stu_id,user_school,user_course_group] #用户的信息集合 + user_work_scores = [] + #学生总成绩 shixun_score = 0.0 # 实训作业的总分 common_score = 0.0 #普通作业的总分 @@ -1548,10 +1583,6 @@ class CoursesController < ApplicationController total_user_score_array.push(user_work_scores) # 全部成员的集合 end - #1.课堂活跃度统计的集合 - course_user_level = course_user_level.sort_by {|k| k[:u_12]}.reverse - @user_activity_level = [course_activity_title,user_cell_head,course_user_level] - #2.学生总成绩的集合 ## 作业标题的集合 course_user_score_title = "学生总成绩" diff --git a/app/views/courses/export_course_info.xlsx.axlsx b/app/views/courses/export_course_info.xlsx.axlsx new file mode 100644 index 000000000..789f5c43b --- /dev/null +++ b/app/views/courses/export_course_info.xlsx.axlsx @@ -0,0 +1,29 @@ +wb = xlsx_package.workbook +wb.use_shared_strings = true +wb.styles do |s| + no_wrap_sz = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: false,:horizontal => :center,:vertical => :center } + sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } + row_cell = s.add_style :bg_color=> "FAEBDC",:border => { :style => :thin, :color =>"000000" },alignment: {wrap_text: true,:horizontal => :center,:vertical => :center } + blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center} + + #课堂信息摘要 + wb.add_worksheet(name:course_info[0]) do |sheet| + sheet.sheet_view.show_grid_lines = false + course_main_info = course_info[1] + course_group_info = course_info[2] + group_info_d = course_group_info[0] + group_info_detail = course_group_info[1] + course_main_info.each do |c| + sheet.add_row c, :style => sz_all #用户id + end + sheet["A1:A7"].each { |c| c.style = row_cell } + sheet.add_row [],:style => sz_all + if group_info_detail.count > 0 + sheet.add_row group_info_d, :style => blue_cell + group_info_detail.each do |group| + sheet.add_row group, :style => sz_all #用户id + end + sheet.column_info.second.width = 40 + end + end #add_worksheet +end diff --git a/app/views/courses/export_member_act_score.xlsx.axlsx b/app/views/courses/export_member_act_score.xlsx.axlsx new file mode 100644 index 000000000..357b28a34 --- /dev/null +++ b/app/views/courses/export_member_act_score.xlsx.axlsx @@ -0,0 +1,25 @@ +wb = xlsx_package.workbook +wb.use_shared_strings = true +wb.styles do |s| + no_wrap_sz = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: false,:horizontal => :center,:vertical => :center } + sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } + row_cell = s.add_style :bg_color=> "FAEBDC",:border => { :style => :thin, :color =>"000000" },alignment: {wrap_text: true,:horizontal => :center,:vertical => :center } + blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center} + + #课堂活跃度统计 + wb.add_worksheet(name:activity_level[0]) do |sheet| + sheet.sheet_view.show_grid_lines = false + sheet_title = activity_level[1] + sheet_content = activity_level[2] + sheet.add_row sheet_title, :height => 25,:style => blue_cell + if sheet_content.count > 0 + sheet_content.each_with_index do |c,index| + c_1 = (index+1) + c_2 = [c_1] + c.values + sheet.add_row c_2, :height => 25, :style => sz_all #用户id + end + sheet.column_widths *([20]*sheet.column_info.count) + sheet.column_info.first.width = 8 + end + end #add_worksheet +end diff --git a/app/views/courses/export_member_scores_excel.xlsx.axlsx b/app/views/courses/export_member_scores_excel.xlsx.axlsx index db4f06ab1..a57211d44 100644 --- a/app/views/courses/export_member_scores_excel.xlsx.axlsx +++ b/app/views/courses/export_member_scores_excel.xlsx.axlsx @@ -6,44 +6,6 @@ wb.styles do |s| row_cell = s.add_style :bg_color=> "FAEBDC",:border => { :style => :thin, :color =>"000000" },alignment: {wrap_text: true,:horizontal => :center,:vertical => :center } blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center} - #课堂信息摘要 - wb.add_worksheet(name:course_info[0]) do |sheet| - sheet.sheet_view.show_grid_lines = false - course_main_info = course_info[1] - course_group_info = course_info[2] - group_info_d = course_group_info[0] - group_info_detail = course_group_info[1] - course_main_info.each do |c| - sheet.add_row c, :style => sz_all #用户id - end - sheet["A1:A7"].each { |c| c.style = row_cell } - sheet.add_row [],:style => sz_all - if group_info_detail.count > 0 - sheet.add_row group_info_d, :style => blue_cell - group_info_detail.each do |group| - sheet.add_row group, :style => sz_all #用户id - end - sheet.column_info.second.width = 40 - end - end #add_worksheet - - #课堂活跃度统计 - wb.add_worksheet(name:activity_level[0]) do |sheet| - sheet.sheet_view.show_grid_lines = false - sheet_title = activity_level[1] - sheet_content = activity_level[2] - sheet.add_row sheet_title, :height => 25,:style => blue_cell - if sheet_content.count > 0 - sheet_content.each_with_index do |c,index| - c_1 = (index+1) - c_2 = [c_1] + c.values - sheet.add_row c_2, :height => 25, :style => sz_all #用户id - end - sheet.column_widths *([20]*sheet.column_info.count) - sheet.column_info.first.width = 8 - end - end #add_worksheet - #学生总成绩 wb.add_worksheet(name:course_scores[0]) do |sheet| sheet.sheet_view.show_grid_lines = false diff --git a/config/routes.rb b/config/routes.rb index 61d59a1a8..4444ca6c0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -343,6 +343,8 @@ Rails.application.routes.draw do get 'base_info' get 'attahcment_category_list' get 'export_member_scores_excel' #导出课堂信息 + get 'export_couser_info' + get 'export_member_act_score' post 'switch_to_teacher' post 'switch_to_assistant' post 'switch_to_student' From 44e7a4da00fb765b3706ba96196692efab858d37 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 27 Aug 2019 10:44:29 +0800 Subject: [PATCH 04/24] =?UTF-8?q?=E9=A2=98=E5=BA=93=E7=9A=84=E5=8F=91?= =?UTF-8?q?=E9=80=81=E8=87=B3=E8=AF=BE=E5=A0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/question_banks_controller.rb | 26 ++++++++++++++++++- .../question_banks/my_courses.json.jbuilder | 4 +++ config/routes.rb | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 app/views/question_banks/my_courses.json.jbuilder diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 098c07d1b..96fcbeace 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -1,6 +1,6 @@ class QuestionBanksController < ApplicationController before_action :require_login, :check_auth - before_action :params_filter + before_action :params_filter, except: [:my_courses] # 题库选用列表 # object_type: # normal 普通作业题库; group 分组作业题库; poll问卷题库; exercise试卷题库; gtask 毕设选题题库;gtopic 毕设任务 @@ -79,6 +79,30 @@ class QuestionBanksController < ApplicationController end end + def my_courses + @courses = current_user.manage_courses.where(is_delete: 0, is_end: 0) + end + + def send_to_course + bank = current_bank + course = current_user.manage_courses.find_by(id: params[:course_id]) + case @object_type + when 'HomeworkBank' # 作业 + quote_homework_bank bank, course + when 'ExerciseBank' + if bank.container_type == 'Exercise' # 试卷 + quote_exercise_bank bank, course + else # 问卷 + quote_poll_bank bank, course + end + when 'GtaskBank' + quote_gtask_bank bank, course + when 'GtopicBank' + quote_gtopic_bank bank, course + end + normal_status("发送成功") + end + def destroy bank = current_bank diff --git a/app/views/question_banks/my_courses.json.jbuilder b/app/views/question_banks/my_courses.json.jbuilder new file mode 100644 index 000000000..01ae7d245 --- /dev/null +++ b/app/views/question_banks/my_courses.json.jbuilder @@ -0,0 +1,4 @@ +json.courses @courses do |course| + json.course_id course.id + json.course_name course.name +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1de51e4d0..2081f47d2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -630,6 +630,8 @@ Rails.application.routes.draw do collection do get :bank_list post :save_banks + get :my_courses + post :send_to_course end end From e82ef836d5d103c23228dbe9f8e4b89187d1442d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 27 Aug 2019 14:26:51 +0800 Subject: [PATCH 05/24] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E9=80=89=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/gtopic_banks_controller.rb | 32 ++++++++++++++++++++++ app/views/gtopic_banks/show.json.jbuilder | 6 ++++ config/routes.rb | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 app/controllers/gtopic_banks_controller.rb create mode 100644 app/views/gtopic_banks/show.json.jbuilder diff --git a/app/controllers/gtopic_banks_controller.rb b/app/controllers/gtopic_banks_controller.rb new file mode 100644 index 000000000..3629b87bc --- /dev/null +++ b/app/controllers/gtopic_banks_controller.rb @@ -0,0 +1,32 @@ +class GtopicBanksController < ApplicationController + before_action :require_login + before_action :find_bank + before_action :bank_admin, only: [:update] + + def show + @bank_attachments = @bank.attachments + end + + def update + @bank.update_attributes(gtopic_bank_params) + Attachment.associate_container(params[:attachment_ids], @graduation_topic.id, @graduation_topic.class) if params[:attachment_ids] + end + + private + + def find_bank + @bank = GtopicBank.find_by!(id: params[:id]) + tip_exception(403, "无权限") unless (current_user.certification_teacher? && (@bank.is_public || @bank.user_id == current_user.id)) || current_user.admin? + end + + def bank_admin + tip_exception(403, "无权限") unless (current_user.certification_teacher? && @bank.user_id == current_user.id) || current_user.admin? + end + + def gtopic_bank_params + tip_exception("name参数不能为空") if params[:gtopic_bank][:name].blank? + tip_exception("description参数不能为空") if params[:gtopic_bank][:description].blank? + params.require(:gtopic_bank).permit(:name, :topic_type, :topic_source, :topic_property_first, :description, + :topic_property_second, :source_unit, :topic_repeat, :province, :city) + end +end diff --git a/app/views/gtopic_banks/show.json.jbuilder b/app/views/gtopic_banks/show.json.jbuilder new file mode 100644 index 000000000..9c5226930 --- /dev/null +++ b/app/views/gtopic_banks/show.json.jbuilder @@ -0,0 +1,6 @@ +json.(@bank, :id, :name, :description, :is_public, :topic_type, :topic_source, :topic_property_first, :topic_property_second, + :source_unit, :topic_repeat, :province, :city) + +json.attachment_list @bank_attachments do |attachment| + json.partial! "attachments/attachment_simple", locals: {attachment: attachment} +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2081f47d2..c160cf938 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -641,6 +641,8 @@ Rails.application.routes.draw do end end + resources :gtopic_banks + resources :attachments resources :schools do From 953c621d71ea3221a52d18ea76e6bd22d98eb9c6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 27 Aug 2019 14:38:55 +0800 Subject: [PATCH 06/24] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/gtask_banks_controller.rb | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 app/controllers/gtask_banks_controller.rb diff --git a/app/controllers/gtask_banks_controller.rb b/app/controllers/gtask_banks_controller.rb new file mode 100644 index 000000000..12cba1e6d --- /dev/null +++ b/app/controllers/gtask_banks_controller.rb @@ -0,0 +1,2 @@ +class GtaskBanksController < ApplicationController +end From bb2f8c67ac0caca38ea1af4ec36f303f57c447e0 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 27 Aug 2019 15:35:02 +0800 Subject: [PATCH 07/24] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/gtask_banks_controller.rb | 2 -- app/controllers/gtopic_banks_controller.rb | 2 +- app/controllers/task_banks_controller.rb | 32 ++++++++++++++++++++++ app/views/task_banks/show.json.jbuilder | 14 ++++++++++ 4 files changed, 47 insertions(+), 3 deletions(-) delete mode 100644 app/controllers/gtask_banks_controller.rb create mode 100644 app/controllers/task_banks_controller.rb create mode 100644 app/views/task_banks/show.json.jbuilder diff --git a/app/controllers/gtask_banks_controller.rb b/app/controllers/gtask_banks_controller.rb deleted file mode 100644 index 12cba1e6d..000000000 --- a/app/controllers/gtask_banks_controller.rb +++ /dev/null @@ -1,2 +0,0 @@ -class GtaskBanksController < ApplicationController -end diff --git a/app/controllers/gtopic_banks_controller.rb b/app/controllers/gtopic_banks_controller.rb index 3629b87bc..002bc9848 100644 --- a/app/controllers/gtopic_banks_controller.rb +++ b/app/controllers/gtopic_banks_controller.rb @@ -9,7 +9,7 @@ class GtopicBanksController < ApplicationController def update @bank.update_attributes(gtopic_bank_params) - Attachment.associate_container(params[:attachment_ids], @graduation_topic.id, @graduation_topic.class) if params[:attachment_ids] + Attachment.associate_container(params[:attachment_ids], @bank.id, @bank.class) if params[:attachment_ids] end private diff --git a/app/controllers/task_banks_controller.rb b/app/controllers/task_banks_controller.rb new file mode 100644 index 000000000..7785d6d94 --- /dev/null +++ b/app/controllers/task_banks_controller.rb @@ -0,0 +1,32 @@ +class TaskBanksController < ApplicationController + before_action :require_login + before_action :find_bank + before_action :bank_admin, only: [:update] + + def show + @bank_attachments = @bank.attachments + end + + def update + @bank.update_attributes(gtask_bank_params) + Attachment.associate_container(params[:attachment_ids], @graduation_topic.id, @graduation_topic.class) if params[:attachment_ids] + end + + private + + def find_bank + @bank = GtaskBank.find_by!(id: params[:id]) + tip_exception(403, "无权限") unless (current_user.certification_teacher? && (@bank.is_public || @bank.user_id == current_user.id)) || current_user.admin? + end + + def bank_admin + tip_exception(403, "无权限") unless (current_user.certification_teacher? && @bank.user_id == current_user.id) || current_user.admin? + end + + def gtask_bank_params + tip_exception("name参数不能为空") if params[:gtopic_bank][:name].blank? + tip_exception("description参数不能为空") if params[:gtopic_bank][:description].blank? + params.require(:gtopic_bank).permit(:name, :topic_type, :topic_source, :topic_property_first, :description, + :topic_property_second, :source_unit, :topic_repeat, :province, :city) + end +end diff --git a/app/views/task_banks/show.json.jbuilder b/app/views/task_banks/show.json.jbuilder new file mode 100644 index 000000000..b929fafd8 --- /dev/null +++ b/app/views/task_banks/show.json.jbuilder @@ -0,0 +1,14 @@ +json.(@bank, :id, :name, :description, :task_type, :is_public) +# 附件 +json.attachments @bank_attachments do |attachment| + json.partial! "attachments/attachment_simple", locals: {attachment: attachment} +end + +# 分组要求 +if @bank.task_type == 2 + json.group_info do + json.max_number @bank.max_num + json.min_number @bank.min_num + json.base_on_project @bank.base_on_project + end +end From 2dace6763a53be3ac8035f9075a8cc8e4dbfaf3a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 27 Aug 2019 16:54:13 +0800 Subject: [PATCH 08/24] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/gtopic_banks_controller.rb | 7 ++++-- app/controllers/task_banks_controller.rb | 28 +++++++++++++++++----- config/routes.rb | 1 + 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/controllers/gtopic_banks_controller.rb b/app/controllers/gtopic_banks_controller.rb index 002bc9848..da56c7acf 100644 --- a/app/controllers/gtopic_banks_controller.rb +++ b/app/controllers/gtopic_banks_controller.rb @@ -8,8 +8,11 @@ class GtopicBanksController < ApplicationController end def update - @bank.update_attributes(gtopic_bank_params) - Attachment.associate_container(params[:attachment_ids], @bank.id, @bank.class) if params[:attachment_ids] + ActiveRecord::Base.transaction do + @bank.update_attributes(gtopic_bank_params) + Attachment.associate_container(params[:attachment_ids], @bank.id, @bank.class) if params[:attachment_ids] + normal_status(0, "更新成功") + end end private diff --git a/app/controllers/task_banks_controller.rb b/app/controllers/task_banks_controller.rb index 7785d6d94..9de4f1faf 100644 --- a/app/controllers/task_banks_controller.rb +++ b/app/controllers/task_banks_controller.rb @@ -8,8 +8,17 @@ class TaskBanksController < ApplicationController end def update - @bank.update_attributes(gtask_bank_params) - Attachment.associate_container(params[:attachment_ids], @graduation_topic.id, @graduation_topic.class) if params[:attachment_ids] + ActiveRecord::Base.transaction do + begin + @bank.update_attributes(gtask_bank_params) + Attachment.associate_container(params[:attachment_ids], @bank.id, @bank.class) if params[:attachment_ids] + normal_status(0, "更新成功") + rescue Exception => e + uid_logger(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback + end + end end private @@ -24,9 +33,16 @@ class TaskBanksController < ApplicationController end def gtask_bank_params - tip_exception("name参数不能为空") if params[:gtopic_bank][:name].blank? - tip_exception("description参数不能为空") if params[:gtopic_bank][:description].blank? - params.require(:gtopic_bank).permit(:name, :topic_type, :topic_source, :topic_property_first, :description, - :topic_property_second, :source_unit, :topic_repeat, :province, :city) + tip_exception("name参数不能为空") if params[:gtask_bank][:name].blank? + tip_exception("description参数不能为空") if params[:gtask_bank][:description].blank? + if @bank.homework_type == 3 + tip_exception("base_on_project参数不能为空") if params[:gtask_bank][:base_on_project].nil? + tip_exception("min_num参数不能为空") if params[:gtask_bank][:min_num].blank? + tip_exception("max_num参数不能为空") if params[:gtask_bank][:max_num].blank? + tip_exception("最小人数不能小于1") if params[:gtask_bank][:min_num].to_i < 1 + tip_exception("最大人数不能小于最小人数") if params[:gtask_bank][:max_num].to_i < params[:gtask_bank][:min_num].to_i + end + params.require(:gtask_bank).permit(:name, :description) if @bank.task_type == 1 + params.require(:gtask_bank).permit(:name, :description, :min_num, :max_num, :base_on_project) if @bank.task_type == 2 end end diff --git a/config/routes.rb b/config/routes.rb index c160cf938..8f357eb0b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -642,6 +642,7 @@ Rails.application.routes.draw do end resources :gtopic_banks + resources :task_banks resources :attachments From b3d30cac3f3b29851264aa09648d02c480f90b39 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 27 Aug 2019 17:16:55 +0800 Subject: [PATCH 09/24] =?UTF-8?q?=E9=80=89=E7=94=A8=E8=B5=84=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index a6eafe0f3..791d145c2 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -172,17 +172,17 @@ class FilesController < ApplicationController attachment_ids.each do |attachment_id| ori = Attachment.find_by_id(attachment_id) # 同一个资源可以多次发送到课堂 - @course.attachments.each do |att| - @exist = false - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from - att.created_on = Time.now - att.save - @exist = true - break - end - end - - next if @exist + # @course.attachments.each do |att| + # @exist = false + # if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + # att.created_on = Time.now + # att.save + # @exist = true + # break + # end + # end + # + # next if @exist attach_copied_obj = ori.copy attach_copied_obj.container = @course attach_copied_obj.created_on = Time.now From d403789253073198e49dd483e92424d985e42225 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 28 Aug 2019 11:09:23 +0800 Subject: [PATCH 10/24] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_banks_controller.rb | 71 ++++++++++++++++++++ app/models/exercise_bank_question.rb | 17 ++++- app/views/exercise_banks/show.json.jbuilder | 19 ++++++ config/routes.rb | 1 + 4 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 app/controllers/exercise_banks_controller.rb create mode 100644 app/views/exercise_banks/show.json.jbuilder diff --git a/app/controllers/exercise_banks_controller.rb b/app/controllers/exercise_banks_controller.rb new file mode 100644 index 000000000..c51688713 --- /dev/null +++ b/app/controllers/exercise_banks_controller.rb @@ -0,0 +1,71 @@ +class ExerciseBanksController < ApplicationController + before_action :require_login + before_action :find_bank + before_action :bank_admin, only: [:update] + + def show + @exercise_questions = @bank.exercise_bank_questions&.includes(:exercise_bank_choices, :exercise_bank_shixun_challenges, + :exercise_bank_standard_answers).order("question_number ASC") + @exercise_ques_count = @exercise_questions.size # 全部的题目数 + @exercise_ques_scores = @exercise_questions.pluck(:question_score).sum + + #单选题的数量及分数 + exercise_single_ques = @exercise_questions.find_by_custom("question_type", Exercise::SINGLE) + @exercise_single_ques_count = exercise_single_ques.size + @exercise_single_ques_scores = exercise_single_ques.pluck(:question_score).sum + + #多选题的数量及分数 + exercise_double_ques = @exercise_questions.find_by_custom("question_type", Exercise::MULTIPLE) + @exercise_double_ques_count = exercise_double_ques.size + @exercise_double_ques_scores = exercise_double_ques.pluck(:question_score).sum + + # 判断题数量及分数 + exercise_ques_judge = @exercise_questions.find_by_custom("question_type", Exercise::JUDGMENT) + @exercise_ques_judge_count = exercise_ques_judge.size + @exercise_ques_judge_scores = exercise_ques_judge.pluck(:question_score).sum + + #填空题数量及分数 + exercise_ques_null = @exercise_questions.find_by_custom("question_type", Exercise::COMPLETION) + @exercise_ques_null_count = exercise_ques_null.size + @exercise_ques_null_scores = exercise_ques_null.pluck(:question_score).sum + + #简答题数量及分数 + exercise_ques_main = @exercise_questions.find_by_custom("question_type", Exercise::SUBJECTIVE) + @exercise_ques_main_count = exercise_ques_main.size + @exercise_ques_main_scores = exercise_ques_main.pluck(:question_score).sum + + #实训题数量及分数 + exercise_ques_shixun = @exercise_questions.find_by_custom("question_type", Exercise::PRACTICAL) + @exercise_ques_shixun_count = exercise_ques_shixun.size + @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum + end + + def update + + end + + private + + def find_bank + @bank = ExerciseBank.find_by!(id: params[:id]) + tip_exception(403, "无权限") unless (current_user.certification_teacher? && (@bank.is_public || @bank.user_id == current_user.id)) || current_user.admin? + end + + def bank_admin + tip_exception(403, "无权限") unless (current_user.certification_teacher? && @bank.user_id == current_user.id) || current_user.admin? + end + + def gtask_bank_params + tip_exception("name参数不能为空") if params[:gtask_bank][:name].blank? + tip_exception("description参数不能为空") if params[:gtask_bank][:description].blank? + if @bank.homework_type == 3 + tip_exception("base_on_project参数不能为空") if params[:gtask_bank][:base_on_project].nil? + tip_exception("min_num参数不能为空") if params[:gtask_bank][:min_num].blank? + tip_exception("max_num参数不能为空") if params[:gtask_bank][:max_num].blank? + tip_exception("最小人数不能小于1") if params[:gtask_bank][:min_num].to_i < 1 + tip_exception("最大人数不能小于最小人数") if params[:gtask_bank][:max_num].to_i < params[:gtask_bank][:min_num].to_i + end + params.require(:gtask_bank).permit(:name, :description) if @bank.task_type == 1 + params.require(:gtask_bank).permit(:name, :description, :min_num, :max_num, :base_on_project) if @bank.task_type == 2 + end +end diff --git a/app/models/exercise_bank_question.rb b/app/models/exercise_bank_question.rb index 5a39fd5d2..af533836b 100644 --- a/app/models/exercise_bank_question.rb +++ b/app/models/exercise_bank_question.rb @@ -5,13 +5,16 @@ class ExerciseBankQuestion < ApplicationRecord has_many :exercise_bank_choices, :dependent => :destroy has_many :exercise_bank_standard_answers, :dependent => :destroy #attr_accessible :question_number, :question_score, :question_title, :question_type + scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 def question_type_name case self.question_type - when 1 + when 0 "单选题" - when 2 + when 1 "多选题" + when 2 + "判断题" when 3 "填空题" when 4 @@ -20,4 +23,14 @@ class ExerciseBankQuestion < ApplicationRecord "实训题" end end + + + #获取问题的全部标准答案 + def get_standard_answer_ids + exercise_bank_standard_answers.pluck(:exercise_bank_choice_id) + end + + def get_standard_answer_text + exercise_bank_standard_answers.pluck(:answer_text) + end end \ No newline at end of file diff --git a/app/views/exercise_banks/show.json.jbuilder b/app/views/exercise_banks/show.json.jbuilder new file mode 100644 index 000000000..773d7bf9f --- /dev/null +++ b/app/views/exercise_banks/show.json.jbuilder @@ -0,0 +1,19 @@ +json.exercise do + json.extract! @bank, :id, :name, :description, :is_public +end + +json.partial! "exercises/exercise_scores" + +json.exercise_questions do + json.array! @exercise_questions do |q| + json.partial! "exercise_questions/exercise_questions", + question: q, + choices:q.exercise_bank_choices, + shixun_challenges: q.exercise_bank_shixun_challenges, + exercise_type:1, + user_answer:[], + shixun_type:0, + ques_position:nil, + edit_type:nil + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3bed4265e..dcce1976b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -643,6 +643,7 @@ Rails.application.routes.draw do resources :gtopic_banks resources :task_banks + resources :exercise_banks resources :attachments From 51fe553ff9731449199dfecfdbe98ff24a8a03ba Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 28 Aug 2019 15:29:41 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_bank_questions_controller.rb | 2 + app/controllers/exercise_banks_controller.rb | 1 + app/helpers/exercise_bank_questions_helper.rb | 2 + app/models/exercise_bank_standard_answer.rb | 1 + .../_exercise_bank_questions.json.jbuilder | 69 +++++++++++++++++++ app/views/exercise_banks/show.json.jbuilder | 5 +- ...dd_is_ordered_to_exercise_bank_question.rb | 5 ++ 7 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 app/controllers/exercise_bank_questions_controller.rb create mode 100644 app/helpers/exercise_bank_questions_helper.rb create mode 100644 app/views/exercise_bank_questions/_exercise_bank_questions.json.jbuilder create mode 100644 db/migrate/20190828055710_add_is_ordered_to_exercise_bank_question.rb diff --git a/app/controllers/exercise_bank_questions_controller.rb b/app/controllers/exercise_bank_questions_controller.rb new file mode 100644 index 000000000..c7babb949 --- /dev/null +++ b/app/controllers/exercise_bank_questions_controller.rb @@ -0,0 +1,2 @@ +class ExerciseBankQuestionsController < ApplicationController +end diff --git a/app/controllers/exercise_banks_controller.rb b/app/controllers/exercise_banks_controller.rb index c51688713..e3d9718b3 100644 --- a/app/controllers/exercise_banks_controller.rb +++ b/app/controllers/exercise_banks_controller.rb @@ -1,3 +1,4 @@ +#encoding: UTF-8 class ExerciseBanksController < ApplicationController before_action :require_login before_action :find_bank diff --git a/app/helpers/exercise_bank_questions_helper.rb b/app/helpers/exercise_bank_questions_helper.rb new file mode 100644 index 000000000..10df0f5b3 --- /dev/null +++ b/app/helpers/exercise_bank_questions_helper.rb @@ -0,0 +1,2 @@ +module ExerciseBankQuestionsHelper +end diff --git a/app/models/exercise_bank_standard_answer.rb b/app/models/exercise_bank_standard_answer.rb index 9cd82afe6..2535473b0 100644 --- a/app/models/exercise_bank_standard_answer.rb +++ b/app/models/exercise_bank_standard_answer.rb @@ -2,4 +2,5 @@ class ExerciseBankStandardAnswer < ApplicationRecord belongs_to :exercise_bank_question belongs_to :exercise_bank_choice #attr_accessible :answer_text + scope :standard_by_ids, lambda { |s| where(exercise_bank_choice_id: s) } end \ No newline at end of file diff --git a/app/views/exercise_bank_questions/_exercise_bank_questions.json.jbuilder b/app/views/exercise_bank_questions/_exercise_bank_questions.json.jbuilder new file mode 100644 index 000000000..a77b8a975 --- /dev/null +++ b/app/views/exercise_bank_questions/_exercise_bank_questions.json.jbuilder @@ -0,0 +1,69 @@ +json.question_id question.id +q_positon = question.question_number +if ques_position.present? + q_positon = ques_position +end +json.q_position q_positon +json.question_title question.question_title +json.question_type question.question_type +json.question_score question.question_score.round(1).to_s +if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置 + standard_answers_array = question.get_standard_answer_ids + exercise_choices = choices.order("choice_position ASC") + json.question_choices exercise_choices.each do |a| + #TODO: 旧版本来一个题只有一个标准答案的,新版又做成了一个题有多个标准答案(exercise_choice_id存放的是标准答案的位置..) + standard_answer_b = standard_answers_array.join("").include?(a.choice_position.to_s) + choice_text = a.choice_text + if question.question_type == 2 + if choice_text == "对" + choice_text = "正确" + end + if choice_text == "错" + choice_text = "错误" + end + end + json.choice_id a.id + # json.choice_text (edit_type.present? || question.question_type == 2) ? a.choice_text : "#{(index+65).chr}.#{a.choice_text}" + + json.choice_text choice_text + json.choice_position a.choice_position + json.standard_boolean standard_answer_b + end + + json.standard_answer standard_answers_array + if question.question_type == 2 #返回答案的文字 + standard_text = standard_answers_array.first.to_i == 1 ? "正确" : "错误" + else + array_text_answer = [] + standard_answers_array.each{|a| array_text_answer.push((a+64).chr)} + standard_text = array_text_answer.join("") + end + json.standard_answer_show standard_text + +elsif question.question_type == 3 #当为填空题时 + standard_answers_count = question.exercise_bank_standard_answers + standard_answer_ex = standard_answers_count.pluck(:exercise_bank_choice_id).uniq + json.is_ordered question.is_ordered + json.multi_count standard_answer_ex.size #有几个填空 + json.standard_answer do + json.array! standard_answer_ex.each do |a| + s_answer_text = standard_answers_count.standard_by_ids(a).pluck(:answer_text) + json.choice_id a + json.answer_text s_answer_text + end + end +elsif question.question_type == 4 #简答题时 + json.standard_answer question.exercise_bank_standard_answers.pluck(:answer_text) +elsif question.question_type == 5 + json.shixun_id question.shixun_id + json.shixun_name question.shixun_name.present? ? question.shixun_name : "" + json.shixun_identifier question.shixun.identifier + json.shixun do + json.array! shixun_challenges do |s| + json.challenge_id s.challenge_id + json.challenge_position s.position + json.challenge_name s.challenge.subject + json.challenge_score s.question_score.round(1).to_s + end + end +end \ No newline at end of file diff --git a/app/views/exercise_banks/show.json.jbuilder b/app/views/exercise_banks/show.json.jbuilder index 773d7bf9f..1b2a931fa 100644 --- a/app/views/exercise_banks/show.json.jbuilder +++ b/app/views/exercise_banks/show.json.jbuilder @@ -6,13 +6,10 @@ json.partial! "exercises/exercise_scores" json.exercise_questions do json.array! @exercise_questions do |q| - json.partial! "exercise_questions/exercise_questions", + json.partial! "exercise_bank_questions/exercise_bank_questions", question: q, choices:q.exercise_bank_choices, shixun_challenges: q.exercise_bank_shixun_challenges, - exercise_type:1, - user_answer:[], - shixun_type:0, ques_position:nil, edit_type:nil end diff --git a/db/migrate/20190828055710_add_is_ordered_to_exercise_bank_question.rb b/db/migrate/20190828055710_add_is_ordered_to_exercise_bank_question.rb new file mode 100644 index 000000000..967d89e5f --- /dev/null +++ b/db/migrate/20190828055710_add_is_ordered_to_exercise_bank_question.rb @@ -0,0 +1,5 @@ +class AddIsOrderedToExerciseBankQuestion < ActiveRecord::Migration[5.2] + def change + add_column :exercise_bank_questions, :is_ordered, :boolean, :default => true + end +end From 25e5a304ae9e2a335fa744deef2dfb233ab4fecd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Wed, 28 Aug 2019 16:45:37 +0800 Subject: [PATCH 12/24] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=A2=9E=E5=8A=A0=E5=88=A0=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/tpm/TPMsettings/TPMsettings.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js index 089b0b525..50358aba6 100644 --- a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js +++ b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js @@ -2179,19 +2179,18 @@ export default class TPMsettings extends Component { :""} - {/*"name": "我是镜像名", # 镜像名称*/} - {/*"cpu_limit": 1, # cpu核*/} - {/*"lower_cpu_limit": 0.1, # 最低cpu核 浮点数*/} - {/*"memory_limit": 1024 ,#内存限制*/} - {/*"request_limit": 10, # 内存要求*/} - {/*"mirror_repository_id": 12, # 镜像id*/} + {this.props.identity<3?

服务配置

{ shixun_service_configs&&shixun_service_configs.map((item,key)=>{ + return(
-

{item.name}

+

+ {item.name} + this.Deselectlittle(item.mirror_repository_id)}> +

From 14fd93f7bed8643f740eb6b9546327df7c9d8cd0 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 28 Aug 2019 16:47:49 +0800 Subject: [PATCH 13/24] =?UTF-8?q?=E7=A7=BB=E9=99=A4scripts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/scripts/build.js | 189 ----------------------------- public/react/src/scripts/concat.js | 169 -------------------------- public/react/src/scripts/start.js | 114 ----------------- public/react/src/scripts/test.js | 27 ----- 4 files changed, 499 deletions(-) delete mode 100644 public/react/src/scripts/build.js delete mode 100644 public/react/src/scripts/concat.js delete mode 100644 public/react/src/scripts/start.js delete mode 100644 public/react/src/scripts/test.js diff --git a/public/react/src/scripts/build.js b/public/react/src/scripts/build.js deleted file mode 100644 index ae6eade9b..000000000 --- a/public/react/src/scripts/build.js +++ /dev/null @@ -1,189 +0,0 @@ -'use strict'; - -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'production'; -process.env.NODE_ENV = 'production'; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -// Ensure environment variables are read. -require('../config/env'); - -const path = require('path'); -const chalk = require('chalk'); -const fs = require('fs-extra'); -const webpack = require('webpack'); -const config = require('../config/webpack.config.prod'); -const paths = require('../config/paths'); -const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); -const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages'); -const printHostingInstructions = require('react-dev-utils/printHostingInstructions'); -const FileSizeReporter = require('react-dev-utils/FileSizeReporter'); -const printBuildError = require('react-dev-utils/printBuildError'); - -var CombinedStream = require('combined-stream'); -var fs2 = require('fs'); - -const measureFileSizesBeforeBuild = - FileSizeReporter.measureFileSizesBeforeBuild; -const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; -const useYarn = fs.existsSync(paths.yarnLockFile); - -// These sizes are pretty large. We'll warn for bundles exceeding them. -const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024; -const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; - -// Warn and crash if required files are missing -if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { - process.exit(1); -} - -// First, read the current file sizes in build directory. -// This lets us display how much they changed later. -measureFileSizesBeforeBuild(paths.appBuild) - .then(previousFileSizes => { - // Remove all content but keep the directory so that - // if you're in it, you don't end up in Trash - fs.emptyDirSync(paths.appBuild); - // Merge with the public folder - copyPublicFolder(); - // Start the webpack build - return build(previousFileSizes); - }) - .then( - ({ stats, previousFileSizes, warnings }) => { - if (warnings.length) { - console.log(chalk.yellow('Compiled with warnings.\n')); - console.log(warnings.join('\n\n')); - console.log( - '\nSearch for the ' + - chalk.underline(chalk.yellow('keywords')) + - ' to learn more about each warning.' - ); - console.log( - 'To ignore, add ' + - chalk.cyan('// eslint-disable-next-line') + - ' to the line before.\n' - ); - } else { - console.log(chalk.green('Compiled successfully.\n')); - } - - console.log('File sizes after gzip:\n'); - printFileSizesAfterBuild( - stats, - previousFileSizes, - paths.appBuild, - WARN_AFTER_BUNDLE_GZIP_SIZE, - WARN_AFTER_CHUNK_GZIP_SIZE - ); - console.log(); - - const appPackage = require(paths.appPackageJson); - const publicUrl = paths.publicUrl; - const publicPath = config.output.publicPath; - const buildFolder = path.relative(process.cwd(), paths.appBuild); - printHostingInstructions( - appPackage, - publicUrl, - publicPath, - buildFolder, - useYarn - ); - }, - err => { - console.log(chalk.red('Failed to compile.\n')); - printBuildError(err); - process.exit(1); - } - ); - -// Create the production build and print the deployment instructions. -function build(previousFileSizes) { - console.log('Creating an optimized production build...'); - - let compiler = webpack(config); - return new Promise((resolve, reject) => { - compiler.run((err, stats) => { - if (err) { - return reject(err); - } - const messages = formatWebpackMessages(stats.toJson({}, true)); - if (messages.errors.length) { - // Only keep the first error. Others are often indicative - // of the same problem, but confuse the reader with noise. - if (messages.errors.length > 1) { - messages.errors.length = 1; - } - return reject(new Error(messages.errors.join('\n\n'))); - } - if ( - process.env.CI && - (typeof process.env.CI !== 'string' || - process.env.CI.toLowerCase() !== 'false') && - messages.warnings.length - ) { - console.log( - chalk.yellow( - '\nTreating warnings as errors because process.env.CI = true.\n' + - 'Most CI servers set it automatically.\n' - ) - ); - return reject(new Error(messages.warnings.join('\n\n'))); - } - - generateNewIndexJsp(); - - return resolve({ - stats, - previousFileSizes, - warnings: messages.warnings, - }); - }); - }); -} - -function copyPublicFolder() { - fs.copySync(paths.appPublic, paths.appBuild, { - dereference: true, - filter: file => file !== paths.appHtml, - }); -} - - -function generateNewIndexJsp() { - // var combinedStream = CombinedStream.create(); - var filePath = paths.appBuild + '/index.html'; - // var htmlContent = fs2.createReadStream( filePath ) - - // stream没有replace方法 - // htmlContent = htmlContent.replace('/js/js_min_all.js', '/react/build/js/js_min_all.js') - // htmlContent = htmlContent.replace('/css/css_min_all.css', '/react/build/css/css_min_all.css') - - // combinedStream.append(htmlContent); - // combinedStream.pipe(fs2.createWriteStream( filePath )); - - var outputPath = paths.appBuild + '/../../../app/views/common/index.html.erb' - fs2.readFile(filePath, 'utf8', function (err,data) { - if (err) { - return console.log(err); - } - var result = data.replace('/js/js_min_all.js', '/react/build/js/js_min_all.js') - .replace('/js/js_min_all_2.js', '/react/build/js/js_min_all_2.js') - - .replace('/css/css_min_all.css', '/react/build/css/css_min_all.css') - .replace('/js/create_kindeditor.js', '/react/build/js/create_kindeditor.js') - .replace(/http:\/\/localhost:3000/g, ''); - - // .replace('/css/css_min_all.css', '/react/build/css/css_min_all.css'); - - fs2.writeFile(outputPath, result, 'utf8', function (err) { - if (err) return console.log(err); - }); - }); -} \ No newline at end of file diff --git a/public/react/src/scripts/concat.js b/public/react/src/scripts/concat.js deleted file mode 100644 index e327e50a4..000000000 --- a/public/react/src/scripts/concat.js +++ /dev/null @@ -1,169 +0,0 @@ -var fs = require('fs'); -var uglify = require("uglify-js"); -var path = require('path'); -var concat = require('concat') - -var results = []; -var walk = function(dir, done) { - - fs.readdir(dir, function(err, list) { - console.log(list) - if (err) return done(err); - var pending = list.length; - if (!pending) return done(null, results); - list.forEach(function(file) { - file = path.resolve(dir, file); - fs.stat(file, function(err, stat) { - if (stat && stat.isDirectory()) { - walk(file, function(err, res) { - // results = results.concat(res); - if (!--pending) done(null, results); - }); - } else { - results.push(file); - if (!--pending) done(null, results); - } - }); - }); - }); -}; - -// 需要输出文件名数组时改为true -var jsDir = './public/js/'; -var cssDir = './public/css' - -// true && -false && -walk(cssDir, function() { - console.log('results', results.length, results) -}) -// return; - -// ----------------------------------------------------------------------------- CSS - var cssResults = [ - - 'D:\\Code\\trustieplus\\public\\react\\public\\css\\edu-common.css', - 'D:\\Code\\trustieplus\\public\\react\\public\\css\\edu-public.css', - 'D:\\Code\\trustieplus\\public\\react\\public\\css\\taskstyle.css' , - - 'D:\\Code\\trustieplus\\public\\react\\public\\css\\font-awesome.css', - - 'D:\\Code\\trustieplus\\public\\react\\public\\css\\editormd.min.css', - 'D:\\Code\\trustieplus\\public\\react\\public\\css\\merge.css', - - ] - concat(cssResults, './public/css/css_min_all.css') - -return; - -// ----------------------------------------------------------------------------- JS - var _results = [ - - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\jquery-1.8.3.min.js', - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\editormd\\underscore.min.js', - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\editormd\\marked.min.js', - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\editormd\\prettify.min.js', - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\editormd\\raphael.min.js', - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\editormd\\sequence-diagram.min.js', - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\editormd\\flowchart.min.js', - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\editormd\\jquery.flowchart.min.js', - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\editormd\\editormd.min.js', - - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\codemirror\\codemirror.js', - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\codemirror\\mode\\javascript.js', - - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\diff_match_patch.js', - - - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\merge.js', - - 'D:\\Code\\trustieplus\\public\\react\\public\\js\\edu_tpi.js', - - ] - - // 合并js时,需确保每个js都正常结束,未正常结束的需要在js文件结尾加一个;好,不然会出现脚本错。 - concat(_results, './public/js/js_min_all.js') - - // var uglified = uglify.minify(['./public/js/merge.js']); - // console.log('uglified', uglified) - // fs.writeFile('concat.min.js', uglified.code, function (err){ - // if(err) { - // console.log(err); - // } else { - // console.log("Script generated and saved:", 'concat.min.js'); - // } - // }); - - -// var uglified = uglify.minify(['file1.js', 'file2.js', 'file3.js']); - - - -/** - 优化 - underscore被单独加载了,去掉'D:\\Code\\trustieplus\\public\\react\\public\\js\\editormd\\underscore.min.js', - marked - raphaeljs sequence diagrams 1.0.4 - - - 统计 js_min_all加载的js: - https://github.com/paulmillr/es6-shim - jQuery v1.8.3 jquery.com - Underscore.js 1.8.2 - marked v0.3.3 - ??? - Raphaël 2.1.3 - JavaScript Vector Library - flowchart, v1.3.4 - editormd.js - - // Codemirror单独放置,哪些地方还在使用Codemirror? - // 新版使用了Monaco 无需一些Codemirror插件了 - CodeMirror - cm active-line.js - cm mode javascript - cm merge.js - CodeMirror addon hint - cm showHint - cm anyword-hint - CodeMirror python - CodeMirror c-like(java) - CodeMirror matchbrackets - - 余下 - CodeMirror - diff - merge - - 移除的在js_min_cm.js - /** - active-line.js - mode javascript - fuzzysort - showHint - javascript-hint - anyword-hint - CodeMirror python - CodeMirror c-like(java) - CodeMirror matchbrackets - - / - - ???——> - // Copyright (C) 2006 Google Inc. - // - // Licensed under the Apache License, Version 2.0 (the "License"); - // you may not use this file except in compliance with the License. - // You may obtain a copy of the License at - // - // http://www.apache.org/licenses/LICENSE-2.0 - // - // Unless required by applicable law or agreed to in writing, software - // distributed under the License is distributed on an "AS IS" BASIS, - // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - // See the License for the specific language governing permissions and - // limitations under the License. - - - 去掉了 - marked v0.3.3 去不了,去掉后 这句代码会报错:window.editormd.markdownToHTML , TODO 看能否去掉单独加载marked的地方 - */ \ No newline at end of file diff --git a/public/react/src/scripts/start.js b/public/react/src/scripts/start.js deleted file mode 100644 index 3f68f1576..000000000 --- a/public/react/src/scripts/start.js +++ /dev/null @@ -1,114 +0,0 @@ -'use strict'; - -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'development'; -process.env.NODE_ENV = 'development'; - - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -// Ensure environment variables are read. -require('../config/env'); - -const fs = require('fs'); -const chalk = require('chalk'); -const webpack = require('webpack'); -const WebpackDevServer = require('webpack-dev-server'); -const clearConsole = require('react-dev-utils/clearConsole'); -const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles'); -const { - choosePort, - createCompiler, - prepareProxy, - prepareUrls, -} = require('react-dev-utils/WebpackDevServerUtils'); -const openBrowser = require('react-dev-utils/openBrowser'); -const paths = require('../config/paths'); -const config = require('../config/webpack.config.dev'); -const createDevServerConfig = require('../config/webpackDevServer.config'); - -const useYarn = fs.existsSync(paths.yarnLockFile); -const isInteractive = process.stdout.isTTY; - -const portSetting = require(paths.appPackageJson).port -if ( portSetting ) { - process.env.port = portSetting -} - -// Warn and crash if required files are missing -if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { - process.exit(1); -} - -// Tools like Cloud9 rely on this. -const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000; -const HOST = process.env.HOST || '0.0.0.0'; - -if (process.env.HOST) { - console.log( - chalk.cyan( - `Attempting to bind to HOST environment variable: ${chalk.yellow( - chalk.bold(process.env.HOST) - )}` - ) - ); - console.log( - `If this was unintentional, check that you haven't mistakenly set it in your shell.` - ); - console.log(`Learn more here: ${chalk.yellow('http://bit.ly/2mwWSwH')}`); - console.log(); -} - -// We attempt to use the default port but if it is busy, we offer the user to -// run on a different port. `choosePort()` Promise resolves to the next free port. -choosePort(HOST, DEFAULT_PORT) - .then(port => { - if (port == null) { - // We have not found a port. - return; - } - const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; - const appName = require(paths.appPackageJson).name; - const urls = prepareUrls(protocol, HOST, port); - // Create a webpack compiler that is configured with custom messages. - const compiler = createCompiler(webpack, config, appName, urls, useYarn); - // Load proxy config - const proxySetting = require(paths.appPackageJson).proxy; - console.log('-------------------------proxySetting:', proxySetting) - const proxyConfig = prepareProxy(proxySetting, paths.appPublic); - // Serve webpack assets generated by the compiler over a web sever. - const serverConfig = createDevServerConfig( - proxyConfig, - urls.lanUrlForConfig - ); - const devServer = new WebpackDevServer(compiler, serverConfig); - // Launch WebpackDevServer. - devServer.listen(port, HOST, err => { - if (err) { - return console.log(err); - } - if (isInteractive) { - clearConsole(); - } - console.log(chalk.cyan('Starting the development server...\n')); - openBrowser(urls.localUrlForBrowser); - }); - - ['SIGINT', 'SIGTERM'].forEach(function(sig) { - process.on(sig, function() { - devServer.close(); - process.exit(); - }); - }); - }) - .catch(err => { - if (err && err.message) { - console.log(err.message); - } - process.exit(1); - }); diff --git a/public/react/src/scripts/test.js b/public/react/src/scripts/test.js deleted file mode 100644 index 45fd882fd..000000000 --- a/public/react/src/scripts/test.js +++ /dev/null @@ -1,27 +0,0 @@ -'use strict'; - -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'test'; -process.env.NODE_ENV = 'test'; -process.env.PUBLIC_URL = ''; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -// Ensure environment variables are read. -require('../config/env'); - -const jest = require('jest'); -const argv = process.argv.slice(2); - -// Watch unless on CI or in coverage mode -if (!process.env.CI && argv.indexOf('--coverage') < 0) { - argv.push('--watch'); -} - - -jest.run(argv); From 2191946088a2cc798ba5b1fa7a3b766ed0eceaf4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 28 Aug 2019 16:48:35 +0800 Subject: [PATCH 14/24] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index d9ab31b8d..38b4bea4d 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -348,7 +348,8 @@ class ShixunsController < ApplicationController sub_type.each do |mirror| ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror) # 实训子镜像服务配置 - ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror) + name = MirrorRepository.find_by(id: mirror).try(:name) #查看镜像是否有名称,如果没有名称就不用服务配置 + ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror) if name.present? end end @@ -422,6 +423,7 @@ class ShixunsController < ApplicationController # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 if current_user.admin? || current_user.business? @shixun.shixun_service_configs.destroy_all + logger.info("######service_config_params[:shixun_service_configs]:#{service_config_params[:shixun_service_configs]}") @shixun.shixun_service_configs.create!(service_config_params[:shixun_service_configs]) end rescue Exception => e From a39b5e60987077d8eebc66416f448f9212c88947 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 28 Aug 2019 16:50:24 +0800 Subject: [PATCH 15/24] sharetest --- public/react/src/modules/test/ShareTest.js | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 public/react/src/modules/test/ShareTest.js diff --git a/public/react/src/modules/test/ShareTest.js b/public/react/src/modules/test/ShareTest.js new file mode 100644 index 000000000..293396109 --- /dev/null +++ b/public/react/src/modules/test/ShareTest.js @@ -0,0 +1,35 @@ +/** + + + + */ + +if(window.wx) { + wx.ready(function () { //需在用户可能点击分享按钮前就先调用 + alert('got wx1') + wx.updateAppMessageShareData({ + title: ' title', // 分享标题 + desc: 'hello world', // 分享描述 + link: 'https://www.educoder.net', // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 + imgUrl: 'https://pre-newweb.educoder.net/images/educoder/headNavLogo.png', // 分享图标 + success: function () { + // 设置成功 + } + }) + }); + +// wx.onMenuShareAppMessage({ +//             title:' title', // 分享标题 +//             desc:'hello world', // 分享描述 +//             link: 'https://www.educoder.net', //location.href, // 分享链接 +//             imgUrl: 'https://pre-newweb.educoder.net/images/educoder/headNavLogo.png', // 分享图标 +//             type: '', // 分享类型,music、video或link,不填默认为link +//             dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空 +//             success: function () {  +//                 // 用户确认分享后执行的回调函数 +//             }, +//             cancel: function () {  +//                 // 用户取消分享后执行的回调函数 +//             } +//         }); + } \ No newline at end of file From f229346cb84afdd9e142139d20b0d2c150eb6aa8 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 28 Aug 2019 16:53:58 +0800 Subject: [PATCH 16/24] =?UTF-8?q?=E9=95=9C=E5=83=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 38b4bea4d..64c0cf1ae 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -424,7 +424,11 @@ class ShixunsController < ApplicationController if current_user.admin? || current_user.business? @shixun.shixun_service_configs.destroy_all logger.info("######service_config_params[:shixun_service_configs]:#{service_config_params[:shixun_service_configs]}") - @shixun.shixun_service_configs.create!(service_config_params[:shixun_service_configs]) + service_config_params[:shixun_service_configs].each do |config| + name = MirrorRepository.find_by_id(config[:mirror_repository_id])&.name + # 不保存没有镜像的配置 + @shixun.shixun_service_configs.create!(config) if name.present? + end end rescue Exception => e uid_logger_error(e.message) From b47e8ab58ce9ec5b6daaf861088501e4a4fd2c2c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 28 Aug 2019 16:54:45 +0800 Subject: [PATCH 17/24] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 64c0cf1ae..78e6cc0f0 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -423,8 +423,8 @@ class ShixunsController < ApplicationController # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 if current_user.admin? || current_user.business? @shixun.shixun_service_configs.destroy_all - logger.info("######service_config_params[:shixun_service_configs]:#{service_config_params[:shixun_service_configs]}") service_config_params[:shixun_service_configs].each do |config| + logger.info("####{config[:mirror_repository_id]}") name = MirrorRepository.find_by_id(config[:mirror_repository_id])&.name # 不保存没有镜像的配置 @shixun.shixun_service_configs.create!(config) if name.present? From 76c9020b766b3f092fc435bd5d6539768453a016 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 28 Aug 2019 16:54:47 +0800 Subject: [PATCH 18/24] =?UTF-8?q?=E7=A6=81=E7=94=A8zoom=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=EF=BC=8C=E7=AE=97=E6=B3=95=E4=B8=8D=E5=AF=B9=EF=BC=8C=E6=9C=89?= =?UTF-8?q?=E4=BA=9B=E6=98=BE=E7=A4=BA=E5=99=A8=EF=BC=88=E5=B0=8F=E7=B1=B3?= =?UTF-8?q?=E7=AC=94=E8=AE=B0=E6=9C=AC=EF=BC=89=E9=BB=98=E8=AE=A4=E4=B8=BA?= =?UTF-8?q?125?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/page/Index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/react/src/modules/page/Index.js b/public/react/src/modules/page/Index.js index c695a0022..b2daa27e4 100644 --- a/public/react/src/modules/page/Index.js +++ b/public/react/src/modules/page/Index.js @@ -55,12 +55,12 @@ class Index extends Component { window.$('#root').css('position', 'absolute') // TPI浏览器缩放 - setTimeout(() => { - const agent = navigator.userAgent; - if (agent.indexOf('Mac OS') == -1) { - window._initZoomCheck() - } - }, 800) + // setTimeout(() => { + // const agent = navigator.userAgent; + // if (agent.indexOf('Mac OS') == -1) { + // window._initZoomCheck() + // } + // }, 800) this.onDrawerButtonClick = this.onDrawerButtonClick.bind(this) From 8dbaf05da29cc9c80257cab9e060191bd55328d4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 28 Aug 2019 17:24:23 +0800 Subject: [PATCH 19/24] =?UTF-8?q?=E5=B0=8F=E7=B1=BB=E5=88=AB=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7c8015894..951baea86 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -428,7 +428,7 @@ class ApplicationController < ActionController::Base list = [] mirrors = MirrorRepository.select([:id, :type_name]).published_small_mirror mirrors.try(:each) do |mirror| - list << {id: mirror.id, type_name: mirror.type_name} + list << {id: mirror.id, type_name: mirror.type_name, description: mirror.description} end list end From cbb95d3022d5a94d5daa1bf4aff4e52fcde2dafe Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 28 Aug 2019 17:25:47 +0800 Subject: [PATCH 20/24] =?UTF-8?q?=E5=B0=8F=E7=B1=BB=E5=88=AB=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 951baea86..6046be5af 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -426,7 +426,7 @@ class ApplicationController < ActionController::Base # 小类别列表 def shixun_small_type list = [] - mirrors = MirrorRepository.select([:id, :type_name]).published_small_mirror + mirrors = MirrorRepository.select([:id, :type_name, :description]).published_small_mirror mirrors.try(:each) do |mirror| list << {id: mirror.id, type_name: mirror.type_name, description: mirror.description} end From 9b3ae694ff2910491ba0d25c06b54852cb5dd707 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 28 Aug 2019 17:28:22 +0800 Subject: [PATCH 21/24] =?UTF-8?q?=E6=96=87=E5=AD=97=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../react/src/modules/page/component/TPICodeSetting.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/public/react/src/modules/page/component/TPICodeSetting.js b/public/react/src/modules/page/component/TPICodeSetting.js index 27ad3746b..51a9f390c 100644 --- a/public/react/src/modules/page/component/TPICodeSetting.js +++ b/public/react/src/modules/page/component/TPICodeSetting.js @@ -146,23 +146,25 @@ class TPICodeSetting extends Component { {/* */}
- +
跳关
{ task_pass ? '允许' : '不允许'}
+
+ + : "不允许学员通过金币解锁查看测试集内容"} disableFocusListener={true}>
测试集解锁
{ test_set_permission ? '允许' : '不允许'}
- +
代码复制粘贴
From d4f409b54ea2efcb7964830b8240482aac651ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Wed, 28 Aug 2019 17:32:05 +0800 Subject: [PATCH 22/24] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/tpm/TPMsettings/TPMsettings.js | 65 +++++++++++++++---- .../src/modules/tpm/newshixuns/Newshixuns.js | 8 ++- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js index 50358aba6..839638344 100644 --- a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js +++ b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js @@ -560,13 +560,32 @@ export default class TPMsettings extends Component { } bigClass = (value) => { + // choice_main_type + // choice_small_type + let {settingsData,shixun_service_configs,choice_main_type,choice_small_type}=this.state; + + let list=[] + list.push(choice_main_type) + choice_small_type.map((item,key)=>{ + list.push(item) + }) + + let newshixun_service_configs=shixun_service_configs; + + let newshixun_service_configsagin=[] + + newshixun_service_configs.map((item,key)=>{ + list.map((its,index)=>{ + if(item.mirror_repository_id===its){ + newshixun_service_configsagin.push(item) + } + }) + }) - let {settingsData,shixun_service_configs}=this.state; - let newshixun_service_configs=shixun_service_configs; settingsData.shixun.main_type.some((item,key)=> { if (item.id === value) { - newshixun_service_configs[0]={ + newshixun_service_configsagin[0]={ mirror_repository_id:value, name:item.type_name, cpu_limit:1, @@ -586,8 +605,8 @@ export default class TPMsettings extends Component { choice_main_type: value, standard_scripts:response.data, choice_standard_scripts:null, - shixun_service_configs:newshixun_service_configs, - shixun_service_configlist:newshixun_service_configs, + shixun_service_configs:newshixun_service_configsagin, + shixun_service_configlist:newshixun_service_configsagin, }) } }).catch((error) => { @@ -628,7 +647,7 @@ export default class TPMsettings extends Component { } littleClass = (value) => { - let {settingsData,shixun_service_configs,choice_small_type}=this.state; + let {settingsData,shixun_service_configs,choice_small_type,choice_main_type}=this.state; let newshixun_service_configs=shixun_service_configs; let newchoice_small_type=choice_small_type; // if(Array.isArray(value)===true){ @@ -649,9 +668,26 @@ export default class TPMsettings extends Component { // ) // }) // } + + let list=[] + list.push(choice_main_type) + choice_small_type.map((item,key)=>{ + list.push(item) + }) + + let newshixun_service_configsagin=[] + + newshixun_service_configs.map((item,key)=>{ + list.map((its,index)=>{ + if(item.mirror_repository_id===its){ + newshixun_service_configsagin.push(item) + } + }) + }) + settingsData.shixun.small_type.some((items,keys)=> { if (items.id === value) { - newshixun_service_configs.push({ + newshixun_service_configsagin.push({ mirror_repository_id:value, name:items.type_name, cpu_limit:1, @@ -666,10 +702,11 @@ export default class TPMsettings extends Component { newchoice_small_type.push(value) + consoe.log(newshixun_service_configsagin) this.setState({ choice_small_type: newchoice_small_type, - shixun_service_configs:newshixun_service_configs, - shixun_service_configlist:newshixun_service_configs, + shixun_service_configs:newshixun_service_configsagin, + shixun_service_configlist:newshixun_service_configsagin, }) } onPodExistTimeChange = (e) => { @@ -1609,7 +1646,7 @@ export default class TPMsettings extends Component { settingsData === undefined ? "" : settingsData.shixun.main_type.map((item, key) => { return ( @@ -1738,7 +1775,11 @@ export default class TPMsettings extends Component { { settingsData === undefined ? "" : settingsData.shixun.small_type.map((item, key) => { return( - + ) }) } @@ -2189,7 +2230,7 @@ export default class TPMsettings extends Component {

{item.name} - this.Deselectlittle(item.mirror_repository_id)}> + {/*this.Deselectlittle(item.mirror_repository_id)}>*/}

diff --git a/public/react/src/modules/tpm/newshixuns/Newshixuns.js b/public/react/src/modules/tpm/newshixuns/Newshixuns.js index e4e37d15a..fbbc807b5 100644 --- a/public/react/src/modules/tpm/newshixuns/Newshixuns.js +++ b/public/react/src/modules/tpm/newshixuns/Newshixuns.js @@ -994,7 +994,7 @@ class Newshixuns extends Component { newshixunlist === undefined ? "" : newshixunlist.main_type.map((item, key) => { return ( @@ -1119,7 +1119,11 @@ class Newshixuns extends Component { { newshixunlist === undefined ? "" : newshixunlist.small_type.map((item, key) => { return ( - + ) }) } From 0c31fc2675f5b67487a568d38a5fd317da66db7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Wed, 28 Aug 2019 17:35:40 +0800 Subject: [PATCH 23/24] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/tpm/TPMsettings/TPMsettings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js index 839638344..a011dc1b2 100644 --- a/public/react/src/modules/tpm/TPMsettings/TPMsettings.js +++ b/public/react/src/modules/tpm/TPMsettings/TPMsettings.js @@ -702,7 +702,6 @@ export default class TPMsettings extends Component { newchoice_small_type.push(value) - consoe.log(newshixun_service_configsagin) this.setState({ choice_small_type: newchoice_small_type, shixun_service_configs:newshixun_service_configsagin, From 773a33f06bb75aa3a8a6faceb8fc8249d9edfee3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 29 Aug 2019 08:53:22 +0800 Subject: [PATCH 24/24] =?UTF-8?q?=E9=A2=98=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_bank_questions_controller.rb | 386 ++++++++++++++++++ app/controllers/exercise_banks_controller.rb | 18 +- app/controllers/gtopic_banks_controller.rb | 6 +- app/models/exercise_bank.rb | 3 + app/models/exercise_bank_choice.rb | 3 + app/models/exercise_bank_question.rb | 4 + .../_exercise_bank_questions.json.jbuilder | 5 +- app/views/gtopic_banks/edit.json.jbuilder | 15 + 8 files changed, 423 insertions(+), 17 deletions(-) create mode 100644 app/views/gtopic_banks/edit.json.jbuilder diff --git a/app/controllers/exercise_bank_questions_controller.rb b/app/controllers/exercise_bank_questions_controller.rb index c7babb949..416358af6 100644 --- a/app/controllers/exercise_bank_questions_controller.rb +++ b/app/controllers/exercise_bank_questions_controller.rb @@ -1,2 +1,388 @@ class ExerciseBankQuestionsController < ApplicationController + before_action :require_login, :check_auth #用户需登陆 + before_action :get_exercise, only:[:create] #获取试卷 + before_action :get_exercise_question, except: [:create] #获取试卷的问题及试卷 + before_action :bank_admin #是否为老师 + before_action :validate_params, only: [:create, :update] #传入参数的验证 + + def create + ActiveRecord::Base.transaction do + begin + question_options = { + :question_title => params[:question_title], + :question_type => params[:question_type].present? ? params[:question_type].to_i : 0, #默认为单选题 + :question_number => @exercise.exercise_bank_questions.count + 1, + :question_score => params[:question_score].present? ? params[:question_score].to_f.round(1) : 5.0, + :shixun_id => params[:shixun_id].blank? ? "" : params[:shixun_id], + :is_ordered => params[:is_ordered] # 填空题的答案是否为一一对应关系,默认为true即为一一对应 + } + @exercise_question = @exercise.exercise_bank_questions.new(question_options) + #插入问题时,那么从插入的这个id以后的question_num都将要+1 + if params[:insert_id].present? + insert_exercise = @exercise.exercise_bank_questions.find_by(id: params[:insert_id]) + if insert_exercise.present? #如果该问题存在的话,意思是如果是第一题,那么就不存在插入 + ques_num = insert_exercise.question_number.to_i + @exercise_question.question_number = ques_num + 1 #更新了问题的位置 + @exercise.exercise_bank_questions.insert_question_ex(ques_num).update_all("question_number = question_number + 1") + end + end + + if @exercise_question.save + #为选择题(包括单选和多选)的时候,创建问题选项 + ques_type = @exercise_question.question_type + if ques_type <= Exercise::MULTIPLE + choices_array = params[:question_choices] + choices_count= choices_array.count + standard_answer = params[:standard_answers] #为数组格式,因为可能会有单选和多选,标准答案,已提前判断不能为空, + standard_answer = standard_answer.uniq.reject(&:blank?) + (1..choices_count).each do |c| + choice = choices_array[c-1] #每一个选项的内容 + choice_option = { + :choice_position => c, + :choice_text => choice.strip + } + question_choices = @exercise_question.exercise_bank_choices.new(choice_option) + question_choices.save + end + #标准答案的存储,如:["1","2","3"..]等,1对应A,2对应B,3对应C。。。 + standard_answer.each do |a| + choice_id = a.to_i + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :exercise_bank_choice_id => choice_id #即为选择的位置参数 + } + question_standard_answer = ExerciseBankStandardAnswer.new(standard_option) + question_standard_answer.save + if standard_answer.count > 1 && ques_type == Exercise::SINGLE #当标准答案数大于1,且不为多选时,修改为多选 + @exercise_question.update_attribute("question_type",Exercise::MULTIPLE) + elsif standard_answer.count == 1 && ques_type == Exercise::MULTIPLE + @exercise_question.update_attribute("question_type",Exercise::SINGLE) + end + end + elsif ques_type == Exercise::JUDGMENT #这个为判断题 + choices_array = params[:question_choices] #判断的选项,对/错等等 + choices_count= choices_array.count + (1..choices_count).each do |c| + choice = choices_array[c-1] #每一个选项的内容 + choice_option = { + :choice_position => c, + :choice_text => choice.strip + } + question_choices = @exercise_question.exercise_bank_choices.create(choice_option) + question_choices.save + end + standard_answer = params[:standard_answers] #对应选项的id + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :exercise_bank_choice_id => standard_answer.first.to_i + } + question_standard_answer = ExerciseBankStandardAnswer.new(standard_option) + question_standard_answer.save + elsif ques_type == Exercise::COMPLETION #填空题,每空的参考答案有多个,那么以位置对应 + standard_answer = params[:standard_answers] + standard_answer.each do |a| + null_choice_id = a[:choice_id] + null_choice_text = a[:answer_text] + null_choice_text.each do |n| + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :exercise_bank_choice_id => null_choice_id, + :answer_text => n + } + question_standard_answer = ExerciseBankStandardAnswer.new(standard_option) + question_standard_answer.save + end + end + elsif ques_type == Exercise::SUBJECTIVE #简答题 + if params[:standard_answers].present? && params[:standard_answers].reject(&:blank?).count > 0 + standard_answer = params[:standard_answers] + standard_answer.each do |a| + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :answer_text => a, + } + question_standard_answer = ExerciseBankStandardAnswer.new(standard_option) + question_standard_answer.save + end + end + elsif ques_type == Exercise::PRACTICAL #实训题 + shixun = Shixun.find_by(id: params[:shixun_id]) + shixun_scores = params[:question_scores] #试卷有多个的分值有多个分数表,所以为分数的数组 + shixun_name = params[:shixun_name] || shixun.name + question_score = 0 + shixun.challenges.try(:each_with_index) do |challenge,index| + shixun_option = { + :challenge_id => challenge.id, + :shixun_id => shixun.id, + :exercise_bank_question_id => @exercise_question.id, + :position => (index + 1), + :question_score => shixun_scores[index].present? ? shixun_scores[index].to_f.round(1) : 5 + } + ex_shixun_challenge = ExerciseBankShixunChallenge.create(shixun_option) + question_score += ex_shixun_challenge.question_score # 问题的分数,为各个关卡分数的总和 + end + @exercise_question.update_attributes(:question_score => question_score, :shixun_name=> shixun_name) + end + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception("试卷问题创建失败!") + raise ActiveRecord::Rollback + end + end + end + + def update + ActiveRecord::Base.transaction do + begin + # 更新试卷题目的内容 + question_options = { + :question_title => params[:question_title], + :is_ordered => params[:is_ordered], # 填空题的答案是否为一一对应关系,默认为true即为一一对应 + :question_score => params[:question_score].present? ? params[:question_score].to_f.round(1) : 5.0 #不可修改分数 + } + choices_array = params[:question_choices] + stan_answer_params = params[:standard_answers] + standard_answer = stan_answer_params.present? ? stan_answer_params.uniq.reject(&:blank?) : [] + @exercise_question.update_attributes(question_options) + #当选项存在时,可修改选项内容,但是不能更改选项的位置(即不能增删选项) + if choices_array.present? + ex_choices = @exercise_question.exercise_bank_choices + ex_choice_count = ex_choices.count + choice_array_count = choices_array.count + ex_choice_count_array = (1..ex_choice_count).to_a + choice_array_count_array = (1..choice_array_count).to_a + if ex_choice_count > choice_array_count #如果选项有减少的,那么只更新传入的,删除以前的 + choice_array_count_array.each do |c| + choice = choices_array[c-1] #每一个选项的内容 + exercise_choice = @exercise_question.exercise_bank_choices.find_choice_custom("choice_position",(c)) + exercise_choice.update(choice_text:choice) + end + drop_ex_choice = @exercise_question.exercise_bank_choices.left_choice_choose("choice_position",(choice_array_count)) + drop_ex_choice.destroy_all + else + ex_choice_count_array.each do |c| + choice = choices_array[c-1] #每一个选项的内容 + exercise_choice = @exercise_question.exercise_bank_choices.find_choice_custom("choice_position",(c)) + exercise_choice.update(choice_text:choice) + end + new_add_choice = choice_array_count_array - ex_choice_count_array #新传入的需新增 + if new_add_choice.count > 0 + new_add_choice.each do |i| + choice_option = { + :choice_position => i, + :choice_text => choices_array[i-1].strip + } + question_choices = @exercise_question.exercise_bank_choices.new(choice_option) + question_choices.save + end + end + end + end + #试卷未发布时,当标准答案存在时,可修改标准答案内容,可增删标准答案,否则只能修改标准答案,不能增删标准答案 + @exercise_answers_array = @exercise_question.exercise_bank_standard_answers #问卷的全部标准答案 + if standard_answer.present? + if @exercise_question.question_type <= Exercise::JUDGMENT #选择题/判断题,标准答案为一个或多个 + exercise_standard_choices = @exercise_answers_array.pluck(:exercise_bank_choice_id) #问题以前的全部标准答案选项位置 + if exercise_standard_choices.sort != standard_answer.sort #表示答案有更改的 + standard_answer_change = true + common_standard_choices = standard_answer & exercise_standard_choices # 传入的标准答案的选项位置和以前的并集,即表示不用做更改的 + old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉 + new_left_standard_choices = standard_answer - common_standard_choices # 传入的标准答案差集共同的,剩余的表示需要新建 + if old_left_standard_choices.count > 0 + @exercise_answers_array.standard_by_ids(old_left_standard_choices).destroy_all + end + if new_left_standard_choices.count > 0 #新建标准答案 + new_left_standard_choices.each do |s| + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :exercise_bank_choice_id => s.to_i #即为选择的位置参数 + } + question_standard_answer = ExerciseBankStandardAnswer.new(standard_option) + question_standard_answer.save + end + + end + if standard_answer.count > 1 && @exercise_question.question_type == Exercise::SINGLE #当标准答案数大于1,且不为多选时,修改为多选 + @exercise_question.update_attribute("question_type",Exercise::MULTIPLE) + elsif standard_answer.count == 1 && @exercise_question.question_type == Exercise::MULTIPLE + @exercise_question.update_attribute("question_type",Exercise::SINGLE) + end + end + elsif @exercise_question.question_type == Exercise::COMPLETION #填空题 + old_ex_answer = @exercise_question.exercise_bank_standard_answers #当前问题的全部标准答案 + old_ex_answer_choice_texts = old_ex_answer.pluck(:answer_text).uniq.sort + new_ex_answer_choice_texts = standard_answer.pluck(:answer_text).sum.uniq.sort + if old_ex_answer_choice_texts != new_ex_answer_choice_texts #填空题标准答案有更改时,才会更新标准答案 + new_ex_answer_choice_ids = standard_answer.map {|a| a[:choice_id]}.uniq #新传入的答案数组序号 + old_ex_answer_choice_ids = old_ex_answer.pluck(:exercise_bank_choice_id).uniq #全部的答案数组序号 + standard_answer_change = true + #删除多余的选项 + if old_ex_answer_choice_ids.count > new_ex_answer_choice_ids.count #有减少的填空 + delete_ex_answer_choice_ids = old_ex_answer_choice_ids - new_ex_answer_choice_ids + old_ex_answer.standard_by_ids(delete_ex_answer_choice_ids).destroy_all + end + standard_answer.each do |aa| + null_choice_id = aa[:choice_id] + null_choice_text = aa[:answer_text] + null_choice_text_count = null_choice_text.count #当前传入的答案数量 + null_choice_text_count_array = (1..null_choice_text_count).to_a + + ex_answer_pre = old_ex_answer.standard_by_ids(null_choice_id) #当前问题的全部答案 + ex_answer_pre_count = ex_answer_pre.count + ex_answer_pre_count_array = (1..ex_answer_pre_count).to_a + + if old_ex_answer_choice_ids.include?(null_choice_id) #以前的填空题答案包含有现在的填空序号 + if null_choice_text_count >= ex_answer_pre_count + new_add_choice = null_choice_text_count_array - ex_answer_pre_count_array + ex_answer_pre_count_array.each do |n| + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :exercise_bank_choice_id => null_choice_id, + :answer_text => null_choice_text[n-1] + } + ex_answer_pre[n-1].update(standard_option) + end + if new_add_choice.count > 0 #表示有新增的 + new_add_choice.each do |i| + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :exercise_bank_choice_id => null_choice_id, + :answer_text => null_choice_text[i-1] + } + question_standard_answer = ExerciseBankStandardAnswer.new(standard_option) + question_standard_answer.save + end + end + else + new_delete_choice = ex_answer_pre_count_array - null_choice_text_count_array + null_choice_text.each_with_index do |n,index| + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :exercise_bank_choice_id => null_choice_id, + :answer_text => n + } + ex_answer_pre[index].update(standard_option) + end + if new_delete_choice.count > 0 #表示填空题的答案有删减的 + new_delete_choice.each do |d| + ex_answer_pre[d-1].destroy + end + end + end + else + null_choice_text.each do |n| + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :exercise_bank_choice_id => null_choice_id, + :answer_text => n + } + question_standard_answer = ExerciseBankStandardAnswer.new(standard_option) + question_standard_answer.save + end + end + end + end + end + end + if @exercise_question.question_type == Exercise::SUBJECTIVE #主观题 + main_standard_answer = standard_answer.present? ? standard_answer.first : nil + if @exercise_answers_array.present? + @exercise_answers_array.first.update_attribute("answer_text",main_standard_answer) + else + standard_option = { + :exercise_bank_question_id => @exercise_question.id, + :answer_text => main_standard_answer, + } + question_standard_answer = ExerciseBankStandardAnswer.new(standard_option) + question_standard_answer.save + end + elsif @exercise_question.question_type == Exercise::PRACTICAL + question_score = 0 + shixun_name = params[:shixun_name] || @exercise_question.shixun_name + @exercise_question.exercise_shixun_challenges.each_with_index do |challenge, index| + challenge.question_score = params[:question_scores][index].to_f.round(1) + challenge.save + question_score += params[:question_scores][index].to_f.round(1) + end + @exercise_question.question_score = question_score + @exercise_question.shixun_name = shixun_name + @exercise_question.save + end + + #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. + + if standard_answer_change && @exercise.exercise_status >= Exercise::PUBLISHED + # ex_users_committed = @exercise.exercise_users.exercise_user_committed + # if ex_users_committed.size > 0 + # ex_users_committed.each do |ex_user| + # update_objective_score = update_single_score(@exercise_question,ex_user.user_id,standard_answer) + # if update_objective_score != 0 + # objective_score = ex_user.objective_score + # new_objective_score = objective_score + update_objective_score + # total_score = ex_user.score + update_objective_score + # total_score = total_score < 0.0 ? 0.0 : total_score + # ex_user.update_attributes(objective_score:new_objective_score,score:total_score) + # end + # end + # end + normal_status(3,"修改了标准答案\n是否重新计算学生答题的成绩?") + else + normal_status(0,"试卷更新成功!") + end + + rescue Exception => e + uid_logger_error(e.message) + tip_exception("页面调用失败!") + raise ActiveRecord::Rollback + end + end + end + + private + + def bank_admin + tip_exception(403, "无权限") unless (current_user.certification_teacher? && @bank.user_id == current_user.id) || current_user.admin? + end + + def get_exercise + @exercise = ExerciseBank.find_by!(id:params[:exercise_bank_id]) + end + + def get_exercise_question + @exercise_question = ExerciseBankQuestion.find_by!(id: params[:id]) + @exercise = @exercise_question.exercise_bank + end + + def validate_params + normal_status(-1,"题目不允许为空!") if (params[:question_title].blank? && params[:question_type].to_i != Exercise::PRACTICAL ) #除了实训题,其余题目必需有题干 + normal_status(-1,"问题类型不允许为空!" ) if params[:question_type].blank? + normal_status(-1,"分值不允许为空!" ) if params[:question_score].blank? && params[:question_scores].blank? #分值的数组或参数必需存在一个 + if params[:question_score].present? && params[:question_score].to_f <= 0.0 #问题类型存在,则分值不能为空,且必需大于0 + normal_status(-1,"分值必需大于0!") + elsif (params[:question_score].present? && params[:question_score].to_f.round(1) > 100.0) || (params[:question_scores].present? && (params[:question_scores].map{|a| a.to_f.round(1)}.max > 100.0)) + normal_status(-1,"分值不能超过100分!") + elsif params[:question_scores].present? && params[:question_scores].include?(0.0) #如果有负数,则自动取绝对值,#多个分数值,针对实训题的 + normal_status(-1,"分值必需大于0!") + elsif params[:standard_answers].present? && params[:question_choices].present? && (params[:standard_answers].count > params[:question_choices].count) + normal_status(-1,"标准答案数不能大于选项数!") + elsif [0,1,2,3].include?(params[:question_type].to_i) && (params[:standard_answers].blank? || params[:standard_answers].include?("")) #选择题/判断题/填空题 问题选项/标准答案不能为空,也不能包含空的内容 + normal_status(-1,"标准答案不能为空!") + elsif params[:question_type].to_i == 2 && (params[:standard_answers].count > 1 || params[:question_choices].blank? || params[:question_choices].include?("")) #判断题的标准答案不能大于1个,选项不能为空 + normal_status(-1,"判断题选项不能为空/标准答案不能大于1个!") + elsif params[:question_type].to_i <= 1 && (params[:question_choices].blank? || params[:question_choices].include?("") || params[:question_choices].count < 2) #选择题选项不能为空,且不能小于2 + normal_status(-1,"选择题选项内容不能为空,且不能少于2个!") + elsif params[:question_type].to_i == 3 && (params[:standard_answers].blank? || params[:standard_answers].count > 5 ) #填空题选项最多为5个,且如果为1个的话,不允许修改is_ordered + normal_status(-1,"填空题标准答案不能为空/不能超过5个!") + elsif params[:question_type].to_i == 4 && params[:standard_answers].count > 2 #简单题参考答案最多为1个 + normal_status(-1,"简答题的参考答案不能大于2个!") + elsif params[:question_type].to_i == 5 + if params[:shixun_id].blank? #实训题的id不能为空 + normal_status(-1,"实训题id不能为空!") + elsif params[:shixun_name].blank? + normal_status(-1,"实训题名称不能为空!") + end + end + end + end diff --git a/app/controllers/exercise_banks_controller.rb b/app/controllers/exercise_banks_controller.rb index e3d9718b3..29af3c42b 100644 --- a/app/controllers/exercise_banks_controller.rb +++ b/app/controllers/exercise_banks_controller.rb @@ -42,7 +42,9 @@ class ExerciseBanksController < ApplicationController end def update - + tip_exception("试卷标题不能为空!") if params[:exercise_name].blank? + @bank.update_attributes!(name: params[:exercise_name], description: params[:exercise_description]) + normal_status(0,"试卷更新成功!") end private @@ -55,18 +57,4 @@ class ExerciseBanksController < ApplicationController def bank_admin tip_exception(403, "无权限") unless (current_user.certification_teacher? && @bank.user_id == current_user.id) || current_user.admin? end - - def gtask_bank_params - tip_exception("name参数不能为空") if params[:gtask_bank][:name].blank? - tip_exception("description参数不能为空") if params[:gtask_bank][:description].blank? - if @bank.homework_type == 3 - tip_exception("base_on_project参数不能为空") if params[:gtask_bank][:base_on_project].nil? - tip_exception("min_num参数不能为空") if params[:gtask_bank][:min_num].blank? - tip_exception("max_num参数不能为空") if params[:gtask_bank][:max_num].blank? - tip_exception("最小人数不能小于1") if params[:gtask_bank][:min_num].to_i < 1 - tip_exception("最大人数不能小于最小人数") if params[:gtask_bank][:max_num].to_i < params[:gtask_bank][:min_num].to_i - end - params.require(:gtask_bank).permit(:name, :description) if @bank.task_type == 1 - params.require(:gtask_bank).permit(:name, :description, :min_num, :max_num, :base_on_project) if @bank.task_type == 2 - end end diff --git a/app/controllers/gtopic_banks_controller.rb b/app/controllers/gtopic_banks_controller.rb index da56c7acf..6269173ec 100644 --- a/app/controllers/gtopic_banks_controller.rb +++ b/app/controllers/gtopic_banks_controller.rb @@ -1,12 +1,16 @@ class GtopicBanksController < ApplicationController before_action :require_login before_action :find_bank - before_action :bank_admin, only: [:update] + before_action :bank_admin, only: [:edit, :update] def show @bank_attachments = @bank.attachments end + def edit + @attachments = @bank.attachments + end + def update ActiveRecord::Base.transaction do @bank.update_attributes(gtopic_bank_params) diff --git a/app/models/exercise_bank.rb b/app/models/exercise_bank.rb index 22c2a5041..067d080b5 100644 --- a/app/models/exercise_bank.rb +++ b/app/models/exercise_bank.rb @@ -18,4 +18,7 @@ class ExerciseBank < ApplicationRecord scope :exercise_bank_search, lambda { |keywords| where("name LIKE ?", "%#{keywords}%") unless keywords.blank?} + validates :name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } + validates :description, length: { maximum: 100, too_long: "100 characters is the maximum allowed" } + end \ No newline at end of file diff --git a/app/models/exercise_bank_choice.rb b/app/models/exercise_bank_choice.rb index d3a91bb02..be29ca786 100644 --- a/app/models/exercise_bank_choice.rb +++ b/app/models/exercise_bank_choice.rb @@ -1,4 +1,7 @@ class ExerciseBankChoice < ApplicationRecord belongs_to :exercise_bank_question has_many :exercise_bank_standard_answers + + scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 + scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 end \ No newline at end of file diff --git a/app/models/exercise_bank_question.rb b/app/models/exercise_bank_question.rb index af533836b..14b166333 100644 --- a/app/models/exercise_bank_question.rb +++ b/app/models/exercise_bank_question.rb @@ -5,7 +5,11 @@ class ExerciseBankQuestion < ApplicationRecord has_many :exercise_bank_choices, :dependent => :destroy has_many :exercise_bank_standard_answers, :dependent => :destroy #attr_accessible :question_number, :question_score, :question_title, :question_type + + scope :insert_question_ex, lambda {|k| where("question_number > ?",k)} scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 + scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 + scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 def question_type_name case self.question_type diff --git a/app/views/exercise_bank_questions/_exercise_bank_questions.json.jbuilder b/app/views/exercise_bank_questions/_exercise_bank_questions.json.jbuilder index a77b8a975..5cc439706 100644 --- a/app/views/exercise_bank_questions/_exercise_bank_questions.json.jbuilder +++ b/app/views/exercise_bank_questions/_exercise_bank_questions.json.jbuilder @@ -34,8 +34,11 @@ if question.question_type <= 2 #当为选择题或判断题时,只显示选 if question.question_type == 2 #返回答案的文字 standard_text = standard_answers_array.first.to_i == 1 ? "正确" : "错误" else + if question.question_type == 1 && standard_answers_array.size == 1 + standard_answers_array = standard_answers_array.first.to_s.split("") + end array_text_answer = [] - standard_answers_array.each{|a| array_text_answer.push((a+64).chr)} + standard_answers_array.each{|a| array_text_answer.push((a.to_i+64).chr)} standard_text = array_text_answer.join("") end json.standard_answer_show standard_text diff --git a/app/views/gtopic_banks/edit.json.jbuilder b/app/views/gtopic_banks/edit.json.jbuilder new file mode 100644 index 000000000..1abc812ac --- /dev/null +++ b/app/views/gtopic_banks/edit.json.jbuilder @@ -0,0 +1,15 @@ +json.topic_type topic_type +json.topic_source topic_source +json.topic_property_first topic_property_first +json.topic_property_second topic_property_second +json.topic_repeat topic_repeat + +json.selected_data do + json.(@bank, :name, :topic_type, :topic_source, :topic_property_first, + :description, :topic_property_second, :source_unit, :topic_repeat, + :province, :city, :is_public) +end + +json.attachments @attachments do |attachment| + json.partial! "attachments/attachment_simple", locals: {attachment: attachment} +end \ No newline at end of file