Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#11030] Batch download for session-table component #11066

Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2abf659
Set up services
teikjun Mar 26, 2021
a901197
Process download in batches partitioned by questionId
teikjun Mar 26, 2021
bd810d3
Refactor and fix lint issues
teikjun Mar 26, 2021
f167c8d
Refactor code
teikjun Mar 26, 2021
e17e590
Update snapshot test for instructor-home-page component
teikjun Mar 26, 2021
c267ea3
Merge branch 'master' into 11030-batch-download-for-session-table-com…
daongochieu2810 Mar 27, 2021
abbb5fa
Make requested changes
teikjun Mar 27, 2021
7afba36
Fix lint issues
teikjun Mar 27, 2021
a4b1620
Use outputData length instead of counter
teikjun Mar 28, 2021
5b7abbf
Add type definition to variable
teikjun Mar 28, 2021
19e1d16
Add newline
teikjun Mar 28, 2021
5c1b9ff
Merge branch 'master' into 11030-batch-download-for-session-table-com…
daongochieu2810 Mar 29, 2021
27a3fed
Merge branch 'master' into 11030-batch-download-for-session-table-com…
teikjun Apr 2, 2021
a4b9501
Merge branch 'master' into 11030-batch-download-for-session-table-com…
teikjun Apr 4, 2021
f94a8b5
Merge branch 'master' into 11030-batch-download-for-session-table-com…
teikjun Apr 6, 2021
b52e883
Merge branch 'master' into 11030-batch-download-for-session-table-com…
teikjun Apr 6, 2021
2ec7992
Merge branch 'master' into 11030-batch-download-for-session-table-com…
daongochieu2810 Apr 12, 2021
c6f34aa
Merge branch 'master' into 11030-batch-download-for-session-table-com…
daongochieu2810 Apr 12, 2021
d1b0dab
Merge branch 'master' into 11030-batch-download-for-session-table-com…
madanalogy Apr 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports[`InstructorHomePageComponent should snap when courses are still loading
isSendReminderLoading="false"
navigationService={[Function NavigationService]}
ngbModal={[Function NgbModal]}
progressBarService={[Function ProgressBarService]}
publishUnpublishRetryAttempts={[Function Number]}
router={[Function Router]}
simpleModalService={[Function SimpleModalService]}
Expand Down Expand Up @@ -85,6 +86,7 @@ exports[`InstructorHomePageComponent should snap with default fields 1`] = `
isSendReminderLoading="false"
navigationService={[Function NavigationService]}
ngbModal={[Function NgbModal]}
progressBarService={[Function ProgressBarService]}
publishUnpublishRetryAttempts={[Function Number]}
router={[Function Router]}
simpleModalService={[Function SimpleModalService]}
Expand Down Expand Up @@ -151,6 +153,7 @@ exports[`InstructorHomePageComponent should snap with one course with error load
isSendReminderLoading="false"
navigationService={[Function NavigationService]}
ngbModal={[Function NgbModal]}
progressBarService={[Function ProgressBarService]}
publishUnpublishRetryAttempts={[Function Number]}
router={[Function Router]}
simpleModalService={[Function SimpleModalService]}
Expand Down Expand Up @@ -305,6 +308,7 @@ exports[`InstructorHomePageComponent should snap with one course with one feedba
isSendReminderLoading="false"
navigationService={[Function NavigationService]}
ngbModal={[Function NgbModal]}
progressBarService={[Function ProgressBarService]}
publishUnpublishRetryAttempts={[Function Number]}
router={[Function Router]}
simpleModalService={[Function SimpleModalService]}
Expand Down Expand Up @@ -829,6 +833,7 @@ exports[`InstructorHomePageComponent should snap with one course with two feedba
isSendReminderLoading="false"
navigationService={[Function NavigationService]}
ngbModal={[Function NgbModal]}
progressBarService={[Function ProgressBarService]}
publishUnpublishRetryAttempts={[Function Number]}
router={[Function Router]}
simpleModalService={[Function SimpleModalService]}
Expand Down Expand Up @@ -1482,6 +1487,7 @@ exports[`InstructorHomePageComponent should snap with one course with unexpanded
isSendReminderLoading="false"
navigationService={[Function NavigationService]}
ngbModal={[Function NgbModal]}
progressBarService={[Function ProgressBarService]}
publishUnpublishRetryAttempts={[Function Number]}
router={[Function Router]}
simpleModalService={[Function SimpleModalService]}
Expand Down Expand Up @@ -1743,6 +1749,7 @@ exports[`InstructorHomePageComponent should snap with one course with unpopulate
isSendReminderLoading="false"
navigationService={[Function NavigationService]}
ngbModal={[Function NgbModal]}
progressBarService={[Function ProgressBarService]}
publishUnpublishRetryAttempts={[Function Number]}
router={[Function Router]}
simpleModalService={[Function SimpleModalService]}
Expand Down Expand Up @@ -2032,6 +2039,7 @@ exports[`InstructorHomePageComponent should snap with one course without feedbac
isSendReminderLoading="false"
navigationService={[Function NavigationService]}
ngbModal={[Function NgbModal]}
progressBarService={[Function ProgressBarService]}
publishUnpublishRetryAttempts={[Function Number]}
router={[Function Router]}
simpleModalService={[Function SimpleModalService]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FeedbackQuestionsService } from '../../../services/feedback-questions.s
import { FeedbackSessionsService } from '../../../services/feedback-sessions.service';
import { InstructorService } from '../../../services/instructor.service';
import { NavigationService } from '../../../services/navigation.service';
import { ProgressBarService } from '../../../services/progress-bar.service';
import { SimpleModalService } from '../../../services/simple-modal.service';
import { StatusMessageService } from '../../../services/status-message.service';
import { StudentService } from '../../../services/student.service';
Expand Down Expand Up @@ -84,10 +85,12 @@ export class InstructorHomePageComponent extends InstructorSessionModalPageCompo
studentService: StudentService,
instructorService: InstructorService,
tableComparatorService: TableComparatorService,
private simpleModalService: SimpleModalService,
simpleModalService: SimpleModalService,
daongochieu2810 marked this conversation as resolved.
Show resolved Hide resolved
progressBarService: ProgressBarService,
private courseService: CourseService) {
super(router, instructorService, statusMessageService, navigationService, feedbackSessionsService,
feedbackQuestionsService, tableComparatorService, ngbModal, studentService);
feedbackQuestionsService, tableComparatorService, ngbModal, simpleModalService,
progressBarService, studentService);
}

ngOnInit(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Router } from '@angular/router';
import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { saveAs } from 'file-saver';
import { from, Observable, of } from 'rxjs';
import { catchError, concatMap, finalize, last, switchMap } from 'rxjs/operators';
import { concat, from, Observable, of } from 'rxjs';
import { catchError, concatMap, finalize, last, switchMap, takeWhile } from 'rxjs/operators';
import { FeedbackQuestionsService } from '../../services/feedback-questions.service';
import { FeedbackSessionsService } from '../../services/feedback-sessions.service';
import { InstructorService } from '../../services/instructor.service';
import { NavigationService } from '../../services/navigation.service';
import { ProgressBarService } from '../../services/progress-bar.service';
import { SimpleModalService } from '../../services/simple-modal.service';
import { StatusMessageService } from '../../services/status-message.service';
import { TableComparatorService } from '../../services/table-comparator.service';
import {
Expand All @@ -21,6 +23,7 @@ import { SortBy, SortOrder } from '../../types/sort-properties';
import { CopySessionModalResult } from '../components/copy-session-modal/copy-session-modal-model';
import { ErrorReportComponent } from '../components/error-report/error-report.component';
import { CopySessionResult, SessionsTableRowModel } from '../components/sessions-table/sessions-table-model';
import { SimpleModalType } from '../components/simple-modal/simple-modal-type';
import { ErrorMessageOutput } from '../error-message-output';

/**
Expand All @@ -41,7 +44,9 @@ export abstract class InstructorSessionBasePageComponent {
protected feedbackSessionsService: FeedbackSessionsService,
protected feedbackQuestionsService: FeedbackQuestionsService,
protected tableComparatorService: TableComparatorService,
protected ngbModal: NgbModal) { }
protected ngbModal: NgbModal,
protected simpleModalService: SimpleModalService,
protected progressBarService: ProgressBarService) { }

/**
* Copies a feedback session.
Expand Down Expand Up @@ -278,23 +283,65 @@ export abstract class InstructorSessionBasePageComponent {
* Downloads the result of a feedback session in csv.
*/
downloadSessionResult(model: SessionsTableRowModel): void {
this.feedbackQuestionsService.getFeedbackQuestions({
courseId: model.feedbackSession.courseId,
feedbackSessionName: model.feedbackSession.feedbackSessionName,
intent: Intent.INSTRUCTOR_RESULT,
}).subscribe((feedbackQuestions: FeedbackQuestions) => {
const questions: FeedbackQuestion[] = feedbackQuestions.questions;
this.downloadSessionResultHelper(questions, model);
});
}

downloadSessionResultHelper(questions: FeedbackQuestion[], model: SessionsTableRowModel): void {
this.isResultActionLoading = true;
const filename: string =
`${model.feedbackSession.courseId}_${model.feedbackSession.feedbackSessionName}_result.csv`;
let blob: any;
let downloadAborted: boolean = false;
const outputData: string[] = [];

const modalContent: string = 'Downloading the results of your feedback session...';
const loadingModal: NgbModalRef = this.simpleModalService.openLoadingModal(
'Download Progress', SimpleModalType.LOAD, modalContent);
loadingModal.result.then(() => {
this.isResultActionLoading = false;
downloadAborted = true;
});

this.feedbackSessionsService.downloadSessionResults(
model.feedbackSession.courseId,
model.feedbackSession.feedbackSessionName,
Intent.INSTRUCTOR_RESULT,
true,
true,
) .pipe(finalize(() => this.isResultActionLoading = false))
.subscribe((resp: string) => {
blob = new Blob([resp], { type: 'text/csv' });
saveAs(blob, filename);
}, (resp: ErrorMessageOutput) => {
this.statusMessageService.showErrorToast(resp.error.message);
concat(
...questions.map((question: FeedbackQuestion) =>
this.feedbackSessionsService.downloadSessionResults(
model.feedbackSession.courseId,
model.feedbackSession.feedbackSessionName,
Intent.INSTRUCTOR_RESULT,
true,
true,
question.feedbackQuestionId,
),
),
).pipe(finalize(() => this.isResultActionLoading = false))
.pipe(takeWhile(() => this.isResultActionLoading && !downloadAborted))
.subscribe({
next: (resp: string) => {
outputData.push(resp);
const numberOfQuestionsDownloaded: number = outputData.length;
const totalNumberOfQuestions: number = questions.length;
const progressPercentage: number = Math.round(100 * numberOfQuestionsDownloaded / totalNumberOfQuestions);
this.progressBarService.updateProgress(progressPercentage);
},
complete: () => {
if (downloadAborted) {
return;
}
loadingModal.close();
blob = new Blob(outputData, { type: 'text/csv' });
saveAs(blob, filename);
},
error: (resp: ErrorMessageOutput) => {
this.statusMessageService.showErrorToast(resp.error.message);
loadingModal.close();
},
});
}

teikjun marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import { FeedbackSessionsService } from '../../../services/feedback-sessions.service';
import { InstructorService } from '../../../services/instructor.service';
import { NavigationService } from '../../../services/navigation.service';
import { ProgressBarService } from '../../../services/progress-bar.service';
import { SimpleModalService } from '../../../services/simple-modal.service';
import { StatusMessageService } from '../../../services/status-message.service';
import { StudentService } from '../../../services/student.service';
Expand Down Expand Up @@ -189,14 +190,16 @@ export class InstructorSessionEditPageComponent extends InstructorSessionBasePag
feedbackQuestionsService: FeedbackQuestionsService,
tableComparatorService: TableComparatorService,
ngbModal: NgbModal,
simpleModalService: SimpleModalService,
daongochieu2810 marked this conversation as resolved.
Show resolved Hide resolved
progressBarService: ProgressBarService,
private studentService: StudentService,
private courseService: CourseService,
private route: ActivatedRoute,
private timezoneService: TimezoneService,
private simpleModalService: SimpleModalService,
private changeDetectorRef: ChangeDetectorRef) {
super(router, instructorService, statusMessageService, navigationService,
feedbackSessionsService, feedbackQuestionsService, tableComparatorService, ngbModal);
feedbackSessionsService, feedbackQuestionsService, tableComparatorService,
ngbModal, simpleModalService, progressBarService);
}

ngOnInit(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { FeedbackQuestionsService } from '../../services/feedback-questions.serv
import { FeedbackSessionsService } from '../../services/feedback-sessions.service';
import { InstructorService } from '../../services/instructor.service';
import { NavigationService } from '../../services/navigation.service';
import { ProgressBarService } from '../../services/progress-bar.service';
import { SimpleModalService } from '../../services/simple-modal.service';
import { StatusMessageService } from '../../services/status-message.service';
import { StudentService } from '../../services/student.service';
import { TableComparatorService } from '../../services/table-comparator.service';
Expand Down Expand Up @@ -47,9 +49,12 @@ export abstract class InstructorSessionModalPageComponent extends InstructorSess
feedbackQuestionsService: FeedbackQuestionsService,
tableComparatorService: TableComparatorService,
ngbModal: NgbModal,
simpleModalService: SimpleModalService,
progressBarService: ProgressBarService,
protected studentService: StudentService) {
super(router, instructorService, statusMessageService, navigationService,
feedbackSessionsService, feedbackQuestionsService, tableComparatorService, ngbModal);
feedbackSessionsService, feedbackQuestionsService, tableComparatorService,
ngbModal, simpleModalService, progressBarService);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { FeedbackQuestionsService } from '../../../services/feedback-questions.s
import { FeedbackSessionsService, TemplateSession } from '../../../services/feedback-sessions.service';
import { InstructorService } from '../../../services/instructor.service';
import { NavigationService } from '../../../services/navigation.service';
import { ProgressBarService } from '../../../services/progress-bar.service';
import { SimpleModalService } from '../../../services/simple-modal.service';
import { StatusMessageService } from '../../../services/status-message.service';
import { StudentService } from '../../../services/student.service';
import { TableComparatorService } from '../../../services/table-comparator.service';
Expand Down Expand Up @@ -152,11 +154,14 @@ export class InstructorSessionsPageComponent extends InstructorSessionModalPageC
studentService: StudentService,
instructorService: InstructorService,
tableComparatorService: TableComparatorService,
simpleModalService: SimpleModalService,
progressBarService: ProgressBarService,
private courseService: CourseService,
private route: ActivatedRoute,
private timezoneService: TimezoneService) {
super(router, instructorService, statusMessageService, navigationService, feedbackSessionsService,
feedbackQuestionsService, tableComparatorService, ngbModalService, studentService);
feedbackQuestionsService, tableComparatorService, ngbModalService,
simpleModalService, progressBarService, studentService);
}

ngOnInit(): void {
Expand Down