Skip to content

Commit 57ea875

Browse files
committed
Debugging, fixed resource codelists
Fix save and re-edit values. Added GRIB to format, GEE collection to access modality
1 parent 499c27e commit 57ea875

File tree

2 files changed

+76
-43
lines changed

2 files changed

+76
-43
lines changed

_static/RDL_MDE.html

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,11 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
841841
* Handles all field creation needs across normal, modal, and array contexts
842842
*/
843843
class FieldCreationContext {
844-
constructor(type = 'normal', container = null) {
844+
constructor(type = 'normal', container = null, itemData = null) {
845845
this.type = type; // 'normal', 'modal', 'inline', 'array'
846846
this.container = container;
847847
this.idPrefix = type === 'modal' ? 'modal_' : '';
848+
this.itemData = itemData; // For inline context, stores the item being edited
848849
}
849850

850851
createField(name, property, value, options = {}) {
@@ -950,6 +951,17 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
950951
return { ...resolved, title: property.title || resolved.title, description: property.description || resolved.description };
951952
}
952953
}
954+
955+
// Handle anyOf - extract format if it exists in any of the options
956+
if (property.anyOf && !property.format) {
957+
for (const option of property.anyOf) {
958+
if (option.format) {
959+
// Create a merged property with the format from anyOf
960+
return { ...property, format: option.format };
961+
}
962+
}
963+
}
964+
953965
return property;
954966
}
955967

@@ -1002,7 +1014,13 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
10021014
// Check for dependencies
10031015
const dependsOn = FIELD_DEPENDENCIES[name];
10041016
if (dependsOn) {
1005-
const parentValue = getNestedValue(currentFormData, dependsOn);
1017+
// For inline context, get parent value from itemData; otherwise from currentFormData
1018+
let parentValue;
1019+
if (this.context.type === 'inline' && this.context.itemData) {
1020+
parentValue = this.context.itemData[dependsOn];
1021+
} else {
1022+
parentValue = getNestedValue(currentFormData, dependsOn);
1023+
}
10061024
return this.createDependentSelect(name, property, value, dependsOn, parentValue, options);
10071025
}
10081026

@@ -1238,7 +1256,7 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
12381256
createDependentSelect(name, property, value, dependsOn, parentValue, options) {
12391257
const select = document.createElement('select');
12401258
select.className = 'form-select field-with-validation';
1241-
console.log(`[CREATE DEPENDENT SELECT] Creating dependent select for "${name}", context type: "${this.context.type}", value: "${value}"`);
1259+
console.log(`[CREATE DEPENDENT SELECT] Creating dependent select for "${name}", context type: "${this.context.type}", value: "${value}", parentValue: "${parentValue}"`);
12421260
// Always set ID (needed for dependency system), but only set name for non-inline context
12431261
// (name attribute causes FormData collection, which we want to avoid for inline fields)
12441262
select.id = this.context.getFieldId(name);
@@ -1258,9 +1276,17 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
12581276
// Start with all available options
12591277
let availableOptions = property.enum || [];
12601278

1261-
// Filter options if we have a parent value
1262-
if (parentValue && currentSchema.hazard_process_mappings && name.includes('process')) {
1263-
availableOptions = currentSchema.hazard_process_mappings[parentValue] || property.enum || [];
1279+
// Filter options based on parent value
1280+
if (parentValue) {
1281+
if (currentSchema.hazard_process_mappings && name.includes('process')) {
1282+
// Filter process options based on hazard type
1283+
availableOptions = currentSchema.hazard_process_mappings[parentValue] || property.enum || [];
1284+
} else if (name.includes('intensity_measure')) {
1285+
// Filter IMT options based on hazard type
1286+
const filteredIMTs = getFilteredIMTOptions(parentValue);
1287+
availableOptions = filteredIMTs.map(opt => opt.code);
1288+
console.log(`[CREATE DEPENDENT SELECT] Filtered ${availableOptions.length} IMT options for hazard type "${parentValue}"`);
1289+
}
12641290
}
12651291

12661292
// Populate options
@@ -1283,7 +1309,7 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
12831309
select.appendChild(optionElement);
12841310
});
12851311

1286-
console.log(`[CREATE DEPENDENT SELECT] Finished creating select, selected value: "${select.value}"`);
1312+
console.log(`[CREATE DEPENDENT SELECT] Finished creating select with ${availableOptions.length} options, selected value: "${select.value}"`);
12871313

12881314
this.context.setupEventListeners(select, name, property, options);
12891315

@@ -1636,7 +1662,7 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
16361662
});
16371663
} else {
16381664
arrayData.forEach((item, index) => {
1639-
const objectCard = createObjectSummaryCard(item, index, name, property);
1665+
const objectCard = createObjectSummaryCard(item, index, name, property, arrayData, renderArrayItems);
16401666
itemsContainer.appendChild(objectCard);
16411667
});
16421668
}
@@ -1850,14 +1876,15 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
18501876
if (itemSchema && itemSchema.properties) {
18511877
Object.entries(itemSchema.properties).forEach(([key, prop]) => {
18521878
if (key === 'id') return; // Skip ID field
1853-
1879+
18541880
const fieldDiv = document.createElement('div');
18551881
fieldDiv.className = 'mb-2';
18561882
fieldDiv.setAttribute('data-field-name', key);
1857-
1883+
18581884
// Create a sub-context for inline editing
18591885
// Don't use ID/name attributes to avoid polluting FormData
1860-
const inlineContext = new FieldCreationContext('inline', fieldDiv);
1886+
// Pass item data so dependent fields can look up parent values
1887+
const inlineContext = new FieldCreationContext('inline', fieldDiv, item);
18611888
const fieldElement = inlineContext.createField(key, prop, item[key]);
18621889

18631890

@@ -1910,7 +1937,8 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
19101937
};
19111938

19121939
// Create context - don't use ID/name to avoid polluting FormData
1913-
const currencyContext = new FieldCreationContext('inline', currencyDiv);
1940+
// Pass item data so dependent fields can look up parent values
1941+
const currencyContext = new FieldCreationContext('inline', currencyDiv, item);
19141942
console.log(`[CURRENCY FIELD] Created context with type: ${currencyContext.type}`);
19151943
const savedCurrencyValue = item['currency'];
19161944
console.log(`[CURRENCY FIELD] Creating currency field for ${arrayName}[${index}], savedValue: "${savedCurrencyValue}"`);
@@ -2093,12 +2121,13 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
20932121
if (property.properties) {
20942122
Object.entries(property.properties).forEach(([key, prop]) => {
20952123
const fieldValue = value && value[key] ? value[key] : null;
2096-
const subContext = new FieldCreationContext(this.context.type, this.context.container);
2124+
// Pass itemData to sub-context so nested fields can access parent item data for dependencies
2125+
const subContext = new FieldCreationContext(this.context.type, this.context.container, this.context.itemData || value);
20972126
const field = subContext.createField(`${name}.${key}`, prop, fieldValue, options);
20982127
container.appendChild(field);
20992128
});
21002129
}
2101-
2130+
21022131
return container;
21032132
}
21042133

@@ -2932,27 +2961,27 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
29322961

29332962
rebuildDependentDropdown(selectElement, fieldName, parentValue) {
29342963
if (!parentValue) return;
2935-
2964+
29362965
console.log(`Rebuilding dropdown: ${fieldName} based on parent value: ${parentValue}`);
2937-
2966+
29382967
const currentValue = selectElement.value;
2939-
2968+
29402969
// Clear existing options
29412970
selectElement.innerHTML = '';
2942-
2971+
29432972
const emptyOption = document.createElement('option');
29442973
emptyOption.value = '';
29452974
emptyOption.textContent = 'Select an option...';
29462975
selectElement.appendChild(emptyOption);
2947-
2976+
29482977
// Get available options based on parent value
29492978
let availableOptions = [];
2950-
2979+
29512980
if ((fieldName.includes('process') || fieldName === 'processes') && currentSchema.hazard_process_mappings) {
29522981
availableOptions = currentSchema.hazard_process_mappings[parentValue] || [];
29532982
console.log(`Found ${availableOptions.length} process options for "${parentValue}":`, availableOptions);
29542983
}
2955-
2984+
29562985
// Populate new options
29572986
availableOptions.forEach(option => {
29582987
const optionElement = document.createElement('option');
@@ -2967,10 +2996,10 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
29672996
if (currentValue === option) {
29682997
optionElement.selected = true;
29692998
}
2970-
2999+
29713000
selectElement.appendChild(optionElement);
29723001
});
2973-
3002+
29743003
// If previous selection is no longer valid, clear it
29753004
if (currentValue && !availableOptions.includes(currentValue)) {
29763005
selectElement.value = '';
@@ -3953,8 +3982,8 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
39533982
const modalTitle = document.getElementById('objectEditorModalLabel');
39543983
modalTitle.textContent = `Edit ${objectSchema.title || arrayName}`;
39553984

3956-
// Always use the latest array data from currentFormData if available
3957-
const fullArrayData = getNestedValue(currentFormData, arrayName) || [];
3985+
// Use passed arrayData if available, otherwise get from currentFormData
3986+
const fullArrayData = arrayData || getNestedValue(currentFormData, arrayName) || [];
39583987
// Preload the object data from the array if it exists
39593988
// Only clone the object if editing, otherwise use empty object for new
39603989
let objectData = {};
@@ -4047,7 +4076,7 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
40474076
modal.show();
40484077
}
40494078

4050-
function createObjectSummaryCard(objectData, index, arrayName, arrayProperty) {
4079+
function createObjectSummaryCard(objectData, index, arrayName, arrayProperty, arrayData, renderCallback) {
40514080
const card = document.createElement('div');
40524081
card.className = 'object-summary-card';
40534082

@@ -4157,7 +4186,7 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
41574186
editBtn.className = 'btn btn-outline-primary btn-sm';
41584187
editBtn.textContent = '✏️ Edit';
41594188
editBtn.addEventListener('click', () => {
4160-
openObjectEditor(arrayName, index, arrayProperty.items, null, null);
4189+
openObjectEditor(arrayName, index, arrayProperty.items, arrayData, renderCallback);
41614190
});
41624191

41634192
const removeBtn = document.createElement('button');
@@ -4211,17 +4240,20 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
42114240
cards.forEach((card, index) => {
42124241
const item = {};
42134242
const fieldDivs = card.querySelectorAll('[data-field-name]');
4214-
4243+
42154244
fieldDivs.forEach(fieldDiv => {
42164245
const fieldNameAttr = fieldDiv.getAttribute('data-field-name');
42174246
if (fieldNameAttr && fieldNameAttr !== 'id') {
42184247
const input = fieldDiv.querySelector('input, select, textarea');
42194248
if (input) {
4220-
if (input.type === 'checkbox') {
4221-
item[fieldNameAttr] = input.checked;
4249+
const rawValue = input.type === 'checkbox' ? input.checked : input.value;
4250+
// Convert to proper type based on schema (only for non-checkbox fields)
4251+
const convertedValue = input.type === 'checkbox' ? rawValue : convertValueBySchema(fieldNameAttr, rawValue);
4252+
4253+
// Use setNestedValue to handle nested properties like 'hazard.type' or 'occurrence.probabilistic.return_period'
4254+
if (fieldNameAttr.includes('.')) {
4255+
setNestedValue(item, fieldNameAttr, convertedValue);
42224256
} else {
4223-
// Convert to proper type based on schema
4224-
const convertedValue = convertValueBySchema(fieldNameAttr, input.value);
42254257
item[fieldNameAttr] = convertedValue;
42264258
}
42274259
}

_static/rdls_schema_v0.3.json

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,7 @@
15361536
"Cloud Optimized GeoTIFF (cog)",
15371537
"GRID (grd)",
15381538
"NetCDF (nc)",
1539+
"GRIB (grib)",
15391540
"HDF5 (hdf5)",
15401541
"Zarr (zarr)",
15411542
"GeoPackage (gpkg)",
@@ -1561,17 +1562,17 @@
15611562
"codelist": "access_modality.csv",
15621563
"openCodelist": false,
15631564
"enum": [
1564-
"download",
1565-
"api",
1566-
"ogc_api_features",
1567-
"ogc_api_coverages",
1568-
"ogc_api_tiles",
1569-
"wms",
1570-
"wfs",
1571-
"wcs",
1572-
"stac",
1573-
"rest",
1574-
"website"
1565+
"File download",
1566+
"Download page",
1567+
"API",
1568+
"OGC_API",
1569+
"GEE_collection",
1570+
"WMS",
1571+
"WFS",
1572+
"WCS",
1573+
"STAC",
1574+
"REST",
1575+
"Dashboard"
15751576
]
15761577
},
15771578
"spatial_resolution": {

0 commit comments

Comments
 (0)