diff --git a/lib/AppContext.js b/lib/AppContext.js index 51a1583a..bb5bf991 100644 --- a/lib/AppContext.js +++ b/lib/AppContext.js @@ -226,7 +226,6 @@ export default class AppContext { const isForcedSchemaProvided = overrides.forced_schema !== null; const isLocaleChange = overrides.locale !== null; - const clearAndSetup = async ( data_harmonizers = {}, forced_schema = null @@ -376,7 +375,6 @@ export default class AppContext { translationsByLanguage[currentLang] = { ...enumResource, }; - }); // Generate translation maps between all possible language combinations diff --git a/lib/DataHarmonizer.js b/lib/DataHarmonizer.js index 9c967bee..b54bf60c 100644 --- a/lib/DataHarmonizer.js +++ b/lib/DataHarmonizer.js @@ -2852,14 +2852,13 @@ class DataHarmonizer { toJSON() { const handsontableInstance = this.hot; const tableData = this.fullData(handsontableInstance); - const columnHeaders = handsontableInstance.getColHeader().map(stripDiv); // TODO: use fields() or this.getFlatHeaders()[1]; + const columnHeaders = handsontableInstance.getColHeader().map(stripDiv); // TODO: use fields() or this.getFlatHeaders()[1]; console.log(columnHeaders); function createStruct(row) { const structInstance = {}; // iterate over the columns in a row for (let i = 0; i < row.length; i++) { - const columnHeader = columnHeaders[i]; console.log(columnHeader); diff --git a/lib/Toolbar.js b/lib/Toolbar.js index e112fd95..a904ce3e 100644 --- a/lib/Toolbar.js +++ b/lib/Toolbar.js @@ -15,7 +15,10 @@ import { prependToSheet, } from '@/lib/utils/files'; import { nullValuesToString, isEmptyUnitVal } from '@/lib/utils/general'; -import { MULTIVALUED_DELIMITER, titleOverText, slotNamesForTitlesMap } from '@/lib/utils/fields'; +import { + MULTIVALUED_DELIMITER, + titleOverText, +} from '@/lib/utils/fields'; import { takeKeys, invert } from '@/lib/utils/objects'; import { findBestLocaleMatch, @@ -164,7 +167,6 @@ class Toolbar { if (supportsLocale) { try { - // first cache data const current_template = this.context.appConfig.template_path; let _dh_data_cache = {}; @@ -180,7 +182,7 @@ class Toolbar { } // reload the context with the new locale - + await this.context .reload(current_template, { locale: language_update, @@ -200,9 +202,7 @@ class Toolbar { // Jump to modal as well this.setupJumpToModal(initialDh); this.setupFillModal(initialDh); - }); - } catch (error) { if (error instanceof LocaleNotSupportedError) { console.warn(error); @@ -412,7 +412,6 @@ class Toolbar { } const locale = in_language; - await this.context .reload(template_path, { locale }) .then((context) => { @@ -475,77 +474,75 @@ class Toolbar { const schema_container = this.context.template.default.schema.classes.Container; const Container = Object.entries( - // default schema is guaranteed to feature the Container - schema_container.attributes - ).reduce((acc, [cls_key, { name, range }]) => { - - // TODO: check if container attributes always have ranges? - if (typeof range !== 'undefined') { - const processedClass = { - [name]: MultiEntityJSON[range] - .map((obj) => nullValuesToString(obj)) - .map((entry) => { - // translation: if available, use title over text given a non-default localization for export - // TODO?: check if current lang is equal to current schema lang? - const fields = this.context.dhs[range].getFields(); - const findField = (colKey) => - fields.filter((field) => field.title === colKey)[0]; - entry = Object.fromEntries( - Object.entries(entry).map(([k, v]) => { - const field = findField(k); - let nv = v; - if (field.sources && !isEmptyUnitVal(v)) { - const merged_permissible_values = field.sources.reduce( - (acc, source) => { - return Object.assign( - acc, - field.permissible_values[source] - ); - }, - {} - ); - if (field.multivalued === true) { - nv = v - .split(MULTIVALUED_DELIMITER) - .map((_v) => { - if (!(_v in merged_permissible_values)) - console.warn( - `${_v} not in merged_permissible_values ${Object.keys( - merged_permissible_values - )}` - ); - return _v in merged_permissible_values - ? titleOverText(merged_permissible_values[_v]) - : _v; - }) - .join(MULTIVALUED_DELIMITER); - } else { - if (!(v in merged_permissible_values)) - console.warn( - `${v} not in merged_permissible_values ${Object.keys( - merged_permissible_values - )}` - ); - nv = - v in merged_permissible_values - ? titleOverText(merged_permissible_values[v]) - : v; - } + // default schema is guaranteed to feature the Container + schema_container.attributes + ).reduce((acc, [cls_key, { name, range }]) => { + // TODO: check if container attributes always have ranges? + if (typeof range !== 'undefined') { + const processedClass = { + [name]: MultiEntityJSON[range] + .map((obj) => nullValuesToString(obj)) + .map((entry) => { + // translation: if available, use title over text given a non-default localization for export + // TODO?: check if current lang is equal to current schema lang? + const fields = this.context.dhs[range].getFields(); + const findField = (colKey) => + fields.filter((field) => field.title === colKey)[0]; + entry = Object.fromEntries( + Object.entries(entry).map(([k, v]) => { + const field = findField(k); + let nv = v; + if (field.sources && !isEmptyUnitVal(v)) { + const merged_permissible_values = field.sources.reduce( + (acc, source) => { + return Object.assign( + acc, + field.permissible_values[source] + ); + }, + {} + ); + if (field.multivalued === true) { + nv = v + .split(MULTIVALUED_DELIMITER) + .map((_v) => { + if (!(_v in merged_permissible_values)) + console.warn( + `${_v} not in merged_permissible_values ${Object.keys( + merged_permissible_values + )}` + ); + return _v in merged_permissible_values + ? titleOverText(merged_permissible_values[_v]) + : _v; + }) + .join(MULTIVALUED_DELIMITER); + } else { + if (!(v in merged_permissible_values)) + console.warn( + `${v} not in merged_permissible_values ${Object.keys( + merged_permissible_values + )}` + ); + nv = + v in merged_permissible_values + ? titleOverText(merged_permissible_values[v]) + : v; } - return [k, nv]; - }) - ); - return entry; - }), - }; - - - return Object.assign(acc, processedClass); - } else { - console.warn('Container entry has no range:', cls_key); - return acc; - } - }, {}); + } + return [k, nv]; + }) + ); + return entry; + }), + }; + + return Object.assign(acc, processedClass); + } else { + console.warn('Container entry has no range:', cls_key); + return acc; + } + }, {}); const JSONFormat = { schema: this.context.template.schema.id, @@ -556,21 +553,23 @@ class Toolbar { }; if (ext === 'json') { - - const filterFunctionTemplate = (condCallback = () => true, keyCallback = (id) => id) => obj => - Object.keys(obj).reduce((acc, itemKey) => { - return condCallback(obj, acc, itemKey) - ? { - ...acc, - [keyCallback(itemKey)]: obj[itemKey], - } - : acc; - }, {}); + const filterFunctionTemplate = + (condCallback = () => true, keyCallback = (id) => id) => + (obj) => + Object.keys(obj).reduce((acc, itemKey) => { + return condCallback(obj, acc, itemKey) + ? { + ...acc, + [keyCallback(itemKey)]: obj[itemKey], + } + : acc; + }, {}); const filterEmptyKeys = filterFunctionTemplate( - (obj, acc, itemKey) => itemKey in obj && !(itemKey in acc) && obj[itemKey] != '', - id => id, - ) + (obj, acc, itemKey) => + itemKey in obj && !(itemKey in acc) && obj[itemKey] != '', + (id) => id + ); // const fields = this.context.getCurrentDataHarmonizer().getFields(); // const slotNamesForTitles = slotNamesForTitlesMap(fields); @@ -580,9 +579,8 @@ class Toolbar { // (em) => slotNamesForTitles[em], // ) - const processEntryKeys = (lst) => - lst.map(filterEmptyKeys) - // .map(projectSlotNamestToTitles); + const processEntryKeys = (lst) => lst.map(filterEmptyKeys); + // .map(projectSlotNamestToTitles); for (let concept in JSONFormat.Container) { JSONFormat.Container[concept] = processEntryKeys( @@ -596,7 +594,6 @@ class Toolbar { ext, ]); } else { - const sectionCoordinatesByClass = Object.values(this.context.dhs).reduce( (acc, dh) => { const sectionTiles = dh.sections.map((s) => s.title); @@ -885,7 +882,7 @@ class Toolbar { let { template_path, schema } = loadResult; // RELOAD THE INTERFACE BY INTERACTING WITH THE CONTEXT - + this.context .reload(template_path, { forced_schema: file ? schema : null, diff --git a/lib/utils/1m.js b/lib/utils/1m.js index 63c94081..41bf249a 100644 --- a/lib/utils/1m.js +++ b/lib/utils/1m.js @@ -393,10 +393,8 @@ const updateRows = (dh, [col, oldVal, newVal]) => { // hot.getDataAtRow(rowIndex) // ); clearRow(hot, rowIndex); - } if (shouldRemapChildCol) { - modifyRow(hot, rowIndex, col, newVal); } return CONTINUE_SIGNAL; diff --git a/lib/utils/fields.js b/lib/utils/fields.js index db98a25d..536e1d51 100644 --- a/lib/utils/fields.js +++ b/lib/utils/fields.js @@ -6,7 +6,7 @@ import { parseJsonDate, datatypeIsDateOrTime, } from '@/lib/utils/datatypes'; -import { consolidate, invert } from '@/lib/utils/objects'; +import { consolidate } from '@/lib/utils/objects'; export const MULTIVALUED_DELIMITER = '; '; @@ -165,16 +165,19 @@ export function fieldTitleMapFromIndex(fields) { export function fieldSymbolsAtIndexMap(fields) { const invertedFieldTitleIndex = fieldTitleMapFromIndex(fields); const invertedFieldNameMapToIndex = fieldNameMapFromIndex(fields); - if (Object.keys(invertedFieldTitleIndex).length != Object.keys(invertedFieldNameMapToIndex).length) { - console.error("Field Title and Field Index maps are different sizes!"); + if ( + Object.keys(invertedFieldTitleIndex).length != + Object.keys(invertedFieldNameMapToIndex).length + ) { + console.error('Field Title and Field Index maps are different sizes!'); } else { const tempObj = {}; for (let i = 0; i < Object.values(invertedFieldTitleIndex).length; i++) { tempObj[i] = { slotName: invertedFieldNameMapToIndex[i], - slotTitle: invertedFieldTitleIndex[i] + slotTitle: invertedFieldTitleIndex[i], }; - }; + } return tempObj; } return null; @@ -184,7 +187,8 @@ export function slotNamesForTitlesMap(fields) { const fieldSymbolsAtIndex = fieldSymbolsAtIndexMap(fields); let tempObject = {}; for (let index in fieldSymbolsAtIndex) { - tempObject[fieldSymbolsAtIndex[index].slotTitle] = fieldSymbolsAtIndex[index].slotName; + tempObject[fieldSymbolsAtIndex[index].slotTitle] = + fieldSymbolsAtIndex[index].slotName; } return tempObject; } @@ -193,9 +197,11 @@ export function slotTitleForNameMap(fields) { const fieldSymbolsAtIndex = fieldSymbolsAtIndexMap(fields); let tempObject = {}; for (let index in fieldSymbolsAtIndex) { - tempObject[fieldSymbolsAtIndex[index].slotName] = fieldSymbolsAtIndex[index].slotTitle; + tempObject[fieldSymbolsAtIndex[index].slotName] = + fieldSymbolsAtIndex[index].slotTitle; } - return tempObject;} + return tempObject; +} export function findFieldIndex(fields, key, translationMap = {}) { // First try to find a direct match. @@ -215,7 +221,6 @@ export function findFieldIndex(fields, key, translationMap = {}) { } export function dataObjectToArray(dataObject, fields, options = {}) { - const { serializedDateFormat, dateFormat, @@ -257,7 +262,7 @@ export function dataObjectToArray(dataObject, fields, options = {}) { return datatypes.stringify(originalValue, datatype); }; - const slotNamesForTitles = slotNamesForTitlesMap(fields) + const slotNamesForTitles = slotNamesForTitlesMap(fields); for (const [slotTitle, value] of Object.entries(dataObject)) { const slotName = slotNamesForTitles[slotTitle]; const fieldIdx = findFieldIndex(fields, slotName, translationMap); diff --git a/lib/utils/templates.js b/lib/utils/templates.js index 58defb48..f74977bc 100644 --- a/lib/utils/templates.js +++ b/lib/utils/templates.js @@ -229,7 +229,6 @@ export function findBestLocaleMatch( preferredLocales, strict = false ) { - for (const preferred of preferredLocales) { // Check for exact match if (availableLocales.includes(preferred)) {