Skip to content

Commit

Permalink
feat(analytics): excel export of reports table (#2691)
Browse files Browse the repository at this point in the history
  • Loading branch information
open-dynaMIX authored Apr 19, 2024
1 parent 18736dd commit 060f0db
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 17 deletions.
11 changes: 10 additions & 1 deletion packages/analytics/addon/components/ca-report-preview.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@
<UkSpinner @ratio={{1}} />
</div>
{{else}}
<table class="uk-table uk-table-divider uk-table-striped">
<UkButton
class="uk-button uk-button-primary uk-float-right uk-margin-small-top"
{{on "click" this.exportTable}}
>
{{t "caluma.analytics.preview.export"}}
</UkButton>
<table
class="uk-table uk-table-divider uk-table-striped"
id="reports-table"
>
<thead>
<tr>
{{#each this.data.value.headings as |header|}}
Expand Down
16 changes: 16 additions & 0 deletions packages/analytics/addon/components/ca-report-preview.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { action } from "@ember/object";
import { next } from "@ember/runloop";
import { inject as service } from "@ember/service";
import Component from "@glimmer/component";
import { tracked } from "@glimmer/tracking";
import { queryManager } from "ember-apollo-client";
import { task } from "ember-concurrency";
import { trackedTask } from "reactiveweb/ember-concurrency";
import * as XLSX from "xlsx";

import getAnalyticsResultsQuery from "@projectcaluma/ember-analytics/gql/queries/get-analytics-results.graphql";

Expand Down Expand Up @@ -58,4 +61,17 @@ export default class CaReportPreviewComponent extends Component {
}
return null;
}

@action
exportTable() {
next(() => {
const wb = XLSX.utils.table_to_book(
document.getElementById("reports-table"),
);
XLSX.writeFile(
wb,
`${new Date().toLocaleDateString()}_${this.args.slug}.xlsx`,
);
});
}
}
3 changes: 2 additions & 1 deletion packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"ember-uikit": "^9.1.1",
"ember-validated-form": "^7.0.1",
"graphql": "^15.8.0",
"reactiveweb": "^1.2.2"
"reactiveweb": "^1.2.2",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz"
},
"//": [
"TODO: remove obsolete dependency to `ember-data` which is only necessary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ module("Integration | Component | ca-report-preview", function (hooks) {
setupRenderingTest(hooks);
setupIntl(hooks);

test.skip("it renders", async function (assert) {
test("it renders", async function (assert) {
await render(hbs`<CaReportPreview />`);

assert
.dom(this.element)
.hasText(
"t:caluma.analytics.sections.table-preview:() t:caluma.analytics.preview.refresh:() t:caluma.analytics.preview.download:()",
);
assert.dom(this.element).hasText("t:caluma.analytics.preview.export:()");
assert.dom(this.element.querySelector("#reports-table")).exists();
});

todo("it renders table data", async function () {});
Expand Down
2 changes: 2 additions & 0 deletions packages/analytics/translations/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ caluma:
cases: Dossiers
work-items: Aufgaben
documents: Dokumente
preview:
export: Export
2 changes: 2 additions & 0 deletions packages/analytics/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ caluma:
cases: Cases
work-items: Work items
documents: Documents
preview:
export: Export
2 changes: 2 additions & 0 deletions packages/analytics/translations/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ caluma:
cases: Dossiers
work-items: Tâches
documents: Documents
preview:
export: Export
38 changes: 29 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 060f0db

Please sign in to comment.