Skip to content

Commit 54d4034

Browse files
JSON loading for multisheet data
1 parent 79eb101 commit 54d4034

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed

lib/DataHarmonizer.js

+43-36
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,44 @@ class DataHarmonizer {
11201120

11211121
/***************************** PRIVATE functions *************************/
11221122

1123+
/**
1124+
* Load data into table as an array of objects. The keys of each object are
1125+
* field names and the values are the cell values.
1126+
*
1127+
* @param {Array<Object>} data table data
1128+
*/
1129+
loadDataObjects(data) {
1130+
const fields = this.getFields();
1131+
if (typeof data === 'object' && !Array.isArray(data) && data !== null) {
1132+
// An object was provided, so try to pick out the grid data from
1133+
// one of it's fields.
1134+
const inferredIndexSlot = this.getInferredIndexSlot();
1135+
1136+
if (inferredIndexSlot) {
1137+
data = data[inferredIndexSlot];
1138+
} else {
1139+
const dataKeys = Object.keys(data);
1140+
if (dataKeys.length === 1) {
1141+
data = data[dataKeys[0]];
1142+
}
1143+
}
1144+
}
1145+
1146+
if (!Array.isArray(data)) {
1147+
console.warn('Unable to get grid data from input');
1148+
return;
1149+
}
1150+
const listData = data.map((row) =>
1151+
dataObjectToArray(row, fields, {
1152+
serializedDateFormat: this.dateExportBehavior,
1153+
dateFormat: this.dateFormat,
1154+
datetimeFormat: this.datetimeFormat,
1155+
timeFormat: this.timeFormat,
1156+
})
1157+
);
1158+
return this.matrixFieldChangeRules(listData);
1159+
}
1160+
11231161
/**
11241162
* Parses binary spreadsheet data into a JSON matrix and processes it for use.
11251163
* If header rows are detected in the data, they are removed, and any additional
@@ -1859,6 +1897,11 @@ class DataHarmonizer {
18591897
}
18601898

18611899
getInferredIndexSlot() {
1900+
1901+
if (this.class_assignment) {
1902+
return this.class_assignment;
1903+
}
1904+
18621905
const classes = Object.values(this.schema.classes);
18631906
const treeRootClass = classes.find((cls) => cls.tree_root);
18641907
if (!treeRootClass) {
@@ -1880,42 +1923,6 @@ class DataHarmonizer {
18801923
return index_attrs[0].name;
18811924
}
18821925

1883-
/**
1884-
* Load data into table as an array of objects. The keys of each object are
1885-
* field names and the values are the cell values.
1886-
*
1887-
* @param {Array<Object>} data table data
1888-
*/
1889-
loadDataObjects(data) {
1890-
const fields = this.getFields();
1891-
if (typeof data === 'object' && !Array.isArray(data) && data !== null) {
1892-
// An object was provided, so try to pick out the grid data from
1893-
// one of it's fields.
1894-
const inferredIndexSlot = this.getInferredIndexSlot();
1895-
if (inferredIndexSlot) {
1896-
data = data[inferredIndexSlot];
1897-
} else {
1898-
const dataKeys = Object.keys(data);
1899-
if (dataKeys.length === 1) {
1900-
data = data[dataKeys[0]];
1901-
}
1902-
}
1903-
}
1904-
if (!Array.isArray(data)) {
1905-
console.warn('Unable to get grid data from input');
1906-
return;
1907-
}
1908-
const listData = data.map((row) =>
1909-
dataObjectToArray(row, fields, {
1910-
serializedDateFormat: this.dateExportBehavior,
1911-
dateFormat: this.dateFormat,
1912-
datetimeFormat: this.datetimeFormat,
1913-
timeFormat: this.timeFormat,
1914-
})
1915-
);
1916-
return this.matrixFieldChangeRules(listData);
1917-
}
1918-
19191926
/**
19201927
*
19211928
* From export_utils.js

lib/Toolbar.js

+1
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ class Toolbar {
515515
.then(async (context) => {
516516
let columnCoordinates;
517517
const dh = context.getCurrentDataHarmonizer();
518+
console.log(context);
518519
if (!languages) languages = await dh.getLanguages(template_name);
519520
if (!schemaClass) schemaClass = schema.classes[template_name];
520521
if (!columnCoordinates) columnCoordinates = dh.getColumnCoordinates();

0 commit comments

Comments
 (0)