Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
kennethbruskiewicz committed Sep 20, 2023
1 parent 303c3b9 commit 568a944
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
**/dist/**/*
web/templates/**/*
.venv
.notes
.vscode
README.md
76 changes: 38 additions & 38 deletions lib/DataHarmonizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DataHarmonizer {
this.field_settings = options.fieldSettings || {};
this.helpSidebarOptions = Object.assign(
{ enabled: true },
options.helpSidebar || {},
options.helpSidebar || {}
);
this.columnHelpEntries = options.columnHelpEntries || [
'column',
Expand Down Expand Up @@ -125,7 +125,7 @@ class DataHarmonizer {
$(this.root).on('dblclick', '.secondary-header-cell', (e) => {
const innerText = e.target.innerText;
const field = this.getFields().filter(
(field) => field.title === innerText,
(field) => field.title === innerText
)[0];
$('#field-description-text').html(this.getComment(field));
$('#field-description-modal').modal('show');
Expand Down Expand Up @@ -189,7 +189,7 @@ class DataHarmonizer {
let field = Object.assign(
{},
self.schema.slots[name],
specification.slots[name],
specification.slots[name]
);

//let field = specification.slots[name];
Expand Down Expand Up @@ -299,12 +299,12 @@ class DataHarmonizer {
// This calculates for each categorical field in schema.yaml a
// flat list of allowed values (indented to represent hierarchy)
let flatVocab = self.stringifyNestedVocabulary(
range_obj.permissible_values,
range_obj.permissible_values
);
new_field.flatVocabulary.push(...flatVocab);
// Lowercase version used for easy lookup/validation
new_field.flatVocabularyLCase.push(
...flatVocab.map((val) => val.trim().toLowerCase()),
...flatVocab.map((val) => val.trim().toLowerCase())
);
} else {
// If range is a class ...
Expand Down Expand Up @@ -392,7 +392,7 @@ class DataHarmonizer {
new_field.pattern = new RegExp(field.pattern);
} catch (err) {
console.log(
`TEMPLATE ERROR: Check the regular expression syntax for "${new_field.title}".`,
`TEMPLATE ERROR: Check the regular expression syntax for "${new_field.title}".`
);
console.log(err);
// Allow anything until regex fixed.
Expand Down Expand Up @@ -555,7 +555,7 @@ class DataHarmonizer {
this.enableMultiSelection();
} else {
console.log(
'This template had no sections and fields: ' + this.template_name,
'This template had no sections and fields: ' + this.template_name
);
}
}
Expand All @@ -565,7 +565,7 @@ class DataHarmonizer {
this.hot.alter(
'insert_row_below',
this.hot.countRows() - 1 + numRows,
numRows,
numRows
);
});
}
Expand Down Expand Up @@ -647,7 +647,7 @@ class DataHarmonizer {
hiddenRows = [...hiddenRows, ...emptyRows];
} else if (id === 'show-invalid-rows-dropdown-item') {
const invalidRowsSet = new Set(
Object.keys(this.invalid_cells).map(Number),
Object.keys(this.invalid_cells).map(Number)
);
hiddenRows = rows.filter((row) => !invalidRowsSet.has(row));
hiddenRows = [...hiddenRows, ...emptyRows];
Expand Down Expand Up @@ -731,7 +731,7 @@ class DataHarmonizer {
var win = window.open(
'',
'Reference',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1000,height=600',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=1000,height=600'
);

win.document.head.innerHTML = `
Expand Down Expand Up @@ -839,7 +839,7 @@ class DataHarmonizer {
parseInt(column),
parseInt(row),
parseInt(column),
true,
true
);
//Ensures field is positioned on left side of screen.
this.hot.scrollViewportTo(row, column);
Expand Down Expand Up @@ -886,7 +886,7 @@ class DataHarmonizer {
const headerRowData = this.compareMatrixHeadersToGrid(matrix);
if (headerRowData > 0) {
this.hot.loadData(
this.matrixFieldChangeRules(matrix.slice(headerRowData)),
this.matrixFieldChangeRules(matrix.slice(headerRowData))
);
} else {
this.launchSpecifyHeadersModal(matrix);
Expand All @@ -905,17 +905,17 @@ class DataHarmonizer {
const self = this;
if (flatHeaders) {
$('#field-mapping').prepend(
'<col></col>'.repeat(flatHeaders[1].length + 1),
'<col></col>'.repeat(flatHeaders[1].length + 1)
);
$('#expected-headers-tr').html(
'<td><b>Expected second row</b></td> <td>' +
flatHeaders[1].join('</td><td>') +
'</td>',
'</td>'
);
$('#actual-headers-tr').html(
'<td><b>Imported second row</b></td> <td>' +
matrix[1].join('</td><td>') +
'</td>',
'</td>'
);
flatHeaders[1].forEach(function (item, i) {
if (item != matrix[1][i]) {
Expand All @@ -932,16 +932,16 @@ class DataHarmonizer {
// Try to load data again using User specified header row
const mappedMatrixObj = self.mapMatrixToGrid(
matrix,
specifiedHeaderRow - 1,
specifiedHeaderRow - 1
);
$('#specify-headers-modal').modal('hide');
this.runBehindLoadingScreen(() => {
self.hot.loadData(
self.matrixFieldChangeRules(mappedMatrixObj.matrix.slice(2)),
self.matrixFieldChangeRules(mappedMatrixObj.matrix.slice(2))
);
if (mappedMatrixObj.unmappedHeaders.length) {
const unmappedHeaderDivs = mappedMatrixObj.unmappedHeaders.map(
(header) => `<li>${header}</li>`,
(header) => `<li>${header}</li>`
);
$('#unmapped-headers-list').html(unmappedHeaderDivs);
$('#unmapped-headers-modal').modal('show');
Expand Down Expand Up @@ -1061,7 +1061,7 @@ class DataHarmonizer {
getFields() {
return Array.prototype.concat.apply(
[],
this.template.map((section) => section.children),
this.template.map((section) => section.children)
);
}

Expand All @@ -1082,7 +1082,7 @@ class DataHarmonizer {
const required = child.required ? ' required' : '';
const recommended = child.recommended ? ' recommended' : '';
rows[1].push(
`<div class="secondary-header-text${required}${recommended}">${child.title}</div>`,
`<div class="secondary-header-text${required}${recommended}">${child.title}</div>`
);
}
}
Expand Down Expand Up @@ -1192,7 +1192,7 @@ class DataHarmonizer {
}

$('#field-description-text').html(
`${fields[col].title}<select multiple class="multiselect" rows="15">${content}</select>`,
`${fields[col].title}<select multiple class="multiselect" rows="15">${content}</select>`
);
$('#field-description-modal').modal('show');
$('#field-description-text .multiselect')
Expand All @@ -1211,7 +1211,7 @@ class DataHarmonizer {
}) // must be rendered when html is visible
.on('change', function () {
let newValCsv = formatMultivaluedValue(
$('#field-description-text .multiselect').val(),
$('#field-description-text .multiselect').val()
);
self.setDataAtCell(row, col, newValCsv, 'thisChange');
});
Expand Down Expand Up @@ -1397,7 +1397,7 @@ class DataHarmonizer {
// List null value menu items directly
if (item === 'null value menu') {
let null_values = Object.keys(
self.schema.enums[item].permissible_values,
self.schema.enums[item].permissible_values
);
sources.push(item + ': (' + null_values.join('; ') + ')');
} else {
Expand Down Expand Up @@ -1504,7 +1504,7 @@ class DataHarmonizer {
dateFormat: this.dateFormat,
datetimeFormat: this.datetimeFormat,
timeFormat: this.timeFormat,
}),
})
);
if (typeof indexSlot === 'string') {
return {
Expand All @@ -1528,17 +1528,17 @@ class DataHarmonizer {
const treeRootClass = classes.find((cls) => cls.tree_root);
if (!treeRootClass) {
console.warn(
`While getting inferred index slot, could not find tree_root class.`,
`While getting inferred index slot, could not find tree_root class.`
);
return;
}
const treeRootAttrs = Object.values(treeRootClass.attributes);
const index_attrs = treeRootAttrs.filter(
(attr) => attr.range === this.template_name,
(attr) => attr.range === this.template_name
);
if (!index_attrs || index_attrs.length !== 1) {
console.warn(
`While getting inferred index slot, could not find single slot with range ${this.template_name} on tree_root class ${treeRootClass.name}.`,
`While getting inferred index slot, could not find single slot with range ${this.template_name} on tree_root class ${treeRootClass.name}.`
);
return;
}
Expand Down Expand Up @@ -1576,7 +1576,7 @@ class DataHarmonizer {
dateFormat: this.dateFormat,
datetimeFormat: this.datetimeFormat,
timeFormat: this.timeFormat,
}),
})
);
this.hot.loadData(this.matrixFieldChangeRules(listData));
}
Expand Down Expand Up @@ -1649,7 +1649,7 @@ class DataHarmonizer {
if (!sources) {
console.log(
'Malformed export.js exportHeader field:',
target.field,
target.field
);
}
// If given field isn't already mapped, add it.
Expand Down Expand Up @@ -1709,7 +1709,7 @@ class DataHarmonizer {
delimiter,
prefix,
nullOptionsMap = null,
skipNull = false,
skipNull = false
) {
const self = this;
const mappedCell = [];
Expand All @@ -1730,14 +1730,14 @@ class DataHarmonizer {
// if sources exist, fetch transformed Value
if (field.sources) {
mappedCell.push(
self.getTransformedField(headerName, mappedCellVal, field, prefix),
self.getTransformedField(headerName, mappedCellVal, field, prefix)
);
} else if (field.multivalued === true) {
// ISSUE: relying on semicolon delimiter in input

for (let cellVal of mappedCellVal.split(';')) {
mappedCell.push(
self.getTransformedField(headerName, cellVal.trim(), field, prefix),
self.getTransformedField(headerName, cellVal.trim(), field, prefix)
);
}
} else {
Expand Down Expand Up @@ -2035,7 +2035,7 @@ class DataHarmonizer {
if (dateGranularity === 'year' || dateGranularity === 'month') {
matrix[row][col] = this.setDateChange(
dateGranularity,
matrix[row][col],
matrix[row][col]
);
}
}
Expand Down Expand Up @@ -2288,7 +2288,7 @@ class DataHarmonizer {
field,
columnIndex,
row,
TODAY,
TODAY
);
break;

Expand Down Expand Up @@ -2323,7 +2323,7 @@ class DataHarmonizer {
bad_pattern[field.pattern] = true;
console.log(
`Regular expression /${field.pattern}/ in ${field.title} failed`,
err,
err
);
}
continue;
Expand All @@ -2340,7 +2340,7 @@ class DataHarmonizer {
if (field.multivalued === true) {
const [vocabValid, update] = validateValsAgainstVocab(
cellVal,
field,
field
);

valid = vocabValid;
Expand All @@ -2350,7 +2350,7 @@ class DataHarmonizer {
} else {
const [vocabValid, update] = validateValAgainstVocab(
cellVal,
field,
field
);
valid = vocabValid;
if (update) {
Expand Down Expand Up @@ -2410,7 +2410,7 @@ class DataHarmonizer {

// Returns FIRST index for a field marked as an .identifier
const identifierFieldCol = fields.findIndex(
(field) => field.identifier && field.identifier === true,
(field) => field.identifier && field.identifier === true
);
if (identifierFieldCol >= 0) {
doUniqueValidation([identifierFieldCol]);
Expand Down
8 changes: 4 additions & 4 deletions lib/HelpSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class HelpSidebar {
if (typeof this.options.onToggle === 'function') {
setTimeout(
() => this.options.onToggle(this.isOpen),
this.options.toggleTransitionDuration,
this.options.toggleTransitionDuration
);
}
}
Expand All @@ -70,19 +70,19 @@ class HelpSidebar {
this.content = $(
`<div class="help-sidebar__content">
<h4 class="help-sidebar__title">${this.options.title}</h4>
</div>`,
</div>`
).appendTo(this.sidebar);

this.contentInner = $(
`<div class="help-sidebar__content-inner">
<p class="help-sidebar__placeholder">
${this.options.placeholder}
</p>
</div>`,
</div>`
).appendTo(this.content);

this.toggler = $(
`<button class="help-sidebar__toggler">${this._getTogglerLabel()}</button>`,
`<button class="help-sidebar__toggler">${this._getTogglerLabel()}</button>`
).appendTo(this.sidebar);

this.toggler.on('click', this._handleTogglerClick.bind(this));
Expand Down
8 changes: 4 additions & 4 deletions lib/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class Toolbar {
$('#export-to-format-select').on('change', () => {
const exportFormat = $('#export-to-format-select').val();
$('#export_file_suffix').text(
'.' + dh.export_formats[exportFormat].fileType,
'.' + dh.export_formats[exportFormat].fileType
);
});

Expand Down Expand Up @@ -354,7 +354,7 @@ class Toolbar {
let contentBuffer = await readFileAsync(file);
schema = JSON.parse(contentBuffer);
template_name = Object.keys(schema.classes).filter(
(e) => schema.classes[e].is_a === 'dh_interface',
(e) => schema.classes[e].is_a === 'dh_interface'
)[0];
} catch (err) {
console.log(err);
Expand Down Expand Up @@ -382,7 +382,7 @@ class Toolbar {
if (
!('pertains_to' in this.dh.export_formats[option]) ||
this.dh.export_formats[option].pertains_to.includes(
this.dh.template_name,
this.dh.template_name
)
) {
select.append(new Option(option, option));
Expand All @@ -404,7 +404,7 @@ class Toolbar {
let section_ptr = 0;
for (const section of this.dh.template) {
$('#section-menu').append(
`<div id="show-section-${section_ptr}" class="dropdown-item show-section-dropdown-item">${section.title}</div>`,
`<div id="show-section-${section_ptr}" class="dropdown-item show-section-dropdown-item">${section.title}</div>`
);
section_ptr++;
}
Expand Down
Loading

0 comments on commit 568a944

Please sign in to comment.