Skip to content
Snippets Groups Projects
Commit 8daedc54 authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

#61 students can see their solutions

parent 42864ee3
Branches
Tags v1.0.0
No related merge requests found
...@@ -31,10 +31,10 @@ export const getTasks = () => ( ...@@ -31,10 +31,10 @@ export const getTasks = () => (
} }
); );
export const getSolutions = id => ( export const getSolutions = taskId => (
async (dispatch) => { async (dispatch) => {
try { try {
const response = await axios.get('/api/v1/homework/solutions/', { params: { profileID: id } }); const response = await axios.get('/api/v1/homework/solutions/', { task: taskId });
dispatch({ dispatch({
type: GET_SOLUTIONS, type: GET_SOLUTIONS,
payload: response.data, payload: response.data,
...@@ -183,11 +183,11 @@ export const addSolution = ({ ...@@ -183,11 +183,11 @@ export const addSolution = ({
} }
); );
export const getDocuments = (id, solution) => ( export const getDocuments = (solutionID) => (
async (dispatch) => { async (dispatch) => {
try { try {
const response = const response =
await axios.get('/api/v1/documents', { params: { profileID: id, solutionID: solution } }); await axios.get('/api/v1/documents', { params: { solution: solutionID } });
dispatch({ dispatch({
type: GET_DOCUMENTS, type: GET_DOCUMENTS,
payload: response.data, payload: response.data,
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Modal, Button, Form, Input, TextArea, Icon, Header } from 'semantic-ui-react'; import { Modal, Button, Form, Input, TextArea, Icon, Header, Segment, Message } from 'semantic-ui-react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { addSolution, writeSolution, writeSolutionFile, addDocument, clearWrite } from '../../actions/homework'; import { addSolution, writeSolution, writeSolutionFile, addDocument, clearWrite } from '../../actions/homework';
import './Forms.css'; import './Forms.css';
...@@ -20,6 +20,7 @@ const allowedFileTypes = [ ...@@ -20,6 +20,7 @@ const allowedFileTypes = [
const maxFileSize = 50; const maxFileSize = 50;
class AddSolutionForm extends Component { class AddSolutionForm extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
...@@ -27,30 +28,34 @@ class AddSolutionForm extends Component { ...@@ -27,30 +28,34 @@ class AddSolutionForm extends Component {
}; };
} }
render() { render() {
const { const {
name, description, file name, description, file
} = this.props.newSolution } = this.props.newSolution
const task = this.props.taskid; const task = this.props.taskid;
const thisTaskSolution = this.props.homeworks.solutions
.filter(solution => solution.task === task)
const thisTaskDocument = this.props.homeworks.documents
.filter(document => document.solution === thisTaskSolution[0]?.id)
const lastName = thisTaskDocument[0]?.name
const lastDesc = thisTaskDocument[0]?.description
const lastFile = thisTaskDocument[0]?.file
console.log(lastName, lastDesc, lastFile)
// const name = thisTaskDocument[0]?.name
// const description = thisTaskDocument[0]?.description
// const file = '';
const corrected = false; const corrected = false;
const accepted = false; const accepted = false;
const sentences = this.props.taskdesc.split('\n'); const sentences = this.props.taskdesc.split('\n');
const note = ''; const note = '';
const disabledText = 'A határidő lejárt, további beadás nem lehetséges.'; const disabledText = 'A határidő lejárt, további beadás nem lehetséges.';
// const {
// studentFullName, studentId, taskTitle, taskSolutions,
// } = this.props;
// const taskSolutionsProfile =
// taskSolutions.filter(solution => solution.created_by === studentId);
// const relevantSolution = taskSolutionsProfile.slice(-1)[0];
// const relevantDocuments = this.props.homeworks.documents.filter(document =>
// document.solution === relevantSolution.id).filter(document =>
// document.uploaded_by_name === studentFullName);
// const relevantDocument = relevantDocuments.slice(-1)[0];
return ( return (
<Modal <Modal
open={this.state.showModal} open={this.state.showModal}
...@@ -79,6 +84,31 @@ class AddSolutionForm extends Component { ...@@ -79,6 +84,31 @@ class AddSolutionForm extends Component {
{this.props.disabled ? {this.props.disabled ?
customMessage(disabledText, undefined, undefined, this.props.disabled) : customMessage(disabledText, undefined, undefined, this.props.disabled) :
<Form> <Form>
{lastName ?
<Segment style={{paddingBottom: '1em'}}>
<div style={{ marginBottom: '1em', fontWeight: 'bold' }}>Legutóbbi megoldásod:</div>
<Segment attached='top'>
<h5 style={{paddingBottom: '0.4em'}}>Cím:</h5>
{lastName}
</Segment>
<Segment attached>
<h5 style={{paddingBottom: '0.4em'}}>Leírás:</h5>
{lastDesc}
</Segment>
<Segment attached='bottom'>
<h5>Beadott fájl:</h5>
{lastFile ?
<a href={lastFile} rel='noreferrer noopener' target='_blank'>Fájl letöltése</a>
:
<span>-</span>
}
</Segment>
</Segment>
:
null
}
<Form.Field <Form.Field
control={Input} control={Input}
label='Megoldás címe:' label='Megoldás címe:'
......
...@@ -5,11 +5,11 @@ class HiddenForm extends Component { ...@@ -5,11 +5,11 @@ class HiddenForm extends Component {
render(){ render(){
return ( return (
<div> <div>
<p style={{ marginBottom: 0, fontWeight: this.props.fontWeight }}>{this.props.label}</p> <div style={{ marginBottom: 0, fontWeight: this.props.fontWeight }}>{this.props.label}</div>
<Segment style={{ marginTop: 0 }}> <Segment style={{ marginTop: 0 }}>
<p> <div>
{this.props.value} {this.props.value}
</p> </div>
</Segment> </Segment>
</div> </div>
) )
......
...@@ -13,6 +13,7 @@ import moment from 'moment'; ...@@ -13,6 +13,7 @@ import moment from 'moment';
import { import {
getTasks, getTasks,
getSolutions, getSolutions,
getDocuments,
addTask, addTask,
setSelectedTask, setSelectedTask,
deleteTask, deleteTask,
...@@ -69,18 +70,18 @@ export const customMessage = (header, text, marginBottom, warning) => ( ...@@ -69,18 +70,18 @@ export const customMessage = (header, text, marginBottom, warning) => (
class Homework extends Component { class Homework extends Component {
componentDidMount() { componentDidMount() {
this.props.getTasks(); this.props.getTasks()
this.props.getProfiles(); this.props.getProfiles()
this.props.getSolutions(this.props.user.id); this.props.getSolutions()
this.props.getDocuments()
} }
// Returns a table style for the given task // Returns a table style for the given task
getTaskDisplayStyle(task) { getTaskDisplayStyle(task) {
const taskSolutions = this.props.homeworks.solutions.filter(solution => const taskSolution = this.props.homeworks.solutions
solution.task === task.id).filter(solution => .filter(solution => solution.task === task.id)
solution.created_by === this.props.user.id);
if (taskSolutions.length === 0) { if (taskSolution.length === 0) {
if (moment().isBefore(task.deadline)) { if (moment().isBefore(task.deadline)) {
return 'can_submit'; return 'can_submit';
} }
...@@ -88,11 +89,11 @@ class Homework extends Component { ...@@ -88,11 +89,11 @@ class Homework extends Component {
return 'no_submit'; return 'no_submit';
} }
if (taskSolutions[taskSolutions.length - 1].corrected === false) { if (taskSolution[0].corrected === false) {
return 'wait_correction'; return 'wait_correction';
} }
if (taskSolutions[taskSolutions.length - 1].accepted === false) { if (taskSolution[0].accepted === false) {
return 'no_accept'; return 'no_accept';
} }
...@@ -103,8 +104,9 @@ class Homework extends Component { ...@@ -103,8 +104,9 @@ class Homework extends Component {
// given parameters separates the active/inactive tasks and normal/staff users // given parameters separates the active/inactive tasks and normal/staff users
renderTaskList(active, staff) { renderTaskList(active, staff) {
const { user, homeworks } = this.props; const { user, homeworks } = this.props;
const profileSolutions = homeworks.solutions.filter(solution => const profileSolutions = homeworks.solutions
solution.created_by === user.id); .filter(solution => solution.created_by === user.id);
// Normal user // Normal user
if (!staff) { if (!staff) {
...@@ -372,6 +374,7 @@ export default connect( ...@@ -372,6 +374,7 @@ export default connect(
getTasks, getTasks,
setSelectedTask, setSelectedTask,
getSolutions, getSolutions,
getDocuments,
addTask, addTask,
deleteTask, deleteTask,
getProfiles, getProfiles,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment