@@ -71,9 +71,9 @@ class AppContext {
71
71
schema_tree = { } ;
72
72
dhs = { } ;
73
73
current_data_harmonizer_name = null ;
74
+ template = null ;
74
75
75
76
constructor ( appConfig ) {
76
- this . template = null ;
77
77
this . appConfig = appConfig ;
78
78
}
79
79
@@ -83,7 +83,8 @@ class AppContext {
83
83
84
84
setDataHarmonizers ( data_harmonizers ) {
85
85
this . dhs = data_harmonizers ;
86
- this . setCurrentDataHarmonizer ( this . schema_tree [ 'Container' ] . children [ 0 ] ) ;
86
+ // NOTE: non-deterministic, assumes that the insertion order is the right order
87
+ this . setCurrentDataHarmonizer ( Object . keys ( this . dhs ) [ 0 ] ) ;
87
88
}
88
89
89
90
setCurrentDataHarmonizer ( data_harmonizer_name ) {
@@ -213,9 +214,8 @@ class AppContext {
213
214
const one_to_many = { } ;
214
215
for ( const [ prefix , suffixes ] of Object . entries ( suffix_dict ) ) {
215
216
if (
216
- suffixes . some (
217
- ( suffix ) =>
218
- typeof filtered_multi_suffixes_filter [ suffix ] !== 'undefined'
217
+ suffixes . some ( ( suffix ) =>
218
+ typeof filtered_multi_suffixes_filter [ suffix ] !== 'undefined'
219
219
) &&
220
220
suffixes . length >= suffix_threshold
221
221
) {
@@ -234,9 +234,7 @@ class AppContext {
234
234
235
235
async initializeTemplate ( template_path ) {
236
236
const [ schema_name ] = template_path . split ( '/' ) ;
237
- if ( ! this . template ) {
238
- this . template = await Template . create ( schema_name ) ;
239
- }
237
+ this . template = await Template . create ( schema_name ) ;
240
238
return this ;
241
239
}
242
240
@@ -249,8 +247,6 @@ class AppContext {
249
247
default : { langcode : 'default' , nativeName : 'Default' } ,
250
248
} ;
251
249
252
- console . log ( this . template . locales ) ;
253
-
254
250
this . template . locales . forEach ( ( locale ) => {
255
251
const langcode = locale . split ( '-' ) [ 0 ] ;
256
252
const nativeName = tags . language ( langcode )
@@ -263,10 +259,11 @@ class AppContext {
263
259
}
264
260
265
261
async addTranslationResources ( template , locales = null ) {
266
- console . log ( 'add translation resources' ) ;
262
+
267
263
if ( locales === null ) {
268
- locales = this . getLocaleData ( template ) ;
264
+ locales = await this . getLocaleData ( template ) ;
269
265
}
266
+
270
267
// Consolidate function for reducing objects
271
268
function consolidate ( iterable , reducer ) {
272
269
return Object . entries ( iterable ) . reduce ( reducer , { } ) ;
@@ -371,12 +368,6 @@ class AppContext {
371
368
return Array . from ( slotGroups ) ;
372
369
}
373
370
374
- async getLocales ( ) {
375
- const locales = this . getLocaleData ( this . template ) ;
376
- this . addTranslationResources ( this . template , locales ) ; // TODO side effect – put elsewhere?
377
- return locales ;
378
- }
379
-
380
371
async getExportFormats ( schema ) {
381
372
return ( await import ( `@/web/templates/${ schema } /export.js` ) ) . default ;
382
373
}
@@ -432,17 +423,7 @@ class AppContext {
432
423
// schemaClass,
433
424
// columnCoordinates,
434
425
} ) {
435
- this . appConfig = new AppConfig ( template_path ) ;
436
- this . initializeTemplate ( this . appConfig . template_path ) ;
437
-
438
- this . clearInterface ( ) ;
439
- this . clearContext ( ) ;
440
-
441
- const [ _template_name , _schema_name ] =
442
- this . appConfig . template_path . split ( '/' ) ;
443
- const _export_formats =
444
- exportFormats || ( await this . getExportFormats ( _template_name ) ) ;
445
-
426
+
446
427
// attributes are the classes which feature 1-M relationshisps
447
428
// to process these classes into DataHarmonizer tables, the following must be performed:
448
429
// - Navigation: one tab per class = one data harmonizer per class
@@ -451,70 +432,80 @@ class AppContext {
451
432
// - Loading: the system will expect an excel file with sheets or a database with tables for selection. the Toolbar must know.
452
433
453
434
// the existence of a container class signifies a 1-M data loading setup with an ID join
454
- // if (classes['Container']) {
455
-
456
- // /* e.g.
457
-
458
- // const container = {
459
- // "Container": {
460
- // "name": "Container",
461
- // "from_schema": "https://example.com/GRDI",
462
- // "attributes": {
463
- // "GRDI_Sample": {
464
- // "name": "GRDI_Sample",
465
- // "from_schema": "https://example.com/GRDI",
466
- // "multivalued": true,
467
- // "alias": "GRDI_samples",
468
- // "owner": "Container",
469
- // "domain_of": [
470
- // "Container"
471
- // ],
472
- // "range": "GRDI_Sample",
473
- // "inlined_as_list": true
474
- // },
475
- // "AMR_Test": {
476
- // "name": "AMR_Test",
477
- // "from_schema": "https://example.com/GRDI",
478
- // "multivalued": true,
479
- // "alias": "AMR_Tests",
480
- // "owner": "Container",
481
- // "domain_of": [
482
- // "Container"
483
- // ],
484
- // "range": "AMR_Test",
485
- // "inlined_as_list": true
486
- // }
487
- // },
488
- // "tree_root": true
489
- // }
490
- // }
491
-
492
- // const schema_tree = {
493
- // "Container": { tree_root: true, children: ["AMR_Test", "GRDI_samples"] }
494
- // "GRDI_Sample": { shared_key: ["sample_collector_sample_ID"], children: ["AMR_Test"] } // TODO: should shared_key be shared between nodes on tree?
495
- // "AMR_Test": { shared_key: ["sample_collector_sample_ID"], children: [] },
496
- // }
497
-
498
- // */
499
-
500
- const schema_tree = buildSchemaTree ( schema ) ;
501
- this . setSchemaTree ( schema_tree ) ;
502
- data_harmonizers = makeDataHarmonizersFromSchemaTree (
503
- this ,
504
- schema ,
505
- schema_tree ,
506
- _schema_name ,
507
- _export_formats
508
- ) ;
509
- // HACK
510
- delete data_harmonizers [ undefined ] ;
511
- this . setDataHarmonizers ( data_harmonizers ) ;
512
- attachPropagationEventHandlersToDataHarmonizers (
513
- data_harmonizers ,
514
- schema_tree
515
- ) ;
516
435
517
- return this ;
436
+ /* e.g.
437
+
438
+ const container = {
439
+ "Container": {
440
+ "name": "Container",
441
+ "from_schema": "https://example.com/GRDI",
442
+ "attributes": {
443
+ "GRDI_Sample": {
444
+ "name": "GRDI_Sample",
445
+ "from_schema": "https://example.com/GRDI",
446
+ "multivalued": true,
447
+ "alias": "GRDI_samples",
448
+ "owner": "Container",
449
+ "domain_of": [
450
+ "Container"
451
+ ],
452
+ "range": "GRDI_Sample",
453
+ "inlined_as_list": true
454
+ },
455
+ "AMR_Test": {
456
+ "name": "AMR_Test",
457
+ "from_schema": "https://example.com/GRDI",
458
+ "multivalued": true,
459
+ "alias": "AMR_Tests",
460
+ "owner": "Container",
461
+ "domain_of": [
462
+ "Container"
463
+ ],
464
+ "range": "AMR_Test",
465
+ "inlined_as_list": true
466
+ }
467
+ },
468
+ "tree_root": true
469
+ }
470
+ }
471
+
472
+ const schema_tree = {
473
+ "Container": { tree_root: true, children: ["AMR_Test", "GRDI_samples"] }
474
+ "GRDI_Sample": { shared_key: ["sample_collector_sample_ID"], children: ["AMR_Test"] } // TODO: should shared_key be shared between nodes on tree?
475
+ "AMR_Test": { shared_key: ["sample_collector_sample_ID"], children: [] },
476
+ }
477
+
478
+ */
479
+
480
+ this . appConfig = new AppConfig ( template_path ) ;
481
+ this . clearInterface ( ) ;
482
+ this . clearContext ( ) ;
483
+
484
+ return this . initializeTemplate ( this . appConfig . template_path )
485
+ . then ( async context => {
486
+ const [ _template_name , _schema_name ] =
487
+ context . appConfig . template_path . split ( '/' ) ;
488
+ const _export_formats =
489
+ exportFormats || ( await context . getExportFormats ( _template_name ) ) ;
490
+ const schema_tree = buildSchemaTree ( schema ) ;
491
+ context . appConfig . template_path . split ( '/' ) ;
492
+ context . setSchemaTree ( schema_tree ) ;
493
+ data_harmonizers = makeDataHarmonizersFromSchemaTree (
494
+ this ,
495
+ schema ,
496
+ schema_tree ,
497
+ _schema_name ,
498
+ _export_formats
499
+ ) ;
500
+ // HACK
501
+ delete data_harmonizers [ undefined ] ;
502
+ context . setDataHarmonizers ( data_harmonizers ) ;
503
+ attachPropagationEventHandlersToDataHarmonizers (
504
+ data_harmonizers ,
505
+ schema_tree
506
+ ) ;
507
+ return context ;
508
+ } ) ;
518
509
}
519
510
}
520
511
@@ -588,6 +579,7 @@ function findSlotNamesForClass(schema, class_name) {
588
579
* @returns {Object|null } The schema tree object, or null if no "Container" classes are found.
589
580
*/
590
581
function buildSchemaTree ( schema ) {
582
+
591
583
function updateChildrenAndSharedKeys ( data ) {
592
584
// Use a deep clone to avoid mutating the original object
593
585
const result = JSON . parse ( JSON . stringify ( data ) ) ;
@@ -660,11 +652,7 @@ function buildSchemaTree(schema) {
660
652
} ;
661
653
}
662
654
663
- const attributes = schema . classes [ 'Container' ] . attributes ;
664
- const classes = Object . values ( attributes ) . reduce (
665
- ( acc , item ) => acc . concat ( [ item . range ] ) ,
666
- [ ]
667
- ) ;
655
+ const classes = Object . keys ( schema . classes ) . filter ( el => el !== 'dh_interface' ) ;
668
656
const tree_base = {
669
657
Container : { tree_root : true , children : classes } ,
670
658
} ;
@@ -991,6 +979,7 @@ const main = async function () {
991
979
context
992
980
. initializeTemplate ( context . appConfig . template_path )
993
981
. then ( async ( context ) => {
982
+
994
983
// // internationalize
995
984
// // TODO: connect to locale of browser!
996
985
// // Takes `lang` as argument (unused)
@@ -999,12 +988,6 @@ const main = async function () {
999
988
$ ( document ) . localize ( ) ;
1000
989
dhs . forEach ( ( dh ) => dh . render ( ) ) ;
1001
990
} ) ;
1002
- context . addTranslationResources (
1003
- context . template ,
1004
- context . getLocaleData ( )
1005
- ) ;
1006
-
1007
- // await context.setupDataHarmonizers();
1008
991
1009
992
// // TODO: data harmonizers require initialization code inside of the toolbar to fully render? wut
1010
993
new Toolbar ( dhToolbarRoot , context . getCurrentDataHarmonizer ( ) , menu , {
0 commit comments