Skip to content

Commit

Permalink
ads data download feature to course/instructor session types viz.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopfstedt committed Dec 5, 2024
1 parent a91fedf commit 80adf20
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
{{/if}}
{{#if (and (not @isIcon) this.hasData @showDataTable)}}
<div class="data-table" data-test-data-table>
<div class="table-actions" data-test-data-table-actions>
<button
type="button"
disabled={{not this.hasData}}
{{on "click" (perform this.downloadData)}}
data-test-download-data
>
<FaIcon @icon="download" /> {{t "general.download"}}
</button>
</div>
<table>
<thead>
<tr>
Expand Down Expand Up @@ -78,4 +88,4 @@
{{else}}
<LoadingSpinner />
{{/if}}
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import Component from '@glimmer/component';
import { filter, map } from 'rsvp';
import { htmlSafe } from '@ember/template';
import { restartableTask, timeout } from 'ember-concurrency';
import { dropTask, restartableTask, timeout } from 'ember-concurrency';
import { service } from '@ember/service';
import { cached, tracked } from '@glimmer/tracking';
import { TrackedAsyncData } from 'ember-async-data';
import { findById, mapBy, sortBy, uniqueValues } from 'ilios-common/utils/array-helpers';
import { action } from '@ember/object';
import PapaParse from 'papaparse';
import createDownloadFile from 'ilios-common/utils/create-download-file';
import { findById, mapBy, sortBy, uniqueValues } from 'ilios-common/utils/array-helpers';

export default class CourseVisualizeInstructorSessionTypeGraph extends Component {
@service router;
Expand Down Expand Up @@ -135,4 +137,21 @@ export default class CourseVisualizeInstructorSessionTypeGraph extends Component
);
this.tooltipContent = htmlSafe(uniqueValues(mapBy(meta.sessions, 'title')).sort().join(', '));
});

downloadData = dropTask(async () => {
const data = await this.getData(this.args.course, this.args.user);
const output = data.map((obj) => {
const rhett = {};
rhett[`${this.intl.t('general.sessionType')}`] = obj.meta.sessionType.title;
rhett[this.intl.t('general.sessions')] = mapBy(obj.meta.sessions, 'title').sort().join(', ');
rhett[this.intl.t('general.minutes')] = obj.data;
return rhett;
});
const csv = PapaParse.unparse(output);
createDownloadFile(
`ilios-course-${this.args.course.id}-instructor-${this.args.user.id}-session-types.csv`,
csv,
'text/csv',
);
});
}

0 comments on commit 80adf20

Please sign in to comment.