Skip to content

Commit 87acb2f

Browse files
committed
Implementing group exams table which lists past exams.
1 parent 1fa02a0 commit 87acb2f

File tree

5 files changed

+99
-11
lines changed

5 files changed

+99
-11
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { FormattedMessage } from 'react-intl';
4+
import { Table } from 'react-bootstrap';
5+
import { defaultMemoize } from 'reselect';
6+
7+
import DateTime from '../../widgets/DateTime';
8+
import Button from '../../widgets/TheButton';
9+
import { VisibleIcon } from '../../icons';
10+
11+
const sortExams = defaultMemoize(exams => {
12+
const sorted = [...exams];
13+
return sorted.sort((a, b) => a.end - b.end);
14+
});
15+
16+
const GroupExamsTable = ({ exams = null, selected = null, setSelected = null }) =>
17+
exams && exams.length > 0 ? (
18+
<Table className="mb-0">
19+
<thead>
20+
<tr>
21+
<th />
22+
<th>
23+
<FormattedMessage id="app.groupExamsTable.begin" defaultMessage="Begun at" />
24+
</th>
25+
<th>
26+
<FormattedMessage id="app.groupExamsTable.end" defaultMessage="Ended at" />
27+
</th>
28+
<th>
29+
<FormattedMessage id="app.groupExamsTable.lockType" defaultMessage="Lock type" />
30+
</th>
31+
{setSelected && <th />}
32+
</tr>
33+
</thead>
34+
<tbody>
35+
{sortExams(exams).map((exam, idx) => (
36+
<tr key={exam.id} className={selected === exam.id ? 'table-primary' : ''}>
37+
<td className="text-bold">#{idx + 1}</td>
38+
<td>
39+
<DateTime unixts={exam.begin} showRelative showSeconds />
40+
</td>
41+
<td>
42+
<DateTime unixts={exam.end} showRelative showSeconds />
43+
</td>
44+
<td>
45+
<em>
46+
{exam.strict ? (
47+
<FormattedMessage id="app.groupExams.lockStrict" defaultMessage="strict" />
48+
) : (
49+
<FormattedMessage id="app.groupExams.lockRegular" defaultMessage="regular" />
50+
)}
51+
</em>
52+
</td>
53+
{setSelected && (
54+
<td>
55+
<Button
56+
size="xs"
57+
variant="primary"
58+
disabled={selected === exam.id}
59+
onClick={() => setSelected(exam.id)}>
60+
<VisibleIcon visible gapRight />
61+
<FormattedMessage id="app.groupExamsTable.selectButton" defaultMessage="Detail" />
62+
</Button>
63+
</td>
64+
)}
65+
</tr>
66+
))}
67+
</tbody>
68+
</Table>
69+
) : (
70+
<div className="text-center text-muted p-2">
71+
<em>
72+
<FormattedMessage id="app.groupExams.noPreviousExams" defaultMessage="There are no previous exams recorded." />
73+
</em>
74+
</div>
75+
);
76+
77+
GroupExamsTable.propTypes = {
78+
exams: PropTypes.array,
79+
selected: PropTypes.string,
80+
setSelected: PropTypes.func,
81+
};
82+
83+
export default GroupExamsTable;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import GroupExamsTable from './GroupExamsTable';
2+
export default GroupExamsTable;

src/locales/cs.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,10 @@
10921092
"app.groupExams.studentInfoStrict": "Navíc nebudete moct přistupovat k ostatním skupinám dokud budete v uzamčeném režimu.",
10931093
"app.groupExams.timeAccuracyWarning": "Lokální hodiny na vašem systému musí být dostatečně seřízené, jinak nemusí tato komponenta fungovat zcela správně.",
10941094
"app.groupExams.title": "Zkouškové termíny skupiny",
1095+
"app.groupExamsTable.begin": "Začala",
1096+
"app.groupExamsTable.end": "Skončila",
1097+
"app.groupExamsTable.lockType": "Typ zámku",
1098+
"app.groupExamsTable.selectButton": "Detail",
10951099
"app.groupInfo.title": "Podrobnosti a metadata skupiny",
10961100
"app.groupInvitationForm.expireAt": "Konec platnosti:",
10971101
"app.groupInvitationForm.expireAtExplanation": "Odkaz pozvánky bude rozpoznatelný ReCodExem i po uplynutí doby platnosti, ale studenti jej nebudou moci použít.",

src/locales/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,10 @@
10921092
"app.groupExams.studentInfoStrict": "Furthermore, you will not be able to access other groups until the exam lock expires.",
10931093
"app.groupExams.timeAccuracyWarning": "Your local system clock should be sufficiently synchronized or this component may not work properly.",
10941094
"app.groupExams.title": "Group Exam Terms",
1095+
"app.groupExamsTable.begin": "Begun at",
1096+
"app.groupExamsTable.end": "Ended at",
1097+
"app.groupExamsTable.lockType": "Lock type",
1098+
"app.groupExamsTable.selectButton": "Detail",
10951099
"app.groupInfo.title": "Group Details and Metadata",
10961100
"app.groupInvitationForm.expireAt": "Expire at:",
10971101
"app.groupInvitationForm.expireAtExplanation": "An invitation link will be still recognized by ReCodEx after the expiration date, but the students will not be allowed to use it.",

src/pages/GroupExams/GroupExams.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Page from '../../components/layout/Page';
1010
import { GroupNavigation } from '../../components/layout/Navigation';
1111
import Box from '../../components/widgets/Box';
1212
import GroupArchivedWarning from '../../components/Groups/GroupArchivedWarning';
13+
import GroupExamsTable from '../../components/Groups/GroupExamsTable';
1314
import { GroupExamsIcon } from '../../components/icons';
1415

1516
import { fetchGroup, fetchGroupIfNeeded, setExamPeriod, removeExamPeriod } from '../../redux/modules/groups';
@@ -70,17 +71,11 @@ class GroupExams extends Component {
7071
</Col>
7172

7273
<Col xs={12} xl={6}>
73-
<Box title={<FormattedMessage id="app.groupExams.listBoxTitle" defaultMessage="Previous exams" />}>
74-
{group.privateData.exams && group.privateData.exams.length > 0 ? null : (
75-
<div className="text-center text-muted p-2">
76-
<em>
77-
<FormattedMessage
78-
id="app.groupExams.noPreviousExams"
79-
defaultMessage="There are no previous exams recorded."
80-
/>
81-
</em>
82-
</div>
83-
)}
74+
<Box
75+
title={<FormattedMessage id="app.groupExams.listBoxTitle" defaultMessage="Previous exams" />}
76+
noPadding
77+
unlimitedHeight>
78+
<GroupExamsTable exams={group.privateData.exams} />
8479
</Box>
8580
</Col>
8681
</Row>

0 commit comments

Comments
 (0)