Skip to content

Commit

Permalink
Merge pull request #4 from DSACMS/nat/more-components
Browse files Browse the repository at this point in the history
Components: Implemented select boxes and tags components to support multi-select & free response list fields
  • Loading branch information
natalialuzuriaga authored Dec 19, 2024
2 parents 6249dc5 + ac001b9 commit f7c7b4c
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 12 deletions.
39 changes: 30 additions & 9 deletions js/formDataToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,41 @@ async function retrieveFile(filePath) {

// Populates blank code.json object with values from form
function populateObject(data, blankObject) {
for (let key in data) {
console.log("current key", key);
console.log("check if value exists", data.hasOwnProperty(key));

for (const key in data) {
if (blankObject.hasOwnProperty(key)) {
if (typeof data[key] === "object" && data[key] !== null) {
// If object, recursively populate
// TODO: test out for permissions and description objects
populateObject(data[key], blankObject[key]);
} else {
// Add value
console.log(`${key}: ${data[key]}`);

if(typeof data[key] === "object" && isMultiSelect(data[key])) {
blankObject[key] = getSelectedOptions(data[key]);
}
else {
blankObject[key] = data[key];
}

}
}
}

function isMultiSelect(obj) {
for (const key in obj) {
if (typeof obj[key] !== 'boolean') {
return false;
}
}
return true; // Return true if all values are booleans
}

// Convert from dictionary to array
function getSelectedOptions(options) {
let selectedOptions = [];

for (let key in options) {
if(options[key]) {
selectedOptions.push(key);
}
}
return selectedOptions;
}

async function populateCodeJson(data) {
Expand Down
33 changes: 31 additions & 2 deletions js/generateFormComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ function transformArrayToOptions(arr) {

function determineType(field) {
if (field.type === "array") {
// TODO: Implement multi-select fields
// Multi-select
if (field.items.hasOwnProperty("enum")) {
return "selectboxes";
}
return "array-textfield";
// Free response list
return "tags";
} else if (field.hasOwnProperty("enum")) {
// Single select
return "radio";
} else if (field.type === "number") {
return "number";
Expand All @@ -51,6 +53,17 @@ function createComponent(fieldName, fieldObject) {
tooltip: fieldObject["description"],
description: fieldObject["description"],
};
case "tags":
return {
label: fieldName,
tableView: false,
storeas: "array",
validateWhenHidden: false,
key: fieldName,
type: "tags",
input: true,
description: fieldObject["description"]
};
case "number":
return {
label: fieldName,
Expand Down Expand Up @@ -80,6 +93,22 @@ function createComponent(fieldName, fieldObject) {
key: fieldName,
type: "radio",
input: true,
description: fieldObject["description"]
};
case "selectboxes":
var options = transformArrayToOptions(fieldObject.items.enum);
console.log("checking options here:", options);
return {
label: fieldName,
optionsLabelPosition: "right",
tableView: false,
values: options,
validateWhenHidden: false,
key: fieldName,
type: "selectboxes",
input: true,
inputType: "checkbox",
description: fieldObject["description"]
};
default:
break;
Expand Down
42 changes: 42 additions & 0 deletions schemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,48 @@
"laborHours": {
"type": "number",
"description": "Labor hours invested in the project"
},
"platforms": {
"type": "array",
"description": "Platforms supported by the project",
"items": {
"type": "string",
"enum": ["web", "windows", "mac", "linux", "ios", "android", "other"]
}
},
"categories": {
"type": "array",
"description": "Categories the project belongs to. Select from: https://yml.publiccode.tools/categories-list.html",
"items": {
"type": "string"
}
},
"softwareType": {
"type": "string",
"description": "Type of software",
"enum": [
"standalone/mobile",
"standalone/iot",
"standalone/desktop",
"standalone/web",
"standalone/backend",
"standalone/other",
"addon",
"library",
"configurationFiles"
]
},
"languages": {
"type": "array",
"description": "Programming languages that make up the codebase",
"items": {
"type": "string"
}
},
"maintenance": {
"type": "string",
"description": "Maintenance status",
"enum": ["internal", "contract", "community", "none"]
}
}
}
7 changes: 6 additions & 1 deletion schemas/template-code.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@
"status": "",
"organization": "",
"vcs": "",
"laborHours": 0
"laborHours": 0,
"platforms": [""],
"categories": [""],
"softwareType": [""],
"languages": [""],
"maintenance": ""
}

0 comments on commit f7c7b4c

Please sign in to comment.