Merge branch 'dev_course' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_course

dev_course
SylorHuang 6 years ago
commit 4a2f4154fb

@ -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 (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 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 end
@courses_count = @courses.size @courses_count = @courses.size
@ -937,7 +937,7 @@ class CoursesController < ApplicationController
@page = params[:page] || 1 @page = params[:page] || 1
@page_size = params[:page_size] || 15 @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 # @total_count = @courses.count
# offset = 0 # offset = 0
@ -994,6 +994,20 @@ class CoursesController < ApplicationController
end end
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 private
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.

@ -240,7 +240,7 @@ class QuestionBanksController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
new_task = GraduationTask.new new_task = GraduationTask.new
new_task.attributes = task.attributes.dup.except("id", "course_id", "user_id", "quotes", "graduation_task_id", 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.course_id = course.id
new_task.gtask_bank_id = task.id new_task.gtask_bank_id = task.id
new_task.user_id = current_user.id new_task.user_id = current_user.id
@ -266,7 +266,7 @@ class QuestionBanksController < ApplicationController
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
new_topic = GraduationTopic.new new_topic = GraduationTopic.new
new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", 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.course_id = course.id
new_topic.gtopic_bank_id = topic.id new_topic.gtopic_bank_id = topic.id
new_topic.user_id = current_user.id new_topic.user_id = current_user.id

@ -14,7 +14,7 @@ module GraduationTasksHelper
# 交叉评阅 # 交叉评阅
def cross_comment task, user_id 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}] [{id: 1, name: "只看我的交叉评阅", count: task.graduation_work_comment_assignations.myself(user_id).count}]
else else
[] []

@ -61,6 +61,8 @@ class Course < ApplicationRecord
scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) } scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) }
scope :ended, ->(is_end = true) { where(is_end: is_end) } 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 :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_user, ->(user) { joins(:course_members).where('course_members.user_id = ?', user.id).order(updated_at: :desc) }
scope :by_keywords, lambda { |keywords| scope :by_keywords, lambda { |keywords|

@ -56,11 +56,10 @@ class Message < ApplicationRecord
from_board = Board.find(messages.first.board_id) from_board = Board.find(messages.first.board_id)
root_ids = messages.map(&:id) root_ids = messages.map(&:id)
children = Message.where(parent_id: root_ids).select(:id).to_a children_ids = Message.where(parent_id: root_ids).pluck(:id)
children_ids = children.map(&:id) second_children_ids = Message.where(parent_id: children_ids).pluck(:id)
second_children = Message.where(parent_id: children_ids).select(:id).to_a
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 ActiveRecord::Base.transaction do
Message.where(id: ids, board_id: from_board.id).update_all(board_id: to_board.id) Message.where(id: ids, board_id: from_board.id).update_all(board_id: to_board.id)

@ -11,7 +11,7 @@ class Users::CourseService
end end
def call def call
courses = category_scope_courses.deleted(false) courses = category_scope_courses.not_deleted
courses = status_filter(courses) courses = status_filter(courses)
@ -38,9 +38,9 @@ class Users::CourseService
case params[:status] case params[:status]
when 'processing' then when 'processing' then
relations.ended(false) relations.processing
when 'end' then when 'end' then
relations.ended(true) relations.ended
else else
relations relations
end end

@ -10,7 +10,7 @@ json.courses do
json.tasks_count get_tasks_count course json.tasks_count get_tasks_count course
json.visits course.visits json.visits course.visits
json.is_public course.is_public 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.is_end course.is_end
json.first_category_url module_url(course.course_modules.first, course) json.first_category_url module_url(course.course_modules.first, course)
end end

@ -303,6 +303,7 @@ Rails.application.routes.draw do
post 'search_course_list' post 'search_course_list'
get 'board_list' get 'board_list'
get 'mine' get 'mine'
get 'search_slim'
end end
resources :polls, only:[:index,:new,:create] do resources :polls, only:[:index,:new,:create] do

@ -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
Loading…
Cancel
Save