@@ -16,20 +16,41 @@ async function retrieveFile(filePath) {
1616
1717// Populates blank code.json object with values from form
1818function 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
3556async function populateCodeJson ( data ) {
0 commit comments