This commit is contained in:
Gerard 2019-01-23 11:17:35 +01:00
commit e6213fb83f
21 changed files with 115 additions and 103 deletions

1
.gitignore vendored
View File

@ -3,4 +3,5 @@ dist/*
npm-debug.log npm-debug.log
.eslintcache .eslintcache
datasources.*.json datasources.*.json
print.*.json
db.json db.json

View File

@ -6,6 +6,7 @@ RUN apt-get update \
curl \ curl \
ca-certificates \ ca-certificates \
gnupg2 \ gnupg2 \
libfontconfig \
&& curl -sL https://deb.nodesource.com/setup_8.x | bash - \ && curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& apt-get install -y --no-install-recommends \ && apt-get install -y --no-install-recommends \
nodejs \ nodejs \

View File

@ -11,7 +11,8 @@
<vn-card> <vn-card>
<vn-vertical> <vn-vertical>
<vn-horizontal class="catalog-header" pad-medium-h> <vn-horizontal class="catalog-header" pad-medium-h>
<vn-one><!-- {{model.data.length || 0}} <span translate>results</span> --></vn-one> <vn-one ng-if="model.moreRows">
<span translate>More than</span> {{model.limit}} <span translate>results</span></vn-one>
<vn-one> <vn-one>
<vn-horizontal> <vn-horizontal>
<vn-autocomplete vn-id="field" vn-one <vn-autocomplete vn-id="field" vn-one

View File

@ -39,12 +39,13 @@ class Controller {
return order.field == itemTag.tagFk; return order.field == itemTag.tagFk;
}); });
if (!alreadyAdded) if (!alreadyAdded) {
this.fieldList.push({ this.fieldList.push({
name: itemTag.name, name: itemTag.name,
field: itemTag.tagFk, field: itemTag.tagFk,
isTag: true isTag: true
}); });
}
}); });
}); });
} }

View File

@ -2,6 +2,7 @@ Address: Consignatario
Catalog: Catálogo Catalog: Catálogo
from: desde from: desde
results: resultados results: resultados
More than: Más de
No results: Sin resultados No results: Sin resultados
Enter a new search: Introduce una nueva búsqueda Enter a new search: Introduce una nueva búsqueda
Plant: Planta Plant: Planta

53
package-lock.json generated
View File

@ -4019,7 +4019,7 @@
"dot-prop": { "dot-prop": {
"version": "4.2.0", "version": "4.2.0",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-4.2.0.tgz",
"integrity": "sha512-tUMXrxlExSW6U2EXiiKGSBVdYgtV8qlHL+C10TsW4PURY/ic+eaysnSkwB4kA/mBlCyy/IKDJ+Lc3wbWeaXtuQ==", "integrity": "sha1-HxngwuGqDjJ5fEl5nyg3rGr2nFc=",
"dev": true, "dev": true,
"requires": { "requires": {
"is-obj": "^1.0.0" "is-obj": "^1.0.0"
@ -4192,7 +4192,7 @@
}, },
"jsonfile": { "jsonfile": {
"version": "2.4.0", "version": "2.4.0",
"resolved": "http://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz",
"integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=",
"dev": true, "dev": true,
"requires": { "requires": {
@ -5517,7 +5517,8 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
@ -5538,12 +5539,14 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -5558,17 +5561,20 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -5685,7 +5691,8 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -5697,6 +5704,7 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -5711,6 +5719,7 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -5718,12 +5727,14 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.2.4", "version": "2.2.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.1", "safe-buffer": "^5.1.1",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -5742,6 +5753,7 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
@ -5822,7 +5834,8 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -5834,6 +5847,7 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -5919,7 +5933,8 @@
"safe-buffer": { "safe-buffer": {
"version": "5.1.1", "version": "5.1.1",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
@ -5955,6 +5970,7 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
@ -5974,6 +5990,7 @@
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
@ -6017,12 +6034,14 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.2", "version": "3.0.2",
"bundled": true, "bundled": true,
"dev": true "dev": true,
"optional": true
} }
} }
}, },
@ -8160,7 +8179,7 @@
"karma-chrome-launcher": { "karma-chrome-launcher": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-2.2.0.tgz", "resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-2.2.0.tgz",
"integrity": "sha512-uf/ZVpAabDBPvdPdveyk1EPgbnloPvFFGgmRhYLTDH7gEB4nZdSBk8yTU47w1g/drLSx5uMOkjKk7IWKfWg/+w==", "integrity": "sha1-zxudBxNswY/iOTJ9JGVMPbw2is8=",
"dev": true, "dev": true,
"requires": { "requires": {
"fs-access": "^1.0.0", "fs-access": "^1.0.0",
@ -14271,7 +14290,7 @@
"split2": { "split2": {
"version": "2.2.0", "version": "2.2.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-2.2.0.tgz", "resolved": "https://registry.npmjs.org/split2/-/split2-2.2.0.tgz",
"integrity": "sha512-RAb22TG39LhI31MbreBgIuKiIKhVsawfTgEGqKHTK87aG+ul/PB8Sqoi3I7kVdRWiCfrKxK3uo4/YUkpNvhPbw==", "integrity": "sha1-GGsldbz4PoW30YRldWI47k7kJJM=",
"dev": true, "dev": true,
"requires": { "requires": {
"through2": "^2.0.2" "through2": "^2.0.2"
@ -15303,7 +15322,7 @@
"touch": { "touch": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz", "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz",
"integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==", "integrity": "sha1-/jZfX3XsntTlaCXgu3bSSrdK+Ds=",
"dev": true, "dev": true,
"requires": { "requires": {
"nopt": "~1.0.10" "nopt": "~1.0.10"
@ -16925,7 +16944,7 @@
"write-file-atomic": { "write-file-atomic": {
"version": "2.3.0", "version": "2.3.0",
"resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.3.0.tgz", "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.3.0.tgz",
"integrity": "sha512-xuPeK4OdjWqtfi59ylvVL0Yn35SF3zgcAcv7rBPFHVaEapaDr4GdGgm3j7ckTwH9wHL7fGmgfAnb0+THrHb8tA==", "integrity": "sha1-H/YVdcLipOjlENb6TiQ8zhg5mas=",
"dev": true, "dev": true,
"requires": { "requires": {
"graceful-fs": "^4.1.11", "graceful-fs": "^4.1.11",

View File

@ -4,6 +4,7 @@ let env = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
let configPath = `/etc/salix`; let configPath = `/etc/salix`;
let config = require('../config/print.json'); let config = require('../config/print.json');
let configFiles = [ let configFiles = [
`${appPath}/config/print.${env}.json`,
`${configPath}/print.json`, `${configPath}/print.json`,
`${configPath}/print.${env}.json` `${configPath}/print.${env}.json`
]; ];
@ -28,5 +29,4 @@ for (let proxyFile of proxyFiles) {
// config.proxy = proxyConf; // config.proxy = proxyConf;
config.env = env; config.env = env;
module.exports = config; module.exports = config;

View File

@ -47,9 +47,10 @@ module.exports = {
* @param {Object} ctx - Request context * @param {Object} ctx - Request context
*/ */
async preFetch(component, ctx) { async preFetch(component, ctx) {
const preFetchData = {attachments: []}; let mergedData = {attachments: []};
let params = {}; let asyncData = {};
let data = {}; let data = {};
let params = {};
if (Object.keys(ctx.body).length > 0) if (Object.keys(ctx.body).length > 0)
params = ctx.body; params = ctx.body;
@ -63,36 +64,34 @@ module.exports = {
data = component.data(); data = component.data();
if (component.hasOwnProperty('asyncData')) { if (component.hasOwnProperty('asyncData')) {
const asyncData = await component.asyncData(ctx, params); asyncData = await component.asyncData(ctx, params);
if (asyncData.locale) { if (asyncData.locale) {
const locale = component.i18n.messages[asyncData.locale]; const locale = component.i18n.messages[asyncData.locale];
preFetchData.subject = locale.subject; mergedData.subject = locale.subject;
} }
if (asyncData.recipient)
preFetchData.recipient = asyncData.recipient;
const mergedData = {...data, ...asyncData};
component.data = function data() {
return mergedData;
};
} }
if (data && data.hasOwnProperty('attachments')) { mergedData = Object.assign(mergedData, data, asyncData);
const fileNames = data.attachments;
fileNames.forEach(attachment => { component.data = function data() {
return mergedData;
};
if (data.hasOwnProperty('files')) {
const files = data.files;
files.forEach(file => {
const componentPath = `${this.path}/${component.name}`; const componentPath = `${this.path}/${component.name}`;
let fileSrc = componentPath + attachment; let fileSrc = componentPath + file;
if (attachment.slice(0, 4) === 'http' || attachment.slice(0, 4) === 'https') if (file.slice(0, 4) === 'http' || file.slice(0, 4) === 'https')
fileSrc = attachment; fileSrc = file;
const fileName = attachment.split('/').pop(); const fileName = file.split('/').pop();
preFetchData.attachments.push({ mergedData.attachments.push({
filename: fileName, filename: fileName,
path: fileSrc, path: fileSrc,
cid: attachment, cid: file,
}); });
}); });
} }
@ -108,14 +107,14 @@ module.exports = {
return Promise.all(promises).then(results => { return Promise.all(promises).then(results => {
results.forEach(result => { results.forEach(result => {
result.attachments.forEach(atth => { result.attachments.forEach(atth => {
preFetchData.attachments.push(atth); mergedData.attachments.push(atth);
}); });
}); });
return preFetchData; return mergedData;
}); });
} }
return preFetchData; return mergedData;
}, },
async attachAssets(component) { async attachAssets(component) {

View File

@ -1,21 +0,0 @@
module.exports = app => {
process.on('uncaughtException', err => {
console.error(`Caught exception: ${err}`);
});
process.on('warning', () => {
console.error(`My warning err`);
});
app.use(function(error, request, response, next) {
if (!error.httpStatusCode)
return next(error);
response.status(error.httpStatusCode);
response.json({
httpStatusCode: error.httpStatusCode,
name: error.name,
message: error.message,
});
});
};

View File

@ -43,21 +43,29 @@ module.exports = {
* @param {Object} ctx - Request context * @param {Object} ctx - Request context
*/ */
async preFetch(component, ctx) { async preFetch(component, ctx) {
let mergedData = {};
let asyncData = {};
let data = {}; let data = {};
if (Object.keys(ctx.body).length > 0)
params = ctx.body;
if (Object.keys(ctx.query).length > 0)
params = ctx.query;
await this.attachAssets(component); await this.attachAssets(component);
if (component.hasOwnProperty('data')) if (component.hasOwnProperty('data'))
data = component.data(); data = component.data();
if (component.hasOwnProperty('asyncData')) { if (component.hasOwnProperty('asyncData'))
const fetch = await component.asyncData(ctx, ctx.body); asyncData = await component.asyncData(ctx, params);
const mergedData = {...data, ...fetch};
component.data = function data() { mergedData = Object.assign(mergedData, data, asyncData);
return mergedData;
}; component.data = function data() {
} return mergedData;
};
if (component.components) { if (component.components) {
const components = component.components; const components = component.components;

View File

@ -4,7 +4,6 @@ const UserException = require(`${appPath}/lib/exceptions/userException`);
module.exports = { module.exports = {
name: 'delivery-note', name: 'delivery-note',
async asyncData(ctx, params) { async asyncData(ctx, params) {
console.log(params);
const promises = []; const promises = [];
const dataIndex = promises.push(this.methods.fetchData()) - 1; const dataIndex = promises.push(this.methods.fetchData()) - 1;
const itemsIndex = promises.push(this.methods.fetchItems()) - 1; const itemsIndex = promises.push(this.methods.fetchItems()) - 1;

View File

@ -1,21 +1,21 @@
module.exports = { module.exports = {
name: 'email-footer', name: 'email-footer',
asyncData(ctx, params) { asyncData(ctx) {
return { return {
isPreview: ctx.method === 'GET', isPreview: ctx.method === 'GET',
}; };
}, },
created() { created() {
const embeded = []; const embeded = [];
this.attachments.map((attachment) => { this.files.map(file => {
const src = this.isPreview ? attachment : `cid:${attachment}`; const src = this.isPreview ? file : `cid:${file}`;
embeded[attachment] = src; embeded[file] = src;
}); });
this.embeded = embeded; this.embeded = embeded;
}, },
data() { data() {
return { return {
attachments: [ files: [
'/assets/images/facebook.png', '/assets/images/facebook.png',
'/assets/images/twitter.png', '/assets/images/twitter.png',
'/assets/images/youtube.png', '/assets/images/youtube.png',

View File

@ -1,22 +1,22 @@
module.exports = { module.exports = {
name: 'email-header', name: 'email-header',
asyncData(ctx, params) { asyncData(ctx) {
return { return {
isPreview: ctx.method === 'GET', isPreview: ctx.method === 'GET',
}; };
}, },
created() { created() {
const embeded = []; const embeded = [];
this.attachments.map((attachment) => { this.files.map(file => {
const src = this.isPreview ? attachment : `cid:${attachment}`; const src = this.isPreview ? file : `cid:${file}`;
embeded[attachment] = src; embeded[file] = src;
}); });
this.embeded = embeded; this.embeded = embeded;
}, },
data() { data() {
return { return {
attachments: ['/assets/images/logo.png'], files: ['/assets/images/logo.png'],
}; };
}, },
}; };

View File

@ -13,6 +13,9 @@ module.exports = {
if (!params.clientFk) if (!params.clientFk)
throw new UserException('No client id specified'); throw new UserException('No client id specified');
if (!params.companyFk)
throw new UserException('No company id specified');
return this.methods.fetchClientData(params.clientFk, params.companyFk) return this.methods.fetchClientData(params.clientFk, params.companyFk)
.then(([result]) => { .then(([result]) => {
return Object.assign(data, result[0]); return Object.assign(data, result[0]);

View File

@ -1,11 +1,14 @@
const database = require(`${appPath}/lib/database`); const database = require(`${appPath}/lib/database`);
const reportEngine = require(`${appPath}/lib/reportEngine.js`);
const emailHeader = require('../email-header'); const emailHeader = require('../email-header');
const emailFooter = require('../email-footer'); const emailFooter = require('../email-footer');
const UserException = require(`${appPath}/lib/exceptions/userException`); const UserException = require(`${appPath}/lib/exceptions/userException`);
module.exports = { module.exports = {
name: 'letter-debtor-st', name: 'letter-debtor-st',
async asyncData(ctx, params) { async asyncData(ctx, params) {
const promises = [];
const data = { const data = {
isPreview: ctx.method === 'GET', isPreview: ctx.method === 'GET',
}; };
@ -16,23 +19,24 @@ module.exports = {
if (!params.companyFk) if (!params.companyFk)
throw new UserException('No company id specified'); throw new UserException('No company id specified');
return this.methods.fetchClientData(params.clientFk, params.companyFk) promises.push(reportEngine.toPdf('delivery-note', ctx));
.then(([[result]]) => { promises.push(this.methods.fetchClient(params.clientFk, params.companyFk));
if (!result) throw new UserException('Client data not found');
return Object.assign(data, result); return Promise.all(promises).then(result => {
}); const stream = result[0];
const [[client]] = result[1];
Object.assign(data, client);
Object.assign(data, {attachments: [{filename: 'delivery-note.pdf', content: stream}]});
return data;
});
}, },
created() { created() {
this.$i18n.locale = this.locale; this.$i18n.locale = this.locale;
}, },
data() {
return {
attachments: ['http://localhost:5000/report/delivery-note'],
};
},
methods: { methods: {
fetchClientData(clientFk, companyFk) { fetchClient(clientFk, companyFk) {
return database.pool.query(` return database.pool.query(`
SELECT SELECT
u.lang locale, u.lang locale,
@ -47,7 +51,7 @@ module.exports = {
JOIN bankEntity be ON be.id = sa.bankEntityFk JOIN bankEntity be ON be.id = sa.bankEntityFk
JOIN account.user u ON u.id = c.id JOIN account.user u ON u.id = c.id
WHERE c.id = ? AND cny.id = ?`, [clientFk, companyFk]); WHERE c.id = ? AND cny.id = ?`, [clientFk, companyFk]);
}, }
}, },
computed: { computed: {
accountAddress: function() { accountAddress: function() {

View File

@ -23,7 +23,7 @@ module.exports = {
}, },
data() { data() {
return { return {
attachments: ['/assets/files/model.ezp'], files: ['/assets/files/model.ezp'],
}; };
}, },
methods: { methods: {

View File

@ -1,18 +1,14 @@
const database = require('./lib/database');
const smtp = require('./lib/smtp');
module.exports = app => { module.exports = app => {
global.appPath = __dirname; global.appPath = __dirname;
process.env.OPENSSL_CONF = '/etc/ssl/'; process.env.OPENSSL_CONF = '/etc/ssl/';
// Init database instance // Init database instance
database.init(); require('./lib/database').init();
// Init SMTP Instance // Init SMTP Instance
smtp.init(); require('./lib/smtp').init();
require('./lib/router')(app); require('./lib/router')(app);
// require('./lib/errorHandler')(app);
}; };