diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c442e5a6c..cb3b5c929 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 @@ -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 @@ -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/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 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/models/course.rb b/app/models/course.rb index c0c7f1f23..e4ade6e9f 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: 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/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/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 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 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 diff --git a/lib/tasks/course_board_message_count.rake b/lib/tasks/course_board_message_count.rake new file mode 100644 index 000000000..35e439403 --- /dev/null +++ b/lib/tasks/course_board_message_count.rake @@ -0,0 +1,26 @@ +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) + 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) + end + end + + Board.reset_counters(board.id, :messages) + logger("transfer success ~") + end + end + + def logger(msg) + puts msg + end +end \ No newline at end of file