From 65d4b82ea0cdb5230c8f30a3ad9c9b3b2e934120 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 1 Feb 2020 14:31:07 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/weapps/subjects_controller.rb | 4 ++++ config/routes.rb | 2 ++ 2 files changed, 6 insertions(+) create mode 100644 app/controllers/weapps/subjects_controller.rb diff --git a/app/controllers/weapps/subjects_controller.rb b/app/controllers/weapps/subjects_controller.rb new file mode 100644 index 000000000..8459ee147 --- /dev/null +++ b/app/controllers/weapps/subjects_controller.rb @@ -0,0 +1,4 @@ +class Weapps::SubjectsController < Weapps::BaseController + + +end diff --git a/config/routes.rb b/config/routes.rb index e7482d813..9b2bd3a16 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1018,6 +1018,8 @@ Rails.application.routes.draw do post :cancel_sticky, on: :collection end + resources :subjects, path: :paths, only: [:create, :update, :edit, :show] + resources :courses, only: [:create, :update, :edit, :show] do member do get :shixun_homework_category From ee58beb14762ce5fd8aad1c48f4cf62011807a63 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 1 Feb 2020 14:32:51 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/weapps/subjects_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/weapps/subjects_controller.rb b/app/controllers/weapps/subjects_controller.rb index 8459ee147..cabeb729c 100644 --- a/app/controllers/weapps/subjects_controller.rb +++ b/app/controllers/weapps/subjects_controller.rb @@ -1,4 +1,14 @@ class Weapps::SubjectsController < Weapps::BaseController + before_action :require_login + # 首页 + def index + + end + + # 详情 + def show + + end end From 21a26aba3772f1e7ba5593379f7f944ec94d72cf Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 1 Feb 2020 15:05:12 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/weapps/subjects_controller.rb | 12 ++++++++++++ app/views/weapps/subjects/show.json.jbuilder | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 app/views/weapps/subjects/show.json.jbuilder diff --git a/app/controllers/weapps/subjects_controller.rb b/app/controllers/weapps/subjects_controller.rb index cabeb729c..a760632ae 100644 --- a/app/controllers/weapps/subjects_controller.rb +++ b/app/controllers/weapps/subjects_controller.rb @@ -1,5 +1,6 @@ class Weapps::SubjectsController < Weapps::BaseController before_action :require_login + before_action :find_subject, except: [:index] # 首页 def index @@ -8,7 +9,18 @@ class Weapps::SubjectsController < Weapps::BaseController # 详情 def show + # 合作团队 + Rails.logger.info("##########subject: #{@subject.id}") + @members = @subject.subject_members.includes(:user) + shixuns = @subject.shixuns.published.pluck(:id) + challenge_ids = Challenge.where(shixun_id: shixuns).pluck(:id) + # 实训路径中的所有实训标签 + @tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq + end + private + def find_subject + @subject = Subject.find(params[:id]) end end diff --git a/app/views/weapps/subjects/show.json.jbuilder b/app/views/weapps/subjects/show.json.jbuilder new file mode 100644 index 000000000..757257e82 --- /dev/null +++ b/app/views/weapps/subjects/show.json.jbuilder @@ -0,0 +1,17 @@ +json.subject do + json.name @subject.name + json.description @subject.description + json.shixuns_count @subject.shixuns_count + json.member_count @subject.member_count + json.subject_score @subject.all_score + json.learning_notes @subject.learning_notes +end + +json.team_title @subject.team_title +json.members @members do |member| + json.partial! 'subjects/subject_member', locals: { user: member.user } + json.role member.role +end + +# 技能标签 +json.tags_name @tags \ No newline at end of file From bc2fb6801d557e91c9c517cce0a4af792342d021 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 1 Feb 2020 17:24:44 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B=E5=88=97=E8=A1=A8=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/weapps/subjects_controller.rb | 4 +- app/queries/weapps/subject_query.rb | 37 +++++++++++++++++++ app/views/weapps/subjects/index.json.jbuilder | 7 ++++ config/routes.rb | 2 +- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 app/queries/weapps/subject_query.rb create mode 100644 app/views/weapps/subjects/index.json.jbuilder diff --git a/app/controllers/weapps/subjects_controller.rb b/app/controllers/weapps/subjects_controller.rb index cabeb729c..b9e79a068 100644 --- a/app/controllers/weapps/subjects_controller.rb +++ b/app/controllers/weapps/subjects_controller.rb @@ -3,7 +3,9 @@ class Weapps::SubjectsController < Weapps::BaseController # 首页 def index - + subjects = Weapps::SubjectQuery.call(current_laboratory, params) + @subject_count = subjects.map(&:id).size + @subjects = paginate subjects end # 详情 diff --git a/app/queries/weapps/subject_query.rb b/app/queries/weapps/subject_query.rb new file mode 100644 index 000000000..e867c312b --- /dev/null +++ b/app/queries/weapps/subject_query.rb @@ -0,0 +1,37 @@ +class Weapps::SubjectQuery < ApplicationQuery + include CustomSortable + attr_reader :params + + def initialize(current_laboratory, params) + @current_laboratory = current_laboratory + @params = params + end + + def call + subjects = @current_laboratory.subjects + + # 课程体系的过滤 + if params[:sub_discipline_id].present? + subjects = subjects.joins(:sub_disciplines).where(sub_disciplines: {id: params[:sub_discipline_id]}) + elsif params[:discipline_id].present? + subjects = subjects.joins(:sub_disciplines).where(sub_disciplines: {discipline_id: params[:discipline_id]}) + else + subjects = subjects.joins(:sub_discipline_containers).where(sub_discipline_containers: {container_type: "Subject"}) + end + + subjects = subjects.left_joins(:shixuns).select('subjects.id, subjects.name, subjects.excellent, subjects.stages_count, subjects.status, + subjects.shixuns_count, subjects.updated_at, IFNULL(sum(shixuns.myshixuns_count), 0) myshixuns_count') + .group('subjects.id').order("#{order_type} #{sort_type}") + subjects + end + + private + + def order_type + params[:order] || "updated_at" + end + + def sort_type + params[:sort] || "desc" + end +end \ No newline at end of file diff --git a/app/views/weapps/subjects/index.json.jbuilder b/app/views/weapps/subjects/index.json.jbuilder new file mode 100644 index 000000000..64b18c4e9 --- /dev/null +++ b/app/views/weapps/subjects/index.json.jbuilder @@ -0,0 +1,7 @@ +json.subjects @subjects do |subject| + json.(subject, :id, :excellent, :name, :stages_count, :shixuns_count, :myshixuns_count) + json.image_url url_to_avatar(subject) + json.allow_visit subject.status > 1 || User.current.manager_of_subject?(subject) || User.current.admin? +end + +json.total_count @subject_count \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9b2bd3a16..2b91375ff 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1018,7 +1018,7 @@ Rails.application.routes.draw do post :cancel_sticky, on: :collection end - resources :subjects, path: :paths, only: [:create, :update, :edit, :show] + resources :subjects, path: :paths, only: [:index, :create, :update, :edit, :show] resources :courses, only: [:create, :update, :edit, :show] do member do