WIP: 6367-blankNotification #1903
|
@ -17,14 +17,13 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.send = async options => {
|
Self.send = async options => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const findStatus = 'pending';
|
|
||||||
|
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const notificationQueue = await models.NotificationQueue.find({
|
const notificationQueue = await models.NotificationQueue.find({
|
||||||
where: {status: findStatus},
|
where: {status: 'pending'},
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
relation: 'notification',
|
relation: 'notification',
|
||||||
|
@ -41,19 +40,17 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}]
|
||||||
]
|
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const statusSent = 'sent';
|
const statusSent = 'sent';
|
||||||
const statusError = 'error';
|
|
||||||
|
|
||||||
for (const queue of notificationQueue) {
|
for (const queue of notificationQueue) {
|
||||||
const queueName = queue.notification().name;
|
const queueName = queue.notification().notificationTemplate().code;
|
||||||
const queueParams = JSON.parse(queue.params);
|
const queueParams = JSON.parse(queue.params);
|
||||||
|
|
||||||
for (const notificationUser of queue.notification().subscription()) {
|
for (const notificationUser of queue.notification().subscription()) {
|
||||||
|
@ -76,7 +73,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
await queue.updateAttribute('status', statusSent);
|
await queue.updateAttribute('status', statusSent);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await queue.updateAttribute('status', statusError);
|
await queue.updateAttribute('status', 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()};
|
||||||
|
|
|
@ -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');
|
||||||
};
|
};
|
||||||
|
|
|
@ -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`,
|
||||||
|
];
|
|
@ -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;
|
|
@ -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,13 +88,21 @@ class Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
get stylesheet() {
|
get stylesheet() {
|
||||||
let mergedStyles = '';
|
let css = [];
|
||||||
const stylePath = path.resolve(__dirname, `${this.path}/assets/css`);
|
|
||||||
|
|
||||||
if (!fs.existsSync(stylePath))
|
const path = require('path');
|
||||||
return mergedStyles;
|
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() {
|
||||||
|
@ -94,16 +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}`);
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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>
|
|
@ -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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -77,7 +77,6 @@ class Email extends Component {
|
||||||
for (let attachment of options.attachments)
|
for (let attachment of options.attachments)
|
||||||
attachments.push(attachment);
|
attachments.push(attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
const localeSubject = await this.getSubject();
|
const localeSubject = await this.getSubject();
|
||||||
const mailOptions = {
|
const mailOptions = {
|
||||||
to: this.args.recipient,
|
to: this.args.recipient,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
class Stylesheet {
|
class Stylesheet {
|
||||||
constructor(files) {
|
constructor(files) {
|
||||||
|
@ -8,9 +7,8 @@ class Stylesheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
mergeStyles() {
|
mergeStyles() {
|
||||||
for (const file of this.files) {
|
for (const file of this.files)
|
||||||
this.css.push(fs.readFileSync(file));
|
this.css.push(fs.readFileSync(file));
|
||||||
}
|
|
||||||
|
|
||||||
return this.css.join('\n');
|
return this.css.join('\n');
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
.red{
|
||||||
|
background-color: red;
|
||||||
|
}
|
|
@ -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>
|
||||||
|
|
|
@ -7,6 +7,7 @@ module.exports = new Stylesheet([
|
||||||
`${vnPrintPath}/common/css/spacing.css`,
|
`${vnPrintPath}/common/css/spacing.css`,
|
||||||
`${vnPrintPath}/common/css/misc.css`,
|
`${vnPrintPath}/common/css/misc.css`,
|
||||||
`${vnPrintPath}/common/css/layout.css`,
|
`${vnPrintPath}/common/css/layout.css`,
|
||||||
`${vnPrintPath}/common/css/email.css`])
|
`${vnPrintPath}/common/css/email.css`,
|
||||||
|
`${__dirname}/style.css`])
|
||||||
.mergeStyles();
|
.mergeStyles();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
.claseTest{
|
||||||
|
color: red;
|
||||||
|
}
|
|
@ -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>
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
.div{
|
||||||
|
background-color: red;
|
||||||
|
}
|
|
@ -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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue