Skip to content

Commit 1d9ed91

Browse files
Added new schemas with redirects
Signed-off-by: Natalia Luzuriaga <natalia.luzuriaga@cms.hhs.gov>
1 parent 2480be4 commit 1d9ed91

4 files changed

Lines changed: 336 additions & 15 deletions

File tree

404.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta http-equiv="refresh" content="0; url=/?page=">
6+
<script>
7+
// Extract the path from URL (e.g., /cms) and redirect
8+
(function () {
9+
const repoName = "codejson-generator"; // change if needed
10+
let path = window.location.pathname.replace(`/${repoName}`, "").replace(/^\/+/, "").replace(/\/$/, "");
11+
const newUrl = path
12+
? `/${repoName ? repoName + "/" : ""}?page=${encodeURIComponent(path)}`
13+
: `/${repoName ? repoName + "/" : ""}`;
14+
window.location.replace(newUrl);
15+
})();
16+
</script>
17+
</head>
18+
19+
<body>
20+
<p>Redirecting...</p>
21+
</body>
22+
23+
</html>

js/generateFormComponents.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function transformArrayToOptions(arr) {
2323
}
2424

2525
// Function that handles validation object needed for each form component
26-
function determineValidation(fieldName, fieldObject, requiredArray){
26+
function determineValidation(fieldName, fieldObject, requiredArray) {
2727
return {
2828
"required": requiredArray.includes(fieldName)
2929
}
@@ -207,7 +207,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
207207
description: fieldObject["description"],
208208
validate
209209
};
210-
case "container":
210+
case "container":
211211
return {
212212
label: fieldName,
213213
hideLabel: false,
@@ -238,7 +238,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
238238
input: true,
239239
components: [],
240240
validate
241-
};
241+
};
242242
default:
243243
break;
244244
}
@@ -256,44 +256,47 @@ function createAutoGenerationBox() {
256256
}
257257

258258
// Iterates through each json field and creates component array for Form.io
259-
function createAllComponents(schema, prefix = ""){
259+
function createAllComponents(schema, prefix = "") {
260260
let components = [];
261261

262262
if (schema.type === "object" && schema.properties) {
263263

264264
const items = schema.properties.hasOwnProperty("items") ? schema.properties.items : schema.properties;
265-
265+
266266
let requiredArray = [];
267267
if (schema.hasOwnProperty("required")) {
268268
requiredArray = schema.required;
269269
}
270270

271-
for (const [key, value] of Object.entries(items)) {
272-
271+
for (const [key, value] of Object.entries(items)) {
272+
273273
console.log("key at play:", key);
274274
const fullKey = prefix ? `${prefix}.${key}` : key;
275275

276276
let fieldComponent = createComponent(key, value, requiredArray);
277277

278278
if (fieldComponent.type === "container") {
279279
fieldComponent.components = createAllComponents(value, fullKey);
280-
}
280+
}
281281
else if (fieldComponent.type === "datagrid") {
282282
fieldComponent.components = createAllComponents(value.items, fullKey);
283283
}
284284

285285
components.push(fieldComponent);
286-
}
287-
}
286+
}
287+
}
288288

289-
return components;
289+
return components;
290290
}
291291

292292
// Creates complete form based on input json schema
293293
async function createFormComponents() {
294294
let components = [];
295295

296-
const filePath = "schemas/schema.json";
296+
// Fetching schema based on search params
297+
const params = new URLSearchParams(window.location.search);
298+
const page = params.get("page") || "gov";
299+
const filePath = `schemas/${page}/schema.json`;
297300
const jsonData = await retrieveFile(filePath);
298301
console.log("JSON Data:", jsonData);
299302

@@ -326,7 +329,7 @@ async function createFormComponents() {
326329
tableView: false,
327330
});
328331

329-
332+
330333

331334
console.log(components);
332335

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"repositoryURL": {
115115
"type": "string",
116116
"format": "uri",
117-
"description": "The URL of the public release repository for open source repositories. This field is not required for repositories that are only available as government-wide reuse or are closed (pursuant to one of the exemptions)."
117+
"description": "The URL of the public release repository for open source repositories. This field is not required for repositories that are only available as government-wide reuse or are closed (pursuant to one of the exemptions). It can be listed as 'private' for repositories that are closed."
118118
},
119119
"projectURL": {
120120
"type": "string",
@@ -403,4 +403,4 @@
403403
"maturityModelTier"
404404
],
405405
"additionalProperties": false
406-
}
406+
}

0 commit comments

Comments
 (0)