import React, { Component } from 'react'; import { SnackbarHOC } from 'educoder'; import {BrowserRouter as Router,Route,Switch,Link} from 'react-router-dom'; import {Tooltip,Menu,Pagination,Spin, Dropdown,Checkbox} from 'antd'; import axios from 'axios'; import {getImageUrl,WordsBtn} from 'educoder'; import moment from 'moment'; import Modals from '../../modals/Modals'; import SendTopics from '../../modals/SendTopics' import NoneData from '../../courses/coursesPublic/NoneData'; import "./usersInfo.css"; import Withoutpermission from './Withoutpermission.png'; class InfosTopics extends Component{ constructor(props){ super(props); this.state={ isSpin:false, category:"normal", course_list_id:undefined, sort_by:"updated_at", sort_direction:"desc", page:1, data:undefined, checkBoxValues:[], per_page:15, isshowprofes:false } } componentDidMount(){ // let types=this.props.match.params.topicstype; // let professional_certification=this.props.current_user&&this.props.current_user.professional_certification; // // if(professional_certification===false&&types==="publicly"){ // this.setState({ // isshowprofes:true // }) // }else{ // this.updataslist() // } this.updataslist() } // componentDidUpdate(prevProps) { // // if(prevProps.current_user!=this.props.current_user){ // let types=this.props.match.params.topicstype; // let professional_certification=this.props.current_user&&this.props.current_user.professional_certification; // // console.log(professional_certification) // if(professional_certification===false&&types==="publicly"){ // this.setState({ // isshowprofes:true // }) // }else{ // this.updataslist() // } // } // } updataslist=()=>{ let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; this.searchAlldata(types,category,course_list_id,sort_by,sort_direction,page) } searchAlldata=(type,category,course_list_id,sort_by,sort_direction,page)=>{ this.setState({ isSpin:true }) let {per_page}=this.state; let url=`/users/question_banks.json`; axios.get(encodeURI(url),{params:{ type, object_type:category, course_list_id, sort_by, sort_direction, page, per_page } }).then((response) => { if(response){ if(response.status){ if(response.data.status == -2){ this.setState({ isshowprofes:true, isSpin:false }) }else if(response.data.status === 403||response.data.status === 401||response.data.status === 500){ this.setState({ isSpin:false }) }else{ this.setState({ data:response.data, checkBoxValues:[], isSpin:false }) } } } }).catch((error) => { this.setState({ isSpin:false }) }); } searchCategory=(type)=>{ this.setState({ category:type, course_list_id:undefined, }) let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; this.searchAlldata(types,type,undefined,sort_by,sort_direction,page) } searchCourselistid=(id)=>{ this.setState({ course_list_id:id }) let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; this.searchAlldata(types,category,id,sort_by,sort_direction,page) } onCheckBoxChange=(checkedValues)=>{ if(checkedValues.length>15){ this.props.showNotification("选择条数不能大于15条") }else{ this.setState({ checkBoxValues:checkedValues }) } } updatedlist=(updatedtype)=>{ let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; if(updatedtype===sort_by){ if(sort_direction==="desc"){ this.setState({ sort_direction:"asc", sort_by:updatedtype }) this.searchAlldata(types,category,course_list_id,updatedtype,"asc",page) }else{ this.setState({ sort_direction:"desc", sort_by:updatedtype }) this.searchAlldata(types,category,course_list_id,updatedtype,"desc",page) } }else{ this.setState({ sort_direction:"desc", sort_by:updatedtype }) this.searchAlldata(types,category,course_list_id,updatedtype,"desc",page) } } changePage=(pageNumber)=>{ let types=this.props.match.params.topicstype; let { category,course_list_id,sort_by,sort_direction,page}=this.state; this.searchAlldata(types,category,course_list_id,sort_by,sort_direction,pageNumber) this.setState({ page:pageNumber, checkBoxValues:[] }) } deletecheckBoxValues=()=>{ let {checkBoxValues}=this.state; if(checkBoxValues.length===0){ this.props.showNotification("请选择题库") }else{ this.setState({ Modalstype:true, Modalstopval:"是否确认删除?", ModalCancel:this.topicscancelmodel, ModalSave:this.topicssavedelete, }) } } topicssavedelete=()=>{ let {checkBoxValues,category}=this.state; const url = `/question_banks/multi_delete.json`; axios.delete(url, { data: { object_id: checkBoxValues, object_type:category }}) .then((response) => { if(response.data.status===0){ this.updataslist() this.props.showNotification(response.data.message) }else{ this.props.showNotification(response.data.message) } }) .catch(function (error) { console.log(error); }); this.topicscancelmodel() } topicscancelmodel=()=>{ this.setState({ Modalstype:false, Loadtype:false, visible:false, Modalstopval:"", ModalCancel:"", ModalSave:"", checkBoxValues:[], checkedtype:false }) } openTopics=(id)=>{ this.setState({ Modalstype:true, Modalstopval:"公开后不能重设为私有", ModalsBottomval:"是否确认设为公开?", ModalCancel:this.topicscancelmodel, ModalSave:()=>this.topicssaveonOpen(id), }) } topicssaveonOpen=(id)=>{ let {category}=this.state; const url = `/question_banks/multi_public.json`; axios.post(url,{ object_id:[id], object_type:category }).then((response) => { if(response.data.status===0){ this.updataslist() this.props.showNotification(response.data.message) }else{ this.props.showNotification(response.data.message) } }).catch(function (error) { console.log(error); }); this.topicscancelmodel() } sendTopics=()=>{ let {checkBoxValues}=this.state; if(checkBoxValues.length===0){ this.props.showNotification("请选择题库") }else{ this.setState({ visible:true }) } } render(){ let{ category, course_list_id, isSpin, data, page, sort_direction, sort_by, checkBoxValues, Modalstype, visible, isshowprofes } = this.state; let { is_current, current_user, }=this.props; let categorylist=[ {val:"普通作业",type:"normal"}, {val:"分组作业",type:"group"}, {val:"毕设选题",type:"gtopic"}, {val:"毕设任务",type:"gtask"}, {val:"试卷",type:"exercise"}, {val:"问卷",type:"poll"}, ] let types=this.props.match.params.topicstype; let username=this.props.match.params.username; //types===publicly 公共 //types===personal 私有 let user_id=this.props.current_user&&this.props.current_user.user_id; let user_type=this.props.current_user&&this.props.current_user.user_identity; let targetuserid=this.props.data&&this.props.data.id; // console.log(is_current) // console.log(current_user) // console.log(current_user.is_teacher) // console.log(current_user.admin) const menu = ( this.updatedlist("updated_at")}> 最近更新 this.updatedlist("name")}> 题目名称 {types==="publicly"?this.updatedlist("contributor")}> 贡献者 :""} ); // console.log(this.props) return(
{/*提示*/} {Modalstype&&Modalstype===true?:""} {/*发送至弹窗*/} { visible&&visible===true? this.updataslist()} topicscancelmodel={()=>this.topicscancelmodel()} />:"" }
{types==="publicly"?
我的题库
公共题库
:
我的题库
公共题库
} {isshowprofes===false?
{categorylist.map((item,key)=>{ return( this.searchCategory(item.type)}>{item.val} ) })}
{data&&data.count===undefined?"":data&&data.count===0?"":
  • this.searchCourselistid(undefined)}>全部
  • {data===undefined?"":data.course_list===undefined||data.course_list.length===0?"":data.course_list.map((item,key)=>{ return(
  • this.searchCourselistid(item.id)}>{item.name}
  • ) })}
    }
    :

    通过职业认证的教师才能访问公共题库

    }
    {isshowprofes===false?data&&data.count===undefined?"":data&&data.count===0?"":

    {data&&data.count===undefined?0:data&&data.count} 已选择 {checkBoxValues.length} 个 (不支持跨页勾选)

    {sort_by==="updated_at"?'最近更新':sort_by==="name"?'题目名称':sort_by==="contributor"?"贡献者":""} this.updatedlist(sort_by)}> {user_type!="学生"?this.sendTopics()}>发送:""} {types==="personal"?((is_current && current_user && current_user.is_teacher ) || current_user && current_user.admin) &&this.deletecheckBoxValues()}>删除:""}

    :""} {isshowprofes===true?"":data===undefined?:data.question_banks===undefined||data.question_banks.length===0?: {data.question_banks.map((item,key)=>{ return(
    {user_type!="学生"?:""} 55?item.name:""} className="ml10 fl mt3 font-16 color-dark maxwidth900" href={ category==="normal"?`/banks/normal/${item.id}/${types}?tab=0`: category==="group"?`/banks/group/${item.id}/${types}?tab=0`: category==="poll"?`/banks/poll/${item.id}/${types}`: category==="exercise"?`/banks/exercise/${item.id}/${types}`: category==="gtask"?`/banks/gtask/${item.id}/${types}?tab=0`: category==="gtopic"?`/banks/gtopic/${item.id}/${types}?tab=0`:"" } > {item.name} {item.is_public===true?types==="publicly"?"":公开:""}

    {types==="publicly"?{item.creator_name}:""} {item.quotes_count} 次引用 {item.solve_count} 次答题 {moment(item.updated_at).fromNow()} {item.course_list_name===null?"":

    {item.course_list_name}
    }

    {types==="personal"?((is_current && current_user && current_user.is_teacher ) || current_user && current_user.admin) &&编辑 :""} {types==="personal"&&item.is_public===false?((is_current && current_user && current_user.is_teacher ) || current_user && current_user.admin) &&this.openTopics(item.id)}>设为公开:""}
    )})}
    } { isshowprofes===true?"":data&&data.count >15 &&
    }
    ) } } export default InfosTopics;