Skip to content

Commit

Permalink
ads data download feature to course/instructor vocab terms viz.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopfstedt committed Dec 5, 2024
1 parent 80adf20 commit dd3c328
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
Expand Up @@ -2,12 +2,14 @@ import Component from '@glimmer/component';
import { filter, map } from 'rsvp';
import { isEmpty } from '@ember/utils';
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 } 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 } from 'ilios-common/utils/array-helpers';

export default class CourseVisualizeInstructorTermGraph extends Component {
@service router;
Expand Down Expand Up @@ -156,4 +158,21 @@ export default class CourseVisualizeInstructorTermGraph extends Component {
);
this.tooltipContent = htmlSafe(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.term')}`] = obj.meta.term.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}-vocabulary-terms.csv`,
csv,
'text/csv',
);
});
}

0 comments on commit dd3c328

Please sign in to comment.