Skip to content

Commit 69ddbf4

Browse files
Merge pull request #10 from DSACMS/nat/objs
Components: Added container component for object fields & updated code.json schema
2 parents c0c7d3b + b8b485a commit 69ddbf4

File tree

3 files changed

+109
-60
lines changed

3 files changed

+109
-60
lines changed

js/generateFormComponents.js

+81-55
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ function transformArrayToOptions(arr) {
2323
}
2424

2525
function determineType(field) {
26-
if (field.type === "array") {
26+
if (field.type === "object") {
27+
return "container";
28+
} else if (field.type === "array") {
2729
// Multi-select
2830
if (field.items.hasOwnProperty("enum")) {
2931
return "selectboxes";
@@ -56,7 +58,7 @@ function createComponent(fieldName, fieldObject) {
5658
label: fieldName,
5759
input: true,
5860
tooltip: fieldObject["description"],
59-
description: fieldObject["description"],
61+
description: fieldObject["description"]
6062
};
6163
case "tags":
6264
return {
@@ -83,7 +85,7 @@ function createComponent(fieldName, fieldObject) {
8385
key: fieldName,
8486
type: "number",
8587
input: true,
86-
description: fieldObject["description"],
88+
description: fieldObject["description"]
8789
};
8890
case "radio":
8991
var options = transformArrayToOptions(fieldObject.enum);
@@ -117,61 +119,71 @@ function createComponent(fieldName, fieldObject) {
117119
};
118120
case "datetime":
119121
return {
120-
"label": fieldName,
121-
"tableView": false,
122-
"datePicker": {
123-
"disableWeekends": false,
124-
"disableWeekdays": false
122+
label: fieldName,
123+
tableView: false,
124+
datePicker: {
125+
disableWeekends: false,
126+
disableWeekdays: false
125127
},
126-
"enableMinDateInput": false,
127-
"enableMaxDateInput": false,
128-
"validateWhenHidden": false,
129-
"key": fieldName,
130-
"type": "datetime",
131-
"input": true,
132-
"widget": {
133-
"type": "calendar",
134-
"displayInTimezone": "viewer",
135-
"locale": "en",
136-
"useLocaleSettings": false,
137-
"allowInput": true,
138-
"mode": "single",
139-
"enableTime": true,
140-
"noCalendar": false,
141-
"format": "yyyy-MM-dd hh:mm a",
142-
"hourIncrement": 1,
143-
"minuteIncrement": 1,
144-
"time_24hr": false,
145-
"minDate": null,
146-
"disableWeekends": false,
147-
"disableWeekdays": false,
148-
"maxDate": null
128+
enableMinDateInput: false,
129+
enableMaxDateInput: false,
130+
validateWhenHidden: false,
131+
key: fieldName,
132+
type: "datetime",
133+
input: true,
134+
widget: {
135+
type: "calendar",
136+
displayInTimezone: "viewer",
137+
locale: "en",
138+
useLocaleSettings: false,
139+
allowInput: true,
140+
mode: "single",
141+
enableTime: true,
142+
noCalendar: false,
143+
format: "yyyy-MM-dd hh:mm a",
144+
hourIncrement: 1,
145+
minuteIncrement: 1,
146+
time_24hr: false,
147+
minDate: null,
148+
disableWeekends: false,
149+
disableWeekdays: false,
150+
maxDate: null
149151
},
150152
description: fieldObject["description"]
151-
}
153+
};
152154
case "select-boolean":
153155
return {
154-
"label": fieldName,
155-
"widget": "html5",
156-
"tableView": true,
157-
"data": {
158-
"values": [
156+
label: fieldName,
157+
widget: "html5",
158+
tableView: true,
159+
data: {
160+
values: [
159161
{
160-
"label": "True",
161-
"value": "true"
162+
label: "True",
163+
value: "true"
162164
},
163165
{
164-
"label": "False",
165-
"value": "false"
166+
label: "False",
167+
value: "false"
166168
}
167169
]
168170
},
169-
"validateWhenHidden": false,
170-
"key": fieldName,
171-
"type": "select",
172-
"input": true,
171+
validateWhenHidden: false,
172+
key: fieldName,
173+
type: "select",
174+
input: true,
173175
description: fieldObject["description"]
174-
}
176+
};
177+
case "container":
178+
return {
179+
label: fieldName,
180+
tableView: false,
181+
validateWhenHidden: false,
182+
key: fieldName,
183+
type: "container",
184+
input: true,
185+
components: []
186+
};
175187
default:
176188
break;
177189
}
@@ -182,25 +194,39 @@ function createFormHeading(title, description) {
182194
container.innerHTML = `<h1>${title}</h1>\n<h2>${description}</h2>`;
183195
}
184196

197+
function createAllComponents(schema, prefix = ""){
198+
let components = [];
199+
200+
console.log("checking schema", schema);
201+
202+
if (schema.type === "object" && schema.properties) {
203+
for (const [key, value] of Object.entries(schema.properties)) {
204+
205+
const fullKey = prefix ? `${prefix}.${key}` : key;
206+
207+
var fieldComponent = createComponent(key, value);
208+
209+
if (fieldComponent.type === "container") {
210+
fieldComponent.components = createAllComponents(value, fullKey);
211+
}
212+
components.push(fieldComponent);
213+
}
214+
}
215+
216+
return components;
217+
}
218+
185219
// Iterates through each json field and creates component array for Form.io
186220
async function createFormComponents() {
187221
let components = [];
188-
let formFields = {};
189222

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

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

196-
formFields = jsonData["properties"];
197-
console.log("form Fields:", formFields);
198-
199-
for (const key in formFields) {
200-
console.log(`${key}:`, formFields[key]);
201-
var fieldComponent = createComponent(key, formFields[key]);
202-
components.push(fieldComponent);
203-
}
229+
components = createAllComponents(jsonData);
204230

205231
// Add submit button to form
206232
components.push({

schemas/schema-0.0.0.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"items": {
4343
"type": "object",
4444
"properties": {
45-
"url": {
45+
"URL": {
4646
"type": "string",
4747
"format": "uri",
4848
"description": "The URL of the release license"
@@ -110,6 +110,11 @@
110110
"Centers for Medicare & Medicaid Services"
111111
]
112112
},
113+
"repositoryURL": {
114+
"type": "string",
115+
"format": "uri",
116+
"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+
},
113118
"vcs": {
114119
"type": "string",
115120
"description": "Version control system used",
@@ -182,6 +187,7 @@
182187
},
183188
"date": {
184189
"type": "object",
190+
"description": "A date object describing the release",
185191
"properties": {
186192
"created": {
187193
"type": "string",
@@ -209,6 +215,7 @@
209215
},
210216
"contact": {
211217
"type": "object",
218+
"description": "Point of contact for the release",
212219
"properties": {
213220
"email": {
214221
"type": "string",
@@ -286,7 +293,7 @@
286293
"description": "Location where source code is hosted",
287294
"enum": [
288295
"github.com/CMSgov",
289-
"github.com/CMSgov",
296+
"github.com/CMS-Enterprise",
290297
"github.cms.gov",
291298
"CCSQ GitHub"
292299
]
@@ -310,6 +317,7 @@
310317
"status",
311318
"permissions",
312319
"organization",
320+
"repositoryURL",
313321
"vcs",
314322
"laborHours",
315323
"platforms",

schemas/template-code.json

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
11
{
22
"name": "",
3-
"softwareDescription": "",
3+
"description": "",
4+
"longDescription": "",
45
"status": "",
56
"organization": "",
7+
"repositoryURL": "",
68
"vcs": "",
79
"laborHours": 0,
810
"platforms": [""],
911
"categories": [""],
1012
"softwareType": [""],
1113
"languages": [""],
1214
"maintenance": "",
13-
"lastModified": "",
14-
"localisation": ""
15+
"date": [""],
16+
"tags": [""],
17+
"contact": {
18+
"email": "",
19+
"name": ""
20+
},
21+
"localisation": "",
22+
"repositoryType": "",
23+
"userInput": "",
24+
"fismaLevel": "",
25+
"group": "",
26+
"subsetInHealthcare": "",
27+
"userType": "",
28+
"repositoryHost": "",
29+
"maturityModelTier": ""
1530
}

0 commit comments

Comments
 (0)