Skip to content

Commit

Permalink
feat(core/reports): html icons to text in csv/xlsx widget export
Browse files Browse the repository at this point in the history
  • Loading branch information
robzan8 authored and trik committed Jan 10, 2022
1 parent fc3b0e0 commit b211ce8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/core/reports/widget-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ export class AjfWidgetExport {
@Input() overlay = true;
@Input() enable = false;

private static _iconsMap: {[html: string]: string} = {};

/**
* Allows rendering html icons as text.
*/
static addIcons(icons: {[html: string]: string}) {
AjfWidgetExport._iconsMap = {...AjfWidgetExport._iconsMap, ...icons};
}

constructor() {}

/**
Expand Down Expand Up @@ -78,6 +87,7 @@ export class AjfWidgetExport {
}

private _buildXlsxData(): unknown[][] {
const iconsMap = AjfWidgetExport._iconsMap;
let xlsxData: unknown[][] = [];
let labels: string[] = [];
switch (this.widgetType) {
Expand Down Expand Up @@ -117,7 +127,11 @@ export class AjfWidgetExport {
isNewRowAfterRowspan = true;
}
tableData[i].forEach((elem: AjfTableCell, idxElem: number) => {
res.push(elem.value.changingThisBreaksApplicationSecurity);
let val = elem.value.changingThisBreaksApplicationSecurity;
if (iconsMap[val]) {
val = iconsMap[val];
}
res.push(val);

if (elem.colspan && elem.colspan > 1) {
for (let j = 1; j < elem.colspan; j++) {
Expand Down
3 changes: 3 additions & 0 deletions src/dev-app/mat-reports/reports-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import {
AjfReportInstance,
AjfReportSerializer,
AjfWidgetExport,
createReportInstance,
openReportPdf,
} from '@ajf/core/reports';
Expand Down Expand Up @@ -58,6 +59,8 @@ export class ReportsDemo {
_ts.setTranslation(engDict, 'ENG');
_ts.setDefaultLang('ENG');
this._populateReport();

AjfWidgetExport.addIcons({'3a': '3a export icon!'});
}

setReport(): void {
Expand Down
3 changes: 3 additions & 0 deletions tools/public_api_guard/core/reports.md
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ export type AjfWidgetCreate = Pick<AjfWidget, 'widgetType'> & Partial<AjfWidget>
// @public (undocumented)
export class AjfWidgetExport {
constructor();
static addIcons(icons: {
[html: string]: string;
}): void;
// (undocumented)
data: ChartData | AjfTableCell[][];
// (undocumented)
Expand Down

0 comments on commit b211ce8

Please sign in to comment.