@@ -3616,6 +3616,8 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
36163616 summaryText = hazardDisplay ;
36173617 } else if ( arrayName . includes ( 'losses' ) && objectData . hazard_type ) {
36183618 summaryText = objectData . hazard_type . replace ( / _ / g, ' ' ) . replace ( / \b \w / g, l => l . toUpperCase ( ) ) + ' Loss' ;
3619+ } else if ( arrayName . includes ( 'socio_economic' ) && objectData . indicator_name ) {
3620+ summaryText = objectData . indicator_name ;
36193621 } else if ( objectData . name ) {
36203622 summaryText = objectData . name ;
36213623 } else if ( objectData . title ) {
@@ -4416,39 +4418,57 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
44164418 vulnerabilityValid = false ;
44174419 vulnerabilityError = 'Dataset with vulnerability risk_data_type must have vulnerability metadata' ;
44184420 } else {
4419- // Define required vulnerability attributes
4420- const requiredVulnerabilityAttributes = [
4421- { field : 'hazard_primary' , name : 'primary hazard type' } ,
4422- { field : 'hazard_analysis_type' , name : 'hazard analysis type' } ,
4423- { field : 'intensity' , name : 'hazard intensity measurement' } ,
4424- { field : 'category' , name : 'exposure category' } ,
4425- { field : 'impact_type' , name : 'impact type' } ,
4426- { field : 'impact_modelling' , name : 'impact modelling' } ,
4427- { field : 'impact_metric' , name : 'impact metric' } ,
4428- { field : 'quantity_kind' , name : 'quantity kind' }
4429- ] ;
4430-
4431- // Check each required attribute
4432- for ( const attr of requiredVulnerabilityAttributes ) {
4433- if ( ! vulnerability [ attr . field ] || vulnerability [ attr . field ] . toString ( ) . trim ( ) === '' ) {
4434- vulnerabilityValid = false ;
4435- vulnerabilityError = `Vulnerability is missing required ${ attr . name } ` ;
4436- break ;
4421+ // Check which approach is being used
4422+ // hasFunctions should only be true if there are actual non-empty function arrays
4423+ const hasFunctions = vulnerability . functions && Object . keys ( vulnerability . functions ) . some ( key => {
4424+ const funcArray = vulnerability . functions [ key ] ;
4425+ return Array . isArray ( funcArray ) && funcArray . length > 0 ;
4426+ } ) ;
4427+ const hasSocioEconomic = vulnerability . socio_economic && vulnerability . socio_economic . length > 0 ;
4428+
4429+ if ( ! hasFunctions && ! hasSocioEconomic ) {
4430+ vulnerabilityValid = false ;
4431+ vulnerabilityError = 'Vulnerability must specify at least one approach: vulnerability functions, fragility functions, damage-to-loss functions, engineering demand functions, or socio-economic indicators' ;
4432+ } else if ( hasSocioEconomic && ! hasFunctions ) {
4433+ // Socio-economic only: validate that each indicator has required fields
4434+ for ( let i = 0 ; i < vulnerability . socio_economic . length ; i ++ ) {
4435+ const indicator = vulnerability . socio_economic [ i ] ;
4436+ const requiredFields = [
4437+ { field : 'indicator_name' , name : 'indicator name' } ,
4438+ { field : 'indicator_code' , name : 'indicator code' } ,
4439+ { field : 'description' , name : 'description' } ,
4440+ { field : 'reference_year' , name : 'reference year' }
4441+ ] ;
4442+
4443+ for ( const attr of requiredFields ) {
4444+ if ( ! indicator [ attr . field ] || indicator [ attr . field ] . toString ( ) . trim ( ) === '' ) {
4445+ vulnerabilityValid = false ;
4446+ vulnerabilityError = `Socio-economic indicator ${ i + 1 } is missing required ${ attr . name } ` ;
4447+ break ;
4448+ }
4449+ }
4450+ if ( ! vulnerabilityValid ) break ;
44374451 }
4438- }
4452+ } else if ( hasFunctions ) {
4453+ // Function-based approach: validate required vulnerability attributes
4454+ const requiredVulnerabilityAttributes = [
4455+ { field : 'hazard_primary' , name : 'primary hazard type' } ,
4456+ { field : 'hazard_analysis_type' , name : 'hazard analysis type' } ,
4457+ { field : 'intensity' , name : 'hazard intensity measurement' } ,
4458+ { field : 'category' , name : 'exposure category' } ,
4459+ { field : 'impact_type' , name : 'impact type' } ,
4460+ { field : 'impact_modelling' , name : 'impact modelling' } ,
4461+ { field : 'impact_metric' , name : 'impact metric' } ,
4462+ { field : 'quantity_kind' , name : 'quantity kind' }
4463+ ] ;
44394464
4440- // Check that at least one vulnerability approach is present
4441- if ( vulnerabilityValid ) {
4442- const hasVulnerabilityApproach =
4443- ( vulnerability . functions ?. vulnerability ) ||
4444- ( vulnerability . functions ?. fragility ) ||
4445- ( vulnerability . functions ?. damage_to_loss ) ||
4446- ( vulnerability . functions ?. engineering_demand ) ||
4447- ( vulnerability . se_indicator ) ;
4448-
4449- if ( ! hasVulnerabilityApproach ) {
4450- vulnerabilityValid = false ;
4451- vulnerabilityError = 'Vulnerability must specify at least one approach: vulnerability function, fragility function, damage-to-loss function, engineering demand function, or socio-economic vulnerability indicator' ;
4465+ // Check each required attribute
4466+ for ( const attr of requiredVulnerabilityAttributes ) {
4467+ if ( ! vulnerability [ attr . field ] || vulnerability [ attr . field ] . toString ( ) . trim ( ) === '' ) {
4468+ vulnerabilityValid = false ;
4469+ vulnerabilityError = `Vulnerability is missing required ${ attr . name } ` ;
4470+ break ;
4471+ }
44524472 }
44534473 }
44544474 }
@@ -5154,10 +5174,49 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
51545174 try {
51555175 let loadedData = JSON . parse ( event . target . result ) ;
51565176
5177+ // Check if this is a package with datasets array
5178+ if ( loadedData . datasets && Array . isArray ( loadedData . datasets ) ) {
5179+ if ( loadedData . datasets . length === 0 ) {
5180+ alert ( 'The package contains no datasets.' ) ;
5181+ return ;
5182+ }
5183+ // Alert if multiple datasets
5184+ if ( loadedData . datasets . length > 1 ) {
5185+ alert ( 'Package contains multiple datasets. Loading the first dataset only.' ) ;
5186+ }
5187+ // Load the first dataset
5188+ loadedData = loadedData . datasets [ 0 ] ;
5189+ }
5190+
51575191 // Migrate attribution data from old format to new format
51585192 loadedData = migrateAttributionData ( loadedData ) ;
51595193
51605194 currentFormData = loadedData ;
5195+
5196+ // Activate sections based on loaded data
5197+ activeSections . clear ( ) ;
5198+ activeSections . add ( 'general' ) ;
5199+
5200+ SECTIONS . forEach ( section => {
5201+ const checkbox = document . getElementById ( `${ section } Check` ) ;
5202+ if ( loadedData [ section ] ) {
5203+ activeSections . add ( section ) ;
5204+ if ( checkbox ) {
5205+ checkbox . checked = true ;
5206+ }
5207+ // Only add tab if it doesn't already exist
5208+ const existingTab = document . getElementById ( `${ section } -tab` ) ;
5209+ if ( ! existingTab ) {
5210+ addSectionTab ( section ) ;
5211+ }
5212+ } else {
5213+ if ( checkbox ) {
5214+ checkbox . checked = false ;
5215+ }
5216+ removeSectionTab ( section ) ;
5217+ }
5218+ } ) ;
5219+
51615220 updatePreview ( ) ;
51625221 generateForm ( ) ;
51635222 } catch ( error ) {
0 commit comments