Skip to content

Commit 6249dc5

Browse files
Merge pull request #3 from DSACMS/nat/more-components
Components: Implemented single select and text input components
2 parents 3ef95dc + d1ce529 commit 6249dc5

3 files changed

Lines changed: 89 additions & 6 deletions

File tree

js/generateFormComponents.js

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,34 @@ async function retrieveFile(filePath) {
1515
}
1616
}
1717

18-
// Creates Form.io component based on json fields
19-
// Supports text field for now
20-
// TODO: Create components for number, select, and multi-select
18+
function transformArrayToOptions(arr) {
19+
return arr.map((item) => ({
20+
label: item.toString(),
21+
value: item.toString(),
22+
}));
23+
}
24+
25+
function determineType(field) {
26+
if (field.type === "array") {
27+
// TODO: Implement multi-select fields
28+
if (field.items.hasOwnProperty("enum")) {
29+
return "selectboxes";
30+
}
31+
return "array-textfield";
32+
} else if (field.hasOwnProperty("enum")) {
33+
return "radio";
34+
} else if (field.type === "number") {
35+
return "number";
36+
} else if (field.type === "string") {
37+
return "textfield";
38+
}
39+
}
40+
41+
// Creates Form.io component based on json field type
2142
function createComponent(fieldName, fieldObject) {
22-
switch (fieldObject["type"]) {
23-
case "string":
43+
var componentType = determineType(fieldObject);
44+
switch (componentType) {
45+
case "textfield":
2446
return {
2547
type: "textfield",
2648
key: fieldName,
@@ -29,6 +51,36 @@ function createComponent(fieldName, fieldObject) {
2951
tooltip: fieldObject["description"],
3052
description: fieldObject["description"],
3153
};
54+
case "number":
55+
return {
56+
label: fieldName,
57+
applyMaskOn: "change",
58+
mask: false,
59+
tableView: false,
60+
delimiter: false,
61+
requireDecimal: false,
62+
inputFormat: "plain",
63+
truncateMultipleSpaces: false,
64+
validateWhenHidden: false,
65+
key: fieldName,
66+
type: "number",
67+
input: true,
68+
description: fieldObject["description"],
69+
};
70+
case "radio":
71+
var options = transformArrayToOptions(fieldObject.enum);
72+
console.log("checking options here:", options);
73+
return {
74+
label: fieldName,
75+
optionsLabelPosition: "right",
76+
inline: false,
77+
tableView: false,
78+
values: options,
79+
validateWhenHidden: false,
80+
key: fieldName,
81+
type: "radio",
82+
input: true,
83+
};
3284
default:
3385
break;
3486
}

schemas/schema.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,33 @@
1111
"softwareDescription": {
1212
"type": "string",
1313
"description": "project description here"
14+
},
15+
"status": {
16+
"type": "string",
17+
"enum": [
18+
"Ideation",
19+
"Development",
20+
"Alpha",
21+
"Beta",
22+
"Release Candidate",
23+
"Production",
24+
"Archival"
25+
],
26+
"description": "Development status of the project"
27+
},
28+
"organization": {
29+
"type": "string",
30+
"description": "Organization responsible for the project",
31+
"enum": ["Centers for Medicare & Medicaid Services"]
32+
},
33+
"vcs": {
34+
"type": "string",
35+
"description": "Version control system used",
36+
"enum": ["git", "hg", "svn", "rcs", "bzr"]
37+
},
38+
"laborHours": {
39+
"type": "number",
40+
"description": "Labor hours invested in the project"
1441
}
1542
}
1643
}

schemas/template-code.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
22
"name": "",
3-
"softwareDescription": ""
3+
"softwareDescription": "",
4+
"status": "",
5+
"organization": "",
6+
"vcs": "",
7+
"laborHours": 0
48
}

0 commit comments

Comments
 (0)