@@ -56,6 +56,7 @@ exports.SessionSetFile = (sid, filename) => {
5656 sheetNames : Array . from ( Object . keys ( wb . Sheets ) ) ,
5757 jobs : new Map ( ) ,
5858 // State we store for the frontend (we don't do anything with it, just store it and spit it back on demand)
59+ attributeDefs : [ ] , // A list of objects with {name:string, required:boolean, type:string} defining the attributes we output
5960 headerRanges : { } , // A map from sheetname to the header range
6061 footerRanges : { } , // A map from sheetname to the footer range
6162 mappingRules : { } , // A map from column index to attribute name
@@ -68,14 +69,9 @@ exports.SessionSetFile = (sid, filename) => {
6869/// Storage of UI state for the frontend
6970///
7071
71- exports . SessionGetMappingRules = ( sid ) => {
72- let session = sessionStore . get ( sid ) ;
73- return session . mappingRules ;
74- } ;
75-
76- exports . SessionSetMappingRules = ( sid , rules ) => {
77- sessionStore . apply ( sid , ( s ) => { s . mappingRules = rules } )
78- } ;
72+ exports . SessionSetAttributes = ( sid , attrDefs ) => {
73+ sessionStore . apply ( sid , ( s ) => { s . attribudeDefs = attrDefs } )
74+ }
7975
8076exports . SessionSetHeaderRange = ( sid , range ) => {
8177 assert ( range != null , "Null range passed to SessionSetHeaderRange" ) ;
@@ -100,6 +96,15 @@ exports.SessionGetFooterRange = (sid, sheetName) => {
10096 return session . footerRanges [ sheetName ]
10197} ;
10298
99+ exports . SessionGetMappingRules = ( sid ) => {
100+ let session = sessionStore . get ( sid ) ;
101+ return session . mappingRules ;
102+ } ;
103+
104+ exports . SessionSetMappingRules = ( sid , rules ) => {
105+ sessionStore . apply ( sid , ( s ) => { s . mappingRules = rules } )
106+ } ;
107+
103108exports . SessionGetFormatChoices = ( sid ) => {
104109 let session = sessionStore . get ( sid ) ;
105110 return session . formatChoices ;
@@ -109,6 +114,35 @@ exports.SessionSetFormatChoices = (sid, choices) => {
109114 sessionStore . apply ( sid , ( s ) => { s . formatChoices = choices } )
110115} ;
111116
117+ ///
118+ /// Frontend helpers
119+ ///
120+
121+
122+ // Returns an array of column indexes that need a format to be chosen - requires
123+ // that SessionSetAttributes and SessionSetMappingRules have both happened so we
124+ // have the required information.
125+ exports . SessionGetColumnsNeedingFormats = ( sid ) => {
126+ const session = sessionStore . get ( sid ) ;
127+ const attributes = session . attribudeDefs ;
128+ const mappings = session . mappingRules ;
129+ const supportedTypes = attributeTypes . supportedTypes ;
130+
131+ let columnsNeedingFormats = new Array ( ) ;
132+
133+ Object . entries ( mappings ) . forEach ( ( entry ) => {
134+ const [ colIdx , columnAttribute ] = entry ;
135+ const columnDef = attributes . find ( ( attr ) => attr . name == columnAttribute ) ;
136+ const columnTypeName = columnDef . type ;
137+ const columnType = supportedTypes . get ( columnTypeName ) ;
138+ if ( columnType . formats ) {
139+ columnsNeedingFormats . push ( colIdx ) ;
140+ }
141+ } ) ;
142+
143+ return columnsNeedingFormats ;
144+ } ;
145+
112146///
113147/// Information about the loaded input file
114148///
0 commit comments