Skip to content

Commit

Permalink
Resume exam at last unanswered question (connects #668) (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbert authored May 18, 2018
1 parent 1b3449b commit cf82bd1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/app/courses/courses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class CoursesService {
submission: any = { courseId: '', examId: '' };
private courseUpdated = new Subject<any[]>();
courseUpdated$ = this.courseUpdated.asObservable();
private submissionUpdated = new Subject<any[]>();
submissionUpdated$ = this.submissionUpdated.asObservable();
stepIndex: any;
returnUrl: string;

Expand Down Expand Up @@ -53,6 +55,7 @@ export class CoursesService {
} else {
this.newSubmission({ parentId, parent, user, type });
}
this.submissionUpdated.next(this.submission);
});
}

Expand Down
17 changes: 15 additions & 2 deletions src/app/courses/step-view-courses/courses-step-view.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CoursesService } from '../courses.service';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
import { Subject } from 'rxjs/Subject';
import { takeUntil } from 'rxjs/operators';
import { UserService } from '../../shared/user.service';

@Component({
templateUrl: './courses-step-view.component.html',
Expand All @@ -16,18 +17,30 @@ export class CoursesStepViewComponent implements OnInit, OnDestroy {
stepDetail: any = { stepTitle: '', description: '' };
maxStep = 1;
resourceUrl = '';
examStart = 1;

constructor(
private router: Router,
private route: ActivatedRoute,
private coursesService: CoursesService
private coursesService: CoursesService,
private userService: UserService
) { }

ngOnInit() {
this.coursesService.courseUpdated$.pipe(takeUntil(this.onDestroy$)).subscribe((course: any) => {
// To be readable by non-technical people stepNum param will start at 1
this.stepDetail = course.steps[this.stepNum - 1];
this.maxStep = course.steps.length;
if (this.stepDetail.exam) {
this.coursesService.openSubmission({
parentId: this.stepDetail.exam._id + '@' + course._id,
parent: this.stepDetail.exam,
user: this.userService.get().name,
type: 'exam' });
}
this.coursesService.submissionUpdated$.pipe(takeUntil(this.onDestroy$)).subscribe((submission: any) => {
this.examStart = submission.answers.length + 1;
});
});
this.route.paramMap.pipe(takeUntil(this.onDestroy$)).subscribe((params: ParamMap) => {
this.stepNum = +params.get('stepNum'); // Leading + forces string to number
Expand All @@ -54,7 +67,7 @@ export class CoursesStepViewComponent implements OnInit, OnDestroy {
}

goToExam() {
this.router.navigate([ 'exam', 1 ], { relativeTo: this.route });
this.router.navigate([ 'exam', this.examStart ], { relativeTo: this.route });
}

}

0 comments on commit cf82bd1

Please sign in to comment.