Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<html lang="en-US">
<meta charset="UTF-8">
<meta name="description" content="Form to generate a code.json file containing repository metadata">

<head>
<title>code.json metadata</title>
Expand Down Expand Up @@ -279,11 +280,13 @@ <h3 class="usa-heading margin-top-neg-05 margin-bottom-1" id="quiz-subheading">
</div>

<!-- Form header -->
<div id="form-subheader">
<div class="form-subheader">
<div class="step-header">
<div class="step-number">3</div>
<h2>Complete the entire form to generate the code.json file</h2>
</div>
<p class="usa-heading margin-top-neg-05 margin-bottom-2"><em>A red asterisk (<span style="color:red">*</span>)
indicates a required field</em></p>
</div>

<div id="formio"></div>
Expand Down
7 changes: 3 additions & 4 deletions js/autoGenerateFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,9 @@ async function preFillFields(repoData, languages) {
feedbackComp.setValue(issuesUrl)
}

// Update upstream

if (form.getComponent('upstream') && repoData.html_url) {
const upstreamComp = form.getComponent('upstream');
// Update SBOM
if (form.getComponent('SBOM') && repoData.html_url) {
const upstreamComp = form.getComponent('SBOM');
const urlParts = repoData.html_url.split('/')

if (urlParts.length >= 2) {
Expand Down
11 changes: 9 additions & 2 deletions js/formDataToJson.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ function getSelectedOptions(options) {
return selectedOptions;
}

function isEmptyObject(obj) {
return Object.values(obj).every(value =>
value === "" ||
value === null ||
value === undefined
);
}

// Populates fields with form data
function populateObject(data, fields) {
let reorderedObject = {}
Expand All @@ -45,7 +53,7 @@ function populateObject(data, fields) {
let value = data[field];

// Does not assign optional properties with blank values
if (value == null || value === "") {
if (value == null || value === "" || (Array.isArray(value) && typeof value[0] === 'object' && isEmptyObject(value[0]))) {
continue;
}

Expand Down Expand Up @@ -290,7 +298,6 @@ async function createProjectPR(event) {
console.error("No API key found!");
alert("No API Key in submitted data! Please provide an API key");
}
//console.log(codeJSONObj)
}

// Triggers local file download
Expand Down
49 changes: 27 additions & 22 deletions js/generateFormComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,23 @@ function determineType(field) {
}

// Creates Form.io component based on json field type
function createComponent(fieldName, fieldObject, requiredArray) {
function createComponent(fieldName, fieldObject, requiredArray, prefix) {
const componentType = determineType(fieldObject);
console.log(componentType, "type determined");
const validate = determineValidation(fieldName, fieldObject, requiredArray);
const label = !validate.required && !prefix ? fieldName + " (optional)" : fieldName;
switch (componentType) {
case "textfield":
return {
type: "textfield",
key: fieldName,
label: fieldName,
label: label,
input: true,
description: fieldObject["description"],
validate
};
case "tags":
return {
label: fieldName,
label: label,
tableView: false,
storeas: "array",
validateWhenHidden: false,
Expand All @@ -94,7 +94,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
};
case "number":
return {
label: fieldName,
label: label,
applyMaskOn: "change",
mask: false,
tableView: false,
Expand All @@ -111,7 +111,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
};
case "integer":
return {
label: fieldName,
label: label,
applyMaskOn: "change",
mask: false,
tableView: false,
Expand All @@ -131,7 +131,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
var options = transformArrayToOptions(fieldObject.enum);
console.log("checking options here:", options);
return {
label: fieldName,
label: label,
optionsLabelPosition: "right",
inline: false,
tableView: false,
Expand All @@ -147,7 +147,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
var options = transformArrayToOptions(fieldObject.items.enum);
console.log("checking options here:", options);
return {
label: fieldName,
label: label,
optionsLabelPosition: "right",
tableView: false,
values: options,
Expand All @@ -161,7 +161,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
};
case "datetime":
return {
label: fieldName,
label: label,
tableView: false,
datePicker: {
disableWeekends: false,
Expand Down Expand Up @@ -189,7 +189,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
};
case "select-boolean":
return {
label: fieldName,
label: label,
widget: "html5",
tableView: true,
data: {
Expand All @@ -213,7 +213,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
};
case "container":
return {
label: fieldName,
label: label,
hideLabel: false,
tableView: false,
validateWhenHidden: false,
Expand All @@ -226,7 +226,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
};
case "datagrid":
return {
label: fieldName,
label: label,
reorder: false,
addAnotherPosition: "bottom",
layoutFixed: false,
Expand All @@ -246,7 +246,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
case "content":
return {
html: `<p class="margin-top-neg-3 margin-bottom-4 text-base-dark">${fieldObject["content"]}</p>`,
label: fieldName,
label: label,
customClass: fieldObject["className"],
refreshOnChange: false,
key: fieldName,
Expand All @@ -260,11 +260,20 @@ function createComponent(fieldName, fieldObject, requiredArray) {
}

// Adds heading containing schema information
function createFormHeading(title, description) {
function createFormHeading(agency) {
const agencyTitle = (agency === "gov") ? agency.charAt(0).toUpperCase() + agency.slice(1) : agency.toUpperCase();
const agencyDescription = (agency !== "gov") ? agencyTitle : agency;

const container = document.getElementById('form-header');
container.innerHTML = `
<h1>${title}</h1>\n
<h2>${description}</h2>\n
<h1>Welcome to ${agencyTitle} Code.json Generator!</h1>\n
<h2>code.json generator is a web form designed to help ${agencyDescription} teams create a code.json file containing project metadata in compliance with the SHARE IT Act.
Visit the <a
class="usa-link usa-link--external"
rel="noreferrer"
target="_blank"
href="https://dsacms.github.io/share-it-act-lp/">
SHARE IT Act Landing Page</a> for more information.</h2>\n
<h3>Complete the form below to create a code.json file for your project:</h3>\n
`;
}
Expand All @@ -287,7 +296,7 @@ function createAllComponents(schema, prefix = "") {
console.log("key at play:", key);
const fullKey = prefix ? `${prefix}.${key}` : key;

let fieldComponent = createComponent(key, value, requiredArray);
let fieldComponent = createComponent(key, value, requiredArray, prefix);

if (fieldComponent.type === "container") {
fieldComponent.components = createAllComponents(value, fullKey);
Expand Down Expand Up @@ -326,7 +335,7 @@ async function createFormComponents() {
const jsonData = await retrieveFile(filePath);
console.log("JSON Data:", jsonData);

createFormHeading(jsonData["title"], jsonData["description"]);
createFormHeading(page);

components = createAllComponents(jsonData);

Expand Down Expand Up @@ -354,10 +363,6 @@ async function createFormComponents() {
tableView: false,
});



console.log(components);

return components;
}

Expand Down
Loading
Loading