From 592e26f0ab98f8e706307286fa09d631441121f1 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Feb 2020 20:33:03 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 73 ++------------------------ app/views/subjects/index.json.jbuilder | 15 +++--- 2 files changed, 10 insertions(+), 78 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index da88e3258..b4d9ffcd1 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -17,76 +17,9 @@ class SubjectsController < ApplicationController include CustomSortable def index - @tech_system = current_laboratory.subject_repertoires - select = params[:select] # 路径导航类型 - reorder = params[:order] || "publish_time" - search = params[:search] - - ## 分页参数 - page = params[:page] || 1 - limit = params[:limit] || 16 - offset = (page.to_i-1) * limit - - # 最热排序 - if reorder == "myshixun_count" - subject_ids = current_laboratory.subjects.pluck(:id) - subject_ids = subject_ids.length > 0 ? "(" + subject_ids.join(",") + ")" : "(-1)" - laboratory_join = " AND subjects.id in #{subject_ids} " - - if select - @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.public, - subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns - on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - subjects.hidden = 0 AND subjects.public = 2 AND subjects.name like '%#{search}%' #{laboratory_join} - AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") - else - @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.public, - subjects.shixuns_count, subjects.excellent, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns - on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - subjects.hidden = 0 AND subjects.public = 2 AND subjects.name like '%#{search}%' #{laboratory_join} - GROUP BY subjects.id ORDER BY myshixun_member_count DESC") - end - else - @subjects = current_laboratory.subjects - # 我的路径 - if reorder == "mine" - tip_exception(401, "..") unless current_user.logged? - - mine_subject_id = StageShixun.find_by_sql("select DISTINCT(subject_id) from stage_shixuns where shixun_id in - (select distinct(shixun_id) from myshixuns where user_id=#{current_user.id})").map(&:subject_id) - manage_subject_id = SubjectMember.where(user_id: current_user.id).pluck(:subject_id) - total_subject_id = (mine_subject_id + manage_subject_id).uniq - @subjects = @subjects.where(id: total_subject_id) - elsif reorder == "publish_time" - @subjects = @subjects.unhidden - else - @subjects = @subjects.publiced.unhidden - end - - # 类型 - if select - @subjects = @subjects.where(repertoire_id: select) - end - - if search.present? - @subjects = @subjects.where("name like ?", "%#{search}%") - end - - # 排序 - order_str = (reorder == "publish_time" ? "homepage_show desc, excellent desc, public = 2 desc, publish_time asc" : "homepage_show desc, excellent desc, updated_at desc") - @subjects = @subjects.reorder(order_str) - end - - @total_count = @subjects.size - - if reorder != "myshixun_count" - @subjects = @subjects.page(page).per(limit).includes(:shixuns, :repertoire) - else - @subjects = @subjects[offset, limit] - subject_ids = @subjects.pluck(:id) - order_ids = subject_ids.size > 0 ? subject_ids.join(',') : -1 - @subjects = Subject.where(id: subject_ids).order("field(id,#{order_ids})").includes(:shixuns, :repertoire) - end + subjects = Weapps::SubjectQuery.call(current_laboratory, params) + @subject_count = subjects.map(&:id).size + @subjects = paginate subjects end def show diff --git a/app/views/subjects/index.json.jbuilder b/app/views/subjects/index.json.jbuilder index 8cf7898c7..1d8f97ec4 100644 --- a/app/views/subjects/index.json.jbuilder +++ b/app/views/subjects/index.json.jbuilder @@ -1,10 +1,9 @@ -json.tags @tech_system do |tag| - json.tag_id tag.id - json.tag_name tag.name +json.subjects @subjects do |subject| + json.(subject, :id, :excellent, :name, :stages_count, :shixuns_count) + json.myshixuns_count subject.myshixuns_count + json.challenges_count subject.subject_challenge_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.subjects do - json.partial! 'subject', locals: {subjects: @subjects} -end - -json.total_count @total_count +json.total_count @subject_count \ No newline at end of file From 70665d6b8a2f51c272d2d61a95558597ddb1c7be Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Feb 2020 21:54:22 +0800 Subject: [PATCH 2/8] 1 --- app/queries/weapps/subject_query.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/queries/weapps/subject_query.rb b/app/queries/weapps/subject_query.rb index e2f5625e1..8bfe9e9a8 100644 --- a/app/queries/weapps/subject_query.rb +++ b/app/queries/weapps/subject_query.rb @@ -8,7 +8,7 @@ class Weapps::SubjectQuery < ApplicationQuery end def call - subjects = @current_laboratory.subjects.unhidden.publiced.show_moblied + subjects = @current_laboratory.subjects.unhidden.publiced # 课程体系的过滤 if params[:sub_discipline_id].present? From 7e2acf2ffd01185422e5815cd5815b522873caf3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Feb 2020 21:58:23 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=8F=82=E6=95=B0=E4=B8=8D=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/subjects/index.json.jbuilder | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/views/subjects/index.json.jbuilder b/app/views/subjects/index.json.jbuilder index 1d8f97ec4..77362e7b4 100644 --- a/app/views/subjects/index.json.jbuilder +++ b/app/views/subjects/index.json.jbuilder @@ -1,9 +1,5 @@ -json.subjects @subjects do |subject| - json.(subject, :id, :excellent, :name, :stages_count, :shixuns_count) - json.myshixuns_count subject.myshixuns_count - json.challenges_count subject.subject_challenge_count - json.image_url url_to_avatar(subject) - json.allow_visit subject.status > 1 || User.current.manager_of_subject?(subject) || User.current.admin? +json.subjects do + json.partial! 'subject', locals: {subjects: @subjects} end -json.total_count @subject_count \ No newline at end of file +json.total_count @total_count From 0829531f5c9c16ac1606c388ace78bbd2329ce8b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Feb 2020 22:03:00 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E6=8A=80=E6=9C=AF=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 2 +- app/queries/weapps/subject_query.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index b4d9ffcd1..c78eff35a 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -19,7 +19,7 @@ class SubjectsController < ApplicationController def index subjects = Weapps::SubjectQuery.call(current_laboratory, params) @subject_count = subjects.map(&:id).size - @subjects = paginate subjects + @subjects = paginate subjects.includes(:shixuns, :repertoire) end def show diff --git a/app/queries/weapps/subject_query.rb b/app/queries/weapps/subject_query.rb index 8bfe9e9a8..b50c2a104 100644 --- a/app/queries/weapps/subject_query.rb +++ b/app/queries/weapps/subject_query.rb @@ -19,8 +19,8 @@ class Weapps::SubjectQuery < ApplicationQuery 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.homepage_show, - subjects.shixuns_count, subjects.updated_at, IFNULL(sum(shixuns.myshixuns_count), 0) myshixuns_count') + subjects = subjects.left_joins(:shixuns, :repertoire).select('subjects.id, subjects.name, subjects.excellent, subjects.stages_count, subjects.status, subjects.homepage_show, + subjects.shixuns_count, subjects.repertoire_id, subjects.updated_at, IFNULL(sum(shixuns.myshixuns_count), 0) myshixuns_count') .group('subjects.id').order("subjects.homepage_show #{sort_type}, #{order_type} #{sort_type}") subjects end From ea9709bbca7d1f6bce4c8bdbb3bcde6609816af7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Sat, 29 Feb 2020 23:08:22 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=AD=9B=E9=80=89?= =?UTF-8?q?=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/modules/paths/ShixunPathSearch.js | 162 +++++++++++------- .../src/modules/tpm/shixuns/ShixunCardList.js | 2 +- .../modules/tpm/shixuns/ShixunSearchBar.js | 2 +- 3 files changed, 102 insertions(+), 64 deletions(-) diff --git a/public/react/src/modules/paths/ShixunPathSearch.js b/public/react/src/modules/paths/ShixunPathSearch.js index f45098f8e..c7a668fd6 100644 --- a/public/react/src/modules/paths/ShixunPathSearch.js +++ b/public/react/src/modules/paths/ShixunPathSearch.js @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import axios from 'axios'; -import {Input} from 'antd'; +import {Dropdown,Menu} from 'antd'; import {getImageUrl} from 'educoder'; import PathCard from "./ShixunPathCard"; import UpgradeModals from '../modals/UpgradeModals'; @@ -18,59 +18,49 @@ class ShixunPathSearch extends Component{ page:1, pathList:null, sortList:'', - total_count:0 + total_count:0, + sort:"desc", + limit:16, + discipline_id:undefined, + sub_discipline_id:undefined } } + + //切换列表状态 changeStatus=(value)=>{ - this.setState( - { - pathList:null - } - ) - let {select,search}=this.state; + + let {discipline_id,sub_discipline_id }=this.state; this.setState({ order:value, page:1 }) - this.getList(value,select,search,1); - } - //搜索输入 - inputSearchValue=(e)=>{ - this.setState({ - search:e.target.value, - page:1 - }) - } - //搜索 - searchValue=(e)=>{ - let {order,select,search}=this.state; - this.setState({ - page:1 - }) - this.getList(order,select,search,1 ); + this.getList(value,discipline_id,sub_discipline_id,1); } + + //选择页数 onChange=(pageNumber)=> { - let {order,select,search}=this.state; + + let { order,discipline_id,sub_discipline_id }=this.state; this.setState({ page:pageNumber }) - this.getList(order,select,search,pageNumber); + this.getList(order,discipline_id,sub_discipline_id,pageNumber); } //顶部分类 - changeSelect=(tag_id)=>{ - this.setState( - { - pathList:null - } - ) - let { order,search }=this.state; + changeSelect=(e,tag_id,sum)=>{ + this.setState({ - select:tag_id + order:"updated_at", + discipline_id:tag_id, + page:1, + sub_discipline_id:undefined }) - this.getList( order,tag_id,search,1 ); + let { order }=this.state; + this.getList(order,tag_id,undefined,1 ); + e.stopPropagation(); } @@ -85,31 +75,41 @@ class ShixunPathSearch extends Component{ }).catch((error)=>{ console.log(error); }) + this.getdisciplines() + let { order,discipline_id,sub_discipline_id,page }=this.state; + this.getList(order,discipline_id,sub_discipline_id,page ); - let { order,select,search,page }=this.state; - this.getList(order,select,search,page ); } + getdisciplines=()=>{ + let url='/disciplines.json'; + axios.get(url,{params:{ + source:"subject" + }}).then((result)=>{ + if(result.status==200){ + // console.log(result.data.disciplines) + this.setState({ + sortList:result.data.disciplines + }) + } + }).catch((error)=>{ + console.log(error); + }) + } - getList=(order,select,search,page )=>{ + getList=(order,discipline_id,sub_discipline_id,page )=>{ let url='/paths.json'; - // '?order='+order+'&page='+page; - // if(select!=""){ - // url+='&select='+select; - // } - // if(search!=""){ - // url+='&search='+search; - // } axios.get(url,{params:{ - order:order, + sort:"desc", + limit:16, + order:order, page:page, - select:select, - // search:search + discipline_id:discipline_id, + sub_discipline_id:sub_discipline_id }}).then((result)=>{ if(result.status==200){ this.setState({ - sortList:result.data.tags, pathList:result.data.subjects, total_count:result.data.total_count }) @@ -119,11 +119,6 @@ class ShixunPathSearch extends Component{ }) } - - setHistoryFun=(url)=>{ - this.props.history.push(url) - } - //头部获取是否已经登录了 getUser=(url,type)=>{ if(this.props.checkIfLogin()===false){ @@ -140,9 +135,41 @@ class ShixunPathSearch extends Component{ } + } + + getshixunchildValues=(e,id,item)=>{ + + this.setState({ + discipline_id:item.id, + sub_discipline_id:id, + }) + let { order,page }=this.state; + this.getList(order,item.id,id,page ); + e.stopPropagation(); + } + + getmenu=(list,item)=>{ + return( + + +
+
+ { + list.map((tag,e)=>{ + return( + this.getshixunchildValues(e,tag.id,item)}>{tag.name} + ) + }) + } +
+
+
+
+ ) } render() { - let { order,sortList,search,page,total_count,select }=this.state; + let { order,sortList,search,page,total_count,discipline_id }=this.state; let pathstype=false; if(this.props&&this.props.mygetHelmetapi!=null){ let paths="/paths"; @@ -156,8 +183,8 @@ class ShixunPathSearch extends Component{ }) } - // console.log(this.props) - return ( + + return (
{this.state.updata===undefined?"": @@ -185,11 +222,15 @@ class ShixunPathSearch extends Component{
    -
  • 0 ? "" : "active"}>this.changeSelect(null)}>全部
  • +
  • 0 ? "" : "active"}>this.changeSelect(e,undefined)}>全部
  • { sortList && sortList.map((item,key)=>{ return( -
  • this.changeSelect(`${item.tag_id}`)}>{item.tag_name}
  • +
  • this.changeSelect(e,`${item.id}`,item.sub_disciplines.length)} key={key}> + this.getmenu(item.sub_disciplines,item)} placement="bottomCenter"> + {item.name} + +
  • ) }) } @@ -229,6 +270,3 @@ class ShixunPathSearch extends Component{ } } export default ShixunPathSearch; - - -// diff --git a/public/react/src/modules/tpm/shixuns/ShixunCardList.js b/public/react/src/modules/tpm/shixuns/ShixunCardList.js index 235b11323..a0c021980 100644 --- a/public/react/src/modules/tpm/shixuns/ShixunCardList.js +++ b/public/react/src/modules/tpm/shixuns/ShixunCardList.js @@ -211,7 +211,7 @@ class ShixunCardList extends Component { }) } - console.log(this.props.middleshixundata.search_tags) + return (
    diff --git a/public/react/src/modules/tpm/shixuns/ShixunSearchBar.js b/public/react/src/modules/tpm/shixuns/ShixunSearchBar.js index b884d7bf0..782a55b54 100644 --- a/public/react/src/modules/tpm/shixuns/ShixunSearchBar.js +++ b/public/react/src/modules/tpm/shixuns/ShixunSearchBar.js @@ -237,7 +237,7 @@ render() { { shixunhoverData.map((item,key)=>{ return( - =8?"bottomLeft":"bottomCenter"}> + =8?"bottomLeft":"bottomCenter"}>
  • {item.name}
  • From 7557bb6adf99347bad0caf1a67fd3fb25aa8b7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Sat, 29 Feb 2020 23:31:44 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=88=90=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/paths/ShixunPathSearch.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/react/src/modules/paths/ShixunPathSearch.js b/public/react/src/modules/paths/ShixunPathSearch.js index c7a668fd6..a7e944826 100644 --- a/public/react/src/modules/paths/ShixunPathSearch.js +++ b/public/react/src/modules/paths/ShixunPathSearch.js @@ -215,6 +215,7 @@ class ShixunPathSearch extends Component{ .ant-dropdown-menu-item:hover, .ant-dropdown-menu-submenu-title:hover{ background-color: #fff !important; } + a{text-decoration:none !important;} ` } @@ -241,7 +242,7 @@ class ShixunPathSearch extends Component{ {/* this.changeStatus("publish_time")}>全部*/} {/* this.changeStatus("mine")}>我的*/} this.changeStatus("updated_at")}>最新 - this.changeStatus("myshixun_count")}>最热 + this.changeStatus("myshixuns_count")}>最热 {this.props.user&&this.props.user.main_site===false?"":this.props.Headertop===undefined?"":this.getUser("/paths/new")}>+新建实践课程} {this.props.user&&this.props.user.main_site===true?"":this.props.Headertop===undefined?"": pathstype===true?"":this.props.user&&this.props.user.admin===true||this.props.user&&this.props.user.is_teacher===true||this.props.user&&this.props.user.business===true?this.getUser("/paths/new")}>+新建实践课程:"" From 52f6c8f8ae9df1185a1f91aac3d897a6f879d2f4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Feb 2020 23:40:32 +0800 Subject: [PATCH 7/8] 1 --- app/views/subjects/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/subjects/index.json.jbuilder b/app/views/subjects/index.json.jbuilder index 77362e7b4..6c5434850 100644 --- a/app/views/subjects/index.json.jbuilder +++ b/app/views/subjects/index.json.jbuilder @@ -2,4 +2,4 @@ json.subjects do json.partial! 'subject', locals: {subjects: @subjects} end -json.total_count @total_count +json.total_count @subject_count From 36e918ea3509a95234cf55ff8c255908231e64af Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 2 Mar 2020 10:37:57 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E4=B8=8D=E8=A6=81?= =?UTF-8?q?=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 10 +++++----- app/views/shixuns/_shixun.json.jbuilder | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index c40010be2..a5cc27967 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -86,11 +86,11 @@ class ShixunsController < ApplicationController @shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit) - @tag_name_map = TagRepertoire.joins(:shixun_tag_repertoires) - .where(shixun_tag_repertoires: { shixun_id: @shixuns.map(&:id) }) - .group('shixun_tag_repertoires.shixun_id') - .select('shixun_id, tag_repertoires.name') - .each_with_object({}) { |r, obj| obj[r.shixun_id] = r.name } + #@tag_name_map = TagRepertoire.joins(:shixun_tag_repertoires) + # .where(shixun_tag_repertoires: { shixun_id: @shixuns.map(&:id) }) + # .group('shixun_tag_repertoires.shixun_id') + # .select('shixun_id, tag_repertoires.name') + # .each_with_object({}) { |r, obj| obj[r.shixun_id] = r.name } end def shixun_list diff --git a/app/views/shixuns/_shixun.json.jbuilder b/app/views/shixuns/_shixun.json.jbuilder index 89e8d3c62..2994a8a75 100644 --- a/app/views/shixuns/_shixun.json.jbuilder +++ b/app/views/shixuns/_shixun.json.jbuilder @@ -16,7 +16,7 @@ json.array! shixuns do |shixun| json.is_jupyter shixun.is_jupyter? json.power (current_user.shixun_permission(shixun)) # 现在首页只显示已发布的实训 # REDO: 局部缓存 - json.tag_name @tag_name_map&.fetch(shixun.id, nil) || shixun.tag_repertoires.first.try(:name) + json.tag_name nil # @tag_name_map&.fetch(shixun.id, nil) || shixun.tag_repertoires.first.try(:name) json.myshixuns_count shixun.myshixuns_count json.stu_num shixun.myshixuns_count json.score_info shixun.averge_star