From ccc300ac37f6ca063dd9e51e536a50d588ae49a3 Mon Sep 17 00:00:00 2001
From: Thisari Muthuwahandi <thisari.muthuwahandi@mni.thm.de>
Date: Mon, 8 Apr 2019 20:54:18 +0200
Subject: [PATCH] Improve export function

---
 .../comment-export/comment-export.component.ts    | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/app/components/creator/_dialogs/comment-export/comment-export.component.ts b/src/app/components/creator/_dialogs/comment-export/comment-export.component.ts
index 34b04cf14..cfe68e508 100644
--- a/src/app/components/creator/_dialogs/comment-export/comment-export.component.ts
+++ b/src/app/components/creator/_dialogs/comment-export/comment-export.component.ts
@@ -51,7 +51,13 @@ export class CommentExportComponent implements OnInit {
   }
 
   exportJson() {
-    const myBlob = new Blob([JSON.stringify(this.comments, null, 2)], { type: 'application/json' });
+    let jsonComments = JSON.parse(JSON.stringify(this.comments));
+    jsonComments.forEach(element => {
+      delete element.id;
+      delete element.roomId;
+      delete element.creatorId;
+    });
+    const myBlob = new Blob([JSON.stringify(jsonComments, null, 2)], { type: 'application/json' });
     const link = document.createElement('a');
     link.setAttribute('download', 'comments.json');
     link.href = window.URL.createObjectURL(myBlob);
@@ -60,11 +66,12 @@ export class CommentExportComponent implements OnInit {
 
   exportCsv(delimiter: string) {
     let csv: string;
-    const keyFields = Object.keys(this.comments[0]).map(i => `"${i}"`).join(delimiter) + '\r\n';
+    let keyFields = '';
     let valueFields = '';
+    keyFields = Object.keys(this.comments[0]).slice(3).join(delimiter) + '\r\n';
     this.comments.forEach(element => {
-      element.body = element.body.replace(/[\r\n]/g, ' ').replace(/"/g, '""');
-      valueFields += Object.values(element).map(i => `"${i}"`).join(delimiter) + '\r\n';
+      element.body = '"' + element.body.replace(/[\r\n]/g, ' ').replace(/"/g, '""') + '"';
+      valueFields += Object.values(element).slice(3).join(delimiter) + '\r\n';
     });
     csv = keyFields + valueFields;
     const myBlob = new Blob([csv], { type: 'text/csv' });
-- 
GitLab