Skip to content

Commit 89f9520

Browse files
Merge pull request #98 from DSACMS/DSACMS/nat/schema-update
Form: Uses Latest Schema + Guidance Improvements
2 parents 69eb0d2 + 254da2f commit 89f9520

File tree

6 files changed

+274
-67
lines changed

6 files changed

+274
-67
lines changed

index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<html lang="en-US">
22
<meta charset="UTF-8">
3+
<meta name="description" content="Form to generate a code.json file containing repository metadata">
34

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

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

289292
<div id="formio"></div>

js/autoGenerateFields.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,9 @@ async function preFillFields(repoData, languages) {
279279
feedbackComp.setValue(issuesUrl)
280280
}
281281

282-
// Update upstream
283-
284-
if (form.getComponent('upstream') && repoData.html_url) {
285-
const upstreamComp = form.getComponent('upstream');
282+
// Update SBOM
283+
if (form.getComponent('SBOM') && repoData.html_url) {
284+
const upstreamComp = form.getComponent('SBOM');
286285
const urlParts = repoData.html_url.split('/')
287286

288287
if (urlParts.length >= 2) {

js/formDataToJson.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ function getSelectedOptions(options) {
3737
return selectedOptions;
3838
}
3939

40+
function isEmptyObject(obj) {
41+
return Object.values(obj).every(value =>
42+
value === "" ||
43+
value === null ||
44+
value === undefined
45+
);
46+
}
47+
4048
// Populates fields with form data
4149
function populateObject(data, fields) {
4250
let reorderedObject = {}
@@ -45,7 +53,7 @@ function populateObject(data, fields) {
4553
let value = data[field];
4654

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

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

296303
// Triggers local file download

js/generateFormComponents.js

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,23 @@ function determineType(field) {
6666
}
6767

6868
// Creates Form.io component based on json field type
69-
function createComponent(fieldName, fieldObject, requiredArray) {
69+
function createComponent(fieldName, fieldObject, requiredArray, prefix) {
7070
const componentType = determineType(fieldObject);
71-
console.log(componentType, "type determined");
7271
const validate = determineValidation(fieldName, fieldObject, requiredArray);
72+
const label = !validate.required && !prefix ? fieldName + " (optional)" : fieldName;
7373
switch (componentType) {
7474
case "textfield":
7575
return {
7676
type: "textfield",
7777
key: fieldName,
78-
label: fieldName,
78+
label: label,
7979
input: true,
8080
description: fieldObject["description"],
8181
validate
8282
};
8383
case "tags":
8484
return {
85-
label: fieldName,
85+
label: label,
8686
tableView: false,
8787
storeas: "array",
8888
validateWhenHidden: false,
@@ -94,7 +94,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
9494
};
9595
case "number":
9696
return {
97-
label: fieldName,
97+
label: label,
9898
applyMaskOn: "change",
9999
mask: false,
100100
tableView: false,
@@ -111,7 +111,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
111111
};
112112
case "integer":
113113
return {
114-
label: fieldName,
114+
label: label,
115115
applyMaskOn: "change",
116116
mask: false,
117117
tableView: false,
@@ -131,7 +131,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
131131
var options = transformArrayToOptions(fieldObject.enum);
132132
console.log("checking options here:", options);
133133
return {
134-
label: fieldName,
134+
label: label,
135135
optionsLabelPosition: "right",
136136
inline: false,
137137
tableView: false,
@@ -147,7 +147,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
147147
var options = transformArrayToOptions(fieldObject.items.enum);
148148
console.log("checking options here:", options);
149149
return {
150-
label: fieldName,
150+
label: label,
151151
optionsLabelPosition: "right",
152152
tableView: false,
153153
values: options,
@@ -161,7 +161,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
161161
};
162162
case "datetime":
163163
return {
164-
label: fieldName,
164+
label: label,
165165
tableView: false,
166166
datePicker: {
167167
disableWeekends: false,
@@ -189,7 +189,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
189189
};
190190
case "select-boolean":
191191
return {
192-
label: fieldName,
192+
label: label,
193193
widget: "html5",
194194
tableView: true,
195195
data: {
@@ -213,7 +213,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
213213
};
214214
case "container":
215215
return {
216-
label: fieldName,
216+
label: label,
217217
hideLabel: false,
218218
tableView: false,
219219
validateWhenHidden: false,
@@ -226,7 +226,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
226226
};
227227
case "datagrid":
228228
return {
229-
label: fieldName,
229+
label: label,
230230
reorder: false,
231231
addAnotherPosition: "bottom",
232232
layoutFixed: false,
@@ -246,7 +246,7 @@ function createComponent(fieldName, fieldObject, requiredArray) {
246246
case "content":
247247
return {
248248
html: `<p class="margin-top-neg-3 margin-bottom-4 text-base-dark">${fieldObject["content"]}</p>`,
249-
label: fieldName,
249+
label: label,
250250
customClass: fieldObject["className"],
251251
refreshOnChange: false,
252252
key: fieldName,
@@ -260,11 +260,20 @@ function createComponent(fieldName, fieldObject, requiredArray) {
260260
}
261261

262262
// Adds heading containing schema information
263-
function createFormHeading(title, description) {
263+
function createFormHeading(agency) {
264+
const agencyTitle = (agency === "gov") ? agency.charAt(0).toUpperCase() + agency.slice(1) : agency.toUpperCase();
265+
const agencyDescription = (agency !== "gov") ? agencyTitle : agency;
266+
264267
const container = document.getElementById('form-header');
265268
container.innerHTML = `
266-
<h1>${title}</h1>\n
267-
<h2>${description}</h2>\n
269+
<h1>Welcome to ${agencyTitle} Code.json Generator!</h1>\n
270+
<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.
271+
Visit the <a
272+
class="usa-link usa-link--external"
273+
rel="noreferrer"
274+
target="_blank"
275+
href="https://dsacms.github.io/share-it-act-lp/">
276+
SHARE IT Act Landing Page</a> for more information.</h2>\n
268277
<h3>Complete the form below to create a code.json file for your project:</h3>\n
269278
`;
270279
}
@@ -287,7 +296,7 @@ function createAllComponents(schema, prefix = "") {
287296
console.log("key at play:", key);
288297
const fullKey = prefix ? `${prefix}.${key}` : key;
289298

290-
let fieldComponent = createComponent(key, value, requiredArray);
299+
let fieldComponent = createComponent(key, value, requiredArray, prefix);
291300

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

329-
createFormHeading(jsonData["title"], jsonData["description"]);
338+
createFormHeading(page);
330339

331340
components = createAllComponents(jsonData);
332341

@@ -354,10 +363,6 @@ async function createFormComponents() {
354363
tableView: false,
355364
});
356365

357-
358-
359-
console.log(components);
360-
361366
return components;
362367
}
363368

0 commit comments

Comments
 (0)