@ -1,5 +1,5 @@
import React , { Component } from "react" ;
import { Modal , Checkbox , Select , Input , Upload , Button , Icon , message , DatePicker , Tooltip } from "antd" ;
import { Modal , Checkbox , Select , Input , Upload , Button , Icon , message , DatePicker , Tooltip ,Radio } from "antd" ;
import axios from 'axios' ;
import { getUrl , handleDateString , appendFileSizeToUploadFileAll } from 'educoder' ;
import locale from 'antd/lib/date-picker/locale/zh_CN' ;
@ -36,9 +36,10 @@ class Selectsetting extends Component{
course _groups : undefined ,
attachment _histories : undefined ,
datatime : undefined ,
unified _setting : true ,
fileList : [ ] ,
fileListtype : false
fileListtype : false ,
is _public : false ,
Radiovaluetype : false
}
}
@ -54,53 +55,13 @@ class Selectsetting extends Component{
} )
. then ( ( response ) => {
if ( response . status === 200 ) {
let newcourse _groups = [ ] ;
let list = response . data . course _groups ;
// let list=[
// {
// "course_group_id": 820,
// "course_group_name": "示例A班",
// "course_group_publish_time": "2019-04-18T17:00:00.000+08:00"
// },
// {
// "course_group_id": 821,
// "course_group_name": "示例B班",
// "course_group_publish_time": "2019-04-19T19:00:00.000+08:00"
// },
// {
// "course_group_id": 822,
// "course_group_name": "示例C班",
// "course_group_publish_time": "2019-04-10T19:00:00.000+08:00"
// }
// ]
if ( list . length != 0 ) {
list . forEach ( ( item , key ) => {
newcourse _groups . push ( {
course _group _id : item . course _group _id ,
course _group _name : item . course _group _id ,
publish _time : moment ( item . course _group _publish _time ) . format ( dateFormat )
} )
} )
} else {
newcourse _groups . push ( {
course _group _id : undefined ,
course _group _name : undefined ,
publish _time : ""
} )
}
this . setState ( {
datalist : response . data ,
description : response . data . description ,
is _public : response . data . is _public ,
unified _setting : response . data . unified _setting ,
datatime : response . data . publish _time ,
// is_public:response.data.course_groups,
Radiovalue : response . data . delay _publish == false ? 0 : 1 ,
//attachment_histories:response.data.attachment_histories
course _groups : newcourse _groups
} )
}
@ -110,23 +71,6 @@ class Selectsetting extends Component{
} ) ;
let coursesId = this . props . match . params . coursesId ;
if ( this . props . isAdmin ( ) ) {
let url = ` /courses/ ${ coursesId } /all_course_groups.json `
axios . get ( url , {
} )
. then ( ( response ) => {
this . setState ( {
course _groupss : response . data . course _groups ,
} )
} )
. catch ( function ( error ) {
console . log ( error ) ;
} ) ;
}
}
@ -145,21 +89,6 @@ class Selectsetting extends Component{
this . getalldata ( )
}
}
onChangepublics = ( e ) => {
console . log ( e . target . checked )
this . setState ( {
is _public : e . target . checked
} )
}
onChangesettings = ( e ) => {
console . log ( e . target . checked )
this . setState ( {
unified _setting : e . target . checked
} )
}
settextarea = ( e ) => {
@ -180,13 +109,26 @@ class Selectsetting extends Component{
}
savecouseShixunModal = ( ) => {
let { fileList , is _public , unified_setting , description, datatime , course_groups } = this . state ;
let { fileList , is _public , description, datatime , Radiovalue } = this . state ;
let newfileList = [ ] ;
for ( var list of fileList ) {
newfileList . push ( list . response . id )
}
if ( this . state . Radiovalue === 1 ) {
if ( datatime === undefined || datatime === null || datatime === "" ) {
this . setState ( {
Radiovaluetype : true
} )
return
} else {
this . setState ( {
Radiovaluetype : false
} )
}
}
if ( description === undefined || description === null ) {
} else if ( description . length > 100 ) {
@ -196,29 +138,6 @@ class Selectsetting extends Component{
return
}
// course_groups.forEach((item,key)=>{
// if(item.course_group_id===undefined||item.publish_time===undefined){
// this.setState({
// course_group_publish_timestype:true
// })
// return
// }
// })
// if(unified_setting===false){
//
// course_groups.forEach((item,key)=>{
// if(item.course_group_id===undefined){
// this.setState({
// course_group_idtypes:true
// })
// return
// }
// })
//
// }
let coursesId = this . props . match . params . coursesId ;
let attachmentId = this . props . attachmentId ;
let url = "/files/" + this . props . discussMessageid + ".json" ;
@ -228,12 +147,10 @@ class Selectsetting extends Component{
new _attachment _id : newfileList . length === 0 ? undefined : newfileList ,
course _second _category _id : this . props . coursesidtype === undefined || this . props . coursesidtype === "node" ? 0 : attachmentId ,
is _public : is _public ,
is _unified _setting : unified _setting ,
publish _time : unified _setting === true ? datatime === undefined ? moment ( new Date ( ) ) . format ( 'YYYY-MM-DD HH' ) : datatime : undefined ,
publish _time : Radiovalue === 0 ? undefined : datatime === undefined ? moment ( new Date ( ) , dateFormat ) : datatime ,
description : description ,
course_group _publish _times : unified _setting === false ? course _groups : undefined
delay_publish : Radiovalue
} ) . then ( ( result ) => {
if ( result . data . status === 0 ) {
this . props . setupdate ( attachmentId )
this . props . showNotification ( "设置资源成功" ) ;
@ -244,7 +161,6 @@ class Selectsetting extends Component{
}
onChangeTimepublish = ( date , dateString ) => {
// console.log('startValue', dateString);
this . setState ( {
datatime : handleDateString ( dateString ) ,
} )
@ -268,31 +184,6 @@ class Selectsetting extends Component{
}
}
// onAttachmentRemove = (file) => {
// // confirm({
// // title: '确定要删除这个附件吗?',
// // okText: '确定',
// // cancelText: '取消',
// // // content: 'Some descriptions',
// // onOk: () => {
// // this.deleteAttachment(file)
// // },
// // onCancel() {
// // console.log('Cancel');
// // },
// // });
// // return false;
//
// // this.setState({
// // Modalstype:true,
// // Modalstopval:'确定要删除这个附件吗?',
// // ModalSave: ()=>this.deleteAttachment(file),
// // ModalCancel:this.cancelAttachment
// // })
// // return false;
//
// this.deleteAttachment(file);
// }
onAttachmentRemove = ( file ) => {
@ -309,14 +200,7 @@ class Selectsetting extends Component{
fileListtype : false ,
fileList : [ ]
} )
// this.setState((state) => {
// const index = state.fileList.indexOf(file);
// const newFileList = state.fileList.slice();
// newFileList.splice(index, 1);
// return {
// fileList: newFileList,
// };
// });
}
}
} )
@ -332,63 +216,28 @@ class Selectsetting extends Component{
fileList : [ ]
} )
}
// const url = `/attachments/${file.response ? file.response.id : file.uid}.json`
}
onChangeTimepublishs = ( date , dateString , key ) => {
let { course _groups } = this . state ;
let newgroup _publish = course _groups ;
for ( var i = 0 ; i < newgroup _publish . length ; i ++ ) {
if ( i === parseInt ( key ) ) {
newgroup _publish [ i ] . publish _time = handleDateString ( dateString ) ;
}
}
onChangepublic = ( e ) => {
this . setState ( {
course _groups : newgroup _publish ,
} )
}
selectassigngroups = ( e , index , key ) => {
let { course _groups } = this . state ;
let newgroup _publish = course _groups ;
for ( var i = 0 ; i < newgroup _publish . length ; i ++ ) {
if ( i === parseInt ( key ) ) {
newgroup _publish [ i ] . course _group _id = index . props . value ;
}
}
this . setState ( {
course _groups : newgroup _publish ,
is _public : e . target . checked
} )
}
deletegrouppublish = ( key ) => {
let newlist = this . state . course _groups ;
newlist . splice ( key , 1 ) ;
RadioonChange = ( e ) => {
if ( e . target . value === 0 ) {
this . setState ( {
course _groups : newlist
datatime : undefined
} )
}
addgrouppublish = ( ) => {
let newlist = this . state . course _groups ;
newlist . push ( {
course _group _id : undefined ,
publish _time : ""
// moment(new Date()).format('YYYY-MM-DD HH:mm')
} )
this . setState ( {
course_groups : newlist
} )
Radiovalue : e . target . value ,
} ) ;
}
render ( ) {
let { is_public , unified _setting , course _groups , datatime, description , datalist , course _group _publish _timestype } = this . state ;
let { datatime , description , datalist } = this . state ;
const uploadProps = {
width : 600 ,
// https://github.com/ant-design/ant-design/issues/15505
// showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。
// showUploadList: false,
action : ` ${ getUrl ( ) } /api/attachments.json ` ,
onChange : this . handleChange ,
onRemove : this . onAttachmentRemove ,
@ -401,9 +250,13 @@ class Selectsetting extends Component{
return isLt150M ;
} ,
} ;
const radioStyle = {
display : 'block' ,
height : '30px' ,
lineHeight : '30px' ,
} ;
// console.log(this.props.has_course_groups)
console . log ( this . state . Radiovalue )
return (
< div >
< style >
@ -461,9 +314,9 @@ class Selectsetting extends Component{
. fontlefts { text - align : left ; text - align : center ; }
` }</style>
< ul className = "clearfix greybackHead edu-txt-center" >
< li className = "fl paddingleft22 fontlefts" style = { { width : ' 22 0px'} } > 资源名称 < / l i >
< li className = "fl paddingleft22 fontlefts" style = { { width : ' 33 0px'} } > 资源名称 < / l i >
< li className = "fl edu-txt-left" style = { { width : '80px' } } > 下载 < / l i >
< li className = "fl" style = { { width : '100px' } } > 引用 < / l i >
{ /*<li className="fl" style={{width:'100px'}}>引用</li>*/ }
< li className = "fl" style = { { width : '130px' } } > 版本号 < / l i >
< / u l >
@ -490,7 +343,7 @@ class Selectsetting extends Component{
` }</style>
< div className = "pl20 pr20 settingbox" >
< div className = "clearfix edu-txt-center lineh-40 bor-bottom-greyE" >
< li className = "fl" style = { { width : ' 241 px'} } >
< li className = "fl" style = { { width : ' 350 px'} } >
< span className = { "isabox" } title = { datalist && datalist . title } > { datalist && datalist . title } < / s p a n >
{ datalist && datalist . attachment _histories . length === 0 ? "" : < span className = { "newcolor-orange fl" } > 当前版本 < / s p a n > }
< / l i >
@ -505,13 +358,13 @@ class Selectsetting extends Component{
{ datalist && datalist . attachment _histories . map ( ( item , key ) => {
return (
< div className = "clearfix edu-txt-center lineh-40 bor-bottom-greyE" key = { key } >
< li className = "fl" style = { { width : ' 241 px'} } >
< li className = "fl" style = { { width : ' 350 px'} } >
< span className = { "isabox" } title = { item . title } > { item . title } < / s p a n >
{ /*<span className={"newcolor-orange fl"}>当前版本</span>*/ }
< / l i >
< li className = "fl edu-txt-left task-hide paddingl5 "
style = { { width : '76px' } } > { item . downloads _count } < / l i >
< li className = "fl paddingl10 " style = { { width : '100px' } } > { item . quotes } < / l i >
{ /*<li className="fl paddingl10 " style={{width: '100px'}}> {item.quotes} </li>*/ }
< li className = "fl paddingl10 datastyle" >
{ moment ( item . created _on ) . format ( 'YYYY-MM-DD HH:mm' ) === "Invalid date" ? "" : moment ( item . created _on ) . format ( 'YYYY-MM-DD HH:mm' ) }
< / l i >
@ -607,61 +460,15 @@ class Selectsetting extends Component{
< / U p l o a d >
< / p >
{ /*<style>*/ }
{ /*{*/ }
{ /*`*/ }
{ /*.maxwidth400{*/ }
{ /*max-width: 400px;*/ }
{ /*overflow: hidden;*/ }
{ /*text-overflow: ellipsis;*/ }
{ /*white-space: nowrap;*/ }
{ /*}*/ }
{ /*`*/ }
{ /*}*/ }
{ /*</style>*/ }
{ /*{this.state.fileList.length===0?"":this.state.fileList.map((item,key)=>{*/ }
{ /*return(*/ }
{ /*<p className="color-grey mt10" key={key} >*/ }
{ /*<a className="color-grey fl">*/ }
{ /*<i className="font-14 color-green iconfont icon-fujian mr8" aria-hidden="true"></i>*/ }
{ /*</a>*/ }
{ /*<span className="mr12 color9B9B maxwidth400 fl" length="58">*/ }
{ /*{item.name}*/ }
{ /*</span>*/ }
{ /*<span className="color656565 mt2 color-grey-6 font-12 mr8">*/ }
{ /*{item.response===undefined?"":isNaN(bytesToSize(item.filesize))?"123":bytesToSize(item.filesize)}*/ }
{ /*</span>*/ }
{ /*<i className="font-14 iconfont icon-guanbi "*/ }
{ /*id={item.response===undefined?"":item.response.id}*/ }
{ /*aria-hidden="true" onClick={()=>this.onAttachmentRemove(item.response===undefined?"":item.response.id&&item.response.id)}></i>*/ }
{ /*</p>*/ }
{ /*)*/ }
{ /*})}*/ }
{ this . state . newfileListtypes === true ? < p className = { "color-red" } > 请先上传资源 < / p > : " " }
< p className = { this . state . fileListtype === true ? "mt15 ": " "} >
< p className = { this . state . fileListtype === true ? "mt15 selecboxfilas" : "selecboxfilas" } >
< style > { `
. ant- checkbox - wrapper {
. selecboxfilas . ant - checkbox - wrapper {
margin - left : 0 px ! important ;
margin - top : 10 px ;
}
` }</style>
{ /*<div className={this.state.fileListtype===true?"mt30":""}>*/ }
{ /*<Checkbox*/ }
{ /*checked={is_public}*/ }
{ /*onChange={this.onChangepublics}>*/ }
{ /*<span className={"font-14"}>勾选后所有用户可见,否则仅课堂成员可见</span>*/ }
{ /*</Checkbox>*/ }
{ /*</div>*/ }
{ /*{this.props.has_course_groups&&this.props.has_course_groups===true?:""}*/ }
{ this . state . course _groupss && this . state . course _groupss . length > 0 ? < Checkbox
checked = { unified _setting }
onChange = { this . onChangesettings } >
< span > 统一设置 < / s p a n > < s p a n c l a s s N a m e = { " f o n t - 1 4 c o l o r - g r e y - 9 " } > ( 选 中 则 所 有 分 班 使 用 相 同 的 发 布 设 置 , 否 则 各 个 单 独 设 置 ) < / s p a n >
< / C h e c k b o x > : " " }
< style >
{ `
. Selectleft20 {
@ -675,53 +482,11 @@ class Selectsetting extends Component{
}
` }
< / s t y l e >
{ /*this.props.has_course_groups&&this.props.has_course_groups===true?:""*/ }
< div className = { "resourcebox" } >
{ unified _setting === false ?
this . state . course _groups && this . state . course _groups . map ( ( item , key ) => {
return (
< div className = { "mt10 " } key = { key } >
< Select placeholder = "请选择分班名称"
value = { item . course _group _id }
style = { { width : 200 } }
onChange = { ( e , index ) => this . selectassigngroups ( e , index , key ) }
>
{ this . state . course _groupss && this . state . course _groupss . map ( ( item , key ) => {
return (
< Option value = { item . id } key = { key } > { item . name } < / O p t i o n >
)
} ) }
< / S e l e c t >
< DatePicker
showToday = { false }
dropdownClassName = "hideDisable"
showTime = { { format : 'HH:mm' } }
format = "YYYY-MM-DD HH:mm"
locale = { locale }
placeholder = "请选择发布时间"
id = { "startimes" }
className = { "Selectleft20" }
width = { "200px" }
value = { item . publish _time === undefined || item . publish _time === "" ? "" : item . publish _time === null ? "" : moment ( item . publish _time , dateFormat ) }
onChange = { ( e , index ) => this . onChangeTimepublishs ( e , index , key ) }
// onChange={ this.onChangeTimepublish }
disabledTime = { disabledDateTime }
disabledDate = { disabledDate }
/ >
{ key != 0 ? < i className = "iconfont icon-shanchu color-grey-c font-14 font-n ml20" onClick = { ( ) => this . deletegrouppublish ( key ) } > < / i > : " " }
{ key === course _groups . length - 1 ? < i className = "iconfont icon-tianjiafangda color-green ml15" onClick = { this . addgrouppublish } > < / i > : " " }
< / d i v >
)
} ) : "" }
< / d i v >
{ this . props . course _is _public === true ? < div >
< span className = { "color-ooo" } > 公开 : < / s p a n > < C h e c k b o x c h e c k e d = { t h i s . s t a t e . i s _ p u b l i c } o n C h a n g e = { ( e ) = > t h i s . o n C h a n g e p u b l i c ( e ) } >
< span className = { "font-14 color-ooo" } > 选中 , 所有用户可见 , 否则课堂成员可见 < / s p a n >
< / C h e c k b o x >
< / d i v > : " " }
< / p >
< style >
{ `
@ -730,10 +495,17 @@ class Selectsetting extends Component{
}
` }
< / s t y l e >
{ unified _setting === true ?
< p className = { "mt10" } >
< span >
< div className = { this . props . course _is _public === true ? "mt10" : "" } >
< span className = { "color-ooo fl mt6" } > 发布设置 : < / s p a n >
< Radio . Group onChange = { ( e ) => this . RadioonChange ( e ) } value = { this . state . Radiovalue } style = { { 'width' : '460px' } } >
< Radio style = { radioStyle } value = { 0 } >
立即发布
< / R a d i o >
< Radio style = { radioStyle } value = { 1 } className = { "fl" } >
< span className = { "mr5" } > 延迟发布 < / s p a n >
< DatePicker
showToday = { false }
dropdownClassName = "hideDisable"
showTime = { { format : 'HH:mm' } }
@ -746,12 +518,13 @@ class Selectsetting extends Component{
onChange = { this . onChangeTimepublish }
disabledTime = { disabledDateTime }
disabledDate = { disabledDate }
disabled = { this . state . Radiovalue === 1 ? false : true }
/ >
< / s p a n >
< / p > : " " }
{ /*{this.state.course_group_idtypes===true?<p className={"color-red"}>请选择分班</p>:""}*/ }
< / R a d i o >
< span className = { "fl mt5 color-grey-c" } > ( 按照设置的时间定时发布 ) < / s p a n >
< / R a d i o . G r o u p >
< / d i v >
{ /*{course_group_publish_timestype===true?<p className={"color-red mt10"}>请填写完整</p>:""}*/ }
< textarea placeholder = "请输入资源描述, 最大限制100个字符" className = { "mt10" } value = { description } onInput = { this . settextarea } style = { {
width : '100%' ,
@ -760,6 +533,7 @@ class Selectsetting extends Component{
padding : '10px'
} } > < / t e x t a r e a >
{ this . state . descriptiontypes === true ? < p className = { "color-red" } > 描述不能超过最大限制 : 100 个字符 < / p > : " " }
{ this . state . Radiovaluetype === true ? < p className = { "color-red" } > 发布时间不能为空 < / p > : " " }
< / d i v >
< div className = "mt20 marginauto clearfix edu-txt-center" >