WIP: 6367-blankNotification #1903

Draft
pablone wants to merge 11 commits from 6367-blankNotification into dev
18 changed files with 140 additions and 33 deletions

View File

@ -17,14 +17,13 @@ module.exports = Self => {
Self.send = async options => {
const models = Self.app.models;
const findStatus = 'pending';
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const notificationQueue = await models.NotificationQueue.find({
where: {status: findStatus},
where: {status: 'pending'},
include: [
{
relation: 'notification',
@ -41,19 +40,17 @@ module.exports = Self => {
}
}
}
}
},
}
}
}
]
}]
}, myOptions);
const statusSent = 'sent';
const statusError = 'error';
for (const queue of notificationQueue) {
const queueName = queue.notification().name;
const queueName = queue.notification().notificationTemplate().code;
const queueParams = JSON.parse(queue.params);
for (const notificationUser of queue.notification().subscription()) {
@ -76,7 +73,7 @@ module.exports = Self => {
await queue.updateAttribute('status', statusSent);
} catch (error) {
await queue.updateAttribute('status', statusError);
await queue.updateAttribute('status', 'error');
}
}
}

View File

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

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 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`,
];

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');
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,13 +88,21 @@ class Component {
}
get stylesheet() {
let mergedStyles = '';
const stylePath = path.resolve(__dirname, `${this.path}/assets/css`);
let css = [];
if (!fs.existsSync(stylePath))
return mergedStyles;
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() {
@ -94,16 +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;
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;
}
}

View File

@ -0,0 +1,8 @@
<email-body v-bind="$props">
<div class="grid-row">
<div class="grid-block vn-pa-ml">
<h1 v-html="title" align="center"></h1>
<p v-html="text"></p>
</div>
</div>
</email-body>

View File

@ -0,0 +1,22 @@
const Component = require(`vn-print/core/component`);
const emailBody = new Component('email-body');
module.exports = {
name: 'blank-notification',
components: {
'email-body': emailBody.build()
},
props: {
subject: {
type: String,
default: 'Subject'
},
title: {
type: String,
default: 'title'
},
text: {
type: String,
default: 'text'
}
}
};

View File

@ -77,7 +77,6 @@ class Email extends Component {
for (let attachment of options.attachments)
attachments.push(attachment);
}
const localeSubject = await this.getSubject();
const mailOptions = {
to: this.args.recipient,

View File

@ -1,5 +1,4 @@
const fs = require('fs-extra');
const path = require('path');
class Stylesheet {
constructor(files) {
@ -8,9 +7,8 @@ class Stylesheet {
}
mergeStyles() {
for (const file of this.files) {
for (const file of this.files)
this.css.push(fs.readFileSync(file));
}
return this.css.join('\n');
}

View File

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

View File

@ -1,7 +1,7 @@
<email-body v-bind="$props">
<div class="grid-row">
<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.instructions')}}</p>
<p>{{$t('description.conclusion')}}</p>

View File

@ -7,6 +7,7 @@ module.exports = new Stylesheet([
`${vnPrintPath}/common/css/spacing.css`,
`${vnPrintPath}/common/css/misc.css`,
`${vnPrintPath}/common/css/layout.css`,
`${vnPrintPath}/common/css/email.css`])
`${vnPrintPath}/common/css/email.css`,
`${__dirname}/style.css`])
.mergeStyles();

View File

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

View File

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