11const {
22 getFieldsHoldingPrintConfig,
3- getAnnotatedParamsOfAction,
4- getQueueValueHelpEntity
3+ getAnnotatedParamsOfAction
54} = require ( './lib/annotation-helper' ) ;
65
7- const { print, populateQueueValueHelp} = require ( './lib/printUtil' ) ;
8-
96const cds = require ( '@sap/cds' ) ;
10- let queueValueHelpHandlerRegistered = false ;
117
128cds . once ( "served" , async ( ) => {
139 // Iterate over all services
@@ -19,30 +15,18 @@ cds.once("served", async () => {
1915 const printer = await cds . connect . to ( "print" ) ;
2016
2117 srv . after ( 'READ' , entity , async ( _ , req ) => {
22- // TODO: make sure the format of all services are the same
2318 const q = await printer . getQueues ( ) ;
24-
2519 q . forEach ( ( item , index ) => {
2620 req . results [ index ] = { ID : item . ID } ;
2721 } ) ;
2822 req . results . $count = q . length ;
2923 return ;
30-
3124 } ) ;
32-
3325 }
3426
3527 // Track the fields holding print configurations
3628 await getFieldsHoldingPrintConfig ( entity ) ;
3729
38- // ValueHelp entity handler
39- const sourceentity = getQueueValueHelpEntity ( entity . elements ) ;
40- if ( sourceentity ) {
41- // Register for print related handling
42- srv . after ( 'READ' , sourceentity , populateQueueValueHelp ) ;
43- queueValueHelpHandlerRegistered = true ;
44- }
45-
4630 // Check if the entity has actions
4731 if ( entity . actions ) {
4832 let actionsArray ;
@@ -64,7 +48,10 @@ cds.once("served", async () => {
6448 const actionName = boundAction . name . split ( '.' ) . pop ( ) ;
6549
6650 // Register for print related handling
67- srv . after ( actionName , print ) ;
51+ const printer = await cds . connect . to ( "print" ) ;
52+ srv . after ( actionName , async ( results , req ) => {
53+ return printer . print ( req ) ;
54+ } ) ;
6855 }
6956 }
7057 }
0 commit comments