Skip to content

Commit

Permalink
Merge pull request #12 from DSACMS/nat/objs
Browse files Browse the repository at this point in the history
Components: Added Data Grid component & Updated CDNs
  • Loading branch information
natalialuzuriaga authored Jan 8, 2025
2 parents 69ddbf4 + 3a8da32 commit df09c7d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 28 deletions.
22 changes: 9 additions & 13 deletions form.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@
<!-- <script src="https://cdn.form.io/js/formio.embed.js"></script> -->

<!-- Uses bootstrap for now -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap/dist/css/bootstrap.min.css"
/>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>

<!-- Working Form.io CDN -->
<script src="https://unpkg.com/[email protected]/dist/formio.full.min.js"></script>
</head>
<body>
<div id="form-header"></div>
<div id="formio"></div>
<script src="https://unpkg.com/[email protected]/dist/formio.full.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/formio.full.min.css" rel="stylesheet">

<!-- Render the form -->
<script src="js/generateFormComponents.js"></script>
<script src="js/formDataToJson.js"></script>
<script type="text/javascript">
Expand All @@ -55,5 +47,9 @@
console.error("Error creating components:", error);
});
</script>
</head>
<body>
<div id="form-header"></div>
<div id="formio"></div>
</body>
</html>
47 changes: 39 additions & 8 deletions js/generateFormComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ function determineType(field) {
if (field.type === "object") {
return "container";
} else if (field.type === "array") {
// Array of objects
if (field.items.type === "object") {
return "datagrid"
}
// Multi-select
if (field.items.hasOwnProperty("enum")) {
return "selectboxes";
Expand All @@ -37,9 +41,9 @@ function determineType(field) {
return "radio";
} else if (field.type === "number") {
return "number";
} else if (field.type === "boolean"){
} else if (field.type === "boolean") {
return "select-boolean";
} else if (field.type === "string") {
} else if (field.type === "string" || field.type.includes("string")) {
if (field.format == "date-time") {
return "datetime";
}
Expand Down Expand Up @@ -100,7 +104,8 @@ function createComponent(fieldName, fieldObject) {
key: fieldName,
type: "radio",
input: true,
description: fieldObject["description"]
description: fieldObject["description"],
tooltip: fieldObject["description"]
};
case "selectboxes":
var options = transformArrayToOptions(fieldObject.items.enum);
Expand Down Expand Up @@ -184,43 +189,69 @@ function createComponent(fieldName, fieldObject) {
input: true,
components: []
};
case "datagrid":
return {
label: fieldName,
reorder: false,
addAnotherPosition: "bottom",
layoutFixed: false,
enableRowGroups: false,
initEmpty: false,
tableView: false,
defaultValue: [
{}
],
validateWhenHidden: false,
key: fieldName,
type: "datagrid",
input: true,
components: []
};
default:
break;
}
}

// Adds heading containing schema information
function createFormHeading(title, description) {
const container = document.getElementById('form-header');
container.innerHTML = `<h1>${title}</h1>\n<h2>${description}</h2>`;
}

// Iterates through each json field and creates component array for Form.io
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)) {

let items = schema.properties.hasOwnProperty("items") ? schema.properties.items : schema.properties

for (const [key, value] of Object.entries(items)) {

console.log("key at play:", key);
const fullKey = prefix ? `${prefix}.${key}` : key;

var fieldComponent = createComponent(key, value);

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

components.push(fieldComponent);
}
}

return components;
}

// Iterates through each json field and creates component array for Form.io
// Creates complete form based on input json schema
async function createFormComponents() {
let components = [];

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

Expand Down
14 changes: 7 additions & 7 deletions schemas/schema-0.0.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
"items": {
"type": "object",
"properties": {
"URL": {
"type": "string",
"format": "uri",
"description": "The URL of the release license"
},
"name": {
"type": "string",
"enum": [
Expand All @@ -66,11 +61,16 @@
"None"
],
"description": "An abbreviation for the name of the license"
},
"URL": {
"type": "string",
"format": "uri",
"description": "The URL of the release license"
}
},
"required": [
"url",
"name"
"name",
"URL"
]
}
},
Expand Down
1 change: 1 addition & 0 deletions schemas/template-code.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"description": "",
"longDescription": "",
"status": "",
"permissions": "",
"organization": "",
"repositoryURL": "",
"vcs": "",
Expand Down

0 comments on commit df09c7d

Please sign in to comment.