Skip to content

Commit 1449a6f

Browse files
committed
Several fixes
Schema Changes (rdls_schema_v0.3.json) Removed geometry field from Location definition and updated spatial description Fixed risk_data_type structure - moved $ref under items array to match proper schema pattern Changed oneOf to anyOf for date validation in Period start/end fields Metadata Editor Changes (RDL_MDE.html) Fixed bbox/centroid empty values - now outputs empty/undefined instead of [0,0] when not specified Disabled countries field when spatial_scale is 'global' - auto-disables with visual indication and info note Fixed numeric field types - added convertValueBySchema() function to convert string inputs to numbers/integers based on schema (fixes spatial_resolution, event_count, occurrence, event_rate, return_period, value, span, etc.) Removed geometry references from MDE code Added cleanEmptyValues() function - recursively removes empty arrays, empty strings, and null values from exported JSON/XML and GitHub publishes
1 parent 8f41fe4 commit 1449a6f

File tree

2 files changed

+64
-21
lines changed

2 files changed

+64
-21
lines changed

_static/RDL_MDE.html

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,11 +1951,10 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
19511951

19521952
const isDirectFormProperty = !name.includes('.') || name.split('.').length <= 2;
19531953
const isSpatialField = name === 'spatial';
1954-
const isGeometryField = name.endsWith('.geometry');
19551954
const isClassificationField = name.endsWith('.se_indicator') || name === 'se_indicator';
19561955

1957-
// Always show title for spatial field, geometry sub-field, classification fields, or for nested objects
1958-
if (!isDirectFormProperty || isSpatialField || isGeometryField || isClassificationField) {
1956+
// Always show title for spatial field, classification fields, or for nested objects
1957+
if (!isDirectFormProperty || isSpatialField || isClassificationField) {
19591958
const title = document.createElement('h6');
19601959
title.textContent = property.title || name;
19611960
title.className = 'mb-3';
@@ -4892,6 +4891,45 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
48924891
return packagedData;
48934892
}
48944893

4894+
function cleanEmptyValues(obj) {
4895+
// Recursively remove empty strings, empty arrays, and null/undefined values
4896+
if (Array.isArray(obj)) {
4897+
// Filter out empty values from arrays
4898+
const filtered = obj
4899+
.map(item => cleanEmptyValues(item))
4900+
.filter(item => {
4901+
if (item === null || item === undefined || item === '') return false;
4902+
if (Array.isArray(item) && item.length === 0) return false;
4903+
if (typeof item === 'object' && Object.keys(item).length === 0) return false;
4904+
return true;
4905+
});
4906+
return filtered.length > 0 ? filtered : undefined;
4907+
} else if (obj !== null && typeof obj === 'object') {
4908+
// Process objects
4909+
const cleaned = {};
4910+
for (const [key, value] of Object.entries(obj)) {
4911+
const cleanedValue = cleanEmptyValues(value);
4912+
4913+
// Only include the property if it has a meaningful value
4914+
if (cleanedValue !== undefined && cleanedValue !== null && cleanedValue !== '') {
4915+
// Skip empty arrays
4916+
if (Array.isArray(cleanedValue) && cleanedValue.length === 0) {
4917+
continue;
4918+
}
4919+
// Skip empty objects
4920+
if (typeof cleanedValue === 'object' && !Array.isArray(cleanedValue) && Object.keys(cleanedValue).length === 0) {
4921+
continue;
4922+
}
4923+
cleaned[key] = cleanedValue;
4924+
}
4925+
}
4926+
return Object.keys(cleaned).length > 0 ? cleaned : undefined;
4927+
} else if (obj === '' || obj === null || obj === undefined) {
4928+
return undefined;
4929+
}
4930+
return obj;
4931+
}
4932+
48954933
function exportJson() {
48964934
if (Object.keys(currentFormData).length === 0) {
48974935
alert('No data to export. Please fill out the form first.');
@@ -4901,10 +4939,13 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
49014939
const filteredData = getFilteredFormData();
49024940
const packagedData = packageDataset(filteredData);
49034941

4942+
// Clean empty values before export
4943+
const cleanedData = cleanEmptyValues(packagedData);
4944+
49044945
// Generate filename from dataset ID
4905-
const filename = packagedData.datasets?.[0]?.id ? `${packagedData.datasets[0].id}.json` : 'rdls_metadata.json';
4946+
const filename = cleanedData.datasets?.[0]?.id ? `${cleanedData.datasets[0].id}.json` : 'rdls_metadata.json';
49064947

4907-
const blob = new Blob([JSON.stringify(packagedData, null, 2)], {type: 'application/json'});
4948+
const blob = new Blob([JSON.stringify(cleanedData, null, 2)], {type: 'application/json'});
49084949
const url = URL.createObjectURL(blob);
49094950
const a = document.createElement('a');
49104951
a.href = url;
@@ -4920,7 +4961,9 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
49204961
}
49214962

49224963
const filteredData = getFilteredFormData();
4923-
const xml = jsonToXml(filteredData, 'rdls_dataset');
4964+
// Clean empty values before export
4965+
const cleanedData = cleanEmptyValues(filteredData);
4966+
const xml = jsonToXml(cleanedData, 'rdls_dataset');
49244967
const blob = new Blob([xml], {type: 'application/xml'});
49254968
const url = URL.createObjectURL(blob);
49264969
const a = document.createElement('a');
@@ -5064,8 +5107,11 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
50645107
const filteredData = getFilteredFormData();
50655108
const packagedData = packageDataset(filteredData);
50665109

5110+
// Clean empty values before publishing
5111+
const cleanedData = cleanEmptyValues(packagedData);
5112+
50675113
// Generate filename from dataset ID, fallback to title-based naming
5068-
const datasetId = packagedData.datasets?.[0]?.id;
5114+
const datasetId = cleanedData.datasets?.[0]?.id;
50695115
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').split('T')[0];
50705116
const filename = datasetId ? `${datasetId}.json` : `${sanitizeFilename(datasetTitle)}-${timestamp}.json`;
50715117
const branchName = datasetId ? `rdl-dataset-${datasetId}` : `rdl-dataset-${sanitizeFilename(datasetTitle)}-${timestamp}`;
@@ -5087,12 +5133,12 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
50875133

50885134
// Step 3: Create/update file
50895135
showGithubStatus('info', '📄 Uploading dataset file...');
5090-
const content = btoa(JSON.stringify(packagedData, null, 2));
5136+
const content = btoa(JSON.stringify(cleanedData, null, 2));
50915137
const commitMessage = `Add RDLS dataset: ${datasetTitle}
50925138
50935139
Dataset published via RDLS Metadata Editor
5094-
- Title: ${filteredData.title || 'Untitled'}
5095-
- Description: ${filteredData.description ? filteredData.description.substring(0, 100) + '...' : 'No description'}
5140+
- Title: ${cleanedData.datasets?.[0]?.title || 'Untitled'}
5141+
- Description: ${cleanedData.datasets?.[0]?.description ? cleanedData.datasets[0].description.substring(0, 100) + '...' : 'No description'}
50965142
- Timestamp: ${new Date().toISOString()}`;
50975143

50985144
await githubRequest(token, `repos/${repo}/contents/_datasets/json/${filename}`, {
@@ -5114,10 +5160,10 @@ <h5 class="modal-title" id="githubConfigModalLabel">GitHub Configuration</h5>
51145160
base: baseBranch,
51155161
body: `## New RDLS Dataset Submission
51165162
5117-
**Dataset Title:** ${filteredData.title || 'Untitled'}
5163+
**Dataset Title:** ${cleanedData.datasets?.[0]?.title || 'Untitled'}
51185164
51195165
**Description:**
5120-
${filteredData.description || 'No description provided'}
5166+
${cleanedData.datasets?.[0]?.description || 'No description provided'}
51215167
51225168
**File:** \`_datasets/json/${filename}\`
51235169

_static/rdls_schema_v0.3.json

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
"title": "Risk data type",
6666
"type": "array",
6767
"description": "The types of risk data included in the dataset, from the closed [risk_data_type codelist](https://docs.riskdatalibrary.org/en/latest/reference/codelists/#risk-data-type).",
68-
"$ref": "#/$defs/risk_data_type",
68+
"items": {
69+
"$ref": "#/$defs/risk_data_type"
70+
},
6971
"codelist": "risk_data_type.csv",
7072
"openCodelist": false,
7173
"minItems": 1,
@@ -133,7 +135,7 @@
133135
},
134136
"spatial": {
135137
"title": "Spatial coverage",
136-
"description": "The geographical area covered by the dataset. If specified using coordinates, the use of `.bbox` is recommended over `.geometry` or `.centroid`.",
138+
"description": "The geographical area covered by the dataset. If specified using coordinates, the use of `.bbox` is recommended over `.centroid`.",
137139
"$ref": "#/$defs/Location"
138140
},
139141
"license": {
@@ -1930,7 +1932,7 @@
19301932
"title": "Start",
19311933
"type": "string",
19321934
"description": "The start of the period. A date (YYYY-MM-DD) is recommended. However, year-months (YYYY-MM) and years (YYYY) are supported.",
1933-
"oneOf": [
1935+
"anyOf": [
19341936
{
19351937
"format": "date"
19361938
},
@@ -1954,7 +1956,7 @@
19541956
"title": "End date",
19551957
"type": "string",
19561958
"description": "The end of the period. A date (YYYY-MM-DD) is recommended. However, year-months (YYYY-MM) and years (YYYY) are supported.",
1957-
"oneOf": [
1959+
"anyOf": [
19581960
{
19591961
"format": "date"
19601962
},
@@ -2323,11 +2325,6 @@
23232325
[-73.935242, 40.730610],
23242326
[2.3522, 48.8566]
23252327
]
2326-
},
2327-
"geometry": {
2328-
"title": "Geometry",
2329-
"description": "A set of coordinates denoting the vertices of the geographical area. This field describes the extent of the geographical area. To avoid creating very large metadata, geometries should have fewer than 50 vertices.",
2330-
"$ref": "#/$defs/Geometry"
23312328
}
23322329
},
23332330
"minProperties": 1

0 commit comments

Comments
 (0)