From a42ce8c0246a8c76c0eb68e85e5acfd89ca02e5e Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 10:16:18 +0800 Subject: [PATCH 01/11] add search bank slim api --- app/controllers/courses_controller.rb | 14 ++++++++++++++ app/models/course.rb | 2 ++ config/routes.rb | 1 + 3 files changed, 17 insertions(+) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c442e5a6c..5097536d5 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -994,6 +994,20 @@ class CoursesController < ApplicationController end end + def search_slim + courses = current_user.manage_courses.not_deleted.processing + + keyword = params[:keyword].to_s.strip + if keyword.present? + courses = courses.where('name LIKE ?', "%#{keyword}%") + end + + count = courses.count + courses = paginate(courses) + + render_ok(count: count, courses: courses.select(:id, :name).as_json) + end + private # Use callbacks to share common setup or constraints between actions. diff --git a/app/models/course.rb b/app/models/course.rb index c0c7f1f23..61e48d350 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -61,6 +61,8 @@ class Course < ApplicationRecord scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) } scope :ended, ->(is_end = true) { where(is_end: is_end) } + scope :processing, -> { where(is_end: false) } + scope :not_deleted, -> { where(is_delete: false) } scope :deleted, ->(is_delete = 1) { where(is_delete: is_delete) } scope :by_user, ->(user) { joins(:course_members).where('course_members.user_id = ?', user.id).order(updated_at: :desc) } scope :by_keywords, lambda { |keywords| diff --git a/config/routes.rb b/config/routes.rb index e7fac7331..ecd54c8c0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -303,6 +303,7 @@ Rails.application.routes.draw do post 'search_course_list' get 'board_list' get 'mine' + get 'search_slim' end resources :polls, only:[:index,:new,:create] do From 8ab306550aafc3385ee357b8292e1a091ff48364 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 10:31:41 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E4=BB=8E=E9=A2=98=E5=BA=93=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4=E5=BA=94=E4=B8=BA=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/question_banks_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 299224527..bf55db9dd 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -240,7 +240,7 @@ class QuestionBanksController < ApplicationController ActiveRecord::Base.transaction do new_task = GraduationTask.new new_task.attributes = task.attributes.dup.except("id", "course_id", "user_id", "quotes", "graduation_task_id", - "course_list_id", "gtask_bank_id") + "course_list_id", "gtask_bank_id", "created_at", "updated_at") new_task.course_id = course.id new_task.gtask_bank_id = task.id new_task.user_id = current_user.id @@ -266,7 +266,7 @@ class QuestionBanksController < ApplicationController ActiveRecord::Base.transaction do new_topic = GraduationTopic.new new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", - "course_list_id", "gtopic_bank_id") + "course_list_id", "gtopic_bank_id", "created_at", "updated_at") new_topic.course_id = course.id new_topic.gtopic_bank_id = topic.id new_topic.user_id = current_user.id From c7287122af88b31aa07ffd2eb797b2f4c3a076cd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 10:37:53 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 94da87af5..1993851e8 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -10,7 +10,7 @@ json.courses do json.tasks_count get_tasks_count course json.visits course.visits json.is_public course.is_public - json.is_accessible course.is_public? || @user.course_identity(course) < Course::NORMAL + json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end json.first_category_url module_url(course.course_modules.first, course) end From e86cb487a3eab919edf7ed2b42bc5e796d10678e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 10:50:16 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 5097536d5..753999e54 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -87,7 +87,7 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") + @courses = @courses.left_joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") end @courses_count = @courses.size From e442c30823aaf821238b642e686c37cdd1c70723 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 10:52:23 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 753999e54..cd1e9a0ea 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -87,7 +87,7 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.left_joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") + @courses = @courses.left_outer_joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") end @courses_count = @courses.size From bea98cb44a6b35bc14a6e08fbc74a8deb24ac785 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 10:58:44 +0800 Subject: [PATCH 06/11] add course board message count rake --- app/models/message.rb | 7 +++---- lib/tasks/course_board_message_count.rake | 24 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 lib/tasks/course_board_message_count.rake diff --git a/app/models/message.rb b/app/models/message.rb index 26946f6d0..d3d507a72 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -56,11 +56,10 @@ class Message < ApplicationRecord from_board = Board.find(messages.first.board_id) root_ids = messages.map(&:id) - children = Message.where(parent_id: root_ids).select(:id).to_a - children_ids = children.map(&:id) - second_children = Message.where(parent_id: children_ids).select(:id).to_a + children_ids = Message.where(parent_id: root_ids).pluck(:id) + second_children_ids = Message.where(parent_id: children_ids).pluck(:id) - ids = root_ids.concat(children_ids).concat(second_children.map(&:id)).uniq + ids = root_ids.concat(children_ids).concat(second_children_ids).uniq ActiveRecord::Base.transaction do Message.where(id: ids, board_id: from_board.id).update_all(board_id: to_board.id) diff --git a/lib/tasks/course_board_message_count.rake b/lib/tasks/course_board_message_count.rake new file mode 100644 index 000000000..d1ac5524d --- /dev/null +++ b/lib/tasks/course_board_message_count.rake @@ -0,0 +1,24 @@ +namespace :course_board do + desc 'transfer children message to root message board' + task children_message_transfer: :environment do + Board.find_each do |board| + logger("Current transfer board id: #{board.id} ~") + + root_subquery = board.messages.where(parent_id: nil).reorder(nil).pluck(:id) + next if root_subquery.blank? + children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id) + next if children_subquery.blank? + second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id) + + ids = children_subquery.concat(second_children_subquery).uniq + Message.where(id: ids).update_all(board_id: board.id) + + Board.reset_counters(board.id, :messages) + logger("transfer success ~") + end + end + + def logger(msg) + puts msg + end +end \ No newline at end of file From f53b5af75b5953103ed6426d8a6be70adb15fa3b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 10:59:47 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E9=A6=96=E9=A1=B5tiaoz?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 5097536d5..252664139 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -87,7 +87,7 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") + @courses = @courses.joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%").distinct end @courses_count = @courses.size From 819b2347c48447b71c4212081ae07804a0cb95f1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 11:14:41 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E4=BA=A4=E5=8F=89=E8=AF=84=E9=98=85?= =?UTF-8?q?=E6=9C=AA=E5=BC=80=E5=90=AF=E5=89=8D=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/graduation_tasks/tasks_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index fe7ffddc4..cda1eb6d4 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -9,7 +9,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.teacher_comment teacher_comment @task, @current_user.id json.task_status task_status @task, @current_user.id json.course_group_info course_group_info @course, @current_user.id - json.cross_comment cross_comment @task, @current_user + json.cross_comment cross_comment @task, @current_user if @task.status >= 3 end # 课堂下所有老师 TODO: 考虑以后在点击分配时,再获取老师列表 json.teacher_list do From 4a6909b59f32a697624a4d8997aa757339a9f5a4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 11:19:21 +0800 Subject: [PATCH 09/11] =?UTF-8?q?D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/graduation_tasks_helper.rb | 2 +- app/views/graduation_tasks/tasks_list.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/graduation_tasks_helper.rb b/app/helpers/graduation_tasks_helper.rb index 5253b0d56..a5f05d623 100644 --- a/app/helpers/graduation_tasks_helper.rb +++ b/app/helpers/graduation_tasks_helper.rb @@ -14,7 +14,7 @@ module GraduationTasksHelper # 交叉评阅 def cross_comment task, user_id - if task.cross_comment + if task.cross_comment && task.status >= 3 [{id: 1, name: "只看我的交叉评阅", count: task.graduation_work_comment_assignations.myself(user_id).count}] else [] diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index cda1eb6d4..fe7ffddc4 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -9,7 +9,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.teacher_comment teacher_comment @task, @current_user.id json.task_status task_status @task, @current_user.id json.course_group_info course_group_info @course, @current_user.id - json.cross_comment cross_comment @task, @current_user if @task.status >= 3 + json.cross_comment cross_comment @task, @current_user end # 课堂下所有老师 TODO: 考虑以后在点击分配时,再获取老师列表 json.teacher_list do From 4fd4b579af190ce80d5700e8fe6ef6ed74284454 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 11:20:32 +0800 Subject: [PATCH 10/11] fix rake --- lib/tasks/course_board_message_count.rake | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/tasks/course_board_message_count.rake b/lib/tasks/course_board_message_count.rake index d1ac5524d..35e439403 100644 --- a/lib/tasks/course_board_message_count.rake +++ b/lib/tasks/course_board_message_count.rake @@ -5,13 +5,15 @@ namespace :course_board do logger("Current transfer board id: #{board.id} ~") root_subquery = board.messages.where(parent_id: nil).reorder(nil).pluck(:id) - next if root_subquery.blank? - children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id) - next if children_subquery.blank? - second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id) + if root_subquery.present? + children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id) + if children_subquery.present? + second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id) - ids = children_subquery.concat(second_children_subquery).uniq - Message.where(id: ids).update_all(board_id: board.id) + ids = children_subquery.concat(second_children_subquery).uniq + Message.where(id: ids).update_all(board_id: board.id) + end + end Board.reset_counters(board.id, :messages) logger("transfer success ~") From 1253844369cb8438b1b2a0af7ff314bad5a0f2ed Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 13:54:07 +0800 Subject: [PATCH 11/11] modify --- app/controllers/courses_controller.rb | 2 +- app/models/course.rb | 2 +- app/services/users/course_service.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 252664139..cb3b5c929 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -937,7 +937,7 @@ class CoursesController < ApplicationController @page = params[:page] || 1 @page_size = params[:page_size] || 15 - @courses = Course.by_user(current_user).hidden(false).ended(false).deleted(0).by_keywords(params[:search]).distinct + @courses = Course.by_user(current_user).hidden(false).processing.not_deleted.by_keywords(params[:search]).distinct # @total_count = @courses.count # offset = 0 diff --git a/app/models/course.rb b/app/models/course.rb index 61e48d350..e4ade6e9f 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -62,7 +62,7 @@ class Course < ApplicationRecord scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) } scope :ended, ->(is_end = true) { where(is_end: is_end) } scope :processing, -> { where(is_end: false) } - scope :not_deleted, -> { where(is_delete: false) } + scope :not_deleted, -> { where(is_delete: 0) } scope :deleted, ->(is_delete = 1) { where(is_delete: is_delete) } scope :by_user, ->(user) { joins(:course_members).where('course_members.user_id = ?', user.id).order(updated_at: :desc) } scope :by_keywords, lambda { |keywords| diff --git a/app/services/users/course_service.rb b/app/services/users/course_service.rb index 6271db17b..9eb34917e 100644 --- a/app/services/users/course_service.rb +++ b/app/services/users/course_service.rb @@ -11,7 +11,7 @@ class Users::CourseService end def call - courses = category_scope_courses.deleted(false) + courses = category_scope_courses.not_deleted courses = status_filter(courses) @@ -38,9 +38,9 @@ class Users::CourseService case params[:status] when 'processing' then - relations.ended(false) + relations.processing when 'end' then - relations.ended(true) + relations.ended else relations end