diff --git a/controllers/task.go b/controllers/task.go index c1fd80b..da43524 100644 --- a/controllers/task.go +++ b/controllers/task.go @@ -38,7 +38,7 @@ func (p *ProjectController) GetSectionTasksDetail() { learning = false } uid := user.Username - pid, err := p.GetInt64(":projectId") + pid := p.GetString(":projectId") learning = models.IsLearningProject(pid, uid) tasks, err := models.GetSectionTasks(sid, uid, learning) if err != nil { @@ -83,7 +83,7 @@ func (p *ProjectController) GetProjectTasks() { } pid := p.GetString(":projectId") - tasks, err := models.GetProjectTasks(pid, "") + tasks, err := models.GetProjectTasks(pid) if err != nil { p.Data["json"] = Response{ Code: 400, @@ -98,44 +98,51 @@ func (p *ProjectController) GetProjectTasks() { p.ServeJSON() } -// GetProjectTasksAndSubmits +// GetProjectTasksDetail // @Title // @Description get all the tasks of a section // @Param sid path string true "" // @Success 200 {object} // @Failure 400 -// @router /:projectId/tasks-submits [get] -func (p *ProjectController) GetProjectTasksAndSubmits() { +// @router /:projectId/tasks-detail [get] +func (p *ProjectController) GetProjectTasksDetail() { + var resp TaskResponse + var learning bool user := p.GetSessionUser() if user == nil { - p.Data["json"] = TaskResponse{ + resp = TaskResponse{ Response: Response{ Code: 401, Msg: "请先登录", }, } + p.Data["json"] = resp p.ServeJSON() return } - - uid := "" - if user.Tag == "student" { - uid = user.Username - } else if user.Tag == "teacher" { - uid = p.GetString("StudentId") + if user.Tag != "student" { + learning = false } - + uid := user.Username pid := p.GetString(":projectId") - tasks, err := models.GetProjectTasks(pid, uid) + learning = models.IsLearningProject(pid, uid) + tasks, err := models.GetProjectTasksDetail(pid, uid, learning) if err != nil { - p.Data["json"] = Response{ - Code: 400, - Msg: err.Error(), + p.Data["json"] = TaskResponse{ + Response: Response{ + Code: 400, + Msg: err.Error(), + }, + Tasks: nil, + Learning: false, } } else { - p.Data["json"] = Response{ - Code: 200, - Data: tasks, + p.Data["json"] = TaskResponse{ + Response: Response{ + Code: 200, + }, + Tasks: tasks, + Learning: learning, } } p.ServeJSON() diff --git a/models/student.go b/models/student.go index 5beccb6..4876bea 100644 --- a/models/student.go +++ b/models/student.go @@ -1,6 +1,7 @@ package models import ( + "strconv" "time" "xorm.io/xorm" ) @@ -55,11 +56,12 @@ func (l *LearnProject) Delete() (err error) { return } -func IsLearningProject(pid int64, uid string) (e bool) { +func IsLearningProject(pid string, uid string) (e bool) { var err error + id, err := strconv.ParseInt(pid, 10, 64) e, err = (&LearnProject{}).GetEngine().Exist(&LearnProject{ StudentId: uid, - ProjectId: pid, + ProjectId: id, Learning: true, }) if err != nil { diff --git a/models/task.go b/models/task.go index 5601a86..9a6d027 100644 --- a/models/task.go +++ b/models/task.go @@ -22,10 +22,9 @@ type Task struct { } type TaskEvaluate struct { - Task `xorm:"extends"` - Score int `json:"score"` - Scored bool `json:"scored"` - SubmitId int64 `json:"submitId"` + Task `xorm:"extends"` + Submitted bool `json:"submitted"` + Submit Submit `json:"submit"` } type TaskDetail struct { @@ -66,11 +65,11 @@ func GetSectionTasks(sid string, uid string, learning bool) (t []TaskDetail, err Where("section_id = ?", sid). Asc("task_order"). Find(&t) - var s Survey - var qs []Question - var c []Choice var b bool for i := 0; i < len(t); i ++ { + var s Survey + var qs []Question + var c []Choice if t[i].TaskType == "survey" { var m Submit _, err = (&Survey{}).GetEngine(). @@ -123,22 +122,72 @@ func ExchangeTasks(cid1 string, cid2 string) (err error) { return } -func GetProjectTasks(pid string, uid string) (t []TaskEvaluate, err error) { - if uid == "" { - err = (&Task{}).GetEngine(). - Where("project_id = ?", pid). - Asc("chapter_number"). - Asc("section_number"). - Asc("task_order"). - Find(&t) - } else { - err = (&Task{}).GetEngine(). - Where("task.project_id = ?", pid). - Join("LEFT OUTER", "submit", "task.id = submit.task_id"). - Asc("chapter_number"). - Asc("section_number"). - Asc("task_order"). - Find(&t) + +func GetProjectTasksDetail(sid string, uid string, learning bool) (t []TaskDetail, err error) { + err = (&Task{}).GetEngine(). + Where("project_id = ?", sid). + Asc("chapter_number"). + Asc("section_number"). + Asc("task_order"). + Find(&t) + var b bool + for i := 0; i < len(t); i ++ { + var s Survey + var qs []Question + var c []Choice + + if t[i].TaskType == "survey" { + var m Submit + b, err = (&Survey{}).GetEngine(). + Where("task_id = ?", t[i].Id). + Get(&s) + if b { + err = (&Question{}).GetEngine(). + Where("survey_id = ?", s.Id). + Asc("question_order"). + Find(&qs) + t[i].Questions = qs + } + t[i].Survey = s + + if learning { + b, err = (&Submit{}).GetEngine(). + Where("task_id = ?", t[i].Id). + Where("student_id = ?", uid). + Get(&m) + if b { + t[i].Submitted = true + err = (&Choice{}).GetEngine(). + Where("submit_id = ?", m.Id). + Asc("choice_order"). + Find(&c) + t[i].Choices = c + } + t[i].Submit = m + } + } else { + var m Submit + if learning { + b, err = (&Submit{}).GetEngine(). + Where("task_id = ?", t[i].Id). + Where("student_id = ?", uid). + Get(&m) + t[i].Submit = m + if b { + t[i].Submitted = true + } + } + } } return +} + +func GetProjectTasks(pid string) (t []TaskEvaluate, err error) { + err = (&Task{}).GetEngine(). + Where("project_id = ?", pid). + Asc("chapter_number"). + Asc("section_number"). + Asc("task_order"). + Find(&t) + return } \ No newline at end of file diff --git a/openpbl-landing/src/api/TaskApi.js b/openpbl-landing/src/api/TaskApi.js index 098a5cf..48ad922 100644 --- a/openpbl-landing/src/api/TaskApi.js +++ b/openpbl-landing/src/api/TaskApi.js @@ -14,9 +14,9 @@ const TaskApi = { method: 'get', }) }, - getProjectTasksAndSubmits(pid) { + getProjectTasksDetail(pid) { return request({ - url: `/project/${pid}/tasks-submits`, + url: `/project/${pid}/tasks-detail`, method: 'get', }) }, diff --git a/openpbl-landing/src/pages/Project/PreviewProject/PreviewSection.jsx b/openpbl-landing/src/pages/Project/PreviewProject/PreviewSection.jsx index b2e44f4..ad7ecbf 100644 --- a/openpbl-landing/src/pages/Project/PreviewProject/PreviewSection.jsx +++ b/openpbl-landing/src/pages/Project/PreviewProject/PreviewSection.jsx @@ -11,7 +11,7 @@ import FillSurvey from "./component/FillSurvey"; import SubmitApi from "../../../api/SubmitApi"; import util from "../component/Util" import StudentApi from "../../../api/StudentApi"; - +import TaskCard from "./component/TaskCard"; function PreviewSection(obj) { let url = new URLSearchParams(obj.location.search) @@ -127,11 +127,11 @@ function PreviewSection(obj) { window.location.href = backUrl } } - const changeComment = (v, index) => { +/* const changeComment = (v, index) => { tasks[index].submit.submitContent = v.target.value setTasks([...tasks]) - } - const submitComment = (item, index) => { + }*/ +/* const submitComment = (item, index) => { item.submit.submitType = item.taskType SubmitApi.createSubmit(pid, item.id, item.submit) .then(res=>{ @@ -143,8 +143,8 @@ function PreviewSection(obj) { } }) .catch(e=>{console.log(e)}) - } - const updateComment = (item, index) => { + }*/ +/* const updateComment = (item, index) => { SubmitApi.updateSubmit(pid, item.id, item.submit.id, item.submit) .then(res=>{ if (res.data.code === 200) { @@ -155,32 +155,12 @@ function PreviewSection(obj) { } }) .catch(e=>{console.log(e)}) - } + }*/ const setTaskItem = (item, index) => { tasks[index] = item setTasks([...tasks]) } - const props = { - name: 'file', - multiple: true, - action: '', - onChange(info) { - const { status } = info.file; - if (status !== 'uploading') { - console.log(info.file, info.fileList); - } - if (status === 'done') { - message.success(`${info.file.name} 上传成功`); - } else if (status === 'error') { - message.error(`${info.file.name} 上传失败`); - } - }, - onDrop(e) { - console.log('Dropped files', e.dataTransfer.files); - }, - }; - return (
@@ -218,45 +198,16 @@ function PreviewSection(obj) { }

-

{item.taskTitle}

-

{item.taskIntroduce}

- {item.taskType === 'file' ? -
- -

- -

-

点击或拖动文件上传

-

hint -

-
-
- : null - } - {item.taskType === 'comment' ? -
- changeComment(v, index)} /> - {item.submitted ? - - : - - } -
- : null - } - {item.taskType === 'survey' ? - - : null - } + + )) } diff --git a/openpbl-landing/src/pages/Project/PreviewProject/component/FillSurvey.jsx b/openpbl-landing/src/pages/Project/PreviewProject/component/FillSurvey.jsx index 65e83fe..09eb626 100644 --- a/openpbl-landing/src/pages/Project/PreviewProject/component/FillSurvey.jsx +++ b/openpbl-landing/src/pages/Project/PreviewProject/component/FillSurvey.jsx @@ -125,13 +125,13 @@ function FillSurvey(obj) {
))} - {obj.item.submitted ? - - : - - } +
+ {obj.item.submitted ? + + : + + } +
) } diff --git a/openpbl-landing/src/pages/Project/PreviewProject/component/TaskCard.jsx b/openpbl-landing/src/pages/Project/PreviewProject/component/TaskCard.jsx new file mode 100644 index 0000000..06318cd --- /dev/null +++ b/openpbl-landing/src/pages/Project/PreviewProject/component/TaskCard.jsx @@ -0,0 +1,105 @@ +import React from "react"; +import {Button, Input, message, Upload} from "antd"; +import {InboxOutlined} from "@ant-design/icons"; +import FillSurvey from "./FillSurvey"; +import SubmitApi from "../../../../api/SubmitApi"; + + +function TaskCard(obj) { + + const updateComment = (item, index) => { + SubmitApi.updateSubmit(obj.pid, item.id, item.submit.id, item.submit) + .then(res=>{ + if (res.data.code === 200) { + message.success(res.data.msg) + obj.getTasks() + } else { + message.error(res.data.msg) + } + }) + .catch(e=>{console.log(e)}) + } + const submitComment = (item, index) => { + item.submit.submitType = item.taskType + SubmitApi.createSubmit(obj.pid, item.id, item.submit) + .then(res=>{ + if (res.data.code === 200) { + message.success(res.data.msg) + obj.getTasks() + } else { + message.error(res.data.msg) + } + }) + .catch(e=>{console.log(e)}) + } + const changeComment = (v, index) => { + obj.item.submit.submitContent = v.target.value + obj.setTaskItem(obj.item, index) + } + + const props = { + name: 'file', + multiple: true, + action: '', + onChange(info) { + const { status } = info.file; + if (status !== 'uploading') { + console.log(info.file, info.fileList); + } + if (status === 'done') { + message.success(`${info.file.name} 上传成功`); + } else if (status === 'error') { + message.error(`${info.file.name} 上传失败`); + } + }, + onDrop(e) { + console.log('Dropped files', e.dataTransfer.files); + }, + }; + + return ( + <> +

{obj.item.taskTitle}

+

{obj.item.taskIntroduce}

+ {obj.item.taskType === 'file' ? +
+ +

+ +

+

点击或拖动文件上传

+

hint +

+
+
+ : null + } + {obj.item.taskType === 'comment' ? +
+ changeComment(v, obj.index)} /> +
+ {obj.item.submitted ? + + : + + } +
+
+ : null + } + {obj.item.taskType === 'survey' ? + + : null + } + + ) +} + +export default TaskCard \ No newline at end of file diff --git a/openpbl-landing/src/pages/Project/ProjectInfo/component/StudentEvidence.jsx b/openpbl-landing/src/pages/Project/ProjectInfo/component/StudentEvidence.jsx index ded8f99..97d6e84 100644 --- a/openpbl-landing/src/pages/Project/ProjectInfo/component/StudentEvidence.jsx +++ b/openpbl-landing/src/pages/Project/ProjectInfo/component/StudentEvidence.jsx @@ -3,11 +3,13 @@ import {Col, Collapse, Divider, List, Progress, Row, Table} from "antd"; import TaskApi from "../../../../api/TaskApi"; import ChapterApi from "../../../../api/ChapterApi"; +import TaskCard from "../../PreviewProject/component/TaskCard"; function StudentEvidence(obj) { const pid = obj.project.id const [tasks, setTasks] = useState([]) + const [learning, setLearning] = useState(false) const [chapters, setChapters] = useState([]) useEffect(() => { @@ -29,11 +31,37 @@ function StudentEvidence(obj) { }) } const getTasks = () => { - TaskApi.getProjectTasksAndSubmits(pid) + TaskApi.getProjectTasksDetail(pid) .then(res => { if (res.data.code === 200) { - if (res.data.data != null) { - setTasks(res.data.data) + if (res.data.tasks === null) { + setTasks([]) + } else { + let t = res.data.tasks + for (let i = 0; i < t.length; i++) { + if (t[i].questions !== undefined && t[i].questions != null) { + for (let j = 0; j < t[i].questions.length; j++) { + t[i].questions[j].questionOptions = t[i].questions[j].questionOptions.split(",") + } + } else { + t[i].questions = [] + } + if (t[i].choices !== undefined && t[i].choices != null) { + for (let j = 0; j < t[i].choices.length; j++) { + t[i].choices[j].choiceOptions = t[i].choices[j].choiceOptions.split(",") + } + } else { + t[i].choices = [] + for (let j=0; j { return (score * weight / 100).toFixed(2) } + const setTaskItem = (item, index) => { + tasks[index] = item + setTasks([...tasks]) + } return (
@@ -151,31 +183,46 @@ function StudentEvidence(obj) { <> {item.taskTitle} - {item.scored ? + {item.submit.scored ? 已打分 : 未打分 } + + {item.submitted ? + 已提交 + : + 未提交 + } + 权重:{item.taskWeight} - 得分:{getScore(item.score, item.taskWeight)} / {item.taskWeight} + 得分:{getScore(item.submit.score, item.taskWeight)} / {item.taskWeight} } > - neironog + ))} - + />*/} ) } diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index e149eeb..236fb1a 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -45,18 +45,18 @@ func init() { beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"], beego.ControllerComments{ - Method: "UpdateProject", + Method: "GetProjectDetail", Router: "/:id", - AllowHTTPMethods: []string{"post"}, + AllowHTTPMethods: []string{"get"}, MethodParams: param.Make(), Filters: nil, Params: nil}) beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"], beego.ControllerComments{ - Method: "GetProjectDetail", + Method: "UpdateProject", Router: "/:id", - AllowHTTPMethods: []string{"get"}, + AllowHTTPMethods: []string{"post"}, MethodParams: param.Make(), Filters: nil, Params: nil}) @@ -279,18 +279,18 @@ func init() { beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"], beego.ControllerComments{ - Method: "GetSurveyDetailByTaskId", + Method: "CreateSurvey", Router: "/:projectId/task/:taskId/survey", - AllowHTTPMethods: []string{"get"}, + AllowHTTPMethods: []string{"post"}, MethodParams: param.Make(), Filters: nil, Params: nil}) beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"], beego.ControllerComments{ - Method: "CreateSurvey", + Method: "GetSurveyDetailByTaskId", Router: "/:projectId/task/:taskId/survey", - AllowHTTPMethods: []string{"post"}, + AllowHTTPMethods: []string{"get"}, MethodParams: param.Make(), Filters: nil, Params: nil}) @@ -351,8 +351,8 @@ func init() { beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"] = append(beego.GlobalControllerRouter["OpenPBL/controllers:ProjectController"], beego.ControllerComments{ - Method: "GetProjectTasksAndSubmits", - Router: "/:projectId/tasks-submits", + Method: "GetProjectTasksDetail", + Router: "/:projectId/tasks-detail", AllowHTTPMethods: []string{"get"}, MethodParams: param.Make(), Filters: nil,