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
No related branches found
No related tags found
No related merge requests found
......@@ -31,10 +31,10 @@ export const getTasks = () => (
}
);
export const getSolutions = id => (
export const getSolutions = taskId => (
async (dispatch) => {
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({
type: GET_SOLUTIONS,
payload: response.data,
......@@ -183,11 +183,11 @@ export const addSolution = ({
}
);
export const getDocuments = (id, solution) => (
export const getDocuments = (solutionID) => (
async (dispatch) => {
try {
const response =
await axios.get('/api/v1/documents', { params: { profileID: id, solutionID: solution } });
await axios.get('/api/v1/documents', { params: { solution: solutionID } });
dispatch({
type: GET_DOCUMENTS,
payload: response.data,
......
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 { addSolution, writeSolution, writeSolutionFile, addDocument, clearWrite } from '../../actions/homework';
import './Forms.css';
......@@ -20,6 +20,7 @@ const allowedFileTypes = [
const maxFileSize = 50;
class AddSolutionForm extends Component {
constructor(props) {
super(props);
this.state = {
......@@ -27,30 +28,34 @@ class AddSolutionForm extends Component {
};
}
render() {
const {
name, description, file
} = this.props.newSolution
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 accepted = false;
const sentences = this.props.taskdesc.split('\n');
const note = '';
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 (
<Modal
open={this.state.showModal}
......@@ -79,6 +84,31 @@ class AddSolutionForm extends Component {
{this.props.disabled ?
customMessage(disabledText, undefined, undefined, this.props.disabled) :
<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
control={Input}
label='Megoldás címe:'
......
......@@ -5,11 +5,11 @@ class HiddenForm extends Component {
render(){
return (
<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 }}>
<p>
<div>
{this.props.value}
</p>
</div>
</Segment>
</div>
)
......
......@@ -13,6 +13,7 @@ import moment from 'moment';
import {
getTasks,
getSolutions,
getDocuments,
addTask,
setSelectedTask,
deleteTask,
......@@ -69,18 +70,18 @@ export const customMessage = (header, text, marginBottom, warning) => (
class Homework extends Component {
componentDidMount() {
this.props.getTasks();
this.props.getProfiles();
this.props.getSolutions(this.props.user.id);
this.props.getTasks()
this.props.getProfiles()
this.props.getSolutions()
this.props.getDocuments()
}
// Returns a table style for the given task
getTaskDisplayStyle(task) {
const taskSolutions = this.props.homeworks.solutions.filter(solution =>
solution.task === task.id).filter(solution =>
solution.created_by === this.props.user.id);
const taskSolution = this.props.homeworks.solutions
.filter(solution => solution.task === task.id)
if (taskSolutions.length === 0) {
if (taskSolution.length === 0) {
if (moment().isBefore(task.deadline)) {
return 'can_submit';
}
......@@ -88,11 +89,11 @@ class Homework extends Component {
return 'no_submit';
}
if (taskSolutions[taskSolutions.length - 1].corrected === false) {
if (taskSolution[0].corrected === false) {
return 'wait_correction';
}
if (taskSolutions[taskSolutions.length - 1].accepted === false) {
if (taskSolution[0].accepted === false) {
return 'no_accept';
}
......@@ -103,8 +104,9 @@ class Homework extends Component {
// given parameters separates the active/inactive tasks and normal/staff users
renderTaskList(active, staff) {
const { user, homeworks } = this.props;
const profileSolutions = homeworks.solutions.filter(solution =>
solution.created_by === user.id);
const profileSolutions = homeworks.solutions
.filter(solution => solution.created_by === user.id);
// Normal user
if (!staff) {
......@@ -372,6 +374,7 @@ export default connect(
getTasks,
setSelectedTask,
getSolutions,
getDocuments,
addTask,
deleteTask,
getProfiles,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment