diff --git a/dist/Taskview/tasks/Details.d.ts b/dist/Taskview/tasks/Details.d.ts index 49b6aa5..bb2b91c 100644 --- a/dist/Taskview/tasks/Details.d.ts +++ b/dist/Taskview/tasks/Details.d.ts @@ -9,6 +9,7 @@ export declare class Details extends ATask { private eventID; private _entityName; private $lineUpContainer; + private lineup; supports(attributes: IAttribute[], cohorts: ICohort[]): boolean; showSearchBar(): boolean; show(columnHeader: HTMLDivElement, container: HTMLDivElement, attributes: IAttribute[], cohorts: ICohort[]): Promise; @@ -18,4 +19,6 @@ export declare class Details extends ATask { name: string; color: string; }[]; + close(): void; + download(): Promise; } diff --git a/dist/Taskview/tasks/Details.js b/dist/Taskview/tasks/Details.js index 072397d..28c2f62 100644 --- a/dist/Taskview/tasks/Details.js +++ b/dist/Taskview/tasks/Details.js @@ -1,4 +1,5 @@ import * as aq from 'arquero'; +import { select } from 'd3-selection'; import * as LineUpJS from 'lineupjs'; import { colors } from '../../colors'; import { getCohortData } from '../../rest'; @@ -27,7 +28,16 @@ export class Details extends ATask { if (cohorts.length > 0) { this.$lineUpContainer = this.body.append('div').classed('lineup-container', true).node(); this.$lineUpContainer.insertAdjacentElement('beforeend', getAnimatedLoadingText('data')); + select(columnHeader).selectAll('.export').remove(); const data = await this.getData(attributes, cohorts); + select(columnHeader).append('button') // add button after the data is available + .text('Export Data') + .attr('type', 'button') + .attr('title', 'Export to CSV') + .classed('btn btn-coral-prime export', true) + .style('width', '18rem').style('margin-left', '1rem').style('margin-right', '1rem') + .on('click', async () => this.download()); + columnHeader.insertAdjacentHTML('beforeend', ``); if (eventId !== this.eventID) { return; } @@ -106,13 +116,24 @@ export class Details extends ATask { builder.rowHeight(21); builder.singleSelection(); // only single selection possible this.$lineUpContainer.firstChild.remove(); - const lineup = builder.build(this.$lineUpContainer); + this.lineup = builder.build(this.$lineUpContainer); } getCategoryColorsForColumn(mergedDataArray, attr) { const uniqueCat = Array.from(new Set(mergedDataArray.map((elem) => elem[attr.dataKey]))); const categoryColors = uniqueCat.map((cat, i) => { return { name: cat, color: CohortColorSchema.get(i) }; }); - // log.debug('unique categories for "',attr.dataKey,'" : ', categoryColors); return categoryColors; } + close() { + super.close(); + select(this.$columnHeader).selectAll('.export').remove(); + } + async download() { + const data = await this.lineup.data.exportTable(this.lineup.data.getRankings()[0], { separator: ';' }); + const b = new Blob([data], { type: 'text/csv' }); + const downloadHelper = this.$columnHeader.querySelector('a#downloadHelper'); + downloadHelper.href = URL.createObjectURL(b); + downloadHelper.download = 'coral-cohorts.csv'; + downloadHelper.click(); + } } //# sourceMappingURL=Details.js.map \ No newline at end of file diff --git a/dist/Taskview/tasks/Details.js.map b/dist/Taskview/tasks/Details.js.map index 26207de..5b5b7a8 100644 --- a/dist/Taskview/tasks/Details.js.map +++ b/dist/Taskview/tasks/Details.js.map @@ -1 +1 @@ -{"version":3,"file":"Details.js","sourceRoot":"","sources":["../../../src/Taskview/tasks/Details.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAEpC,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,iBAAiB,EAAE,sBAAsB,EAAC,MAAM,YAAY,CAAC;AACrE,OAAO,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAC,UAAU,EAAC,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAE9B,MAAM,OAAO,OAAQ,SAAQ,KAAK;IAAlC;;QACS,UAAK,GAAG,eAAe,CAAC;QACxB,OAAE,GAAG,SAAS,CAAC;QACf,cAAS,GAAG,KAAK,CAAC;QACjB,YAAO,GAAG,CAAC,CAAC;QACZ,gBAAW,GAAW,IAAI,CAAC;IA6GrC,CAAC;IA1GC,QAAQ,CAAC,UAAwB,EAA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AC,CAAC;QACzF,MAAM,cAAc,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,GAAE,OAAO,EAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAC,CAAC,CAAA,CAAC,CAAC,CAAC;QACzG,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,KAAK;QACH,KAAK,CAAC,KAAK,EAAE,CAAC;QACd,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,EAAC,SAAS,EAAE,GAAG,EAAC,CAAC,CAAC;QACtG,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAC,IAAI,EAAE,UAAU,EAAC,CAAC,CAAC;QAE/C,MAAM,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,kBAAkB,CAAsB,CAAC;QACjG,cAAc,CAAC,IAAI,GAAG,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;QAC7C,cAAc,CAAC,QAAQ,GAAG,mBAAmB,CAAC;QAC9C,cAAc,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;CAEF"} \ No newline at end of file diff --git a/dist/scss/components/task/_details.scss b/dist/scss/components/task/_details.scss index baaf520..fb013ec 100644 --- a/dist/scss/components/task/_details.scss +++ b/dist/scss/components/task/_details.scss @@ -3,7 +3,7 @@ .lu-side-panel { // 20em is the value from the LineUpJs scss - width: 20em; // otherwise tdp_core/../_view_lineup.scss sets it to 100% + width: 20rem; // otherwise tdp_core/../_view_lineup.scss sets it to 100% &.lu-collapsed{ width: 0; } diff --git a/src/Taskview/tasks/Details.ts b/src/Taskview/tasks/Details.ts index fff0145..11857df 100644 --- a/src/Taskview/tasks/Details.ts +++ b/src/Taskview/tasks/Details.ts @@ -1,4 +1,5 @@ import * as aq from 'arquero'; +import {select} from 'd3-selection'; import * as LineUpJS from 'lineupjs'; import {Cohort} from '../../Cohort'; import {ICohort} from '../../CohortInterfaces'; @@ -17,6 +18,7 @@ export class Details extends ATask { private eventID = 0; private _entityName: string = null; private $lineUpContainer: HTMLDivElement; + private lineup: LineUpJS.LineUp; supports(attributes: IAttribute[], cohorts: ICohort[]) { return cohorts.length > 0; @@ -33,8 +35,17 @@ export class Details extends ATask { if (cohorts.length > 0) { this.$lineUpContainer = this.body.append('div').classed('lineup-container', true).node(); this.$lineUpContainer.insertAdjacentElement('beforeend', getAnimatedLoadingText('data')); + select(columnHeader).selectAll('.export').remove(); const data = await this.getData(attributes, cohorts as Cohort[]); + select(columnHeader).append('button') // add button after the data is available + .text('Export Data') + .attr('type', 'button') + .attr('title', 'Export to CSV') + .classed('btn btn-coral-prime export', true) + .style('width', '18rem').style('margin-left', '1rem').style('margin-right', '1rem') + .on('click', async () => this.download()); + columnHeader.insertAdjacentHTML('beforeend', ``); if (eventId !== this.eventID) {return;} this.createLineup(data, attributes, cohorts); } @@ -114,14 +125,29 @@ export class Details extends ATask { builder.rowHeight(21); builder.singleSelection(); // only single selection possible this.$lineUpContainer.firstChild.remove(); - const lineup = builder.build(this.$lineUpContainer); + this.lineup = builder.build(this.$lineUpContainer); } getCategoryColorsForColumn(mergedDataArray: any[], attr: IAttribute): {name: string, color: string}[] { const uniqueCat = Array.from(new Set(mergedDataArray.map((elem) => elem[attr.dataKey]))); const categoryColors = uniqueCat.map((cat, i) => {return {name: cat, color: CohortColorSchema.get(i)};}); - // log.debug('unique categories for "',attr.dataKey,'" : ', categoryColors); return categoryColors; } + + close() { + super.close(); + select(this.$columnHeader).selectAll('.export').remove(); + } + + async download() { + const data = await this.lineup.data.exportTable(this.lineup!.data.getRankings()[0], {separator: ';'}); + const b = new Blob([data], {type: 'text/csv'}); + + const downloadHelper = this.$columnHeader.querySelector('a#downloadHelper') as HTMLAnchorElement; + downloadHelper.href = URL.createObjectURL(b); + downloadHelper.download = 'coral-cohorts.csv'; + downloadHelper.click(); + } + } diff --git a/src/scss/components/task/_details.scss b/src/scss/components/task/_details.scss index baaf520..fb013ec 100644 --- a/src/scss/components/task/_details.scss +++ b/src/scss/components/task/_details.scss @@ -3,7 +3,7 @@ .lu-side-panel { // 20em is the value from the LineUpJs scss - width: 20em; // otherwise tdp_core/../_view_lineup.scss sets it to 100% + width: 20rem; // otherwise tdp_core/../_view_lineup.scss sets it to 100% &.lu-collapsed{ width: 0; }