Newer
Older
import {
Container,
Header,
Segment,
Table,
} from 'semantic-ui-react';
import { connect } from 'react-redux';
import moment from 'moment';
import { getTasks, getSolutions, addTask, addDocument } from '../../actions/homework';
import AddTaskForm from '../forms/AddTaskForm';
import AddSolutionForm from '../forms/AddSolutionForm';
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const displayTypes = {
can_submit: {
text: 'Beadható',
icon: 'send',
rowstyle: { warning: false, positive: false, negative: false },
},
no_submit: {
text: 'Beadás elmaradt',
icon: 'warning circle',
rowstyle: { warning: true, positive: false, negative: false },
},
wait_correction: {
text: 'Javításra vár',
icon: 'wait',
rowstyle: { warning: true, positive: false, negative: false },
},
no_accept: {
text: 'Nem elfogadható',
icon: 'warning circle',
rowstyle: { warning: false, positive: false, negative: true },
},
accepted: {
text: 'Elfogadva',
icon: 'checkmark',
rowstyle: { warning: false, positive: true, negative: false },
},
};
const emptyMessage = (header, text, marginBottom) => (
<Message
style={{ marginBottom }}
icon='info'
info
header={header}
content={text}
/>
);
class Homework extends Component {
componentDidMount() {
this.props.getSolutions();
}
getTaskDisplayStyle(task) {
const taskSolutions = this.props.homeworks.solutions.filter(solution =>
solution.task === task.id);
if (taskSolutions.length === 0) {
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
return 'can_submit';
}
return 'no_submit';
}
if (taskSolutions[taskSolutions.length - 1].corrected === false) {
return 'wait_correction';
}
if (taskSolutions[taskSolutions.length - 1].accepted === false) {
return 'no_accept';
}
return 'accepted';
}
renderTaskList(active) {
return this.props.homeworks.tasks
.filter(task => moment().isBefore(task.deadline) === active)
.map(task => (
<Table.Row
key={task.id}
warning={
displayTypes[this.getTaskDisplayStyle(task)].rowstyle.warning
}
positive={
displayTypes[this.getTaskDisplayStyle(task)].rowstyle.positive
}
negative={
displayTypes[this.getTaskDisplayStyle(task)].rowstyle.negative
}
>
<Table.Cell>
<AddSolutionForm taskid={task.id} tasktitle={task.title}/>
{moment(task.deadline).format('YYYY. MM. DD. HH:mm')}
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
</Table.Cell>
<Table.Cell>
<Icon name={displayTypes[this.getTaskDisplayStyle(task)].icon} />{' '}
{displayTypes[this.getTaskDisplayStyle(task)].text}
</Table.Cell>
</Table.Row>
));
}
renderHomeworksTable(active) {
let tableColor = 'green';
let marginBottom = '0em';
if (!active) {
tableColor = 'blue';
marginBottom = '3em';
}
return (
<Table color={tableColor} fixed style={{ marginBottom }}>
<Table.Header>
<Table.Row>
<Table.HeaderCell>
<Icon circular name='home' />
Feladat megnevezése
</Table.HeaderCell>
<Table.HeaderCell>
<Icon circular name='calendar' />
Beadási határidő
</Table.HeaderCell>
<Table.HeaderCell>
<Icon circular name='tasks' />
Állapot
</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>{this.renderTaskList(active)}</Table.Body>
</Table>
);
}
renderHomeworks(active) {
let empty = false;
let emptyText = 'Jelenleg nincs egyetlen beadható feladat sem. ';
let marginBottom = '0em';
const emptyHeaderText = 'Nincs feladat.';
let headerText = 'Aktív feladatok';
if (
this.props.homeworks.tasks.filter(task =>
moment().isBefore(task.deadline) === active).length === 0
) {
empty = true;
}
if (!active) {
headerText = 'Lejárt határidejű feladatok';
emptyText = 'Jelenleg nincs egyetlen lejárt határidejű feladat sem.';
marginBottom = '3em';
}
return (
<Segment style={{ padding: '0 0 2em 0' }} vertical basic>
<Container>
<Header
as='h1'
dividing
content={headerText}
style={{
fontSize: '3em',
fontWeight: 'normal',
marginBottom: 0,
marginTop: '0.5em',
}}
/>
{empty
? emptyMessage(emptyHeaderText, emptyText, marginBottom)
: this.renderHomeworksTable(active)}
</Container>
</Segment>
);
}
render() {
return (
<div>
<Segment style={{ padding: '0 0 2em 0' }} vertical basic>
<Container>
<Header
as='h1'
dividing
content='Házi feladat hozzáadása, módosítása vagy törlése'
style={{
fontSize: '3em',
fontWeight: 'normal',
marginBottom: '0.5em',
marginTop: '0.5em',
}}
/>
<Button.Group>
<AddTaskForm />
</Button.Group>
</Container>
</Segment>
{this.renderHomeworks(true)}
{this.renderHomeworks(false)}
const mapStateToProps = ({ homeworks, user }) => ({ homeworks, user });
export default connect(
mapStateToProps,
{
getTasks,
getSolutions,
addTask,
addDocument,
},