Skip to content
Snippets Groups Projects
Commit e96bb01b authored by Tom Käsler's avatar Tom Käsler
Browse files

Merge branch 'fix-excel-export' into 'master'

Fix async handling and if-else

Closes #313

See merge request !275
parents a90f79c0 0b085330
Branches
Tags
1 merge request!275Fix async handling and if-else
Pipeline #27706 passed with stages
in 7 minutes and 46 seconds
...@@ -103,23 +103,23 @@ export class RoomEditComponent implements OnInit { ...@@ -103,23 +103,23 @@ export class RoomEditComponent implements OnInit {
this.commentService.getComments(this.editRoom.id) this.commentService.getComments(this.editRoom.id)
.subscribe(comments => { .subscribe(comments => {
this.comments = comments; this.comments = comments;
const exportComments = JSON.parse(JSON.stringify(this.comments));
let csv: string;
let keyFields = '';
let valueFields = '';
keyFields = Object.keys(exportComments[0]).slice(3).join(delimiter) + '\r\n';
exportComments.forEach(element => {
element.body = '"' + element.body.replace(/[\r\n]/g, ' ').replace(/ +/g, ' ').replace(/"/g, '""') + '"';
valueFields += Object.values(element).slice(3).join(delimiter) + '\r\n';
});
csv = keyFields + valueFields;
const myBlob = new Blob([csv], { type: 'text/csv' });
const link = document.createElement('a');
const fileName = 'comments_' + date + '.csv';
link.setAttribute('download', fileName);
link.href = window.URL.createObjectURL(myBlob);
link.click();
}); });
const exportComments = JSON.parse(JSON.stringify(this.comments));
let csv: string;
let keyFields = '';
let valueFields = '';
keyFields = Object.keys(exportComments[0]).slice(3).join(delimiter) + '\r\n';
exportComments.forEach(element => {
element.body = '"' + element.body.replace(/[\r\n]/g, ' ').replace(/ +/g, ' ').replace(/"/g, '""') + '"';
valueFields += Object.values(element).slice(3).join(delimiter) + '\r\n';
});
csv = keyFields + valueFields;
const myBlob = new Blob([csv], { type: 'text/csv' });
const link = document.createElement('a');
const fileName = 'comments_' + date + '.csv';
link.setAttribute('download', fileName);
link.href = window.URL.createObjectURL(myBlob);
link.click();
} }
onExport(exportType: string): void { onExport(exportType: string): void {
...@@ -129,8 +129,7 @@ export class RoomEditComponent implements OnInit { ...@@ -129,8 +129,7 @@ export class RoomEditComponent implements OnInit {
const timestamp = dateString + '_' + timeString; const timestamp = dateString + '_' + timeString;
if (exportType === 'comma') { if (exportType === 'comma') {
this.exportCsv(',', timestamp); this.exportCsv(',', timestamp);
} } else if (exportType === 'semicolon') {
if (exportType === 'semicolon') {
this.exportCsv(';', timestamp); this.exportCsv(';', timestamp);
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment