Skip to content

Commit

Permalink
Fixed a bug that caused validation on displaying previously-submitted…
Browse files Browse the repository at this point in the history
… answers a little overzealous.
  • Loading branch information
sei-bstein committed Jan 3, 2024
1 parent fd6ae0f commit e779872
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions projects/gameboard-ui/src/app/game/game.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { GameIsStarted } from '@/guards/game-is-started.guard';
import { GamePageComponent } from './pages/game-page/game-page.component';
import { GamespaceQuizComponent } from './gamespace-quiz/gamespace-quiz.component';
import { HubStateToPlayerStatusPipe } from './pipes/hub-state-to-player-status.pipe';
import { IndexToSubmittedAnswersPipe } from './pipes/index-to-submitted-answers.pipe';
import { PlayComponent } from './components/play/play.component';
import { PlayerEnrollComponent } from './player-enroll/player-enroll.component';
import { PlayerPresenceComponent } from './player-presence/player-presence.component';
Expand All @@ -38,7 +39,6 @@ import { SessionStartCountdownComponent } from './components/session-start-count
import { TeamChallengeScoresToChallengeResultTypeCountPipe } from './pipes/team-challenge-scores-to-challenge-result-type-count.pipe';
import { UserIsPlayingGuard } from '@/guards/user-is-playing.guard';
import { UnityBoardComponent } from '../unity/unity-board/unity-board.component';
import { IndexToSubmittedAnswerPipe } from './pipes/index-to-submitted-answer.pipe';

const MODULE_DECLARATIONS = [
CertificateComponent,
Expand All @@ -50,6 +50,7 @@ const MODULE_DECLARATIONS = [
GameboardPageComponent,
GamespaceQuizComponent,
HubStateToPlayerStatusPipe,
IndexToSubmittedAnswersPipe,
PlayComponent,
PlayerEnrollComponent,
PlayerPresenceComponent,
Expand All @@ -73,7 +74,6 @@ const MODULE_DECLARATIONS = [
ScoreboardTeamDetailModalComponent,
ContinueToGameboardButtonComponent,
ExternalGameLinkBannerComponent,
IndexToSubmittedAnswerPipe,
],
imports: [
CommonModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<markdown [data]="state.challenge.sectionText"></markdown>

<div *ngFor="let q of state.challenge.questions; let i=index" class="form-group p-4 mt-4"
<div *ngFor="let q of state.challenge.questions; let i = index" class="form-group p-4 mt-4"
[class.pop-info]="!q.isGraded" [class.pop-success]="q.isGraded && q.isCorrect"
[class.pop-warning]="q.isGraded && !q.isCorrect">
<label>{{i+1}}. ({{q.weight}}) {{q.text}}</label>
Expand All @@ -28,7 +28,7 @@
<small>
<strong>Previous attempts: </strong>
<!--If the question has been answered correctly, don't show the last historical entry for it (because we display it above)-->
{{ i | indexToSubmittedAnswer:pastSubmissions:q.isCorrect }}
{{ i | indexToSubmittedAnswers:pastSubmissions:q.isCorrect }}
</small>
</div>
</div>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Pipe, PipeTransform } from '@angular/core';
import { ChallengeSubmissionViewModel } from '@/api/challenges.models';
import { unique } from 'projects/gameboard-ui/src/tools';

// takes the index of a challenge question (e.g. 1 = the second question of the challenge), returns a string which concatenates
// all unique answers submitted for the question
@Pipe({ name: 'indexToSubmittedAnswers' })
export class IndexToSubmittedAnswersPipe implements PipeTransform {
transform(questionIndex: number, submissions: ChallengeSubmissionViewModel[], hideLastResponse = false): string {
if (questionIndex < 0 || !submissions || !submissions.length)
throw new Error("Can't use IndexToSubmittedAnswer pipe without an index and submitted answers.");

// ensure that all submissions have at least as many answers as are required to retrieve the questionIndexth answer
const submissionLengths = submissions.map(s => s.answers.length);
if (submissionLengths.some(length => length <= questionIndex)) {
throw new Error(`Can't use IndexToSubmittedAnswer pipe with an out-of-range index (${questionIndex}, ${submissionLengths})`);
}

// the final submitted answer may be the correct answer (if they got the question right). We show that elsewhere, so hide
// it if requested
let displayedSubmissions = [...submissions];
if (hideLastResponse)
displayedSubmissions = displayedSubmissions.slice(0, displayedSubmissions.length - 1);

return unique(
displayedSubmissions
.map(submission => `${submission.answers[questionIndex] ? `"${submission.answers[questionIndex]}"` : "(no response)"}`)
).join(", ");
}
}

0 comments on commit e779872

Please sign in to comment.