Skip to content
Snippets Groups Projects
Commit ff984395 authored by Bereczki Sandor's avatar Bereczki Sandor
Browse files

Added Solution Details Modal

parent 3015e385
No related branches found
No related tags found
No related merge requests found
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Modal, Button, Form, Icon } from 'semantic-ui-react'; import { Modal, Button, Header, Icon } from 'semantic-ui-react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { emptyMessage } from '../pages/Homework';
class CorrectSolutionForm extends Component { class SolutionDetailsForm extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
...@@ -13,9 +14,29 @@ class CorrectSolutionForm extends Component { ...@@ -13,9 +14,29 @@ class CorrectSolutionForm extends Component {
render() { render() {
const taskSolutions = this.props.homeworks.solutions.filter(solution => const taskSolutions = this.props.homeworks.solutions.filter(solution =>
solution.task === this.props.taskid); solution.task === this.props.taskid);
const solutionProfileIds = [...new Set(taskSolutions.map(sol => sol.created_by))];
const solutionProfiles = const noSubmitStudents = [];
this.props.homeworks.profiles.filter(profile => solutionProfileIds.includes(profile.id)); const waitForCorrectionStudents = [];
const noAcceptStudents = [];
const acceptedStudents = [];
for (let i = 0; i < this.props.homeworks.profiles.length; i += 1) {
const profileSolutions = taskSolutions.filter(solution =>
solution.created_by === this.props.homeworks.profiles[i].id);
if (profileSolutions.length === 0) {
noSubmitStudents.push(this.props.homeworks.profiles[i].nick);
} else if (taskSolutions[taskSolutions.length - 1].corrected === false) {
waitForCorrectionStudents.push(this.props.homeworks.profiles[i].nick);
} else if (taskSolutions[taskSolutions.length - 1].accepted === false) {
noAcceptStudents.push(this.props.homeworks.profiles[i].nick);
} else {
acceptedStudents.push(this.props.homeworks.profiles[i].nick);
}
}
const emptyStudentText = 'Nincs ilyen képződő jelenleg.';
return ( return (
<Modal <Modal
open={this.state.showModal} open={this.state.showModal}
...@@ -26,14 +47,38 @@ class CorrectSolutionForm extends Component { ...@@ -26,14 +47,38 @@ class CorrectSolutionForm extends Component {
</Button> </Button>
} }
> >
<Modal.Header>Új javítás beadása a(z) {this.props.tasktitle} nevű feladathoz:</Modal.Header> <Modal.Header>
A megoldások beadásának állapota a(z) {this.props.tasktitle} nevű feladatnál:
</Modal.Header>
<Modal.Content> <Modal.Content>
<Form> <Header as='h3'>Nem érkezett még megoldás:</Header>
<p>Eddig a feladatot beadták:</p> {noSubmitStudents.length === 0 ?
{solutionProfiles.map(profile => ( emptyMessage(emptyStudentText) :
<p>{profile.full_name}</p> noSubmitStudents.map(name => (
))} <Button color='blue' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{name}</Button>
</Form> ))
}
<Header as='h3'>Javításra vár (A névre kattintva kijavítható a megoldás):</Header>
{waitForCorrectionStudents.length === 0 ?
emptyMessage(emptyStudentText) :
waitForCorrectionStudents.map(name => (
<Button inverted color='orange' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{name}</Button>
))
}
<Header as='h3'>A megoldás nem elfogadható:</Header>
{noAcceptStudents.length === 0 ?
emptyMessage(emptyStudentText) :
noAcceptStudents.map(name => (
<Button color='red' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{name}</Button>
))
}
<Header as='h3'>Elfogadva:</Header>
{acceptedStudents.length === 0 ?
emptyMessage(emptyStudentText) :
acceptedStudents.map(name => (
<Button color='green' style={{ marginRight: '1.5em', marginTop: '1.5em' }}>{name}</Button>
))
}
</Modal.Content> </Modal.Content>
<Modal.Actions> <Modal.Actions>
<Button <Button
...@@ -62,4 +107,4 @@ class CorrectSolutionForm extends Component { ...@@ -62,4 +107,4 @@ class CorrectSolutionForm extends Component {
const mapStateToProps = ({ homeworks, user }) => ({ homeworks, user }); const mapStateToProps = ({ homeworks, user }) => ({ homeworks, user });
export default connect(mapStateToProps, { export default connect(mapStateToProps, {
})(CorrectSolutionForm); })(SolutionDetailsForm);
...@@ -13,7 +13,7 @@ import moment from 'moment'; ...@@ -13,7 +13,7 @@ import moment from 'moment';
import { getTasks, getSolutions, addTask, addDocument, getProfiles } from '../../actions/homework'; import { getTasks, getSolutions, addTask, addDocument, getProfiles } from '../../actions/homework';
import AddTaskForm from '../forms/AddTaskForm'; import AddTaskForm from '../forms/AddTaskForm';
import AddSolutionForm from '../forms/AddSolutionForm'; import AddSolutionForm from '../forms/AddSolutionForm';
import CorrectSolutionForm from '../forms/CorrectSolutionForm'; import SolutionDetailsForm from '../forms/SolutionDetailsForm';
const displayTypes = { const displayTypes = {
can_submit: { can_submit: {
...@@ -43,7 +43,7 @@ const displayTypes = { ...@@ -43,7 +43,7 @@ const displayTypes = {
}, },
}; };
const emptyMessage = (header, text, marginBottom) => ( export const emptyMessage = (header, text, marginBottom) => (
<Message <Message
style={{ marginBottom }} style={{ marginBottom }}
icon='info' icon='info'
...@@ -62,7 +62,9 @@ class Homework extends Component { ...@@ -62,7 +62,9 @@ class Homework extends Component {
getTaskDisplayStyle(task) { getTaskDisplayStyle(task) {
const taskSolutions = this.props.homeworks.solutions.filter(solution => const taskSolutions = this.props.homeworks.solutions.filter(solution =>
solution.task === task.id); solution.task === task.id)
.filter(solution =>
solution.created_by === this.props.user.id);
if (taskSolutions.length === 0) { if (taskSolutions.length === 0) {
if (moment().isBefore(task.deadline)) { if (moment().isBefore(task.deadline)) {
...@@ -87,12 +89,33 @@ class Homework extends Component { ...@@ -87,12 +89,33 @@ class Homework extends Component {
if (!staff) { if (!staff) {
return this.props.homeworks.tasks return this.props.homeworks.tasks
.filter(task => moment().isBefore(task.deadline) === active) .filter(task => moment().isBefore(task.deadline) === active)
.map(task => (
<Table.Row
key={task.id}
warning={
displayTypes[this.getTaskDisplayStyle(task)].rowstyle.warning
} }
positive={ positive={
displayTypes[this.getTaskDisplayStyle(task)].rowstyle.positive
}
negative={ negative={
displayTypes[this.getTaskDisplayStyle(task)].rowstyle.negative displayTypes[this.getTaskDisplayStyle(task)].rowstyle.negative
}
>
<Table.Cell> <Table.Cell>
<AddSolutionForm taskid={task.id} tasktitle={task.title} taskdesc={task.text} /> <AddSolutionForm taskid={task.id} tasktitle={task.title} taskdesc={task.text} />
</Table.Cell>
<Table.Cell>
{moment(task.deadline).format('YYYY. MM. DD. HH:mm')}
</Table.Cell>
<Table.Cell>
<Icon name={displayTypes[this.getTaskDisplayStyle(task)].icon} />{' '}
{displayTypes[this.getTaskDisplayStyle(task)].text}
</Table.Cell>
</Table.Row>
));
}
return this.props.homeworks.tasks return this.props.homeworks.tasks
.filter(task => moment().isBefore(task.deadline) === active) .filter(task => moment().isBefore(task.deadline) === active)
.map(task => ( .map(task => (
...@@ -109,7 +132,7 @@ class Homework extends Component { ...@@ -109,7 +132,7 @@ class Homework extends Component {
} }
> >
<Table.Cell> <Table.Cell>
<CorrectSolutionForm taskid={task.id} tasktitle={task.title} taskdesc={task.text} /> <SolutionDetailsForm taskid={task.id} tasktitle={task.title} taskdesc={task.text} />
</Table.Cell> </Table.Cell>
<Table.Cell> <Table.Cell>
{moment(task.deadline).format('YYYY. MM. DD. HH:mm')} {moment(task.deadline).format('YYYY. MM. DD. HH:mm')}
......
import { } from '../actions/types';
const INITIAL_STATE = {
can_submit: [],
no_submit: [],
wait_correction: [],
no_accept: [],
accepted: [],
};
export default (state = INITIAL_STATE, action) => {
switch (action.type) {
default:
return state;
}
};
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