@@ -11,6 +11,8 @@ export class ExamModeUI extends UIScreen {
1111 private _examMode : boolean = false ;
1212 private _examIds : number [ ] = [ ] ;
1313 private _loginScreen : LoginScreenUI ;
14+ private _examStartButtonEnableInterval : ReturnType < typeof setInterval > | null = null ;
15+ private _examStartTime = new Date ( "2099-01-01T00:00:00Z" ) ; // Set to a future date so that the button is disabled by default
1416 protected _events : AuthenticatorEvents = {
1517 authenticationStart : ( ) => {
1618 this . _disableForm ( ) ;
@@ -43,6 +45,7 @@ export class ExamModeUI extends UIScreen {
4345 examStartText : document . getElementById ( 'exam-mode-start' ) as HTMLSpanElement ,
4446 examEndText : document . getElementById ( 'exam-mode-end' ) as HTMLSpanElement ,
4547 examStartButton : document . getElementById ( 'exam-mode-start-button' ) as HTMLButtonElement ,
48+ examStartTimer : document . getElementById ( 'exam-mode-start-timer' ) as HTMLParagraphElement ,
4649 } as UIExamModeElements ;
4750
4851 this . _initForm ( ) ;
@@ -100,6 +103,16 @@ export class ExamModeUI extends UIScreen {
100103 } ) ;
101104 }
102105
106+ private _clearExamStartTimer ( ) : void {
107+ const form = this . _form as UIExamModeElements ;
108+ if ( this . _examStartButtonEnableInterval ) {
109+ clearTimeout ( this . _examStartButtonEnableInterval ) ;
110+ this . _examStartButtonEnableInterval = null ;
111+ }
112+ form . examStartTimer . innerText = "Click the arrow below to start your exam." ;
113+ this . _enableOrDisableSubmitButton ( ) ;
114+ }
115+
103116 private _populateData ( examsToPopulate : ExamForHost [ ] ) : void {
104117 const form = this . _form as UIExamModeElements ;
105118
@@ -108,6 +121,9 @@ export class ExamModeUI extends UIScreen {
108121 form . examProjectsText . innerText = '' ;
109122 form . examStartText . innerText = 'unknown' ;
110123 form . examEndText . innerText = 'unknown' ;
124+ // Clear the timeout for the exam start button and disable it
125+ this . _examStartTime = new Date ( "2099-01-01T00:00:00Z" ) ;
126+ this . _clearExamStartTimer ( ) ;
111127 }
112128 else {
113129 // Find all exams in the data.json file that match the ids in the exams variable
@@ -144,14 +160,42 @@ export class ExamModeUI extends UIScreen {
144160 form . examProjectsText . innerText = projectsText ;
145161 form . examStartText . innerText = earliestExam . toLocaleTimeString ( "en-NL" , { hour : '2-digit' , minute : '2-digit' } ) ;
146162 form . examEndText . innerText = latestExam . toLocaleTimeString ( "en-NL" , { hour : '2-digit' , minute : '2-digit' } ) ;
163+
164+ // Enable or disable the exam start button based on the current time
165+ this . _clearExamStartTimer ( ) ;
166+ this . _examStartTime = earliestExam ;
167+ this . _enableOrDisableSubmitButton ( ) ;
168+ if ( this . _examStartTime . getTime ( ) > Date . now ( ) ) {
169+ this . _examStartButtonEnableInterval = setInterval ( ( ) => {
170+ const timeLeft = Math . floor ( ( this . _examStartTime . getTime ( ) - Date . now ( ) ) / 1000 ) ;
171+ const minutes = Math . floor ( timeLeft / 60 ) ;
172+ const seconds = timeLeft % 60 ;
173+ const formattedTime = `${ ( minutes > 0 ? `${ minutes } minutes and ` : '' ) } ${ seconds } seconds` ;
174+ form . examStartTimer . innerText = `You may start your exam in ${ formattedTime } .` ;
175+
176+ if ( this . _examStartTime . getTime ( ) <= Date . now ( ) ) {
177+ // Clear the timer and enable the button
178+ this . _clearExamStartTimer ( ) ;
179+ return ;
180+ }
181+ } , 1000 ) ;
182+ }
147183 }
148184 }
149185
150186 // Returns true if the exam-start button is disabled, false otherwise
151187 protected _enableOrDisableSubmitButton ( ) : boolean {
152188 const form = this . _form as UIExamModeElements ;
153- form . examStartButton . disabled = false ; // Always enable the button
154- return false ;
189+ const buttonDisabled = this . _examStartTime . getTime ( ) > Date . now ( ) ; // Disable the button if the exam start time is in the future
190+ form . examStartButton . disabled = buttonDisabled ;
191+ if ( ! buttonDisabled ) {
192+ form . examStartTimer . innerText = "Click the arrow below to start your exam." ;
193+ const focusInput = this . _getInputToFocusOn ( ) ;
194+ if ( focusInput ) {
195+ focusInput . focus ( ) ;
196+ }
197+ }
198+ return buttonDisabled ;
155199 }
156200
157201 protected _wigglePasswordInput ( clearInput : boolean = true ) : void {
0 commit comments