Skip to content

Commit fcbbae5

Browse files
author
Damion Dooley
committed
2 parents e95ef40 + 3692f99 commit fcbbae5

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lib/DataHarmonizer.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,13 @@ class DataHarmonizer {
372372
*
373373
* @param {String} file_name: File in templates/[current schema]/ to load.
374374
*/
375-
async openFile(file_name) {
375+
async openFile(file) {
376376
try {
377-
let contentBuffer = await readFileAsync(file_name);
378-
this.loadSpreadsheetData(contentBuffer);
377+
let contentBuffer = await readFileAsync(file);
378+
if (file.type === 'application/json') {
379+
console.log(JSON.parse(contentBuffer));
380+
this.loadDataObjects(JSON.parse(contentBuffer));
381+
} else this.loadSpreadsheetData(contentBuffer);
379382
} catch (err) {
380383
console.log(err);
381384
}
@@ -1892,7 +1895,6 @@ class DataHarmonizer {
18921895
for (let row in matrix) {
18931896
// NOTE: row is string! Adding offsets requires parseInt(row)
18941897
const hotRowPtr = parseInt(row); // + rowOffset;
1895-
console.log('row', row, hotRowPtr);
18961898
const hotRowBinCol = parseInt(col) + binOffset;
18971899
const hotRowNextCol = parseInt(col) + 1;
18981900
const value = matrix[row][col];

lib/Toolbar.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Toolbar {
7676
$fileInput.on('change', function () {
7777
const file = $fileInput[0].files[0];
7878
const ext = file.name.split('.').pop();
79-
const acceptedExts = ['xlsx', 'xls', 'tsv', 'csv'];
79+
const acceptedExts = ['xlsx', 'xls', 'tsv', 'csv', 'json'];
8080
if (!acceptedExts.includes(ext)) {
8181
const errMsg = `Only ${acceptedExts.join(', ')} files are supported`;
8282
$('#open-err-msg').text(errMsg);
@@ -107,7 +107,7 @@ class Toolbar {
107107
const baseName = $('#base-name-save-as-input').val();
108108
const ext = $('#file-ext-save-as-select').val();
109109
if (ext == 'json') {
110-
let data = dh.getDataObjects();
110+
let data = dh.getDataObjects(false);
111111
dh.runBehindLoadingScreen(exportJsonFile, [data, baseName, ext]);
112112
} else {
113113
let matrix = [...dh.getFlatHeaders(), ...dh.getTrimmedData()];

lib/toolbar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
>
2727
<input
2828
type="file"
29-
accept=".xlsx,.xls,.tsv,.csv"
29+
accept=".xlsx,.xls,.tsv,.csv,.json"
3030
class="form-control-file"
3131
id="open-file-input"
3232
/>

0 commit comments

Comments
 (0)