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)}> +
{item.name} - this.Deselectlittle(item.mirror_repository_id)}> + {/*this.Deselectlittle(item.mirror_repository_id)}>*/}