WIP: 6367-blankNotification #1903

Draft
pablone wants to merge 11 commits from 6367-blankNotification into dev
14 changed files with 104 additions and 34 deletions
Showing only changes of commit bc1c4e39ab - Show all commits

View File

@ -19,6 +19,7 @@ module.exports = Self => {
}; };
Self.printEmail = async function(ctx, id, templateName) { Self.printEmail = async function(ctx, id, templateName) {
console.log('printEmail');
const {accessToken} = ctx.req; const {accessToken} = ctx.req;
const args = Object.assign({}, ctx.args); const args = Object.assign({}, ctx.args);
const params = {lang: ctx.req.getLocale()}; const params = {lang: ctx.req.getLocale()};

View File

@ -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');
}; };

View File

@ -1,11 +1,10 @@
const Stylesheet = require(`vn-print/core/stylesheet`);
const path = require('path'); const path = require('path');
const vnPrintPath = path.resolve('print'); const vnPrintPath = path.resolve('print');
module.exports = new Stylesheet([ module.exports = [
`${vnPrintPath}/common/css/spacing.css`, `${vnPrintPath}/common/css/email.css`,
`${vnPrintPath}/common/css/misc.css`,
`${vnPrintPath}/common/css/layout.css`, `${vnPrintPath}/common/css/layout.css`,
`${vnPrintPath}/common/css/email.css`]) `${vnPrintPath}/common/css/misc.css`,
.mergeStyles(); `${vnPrintPath}/common/css/report.css`,
`${vnPrintPath}/common/css/spacing.css`,
];

View File

@ -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;

View File

@ -10,8 +10,12 @@ const path = require('path');
const config = require('./config'); const config = require('./config');
class Component { class Component {
constructor(name) { constructor(name, template) {
console.log('cosntructor Component');
console.log('template: ', template);
console.log('name: ', name);
this.name = name; this.name = name;
this._template = template;
} }
get path() { get path() {
@ -19,8 +23,18 @@ class Component {
} }
get template() { get template() {
console.log('this._template: ', this._template);
if (this._template) return this._template;
const templatePath = `${this.path}/${this.name}.html`; const templatePath = `${this.path}/${this.name}.html`;
const fullPath = path.resolve(__dirname, templatePath); 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'); return fs.readFileSync(fullPath, 'utf8');
} }
@ -74,12 +88,21 @@ class Component {
} }
get stylesheet() { get stylesheet() {
const stylePath = path.resolve(__dirname, `${this.path}/assets/css`); let css = [];
if (!fs.existsSync(stylePath)) const path = require('path');
return ''; 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() { get attachments() {
@ -93,17 +116,22 @@ class Component {
} }
build() { build() {
console.log('this.name ', this.name);
console.log('this._template: ', this._template);
const fullPath = path.resolve(__dirname, this.path); const fullPath = path.resolve(__dirname, this.path);
if (!fs.existsSync(fullPath)) if (!fs.existsSync(fullPath))
throw new Error(`Template "${this.name}" not found`); throw new Error(`Template "${this.name}" not found`);
const component = require(`${this.path}/${this.name}`); let component = {};
component.i18n = this.locale; if (this.template !== undefined) {
component.attachments = this.attachments; component = require(`${this.path}/${this.name}`);
console.log('this.stylesheet: ', this.stylesheet);
component.template = juice.inlineContent(this.template, this.stylesheet, { component.template = juice.inlineContent(this.template, this.stylesheet, {
inlinePseudoElements: true inlinePseudoElements: true
}); });
}
component.i18n = this.locale;
component.attachments = this.attachments;
const tplPath = this.path; const tplPath = this.path;
if (!component.computed) component.computed = {}; if (!component.computed) component.computed = {};
component.computed.path = function() { component.computed.path = function() {
@ -134,9 +162,11 @@ class Component {
* @return {Promise} Rendered component * @return {Promise} Rendered component
*/ */
async render() { async render() {
return renderer.renderToString( const render = await renderer.renderToString(
this.component() this.component()
); );
return render;
} }
} }

View File

@ -7,14 +7,16 @@ module.exports = {
}, },
props: { props: {
subject: { subject: {
type: String type: String,
default: 'Subject'
}, },
title: { title: {
type: String, type: String,
required: true default: 'title'
}, },
text: { text: {
type: String type: String,
default: 'text'
} }
} }
}; };

View File

@ -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();

View File

@ -0,0 +1,3 @@
.red{
background-color: red;
}

View File

@ -1,7 +1,7 @@
<email-body v-bind="$props"> <email-body v-bind="$props">
<div class="grid-row"> <div class="grid-row">
<div class="grid-block vn-pa-ml"> <div class="grid-block vn-pa-ml">
<h1>{{ $t('title') }}</h1> <h1 class="red">{{ $t('title') }}</h1>
<p>{{$t('description.dear')}},</p> <p>{{$t('description.dear')}},</p>
<p>{{$t('description.instructions')}}</p> <p>{{$t('description.instructions')}}</p>
<p>{{$t('description.conclusion')}}</p> <p>{{$t('description.conclusion')}}</p>

View File

@ -35,6 +35,7 @@
<div class="line"><span>{{$t('transferAccount') }}</span></div> <div class="line"><span>{{$t('transferAccount') }}</span></div>
</div> </div>
</div> </div>
<h1>pinga</h1>
</p> </p>
</div> </div>
</div> </div>

View File

@ -0,0 +1,3 @@
.div{
background-color: red;
}

View File

@ -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'
}
}
};