diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b47a9a346..221197f4e 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -121,25 +121,20 @@ class ShixunsController < ApplicationController @shixuns = status == "published" ? @shixuns.where(status: 2) : @shixuns.where(status: [0, 1]) end - ## 搜索关键字创建者、实训名称、院校名称 - unless params[:search].blank? - keyword = params[:search].strip - @shixuns = @shixuns.joins(user: [user_extension: :school]). - where("schools.name like '%#{keyword}%' - or concat(lastname, firstname) like '%#{keyword}%' - or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct - end - ## 筛选 难度 if params[:diff].present? && params[:diff].to_i != 0 - @shixuns = @shixuns.where(trainee: params[:diff]) + @shixuns = @shixuns.where(trainee: params[:diff]) end - @total_count = @shixuns.count page = params[:page] || 1 - limit = params[:limit] || 15 + limit = params[:limit] || 10 + offset = (page.to_i - 1) * limit + order = params[:order] || "desc" + ## 搜索关键字创建者、实训名称、院校名称 + keyword = params[:search] + @shixuns = Shixun.search keyword, where: {id: @shixuns.pluck(:id)}, order: {"myshixuns_count" => order}, limit: limit, offset: offset - @shixuns = @shixuns.order("myshixuns_count desc").page(page).per(limit).includes(:shixun_info, :subjects, user: [user_extension: :school]) + @total_count = @shixuns.total_count end ## 获取顶部菜单 diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb index 49e066eac..0b53e9df3 100644 --- a/app/models/searchable/shixun.rb +++ b/app/models/searchable/shixun.rb @@ -14,7 +14,9 @@ module Searchable::Shixun def search_data { name: name, - description: Util.extract_content(description)[0..Searchable::MAXIMUM_LENGTH] + description: Util.extract_content(description)[0..Searchable::MAXIMUM_LENGTH], + status: status, + myshixuns_count: myshixuns_count }.merge!(searchable_user_data) .merge!(searchable_challenge_data) end @@ -37,7 +39,7 @@ module Searchable::Shixun end def should_index? - status == 2 # published + [0, 1, 2].include?(status) # published end def to_searchable_json diff --git a/app/services/search_service.rb b/app/services/search_service.rb index 7cd1857bd..418021cc0 100644 --- a/app/services/search_service.rb +++ b/app/services/search_service.rb @@ -14,10 +14,12 @@ class SearchService < ApplicationService private def search_options - { + model_options = { index_name: index_names, model_includes: model_includes - }.merge(default_options) + } + model_options.merge(where: { status: 2 }) if index_names == [Shixun] + model_options.merge(default_options) end def index_names diff --git a/app/views/shixuns/shixun_list.json.jbuilder b/app/views/shixuns/shixun_list.json.jbuilder index 13c556014..54ac65a0a 100644 --- a/app/views/shixuns/shixun_list.json.jbuilder +++ b/app/views/shixuns/shixun_list.json.jbuilder @@ -1,15 +1,17 @@ -json.shixun_list @shixuns do |shixun| - json.shixun_id shixun.id - json.identifier shixun.identifier - json.shixun_name shixun.name - json.description shixun.description - json.myshixuns_count shixun.myshixuns_count - json.school shixun.user&.school_name - json.creator shixun.user&.full_name - json.level level_to_s(shixun.trainee) - json.subjects shixun.subjects do |subject| - json.(subject, :id, :name) - end -end +json.shixuns_count @total_count + +json.shixun_list do + json.array! @shixuns.with_highlights(multiple: true) do |obj, highlights| + puts obj + json.merge! obj.to_searchable_json + json.challenge_names obj.challenges.pluck(:subject) -json.shixuns_count @total_count \ No newline at end of file + json.title highlights.delete(:name)&.join('...') || obj.searchable_title + # json.description highlights.values[0,5].each { |arr| arr.is_a?(Array) ? arr.join('...') : arr }.join('') + json.content highlights + json.level level_to_s(obj.trainee) + json.subjects obj.subjects do |subject| + json.(subject, :id, :name) + end + end +end \ No newline at end of file diff --git a/public/react/src/images/path/path.png b/public/react/src/images/path/path.png new file mode 100644 index 000000000..594358959 Binary files /dev/null and b/public/react/src/images/path/path.png differ diff --git a/public/react/src/modules/courses/poll/PollNew.js b/public/react/src/modules/courses/poll/PollNew.js index e3dc06a4a..0d81a6a8e 100644 --- a/public/react/src/modules/courses/poll/PollNew.js +++ b/public/react/src/modules/courses/poll/PollNew.js @@ -70,6 +70,7 @@ class PollNew extends Component { Newdisplay:false, first_category_url:"", left_banner_id:"", + publishtimeid_int:0, } // console.log("试卷新建和编辑"); // console.log(JSON.stringify(props)); @@ -366,7 +367,12 @@ class PollNew extends Component { } //添加单选题目 addmysingles = () => { + if (this.state.q_countst > 0) { + this.scrollToAnchor("publishtimeid"+this.state.publishtimeid_int); + this.props.showNotification(`不能同时编辑两题`); + return; + } if (this.state.newoption === true) { this.setState({ newoption: false @@ -383,12 +389,18 @@ class PollNew extends Component { } } - this.addMytopic(1, this.state.pollid, Insertposition, false, 0); - // } + this.addMytopic(1, this.state.pollid, Insertposition, false, 0,0); + this.scrollToAnchor("publishtimeids"); } //添加多选题目 addmydoubles = () => { + if (this.state.q_countst > 0) { + this.scrollToAnchor("publishtimeid"+this.state.publishtimeid_int); + this.props.showNotification(`不能同时编辑两题`); + + return; + } // console.log("addmymainsint 70") if (this.state.newoption === true) { this.setState({ @@ -407,13 +419,17 @@ class PollNew extends Component { } - this.addMytopic(2, this.state.pollid, Insertposition, false, 0); - - // } + this.addMytopic(2, this.state.pollid, Insertposition, false, 0,0); + this.scrollToAnchor("publishtimeids"); } //添加主观题目 addmymainsint = () => { + if (this.state.q_countst > 0) { + this.scrollToAnchor("publishtimeid"+this.state.publishtimeid_int); + this.props.showNotification(`不能同时编辑两题`); + return; + } this.setState({ Newdisplay:true, }) @@ -427,22 +443,23 @@ class PollNew extends Component { } - this.addMytopic(3, this.state.pollid, Insertposition, false, 0); - // } + this.addMytopic(3, this.state.pollid, Insertposition, false, 0,0); + this.scrollToAnchor("publishtimeids"); } //编辑方法 - adddomedit = (object) => { + adddomedit = (object,indexysl) => { // console.log("adddomedit 76"); if (this.state.q_countst > 0) { this.props.showNotification(`不能同时编辑两题`); - + this.scrollToAnchor("publishtimeids"); return; } var anserbool = false; this.setState({ q_countst: 1, - bindingid:object.question.id + bindingid:object.question.id, + publishtimeid_int:indexysl }) // window.scrollTo(0, this.refs.targetElement.offsetTops) let {adddom} = this.state; @@ -581,9 +598,19 @@ class PollNew extends Component { }) } - + //滚动 + scrollToAnchor=(index)=>{ + // let name="Anchor_"+index; + console.log("scrollToAnchor"); + console.log(index); + if (index) { + let anchorElement = document.getElementById(index); + // if(anchorElement) { anchorElement.scrollIntoView(); } + $("html").animate({ scrollTop: $(anchorElement).offset().top - 150}) + } + } //新增添加题目 有new - addMytopic = (index, pollid, Insertposition, Whether, id) => { + addMytopic = (index, pollid, Insertposition, Whether, id,inty) => { //Whether 是否插入 // console.log("addMytopic 90") // console.log(index) @@ -593,10 +620,17 @@ class PollNew extends Component { console.log("addMytopic"); console.log(id); if (this.state.q_countst > 0) { + if(Whether===true){ + this.scrollToAnchor("publishtimeids"); + } this.props.showNotification(`不能同时编辑两题`); - return; } + if(Whether===true){ + this.setState({ + publishtimeid_int:inty, + }) + } this.state.Insertposition = Insertposition; var Whethername = null; if (Whether === true) { @@ -2081,32 +2115,67 @@ class PollNew extends Component { axios.post(url, { opr: "up", }).then((result) => { + // try { + // if (result.data.status === 0) { + // this.props.showNotification(`上移成功`); + // thiss.thisinitializationdatanew(); + // } + // // console.log(JSON.stringify(result)) + // } catch (e) { + // // console.log("上移题目成功 错误") + // console.log(e) + // } try { - if (result.data.status === 0) { - this.props.showNotification(`上移成功`); - thiss.thisinitializationdatanew(); + if(result){ + if(result.data){ + if (result.data.status === 0) { + this.props.showNotification(`上移成功`); + thiss.thisinitializationdatanew(); + }else{ + this.props.showNotification(`上移失败`); + } + } + }else { + this.props.showNotification(`上移失败`); } - // console.log(JSON.stringify(result)) } catch (e) { - // console.log("上移题目成功 错误") - console.log(e) - } + this.props.showNotification(`上移失败`); + } }) } else { var url = `/poll_questions/${poll_question_id}/up_down.json`; axios.post(url, { opr: "down", }).then((result) => { + // try { + // if (result.data.status === 0) { + // // message.success("下移题目成功", 1) + // this.props.showNotification(`下移成功`); + // thiss.thisinitializationdatanew(); + // } + // // console.log(JSON.stringify(result)) + // } catch (e) { + // // console.log("下移题目成功 错误") + // console.log(e) + // } + + try { - if (result.data.status === 0) { - // message.success("下移题目成功", 1) - this.props.showNotification(`下移成功`); - thiss.thisinitializationdatanew(); + if(result){ + if(result.data){ + if (result.data.status === 0) { + this.props.showNotification(`下移成功`); + thiss.thisinitializationdatanew(); + }else { + this.props.showNotification(`下移失败`); + } + }else { + this.props.showNotification(`上移失败`); + } } - // console.log(JSON.stringify(result)) } catch (e) { - // console.log("下移题目成功 错误") + this.props.showNotification(`上移失败`); console.log(e) } }) @@ -2243,17 +2312,17 @@ class PollNew extends Component { //点击向上排序按钮事件 handleClickBySortUp = (index, object) => { // console.log("handleClickBySortUp 521") - let arr = this.state.poll_questions; - let newarr = [...arr]; + // let arr = this.state.poll_questions; + // let newarr = [...arr]; // console.log(newarr) if (index != 0) { this.Upanddownmovementof(true, object.question.id); - let temp = newarr[index - 1]; - newarr[index - 1] = newarr[index]; - newarr[index] = temp; - this.setState({ - poll_questions: newarr, - }); + // let temp = newarr[index - 1]; + // newarr[index - 1] = newarr[index]; + // newarr[index] = temp; + // this.setState({ + // poll_questions: newarr, + // }); } } @@ -2265,12 +2334,12 @@ class PollNew extends Component { // if (index != newarr.length - 1) { this.Upanddownmovementof(false, object.question.id); - let temp = newarr[index + 1]; - newarr[index + 1] = newarr[index]; - newarr[index] = temp; - this.setState({ - poll_questions: newarr, - }); + // let temp = newarr[index + 1]; + // newarr[index + 1] = newarr[index]; + // newarr[index] = temp; + // this.setState({ + // poll_questions: newarr, + // }); } else { // console.log("2222index==arr.length"); // console.log(this.state.poll_questions); @@ -2897,12 +2966,12 @@ class PollNew extends Component { title="下移">} this.addMytopic(item.question.question_type, this.state.pollid, index + 1, true, item.question.id)}> this.addMytopic(item.question.question_type, this.state.pollid, index + 1, true, item.question.id,index)}> - this.adddomedit(item)}> this.adddomedit(item,index)}> - : this.adddomedit(item)}> : this.adddomedit(item,index)}> } @@ -2959,7 +3028,7 @@ class PollNew extends Component { let arrid = itemo.question.id; let resultDomtwo; resultDomtwo = - + {itemo.question.question_type === 1 ? "单选题" : itemo.question.question_type === 2 ? "多选题" : "主观题"} + {itemo.question.question_type === 1 ? "单选题" : itemo.question.question_type === 2 ? "多选题" : "主观题"} + {itemo.question.question_type === 1 ? "单选题" : itemo.question.question_type === 2 ? "多选题" : "主观题"}