From ad9e06e31c8bb88eab0e3cf36feeeff1f362b684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=2E=20Schr=C3=B6ter?= Date: Fri, 26 Jan 2024 13:27:47 +0100 Subject: [PATCH 1/2] fixed subject id file decoding for csv files with only a single column --- src/lib/forms/StudyForm.svelte | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/lib/forms/StudyForm.svelte b/src/lib/forms/StudyForm.svelte index 592d160..e851112 100644 --- a/src/lib/forms/StudyForm.svelte +++ b/src/lib/forms/StudyForm.svelte @@ -90,34 +90,38 @@ if (el instanceof HTMLInputElement) { if(el.files && el.files.length > 0){ let file: File = el.files[0]; - parseFile(file).then((subjectList) => { - parsingError = ""; - studyProps.update((props) => { - return { + file.text().then((text) => { + let delimiter = text.includes(";") || text.includes(",") ? "" : " "; + parseFile(file, delimiter).then((subjectList) => { + parsingError = ""; + studyProps.update((props) => { + return { ...props, subjectList: subjectList, - }; - }); - }).catch((err) => { - parsingError = err; - studyProps.update((props) => { - return { + }; + }); + }).catch((err) => { + parsingError = err; + studyProps.update((props) => { + return { ...props, subjectList: [], - }; + }; + }); }); - }); + }) } } } - - function parseFile(file: File): Promise{ + + function parseFile(file: File, delimiter: String): Promise{ let subjectList: string [] = []; let err: string = ""; return new Promise((resolve, reject) => { Papa.parse(file, { header: true, skipEmptyLines: true, + delimiter: delimiter, complete: function(parsed: any) { let col = $studyProps.subjectColumn; if (col){ From 8ab730f92e95012ad7559e33332abcfdfdee0dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=2E=20Schr=C3=B6ter?= Date: Fri, 26 Jan 2024 20:08:43 +0100 Subject: [PATCH 2/2] added missing semicolon --- src/lib/forms/StudyForm.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/forms/StudyForm.svelte b/src/lib/forms/StudyForm.svelte index e851112..e5a2a74 100644 --- a/src/lib/forms/StudyForm.svelte +++ b/src/lib/forms/StudyForm.svelte @@ -88,7 +88,7 @@ // parse file content and set subject list to empty list in case of an error let el = document.getElementById('file'); if (el instanceof HTMLInputElement) { - if(el.files && el.files.length > 0){ + if(el.files && el.files.length > 0) { let file: File = el.files[0]; file.text().then((text) => { let delimiter = text.includes(";") || text.includes(",") ? "" : " "; @@ -109,7 +109,7 @@ }; }); }); - }) + }); } } }