diff --git a/lib/DataHarmonizer.js b/lib/DataHarmonizer.js index c944d29d..a7b6b34a 100644 --- a/lib/DataHarmonizer.js +++ b/lib/DataHarmonizer.js @@ -372,10 +372,13 @@ 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); } @@ -1892,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 8135ead6..9d3c835a 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); @@ -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()]; 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 @@ >