diff --git a/client/core/src/lib/app.js b/client/core/src/lib/app.js index 3b58309b4..5851357d8 100644 --- a/client/core/src/lib/app.js +++ b/client/core/src/lib/app.js @@ -12,7 +12,7 @@ export default class App { this.$rootScope = $rootScope; } show(message) { - if (this.snackbar) this.snackbar.show({message: message}); + if (this.snackbar) this.snackbar.show({message: message, timeout: 400}); } showMessage(message) { this.show(message); diff --git a/services/mailer/application/route/notification.js b/services/mailer/application/route/notification.js index bd7a81f11..810fbdf88 100644 --- a/services/mailer/application/route/notification.js +++ b/services/mailer/application/route/notification.js @@ -4,10 +4,15 @@ var config = require('../config.js'); var mail = require('../mail.js'); var template = require('../template.js'); var httpRequest = require('request'); +var auth = require('../auth.js'); +// Auth middleware +var requestToken = function(request, response, next) { + auth.init(request, response, next); +}; // Printer setup -router.post('/printer-setup/:clientId', function(request, response) { +router.get('/printer-setup/:clientId', requestToken, function(request, response) { mail.sendWithTemplate('printer-setup', {clientId: request.params.clientId}, error => { if (error) return response.status(400).json({message: error.message}); @@ -17,7 +22,7 @@ router.post('/printer-setup/:clientId', function(request, response) { }); // Printer setup preview -router.get('/printer-setup/:clientId', function(request, response) { +router.get('/printer-setup/:clientId/preview', requestToken, function(request, response) { template.get('printer-setup', {clientId: request.params.clientId, isPreview: true}, (error, result) => { if (error) return response.status(400).json({message: error.message}); @@ -27,7 +32,7 @@ router.get('/printer-setup/:clientId', function(request, response) { }); // Client welcome -router.post('/client-welcome/:clientId', function(request, response) { +router.get('/client-welcome/:clientId', requestToken, function(request, response) { mail.sendWithTemplate('client-welcome', {clientId: request.params.clientId}, error => { if (error) return response.status(400).json({message: error.message}); @@ -37,7 +42,7 @@ router.post('/client-welcome/:clientId', function(request, response) { }); // Client welcome preview -router.get('/client-welcome/:clientId', function(request, response) { +router.get('/client-welcome/:clientId/preview', requestToken, function(request, response) { template.get('client-welcome', {clientId: request.params.clientId, isPreview: true}, (error, result) => { if (error) return response.status(400).json({message: error.message}); @@ -47,8 +52,13 @@ router.get('/client-welcome/:clientId', function(request, response) { }); // Client SEPA CORE -router.post('/sepa-core/:clientId', function(request, response) { - let path = `${request.proxyHost}/print/manuscript/sepa-core/${request.params.clientId}`; +router.get('/sepa-core/:companyId/:clientId', requestToken, function(request, response) { + let params = { + clientId: request.params.clientId, + companyId: request.params.companyId + }; + + let path = `${request.proxyHost}/print/manuscript/sepa-core/${params.companyId}/${params.clientId}`; let options = { url: path, method: 'GET', @@ -59,25 +69,75 @@ router.post('/sepa-core/:clientId', function(request, response) { let httpStream = httpRequest(options, function(error, httpResponse, body) { if (error || httpResponse.statusCode != 200) - return response.status(400).json({message: error.message}); + return response.status(400).json({message: error}); }); if (httpStream) - mail.sendWithTemplate('sepa-core', { - clientId: request.params.clientId, - attachments: [{filename: 'sepa-core.pdf', content: httpStream}] - }, error => { - if (error) - return response.status(400).json({message: error.message}); - - return response.json(); + params.attachments = [{filename: 'sepa-core.pdf', content: httpStream}]; + + mail.sendWithTemplate('sepa-core', params, error => { + if (error) + return response.status(400).json({message: error.message}); + + return response.json(); }); }); // Client SEPA CORE preview -router.get('/sepa-core/:clientId', function(request, response) { - template.get('sepa-core', { +router.get('/sepa-core/:companyId/:clientId/preview', requestToken, function(request, response) { + let params = { + clientId: request.params.clientId, + companyId: request.params.companyId, + token: request.user.token, + isPreview: true + }; + + template.get('sepa-core', params, (error, result) => { + if (error) + return response.status(400).json({message: error.message}); + + response.send(result.body); + }); +}); + +// First debtor letter +router.get('/letter-debtor-st/:companyId/:clientId', requestToken, function(request, response) { + let params = { + clientId: request.params.clientId, + companyId: request.params.companyId, + token: request.user.token + }; + + let path = `${request.proxyHost}/print/manuscript/letter-debtor/${params.companyId}/${params.clientId}`; + let options = { + url: path, + method: 'GET', + headers: { + 'Authorization': request.headers.authorization + } + } + + let httpStream = httpRequest(options, function(error, httpResponse, body) { + if (error || httpResponse.statusCode != 200) + return response.status(400).json({message: error}); + }); + + if (httpStream) + params.attachments = [{filename: 'extracto.pdf', content: httpStream}]; + + mail.sendWithTemplate('letter-debtor-st', params, error => { + if (error) + return response.status(400).json({message: error.message}); + + return response.json(); + }); +}); + +// First debtor letter preview +router.get('/letter-debtor-st/:companyId/:clientId/preview', requestToken, function(request, response) { + template.get('letter-debtor-st', { clientId: request.params.clientId, + companyId: request.params.companyId, token: request.user.token, isPreview: true }, (error, result) => { @@ -88,6 +148,85 @@ router.get('/sepa-core/:clientId', function(request, response) { }); }); +// Second debtor letter +router.get('/letter-debtor-nd/:companyId/:clientId', requestToken, function(request, response) { + let params = { + clientId: request.params.clientId, + companyId: request.params.companyId, + token: request.user.token + }; + + let path = `${request.proxyHost}/print/manuscript/letter-debtor/${params.companyId}/${params.clientId}`; + let options = { + url: path, + method: 'GET', + headers: { + 'Authorization': request.headers.authorization + } + } + + let httpStream = httpRequest(options, function(error, httpResponse, body) { + if (error || httpResponse.statusCode != 200) + return response.status(400).json({message: error}); + }); + + if (httpStream) + params.attachments = [{filename: 'extracto.pdf', content: httpStream}]; + + mail.sendWithTemplate('letter-debtor-nd', params, error => { + if (error) + return response.status(400).json({message: error.message}); + + return response.json(); + }); +}); + +// Second debtor letter preview +router.get('/letter-debtor-nd/:companyId/:clientId/preview', requestToken, function(request, response) { + template.get('letter-debtor-nd', { + clientId: request.params.clientId, + companyId: request.params.companyId, + token: request.user.token, + isPreview: true + }, (error, result) => { + if (error) + return response.status(400).json({message: error.message}); + + response.send(result.body); + }); +}); + +// Payment method changes +router.get('/payment-update/:clientId', requestToken, function(request, response) { + mail.sendWithTemplate('payment-update', {clientId: request.params.clientId}, error => { + if (error) + return response.status(400).json({message: error.message}); + + return response.json(); + }); +}); + +// Send notification to alias creditInsurance on client deactivate +router.get('/client-deactivate/:clientId', requestToken, function(request, response) { + var params = { + alias: 'creditInsurance', + code: 'clientDeactivate', + bodyParams: { + clientId: request.params.clientId + } + }; + + mail.sendWithTemplate('notification-alias', params, error => { + if (error) + response.status(400).json({message: error.message}); + + return response.json(); + }); +}); + +module.exports = router; + + // Single user notification /* router.post('/:recipient/noticeUserSend', function(request, response) { var params = { @@ -146,34 +285,4 @@ router.get('/sepa-core/:clientId', function(request, response) { mail.sendWithTemplate('notification-notice', params, result => { return response.json(result); }); -}); */ - -// Payment method changes -router.post('/payment-update/:clientId', function(request, response) { - mail.sendWithTemplate('payment-update', {clientId: request.params.clientId}, error => { - if (error) - return response.status(400).json({message: error.message}); - - return response.json(); - }); -}); - -// Send notification to alias creditInsurance on client deactivate -router.post('/client-deactivate/:clientId', function(request, response) { - var params = { - alias: 'creditInsurance', - code: 'clientDeactivate', - bodyParams: { - clientId: request.params.clientId - } - }; - - mail.sendWithTemplate('notification-alias', params, error => { - if (error) - response.status(400).json({message: error.message}); - - return response.json(); - }); -}); - -module.exports = router; +}); */ \ No newline at end of file diff --git a/services/mailer/application/router.js b/services/mailer/application/router.js index ed5794bbe..161271820 100644 --- a/services/mailer/application/router.js +++ b/services/mailer/application/router.js @@ -1,5 +1,7 @@ var express = require('express'); var router = new express.Router(); +var fs = require('fs'); +var path = require('path'); // Mailer default page router.get('/', function(request, response) { @@ -9,4 +11,20 @@ router.get('/', function(request, response) { // Notifications router.use('/notification', require('./route/notification.js')); +// Serve static images +router.use('/static/:template/:image', function(request, response) { + let imagePath = path.join(__dirname, '/template/', request.params.template, '/image/', request.params.image); + + fs.stat(imagePath, function(error) { + if (error) + return response.json({message: 'Image not found'}); + + let readStream = fs.createReadStream(imagePath); + + readStream.on('open', function() { + readStream.pipe(response); + }); + }); +}); + module.exports = router; diff --git a/services/mailer/application/template.js b/services/mailer/application/template.js index d2c13f222..1e9c92fde 100644 --- a/services/mailer/application/template.js +++ b/services/mailer/application/template.js @@ -15,7 +15,7 @@ module.exports = { get: function(template, params, cb) { var templatePath = path.join(__dirname, 'template', `${template}`, `index.html`); var classPath = path.join(__dirname, 'template', `${template}`, `${template}.js`); - var stylePath = path.join(__dirname, 'template', `${template}`, 'static', 'css', 'style.css'); + var stylePath = path.join(__dirname, 'template', `${template}`, 'style.css'); fs.stat(templatePath, (error, stat) => { if (error) @@ -65,6 +65,8 @@ module.exports = { return cb(error); instance._ = result.locale; + instance.isPreview = params.isPreview; + getDataCb(null, result); }); }); @@ -173,14 +175,17 @@ module.exports = { // Template default attachments for (var i = 0; i < tplAttachments.length; i++) { - let name = tplAttachments[i].replace('src="cid:', '').replace('"', ''); + let src = tplAttachments[i].replace('src="cid:', '').replace('"', '').split('/'); + let attachmentTpl = src[0]; + let attachment = src[1]; if (isPreview) { - let attachmentPath = `/mailer/static/images/${name}`; + let attachmentPath = `/mailer/static/${attachmentTpl}/${attachment}`; body = body.replace(tplAttachments[i], `src="${attachmentPath}"`); } else { - let attachmentPath = path.join(__dirname, '../static', 'images', name); - attachments.push({filename: name, path: attachmentPath, cid: name}); + let attachmentPath = path.join(__dirname, 'template', `${attachmentTpl}`, 'image', attachment); + let attachmentName = attachmentTpl + '/' + attachment; + attachments.push({filename: attachmentName, path: attachmentPath, cid: attachmentName}); } } diff --git a/services/mailer/application/template/client-welcome/client-welcome.js b/services/mailer/application/template/client-welcome/client-welcome.js index 469e74386..7cf435d0e 100644 --- a/services/mailer/application/template/client-welcome/client-welcome.js +++ b/services/mailer/application/template/client-welcome/client-welcome.js @@ -14,10 +14,11 @@ module.exports = class ClientWelcome { c.email recipient FROM client c JOIN account.user u ON u.id = c.id - LEFT JOIN worker w ON w.id = c.workerFk + LEFT JOIN worker w ON w.id = c.salesPersonFk LEFT JOIN account.user wu ON wu.id = w.userFk JOIN country ct ON ct.id = c.countryFk WHERE c.id = ?`; + database.pool.query(query, [params.clientId], (error, result) => { if (error || result.length == 0) return cb(new Error('No template data found')); diff --git a/services/mailer/application/template/client-welcome/index.html b/services/mailer/application/template/client-welcome/index.html index a8a711c8e..2c778bee8 100644 --- a/services/mailer/application/template/client-welcome/index.html +++ b/services/mailer/application/template/client-welcome/index.html @@ -22,6 +22,7 @@
{{_.dear}}
{{{_.bodyDescription}}}
+
{{_.dear}}
+ +{{_.bodyDescription}}
+{{_.termLimits}}
++ {{_.payMethod}} + +
+ {{_.legalActions}} +
{{_.contact}}
+ +{{_.waitingForNews}}
+{{_.conclusion}}
+ ++
{{_.dear}}
{{_.bodyDescription}}
{{_.conclusion}}
- {{{previewAttachments}}} + + {{#isPreview}} + + + + + + + + {{/isPreview}} diff --git a/services/mailer/application/template/sepa-core/sepa-core.js b/services/mailer/application/template/sepa-core/sepa-core.js index 04fd71df7..ec19dd29b 100644 --- a/services/mailer/application/template/sepa-core/sepa-core.js +++ b/services/mailer/application/template/sepa-core/sepa-core.js @@ -5,19 +5,19 @@ var format = require(path.join(__dirname, '../../util/format.js')); module.exports = class SepaCore { getData(params, cb) { let query = `SELECT - c.id clientId, CONCAT(w.name, ' ', w.firstName) name, w.phone AS phone, CONCAT(u.name, '@verdnatura.es') AS email, LOWER(ct.code) countryCode, c.email recipient FROM client c - LEFT JOIN worker w ON w.id = c.workerFk + LEFT JOIN worker w ON w.id = c.salesPersonFk LEFT JOIN account.user u ON u.id = w.userFk JOIN country ct ON ct.id = c.countryFk WHERE c.id = ?`; - this.isPreview = params.isPreview; + this.clientId = params.clientId; + this.companyId = params.companyId; this.token = params.token; database.pool.query(query, [params.clientId], (error, result) => { @@ -29,11 +29,4 @@ module.exports = class SepaCore { cb(); }); } - - get previewAttachments() { - if (this.isPreview) - return `` + - ' '; - } }; diff --git a/services/mailer/application/template/sepa-core/style.css b/services/mailer/application/template/sepa-core/style.css new file mode 100644 index 000000000..e69de29bb diff --git a/services/mailer/server/server.js b/services/mailer/server/server.js index 50320a391..457a61ddf 100644 --- a/services/mailer/server/server.js +++ b/services/mailer/server/server.js @@ -13,13 +13,8 @@ app.use(bodyParser.urlencoded({extended: true})); app.use('/static', express.static(path.join(__dirname, '../static'))); -// Auth middleware -var requestToken = function(request, response, next) { - auth.init(request, response, next); -}; - // Load routes -app.use('/', requestToken, require('../application/router.js')); +app.use('/', require('../application/router.js')); app.start = function() { var listener = app.listen(config.app.port, function() { diff --git a/services/mailer/static/css/component.css b/services/mailer/static/css/component.css index 10805e562..b4c018d79 100644 --- a/services/mailer/static/css/component.css +++ b/services/mailer/static/css/component.css @@ -1,137 +1,221 @@ -img { - margin: 0 -} - -p { - text-align: justify -} - -.wrapper { - background-color: #EEE -} - -.container { - font-family: arial, sans-serif; - max-width: 600px; - min-width: 320px; - font-size: 16px; - margin: 0 auto; - color: #555 -} - -.title { - background-color: #95d831; - text-align: center; - padding: 35px 0 -} - -.title h1 { - font-size: 32px; - color: #333; - margin: 0 -} - -.body { - background-color:#FFF; - padding: 20px -} - -.body a { - color: #8dba25 -} - -.body h1 { - color: #999 -} - -.body h3 { - font-size: 16px -} - -.panel { - border: 1px solid #DDD; - margin-bottom: 10px; - padding:10px -} - -.row { - margin-bottom: 15px; - overflow: hidden; - content: ''; - clear: both -} - -.row .text { - margin-bottom: 5px -} - -.row .control { - -webkit-box-sizing: border-box; - -moz-box-sizing: border-box; - box-sizing: border-box -} - -.row .description { - font-size: 8px; - color: #999 -} - -.row .v-align { - padding-top: 5px; - line-height: 21px -} - -.row:last-child { - margin-bottom: 0 -} - -.row.inline .text { - margin-bottom: 0; - width: 40%; - float: left -} - -.row.inline .control { - font-weight: bold; - padding-left: 20px; - color: #000; - width: 60%; - float: left -} - -.box { - border-top: 1px solid #CCC; - border-right: 1px solid #CCC; - border-bottom: 1px solid #CCC; - font-weight: bold; - text-align: center; - padding-top: 4px; - width: 25px; - height: 21px; - color: #000; - float: left -} - -.row .control .box:first-child { - border-left: 1px solid #CCC; -} - -.attachment { - overflow: hidden; - margin-top: 10px -} - -.attachment:after { - content: ' '; - display: block; - clear: both -} - -.attachment-icon { - float: left -} - -.attachment span { - padding: 16px 0 0 10px; - float: left +body { + padding: 0; + margin: 0 +} + +img { + margin: 0 +} + +p { + text-align: justify +} + +.wrapper { + background-color: #EEE +} + +.container { + font-family: arial, sans-serif; + max-width: 600px; + min-width: 320px; + font-size: 16px; + margin: 0 auto; + color: #555 +} + +.title { + background-color: #95d831; + text-align: center; + padding: 35px 0 +} + +.title h1 { + font-size: 32px; + color: #333; + margin: 0 +} + +.body { + background-color:#FFF; + padding: 20px +} + +.body a { + color: #8dba25 +} + +.body h1 { + color: #999 +} + +.body h3 { + font-size: 16px +} + +.panel { + border: 1px solid #DDD; + margin-bottom: 10px; + position: relative; + padding:10px +} + +.row { + margin-bottom: 15px; + overflow: hidden +} + +.row .text { + margin-bottom: 5px +} + +.row .control { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box +} + +.row .text, .row .control { + overflow: hidden +} + +.row .description { + position: relative; + padding-top: 2px; + overflow: hidden; + font-size: 11px; + display: block; + color: #999 +} + +.row .line { + border-bottom: 1px solid #DDD; + border-right: 1px solid #DDD; + border-left: 1px solid #DDD; + margin-top: 10px; + color: #999; + padding: 5px +} + +.row .description span { + background-color: #FFF; + margin: -5px 0 0 50px; + display: block; + padding: 5px; + float: left +} + +.row:last-child { + margin-bottom: 0 +} + +.row.inline .text { + margin-bottom: 0; + width: 40%; + float: left +} + +.row.inline .control { + font-weight: bold; + padding-left: 20px; + color: #000; + width: 60%; + float: left +} + +.row.inline .description { + position: static; + overflow: visible +} + +.box { + border-top: 1px solid #CCC; + border-right: 1px solid #CCC; + border-bottom: 1px solid #CCC; + font-weight: bold; + text-align: center; + padding-top: 4px; + width: 25px; + height: 21px; + color: #000; + float: left +} + +.box.crossed { + font-weight: 100; + font-size: 16px +} + +.row .control .box:first-child { + border-left: 1px solid #CCC; +} + +.font.small { + font-size: 10px +} + +.font.verticalAlign { + height: 27px; + line-height: 27px +} + +.font.centered { + height: 27px; + line-height: 27px; + text-align: center +} + +.verticalText { + -moz-transform: rotate(90deg); + -webkit-transform: rotate(90deg); + transform: rotate(90deg); + position: absolute; + text-align: center; + font-size: .65em; + width: 200px; + right: -115px; + top: 50% +} + +.attachment { + overflow: hidden; + margin-top: 10px +} + +.attachment-icon { + float: left +} + +.attachment span { + padding: 16px 0 0 10px; + float: left +} + +.columns { + overflow: hidden +} + +.columns .size100 { + width: 100%; + float: left +} + +.columns .size75 { + width: 75%; + float: left +} + +.columns .size50 { + width: 50%; + float: left +} + +.columns .size33 { + width: 33.33%; + float: left +} + +.columns .size25 { + width: 25%; + float: left } \ No newline at end of file diff --git a/services/mailer/static/images/attachment.png b/services/mailer/static/images/attachment.png deleted file mode 100644 index 78efe4f95..000000000 Binary files a/services/mailer/static/images/attachment.png and /dev/null differ diff --git a/services/print/application/route/manuscript.js b/services/print/application/route/manuscript.js index 90662b646..091ffa4c3 100644 --- a/services/print/application/route/manuscript.js +++ b/services/print/application/route/manuscript.js @@ -4,22 +4,93 @@ var template = require('../template.js'); var config = require('../config.js'); var pdf = require('html-pdf'); var path = require('path'); +var auth = require('../auth.js'); + +// Auth middleware +var requestToken = function(request, response, next) { + auth.init(request, response, next); +}; // Sepa core -router.post('/sepa-core/:clientId', function(request, response, next) { - template.get('sepa-core', {clientId: request.params.clientId}, (error, result) => { +router.get('/sepa-core/:companyId/:clientId', requestToken, function(request, response, next) { + let params = { + clientId: request.params.clientId, + companyId: request.params.companyId + }; + + template.get('sepa-core', params, (error, result) => { if (error) return response.status(400).json({message: error.message}); - pdf.create(result.body).toStream(function(error, stream) { + pdf.create(result.body, config.pdf).toStream(function(error, stream) { if (error) throw Error(error); + response.setHeader('Content-Disposition', 'attachment; filename="sepa-core.pdf"'); + response.setHeader('Content-type', 'application/pdf'); stream.pipe(response); }); }); }); +// Sepa core html preview +router.get('/sepa-core/:companyId/:clientId/preview', requestToken, function(request, response, next) { + let params = { + clientId: request.params.clientId, + companyId: request.params.companyId, + isPreview: true + }; + + template.get('sepa-core', params, (error, result) => { + if (error) + return response.status(400).json({message: error.message}); + + response.send(result.body); + }); + }); + + // Debtor letter +router.get('/letter-debtor/:companyId/:clientId', requestToken, function(request, response, next) { + let params = { + clientId: request.params.clientId, + companyId: request.params.companyId + }; + + template.get('letter-debtor', params, (error, result) => { + if (error) + return response.status(400).json({message: error.message}); + + pdf.create(result.body, config.pdf).toStream(function(error, stream) { + if (error) + throw Error(error); + + response.setHeader('Content-Disposition', 'attachment; filename="extracto.pdf"'); + response.setHeader('Content-type', 'application/pdf'); + stream.pipe(response); + }); + }); + }); + + // Debtor letter html preview +router.get('/letter-debtor/:companyId/:clientId/preview', requestToken, function(request, response, next) { + let params = { + clientId: request.params.clientId, + companyId: request.params.companyId, + isPreview: true + }; + + template.get('letter-debtor', params, (error, result) => { + if (error) + return response.status(400).json({message: error.message}); + + response.send(result.body); + }); + }); + + +module.exports = router; + + // store pdf /* router.post('/sepa-core/:clientId', function(request, response, next) { template.get('sepa-core', {recipient: request.params.clientId}, (error, result) => { @@ -35,32 +106,4 @@ router.post('/sepa-core/:clientId', function(request, response, next) { }); }); }); - */ -// Sepa core preview -router.get('/sepa-core/:clientId', function(request, response, next) { - template.get('sepa-core', {clientId: request.params.clientId}, (error, result) => { - if (error) - return response.status(400).json({message: error.message}); - - let options = config.pdf; - pdf.create(result.body, options).toStream(function(error, stream) { - if (error) - throw Error(error); - - response.setHeader('Content-Disposition', 'inline; filename="sepa-core.pdf"'); - response.setHeader('Content-type', 'application/pdf'); - stream.pipe(response); - }); - }); -}); - -router.get('/sepa-core-view/:clientId', function(request, response, next) { - template.get('sepa-core', {clientId: request.params.clientId}, (error, result) => { - if (error) - return response.status(400).json({message: error.message}); - - response.send(result.body); - }); - }); - -module.exports = router; + */ \ No newline at end of file diff --git a/services/print/application/router.js b/services/print/application/router.js index 58e9a3694..a9ebe1acf 100644 --- a/services/print/application/router.js +++ b/services/print/application/router.js @@ -1,5 +1,7 @@ var express = require('express'); var router = new express.Router(); +var fs = require('fs'); +var path = require('path'); // Default page router.get('/', function(request, response) { @@ -9,4 +11,21 @@ router.get('/', function(request, response) { // Manuscripts router.use('/manuscript', require('./route/manuscript.js')); +// Serve static images +router.use('/static/:template/:image', function(request, response) { + let imagePath = path.join(__dirname, '/template/', request.params.template, '/image/', request.params.image); + + fs.stat(imagePath, function(error) { + if (error) + return response.json({message: 'Image not found'}); + + let readStream = fs.createReadStream(imagePath); + + readStream.on('open', function() { + readStream.pipe(response); + }); + }); +}); + + module.exports = router; diff --git a/services/print/application/template.js b/services/print/application/template.js index 9bc968c74..9974ebcf5 100644 --- a/services/print/application/template.js +++ b/services/print/application/template.js @@ -4,6 +4,7 @@ var locale = require('./locale.js'); var inlineCss = require('inline-css'); var path = require('path'); + module.exports = { /** * Get template. @@ -15,7 +16,7 @@ module.exports = { get: function(template, params, cb) { var templatePath = path.join(__dirname, 'template', `${template}`, `index.html`); var classPath = path.join(__dirname, 'template', `${template}`, `${template}.js`); - var stylePath = path.join(__dirname, 'template', `${template}`, 'static', 'css', 'style.css'); + var stylePath = path.join(__dirname, 'template', `${template}`, 'style.css'); fs.stat(templatePath, (error, stat) => { if (error) @@ -43,7 +44,7 @@ module.exports = { params.subject = title[1]; } - this.renderImages(template, body, (error, body) => { + this.renderImages(template, body, params.isPreview, (error, body) => { if (error) return cb(error); @@ -53,7 +54,7 @@ module.exports = { }; let getDataCb = () => { - this.render(templatePath, instance, (error, result) => getRenderedStyles(error, result)); + this.render(templatePath, params, instance, (error, result) => getRenderedStyles(error, result)); }; instance.getData(params, (error, result) => { @@ -65,6 +66,7 @@ module.exports = { return cb(error); instance._ = result.locale; + instance.isPreview = params.isPreview; getDataCb(null, result); }); }); @@ -77,7 +79,7 @@ module.exports = { * @param {Object} data - Params * @param {Object} cb - Callback */ - render: function(path, data, cb) { + render: function(path, params, data, cb) { fs.readFile(path, 'utf8', (error, body) => { // Find matching sub-templates let regexp = new RegExp(/\{\{\$\.(.*?)\}\}/, 'ig'); @@ -89,7 +91,7 @@ module.exports = { } let parentBody = body; - this.renderSub(parentBody, subTpl, data, regexp, (error, body) => { + this.renderSub(parentBody, subTpl, params, regexp, (error, body) => { if (error) return cb(error); @@ -99,13 +101,13 @@ module.exports = { }); }, - renderSub: function(body, subTpl, data, regexp, cb) { + renderSub: function(body, subTpl, params, regexp, cb) { let index = 1; subTpl.forEach(keyName => { subTplName = keyName.replace(regexp, '$1'); - this.get(subTplName, data, (error, result) => { + this.get(subTplName, params, (error, result) => { if (error) return cb(error); @@ -140,7 +142,7 @@ module.exports = { let style = ''; let body = style + html; let options = {url: ' '}; - + inlineCss(body, options) .then(function(body) { cb(null, body); @@ -156,7 +158,7 @@ module.exports = { * @param {String} body - template body * @param {Object} cb - Callback */ - renderImages: function(template, body, cb) { + renderImages: function(template, body, isPreview, cb) { let tplImages = body.match(new RegExp('src="cid:(.*?)"', 'ig')); if (!tplImages) @@ -164,10 +166,17 @@ module.exports = { // Template default attachments for (var i = 0; i < tplImages.length; i++) { - let name = tplImages[i].replace('src="cid:', '').replace('"', ''); + let src = tplImages[i].replace('src="cid:', '').replace('"', '').split('/'); + let attachmentTpl = src[0]; + let attachment = src[1]; - let imagePath = path.join(__dirname, 'template', `${template}`, 'static', 'image', name); - body = body.replace(tplImages[i], `src="file:///${imagePath}"`); + if (isPreview) { + let imagePath = `/print/static/${attachmentTpl}/${attachment}`; + body = body.replace(tplImages[i], `src="${imagePath}"`); + } else { + let imagePath = path.join(__dirname, 'template', attachmentTpl, 'image', attachment); + body = body.replace(tplImages[i], `src="file:///${imagePath}"`); + } } cb(null, body); diff --git a/services/mailer/application/template/header/static/image/action.png b/services/print/application/template/footer/image/action.png similarity index 100% rename from services/mailer/application/template/header/static/image/action.png rename to services/print/application/template/footer/image/action.png diff --git a/services/mailer/application/template/header/static/image/facebook.png b/services/print/application/template/footer/image/facebook.png similarity index 100% rename from services/mailer/application/template/header/static/image/facebook.png rename to services/print/application/template/footer/image/facebook.png diff --git a/services/mailer/application/template/header/static/image/info.png b/services/print/application/template/footer/image/info.png similarity index 100% rename from services/mailer/application/template/header/static/image/info.png rename to services/print/application/template/footer/image/info.png diff --git a/services/mailer/application/template/header/static/image/instagram.png b/services/print/application/template/footer/image/instagram.png similarity index 100% rename from services/mailer/application/template/header/static/image/instagram.png rename to services/print/application/template/footer/image/instagram.png diff --git a/services/mailer/application/template/header/static/image/linkedin.png b/services/print/application/template/footer/image/linkedin.png similarity index 100% rename from services/mailer/application/template/header/static/image/linkedin.png rename to services/print/application/template/footer/image/linkedin.png diff --git a/services/mailer/application/template/header/static/image/pinterest.png b/services/print/application/template/footer/image/pinterest.png similarity index 100% rename from services/mailer/application/template/header/static/image/pinterest.png rename to services/print/application/template/footer/image/pinterest.png diff --git a/services/mailer/application/template/header/static/image/twitter.png b/services/print/application/template/footer/image/twitter.png similarity index 100% rename from services/mailer/application/template/header/static/image/twitter.png rename to services/print/application/template/footer/image/twitter.png diff --git a/services/mailer/application/template/header/static/image/youtube.png b/services/print/application/template/footer/image/youtube.png similarity index 100% rename from services/mailer/application/template/header/static/image/youtube.png rename to services/print/application/template/footer/image/youtube.png diff --git a/services/print/application/template/footer/static/image/action.png b/services/print/application/template/footer/static/image/action.png deleted file mode 100644 index 2cd16c453..000000000 Binary files a/services/print/application/template/footer/static/image/action.png and /dev/null differ diff --git a/services/print/application/template/footer/static/image/facebook.png b/services/print/application/template/footer/static/image/facebook.png deleted file mode 100644 index 7ab54c538..000000000 Binary files a/services/print/application/template/footer/static/image/facebook.png and /dev/null differ diff --git a/services/print/application/template/footer/static/image/header.png b/services/print/application/template/footer/static/image/header.png deleted file mode 100644 index 3c063ae44..000000000 Binary files a/services/print/application/template/footer/static/image/header.png and /dev/null differ diff --git a/services/print/application/template/footer/static/image/info.png b/services/print/application/template/footer/static/image/info.png deleted file mode 100644 index fb75cbc4e..000000000 Binary files a/services/print/application/template/footer/static/image/info.png and /dev/null differ diff --git a/services/print/application/template/footer/static/image/instagram.png b/services/print/application/template/footer/static/image/instagram.png deleted file mode 100644 index 66550c4a5..000000000 Binary files a/services/print/application/template/footer/static/image/instagram.png and /dev/null differ diff --git a/services/print/application/template/footer/static/image/linkedin.png b/services/print/application/template/footer/static/image/linkedin.png deleted file mode 100644 index 0d191e5ae..000000000 Binary files a/services/print/application/template/footer/static/image/linkedin.png and /dev/null differ diff --git a/services/print/application/template/footer/static/image/logo.png b/services/print/application/template/footer/static/image/logo.png deleted file mode 100644 index 55e26fec6..000000000 Binary files a/services/print/application/template/footer/static/image/logo.png and /dev/null differ diff --git a/services/print/application/template/footer/static/image/logo.svg b/services/print/application/template/footer/static/image/logo.svg deleted file mode 100644 index 51baf46d3..000000000 --- a/services/print/application/template/footer/static/image/logo.svg +++ /dev/null @@ -1,48 +0,0 @@ - - - \ No newline at end of file diff --git a/services/print/application/template/footer/static/image/pinterest.png b/services/print/application/template/footer/static/image/pinterest.png deleted file mode 100644 index 4d7b28ef8..000000000 Binary files a/services/print/application/template/footer/static/image/pinterest.png and /dev/null differ diff --git a/services/print/application/template/footer/static/image/twitter.png b/services/print/application/template/footer/static/image/twitter.png deleted file mode 100644 index c4a8ab0c1..000000000 Binary files a/services/print/application/template/footer/static/image/twitter.png and /dev/null differ diff --git a/services/print/application/template/footer/static/image/youtube.png b/services/print/application/template/footer/static/image/youtube.png deleted file mode 100644 index 11871deb5..000000000 Binary files a/services/print/application/template/footer/static/image/youtube.png and /dev/null differ diff --git a/services/print/application/template/footer/static/css/style.css b/services/print/application/template/footer/style.css similarity index 89% rename from services/print/application/template/footer/static/css/style.css rename to services/print/application/template/footer/style.css index 8bd10148d..aeddc6f0a 100644 --- a/services/print/application/template/footer/static/css/style.css +++ b/services/print/application/template/footer/style.css @@ -8,6 +8,7 @@ img { max-width: 90%; margin: 0 auto; font-size: 9px; + margin: 30px; color: #555 } diff --git a/services/mailer/application/template/footer/static/image/logo.svg b/services/print/application/template/header/image/logo.svg similarity index 100% rename from services/mailer/application/template/footer/static/image/logo.svg rename to services/print/application/template/header/image/logo.svg diff --git a/services/print/application/template/header/index.html b/services/print/application/template/header/index.html index 30c2a21f1..44e8e52d7 100644 --- a/services/print/application/template/header/index.html +++ b/services/print/application/template/header/index.html @@ -1,5 +1,5 @@
+ {{supplierName}} +
+