From 0f054e6f46baac39f4e1766456aa70a9a71d2401 Mon Sep 17 00:00:00 2001 From: Damion Dooley Date: Wed, 7 Sep 2022 06:24:53 -0700 Subject: [PATCH 1/3] load json data file --- lib/DataHarmonizer.js | 11 ++++++++--- lib/Toolbar.js | 2 +- lib/toolbar.html | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/DataHarmonizer.js b/lib/DataHarmonizer.js index c944d29d..bada969b 100644 --- a/lib/DataHarmonizer.js +++ b/lib/DataHarmonizer.js @@ -372,10 +372,15 @@ class DataHarmonizer { * * @param {String} file_name: File in templates/[current schema]/ to load. */ - async openFile(file_name) { + async openFile(file) { try { - let contentBuffer = await readFileAsync(file_name); - this.loadSpreadsheetData(contentBuffer); + let contentBuffer = await readFileAsync(file); + if (file.type === "application/json") { + console.log(JSON.parse(contentBuffer)); + this.loadDataObjects(JSON.parse(contentBuffer)); + } + else + this.loadSpreadsheetData(contentBuffer); } catch (err) { console.log(err); } diff --git a/lib/Toolbar.js b/lib/Toolbar.js index 8135ead6..9bcf96f5 100644 --- a/lib/Toolbar.js +++ b/lib/Toolbar.js @@ -76,7 +76,7 @@ class Toolbar { $fileInput.on('change', function () { const file = $fileInput[0].files[0]; const ext = file.name.split('.').pop(); - const acceptedExts = ['xlsx', 'xls', 'tsv', 'csv']; + const acceptedExts = ['xlsx', 'xls', 'tsv', 'csv', 'json']; if (!acceptedExts.includes(ext)) { const errMsg = `Only ${acceptedExts.join(', ')} files are supported`; $('#open-err-msg').text(errMsg); diff --git a/lib/toolbar.html b/lib/toolbar.html index 4c198546..197b28ea 100644 --- a/lib/toolbar.html +++ b/lib/toolbar.html @@ -26,7 +26,7 @@ > From d8ccbca3fdbfb5990b46ef6876a5d71b9b42fb10 Mon Sep 17 00:00:00 2001 From: Damion Dooley Date: Wed, 7 Sep 2022 06:26:33 -0700 Subject: [PATCH 2/3] linting --- lib/DataHarmonizer.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/DataHarmonizer.js b/lib/DataHarmonizer.js index bada969b..68c52b00 100644 --- a/lib/DataHarmonizer.js +++ b/lib/DataHarmonizer.js @@ -375,12 +375,10 @@ class DataHarmonizer { async openFile(file) { try { let contentBuffer = await readFileAsync(file); - if (file.type === "application/json") { + if (file.type === 'application/json') { console.log(JSON.parse(contentBuffer)); this.loadDataObjects(JSON.parse(contentBuffer)); - } - else - this.loadSpreadsheetData(contentBuffer); + } else this.loadSpreadsheetData(contentBuffer); } catch (err) { console.log(err); } From 4d8f36d260e9dd5986ce4f621d88b141a55c5fda Mon Sep 17 00:00:00 2001 From: Damion Dooley Date: Wed, 7 Sep 2022 16:23:09 -0700 Subject: [PATCH 3/3] preserve dates as strings in JSON file Other values also taken as strings as well. This is a result of user "save as ...." option. --- lib/DataHarmonizer.js | 1 - lib/Toolbar.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/DataHarmonizer.js b/lib/DataHarmonizer.js index 68c52b00..a7b6b34a 100644 --- a/lib/DataHarmonizer.js +++ b/lib/DataHarmonizer.js @@ -1895,7 +1895,6 @@ class DataHarmonizer { for (let row in matrix) { // NOTE: row is string! Adding offsets requires parseInt(row) const hotRowPtr = parseInt(row); // + rowOffset; - console.log('row', row, hotRowPtr); const hotRowBinCol = parseInt(col) + binOffset; const hotRowNextCol = parseInt(col) + 1; const value = matrix[row][col]; diff --git a/lib/Toolbar.js b/lib/Toolbar.js index 9bcf96f5..9d3c835a 100644 --- a/lib/Toolbar.js +++ b/lib/Toolbar.js @@ -107,7 +107,7 @@ class Toolbar { const baseName = $('#base-name-save-as-input').val(); const ext = $('#file-ext-save-as-select').val(); if (ext == 'json') { - let data = dh.getDataObjects(); + let data = dh.getDataObjects(false); dh.runBehindLoadingScreen(exportJsonFile, [data, baseName, ext]); } else { let matrix = [...dh.getFlatHeaders(), ...dh.getTrimmedData()];