Skip to content

Commit f7c7b4c

Browse files
Merge pull request #4 from DSACMS/nat/more-components
Components: Implemented select boxes and tags components to support multi-select & free response list fields
2 parents 6249dc5 + ac001b9 commit f7c7b4c

File tree

4 files changed

+109
-12
lines changed

4 files changed

+109
-12
lines changed

js/formDataToJson.js

+30-9
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,41 @@ async function retrieveFile(filePath) {
1616

1717
// Populates blank code.json object with values from form
1818
function populateObject(data, blankObject) {
19-
for (let key in data) {
20-
console.log("current key", key);
21-
console.log("check if value exists", data.hasOwnProperty(key));
19+
20+
for (const key in data) {
2221
if (blankObject.hasOwnProperty(key)) {
23-
if (typeof data[key] === "object" && data[key] !== null) {
24-
// If object, recursively populate
25-
// TODO: test out for permissions and description objects
26-
populateObject(data[key], blankObject[key]);
27-
} else {
28-
// Add value
22+
console.log(`${key}: ${data[key]}`);
23+
24+
if(typeof data[key] === "object" && isMultiSelect(data[key])) {
25+
blankObject[key] = getSelectedOptions(data[key]);
26+
}
27+
else {
2928
blankObject[key] = data[key];
3029
}
30+
31+
}
32+
}
33+
}
34+
35+
function isMultiSelect(obj) {
36+
for (const key in obj) {
37+
if (typeof obj[key] !== 'boolean') {
38+
return false;
39+
}
40+
}
41+
return true; // Return true if all values are booleans
42+
}
43+
44+
// Convert from dictionary to array
45+
function getSelectedOptions(options) {
46+
let selectedOptions = [];
47+
48+
for (let key in options) {
49+
if(options[key]) {
50+
selectedOptions.push(key);
3151
}
3252
}
53+
return selectedOptions;
3354
}
3455

3556
async function populateCodeJson(data) {

js/generateFormComponents.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ function transformArrayToOptions(arr) {
2424

2525
function determineType(field) {
2626
if (field.type === "array") {
27-
// TODO: Implement multi-select fields
27+
// Multi-select
2828
if (field.items.hasOwnProperty("enum")) {
2929
return "selectboxes";
3030
}
31-
return "array-textfield";
31+
// Free response list
32+
return "tags";
3233
} else if (field.hasOwnProperty("enum")) {
34+
// Single select
3335
return "radio";
3436
} else if (field.type === "number") {
3537
return "number";
@@ -51,6 +53,17 @@ function createComponent(fieldName, fieldObject) {
5153
tooltip: fieldObject["description"],
5254
description: fieldObject["description"],
5355
};
56+
case "tags":
57+
return {
58+
label: fieldName,
59+
tableView: false,
60+
storeas: "array",
61+
validateWhenHidden: false,
62+
key: fieldName,
63+
type: "tags",
64+
input: true,
65+
description: fieldObject["description"]
66+
};
5467
case "number":
5568
return {
5669
label: fieldName,
@@ -80,6 +93,22 @@ function createComponent(fieldName, fieldObject) {
8093
key: fieldName,
8194
type: "radio",
8295
input: true,
96+
description: fieldObject["description"]
97+
};
98+
case "selectboxes":
99+
var options = transformArrayToOptions(fieldObject.items.enum);
100+
console.log("checking options here:", options);
101+
return {
102+
label: fieldName,
103+
optionsLabelPosition: "right",
104+
tableView: false,
105+
values: options,
106+
validateWhenHidden: false,
107+
key: fieldName,
108+
type: "selectboxes",
109+
input: true,
110+
inputType: "checkbox",
111+
description: fieldObject["description"]
83112
};
84113
default:
85114
break;

schemas/schema.json

+42
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,48 @@
3838
"laborHours": {
3939
"type": "number",
4040
"description": "Labor hours invested in the project"
41+
},
42+
"platforms": {
43+
"type": "array",
44+
"description": "Platforms supported by the project",
45+
"items": {
46+
"type": "string",
47+
"enum": ["web", "windows", "mac", "linux", "ios", "android", "other"]
48+
}
49+
},
50+
"categories": {
51+
"type": "array",
52+
"description": "Categories the project belongs to. Select from: https://yml.publiccode.tools/categories-list.html",
53+
"items": {
54+
"type": "string"
55+
}
56+
},
57+
"softwareType": {
58+
"type": "string",
59+
"description": "Type of software",
60+
"enum": [
61+
"standalone/mobile",
62+
"standalone/iot",
63+
"standalone/desktop",
64+
"standalone/web",
65+
"standalone/backend",
66+
"standalone/other",
67+
"addon",
68+
"library",
69+
"configurationFiles"
70+
]
71+
},
72+
"languages": {
73+
"type": "array",
74+
"description": "Programming languages that make up the codebase",
75+
"items": {
76+
"type": "string"
77+
}
78+
},
79+
"maintenance": {
80+
"type": "string",
81+
"description": "Maintenance status",
82+
"enum": ["internal", "contract", "community", "none"]
4183
}
4284
}
4385
}

schemas/template-code.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,10 @@
44
"status": "",
55
"organization": "",
66
"vcs": "",
7-
"laborHours": 0
7+
"laborHours": 0,
8+
"platforms": [""],
9+
"categories": [""],
10+
"softwareType": [""],
11+
"languages": [""],
12+
"maintenance": ""
813
}

0 commit comments

Comments
 (0)