From 8fc200a1cea6574c60caf8a6f9e0297b97112ec0 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 28 Aug 2019 09:13:11 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E5=8A=A0=E5=AE=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/courses/busyWork/CommonWorkPost.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/react/src/modules/courses/busyWork/CommonWorkPost.js b/public/react/src/modules/courses/busyWork/CommonWorkPost.js index 9de66ee5f..1859d6b70 100644 --- a/public/react/src/modules/courses/busyWork/CommonWorkPost.js +++ b/public/react/src/modules/courses/busyWork/CommonWorkPost.js @@ -740,7 +740,7 @@ render(){
9 ? item.group_name : ''} >{item.group_name}
-
12 ? item.student_id : ''} >{item.student_id}
{item.commit_status===true?已提交 :""}
@@ -784,7 +784,7 @@ render(){
9 ? item.group_name : ''} >{item.group_name}
-
12 ? item.student_id : ''} >{item.student_id}
{item.user_id != this.props.current_user.user_id ? From 046a1e1551aaa71cf22d99251525760feebf967b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 28 Aug 2019 09:20:24 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E4=BA=A4=E4=BA=BA=E4=B8=8D=E8=83=BD=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 10 ++++++---- app/models/student_work.rb | 1 + app/views/student_works/show.json.jbuilder | 3 ++- ...190828011222_add_update_user_id_to_student_works.rb | 6 ++++++ 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20190828011222_add_update_user_id_to_student_works.rb diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index b4677f4e3..f6872e533 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -92,6 +92,7 @@ class StudentWorksController < ApplicationController student_work.commit_time = Time.now student_work.update_time = Time.now student_work.commit_user_id = current_user.id + student_work.update_user_id = current_user.id student_work.group_id = @homework.homework_type == "group" ? @homework.max_group_id : 0 #提交作品时,计算是否迟交 @@ -112,7 +113,7 @@ class StudentWorksController < ApplicationController homework_common_id: @homework.id, project_id: student_work.project_id, late_penalty: student_work.late_penalty, work_status: student_work.work_status, commit_time: Time.now, update_time: Time.now, group_id: student_work.group_id, - commit_user_id: current_user.id) + commit_user_id: current_user.id, update_user_id: current_user.id) stu_work.save! student_work.attachments.each do |attachment| att = attachment.copy @@ -156,6 +157,7 @@ class StudentWorksController < ApplicationController begin @work.description = params[:description] @work.update_time = Time.now + @work.update_user_id = current_user.id # @work.commit_user_id = current_user.id if @work.save! Attachment.associate_container(params[:attachment_ids], @work.id, @work.class) @@ -172,7 +174,7 @@ class StudentWorksController < ApplicationController # 原成员更新描述、更新时间以及附件 @homework.student_works.where(group_id: @work.group_id, user_id: (work_user_ids & params_user_ids)).each do |work| # work.update_attributes(update_time: Time.now, description: @work.description, commit_user_id: current_user.id) - work.update_attributes(update_time: Time.now, description: @work.description) + work.update_attributes(update_time: Time.now, description: @work.description, update_user_id: current_user.id) work.attachments.destroy_all @work.attachments.each do |attachment| att = attachment.copy @@ -192,7 +194,7 @@ class StudentWorksController < ApplicationController @homework.student_works.where(group_id: @work.group_id, user_id: delete_user_ids). update_all(work_status: 0, description: nil, late_penalty: 0, commit_time: nil, update_time: nil, final_score: nil, teacher_score: nil, student_score: nil, teaching_asistant_score: nil, - work_score: nil, project_id: 0, group_id: 0, commit_user_id: nil) + work_score: nil, project_id: 0, group_id: 0, commit_user_id: nil, update_user_id: nil) # 新增加的成员 (params_user_ids - work_user_ids).each do |user_id| @@ -200,7 +202,7 @@ class StudentWorksController < ApplicationController stu_work.update_attributes(user_id: user_id, description: @work.description, homework_common_id: @homework.id, project_id: @work.project_id, late_penalty: @work.late_penalty, work_status: @work.work_status, commit_time: Time.now, update_time: Time.now, - group_id: @work.group_id, commit_user_id: @work.commit_user_id) + group_id: @work.group_id, commit_user_id: @work.commit_user_id, update_user_id: current_user.id) @work.attachments.each do |attachment| att = attachment.copy att.author_id = attachment.author_id diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 074068273..168cfeb68 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -2,6 +2,7 @@ class StudentWork < ApplicationRecord #学生提交作品表 #work_status :0 未提交 1 已提交 2 迟交 belongs_to :user belongs_to :commit_user, class_name: 'User', foreign_key: :commit_user_id, optional: true + belongs_to :update_user, class_name: 'User', foreign_key: :update_user_id, optional: true belongs_to :homework_common belongs_to :myshixun, optional: true has_many :student_works_evaluation_distributions, dependent: :destroy diff --git a/app/views/student_works/show.json.jbuilder b/app/views/student_works/show.json.jbuilder index 5756ac9cb..192e4d8ec 100644 --- a/app/views/student_works/show.json.jbuilder +++ b/app/views/student_works/show.json.jbuilder @@ -5,7 +5,8 @@ json.is_evaluation @is_evaluation json.author_name @is_evaluation ? "匿名" : @work.user.real_name json.is_leader_work @work.user_id == @work.commit_user_id if @homework.homework_type == "group" json.is_author @is_author -json.update_user_name @is_evaluation ? "匿名" : @work.commit_user.try(:real_name) +json.commit_user_name @is_evaluation ? "匿名" : @work.commit_user.try(:real_name) +json.update_user_name @is_evaluation ? "匿名" : @work.update_user.try(:real_name) json.update_atta @homework.late_duration && @is_author diff --git a/db/migrate/20190828011222_add_update_user_id_to_student_works.rb b/db/migrate/20190828011222_add_update_user_id_to_student_works.rb new file mode 100644 index 000000000..c8e007998 --- /dev/null +++ b/db/migrate/20190828011222_add_update_user_id_to_student_works.rb @@ -0,0 +1,6 @@ +class AddUpdateUserIdToStudentWorks < ActiveRecord::Migration[5.2] + def change + add_column :student_works, :update_user_id, :integer + StudentWork.update_all("update_user_id = commit_user_id") + end +end From 904c017177d33c5bb1771bb7c5b6cad5953deaac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=9E=97?= <904079904@qq.com> Date: Wed, 28 Aug 2019 09:28:38 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/forums/MemoNew.js | 1673 ++++++++++---------- 1 file changed, 838 insertions(+), 835 deletions(-) diff --git a/public/react/src/modules/forums/MemoNew.js b/public/react/src/modules/forums/MemoNew.js index 11a3d0ca2..00a39b184 100644 --- a/public/react/src/modules/forums/MemoNew.js +++ b/public/react/src/modules/forums/MemoNew.js @@ -1,835 +1,838 @@ -import React, { Component } from 'react'; -import { Redirect } from 'react-router'; - -import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom"; - -import PropTypes from 'prop-types'; - -import classNames from 'classnames' - -import { Select,Icon, Upload, Button } from 'antd'; - -// demo http://react-component.github.io/upload/examples/simple.html -// import Upload from 'rc-upload'; - -import axios from 'axios' - -import 'antd/lib/select/style/index.css' -import TPMMDEditor from '../tpm/challengesnew/TPMMDEditor' - -import { getUrl, getUploadActionUrl, appendFileSizeToUploadFileAll, appendFileSizeToUploadFile } from 'educoder' -const Option = Select.Option; -const $ = window.$; - -let origin = getUrl(); -let path = getUrl("/editormd/lib/") - -// load -if (!window.postUpMsg) { - $.getScript( - `${origin}/javascripts/attachments.js`, - (data, textStatus, jqxhr) => { - - }); -} - -// editorMD to create -/** - * - * @param id 渲染DOM的id - * @param width 宽度 - * @param high 高度 - * @param placeholder - * @param imageUrl 上传图片的url - * @returns {*} 返回一个editorMD实例 - */ -function create_editorMD(id, width, high, placeholder, imageUrl, callback){ - var editorName = window.editormd(id, { - width : width, - height : high, - syncScrolling : "single", - //你的lib目录的路径,我这边用JSP做测试的 - path : path , // "/editormd/lib/" - tex : true, - tocm : true, - emoji : true, - taskList : true, - codeFold : true, - searchReplace : true, - htmlDecode : "style,script,iframe", - sequenceDiagram : true, - autoFocus: false, - toolbarIcons : function() { - // Or return editormd.toolbarModes[name]; // full, simple, mini - // Using "||" set icons align right. - return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table" - // , '|', "underlineIcon" - , "|", "watch", "clear" ] - }, - toolbarCustomIcons : { - testIcon : "
", - testIcon1 : "
", - - // underlineIcon例子 - // underlineIcon : "
" - }, - //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 - saveHTMLToTextarea : true, - // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 - dialogMaskOpacity : 0.6, - placeholder: placeholder, - imageUpload : true, - imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], - imageUploadURL : imageUrl,//url - onload: function(){ - - // underlineIcon例子 - // $('#'+ id + " .underline").bind('click', function() { - // var __Cursor = editorName.cm.getDoc().getCursor(); - // editorName.appendMarkdown('__') - // editorName.cm.setCursor(__Cursor.line, __Cursor.ch + 2); - // }); - - // this.previewing(); - $("#"+ id +" [type=\"latex\"]").bind("click", function(){ - editorName.cm.replaceSelection("```latex"); - editorName.cm.replaceSelection("\n"); - editorName.cm.replaceSelection("\n"); - editorName.cm.replaceSelection("```"); - var __Cursor = editorName.cm.getDoc().getCursor(); - editorName.cm.setCursor(__Cursor.line-1, 0); - }); - - $("#"+ id +" [type=\"inline\"]").bind("click", function(){ - editorName.cm.replaceSelection("$$$$"); - var __Cursor = editorName.cm.getDoc().getCursor(); - editorName.cm.setCursor(__Cursor.line, __Cursor.ch-2); - editorName.cm.focus(); - }); - $("[type=\"inline\"]").attr("title", "行内公式"); - $("[type=\"latex\"]").attr("title", "多行公式"); - - window.md_elocalStorage(editorName, `memoNew_${id}`, "memoNew"); - - callback && callback() - } - }); - return editorName; -} - -const typeNameMap = { - '技术分享': 5, - '操作指南': 3, -} -export const typeNameMap2 = { - 5: '技术分享', - 3: '操作指南', -} -const defaultType = '技术分享' - -const languageSeparator = '/' -class MemoNew extends Component { - constructor(props) { - super(props) - this.mdRef = React.createRef(); - - // https://testbdweb.trustie.net/uploads.js?attachment_id=1&filename=jqui.js - // https://ant.design/components/upload-cn/ - this.uploaderProps = { - action: '/uploads.js', - data: { attachment_id: 1 }, // , filename: 2 - headers: { - Authorization: 'authorization-text', - }, - multiple: true, - beforeUpload(file) { - // console.log('beforeUpload', file.name); - }, - onStart: (file) => { - console.log('onStart', file.name); - // this.refs.inner.abort(file); - }, - onSuccess(file) { - console.log('onSuccess', file); - }, - onProgress(step, file) { - console.log('onProgress', Math.round(step.percent), file.name); - }, - onError(err) { - console.log('onError', err); - }, - }; - - this.state = { - memoSubject: '', - memoContent: '', - memoType: typeNameMap[defaultType], - memoRepertoire: '', - memoLanguage: [], - - repertoires: [], - currentSelectRepertoiresIndex: -1, - repertoiresTagMap: {}, - - fileList: [] - } - } - onCommit() { - const { memoSubject, memoRepertoire, memoLanguage, currentMemoId, memoType } = this.state; - const { showNotification } = this.props; - if (!memoSubject) { - showNotification('请先输入话题名称') - return - } - let mdVal; - try { - mdVal = this.mdRef.current.getValue() - - } catch (e) { - showNotification('编辑器还未加载完毕,请稍后') - return - } - - if (!mdVal) { - showNotification('请先输入话题内容') - return - } - // !memoRepertoire || - if (memoType === 5 && ( !memoLanguage || memoLanguage.length === 0 )) { - showNotification('请先选择技术标签') - return - } - /* - - - - http://localhost:3000/attachments/download/185790/Git-2.17.1.2-32-bit.exe - https://www.educoder.net/attachments/205112.js?attachment_id=1 - */ - // collect attachments - const $ = window.$; - const attachmentsMap = {}; - const attachmentIds = this.state.fileList.map(item => { - return item.response ? item.response.id : item.id - }) - // $('#attachments_fields .attachment').each(( index, item ) => { - // const filename = $(item).find('.upload_filename').val(); - // // $($('#attachments_fields .attachment')[0]).find('input:nth-child(6)').val() - // const token = $(item).find('input:nth-child(7)').val() - // const attachment_id = parseInt($(item).children().last().val()) - // attachmentsMap[index] = { - // filename, - // token, - // attachment_id - // } - // attachmentIds.push(attachment_id) - // }) - - - if (currentMemoId) { - this.updateMemo(attachmentIds) - } else { - this.newMemo(attachmentIds) - } - } - onCancel() { - const { currentMemoId, memoType } = this.state; - if (currentMemoId) { // 编辑 - this.props.history.push(`/forums/${currentMemoId}`) - } else { // 新建 - this.props.history.push(`/forums`) - } - // debugger;this.props.history.goBack() - } - updateMemo(attachmentsMap) { - const { memoSubject, memoRepertoire, memoLanguage, memoType, currentMemoId, content } = this.state; - const mdVal = this.mdRef.current.getValue() - console.log('isContentEdit: ', mdVal === content); - const newMemoUrl = `/memos/${currentMemoId}.json` - axios.put(newMemoUrl, { - content_changed: this.contentChanged, - tags: memoLanguage, - // memo:{ - subject: memoSubject , - content: mdVal, - forum_id: memoType, - repertoire_name: memoRepertoire, - // language: memoLanguage.join(languageSeparator), - // - // }, - attachment_ids: attachmentsMap - }, { - // withCredentials: true, - }) - .then((response) => { - const { status, message, memo_id } = response.data; - if (status === 0) { - window.$("html,body").animate({"scrollTop":0}) - this.props.history.push(`/forums/${currentMemoId}`) - } else { - this.props.showNotification(message) - } - }).catch((error) => { - console.log(error) - }) - } - newMemo(attachmentsMap) { - const { memoSubject, memoRepertoire, memoLanguage, memoType } = this.state; - const mdVal = this.mdRef.current.getValue() - - const newMemoUrl = `/memos.json` - axios.post(newMemoUrl, { - tags: memoLanguage, - // memo:{ - subject: memoSubject , - content: mdVal, - forum_id: memoType, - // repertoire_name: memoRepertoire, - - // }, - attachment_ids: attachmentsMap - }, { - // withCredentials: true, - }) - .then((response) => { - const { status, message, memo_id } = response.data; - if (status === 0) { - window.$("html,body").animate({"scrollTop":0}) - this.props.history.push(`/forums/${memo_id}`) - } else { - this.props.showNotification(message) - } - }).catch((error) => { - console.log(error) - }) - } - componentDidMount() { - const newMemoUrl = `/memos/new.json` - axios.get(newMemoUrl,{ - // withCredentials: true, - }) - .then((response) => { - const data = response.data; - const repertoires = []; - const repertoiresTagMap = {} - if ( data.tag_list ) { - // data.tag_list.forEach((item, index)=>{ - // const tagArray = []; - // item.tag.forEach( (tag, index) => { - // tagArray.push(tag.name) - // }) - // repertoires.push(item.rep.repertoire.name) - // repertoiresTagMap[item.rep.repertoire.name] = tagArray - // }) - this.setState({ - tag_list: data.tag_list - // repertoires, - // repertoiresTagMap - }) - - // const user = response.data.current_user; - // user.tidding_count = response.data.tidding_count; - // this.props.initCommonState(user) - - // 初始化 csrf meta - const $ = window.$ - $('head').append( $('') ) - $('head').append( $(``) ) - } - }).catch((error) => { - console.log(error) - }) - - // 如果是编辑 - const { match } = this.props - const memoId = match.params.memoId; - if (memoId) { - const memoUrl = `/memos/${match.params.memoId}/edit.json`; - axios.get(memoUrl,{ - // withCredentials: true, - }) - .then((response) => { - const tag_list = response.data.tag_list - if (tag_list) { - // this.setState({...response.data}) - const { content, forum_id, id, repertoire_name, subject, - current_user, tag_list, attachments_url, memo_tags, attachments } = response.data; - this.initMD(content); - // this.onRepertoiresChange(repertoire_name) - // tag -> memo_tags - const tag = memo_tags; - let memoLanguage = [] - if (tag) { - memoLanguage = tag.map((item, index) => { - return item.id + "" - }) - } - const fileList = attachments.map(item => { - return { - id: item.id, - uid: item.id, - name: appendFileSizeToUploadFile(item), - url: item.url, - filesize: item.filesize, - status: 'done' - } - }) - this.setState({ - fileList, - currentMemoId: memoId, - memoSubject: subject, - memoType: forum_id, - memoRepertoire: repertoire_name, - memoLanguage, - attachments_url, - content - - // repertoires: [], - // currentSelectRepertoiresIndex: -1, - }, ()=> { - // 解决有时候编辑时内容不显示的问题 - setTimeout(() => { - this.mdRef.current && this.mdRef.current.setValue(content || '') - }, 2000) - - $('.upload_filename').each((index, item) => { - var width = window._textWidth($(item), '14px'); - console.log(width) - $(item).css('width', width + 20) - }) - - }) - // 加载完后滚动条滚动 - window.$("html,body").animate({"scrollTop":0}) - - this.props.initForumState({ - // current_user, - tag_list - }) - } - - }).catch((error) => { - console.log(error) - }) - } else { - this.initMD(); - } - - - - - } - initMD(initValue) { - return; - - this.contentChanged = false; - const placeholder = ""; - // amp; - // 编辑时要传memoId - // const imageUrl = `/upload_with_markdown?container_id=&container_type=Memo`; - const imageUrl = `/api/attachments.json`; - - // 创建editorMd - - const taskpass_editormd = create_editorMD("memoMD", '100%', 400, placeholder, imageUrl, () => { - setTimeout(()=>{ - taskpass_editormd.resize() - taskpass_editormd.cm && taskpass_editormd.cm.refresh() - }, 500) - - if (initValue) { - taskpass_editormd.setValue(initValue) - } - taskpass_editormd.cm.on("change", (_cm, changeObj) =>{ - console.log('....contentChanged') - this.contentChanged = true; - }) - }); - this.taskpass_editormd = taskpass_editormd; - window.taskpass_editormd = taskpass_editormd; - - } - - renderOptions(array) { - const elementArray = []; - array.forEach(( item, index ) => { - elementArray.push( - - ) - }) - return elementArray - } - onRepertoiresChange(value) { - - const index = this.state.repertoires.indexOf(value) - - this.setState({ - currentSelectRepertoiresIndex: index, - memoRepertoire: value, - memoLanguage: '' - }); - }; - - renderTag() { - const { tag_list } = this.state; - if (!tag_list || tag_list.length === 0) { - return '' - } - const result = [] - - tag_list.forEach((item, index) => { - result.push() - }) - - return result; - } - - onTagChange(value) { - if (value && value.length > 3) { - this.props.showNotification(`最多选择3个技术标签`) - - return; - } - this.setState({ - memoLanguage: value - }) - } - - onTypeChange(value) { - - this.setState({ - memoType: typeNameMap[value] - }) - } - onMemoNameChange(e) { - this.setState({ - memoSubject: e.target.value - }) - } - renderAttachment() { - const { attachments_url } = this.state; - const attachments = [] - attachments_url.forEach((item, index) => { - const ar = item.url.split('/') - const fileName = ar[ar.length - 1] - /* -

- - {fileName} - -

- */ - // ?attachment_id=2 - /* - - - - */ - attachments.push( - - - - - - {window.conver_size(item.id)} - - - -
- {/**/} - -
-
-
- - ) - }) - return attachments; - } - handleChange = (info) => { - if (info.file.status === 'uploading' || info.file.status === 'done') { - let fileList = info.fileList; - this.setState({ - fileList: appendFileSizeToUploadFileAll(fileList) - }); - } - } - onAttachmentRemove = (file) => { - this.props.confirm({ - // title: '确定要删除这个附件吗?', - content: '是否确认删除?', - - okText: '确定', - cancelText: '取消', - // content: 'Some descriptions', - onOk: () => { - this.deleteAttachment(file) - }, - onCancel() { - console.log('Cancel'); - }, - }); - return false; - } - deleteAttachment = (file) => { - // 初次上传不能直接取uid - const url = `/attachments/${file.response ? file.response.id : file.uid}.json` - axios.delete(url, { - }) - .then((response) => { - if (response.data) { - const { status } = response.data; - if (status == 0) { - console.log('--- success') - - this.setState((state) => { - const index = state.fileList.indexOf(file); - const newFileList = state.fileList.slice(); - newFileList.splice(index, 1); - return { - fileList: newFileList, - }; - }); - } - } - }) - .catch(function (error) { - console.log(error); - }); - } - render() { - const { match, history } = this.props - const { - // repertoires, repertoiresTagMap, currentSelectRepertoiresIndex, memoRepertoire, - tag_list, - memoSubject, memoType, - memoLanguage, attachments_url, fileList } = this.state; - const memoId = match.params.memoId; - - const uploadProps = { - width: 600, - fileList, - multiple: true, - // https://github.com/ant-design/ant-design/issues/15505 - // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 - // showUploadList: false, - action: `${getUploadActionUrl()}`, - onChange: this.handleChange, - onRemove: this.onAttachmentRemove, - beforeUpload: (file) => { - console.log('beforeUpload', file.name); - const isLt150M = file.size / 1024 / 1024 < 150; - if (!isLt150M) { - this.props.showNotification('文件大小必须小于150MB!'); - } - return isLt150M; - }, - }; - return ( -
-
- { memoId ? '编辑话题' : '发布话题'} - {/* - */} -
- -
-
-

话题名称

-
- * -
- this.onMemoNameChange(val)} placeholder=""> - -
-
- - 必填项 - -
-
-
-
- -
-
-

内容

-
- * -
- - - {/*
- -
*/} -

-

-
-
- - 必填项 - -
-
- - - - {/*
- - { attachments_url && !!attachments_url.length && - this.renderAttachment() - } - - - {debugger;window.addInputFiles( window.$('.file_selector')[0] ) }} - style={{'display':'none'}} type="file"> - - -
*/} - - - {/*开始上传*/} - - - (单个文件150M以内) - - - {/* 请求status 422 */} - - {/* */} - {/*
- window.$('#_file').click()} - data-tip-down="请选择文件上传"> - - 上传附件 - (单个文件50M以内) - -
*/} -
-
- {/* TODOTODO 这里重复的html代码太多,如果有其他页面有类似需求,需要封装*/} - -
-
-

话题类型

-
- * -
- -
-
- - 必填项 - -
-
-
-
- - {/* memoType === typeNameMap['技术分享'] && -
-
-

技术标签

-
- * -
- -
-
- -
- -
- - 必填项 - -
-
-
-
*/} - - { memoType === typeNameMap['技术分享'] && -
-
-

技术标签

-
- * - -
- -
- -
- - 必填项 - -
-
-
-
} - -
- {this.onCommit()}}>提交 - { this.onCancel() }} className="defalutCancelbtn fl">取消 -
- -
- ); - } -} - -export default MemoNew; +import React, { Component } from 'react'; +import { Redirect } from 'react-router'; + +import { BrowserRouter as Router, Route, Link, Switch } from "react-router-dom"; + +import PropTypes from 'prop-types'; + +import classNames from 'classnames' + +import { Select,Icon, Upload, Button } from 'antd'; + +// demo http://react-component.github.io/upload/examples/simple.html +// import Upload from 'rc-upload'; + +import axios from 'axios' + +import 'antd/lib/select/style/index.css' +import TPMMDEditor from '../tpm/challengesnew/TPMMDEditor' + +import { getUrl, getUploadActionUrl, appendFileSizeToUploadFileAll, appendFileSizeToUploadFile } from 'educoder' +const Option = Select.Option; +const $ = window.$; + +let origin = getUrl(); +let path = getUrl("/editormd/lib/") + +// load +if (!window.postUpMsg) { + $.getScript( + `${origin}/javascripts/attachments.js`, + (data, textStatus, jqxhr) => { + + }); +} + +// editorMD to create +/** + * + * @param id 渲染DOM的id + * @param width 宽度 + * @param high 高度 + * @param placeholder + * @param imageUrl 上传图片的url + * @returns {*} 返回一个editorMD实例 + */ +function create_editorMD(id, width, high, placeholder, imageUrl, callback){ + var editorName = window.editormd(id, { + width : width, + height : high, + syncScrolling : "single", + //你的lib目录的路径,我这边用JSP做测试的 + path : path , // "/editormd/lib/" + tex : true, + tocm : true, + emoji : true, + taskList : true, + codeFold : true, + searchReplace : true, + htmlDecode : "style,script,iframe", + sequenceDiagram : true, + autoFocus: false, + toolbarIcons : function() { + // Or return editormd.toolbarModes[name]; // full, simple, mini + // Using "||" set icons align right. + return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table" + // , '|', "underlineIcon" + , "|", "watch", "clear" ] + }, + toolbarCustomIcons : { + testIcon : "
", + testIcon1 : "
", + + // underlineIcon例子 + // underlineIcon : "
" + }, + //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 + saveHTMLToTextarea : true, + // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 + dialogMaskOpacity : 0.6, + placeholder: placeholder, + imageUpload : true, + imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], + imageUploadURL : imageUrl,//url + onload: function(){ + + // underlineIcon例子 + // $('#'+ id + " .underline").bind('click', function() { + // var __Cursor = editorName.cm.getDoc().getCursor(); + // editorName.appendMarkdown('__') + // editorName.cm.setCursor(__Cursor.line, __Cursor.ch + 2); + // }); + + // this.previewing(); + $("#"+ id +" [type=\"latex\"]").bind("click", function(){ + editorName.cm.replaceSelection("```latex"); + editorName.cm.replaceSelection("\n"); + editorName.cm.replaceSelection("\n"); + editorName.cm.replaceSelection("```"); + var __Cursor = editorName.cm.getDoc().getCursor(); + editorName.cm.setCursor(__Cursor.line-1, 0); + }); + + $("#"+ id +" [type=\"inline\"]").bind("click", function(){ + editorName.cm.replaceSelection("$$$$"); + var __Cursor = editorName.cm.getDoc().getCursor(); + editorName.cm.setCursor(__Cursor.line, __Cursor.ch-2); + editorName.cm.focus(); + }); + $("[type=\"inline\"]").attr("title", "行内公式"); + $("[type=\"latex\"]").attr("title", "多行公式"); + + window.md_elocalStorage(editorName, `memoNew_${id}`, "memoNew"); + + callback && callback() + } + }); + return editorName; +} + +const typeNameMap = { + '技术分享': 5, + '操作指南': 3, +} +export const typeNameMap2 = { + 5: '技术分享', + 3: '操作指南', +} +const defaultType = '技术分享' + +const languageSeparator = '/' +class MemoNew extends Component { + constructor(props) { + super(props) + this.mdRef = React.createRef(); + + // https://testbdweb.trustie.net/uploads.js?attachment_id=1&filename=jqui.js + // https://ant.design/components/upload-cn/ + this.uploaderProps = { + action: '/uploads.js', + data: { attachment_id: 1 }, // , filename: 2 + headers: { + Authorization: 'authorization-text', + }, + multiple: true, + beforeUpload(file) { + // console.log('beforeUpload', file.name); + }, + onStart: (file) => { + console.log('onStart', file.name); + // this.refs.inner.abort(file); + }, + onSuccess(file) { + console.log('onSuccess', file); + }, + onProgress(step, file) { + console.log('onProgress', Math.round(step.percent), file.name); + }, + onError(err) { + console.log('onError', err); + }, + }; + + this.state = { + memoSubject: '', + memoContent: '', + memoType: typeNameMap[defaultType], + memoRepertoire: '', + memoLanguage: [], + + repertoires: [], + currentSelectRepertoiresIndex: -1, + repertoiresTagMap: {}, + + fileList: [] + } + } + onCommit() { + const { memoSubject, memoRepertoire, memoLanguage, currentMemoId, memoType } = this.state; + const { showNotification } = this.props; + if (!memoSubject) { + showNotification('请先输入话题名称') + return + } + let mdVal; + try { + mdVal = this.mdRef.current.getValue() + + } catch (e) { + showNotification('编辑器还未加载完毕,请稍后') + return + } + + if (!mdVal) { + showNotification('请先输入话题内容') + return + } + // !memoRepertoire || + if (memoType === 5 && ( !memoLanguage || memoLanguage.length === 0 )) { + showNotification('请先选择技术标签') + return + } + /* + + + + http://localhost:3000/attachments/download/185790/Git-2.17.1.2-32-bit.exe + https://www.educoder.net/attachments/205112.js?attachment_id=1 + */ + // collect attachments + const $ = window.$; + const attachmentsMap = {}; + const attachmentIds = this.state.fileList.map(item => { + return item.response ? item.response.id : item.id + }) + // $('#attachments_fields .attachment').each(( index, item ) => { + // const filename = $(item).find('.upload_filename').val(); + // // $($('#attachments_fields .attachment')[0]).find('input:nth-child(6)').val() + // const token = $(item).find('input:nth-child(7)').val() + // const attachment_id = parseInt($(item).children().last().val()) + // attachmentsMap[index] = { + // filename, + // token, + // attachment_id + // } + // attachmentIds.push(attachment_id) + // }) + + + if (currentMemoId) { + this.updateMemo(attachmentIds) + } else { + this.newMemo(attachmentIds) + } + } + onCancel() { + const { currentMemoId, memoType } = this.state; + if (currentMemoId) { // 编辑 + this.props.history.push(`/forums/${currentMemoId}`) + } else { // 新建 + this.props.history.push(`/forums`) + } + // debugger;this.props.history.goBack() + } + updateMemo(attachmentsMap) { + const { memoSubject, memoRepertoire, memoLanguage, memoType, currentMemoId, content } = this.state; + const mdVal = this.mdRef.current.getValue() + console.log('isContentEdit: ', mdVal === content); + const newMemoUrl = `/memos/${currentMemoId}.json` + axios.put(newMemoUrl, { + content_changed: this.contentChanged, + tags: memoLanguage, + // memo:{ + subject: memoSubject , + content: mdVal, + forum_id: memoType, + repertoire_name: memoRepertoire, + // language: memoLanguage.join(languageSeparator), + // + // }, + attachment_ids: attachmentsMap + }, { + // withCredentials: true, + }) + .then((response) => { + const { status, message, memo_id } = response.data; + if (status === 0) { + window.$("html,body").animate({"scrollTop":0}) + this.props.history.push(`/forums/${currentMemoId}`) + } else { + this.props.showNotification(message) + } + }).catch((error) => { + console.log(error) + }) + } + newMemo(attachmentsMap) { + const { memoSubject, memoRepertoire, memoLanguage, memoType } = this.state; + const mdVal = this.mdRef.current.getValue() + + const newMemoUrl = `/memos.json` + axios.post(newMemoUrl, { + tags: memoLanguage, + // memo:{ + subject: memoSubject , + content: mdVal, + forum_id: memoType, + // repertoire_name: memoRepertoire, + + // }, + attachment_ids: attachmentsMap + }, { + // withCredentials: true, + }) + .then((response) => { + const { status, message, memo_id } = response.data; + if (status === 0) { + window.$("html,body").animate({"scrollTop":0}) + this.props.history.push(`/forums/${memo_id}`) + } else { + this.props.showNotification(message) + } + }).catch((error) => { + console.log(error) + }) + } + componentDidMount() { + const newMemoUrl = `/memos/new.json` + axios.get(newMemoUrl,{ + // withCredentials: true, + }) + .then((response) => { + const data = response.data; + const repertoires = []; + const repertoiresTagMap = {} + if ( data.tag_list ) { + // data.tag_list.forEach((item, index)=>{ + // const tagArray = []; + // item.tag.forEach( (tag, index) => { + // tagArray.push(tag.name) + // }) + // repertoires.push(item.rep.repertoire.name) + // repertoiresTagMap[item.rep.repertoire.name] = tagArray + // }) + this.setState({ + tag_list: data.tag_list + // repertoires, + // repertoiresTagMap + }) + + // const user = response.data.current_user; + // user.tidding_count = response.data.tidding_count; + // this.props.initCommonState(user) + + // 初始化 csrf meta + const $ = window.$ + $('head').append( $('') ) + $('head').append( $(``) ) + } + }).catch((error) => { + console.log(error) + }) + + // 如果是编辑 + const { match } = this.props + const memoId = match.params.memoId; + if (memoId) { + const memoUrl = `/memos/${match.params.memoId}/edit.json`; + axios.get(memoUrl,{ + // withCredentials: true, + }) + .then((response) => { + const tag_list = response.data.tag_list + if (tag_list) { + // this.setState({...response.data}) + const { content, forum_id, id, repertoire_name, subject, + current_user, tag_list, attachments_url, memo_tags, attachments } = response.data; + this.initMD(content); + // this.onRepertoiresChange(repertoire_name) + // tag -> memo_tags + const tag = memo_tags; + let memoLanguage = [] + if (tag) { + memoLanguage = tag.map((item, index) => { + return item.id + "" + }) + } + const fileList = attachments.map(item => { + return { + id: item.id, + uid: item.id, + name: appendFileSizeToUploadFile(item), + url: item.url, + filesize: item.filesize, + status: 'done' + } + }) + this.setState({ + fileList, + currentMemoId: memoId, + memoSubject: subject, + memoType: forum_id, + memoRepertoire: repertoire_name, + memoLanguage, + attachments_url, + content + + // repertoires: [], + // currentSelectRepertoiresIndex: -1, + }, ()=> { + // 解决有时候编辑时内容不显示的问题 + setTimeout(() => { + this.mdRef.current && this.mdRef.current.setValue(content || '') + }, 2000) + + $('.upload_filename').each((index, item) => { + var width = window._textWidth($(item), '14px'); + console.log(width) + $(item).css('width', width + 20) + }) + + }) + // 加载完后滚动条滚动 + window.$("html,body").animate({"scrollTop":0}) + + this.props.initForumState({ + // current_user, + tag_list + }) + } + + }).catch((error) => { + console.log(error) + }) + } else { + this.initMD(); + } + + + + + } + initMD(initValue) { + return; + + this.contentChanged = false; + const placeholder = ""; + // amp; + // 编辑时要传memoId + // const imageUrl = `/upload_with_markdown?container_id=&container_type=Memo`; + const imageUrl = `/api/attachments.json`; + + // 创建editorMd + + const taskpass_editormd = create_editorMD("memoMD", '100%', 400, placeholder, imageUrl, () => { + setTimeout(()=>{ + taskpass_editormd.resize() + taskpass_editormd.cm && taskpass_editormd.cm.refresh() + }, 500) + + if (initValue) { + taskpass_editormd.setValue(initValue) + } + taskpass_editormd.cm.on("change", (_cm, changeObj) =>{ + console.log('....contentChanged') + this.contentChanged = true; + }) + }); + this.taskpass_editormd = taskpass_editormd; + window.taskpass_editormd = taskpass_editormd; + + } + + renderOptions(array) { + const elementArray = []; + array.forEach(( item, index ) => { + elementArray.push( + + ) + }) + return elementArray + } + onRepertoiresChange(value) { + + const index = this.state.repertoires.indexOf(value) + + this.setState({ + currentSelectRepertoiresIndex: index, + memoRepertoire: value, + memoLanguage: '' + }); + }; + + renderTag() { + const { tag_list } = this.state; + if (!tag_list || tag_list.length === 0) { + return '' + } + const result = [] + + tag_list.forEach((item, index) => { + result.push() + }) + + return result; + } + + onTagChange(value) { + if (value && value.length > 3) { + this.props.showNotification(`最多选择3个技术标签`) + + return; + } + this.setState({ + memoLanguage: value + }) + } + + onTypeChange(value) { + + this.setState({ + memoType: typeNameMap[value] + }) + } + onMemoNameChange(e) { + this.setState({ + memoSubject: e.target.value + }) + } + renderAttachment() { + const { attachments_url } = this.state; + const attachments = [] + attachments_url.forEach((item, index) => { + const ar = item.url.split('/') + const fileName = ar[ar.length - 1] + /* +

+ + {fileName} + +

+ */ + // ?attachment_id=2 + /* + + + + */ + attachments.push( + + + + + + {window.conver_size(item.id)} + + + +
+ {/**/} + +
+
+
+ + ) + }) + return attachments; + } + handleChange = (info) => { + if (info.file.status === 'uploading' || info.file.status === 'done') { + let fileList = info.fileList; + this.setState({ + fileList: appendFileSizeToUploadFileAll(fileList) + }); + } + } + onAttachmentRemove = (file) => { + this.props.confirm({ + // title: '确定要删除这个附件吗?', + content: '是否确认删除?', + + okText: '确定', + cancelText: '取消', + // content: 'Some descriptions', + onOk: () => { + this.deleteAttachment(file) + }, + onCancel() { + console.log('Cancel'); + }, + }); + return false; + } + deleteAttachment = (file) => { + // 初次上传不能直接取uid + const url = `/attachments/${file.response ? file.response.id : file.uid}.json` + axios.delete(url, { + }) + .then((response) => { + if (response.data) { + const { status } = response.data; + if (status == 0) { + console.log('--- success') + + this.setState((state) => { + const index = state.fileList.indexOf(file); + const newFileList = state.fileList.slice(); + newFileList.splice(index, 1); + return { + fileList: newFileList, + }; + }); + } + } + }) + .catch(function (error) { + console.log(error); + }); + } + render() { + const { match, history } = this.props + const { + // repertoires, repertoiresTagMap, currentSelectRepertoiresIndex, memoRepertoire, + tag_list, + memoSubject, memoType, + memoLanguage, attachments_url, fileList } = this.state; + const memoId = match.params.memoId; + + const uploadProps = { + width: 600, + fileList, + multiple: true, + // https://github.com/ant-design/ant-design/issues/15505 + // showUploadList={false},然后外部拿到 fileList 数组自行渲染列表。 + // showUploadList: false, + action: `${getUploadActionUrl()}`, + onChange: this.handleChange, + onRemove: this.onAttachmentRemove, + beforeUpload: (file) => { + console.log('beforeUpload', file.name); + const isLt150M = file.size / 1024 / 1024 < 150; + if (!isLt150M) { + this.props.showNotification('文件大小必须小于150MB!'); + } + return isLt150M; + }, + }; + return ( +
+

交流问答 / 详情

+
+ { memoId ? '编辑话题' : '发布话题'} + {/* + */} +
+ +
+
+

话题名称

+
+ * +
+ this.onMemoNameChange(val)} placeholder=""> + +
+
+ + 必填项 + +
+
+
+
+ +
+
+

内容

+
+ * +
+ + + {/*
+ +
*/} +

+

+
+
+ + 必填项 + +
+
+ + + + {/*
+ + { attachments_url && !!attachments_url.length && + this.renderAttachment() + } + + + {debugger;window.addInputFiles( window.$('.file_selector')[0] ) }} + style={{'display':'none'}} type="file"> + + +
*/} + + + {/*开始上传*/} + + + (单个文件150M以内) + + + {/* 请求status 422 */} + + {/* */} + {/*
+ window.$('#_file').click()} + data-tip-down="请选择文件上传"> + + 上传附件 + (单个文件50M以内) + +
*/} +
+
+ {/* TODOTODO 这里重复的html代码太多,如果有其他页面有类似需求,需要封装*/} + +
+
+

话题类型

+
+ * +
+ +
+
+ + 必填项 + +
+
+
+
+ + {/* memoType === typeNameMap['技术分享'] && +
+
+

技术标签

+
+ * +
+ +
+
+ +
+ +
+ + 必填项 + +
+
+
+
*/} + + { memoType === typeNameMap['技术分享'] && +
+
+

技术标签

+
+ * + +
+ +
+ +
+ + 必填项 + +
+
+
+
} + +
+ {this.onCommit()}}>提交 + { this.onCancel() }} className="defalutCancelbtn fl">取消 +
+ +
+ ); + } +} + +export default MemoNew; From 2266857dac9f9eec403d0c82f84539b748948cc6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 28 Aug 2019 09:29:04 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E8=B5=84=E6=BA=90=E7=9A=84=E5=8F=91?= =?UTF-8?q?=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index a6eafe0f3..791d145c2 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -172,17 +172,17 @@ class FilesController < ApplicationController attachment_ids.each do |attachment_id| ori = Attachment.find_by_id(attachment_id) # 同一个资源可以多次发送到课堂 - @course.attachments.each do |att| - @exist = false - if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from - att.created_on = Time.now - att.save - @exist = true - break - end - end - - next if @exist + # @course.attachments.each do |att| + # @exist = false + # if att.id == ori.id || (!att.copy_from.nil? && !ori.copy_from.nil? && att.copy_from == ori.copy_from) || att.copy_from == ori.id || att.id == ori.copy_from + # att.created_on = Time.now + # att.save + # @exist = true + # break + # end + # end + # + # next if @exist attach_copied_obj = ori.copy attach_copied_obj.container = @course attach_copied_obj.created_on = Time.now From 053a54f9035733e2721828be5d3c0ed1b6de87b7 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 28 Aug 2019 09:38:13 +0800 Subject: [PATCH 5/8] commit_user_name --- .../react/src/modules/courses/busyWork/CommonWorkAppraise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/react/src/modules/courses/busyWork/CommonWorkAppraise.js b/public/react/src/modules/courses/busyWork/CommonWorkAppraise.js index f29204563..d1e271981 100644 --- a/public/react/src/modules/courses/busyWork/CommonWorkAppraise.js +++ b/public/react/src/modules/courses/busyWork/CommonWorkAppraise.js @@ -162,7 +162,7 @@ class CommonWorkAppraise extends Component{ let {course_name, homework_name, search, page, loadingstate, homework_status, reference_answer, attachments, homework_id, project_info, work_members, is_evaluation, - description, update_user_name, update_time, commit_time, author_name, + description, update_user_name, commit_user_name, update_time, commit_time, author_name, revise_attachments, revise_reason, atta_update_user, atta_update_time, atta_update_user_login, Modalstype,Modalstopval,ModalCancel,ModalSave,loadtype, is_leader_work } =this.state; @@ -237,7 +237,7 @@ class CommonWorkAppraise extends Component{ { commit_time && 提交 - {author_name} + {commit_user_name} {moment(commit_time).format('YYYY-MM-DD HH:mm')==="Invalid date"?"":moment(commit_time).format('YYYY-MM-DD HH:mm')} From d040850a3a4aa032222a4e027c7e78f249f9bd80 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 28 Aug 2019 09:41:11 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=8F=82=E8=80=83?= =?UTF-8?q?=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 23 +++++++++++-------- .../challenges/crud_answer.json.jbuilder | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 0f6532372..48ba77b0c 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -234,18 +234,21 @@ class ChallengesController < ApplicationController # {...}, ...] #} def crud_answer - raise '参考答案不能为空' if params[:challenge_answer].empty? - raise '占比之和必须为100%' if params[:challenge_answer].map{|a| a[:score]}.sum != 100 - ActiveRecord::Base.transaction do - @challenge.challenge_answers.destroy_all if @challenge.challenge_answers - params[:challenge_answer].each_with_index do |answer, index| - # 内容为空不保存 - next if answer[:contents].blank? - ChallengeAnswer.create(name: answer[:name], contents: answer[:contents], - level: index+1, score: answer[:score], challenge_id: @challenge.id) + if @challenge.challenge_answers && params[:challenge_answer].empty? + @challenge.challenge_answers.destroy_all + else + raise '参考答案不能为空' if params[:challenge_answer].empty? + raise '占比之和必须为100%' if params[:challenge_answer].map{|a| a[:score]}.sum != 100 + ActiveRecord::Base.transaction do + @challenge.challenge_answers.destroy_all if @challenge.challenge_answers + params[:challenge_answer].each_with_index do |answer, index| + # 内容为空不保存 + next if answer[:contents].blank? + ChallengeAnswer.create(name: answer[:name], contents: answer[:contents], + level: index+1, score: answer[:score], challenge_id: @challenge.id) + end end end - end # 查看参考答案接口 diff --git a/app/views/challenges/crud_answer.json.jbuilder b/app/views/challenges/crud_answer.json.jbuilder index b11268d99..e16f09423 100644 --- a/app/views/challenges/crud_answer.json.jbuilder +++ b/app/views/challenges/crud_answer.json.jbuilder @@ -1,2 +1,2 @@ json.status 1 -json.message "创建参考答案成功" \ No newline at end of file +json.message "操作成功" \ No newline at end of file From 7b988654cb9a70adf7e981b5a5a9ebe2053c7e15 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 28 Aug 2019 09:45:44 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 48ba77b0c..8cb68b1d4 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -234,7 +234,7 @@ class ChallengesController < ApplicationController # {...}, ...] #} def crud_answer - if @challenge.challenge_answers && params[:challenge_answer].empty? + if @challenge.challenge_answers && params[:challenge_answer].blank? @challenge.challenge_answers.destroy_all else raise '参考答案不能为空' if params[:challenge_answer].empty? From 30bc2a03dc1260580ca16e46511353ab9bbeab3f Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 28 Aug 2019 09:52:41 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=AD=94=E6=A1=88=20?= =?UTF-8?q?=E6=9C=AA=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/tpm/challengesnew/TPManswer2.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/public/react/src/modules/tpm/challengesnew/TPManswer2.js b/public/react/src/modules/tpm/challengesnew/TPManswer2.js index 6218cc468..19765597e 100644 --- a/public/react/src/modules/tpm/challengesnew/TPManswer2.js +++ b/public/react/src/modules/tpm/challengesnew/TPManswer2.js @@ -120,7 +120,9 @@ export default class TPManswer extends Component { let urlAnswer = `/shixuns/${id}/challenges/${checkpointId}/answer.json`; axios.get(urlAnswer).then((response) => { - if (response.data) { + if (response.data.status === 401) { + + } else if (response.data) { this.setState({ answers: response.data }) } }) @@ -158,7 +160,7 @@ export default class TPManswer extends Component { if (!isValidate) { return; } - if (totalScore != 100) { + if (answersParams.length != 0 && totalScore != 100) { this.props.showSnackbar("请先保证占比和为100%"); return; }