From d9522e5abca7400d2d22896b3b21771b6d46f7c2 Mon Sep 17 00:00:00 2001 From: Jonathan Johnson Date: Fri, 13 Dec 2024 13:40:23 -0800 Subject: [PATCH] Downloadable Results --- .../reports/course-report-results.hbs | 6 ++++- .../reports/course-report-results.js | 24 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/frontend/app/components/reports/course-report-results.hbs b/packages/frontend/app/components/reports/course-report-results.hbs index 1285d51039..f37a33f714 100644 --- a/packages/frontend/app/components/reports/course-report-results.hbs +++ b/packages/frontend/app/components/reports/course-report-results.hbs @@ -2,7 +2,11 @@

{{t "general.results"}}

diff --git a/packages/frontend/app/components/reports/course-report-results.js b/packages/frontend/app/components/reports/course-report-results.js index f860915fc8..5c1968b238 100644 --- a/packages/frontend/app/components/reports/course-report-results.js +++ b/packages/frontend/app/components/reports/course-report-results.js @@ -1,11 +1,13 @@ import Component from '@glimmer/component'; import { service } from '@ember/service'; import striptags from 'striptags'; +import PapaParse from 'papaparse'; +import { dropTask, timeout } from 'ember-concurrency'; +import createDownloadFile from 'frontend/utils/create-download-file'; export default class CourseReportResultsComponent extends Component { - @service store; - @service graphql; @service router; + @service intl; get results() { return this.args.data.map((o) => { @@ -35,4 +37,22 @@ export default class CourseReportResultsComponent extends Component { return a.sessionTitle.localeCompare(b.sessionTitle); }); } + + downloadReport = dropTask(async () => { + const data = this.sortedResults.map((o) => { + const rhett = {}; + rhett[this.intl.t('general.course')] = o.courseTitle; + rhett[this.intl.t('general.session')] = o.sessionTitle; + rhett[this.intl.t('general.sessionType')] = o.sessionType; + rhett[this.intl.t('general.objective')] = o.title; + rhett[this.intl.t('general.link')] = o.link; + + return rhett; + }); + const csv = PapaParse.unparse(data); + this.finishedBuildingReport = true; + createDownloadFile(`objectives.csv`, csv, 'text/csv'); + await timeout(2000); + this.finishedBuildingReport = false; + }); }