|
1 | 1 | import React, { Component } from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | | -import { FormattedMessage, injectIntl } from 'react-intl'; |
4 | | -import { Modal } from 'react-bootstrap'; |
5 | | - |
6 | | -import ExamForm, { |
7 | | - prepareInitValues as prepareExamInitValues, |
8 | | - transformSubmittedData as transformExamData, |
9 | | -} from '../../forms/ExamForm'; |
10 | | -import Button, { TheButtonGroup } from '../../widgets/TheButton'; |
| 3 | +import { FormattedMessage } from 'react-intl'; |
| 4 | + |
| 5 | +import ExamLockButtonContainer from '../../../containers/ExamLockButtonContainer'; |
11 | 6 | import Callout from '../../widgets/Callout'; |
12 | | -import Icon, { BanIcon, ClockIcon, EditIcon, GroupExamsIcon, LoadingIcon } from '../../icons'; |
| 7 | +import { InfoIcon, GroupExamsIcon } from '../../icons'; |
13 | 8 | import DateTime from '../../widgets/DateTime'; |
14 | 9 | import Explanation from '../../widgets/Explanation'; |
15 | | -import { getErrorMessage } from '../../../locales/apiErrorMessages'; |
16 | 10 |
|
17 | | -import { hasPermissions } from '../../../helpers/common'; |
| 11 | +import { isStudentRole } from '../../helpers/usersRoles'; |
18 | 12 |
|
19 | 13 | const REFRESH_INTERVAL = 1; // [s] |
20 | 14 |
|
@@ -54,47 +48,157 @@ class GroupExamPending extends Component { |
54 | 48 |
|
55 | 49 | render() { |
56 | 50 | const { |
| 51 | + id, |
57 | 52 | privateData: { examBegin, examEnd, examLockStrict }, |
58 | | - currentUser, |
| 53 | + currentUser: { |
| 54 | + privateData: { groupLock, isGroupLockStrict, ipLock, role }, |
| 55 | + }, |
59 | 56 | } = this.props; |
| 57 | + const isStudent = isStudentRole(role); |
60 | 58 |
|
61 | | - //console.log(currentUser); |
62 | 59 | return ( |
63 | 60 | this.state.isExam && ( |
64 | | - <Callout |
65 | | - variant={this.state.examInProgress ? 'danger' : this.state.hasExam ? 'warning' : 'secondary'} |
66 | | - icon={ |
67 | | - this.state.examInProgress ? ( |
68 | | - <GroupExamsIcon className="fa-beat" /> |
69 | | - ) : this.state.hasExam ? ( |
70 | | - <ClockIcon /> |
71 | | - ) : null |
72 | | - }> |
73 | | - TODO |
74 | | - {this.state.hasExam && ( |
75 | | - <table> |
| 61 | + <Callout variant={isStudent && !groupLock ? 'danger' : 'warning'} icon={<GroupExamsIcon />}> |
| 62 | + <h4> |
| 63 | + {isStudent && groupLock ? ( |
| 64 | + <FormattedMessage |
| 65 | + id="app.groupExams.pending.studentLockedTitle" |
| 66 | + defaultMessage="You are locked in for an exam" |
| 67 | + /> |
| 68 | + ) : ( |
| 69 | + <FormattedMessage |
| 70 | + id="app.groupExams.inProgress" |
| 71 | + defaultMessage="Exam in progress, the group is in secured mode" |
| 72 | + /> |
| 73 | + )} |
| 74 | + </h4> |
| 75 | + |
| 76 | + {isStudent ? ( |
| 77 | + <> |
| 78 | + {groupLock ? ( |
| 79 | + <> |
| 80 | + <div className="mb-1"> |
| 81 | + <strong className="mr-2"> |
| 82 | + <FormattedMessage id="app.groupExams.endAtLong" defaultMessage="Exam ends at" />: |
| 83 | + </strong> |
| 84 | + <DateTime unixts={examEnd} showRelative /> |
| 85 | + </div> |
| 86 | + |
| 87 | + <div className="text-muted mb-1"> |
| 88 | + <FormattedMessage |
| 89 | + id="app.groupExams.lockedStudentInfo" |
| 90 | + defaultMessage="You may now see and submit solutions to exam assignments." |
| 91 | + />{' '} |
| 92 | + {isGroupLockStrict ? ( |
| 93 | + <FormattedMessage |
| 94 | + id="app.groupExams.lockedStudentInfoStrict" |
| 95 | + defaultMessage="You may not access any other groups until the exam lock expires." |
| 96 | + /> |
| 97 | + ) : ( |
| 98 | + <FormattedMessage |
| 99 | + id="app.groupExams.lockedStudentInfoRegular" |
| 100 | + defaultMessage="You may access other groups in read-only mode until the exam lock expires." |
| 101 | + /> |
| 102 | + )} |
| 103 | + </div> |
| 104 | + |
| 105 | + {ipLock && ( |
| 106 | + <div className="text-muted mb-1"> |
| 107 | + <FormattedMessage |
| 108 | + id="app.groupExams.ipLockInfo" |
| 109 | + defaultMessage="Your actions are restricted to IP address [{ipLock}] until the exam lock expires. Contact your exam supervisor if you require relocation." |
| 110 | + values={{ ipLock: <code>{ipLock}</code> }} |
| 111 | + /> |
| 112 | + </div> |
| 113 | + )} |
| 114 | + </> |
| 115 | + ) : ( |
| 116 | + <table> |
| 117 | + <tbody> |
| 118 | + <tr> |
| 119 | + <td className="pr-5"> |
| 120 | + <ExamLockButtonContainer groupId={id} size="lg" /> |
| 121 | + </td> |
| 122 | + <td> |
| 123 | + <div className="mb-1"> |
| 124 | + <strong className="mr-2"> |
| 125 | + <FormattedMessage id="app.groupExams.endAtLong" defaultMessage="Exam ends at" />: |
| 126 | + </strong> |
| 127 | + <DateTime unixts={examEnd} showRelative /> |
| 128 | + </div> |
| 129 | + |
| 130 | + <p className="text-muted small"> |
| 131 | + <InfoIcon gapRight /> |
| 132 | + <FormattedMessage |
| 133 | + id="app.groupExams.studentInfo" |
| 134 | + defaultMessage="You need to lock yourself in to see the exam assignments. When locked, your actions will be restricted to your current IP address." |
| 135 | + />{' '} |
| 136 | + {examLockStrict ? ( |
| 137 | + <FormattedMessage |
| 138 | + id="app.groupExams.studentInfoStrict" |
| 139 | + defaultMessage="Furthermore, you will not be able to access other groups until the exam lock expires." |
| 140 | + /> |
| 141 | + ) : ( |
| 142 | + <FormattedMessage |
| 143 | + id="app.groupExams.studentInfoRegular" |
| 144 | + defaultMessage="Furthermore, you will be able to access other groups in a read-only mode until the exam lock expires." |
| 145 | + /> |
| 146 | + )} |
| 147 | + </p> |
| 148 | + </td> |
| 149 | + </tr> |
| 150 | + </tbody> |
| 151 | + </table> |
| 152 | + )} |
| 153 | + |
| 154 | + <hr className="mb-1" /> |
| 155 | + <div className="text-muted small"> |
| 156 | + <FormattedMessage |
| 157 | + id="app.groupExams.timeAccuracyWarning" |
| 158 | + defaultMessage="Your local system clock should be sufficiently synchronized or this component may not work properly." |
| 159 | + /> |
| 160 | + </div> |
| 161 | + </> |
| 162 | + ) : ( |
| 163 | + <table className="w-100"> |
76 | 164 | <tbody> |
77 | 165 | <tr> |
78 | | - <td className="text-bold p-2"> |
| 166 | + <td className="text-bold text-nowrap"> |
79 | 167 | <FormattedMessage id="app.groupExams.beginAt" defaultMessage="Begins at" />: |
80 | 168 | </td> |
81 | | - <td> |
| 169 | + <td className="px-2 py-1 text-nowrap"> |
82 | 170 | <DateTime unixts={examBegin} showRelative /> |
83 | 171 | </td> |
| 172 | + <td rowSpan={3} className="w-100 p-2 pl-5 text-muted"> |
| 173 | + <p> |
| 174 | + <InfoIcon gapRight /> |
| 175 | + <FormattedMessage |
| 176 | + id="app.groupExams.pending.teacherInfo" |
| 177 | + defaultMessage="The exam assignments are currently visible only to students who have lock themselves in the group. " |
| 178 | + /> |
| 179 | + </p> |
| 180 | + <p> |
| 181 | + <InfoIcon gapRight /> |
| 182 | + <FormattedMessage |
| 183 | + id="app.groupExams.timeAccuracyWarning" |
| 184 | + defaultMessage="Your local system clock should be sufficiently synchronized or this component may not work properly." |
| 185 | + /> |
| 186 | + </p> |
| 187 | + </td> |
84 | 188 | </tr> |
85 | 189 | <tr> |
86 | | - <td className="text-bold p-2"> |
| 190 | + <td className="text-bold text-nowrap"> |
87 | 191 | <FormattedMessage id="app.groupExams.endAt" defaultMessage="Ends at" />: |
88 | 192 | </td> |
89 | | - <td> |
| 193 | + <td className="px-2 py-1 text-nowrap"> |
90 | 194 | <DateTime unixts={examEnd} showRelative /> |
91 | 195 | </td> |
92 | 196 | </tr> |
93 | 197 | <tr> |
94 | | - <td className="text-bold p-2"> |
| 198 | + <td className="text-bold text-nowrap"> |
95 | 199 | <FormattedMessage id="app.groupExams.locking" defaultMessage="Lock type" />: |
96 | 200 | </td> |
97 | | - <td> |
| 201 | + <td className="px-2 py-1 text-nowrap"> |
98 | 202 | <em> |
99 | 203 | {examLockStrict ? ( |
100 | 204 | <FormattedMessage id="app.groupExams.lockStrict" defaultMessage="strict" /> |
@@ -135,15 +239,21 @@ class GroupExamPending extends Component { |
135 | 239 | } |
136 | 240 |
|
137 | 241 | GroupExamPending.propTypes = { |
| 242 | + id: PropTypes.string.isRequired, |
138 | 243 | privateData: PropTypes.shape({ |
139 | 244 | examBegin: PropTypes.number, |
140 | 245 | examEnd: PropTypes.number, |
141 | 246 | examLockStrict: PropTypes.bool, |
142 | 247 | }).isRequired, |
143 | 248 | archived: PropTypes.bool, |
144 | | - currentUser: PropTypes.object, |
145 | | - //addNotification: PropTypes.func.isRequired, |
146 | | - intl: PropTypes.object, |
| 249 | + currentUser: PropTypes.shape({ |
| 250 | + privateData: PropTypes.shape({ |
| 251 | + ipLock: PropTypes.string, |
| 252 | + groupLock: PropTypes.string, |
| 253 | + isGroupLockStrict: PropTypes.bool, |
| 254 | + role: PropTypes.string, |
| 255 | + }).isRequired, |
| 256 | + }), |
147 | 257 | }; |
148 | 258 |
|
149 | | -export default injectIntl(GroupExamPending); |
| 259 | +export default GroupExamPending; |
0 commit comments