Skip to content

Commit

Permalink
feat: disable attempt button if passed and add button to review lates…
Browse files Browse the repository at this point in the history
…t attempt in card
  • Loading branch information
satikaj committed Jun 11, 2024
1 parent 5def11c commit 703563c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@
mat-stroked-button
(click)="launchScormPlayer()"
[hidden]="attemptsLeft === 0"
[disabled]="user.isStaff"
[disabled]="user.isStaff || checkIfPassed()"
>
<mat-icon style="width: 20px; height: 20px; font-size: 20px" aria-label="Launch icon">
launch
</mat-icon>
Attempt test
</button>
<button
mat-stroked-button
(click)="reviewLatestCompletedAttempt()"
[hidden]="(!user.isStaff && !task.definition.scormAllowReview) || !latestCompletedAttempt"
>
Review last attempt
</button>
<button
mat-stroked-button
(click)="requestExtraAttempt()"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,83 @@
import {Component, Input, OnChanges, SimpleChanges} from '@angular/core';
import {Task, User, UserService} from 'src/app/api/models/doubtfire-model';
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {
Task,
TestAttempt,
TestAttemptService,
User,
UserService,
} from 'src/app/api/models/doubtfire-model';
import {ScormExtensionModalService} from 'src/app/common/modals/scorm-extension-modal/scorm-extension-modal.service';

@Component({
selector: 'f-task-scorm-card',
templateUrl: './task-scorm-card.component.html',
styleUrls: ['./task-scorm-card.component.scss'],
})
export class TaskScormCardComponent implements OnChanges {
export class TaskScormCardComponent implements OnInit, OnChanges {
@Input() task: Task;
attemptsLeft: number;
latestCompletedAttempt: TestAttempt;
user: User;

constructor(
private extensions: ScormExtensionModalService,
private testAttemptService: TestAttemptService,
private userService: UserService,
) {
this.user = userService.currentUser;
this.user = this.userService.currentUser;
}

ngOnInit() {
this.refreshAttemptData();
}

ngOnChanges(changes: SimpleChanges) {
if (changes.task && changes.task.currentValue) {
this.attemptsLeft = undefined;
this.getAttemptsLeft();
this.refreshAttemptData();
}
}

refreshAttemptData(): void {
this.attemptsLeft = undefined;
this.getAttemptsLeft();
this.latestCompletedAttempt = undefined;
this.testAttemptService.getLatestCompletedAttempt(this.task).subscribe((attempt) => {
this.latestCompletedAttempt = attempt;
});
}

getAttemptsLeft(): void {
if (this.task.definition.scormAttemptLimit != 0) {
this.task.fetchTestAttempts().subscribe((attempts) => {
let count = attempts.length;
if (count > 0 && attempts[0].terminated === false) count--;
this.attemptsLeft = this.task.definition.scormAttemptLimit + this.task.scormExtensions - count;
this.attemptsLeft =
this.task.definition.scormAttemptLimit + this.task.scormExtensions - count;
});
}
}

checkIfPassed(): boolean {
if (this.latestCompletedAttempt) {
return this.latestCompletedAttempt.successStatus;
}
return false;
}

launchScormPlayer(): void {
window.open(
`#/projects/${this.task.project.id}/task_def_id/${this.task.taskDefId}/scorm-player/normal`,
'_blank',
);
}

reviewLatestCompletedAttempt(): void {
window.open(
`#/task_def_id/${this.task.taskDefId}/scorm-player/review/${this.latestCompletedAttempt.id}`,
'_blank',
);
}

requestExtraAttempt(): void {
this.extensions.show(this.task, () => {
this.task.refresh();
Expand Down

0 comments on commit 703563c

Please sign in to comment.