Skip to content

Commit

Permalink
Refactor create course's update of progress bar to reduce code duplic…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
domlimm committed Jul 26, 2022
1 parent 26c082e commit 5e50c39
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,20 +320,19 @@ export class InstructorCoursesPageComponent implements OnInit {
// Wrap in a Promise to wait for all feedback sessions to be copied
const promise: Promise<void> = new Promise<void>((resolve: () => void) => {
if (result.selectedFeedbackSessionList.size < 1) {
this.copyProgressPercentage = 1;
this.progressBarService.updateProgress(this.copyProgressPercentage);

this.updateProgressBarHandler(1);
resolve();

return;
}

result.selectedFeedbackSessionList.forEach((session: FeedbackSession) => {
this.copyFeedbackSession(session, result.newCourseId, result.oldCourseId)
.pipe(finalize(() => {
this.numberOfSessionsCopied += 1;
this.copyProgressPercentage =
Math.round(100 * this.numberOfSessionsCopied / this.totalNumberOfSessionsToCopy);
this.progressBarService.updateProgress(this.copyProgressPercentage);
this.updateProgressBarHandler(
Math.round(100 * this.numberOfSessionsCopied / this.totalNumberOfSessionsToCopy));

if (this.numberOfSessionsCopied === this.totalNumberOfSessionsToCopy) {
resolve();
}
Expand Down Expand Up @@ -361,6 +360,16 @@ export class InstructorCoursesPageComponent implements OnInit {
});
}

/**
* Updates progress bar using ProgressBarService.
* This is a helper function used by {@link InstructorCoursesPageComponent#createCourse()} to
* reduce code duplication.
*/
private updateProgressBarHandler(copyProgressPercentage: number): void {
this.copyProgressPercentage = copyProgressPercentage;
this.progressBarService.updateProgress(this.copyProgressPercentage);
}

/**
* Gets a CourseModel from courseID
*/
Expand Down

0 comments on commit 5e50c39

Please sign in to comment.