Skip to content

Commit

Permalink
Merge pull request #355 from cidgoh/load-json
Browse files Browse the repository at this point in the history
WIP - Load json
  • Loading branch information
ddooley authored Sep 7, 2022
2 parents d5bf27a + 4d8f36d commit 3692f99
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/DataHarmonizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()];
Expand Down
2 changes: 1 addition & 1 deletion lib/toolbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
>
<input
type="file"
accept=".xlsx,.xls,.tsv,.csv"
accept=".xlsx,.xls,.tsv,.csv,.json"
class="form-control-file"
id="open-file-input"
/>
Expand Down

0 comments on commit 3692f99

Please sign in to comment.