@@ -9,7 +9,7 @@ import i18next from 'i18next';
9
9
import { utils as XlsxUtils , read as xlsxRead } from 'xlsx/xlsx.js' ;
10
10
import { renderContent , urlToClickableAnchor } from './utils/content' ;
11
11
import { readFileAsync , updateSheetRange } from '../lib/utils/files' ;
12
- import { findSlotNamesForClass } from '../lib/utils/templates' ;
12
+ // import { findSlotNamesForClass } from '../lib/utils/templates';
13
13
import {
14
14
isValidHeaderRow ,
15
15
rowIsEmpty ,
@@ -38,7 +38,6 @@ import {
38
38
itemCompare ,
39
39
validateValAgainstVocab ,
40
40
validateValsAgainstVocab ,
41
- // validateUniqueValues,
42
41
} from './utils/validation' ;
43
42
44
43
import 'handsontable/dist/handsontable.full.css' ;
@@ -116,7 +115,8 @@ class DataHarmonizer {
116
115
117
116
this . class_assignment = options . class_assignment || null ;
118
117
this . field_settings = options . fieldSettings || { } ;
119
- this . slot_names = options . slot_names || [ ] ;
118
+ this . slots = null ;
119
+ this . slot_names = null ;
120
120
this . hot_override_settings = options . hot_override_settings || { } ;
121
121
122
122
this . helpSidebarOptions = Object . assign (
@@ -187,20 +187,9 @@ class DataHarmonizer {
187
187
this . hot . render ( ) ;
188
188
}
189
189
190
- useSchema ( schema , template_name ) {
191
- console . log ( "useSchema" , template_name )
192
- this . schema = schema ;
193
- this . validator = new Validator ( this . schema , MULTIVALUED_DELIMITER , {
194
- dateFormat : this . dateFormat ,
195
- datetimeFormat : this . datetimeFormat ,
196
- timeFormat : this . timeFormat ,
197
- } ) ;
198
-
199
- this . useTemplate ( template_name ) ;
200
- }
201
190
202
191
/**
203
- * Revise user interface elements to match template name
192
+ * Revise user interface elements to match template content
204
193
*
205
194
* @param {String } template_name: name of template within current schema
206
195
*/
@@ -221,8 +210,8 @@ class DataHarmonizer {
221
210
)
222
211
. filter (
223
212
( [ cls_key ] ) =>
224
- cls_key !== 'dh_interface' &&
225
- cls_key !== 'Container' &&
213
+ // cls_key !== 'dh_interface' &&
214
+ // cls_key !== 'Container' &&
226
215
cls_key === this . class_assignment
227
216
)
228
217
. reduce ( ( acc , [ , spec ] ) => {
@@ -498,15 +487,35 @@ class DataHarmonizer {
498
487
this . sections [ ptr ] [ 'children' ] . sort ( ( a , b ) => a . rank - b . rank ) ;
499
488
}
500
489
501
-
490
+ // Easy lookup arrays.
502
491
this . slots = this . getFields ( ) ;
503
- this . slot_names = findSlotNamesForClass ( this . context . template . default . schema , template_name ) ,
504
- //console.log(this.slot_names)
505
- this . validator . useTargetClass ( this . class_assignment ) ;
492
+ this . slot_names = this . slots . map ( ( field ) => field . name ) ;
506
493
507
494
this . createHot ( ) ;
508
495
}
509
496
497
+
498
+ /**
499
+ * Get a flat array of all fields (slot definitions) in TEMPLATE.
500
+ * @return {Array<Object> } Array of all objects under `children` in TEMPLATE.
501
+ */
502
+ getFields ( ) {
503
+ let fields = Array . prototype . concat . apply (
504
+ [ ] ,
505
+ this . sections . map ( ( section ) => section . children )
506
+ ) ;
507
+
508
+ /* NOTE: Possibly a result of attempting to add other slots besides one in
509
+ * template.
510
+
511
+ fields =
512
+ this.slot_names.length > 0
513
+ ? fields.filter((field) => this.slot_names.includes(field.name))
514
+ : fields;
515
+ */
516
+ return fields ;
517
+ }
518
+
510
519
/**
511
520
* Open file specified by user.
512
521
* Only opens `xlsx`, `xlsx`, `csv` and `tsv` files. Will launch the specify
@@ -960,10 +969,12 @@ class DataHarmonizer {
960
969
this . hideColumns ( hiddenColumns ) ;
961
970
}
962
971
972
+ /*
963
973
showColumnsByNames(names) {
964
974
if (names.length > 0)
965
975
this._updateVisibility((field) => !names.includes(field.name));
966
976
}
977
+ */
967
978
968
979
showRequiredColumns ( ) {
969
980
this . _updateVisibility ( ( field ) => ! field . required ) ;
@@ -1630,25 +1641,6 @@ class DataHarmonizer {
1630
1641
} ;
1631
1642
}
1632
1643
1633
- /**
1634
- * Get a flat array of all fields (slot definitions) in TEMPLATE.
1635
- * @return {Array<Object> } Array of all objects under `children` in TEMPLATE.
1636
- */
1637
- getFields ( ) {
1638
- let fields = Array . prototype . concat . apply (
1639
- [ ] ,
1640
- this . sections . map ( ( section ) => section . children )
1641
- ) ;
1642
-
1643
- fields =
1644
- this . slot_names . length > 0
1645
- ? fields . filter ( ( field ) => this . slot_names . includes ( field . name ) )
1646
- : fields ;
1647
-
1648
- console . log ( "FILTERS" , this . slot_names )
1649
- console . log ( "FIELDS" , fields )
1650
- return fields ;
1651
- }
1652
1644
1653
1645
/**
1654
1646
* Create a matrix containing the nested headers supplied to Handsontable.
@@ -2184,7 +2176,6 @@ class DataHarmonizer {
2184
2176
...options ,
2185
2177
} ;
2186
2178
const listData = this . hot . getData ( ) ;
2187
- //const fields = this.getFields();
2188
2179
const arrayOfObjects = listData
2189
2180
. filter ( ( row ) => ! rowIsEmpty ( row ) )
2190
2181
. map ( ( row ) =>
@@ -2689,11 +2680,8 @@ class DataHarmonizer {
2689
2680
* @return {Array<Array<String>> } Modified matrix.
2690
2681
*/
2691
2682
matrixFieldChangeRules ( matrix ) {
2692
- //const fields = this.slots;
2693
- Object . entries ( this . slots ) . forEach ( ( field , col ) => {
2694
2683
2695
- //for (let col = 0; col < this.slots.length; col++) {
2696
- // const field = fields[col];
2684
+ Object . entries ( this . slots ) . forEach ( ( field , col ) => {
2697
2685
2698
2686
// Test field against capitalization change.
2699
2687
if ( field . capitalize ) {
@@ -2877,8 +2865,8 @@ class DataHarmonizer {
2877
2865
* `{0: {0: 'Required cells cannot be empty'}}`
2878
2866
*/
2879
2867
getInvalidCells ( data ) {
2880
- const fieldNames = this . getFields ( ) . map ( ( field ) => field . name ) ;
2881
- return this . validator . validate ( data , fieldNames ) ;
2868
+ // const fieldNames = this.slots .map((field) => field.name);
2869
+ return this . validator . validate ( data , this . slot_names ) ; // fieldNames);
2882
2870
}
2883
2871
2884
2872
/**
0 commit comments