Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unicode Support for Exports #5889

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/frontend/public/static/export/template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{{exportType}} Report</title>
<style>
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/src/components/global/ExportCSVModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export default class ExportCSVModal extends Vue {
return null;
});
Promise.all(fileConvertPromises)
.then(() => saveSingleOrMultipleFiles(this.files, 'csv'))
.then(() => saveSingleOrMultipleFiles(this.files, 'csv', true))
.finally(() => {
this.closeModal();
});
Expand Down
9 changes: 7 additions & 2 deletions apps/frontend/src/components/global/ExportHTMLModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@

<script lang="ts">
import LinkItem from '@/components/global/sidebaritems/IconLinkItem.vue';
import {s2ab} from '@/utilities/export_util';
import {saveAs} from 'file-saver';
import Vue from 'vue';
import Component from 'vue-class-component';
Expand Down Expand Up @@ -161,7 +160,13 @@ export default class ExportHTMLModal extends Vue {
);

saveAs(
new Blob([s2ab(body)], {type: 'application/octet-stream'}),
new Blob(
[
new Uint8Array([0xef, 0xbb, 0xbf]), // Insert UTF-8 BOM
body
],
{type: 'text/html;charset=utf-8'}
),
`${this.exportType}_Report_${new Date().toString()}.html`.replace(
/[ :]/g,
'_'
Expand Down
22 changes: 19 additions & 3 deletions apps/frontend/src/utilities/export_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,31 @@ type File = {
};
export async function saveSingleOrMultipleFiles(
files: File[],
filetype: string
filetype: string,
insertBOM: boolean = false
) {
if (files.length === 1) {
const blob = new Blob([files[0].data]);
let blob: Blob;
// Insert BOM to force UTF-8 encoding
if (insertBOM) {
blob = new Blob([new Uint8Array([0xef, 0xbb, 0xbf]), files[0].data]);
} else {
blob = new Blob([files[0].data]);
}
saveAs(blob, cleanUpFilename(`${files[0]?.filename}`));
} else {
const zipfile = new ZipFile();
files.forEach((file) => {
const buffer = Buffer.from(file.data);
let buffer: Buffer;
// Insert BOM to force UTF-8 encoding
if (insertBOM) {
buffer = Buffer.concat([
Buffer.from(new Uint8Array([0xef, 0xbb, 0xbf])),
Buffer.from(file.data)
]);
} else {
buffer = Buffer.from(file.data);
}
zipfile.addFile(file.filename, buffer);
});
const blob = new Blob([zipfile.toBuffer()]);
Expand Down
Loading