Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 81 additions & 55 deletions js/generateFormComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ function transformArrayToOptions(arr) {
}

function determineType(field) {
if (field.type === "array") {
if (field.type === "object") {
return "container";
} else if (field.type === "array") {
// Multi-select
if (field.items.hasOwnProperty("enum")) {
return "selectboxes";
Expand Down Expand Up @@ -56,7 +58,7 @@ function createComponent(fieldName, fieldObject) {
label: fieldName,
input: true,
tooltip: fieldObject["description"],
description: fieldObject["description"],
description: fieldObject["description"]
};
case "tags":
return {
Expand All @@ -83,7 +85,7 @@ function createComponent(fieldName, fieldObject) {
key: fieldName,
type: "number",
input: true,
description: fieldObject["description"],
description: fieldObject["description"]
};
case "radio":
var options = transformArrayToOptions(fieldObject.enum);
Expand Down Expand Up @@ -117,61 +119,71 @@ function createComponent(fieldName, fieldObject) {
};
case "datetime":
return {
"label": fieldName,
"tableView": false,
"datePicker": {
"disableWeekends": false,
"disableWeekdays": false
label: fieldName,
tableView: false,
datePicker: {
disableWeekends: false,
disableWeekdays: false
},
"enableMinDateInput": false,
"enableMaxDateInput": false,
"validateWhenHidden": false,
"key": fieldName,
"type": "datetime",
"input": true,
"widget": {
"type": "calendar",
"displayInTimezone": "viewer",
"locale": "en",
"useLocaleSettings": false,
"allowInput": true,
"mode": "single",
"enableTime": true,
"noCalendar": false,
"format": "yyyy-MM-dd hh:mm a",
"hourIncrement": 1,
"minuteIncrement": 1,
"time_24hr": false,
"minDate": null,
"disableWeekends": false,
"disableWeekdays": false,
"maxDate": null
enableMinDateInput: false,
enableMaxDateInput: false,
validateWhenHidden: false,
key: fieldName,
type: "datetime",
input: true,
widget: {
type: "calendar",
displayInTimezone: "viewer",
locale: "en",
useLocaleSettings: false,
allowInput: true,
mode: "single",
enableTime: true,
noCalendar: false,
format: "yyyy-MM-dd hh:mm a",
hourIncrement: 1,
minuteIncrement: 1,
time_24hr: false,
minDate: null,
disableWeekends: false,
disableWeekdays: false,
maxDate: null
},
description: fieldObject["description"]
}
};
case "select-boolean":
return {
"label": fieldName,
"widget": "html5",
"tableView": true,
"data": {
"values": [
label: fieldName,
widget: "html5",
tableView: true,
data: {
values: [
{
"label": "True",
"value": "true"
label: "True",
value: "true"
},
{
"label": "False",
"value": "false"
label: "False",
value: "false"
}
]
},
"validateWhenHidden": false,
"key": fieldName,
"type": "select",
"input": true,
validateWhenHidden: false,
key: fieldName,
type: "select",
input: true,
description: fieldObject["description"]
}
};
case "container":
return {
label: fieldName,
tableView: false,
validateWhenHidden: false,
key: fieldName,
type: "container",
input: true,
components: []
};
default:
break;
}
Expand All @@ -182,25 +194,39 @@ function createFormHeading(title, description) {
container.innerHTML = `<h1>${title}</h1>\n<h2>${description}</h2>`;
}

function createAllComponents(schema, prefix = ""){
let components = [];

console.log("checking schema", schema);

if (schema.type === "object" && schema.properties) {
for (const [key, value] of Object.entries(schema.properties)) {

const fullKey = prefix ? `${prefix}.${key}` : key;

var fieldComponent = createComponent(key, value);

if (fieldComponent.type === "container") {
fieldComponent.components = createAllComponents(value, fullKey);
}
components.push(fieldComponent);
}
}

return components;
}

// Iterates through each json field and creates component array for Form.io
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

async function createFormComponents() {
let components = [];
let formFields = {};

const filePath = "schemas/schema.json";
let jsonData = await retrieveFile(filePath);
console.log("JSON Data:", jsonData);

createFormHeading(jsonData["title"], jsonData["description"]);

formFields = jsonData["properties"];
console.log("form Fields:", formFields);

for (const key in formFields) {
console.log(`${key}:`, formFields[key]);
var fieldComponent = createComponent(key, formFields[key]);
components.push(fieldComponent);
}
components = createAllComponents(jsonData);

// Add submit button to form
components.push({
Expand Down
12 changes: 10 additions & 2 deletions schemas/schema-0.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"items": {
"type": "object",
"properties": {
"url": {
"URL": {
"type": "string",
"format": "uri",
"description": "The URL of the release license"
Expand Down Expand Up @@ -110,6 +110,11 @@
"Centers for Medicare & Medicaid Services"
]
},
"repositoryURL": {
"type": "string",
"format": "uri",
"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)."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also 🔥

},
"vcs": {
"type": "string",
"description": "Version control system used",
Expand Down Expand Up @@ -182,6 +187,7 @@
},
"date": {
"type": "object",
"description": "A date object describing the release",
"properties": {
"created": {
"type": "string",
Expand Down Expand Up @@ -209,6 +215,7 @@
},
"contact": {
"type": "object",
"description": "Point of contact for the release",
"properties": {
"email": {
"type": "string",
Expand Down Expand Up @@ -286,7 +293,7 @@
"description": "Location where source code is hosted",
"enum": [
"github.com/CMSgov",
"github.com/CMSgov",
"github.com/CMS-Enterprise",
Copy link
Copy Markdown
Contributor Author

@natalialuzuriaga natalialuzuriaga Jan 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cookiecutter options are: "repository_host": ["Github.com", "GitHub ENT", "GitHub Cloud", "GitLab.com", "GitLab ENT", "GitLab ENT CCSQ"]

Need to realign, do we want links or name of github?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think links are most useful, then people can check themselves, but I'm willing to change my mind.

"github.cms.gov",
"CCSQ GitHub"
]
Expand All @@ -310,6 +317,7 @@
"status",
"permissions",
"organization",
"repositoryURL",
"vcs",
"laborHours",
"platforms",
Expand Down
21 changes: 18 additions & 3 deletions schemas/template-code.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
{
"name": "",
"softwareDescription": "",
"description": "",
"longDescription": "",
"status": "",
"organization": "",
"repositoryURL": "",
"vcs": "",
"laborHours": 0,
"platforms": [""],
"categories": [""],
"softwareType": [""],
"languages": [""],
"maintenance": "",
"lastModified": "",
"localisation": ""
"date": [""],
"tags": [""],
"contact": {
"email": "",
"name": ""
},
"localisation": "",
"repositoryType": "",
"userInput": "",
"fismaLevel": "",
"group": "",
"subsetInHealthcare": "",
"userType": "",
"repositoryHost": "",
"maturityModelTier": ""
}