Skip to content

Commit

Permalink
Downloadable Results
Browse files Browse the repository at this point in the history
  • Loading branch information
jrjohnson committed Dec 13, 2024
1 parent 3815cfd commit d9522e5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<h2>{{t "general.results"}}</h2>
<div class="download">
<button type="button" {{on "click" (perform this.downloadReport)}} data-test-download>
<FaIcon @icon="download" />
{{#if this.finishedBuildingReport}}
<FaIcon @icon="check" />
{{else}}
<FaIcon @icon="download" />
{{/if}}
{{t "general.downloadResults"}}
</button>
</div>
Expand Down
24 changes: 22 additions & 2 deletions packages/frontend/app/components/reports/course-report-results.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -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;
});
}

0 comments on commit d9522e5

Please sign in to comment.