From 9e916485de54c922998a5be55710ce237b98b4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Wed, 16 Oct 2019 16:00:15 +0800 Subject: [PATCH 01/12] =?UTF-8?q?24865=20=E9=A2=98=E5=BA=93=E9=80=89?= =?UTF-8?q?=E7=94=A8=E5=BC=B9=E6=A1=86=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/courses/busyWork/UseBank.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/react/src/modules/courses/busyWork/UseBank.js b/public/react/src/modules/courses/busyWork/UseBank.js index ed47eb2d0..01f35dace 100644 --- a/public/react/src/modules/courses/busyWork/UseBank.js +++ b/public/react/src/modules/courses/busyWork/UseBank.js @@ -202,7 +202,7 @@ class UseBank extends Component{ width: 170px !important; } .bankwidth{ - width:27% !important; + width:32% !important; overflow:hidden; text-overflow:ellipsis; white-space:nowrap @@ -213,6 +213,10 @@ class UseBank extends Component{ text-overflow:ellipsis; white-space:nowrap } + .with58{ + width:58% !important; + Margin-left:15px + } `} @@ -290,7 +294,7 @@ class UseBank extends Component{ return (

- + 10 && item.course_list_name} From 7bb93aa3d5200203cd43758b864aa278a2e35a60 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 16 Oct 2019 16:11:12 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=A1=AB=E7=A9=BA?= =?UTF-8?q?=E9=A2=98=E7=BB=9F=E8=AE=A1=E9=94=99=E8=AF=AF=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 43 ++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index e13f754be..0bff75ee4 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -112,9 +112,24 @@ module ExercisesHelper effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 # - if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, + # if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, + # ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 + # percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 + # + # end + + if ex.question_type != Exercise::MULTIPLE ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 + else + multiple_score = 0 + user_ids.each do |user_id| + ex_answer_score = ex_answers.select{|answer| answer.user_id == user_id}&.first&.score.to_f + multiple_score += ex_answer_score + end + + percent = (ex_total_score == 0.0 ? 0.0 : (multiple_score / ex_total_score.to_f).round(3) * 100) #正确率 + end question_answer_infos = [] @@ -123,19 +138,19 @@ module ExercisesHelper standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 # right_users_count = 0 # 该问题的正确率 - if ex.question_type == Exercise::MULTIPLE #多选题 - right_user_ids = user_ids - standard_answer.each do |choice_position| - standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first&.id - right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id) - end - right_users_count = right_user_ids.size - else #单选题和判断题 - standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first&.id - right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size - end + # if ex.question_type == Exercise::MULTIPLE #多选题 + # right_user_ids = user_ids + # standard_answer.each do |choice_position| + # standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first&.id + # right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id) + # end + # # right_users_count = right_user_ids.size + # else #单选题和判断题 + # standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first&.id + # # right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size + # end - percent = commit_user_ids > 0 ? (right_users_count / commit_user_ids.to_f).round(3)*100 : 0.0 + # percent = commit_user_ids > 0 ? (right_users_count / commit_user_ids.to_f).round(3)*100 : 0.0 #每个选项的正确率 ex_choices.each do |c| @@ -181,7 +196,7 @@ module ExercisesHelper all_user_count += user_count standard_answer_count += 1 end - percent = commit_user_ids > 0 ? (all_user_count / commit_user_ids.to_f).round(3)*100 : 0.0 + # percent = commit_user_ids > 0 ? (all_user_count / commit_user_ids.to_f).round(3)*100 : 0.0 user_wrong_count = (effictive_users_count - all_user_count ) From a571ae0c35f428cf96de1ce73ca9a469305da60a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 16 Oct 2019 16:12:00 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E7=AB=9E=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../competitions/competitions_controller.rb | 16 ++++++++++++---- .../competitions/index.json.jbuilder | 2 +- config/initializers/wechat_init.rb | 1 + config/routes.rb | 4 ++++ ...1016070842_add_description_to_competitions.rb | 6 ++++++ 5 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20191016070842_add_description_to_competitions.rb diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb index 34dac7350..77159fdaf 100644 --- a/app/controllers/competitions/competitions_controller.rb +++ b/app/controllers/competitions/competitions_controller.rb @@ -1,5 +1,6 @@ class Competitions::CompetitionsController < Competitions::BaseController skip_before_action :require_login + before_action :allow_visit, except: [:index] def index # 已上架 或者 即将上架 @@ -24,10 +25,10 @@ class Competitions::CompetitionsController < Competitions::BaseController end def show - unless current_competition.published? || admin_or_business? - render_forbidden - return - end + end + + def common_header + end private @@ -35,4 +36,11 @@ class Competitions::CompetitionsController < Competitions::BaseController def current_competition @_current_competition ||= Competition.find_by!(identifier: params[:id]) end + + def allow_visit + unless current_competition.published? || admin_or_business? + render_forbidden + return + end + end end \ No newline at end of file diff --git a/app/views/competitions/competitions/index.json.jbuilder b/app/views/competitions/competitions/index.json.jbuilder index 400f17379..4b8390a7d 100644 --- a/app/views/competitions/competitions/index.json.jbuilder +++ b/app/views/competitions/competitions/index.json.jbuilder @@ -1,7 +1,7 @@ json.count @count json.competitions do json.array! @competitions.each do |competition| - json.extract! competition, :id, :identifier, :name, :sub_title + json.extract! competition, :id, :identifier, :name, :sub_title, :bonus, :description json.visits_count competition.visits member_count = @member_count_map&.fetch(competition.id, 0) || competition.team_members.count diff --git a/config/initializers/wechat_init.rb b/config/initializers/wechat_init.rb index 3fd8f9485..3f91d1665 100644 --- a/config/initializers/wechat_init.rb +++ b/config/initializers/wechat_init.rb @@ -13,6 +13,7 @@ rescue => ex puts %Q{\033[33m [warning] wechat config or configuration.yml missing, please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m} wechat_config = {} + weapp_config = {} end # 网站应用 diff --git a/config/routes.rb b/config/routes.rb index 4445278de..e8562b044 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -790,6 +790,10 @@ Rails.application.routes.draw do end resources :teachers, only: [:index] resources :students, only: [:index] + + member do + get :common_header + end end end diff --git a/db/migrate/20191016070842_add_description_to_competitions.rb b/db/migrate/20191016070842_add_description_to_competitions.rb new file mode 100644 index 000000000..268d7b8fc --- /dev/null +++ b/db/migrate/20191016070842_add_description_to_competitions.rb @@ -0,0 +1,6 @@ +class AddDescriptionToCompetitions < ActiveRecord::Migration[5.2] + def change + add_column :competitions, :description, :text + add_column :competitions, :introduction, :text + end +end From 90ef0334ccff69a6ae6f0c3a866d97aa62f8be9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Wed, 16 Oct 2019 16:12:37 +0800 Subject: [PATCH 04/12] =?UTF-8?q?24865=20=E9=A2=98=E5=BA=93=E9=80=89?= =?UTF-8?q?=E7=94=A8=E5=BC=B9=E6=A1=86=E6=A0=B7=E5=BC=8F=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/AppConfig.js | 20 +++++++-------- .../src/modules/courses/busyWork/UseBank.js | 25 +++++++++++++------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index 3c150c90c..9cf68503d 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -21,16 +21,16 @@ let hashTimeout // TODO 开发期多个身份切换 let debugType ="" -// if (isDev) { -// const _search = window.location.search; -// let parsed = {}; -// if (_search) { -// parsed = queryString.parse(_search); -// } -// debugType = window.location.search.indexOf('debug=t') != -1 ? 'teacher' : -// window.location.search.indexOf('debug=s') != -1 ? 'student' : -// window.location.search.indexOf('debug=a') != -1 ? 'admin' : parsed.debug || 'admin' -// } +if (isDev) { + const _search = window.location.search; + let parsed = {}; + if (_search) { + parsed = queryString.parse(_search); + } + debugType = window.location.search.indexOf('debug=t') != -1 ? 'teacher' : + window.location.search.indexOf('debug=s') != -1 ? 'student' : + window.location.search.indexOf('debug=a') != -1 ? 'admin' : parsed.debug || 'admin' +} window._debugType = debugType; export function initAxiosInterceptors(props) { initOnlineOfflineListener() diff --git a/public/react/src/modules/courses/busyWork/UseBank.js b/public/react/src/modules/courses/busyWork/UseBank.js index 01f35dace..de9193fd9 100644 --- a/public/react/src/modules/courses/busyWork/UseBank.js +++ b/public/react/src/modules/courses/busyWork/UseBank.js @@ -178,7 +178,13 @@ class UseBank extends Component{ }) }); - } + }; + + getotiku = (url) => { + window.open(url, '_blank'); + } + + render(){ let { flag, nav_my, loading, hasMore, object_list, search, checkBoxValues,isChecked,page,is_teacher }=this.state @@ -217,6 +223,11 @@ class UseBank extends Component{ width:58% !important; Margin-left:15px } + .with63{ + width: 63% !important; + box-sizing: border-box; + margin-left: 15px; + } `} @@ -294,7 +305,7 @@ class UseBank extends Component{ return (

- + 10 && item.course_list_name} @@ -308,25 +319,23 @@ class UseBank extends Component{ {nav_my === "myself" ? (this.props.object_type && this.props.object_type === "normal" ? this.getotiku(`/banks/normal/${item.id}/edit/personal?tab=0`)} >编辑 : this.props.object_type && this.props.object_type === "group" ? this.getotiku(`/banks/group/${item.id}/edit/publicly?tab=0`)} >编辑 : this.props.object_type && this.props.object_type === "exercise" ? this.getotiku(`/banks/exercise/${item.id}/edit/personal`)} >编辑 : this.props.object_type && this.props.object_type === "poll" ? this.getotiku(`/banks/poll/${item.id}/edit/personal`)} >编辑 : "") : "" } - -

) })} From 40d08fb8e6fe4aac8a92169b3c44c09ece3115e4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 16 Oct 2019 16:22:42 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0b3e35519..a1bd16e94 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -583,6 +583,8 @@ class CoursesController < ApplicationController # 学生身份的处理 student_member = course_members.where(role: %i[STUDENT]).take + + # 不存在则创建学生身份 if params[:roles].include?("STUDENT") && student_member.blank? correspond_teacher_exist = CourseMember.exists?(user_id: params[:user_id], is_active: 1, course_id: @course.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]) new_student = CourseMember.new(user_id: params[:user_id], course_id: @course.id, role: 4) @@ -597,6 +599,9 @@ class CoursesController < ApplicationController student_member.destroy! CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [params[:user_id]]) # CourseDeleteStudentNotifyJob.perform_later(@course.id, [params[:user_id]], current_user.id) + elsif params[:roles].include?("STUDENT") && student_member.present? && !params[:roles].include?("PROFESSOR") && !params[:roles].include?("ASSISTANT_PROFESSOR") + # 学生身份存在且学生没有教师身份时更新is_active + student_member.update_attributes!(is_active: 1) end normal_status(0, "修改成功") From 3815715347cb9fb70a65f020bad350f6e6b4a178 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 16 Oct 2019 16:23:22 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=A1=AB=E7=A9=BA?= =?UTF-8?q?=E9=A2=98=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 61 ++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 0bff75ee4..59a2d3d25 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -112,43 +112,44 @@ module ExercisesHelper effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 # - # if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, - # ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 - # percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 - # - # end - - if ex.question_type != Exercise::MULTIPLE + if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 - else - multiple_score = 0 - user_ids.each do |user_id| - ex_answer_score = ex_answers.select{|answer| answer.user_id == user_id}&.first&.score.to_f - multiple_score += ex_answer_score - end - - percent = (ex_total_score == 0.0 ? 0.0 : (multiple_score / ex_total_score.to_f).round(3) * 100) #正确率 end + # if ex.question_type != Exercise::MULTIPLE + # ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 + # percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 + # else + # multiple_score = 0 + # user_ids.each do |user_id| + # ex_answer_score = ex_answers.select{|answer| answer.user_id == user_id}&.first&.score.to_f + # multiple_score += ex_answer_score + # end + # percent = (ex_total_score == 0.0 ? 0.0 : (multiple_score / ex_total_score.to_f).round(3) * 100) #正确率 + # end + question_answer_infos = [] if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 ex_choices = ex.exercise_choices standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 - # right_users_count = 0 - # 该问题的正确率 - # if ex.question_type == Exercise::MULTIPLE #多选题 - # right_user_ids = user_ids - # standard_answer.each do |choice_position| - # standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first&.id - # right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id) - # end - # # right_users_count = right_user_ids.size - # else #单选题和判断题 - # standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first&.id - # # right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size - # end + right_users_count = 0 + #该问题的正确率 + if ex.question_type == Exercise::MULTIPLE #多选题 + right_user_ids = user_ids + standard_answer.each do |choice_position| + standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first&.id + right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id) + end + right_users_count = right_user_ids.size + right_users_scores = right_users_count * ex&.question_score.to_f + else #单选题和判断题 + standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first&.id + right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size + right_users_scores = right_users_count * ex&.question_score.to_f + end + percent = (ex_total_score == 0.0 ? 0.0 : (right_users_scores / ex_total_score.to_f).round(3) * 100) #正确率 # percent = commit_user_ids > 0 ? (right_users_count / commit_user_ids.to_f).round(3)*100 : 0.0 @@ -174,6 +175,7 @@ module ExercisesHelper null_stand_choice = null_standard_answer.pluck(:exercise_choice_id) #一个exercise_choice_id可能对应多个answer_text null_stand_text = null_standard_answer.pluck(:answer_text) standard_answer_count = 0 + each_null_score = null_stand_choice.size > 0 ? (ex&.question_score.to_f / null_stand_choice.size).round(3) : 0.0 all_user_count = 0 null_stand_choice.each_with_index do |s,index| user_count = 0 @@ -196,6 +198,9 @@ module ExercisesHelper all_user_count += user_count standard_answer_count += 1 end + answer_user_score = all_user_count * each_null_score + percent = (ex_total_score == 0.0 ? 0.0 : (answer_user_score / ex_total_score.to_f).round(3) * 100) #正确率 + # percent = commit_user_ids > 0 ? (all_user_count / commit_user_ids.to_f).round(3)*100 : 0.0 user_wrong_count = (effictive_users_count - all_user_count ) From b3f3b03c461aaf291c5098179b71f876c032e3ce Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 16 Oct 2019 16:24:34 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BB=93=E6=9E=9C=EF=BC=8C=E5=A1=AB=E7=A9=BA=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E6=AD=A3=E7=A1=AE=E7=8E=87=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 59a2d3d25..9a62e6b1d 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -143,15 +143,15 @@ module ExercisesHelper right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id) end right_users_count = right_user_ids.size - right_users_scores = right_users_count * ex&.question_score.to_f + # right_users_scores = right_users_count * ex&.question_score.to_f else #单选题和判断题 standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first&.id right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size - right_users_scores = right_users_count * ex&.question_score.to_f + # right_users_scores = right_users_count * ex&.question_score.to_f end - percent = (ex_total_score == 0.0 ? 0.0 : (right_users_scores / ex_total_score.to_f).round(3) * 100) #正确率 + # percent = (ex_total_score == 0.0 ? 0.0 : (right_users_scores / ex_total_score.to_f).round(3) * 100) #正确率 - # percent = commit_user_ids > 0 ? (right_users_count / commit_user_ids.to_f).round(3)*100 : 0.0 + percent = commit_user_ids > 0 ? (right_users_count / commit_user_ids.to_f).round(3)*100 : 0.0 #每个选项的正确率 ex_choices.each do |c| @@ -175,7 +175,7 @@ module ExercisesHelper null_stand_choice = null_standard_answer.pluck(:exercise_choice_id) #一个exercise_choice_id可能对应多个answer_text null_stand_text = null_standard_answer.pluck(:answer_text) standard_answer_count = 0 - each_null_score = null_stand_choice.size > 0 ? (ex&.question_score.to_f / null_stand_choice.size).round(3) : 0.0 + each_null_score = null_stand_choice.size > 0 ? (ex&.question_score.to_f / null_stand_choice.uniq.size).round(3) : 0.0 all_user_count = 0 null_stand_choice.each_with_index do |s,index| user_count = 0 From 24404ce12f2b4cd044e08ee3874eaa69bc1a7de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Wed, 16 Oct 2019 16:25:35 +0800 Subject: [PATCH 08/12] =?UTF-8?q?24867=20=E6=8F=8F=E8=BF=B0=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E9=BB=98=E8=AE=A4=E6=8F=90=E7=A4=BA=E8=AF=AD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/courses/shixunHomework/Homeworddescription.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/public/react/src/modules/courses/shixunHomework/Homeworddescription.js b/public/react/src/modules/courses/shixunHomework/Homeworddescription.js index df1f33ba8..d7fc20693 100644 --- a/public/react/src/modules/courses/shixunHomework/Homeworddescription.js +++ b/public/react/src/modules/courses/shixunHomework/Homeworddescription.js @@ -65,6 +65,8 @@ class Homeworddescription extends Component { } //获取输入框 settextarea=(e)=>{ + console.log("settextarea"); + console.log(e); this.setState({ description:e }) @@ -89,8 +91,10 @@ class Homeworddescription extends Component { {/**/} - +
From 68649751d3edf8f98f82bd54ea5ae4b3b9ade7ee Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 16 Oct 2019 16:37:31 +0800 Subject: [PATCH 09/12] main_controller --- app/controllers/main_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 0e2628c3e..869ba27f6 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,5 +1,5 @@ class MainController < ApplicationController def index - render file: 'public/react/build/index.html', :layout => false + render file: 'public/react/build/index', formats: [:html] end end \ No newline at end of file From b704f4b2de060a18022ed7c7675620a32e47277e Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 16 Oct 2019 16:44:22 +0800 Subject: [PATCH 10/12] admins: custom carousel --- .../javascripts/admins/carousels/index.js | 8 ++++--- app/assets/stylesheets/admins/common.scss | 8 ++++++- .../admins/carousels_controller.rb | 24 ++++++++++++------- app/controllers/concerns/laboratory_helper.rb | 1 + app/controllers/home_controller.rb | 4 ++-- app/libs/hot_search_keyword.rb | 1 + app/models/laboratory.rb | 2 ++ app/models/portal_image.rb | 4 ++++ .../admins/drag_portal_image_service.rb | 8 +++---- app/views/admins/carousels/index.html.erb | 7 +++--- .../shared/_add_carousel_modal.html.erb | 2 +- .../shared/_laboratory_item.html.erb | 13 +++++++--- app/views/admins/shared/_sidebar.html.erb | 3 +-- config/admins/sidebar.yml | 3 ++- config/routes.rb | 7 +++--- ...5036_add_laboratory_id_to_portal_images.rb | 8 +++++++ 16 files changed, 71 insertions(+), 32 deletions(-) create mode 100644 db/migrate/20191016075036_add_laboratory_id_to_portal_images.rb diff --git a/app/assets/javascripts/admins/carousels/index.js b/app/assets/javascripts/admins/carousels/index.js index 0f279f17e..fe665a35f 100644 --- a/app/assets/javascripts/admins/carousels/index.js +++ b/app/assets/javascripts/admins/carousels/index.js @@ -1,5 +1,7 @@ $(document).on('turbolinks:load', function() { if ($('body.admins-carousels-index-page').length > 0) { + var laboratoryId = $('#carousels-container').data('laboratoryId'); + // ------------ 保存链接 ----------- $('.carousels-card').on('click', '.save-data-btn', function(){ var $link = $(this); @@ -13,7 +15,7 @@ $(document).on('turbolinks:load', function() { $link.attr('disabled', true); $.ajax({ - url: '/admins/carousels/' + id, + url: '/admins/laboratories/' + laboratoryId + '/carousels/' + id, method: 'PATCH', dataType: 'json', data: { link: link, name: name }, @@ -34,7 +36,7 @@ $(document).on('turbolinks:load', function() { $checkbox.attr('disabled', true); $.ajax({ - url: '/admins/carousels/' + id, + url: '/admins/laboratories/' + laboratoryId + '/carousels/' + id, method: 'PATCH', dataType: 'json', data: { status: checked }, @@ -60,7 +62,7 @@ $(document).on('turbolinks:load', function() { var insertId = $(sibling).data('id') || ''; $.ajax({ - url: '/admins/carousels/drag', + url: '/admins/laboratories/' + laboratoryId + '/carousels/drag', method: 'POST', dataType: 'json', data: { move_id: moveId, after_id: insertId }, diff --git a/app/assets/stylesheets/admins/common.scss b/app/assets/stylesheets/admins/common.scss index adad72997..aabe6085c 100644 --- a/app/assets/stylesheets/admins/common.scss +++ b/app/assets/stylesheets/admins/common.scss @@ -48,9 +48,15 @@ } .action-container { - .action { + & > .action { padding: 0 3px; } + + .more-action-dropdown { + .dropdown-item { + font-size: 14px; + } + } } /* 分页 */ diff --git a/app/controllers/admins/carousels_controller.rb b/app/controllers/admins/carousels_controller.rb index cd693d2fd..ad6af7649 100644 --- a/app/controllers/admins/carousels_controller.rb +++ b/app/controllers/admins/carousels_controller.rb @@ -1,15 +1,17 @@ class Admins::CarouselsController < Admins::BaseController before_action :convert_file!, only: [:create] + helper_method :current_laboratory + def index - @images = PortalImage.order(position: :asc) + @images = current_laboratory.portal_images.order(position: :asc) end def create - position = PortalImage.count + 1 + position = current_laboratory.portal_images.count + 1 ActiveRecord::Base.transaction do - image = PortalImage.create!(create_params.merge(position: position)) + image = current_laboratory.portal_images.create!(create_params.merge(position: position)) file_path = Util::FileManage.disk_filename('PortalImage', image.id) File.delete(file_path) if File.exist?(file_path) # 删除之前的文件 @@ -17,7 +19,7 @@ class Admins::CarouselsController < Admins::BaseController end flash[:success] = '保存成功' - redirect_to admins_carousels_path + redirect_to admins_laboratory_carousels_path(current_laboratory) end def update @@ -29,7 +31,7 @@ class Admins::CarouselsController < Admins::BaseController ActiveRecord::Base.transaction do current_image.destroy! # 前移 - PortalImage.where('position > ?', current_image.position) + current_laboratory.portal_images.where('position > ?', current_image.position) .update_all('position = position - 1') file_path = Util::FileManage.disk_filename('PortalImage', current_image.id) @@ -39,10 +41,10 @@ class Admins::CarouselsController < Admins::BaseController end def drag - move = PortalImage.find_by(id: params[:move_id]) - after = PortalImage.find_by(id: params[:after_id]) + move = current_laboratory.portal_images.find_by(id: params[:move_id]) + after = current_laboratory.portal_images.find_by(id: params[:after_id]) - Admins::DragPortalImageService.call(move, after) + Admins::DragPortalImageService.call(current_laboratory, move, after) render_ok rescue Admins::DragPortalImageService::Error => e render_error(e.message) @@ -50,8 +52,12 @@ class Admins::CarouselsController < Admins::BaseController private + def current_laboratory + @_current_laboratory ||= Laboratory.find(params[:laboratory_id]) + end + def current_image - @_current_image ||= PortalImage.find(params[:id]) + @_current_image ||= current_laboratory.portal_images.find(params[:id]) end def create_params diff --git a/app/controllers/concerns/laboratory_helper.rb b/app/controllers/concerns/laboratory_helper.rb index fbb18b36d..08a75fd79 100644 --- a/app/controllers/concerns/laboratory_helper.rb +++ b/app/controllers/concerns/laboratory_helper.rb @@ -2,6 +2,7 @@ module LaboratoryHelper extend ActiveSupport::Concern included do + helper_method :current_laboratory helper_method :default_setting end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 2ed82f1b5..72d6118bf 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -2,10 +2,10 @@ class HomeController < ApplicationController def index # banner图 - images = PortalImage.where(status: true).order("position asc") + images = current_laboratory.portal_images.only_online.order(position: :asc) @images_url = [] images.each do |image| - @images_url << {path: image.link, image_url: Util::FileManage.disk_file_url('PortalImage', image.id)} + @images_url << {path: image.link, image_url: Util::FileManage.source_disk_file_url(image)} end # 目录分级 diff --git a/app/libs/hot_search_keyword.rb b/app/libs/hot_search_keyword.rb index e222bf3a7..f026142cb 100644 --- a/app/libs/hot_search_keyword.rb +++ b/app/libs/hot_search_keyword.rb @@ -1,3 +1,4 @@ +# 基于Redis实现热门搜索关键字 class HotSearchKeyword class << self def add(keyword) diff --git a/app/models/laboratory.rb b/app/models/laboratory.rb index f319ace80..00f5adabf 100644 --- a/app/models/laboratory.rb +++ b/app/models/laboratory.rb @@ -6,6 +6,8 @@ class Laboratory < ApplicationRecord has_one :laboratory_setting, dependent: :destroy + has_many :portal_images, dependent: :destroy + validates :identifier, uniqueness: { case_sensitive: false }, allow_nil: true def site diff --git a/app/models/portal_image.rb b/app/models/portal_image.rb index a3fd71bb5..b07214c77 100644 --- a/app/models/portal_image.rb +++ b/app/models/portal_image.rb @@ -1,4 +1,8 @@ class PortalImage < ApplicationRecord + belongs_to :laboratory + + scope :only_online, -> { where(status: true) } + def online? status? end diff --git a/app/services/admins/drag_portal_image_service.rb b/app/services/admins/drag_portal_image_service.rb index 9f8adea38..5555c08b2 100644 --- a/app/services/admins/drag_portal_image_service.rb +++ b/app/services/admins/drag_portal_image_service.rb @@ -1,9 +1,10 @@ class Admins::DragPortalImageService < ApplicationService Error = Class.new(StandardError) - attr_reader :move, :after + attr_reader :laboratory, :move, :after - def initialize(move, after) + def initialize(laboratory, move, after) + @laboratory = laboratory @move = move @after = after # 移动后下一个位置的元素 end @@ -11,7 +12,7 @@ class Admins::DragPortalImageService < ApplicationService def call return if move.position + 1 == after&.position # 未移动 - images = PortalImage.all + images = laboratory.portal_images ActiveRecord::Base.transaction do if after.blank? || move.id == after.id # 移动至末尾 @@ -31,5 +32,4 @@ class Admins::DragPortalImageService < ApplicationService end end end - end \ No newline at end of file diff --git a/app/views/admins/carousels/index.html.erb b/app/views/admins/carousels/index.html.erb index 89c224784..299d1dcfd 100644 --- a/app/views/admins/carousels/index.html.erb +++ b/app/views/admins/carousels/index.html.erb @@ -1,5 +1,6 @@ <% define_admin_breadcrumbs do + add_admin_breadcrumb('云上实验室', admins_laboratories_path) add_admin_breadcrumb('轮播图') end %> @@ -9,7 +10,7 @@ 首页轮播图(拖动排序) <%= javascript_void_link '添加', class: 'btn btn-primary btn-sm add-btn', data: { toggle: 'modal', target: '.admin-add-carousel-modal' } %>
-
+
<% @images.each_with_index do |image, index| %> -<%= render partial: 'admins/carousels/shared/add_carousel_modal' %> +<%= render partial: 'admins/carousels/shared/add_carousel_modal', locals: { laboratory_id: current_laboratory } %> <%= render partial: 'admins/shared/modal/upload_file_modal' %> \ No newline at end of file diff --git a/app/views/admins/carousels/shared/_add_carousel_modal.html.erb b/app/views/admins/carousels/shared/_add_carousel_modal.html.erb index d1e75e29e..c3055e59e 100644 --- a/app/views/admins/carousels/shared/_add_carousel_modal.html.erb +++ b/app/views/admins/carousels/shared/_add_carousel_modal.html.erb @@ -8,7 +8,7 @@