Skip to content

Commit

Permalink
adds data download feature to course vocabulary terms viz.
Browse files Browse the repository at this point in the history
  • Loading branch information
stopfstedt committed Nov 8, 2024
1 parent cafe151 commit 754e193
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,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 @@ -83,4 +93,4 @@
{{else}}
<LoadingSpinner />
{{/if}}
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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 { action } from '@ember/object';
import { TrackedAsyncData } from 'ember-async-data';
import PapaParse from 'papaparse';
import createDownloadFile from 'ilios-common/utils/create-download-file';
import { findById, mapBy } from 'ilios-common/utils/array-helpers';

export default class CourseVisualizeVocabularyGraph extends Component {
Expand Down Expand Up @@ -148,4 +150,21 @@ export default class CourseVisualizeVocabularyGraph extends Component {
}
this.router.transitionTo('course-visualize-term', this.args.course.id, obj.meta.term.id);
}

downloadData = dropTask(async () => {
const data = await this.getDataObjects(this.args.course, this.args.vocabulary.id);
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}-vocabulary-${this.args.vocabulary.id}`,
csv,
'text/csv',
);
});
}

0 comments on commit 754e193

Please sign in to comment.