@@ -15,7 +15,10 @@ import {
15
15
prependToSheet ,
16
16
} from '@/lib/utils/files' ;
17
17
import { nullValuesToString , isEmptyUnitVal } from '@/lib/utils/general' ;
18
- import { MULTIVALUED_DELIMITER , titleOverText , slotNamesForTitlesMap } from '@/lib/utils/fields' ;
18
+ import {
19
+ MULTIVALUED_DELIMITER ,
20
+ titleOverText ,
21
+ } from '@/lib/utils/fields' ;
19
22
import { takeKeys , invert } from '@/lib/utils/objects' ;
20
23
import {
21
24
findBestLocaleMatch ,
@@ -164,7 +167,6 @@ class Toolbar {
164
167
165
168
if ( supportsLocale ) {
166
169
try {
167
-
168
170
// first cache data
169
171
const current_template = this . context . appConfig . template_path ;
170
172
let _dh_data_cache = { } ;
@@ -180,7 +182,7 @@ class Toolbar {
180
182
}
181
183
182
184
// reload the context with the new locale
183
-
185
+
184
186
await this . context
185
187
. reload ( current_template , {
186
188
locale : language_update ,
@@ -200,9 +202,7 @@ class Toolbar {
200
202
// Jump to modal as well
201
203
this . setupJumpToModal ( initialDh ) ;
202
204
this . setupFillModal ( initialDh ) ;
203
-
204
205
} ) ;
205
-
206
206
} catch ( error ) {
207
207
if ( error instanceof LocaleNotSupportedError ) {
208
208
console . warn ( error ) ;
@@ -412,7 +412,6 @@ class Toolbar {
412
412
}
413
413
const locale = in_language ;
414
414
415
-
416
415
await this . context
417
416
. reload ( template_path , { locale } )
418
417
. then ( ( context ) => {
@@ -475,77 +474,75 @@ class Toolbar {
475
474
const schema_container =
476
475
this . context . template . default . schema . classes . Container ;
477
476
const Container = Object . entries (
478
- // default schema is guaranteed to feature the Container
479
- schema_container . attributes
480
- ) . reduce ( ( acc , [ cls_key , { name, range } ] ) => {
481
-
482
- // TODO: check if container attributes always have ranges?
483
- if ( typeof range !== 'undefined' ) {
484
- const processedClass = {
485
- [ name ] : MultiEntityJSON [ range ]
486
- . map ( ( obj ) => nullValuesToString ( obj ) )
487
- . map ( ( entry ) => {
488
- // translation: if available, use title over text given a non-default localization for export
489
- // TODO?: check if current lang is equal to current schema lang?
490
- const fields = this . context . dhs [ range ] . getFields ( ) ;
491
- const findField = ( colKey ) =>
492
- fields . filter ( ( field ) => field . title === colKey ) [ 0 ] ;
493
- entry = Object . fromEntries (
494
- Object . entries ( entry ) . map ( ( [ k , v ] ) => {
495
- const field = findField ( k ) ;
496
- let nv = v ;
497
- if ( field . sources && ! isEmptyUnitVal ( v ) ) {
498
- const merged_permissible_values = field . sources . reduce (
499
- ( acc , source ) => {
500
- return Object . assign (
501
- acc ,
502
- field . permissible_values [ source ]
503
- ) ;
504
- } ,
505
- { }
506
- ) ;
507
- if ( field . multivalued === true ) {
508
- nv = v
509
- . split ( MULTIVALUED_DELIMITER )
510
- . map ( ( _v ) => {
511
- if ( ! ( _v in merged_permissible_values ) )
512
- console . warn (
513
- `${ _v } not in merged_permissible_values ${ Object . keys (
514
- merged_permissible_values
515
- ) } `
516
- ) ;
517
- return _v in merged_permissible_values
518
- ? titleOverText ( merged_permissible_values [ _v ] )
519
- : _v ;
520
- } )
521
- . join ( MULTIVALUED_DELIMITER ) ;
522
- } else {
523
- if ( ! ( v in merged_permissible_values ) )
524
- console . warn (
525
- `${ v } not in merged_permissible_values ${ Object . keys (
526
- merged_permissible_values
527
- ) } `
528
- ) ;
529
- nv =
530
- v in merged_permissible_values
531
- ? titleOverText ( merged_permissible_values [ v ] )
532
- : v ;
533
- }
477
+ // default schema is guaranteed to feature the Container
478
+ schema_container . attributes
479
+ ) . reduce ( ( acc , [ cls_key , { name, range } ] ) => {
480
+ // TODO: check if container attributes always have ranges?
481
+ if ( typeof range !== 'undefined' ) {
482
+ const processedClass = {
483
+ [ name ] : MultiEntityJSON [ range ]
484
+ . map ( ( obj ) => nullValuesToString ( obj ) )
485
+ . map ( ( entry ) => {
486
+ // translation: if available, use title over text given a non-default localization for export
487
+ // TODO?: check if current lang is equal to current schema lang?
488
+ const fields = this . context . dhs [ range ] . getFields ( ) ;
489
+ const findField = ( colKey ) =>
490
+ fields . filter ( ( field ) => field . title === colKey ) [ 0 ] ;
491
+ entry = Object . fromEntries (
492
+ Object . entries ( entry ) . map ( ( [ k , v ] ) => {
493
+ const field = findField ( k ) ;
494
+ let nv = v ;
495
+ if ( field . sources && ! isEmptyUnitVal ( v ) ) {
496
+ const merged_permissible_values = field . sources . reduce (
497
+ ( acc , source ) => {
498
+ return Object . assign (
499
+ acc ,
500
+ field . permissible_values [ source ]
501
+ ) ;
502
+ } ,
503
+ { }
504
+ ) ;
505
+ if ( field . multivalued === true ) {
506
+ nv = v
507
+ . split ( MULTIVALUED_DELIMITER )
508
+ . map ( ( _v ) => {
509
+ if ( ! ( _v in merged_permissible_values ) )
510
+ console . warn (
511
+ `${ _v } not in merged_permissible_values ${ Object . keys (
512
+ merged_permissible_values
513
+ ) } `
514
+ ) ;
515
+ return _v in merged_permissible_values
516
+ ? titleOverText ( merged_permissible_values [ _v ] )
517
+ : _v ;
518
+ } )
519
+ . join ( MULTIVALUED_DELIMITER ) ;
520
+ } else {
521
+ if ( ! ( v in merged_permissible_values ) )
522
+ console . warn (
523
+ `${ v } not in merged_permissible_values ${ Object . keys (
524
+ merged_permissible_values
525
+ ) } `
526
+ ) ;
527
+ nv =
528
+ v in merged_permissible_values
529
+ ? titleOverText ( merged_permissible_values [ v ] )
530
+ : v ;
534
531
}
535
- return [ k , nv ] ;
536
- } )
537
- ) ;
538
- return entry ;
539
- } ) ,
540
- } ;
541
-
542
-
543
- return Object . assign ( acc , processedClass ) ;
544
- } else {
545
- console . warn ( 'Container entry has no range:' , cls_key ) ;
546
- return acc ;
547
- }
548
- } , { } ) ;
532
+ }
533
+ return [ k , nv ] ;
534
+ } )
535
+ ) ;
536
+ return entry ;
537
+ } ) ,
538
+ } ;
539
+
540
+ return Object . assign ( acc , processedClass ) ;
541
+ } else {
542
+ console . warn ( 'Container entry has no range:' , cls_key ) ;
543
+ return acc ;
544
+ }
545
+ } , { } ) ;
549
546
550
547
const JSONFormat = {
551
548
schema : this . context . template . schema . id ,
@@ -556,21 +553,23 @@ class Toolbar {
556
553
} ;
557
554
558
555
if ( ext === 'json' ) {
559
-
560
- const filterFunctionTemplate = ( condCallback = ( ) => true , keyCallback = ( id ) => id ) => obj =>
561
- Object . keys ( obj ) . reduce ( ( acc , itemKey ) => {
562
- return condCallback ( obj , acc , itemKey )
563
- ? {
564
- ...acc ,
565
- [ keyCallback ( itemKey ) ] : obj [ itemKey ] ,
566
- }
567
- : acc ;
568
- } , { } ) ;
556
+ const filterFunctionTemplate =
557
+ ( condCallback = ( ) => true , keyCallback = ( id ) => id ) =>
558
+ ( obj ) =>
559
+ Object . keys ( obj ) . reduce ( ( acc , itemKey ) => {
560
+ return condCallback ( obj , acc , itemKey )
561
+ ? {
562
+ ...acc ,
563
+ [ keyCallback ( itemKey ) ] : obj [ itemKey ] ,
564
+ }
565
+ : acc ;
566
+ } , { } ) ;
569
567
570
568
const filterEmptyKeys = filterFunctionTemplate (
571
- ( obj , acc , itemKey ) => itemKey in obj && ! ( itemKey in acc ) && obj [ itemKey ] != '' ,
572
- id => id ,
573
- )
569
+ ( obj , acc , itemKey ) =>
570
+ itemKey in obj && ! ( itemKey in acc ) && obj [ itemKey ] != '' ,
571
+ ( id ) => id
572
+ ) ;
574
573
575
574
// const fields = this.context.getCurrentDataHarmonizer().getFields();
576
575
// const slotNamesForTitles = slotNamesForTitlesMap(fields);
@@ -580,9 +579,8 @@ class Toolbar {
580
579
// (em) => slotNamesForTitles[em],
581
580
// )
582
581
583
- const processEntryKeys = ( lst ) =>
584
- lst . map ( filterEmptyKeys )
585
- // .map(projectSlotNamestToTitles);
582
+ const processEntryKeys = ( lst ) => lst . map ( filterEmptyKeys ) ;
583
+ // .map(projectSlotNamestToTitles);
586
584
587
585
for ( let concept in JSONFormat . Container ) {
588
586
JSONFormat . Container [ concept ] = processEntryKeys (
@@ -596,7 +594,6 @@ class Toolbar {
596
594
ext ,
597
595
] ) ;
598
596
} else {
599
-
600
597
const sectionCoordinatesByClass = Object . values ( this . context . dhs ) . reduce (
601
598
( acc , dh ) => {
602
599
const sectionTiles = dh . sections . map ( ( s ) => s . title ) ;
@@ -885,7 +882,7 @@ class Toolbar {
885
882
let { template_path, schema } = loadResult ;
886
883
887
884
// RELOAD THE INTERFACE BY INTERACTING WITH THE CONTEXT
888
-
885
+
889
886
this . context
890
887
. reload ( template_path , {
891
888
forced_schema : file ? schema : null ,
0 commit comments