Skip to content

Commit 6821d4c

Browse files
committed
update the local variant
1 parent d45c799 commit 6821d4c

File tree

4 files changed

+30
-54
lines changed

4 files changed

+30
-54
lines changed

lib/printUtil.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ const { getJwt, readVcapServices } = require("./authUtil");
22
const { getPrintConfigFromActionOrEntity } = require('./annotation-helper');
33
const axios = require('axios');
44
const logger = cds.log("print");
5+
const CONSOLE_MODE = process.env.PRINT_CONSOLE_MODE === 'true';
56

67
/**
78
* Populates the queue value help with available printers.
89
* @param {Object} _ - Unused parameter.
910
* @param {Object} req - The request object.
1011
*/
1112
const populateQueueValueHelp = async function (_, req) {
13+
14+
if (!CONSOLE_MODE) {
1215
const vcap = await readVcapServices();
1316
if (!vcap || vcap?.status === 500) {
1417
// For Production, return the error if print service is not found
@@ -30,19 +33,36 @@ const populateQueueValueHelp = async function (_, req) {
3033
}
3134
});
3235
const resp = await api.get(`/qm/api/v1/rest/queues`);
36+
3337
resp.data.forEach((item, index) => {
3438
req.results[index] = { ID: item.qname };
3539
});
3640
req.results.$count = resp.data.length;
37-
}
41+
} else {
42+
const offlineQueues = [
43+
{ ID: 'DEFAULT_PRINTER' },
44+
{ ID: 'HP_LASERJET_PRO' },
45+
{ ID: 'CANON_IMAGECLASS' },
46+
{ ID: 'XEROX_WORKCENTRE' },
47+
{ ID: 'OFFICE_PRINTER_01' },
48+
{ ID: 'OFFICE_PRINTER_02' }
49+
];
3850

51+
offlineQueues.forEach((item, index) => {
52+
req.results[index] = { ID: item.ID };
53+
});
54+
req.results.$count = offlineQueues.length;
55+
return;
56+
}
3957
/**
4058
* Handles the print request.
4159
* @param {Object} _ - Unused parameter.
4260
* @param {Object} req - The request object.
4361
*/
4462
const print = async function (_, req) {
4563
let { qname, numberOfCopies, docsToPrint } = await getPrintConfigFromActionOrEntity(req);
64+
65+
if (!CONSOLE_MODE) {
4666
const vcap = await readVcapServices(req);
4767
if (!vcap || vcap?.status === 500) {
4868
// For Production, return the error if print service is not found
@@ -113,7 +133,14 @@ const print = async function (_, req) {
113133
logger.info(`Document sent to print queue ${qname}`);
114134
return req.info(200, `Document sent to print queue ${qname} \n
115135
No. of copies requested: ${numberOfCopies}`);
136+
} else {
137+
// Offline / Console Mode
138+
docsToPrint.forEach((doc) => {
139+
logger.info(`Document ${doc.fileName} sent to print queue ${qname}`);
140+
});
116141
}
117142

118-
module.exports = { print, populateQueueValueHelp };
143+
}
144+
}
119145

146+
module.exports = { print, populateQueueValueHelp };

package.json

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,8 @@
4141
"requires": {
4242
"print": {
4343
"vcap": {
44-
"tag": "Print"
45-
},
46-
"[development]": {
47-
"kind": "print-to-console"
44+
"tag": "print"
4845
}
49-
}
50-
},
51-
"kinds": {
52-
"print-to-console": {
53-
"impl": "./srv/printToConsole.js"
54-
}
5546
}
5647
},
5748
"scripts": {

srv/printToConsole.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

srv/service.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)