From bc1c4e39abfebf41583e7094166a1a49cc191078 Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 21 May 2024 08:53:12 +0200 Subject: [PATCH] feat: refs #6367 add new class --- .../common/methods/vn-model/printService.js | 1 + .../client/incotermsAuthorizationHtml.js | 2 +- .../css/import.js => common/css/index.js} | 13 +++-- print/core/blank-template.js | 19 +++++++ print/core/component.js | 52 +++++++++++++++---- .../blank-template/blank-template.html} | 0 .../blank-template/blank-template.js} | 8 +-- .../{assets/css => }/style.css | 0 .../assets/css/import.js | 11 ---- .../assets/css/style.css | 3 ++ .../incoterms-authorization.html | 2 +- .../letter-debtor-nd/letter-debtor-nd.html | 1 + .../simple-notification/assets/style.css | 3 ++ .../simple-notification.js | 23 ++++++++ 14 files changed, 104 insertions(+), 34 deletions(-) rename print/{templates/email/blank-notification/assets/css/import.js => common/css/index.js} (56%) create mode 100644 print/core/blank-template.js rename print/{templates/email/blank-notification/blank-notification.html => core/components/blank-template/blank-template.html} (100%) rename print/{templates/email/blank-notification/blank-notification.js => core/components/blank-template/blank-template.js} (71%) rename print/templates/email/buyer-week-waste/{assets/css => }/style.css (100%) delete mode 100644 print/templates/email/incoterms-authorization/assets/css/import.js create mode 100644 print/templates/email/incoterms-authorization/assets/css/style.css create mode 100644 print/templates/email/simple-notification/assets/style.css create mode 100755 print/templates/email/simple-notification/simple-notification.js diff --git a/loopback/common/methods/vn-model/printService.js b/loopback/common/methods/vn-model/printService.js index 12a6a67cc..d95073bdc 100644 --- a/loopback/common/methods/vn-model/printService.js +++ b/loopback/common/methods/vn-model/printService.js @@ -19,6 +19,7 @@ module.exports = Self => { }; Self.printEmail = async function(ctx, id, templateName) { + console.log('printEmail'); const {accessToken} = ctx.req; const args = Object.assign({}, ctx.args); const params = {lang: ctx.req.getLocale()}; diff --git a/modules/client/back/methods/client/incotermsAuthorizationHtml.js b/modules/client/back/methods/client/incotermsAuthorizationHtml.js index af585b1ae..024affeb7 100644 --- a/modules/client/back/methods/client/incotermsAuthorizationHtml.js +++ b/modules/client/back/methods/client/incotermsAuthorizationHtml.js @@ -50,5 +50,5 @@ module.exports = Self => { } }); - Self.incotermsAuthorizationHtml = (ctx, id) => Self.printEmail(ctx, id, 'incoterms-authorization'); + Self.incotermsAuthorizationHtml = (ctx, id) => Self.printEmail(ctx, id, 'simple-notification'); }; diff --git a/print/templates/email/blank-notification/assets/css/import.js b/print/common/css/index.js similarity index 56% rename from print/templates/email/blank-notification/assets/css/import.js rename to print/common/css/index.js index 4b4bb7086..867765db6 100644 --- a/print/templates/email/blank-notification/assets/css/import.js +++ b/print/common/css/index.js @@ -1,11 +1,10 @@ -const Stylesheet = require(`vn-print/core/stylesheet`); - const path = require('path'); const vnPrintPath = path.resolve('print'); -module.exports = new Stylesheet([ - `${vnPrintPath}/common/css/spacing.css`, - `${vnPrintPath}/common/css/misc.css`, +module.exports = [ + `${vnPrintPath}/common/css/email.css`, `${vnPrintPath}/common/css/layout.css`, - `${vnPrintPath}/common/css/email.css`]) - .mergeStyles(); + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/report.css`, + `${vnPrintPath}/common/css/spacing.css`, +]; diff --git a/print/core/blank-template.js b/print/core/blank-template.js new file mode 100644 index 000000000..0809fc268 --- /dev/null +++ b/print/core/blank-template.js @@ -0,0 +1,19 @@ +const Component = require(`vn-print/core/component`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +const blankTemplate = new Component(`blank-template`); +class Template { + constructor() { + this._template = `${vnPrintPath}/core/components/blank-template/blank-template.html`; + } + build(ass) { + console.log('ass: ', ass); + console.log('Building blank notification'); + console.log('this._template: ', this._template); + blankTemplate.build(this._template); + } +} + +module.exports = Template; diff --git a/print/core/component.js b/print/core/component.js index 0a8095483..bb2d064c3 100644 --- a/print/core/component.js +++ b/print/core/component.js @@ -10,8 +10,12 @@ const path = require('path'); const config = require('./config'); class Component { - constructor(name) { + constructor(name, template) { + console.log('cosntructor Component'); + console.log('template: ', template); + console.log('name: ', name); this.name = name; + this._template = template; } get path() { @@ -19,8 +23,18 @@ class Component { } get template() { + console.log('this._template: ', this._template); + if (this._template) return this._template; const templatePath = `${this.path}/${this.name}.html`; const fullPath = path.resolve(__dirname, templatePath); + console.log('fullPath: ', fullPath); + + if (!fs.existsSync(fullPath)) { + const path = require('path'); + const vnPrintPath = path.resolve('print'); + + return fs.readFileSync(`${vnPrintPath}/core/components/blank-template/blank-template.html`, 'utf8'); + } return fs.readFileSync(fullPath, 'utf8'); } @@ -74,12 +88,21 @@ class Component { } get stylesheet() { - const stylePath = path.resolve(__dirname, `${this.path}/assets/css`); + let css = []; - if (!fs.existsSync(stylePath)) - return ''; + const path = require('path'); + const vnPrintPath = path.resolve('print'); - return require(`${stylePath}/import`); + const styles = require(`${vnPrintPath}/common/css/index.js`); + + for (const style of styles) + css.push(fs.readFileSync(style)); + + const style = `${path.resolve(__dirname, this.path)}/assets/css/style.css`; // regex to match css files + + if (fs.existsSync(style)) css.push(fs.readFileSync(style)); + + return css.join('\n'); } get attachments() { @@ -93,17 +116,22 @@ class Component { } build() { + console.log('this.name ', this.name); + console.log('this._template: ', this._template); const fullPath = path.resolve(__dirname, this.path); if (!fs.existsSync(fullPath)) throw new Error(`Template "${this.name}" not found`); - const component = require(`${this.path}/${this.name}`); + let component = {}; + if (this.template !== undefined) { + component = require(`${this.path}/${this.name}`); + component.template = juice.inlineContent(this.template, this.stylesheet, { + inlinePseudoElements: true + }); + } + component.i18n = this.locale; component.attachments = this.attachments; - console.log('this.stylesheet: ', this.stylesheet); - component.template = juice.inlineContent(this.template, this.stylesheet, { - inlinePseudoElements: true - }); const tplPath = this.path; if (!component.computed) component.computed = {}; component.computed.path = function() { @@ -134,9 +162,11 @@ class Component { * @return {Promise} Rendered component */ async render() { - return renderer.renderToString( + const render = await renderer.renderToString( this.component() ); + + return render; } } diff --git a/print/templates/email/blank-notification/blank-notification.html b/print/core/components/blank-template/blank-template.html similarity index 100% rename from print/templates/email/blank-notification/blank-notification.html rename to print/core/components/blank-template/blank-template.html diff --git a/print/templates/email/blank-notification/blank-notification.js b/print/core/components/blank-template/blank-template.js similarity index 71% rename from print/templates/email/blank-notification/blank-notification.js rename to print/core/components/blank-template/blank-template.js index 9ceb742ea..9fe1c3871 100755 --- a/print/templates/email/blank-notification/blank-notification.js +++ b/print/core/components/blank-template/blank-template.js @@ -7,14 +7,16 @@ module.exports = { }, props: { subject: { - type: String + type: String, + default: 'Subject' }, title: { type: String, - required: true + default: 'title' }, text: { - type: String + type: String, + default: 'text' } } }; diff --git a/print/templates/email/buyer-week-waste/assets/css/style.css b/print/templates/email/buyer-week-waste/style.css similarity index 100% rename from print/templates/email/buyer-week-waste/assets/css/style.css rename to print/templates/email/buyer-week-waste/style.css diff --git a/print/templates/email/incoterms-authorization/assets/css/import.js b/print/templates/email/incoterms-authorization/assets/css/import.js deleted file mode 100644 index 4b4bb7086..000000000 --- a/print/templates/email/incoterms-authorization/assets/css/import.js +++ /dev/null @@ -1,11 +0,0 @@ -const Stylesheet = require(`vn-print/core/stylesheet`); - -const path = require('path'); -const vnPrintPath = path.resolve('print'); - -module.exports = new Stylesheet([ - `${vnPrintPath}/common/css/spacing.css`, - `${vnPrintPath}/common/css/misc.css`, - `${vnPrintPath}/common/css/layout.css`, - `${vnPrintPath}/common/css/email.css`]) - .mergeStyles(); diff --git a/print/templates/email/incoterms-authorization/assets/css/style.css b/print/templates/email/incoterms-authorization/assets/css/style.css new file mode 100644 index 000000000..542c8b197 --- /dev/null +++ b/print/templates/email/incoterms-authorization/assets/css/style.css @@ -0,0 +1,3 @@ +.red{ + background-color: red; +} \ No newline at end of file diff --git a/print/templates/email/incoterms-authorization/incoterms-authorization.html b/print/templates/email/incoterms-authorization/incoterms-authorization.html index 98d2b333c..dd91b04e9 100644 --- a/print/templates/email/incoterms-authorization/incoterms-authorization.html +++ b/print/templates/email/incoterms-authorization/incoterms-authorization.html @@ -1,7 +1,7 @@
-

{{ $t('title') }}

+

{{ $t('title') }}

{{$t('description.dear')}},

{{$t('description.instructions')}}

{{$t('description.conclusion')}}

diff --git a/print/templates/email/letter-debtor-nd/letter-debtor-nd.html b/print/templates/email/letter-debtor-nd/letter-debtor-nd.html index 01bab7939..d949f9f9c 100644 --- a/print/templates/email/letter-debtor-nd/letter-debtor-nd.html +++ b/print/templates/email/letter-debtor-nd/letter-debtor-nd.html @@ -35,6 +35,7 @@
{{$t('transferAccount') }}
+

pinga

diff --git a/print/templates/email/simple-notification/assets/style.css b/print/templates/email/simple-notification/assets/style.css new file mode 100644 index 000000000..1db921897 --- /dev/null +++ b/print/templates/email/simple-notification/assets/style.css @@ -0,0 +1,3 @@ +.div{ + background-color: red; +} \ No newline at end of file diff --git a/print/templates/email/simple-notification/simple-notification.js b/print/templates/email/simple-notification/simple-notification.js new file mode 100755 index 000000000..7edbe2df8 --- /dev/null +++ b/print/templates/email/simple-notification/simple-notification.js @@ -0,0 +1,23 @@ +const Template = require('vn-print/core/blank-template'); +const blankTemplate = new Template('blank-template'); + +module.exports = { + name: 'blank-notification', + components: { + 'email-body': blankTemplate.build() + }, + props: { + subject: { + type: String, + default: 'Subject' + }, + title: { + type: String, + default: 'title' + }, + text: { + type: String, + default: 'text' + } + } +};