@@ -19,7 +19,7 @@ import { MULTIVALUED_DELIMITER, titleOverText } from '../lib/utils/fields';
19
19
import { takeKeys , invert } from '../lib/utils/objects' ;
20
20
import {
21
21
findBestLocaleMatch ,
22
- templatePathForSchemaURI ,
22
+ // templatePathForSchemaURI,
23
23
rangeToContainerClass ,
24
24
LocaleNotSupportedError ,
25
25
} from '../lib/utils/templates' ;
@@ -225,10 +225,13 @@ class Toolbar {
225
225
// provided attempt to use that one. If not the first item in the menu
226
226
// will be used.
227
227
this . updateTemplateOptions ( ) ;
228
+
228
229
if ( options . templatePath ) {
229
- const [ folder , template ] = options . templatePath . split ( '/' ) ;
230
- if ( folder in this . menu && template in this . menu [ folder ] ) {
231
- this . $selectTemplate . val ( options . templatePath ) ;
230
+ const [ schema_folder , template_name ] = options . templatePath . split ( '/' ) ;
231
+ for ( const [ schema_name , schema_obj ] of Object . entries ( this . menu ) ) {
232
+ if ( 'folder' in schema_obj && schema_obj [ 'folder' ] == schema_folder && template_name in schema_obj [ 'templates' ] ) {
233
+ this . $selectTemplate . val ( options . templatePath ) ;
234
+ }
232
235
}
233
236
}
234
237
this . loadSelectedTemplate ( ) ;
@@ -309,14 +312,12 @@ class Toolbar {
309
312
310
313
updateTemplateOptions ( ) {
311
314
this . $selectTemplate . empty ( ) ;
312
- //const view_drafts = $('#view-template-drafts').is(':checked');
313
- for ( const [ folder , templates ] of Object . entries ( this . menu ) ) {
314
- for ( const [ name , template ] of Object . entries ( templates ) ) {
315
- let path = folder + '/' + name ;
316
- if ( template . display ) {
317
- // if (view_drafts || template.status == 'published') {
315
+ for ( const [ schema_name , schema_obj ] of Object . entries ( this . menu ) ) {
316
+ const templates = schema_obj [ 'templates' ] ;
317
+ for ( const [ template_name , template_obj ] of Object . entries ( templates ) ) {
318
+ let path = schema_obj . folder + '/' + template_name ;
319
+ if ( template_obj . display ) {
318
320
this . $selectTemplate . append ( new Option ( path , path ) ) ;
319
- // }
320
321
}
321
322
}
322
323
}
@@ -363,6 +364,7 @@ class Toolbar {
363
364
}
364
365
365
366
async openFile ( ) {
367
+
366
368
const file = $ ( '#open-file-input' ) [ 0 ] . files [ 0 ] ;
367
369
const ext = file . name . split ( '.' ) . pop ( ) ;
368
370
const acceptedExts = [ 'xlsx' , 'xls' , 'tsv' , 'csv' , 'json' ] ;
@@ -378,7 +380,7 @@ class Toolbar {
378
380
// its Container class contains template spec itself.
379
381
// It may have several dhs, one for each Container class mentioned.
380
382
const contentBuffer = await readFileAsync ( file ) ;
381
-
383
+ //alert("opening " + file.name)
382
384
let jsonData ;
383
385
try {
384
386
jsonData = JSON . parse ( contentBuffer . text ) ;
@@ -465,7 +467,6 @@ class Toolbar {
465
467
const baseName = $ ( '#base-name-save-as-input' ) . val ( ) ;
466
468
const ext = $ ( '#file-ext-save-as-select' ) . val ( ) ;
467
469
const lang = $ ( '#select-translation-localization' ) . val ( ) ;
468
-
469
470
const MultiEntityJSON = Object . values ( this . context . dhs ) . reduce (
470
471
( acc , dh ) => {
471
472
return Object . assign ( acc , { [ dh . class_assignment ] : dh . toJSON ( ) } ) ;
@@ -480,8 +481,10 @@ class Toolbar {
480
481
schema_container . attributes
481
482
) . reduce ( ( acc , [ cls_key , { name, range } ] ) => {
482
483
// TODO: check if container attributes always have ranges?
483
- if ( typeof range !== 'undefined' ) {
484
+ if ( typeof range !== 'undefined' && range == this . context . current_data_harmonizer_name ) {
485
+ //Or test range against this.context.appConfig.template_path.split('/')[1]
484
486
const processedClass = {
487
+
485
488
[ name ] : MultiEntityJSON [ range ]
486
489
. map ( ( obj ) => nullValuesToString ( obj ) )
487
490
. map ( ( entry ) => {
@@ -1066,10 +1069,12 @@ class Toolbar {
1066
1069
$ ( '#section-menu' ) . localize ( ) ;
1067
1070
}
1068
1071
1072
+ // NOT USED UNLESS LOADING FILE?
1069
1073
async _defaultGetSchema ( schemaName ) {
1070
1074
return this . menu [ schemaName ] . schema ;
1071
1075
}
1072
1076
1077
+ // NOT USED UNLESS LOADING FILE?
1073
1078
async _defaultGetExportFormats ( schemaName ) {
1074
1079
return this . menu [ schemaName ] . exportFormats ;
1075
1080
}
0 commit comments