@@ -92,7 +92,7 @@ class AppContext {
92
92
93
93
}
94
94
95
- // TODO
95
+
96
96
async propagateChangeToChildren ( node_label , func = id => id ) {
97
97
const dependency_tree = ( await this . getDependencyTree ( ) ) ;
98
98
let current_node_label = node_label ;
@@ -368,14 +368,17 @@ const main = async function () {
368
368
` ) ;
369
369
370
370
let dhs = [ ] ;
371
+ let data_harmonizers = { } ;
371
372
372
373
const context = new AppContext ( new AppConfig ( await getTemplatePath ( ) ) ) ;
373
374
374
375
375
376
context . initializeTemplate ( context . appConfig . template_path )
376
377
. then ( async ( context ) => {
377
378
const _template = context . template ;
378
- const _export_formats = ( await context . getExportFormats ( 'grdi' ) ) ;
379
+ const _schema = _template . current . schema ;
380
+ const [ _template_name , _schema_name ] = context . appConfig . template_path . split ( '/' ) ;
381
+ const _export_formats = ( await context . getExportFormats ( _template_name ) ) ;
379
382
380
383
// // internationalize
381
384
// // TODO: connect to locale of browser!
@@ -570,7 +573,6 @@ const main = async function () {
570
573
} ;
571
574
572
575
const shared_keys_per_class = findSharedKeys ( schema ) ;
573
-
574
576
const pre_schema_tree = classes . reduce ( ( acc , class_key ) => {
575
577
acc [ class_key ] = {
576
578
name : class_key ,
@@ -590,7 +592,6 @@ const main = async function () {
590
592
* @param {Function } callback - The function to perform on each class node.
591
593
*/
592
594
function visitSchemaTree ( schema_tree , callback = tap , next = 'Container' ) {
593
- console . log ( 'visitSchemaTree' , schema_tree )
594
595
if ( ! schema_tree [ next ] ) return ; // Base case: If the class key is not found
595
596
callback ( schema_tree [ next ] ) ; // Perform the callback on the current node
596
597
@@ -639,11 +640,12 @@ const main = async function () {
639
640
640
641
let data_harmonizers = { } ;
641
642
if ( ! ! schema_tree ) {
642
- Object . entries ( schema_tree ) . forEach ( ( obj , index ) => {
643
+ Object . entries ( schema_tree ) . filter ( ( [ cls_key , ] ) => cls_key !== 'Container' ) . forEach ( ( obj , index ) => {
643
644
if ( obj . length > 0 ) {
644
645
const [ cls_key , spec ] = obj ;
645
646
const dhId = `data-harmonizer-grid-${ index } ` ;
646
647
let dhSubroot = createDataHarmonizerContainer ( dhId , index === 0 ) ;
648
+
647
649
dhRoot . appendChild ( dhSubroot ) ; // Appending to the parent container
648
650
649
651
const dhTab = createDataHarmonizerTab ( dhId , spec . name , index === 0 ) ;
@@ -656,9 +658,8 @@ const main = async function () {
656
658
loadingScreenRoot : document . body ,
657
659
field_filters : findSlotNamesForClass ( schema , cls_key ) // TODO: Find slot names for filtering
658
660
} ) ;
659
- // initialize the data harmonizer
660
- // TODO
661
- data_harmonizers [ spec . name ] . useSchema ( schema , _export_formats , 'GRDI_Sample' ) ;
661
+
662
+ data_harmonizers [ spec . name ] . useSchema ( _schema , _export_formats , _schema_name ) ;
662
663
663
664
}
664
665
} ) ;
@@ -674,28 +675,32 @@ const main = async function () {
674
675
* @param {* } old_value - The original value to replace.
675
676
* @param {* } new_value - The new value to replace the original with.
676
677
*/
677
- function transformMultivaluedColumn ( data_harmonizer , column_name , old_value , new_value ) {
678
+ function transformMultivaluedColumn ( data_harmonizer , shared_field , changes , source , old_value , new_value ) {
678
679
const hot = data_harmonizer . hot ;
680
+
681
+ console . log ( 'transform multivalued column execute' , shared_field , changes , source , old_value , new_value ) ;
682
+ console . log ( hot . propToCol ( shared_field . name ) )
679
683
// Verify if column_name is a valid property
680
- if ( hot . propToCol ( column_name ) === - 1 ) {
684
+ if ( hot . propToCol ( shared_field . name ) === - 1 ) {
681
685
console . error ( `Invalid column name: ${ column_name } ` ) ;
682
- return ;
686
+ } else {
687
+ if ( old_value !== new_value ) hot . setDataAtCell ( changes [ 0 ] [ 0 ] , changes [ 0 ] [ 1 ] , new_value ) ;
688
+
689
+ // TODO
690
+ // Perform batch operation to replace old_value with new_value where the condition matches
691
+ // const matchCondition = row => row[column_name] === old_value;
692
+ // hot.batch(() => {
693
+ // hot.getSourceData().forEach((row, rowIndex) => {
694
+ // if (matchCondition(row)) {
695
+ // // Set new value for a property of matched rows
696
+ // hot.setDataAtRowProp(rowIndex, column_name, new_value);
697
+ // }
698
+ // });
699
+ // });
700
+
701
+ // Rerender table after setting data to reflect changes
702
+ hot . render ( ) ;
683
703
}
684
-
685
- const matchCondition = row => row [ column_name ] === old_value ;
686
-
687
- // Perform batch operation to replace old_value with new_value where the condition matches
688
- hot . batch ( ( ) => {
689
- hot . getSourceData ( ) . forEach ( ( row , rowIndex ) => {
690
- if ( matchCondition ( row ) ) {
691
- // Set new value for a property of matched rows
692
- hot . setDataAtRowProp ( rowIndex , column_name , new_value ) ;
693
- }
694
- } ) ;
695
- } ) ;
696
-
697
- // Rerender table after setting data to reflect changes
698
- hot . render ( ) ;
699
704
700
705
} ;
701
706
@@ -738,33 +743,31 @@ const main = async function () {
738
743
*/
739
744
function attachColumnEditHandler ( data_harmonizer , shared_key_name , callback ) {
740
745
const hot = data_harmonizer . hot ;
741
- console . log ( 'attaching column edit handler to ' , hot ) ;
742
-
743
746
// Get the index of the column based on the shared_key_name
744
747
const columnIndex = hot . propToCol ( shared_key_name ) ;
745
-
748
+
746
749
// Check if the column index was found properly
747
750
if ( columnIndex === - 1 ) {
748
751
console . error ( `Column with the name '${ shared_key_name } ' not found.` ) ;
749
- return ;
750
- }
751
-
752
- // Listen for changes using the afterChange hook of Handsontable
753
- hot . addHook ( 'afterChange' , ( changes , source ) => {
754
- // changes is a 2D array containing information about each change
755
- // Each change is of the form [row, prop, oldVal, newVal]
756
- if ( changes && source !== 'loadData' ) { // Ignore initial load changes
757
- changes . forEach ( ( [ row , prop , oldVal , newVal ] ) => {
758
- if ( hot . propToCol ( prop ) === columnIndex ) {
759
- console . log ( `Column ' ${ shared_key_name } ' changed at row ${ row } ` ) ;
760
- // You can put here the code that should be executed when
761
- // the specific column has been edited .
762
- // This could be a function call, an event dispatch, etc.
763
- callback ( changes , source , oldVal , newVal ) ;
764
- }
752
+ } else {
753
+ // Listen for changes using the afterChange hook of Handsontable
754
+ hot . addHook ( 'afterChange' , ( changes , source ) => {
755
+ console . log ( 'afterchange hook execute' , changes , source )
756
+ // changes is a 2D array containing information about each change
757
+ // Each change is of the form [row, prop, oldVal, newVal]
758
+ if ( changes && source !== 'loadData' ) { // Ignore initial load changes
759
+ changes . forEach ( ( [ row , prop , oldVal , newVal ] ) => {
760
+ console . log ( prop , hot . propToCol ( prop ) , columnIndex , shared_key_name , oldVal , newVal ) ;
761
+ console . log ( `Column ' ${ shared_key_name } ' changed at row ${ row } ` ) ;
762
+ // You can put here the code that should be executed when
763
+ // the specific column has been edited.
764
+ // This could be a function call, an event dispatch, etc .
765
+ callback ( changes , source , oldVal , newVal ) ;
766
+ } ) ;
767
+ }
765
768
} ) ;
766
- }
767
- } ) ;
769
+ }
770
+
768
771
}
769
772
770
773
/**
@@ -773,21 +776,24 @@ const main = async function () {
773
776
* @param {Object } schema_tree_node - The schema tree node containing the shared keys and child references.
774
777
*/
775
778
function makeSharedKeyHandler ( data_harmonizer , schema_tree_node ) {
776
- console . log ( 'makeSharedKeyHandler' , data_harmonizer ) ;
777
779
if ( schema_tree_node . shared_keys . length > 0 ) {
778
780
schema_tree_node . shared_keys . forEach ( ( shared_key_name ) => {
779
-
780
781
const updateSchemaNodeChildrenCallback = ( changes , source , old_value , new_value ) => {
781
- schema_tree_node . children . forEach ( cls_key => {
782
- transformMultivaluedColumn ( data_harmonizer , shared_key_name , old_value , new_value ) ;
783
- visitSchemaTree ( schema_tree , ( schema_tree_node ) => {
784
- schema_tree_node . children . forEach ( cls_key => {
785
- visitSchemaTree ( schema_tree , ( ) => transformMultivaluedColumn ( data_harmonizer , shared_key_name , old_value , new_value ) , next = cls_key )
786
- } )
787
- } , next = cls_key )
788
- } )
782
+ if ( schema_tree_node . children . length > 0 ) {
783
+ schema_tree_node . children . forEach ( cls_key => {
784
+ transformMultivaluedColumn ( data_harmonizers [ cls_key ] , shared_key_name , changes , source , old_value , new_value ) ;
785
+ // TODO
786
+ // visitSchemaTree(schema_tree, (schema_tree_node) => {
787
+ // schema_tree_node.children.forEach(cls_key => {
788
+ // visitSchemaTree(schema_tree, () => transformMultivaluedColumn(data_harmonizers[cls_key], shared_key_name, changes, source, old_value, new_value), cls_key)
789
+ // })
790
+ // }, cls_key);
791
+ } ) ;
792
+
793
+ } else {
794
+ console . log ( 'no more iteration for' , schema_tree_node . name ) ;
795
+ }
789
796
} ;
790
-
791
797
attachColumnEditHandler ( data_harmonizer , shared_key_name , updateSchemaNodeChildrenCallback ) ;
792
798
793
799
} ) ;
@@ -804,8 +810,6 @@ const main = async function () {
804
810
* @returns {Object } The same object with event handlers attached.
805
811
*/
806
812
function attachPropagationEventHandlersToDataHarmonizers ( data_harmonizers , schema_tree ) {
807
- console . log ( 'data_harmonizers' , data_harmonizers ) ;
808
- console . log ( 'schema_tree' , schema_tree )
809
813
810
814
visitSchemaTree ( schema_tree , ( schema_tree_node ) => {
811
815
// Propagation:
@@ -824,14 +828,14 @@ const main = async function () {
824
828
function initializeDataHarmonizers ( data_harmonizers ) {
825
829
console . log ( 'data_harmonizers' , data_harmonizers ) ;
826
830
Object . entries ( data_harmonizers ) . forEach ( ( [ cls_key , ] , index ) => {
827
- new Toolbar ( dhToolbarRoot , data_harmonizers [ cls_key ] , menu , {
828
- context : context ,
829
- templatePath : context . appConfig . template_path , // TODO: a default should be loaded before Toolbar is constructed! then take out all loading in "toolbar" to an outside context
830
- releasesURL : 'https: // gi thub.com/cidgoh/pathogen-genomics-package/releases' ,
831
- getLanguages : context . getLocaleData . bind ( context ) ,
832
- getSchema : async ( schema ) => Template . create ( schema ) . then ( result => result . current . schema ) ,
833
- getExportFormats : context . getExportFormats . bind ( context ) ,
834
- } ) ;
831
+ // new Toolbar(dhToolbarRoot, data_harmonizers[cls_key], menu, {
832
+ // context: context,
833
+ // templatePath: context.appConfig.template_path, // TODO: a default should be loaded before Toolbar is constructed! then take out all loading in "toolbar" to an outside context
834
+ // releasesURL: 'https: // gi thub.com/cidgoh/pathogen-genomics-package/releases',
835
+ // getLanguages: context.getLocaleData.bind(context),
836
+ // getSchema: async (schema) => Template.create(schema).then(result => result.current.schema),
837
+ // getExportFormats: context.getExportFormats.bind(context),
838
+ // });
835
839
} ) ;
836
840
console . log ( 'before attachPropagationEventHandlersToDataHarmonizers' ) ;
837
841
attachPropagationEventHandlersToDataHarmonizers ( data_harmonizers , schema_tree ) ;
@@ -842,7 +846,7 @@ const main = async function () {
842
846
const schema_tree = buildSchemaTree ( ( await context . getSchema ( ) ) ) ;
843
847
console . log ( 'schema_tree' , schema_tree ) ;
844
848
console . log ( 'before makeDataHarmonizersFromSchemaTree' ) ;
845
- let data_harmonizers = makeDataHarmonizersFromSchemaTree (
849
+ data_harmonizers = makeDataHarmonizersFromSchemaTree (
846
850
( await context . getSchema ( ) ) ,
847
851
schema_tree ) ;
848
852
// HACK
0 commit comments