diff --git a/client/auth/src/auth.js b/client/auth/src/auth.js index 703c81193..8b7c022dd 100644 --- a/client/auth/src/auth.js +++ b/client/auth/src/auth.js @@ -1,3 +1,3 @@ import './ngModule'; import './config'; -import './login/index'; +import './login/login'; diff --git a/client/auth/src/login/index.html b/client/auth/src/login/login.html old mode 100755 new mode 100644 similarity index 100% rename from client/auth/src/login/index.html rename to client/auth/src/login/login.html diff --git a/client/auth/src/login/index.js b/client/auth/src/login/login.js similarity index 98% rename from client/auth/src/login/index.js rename to client/auth/src/login/login.js index 7c7447d73..229c1a345 100644 --- a/client/auth/src/login/index.js +++ b/client/auth/src/login/login.js @@ -76,6 +76,6 @@ export default class Controller { Controller.$inject = ['$element', '$scope', '$window', '$http']; ngModule.component('vnLogin', { - template: require('./index.html'), + template: require('./login.html'), controller: Controller }); diff --git a/client/client/routes.json b/client/client/routes.json index 91eae4c98..bd49efb49 100644 --- a/client/client/routes.json +++ b/client/client/routes.json @@ -1,5 +1,7 @@ { "module": "client", + "name": "Clients", + "icon": "person", "routes": [ { "url": "/clients", diff --git a/client/client/src/address-create/index.html b/client/client/src/address-create/address-create.html similarity index 100% rename from client/client/src/address-create/index.html rename to client/client/src/address-create/address-create.html diff --git a/client/client/src/address-create/index.js b/client/client/src/address-create/address-create.js similarity index 92% rename from client/client/src/address-create/index.js rename to client/client/src/address-create/address-create.js index 7626ea5a8..8e23af6ea 100644 --- a/client/client/src/address-create/index.js +++ b/client/client/src/address-create/address-create.js @@ -19,7 +19,7 @@ Controller.$inject = ['$scope', '$state']; export const NAME = 'vnAddressCreate'; export const COMPONENT = { - template: require('./index.html'), + template: require('./address-create.html'), controller: Controller }; module.component(NAME, COMPONENT); diff --git a/client/client/src/address-edit/index.html b/client/client/src/address-edit/address-edit.html similarity index 100% rename from client/client/src/address-edit/index.html rename to client/client/src/address-edit/address-edit.html diff --git a/client/client/src/address-edit/index.js b/client/client/src/address-edit/address-edit.js similarity index 88% rename from client/client/src/address-edit/index.js rename to client/client/src/address-edit/address-edit.js index 70f609d2d..1e4fdb600 100644 --- a/client/client/src/address-edit/index.js +++ b/client/client/src/address-edit/address-edit.js @@ -11,7 +11,7 @@ Controller.$inject = ['$stateParams']; export const NAME = 'vnAddressEdit'; export const COMPONENT = { - template: require('./index.html'), + template: require('./address-edit.html'), controllerAs: 'addressData', controller: Controller }; diff --git a/client/client/src/addresses/index.html b/client/client/src/addresses/addresses.html similarity index 100% rename from client/client/src/addresses/index.html rename to client/client/src/addresses/addresses.html diff --git a/client/client/src/addresses/index.js b/client/client/src/addresses/addresses.js similarity index 73% rename from client/client/src/addresses/index.js rename to client/client/src/addresses/addresses.js index 0c0dc0846..be0e6f398 100644 --- a/client/client/src/addresses/index.js +++ b/client/client/src/addresses/addresses.js @@ -1,6 +1,6 @@ import {module} from '../module'; export const component = { - template: require('./index.html') + template: require('./addresses.html') }; module.component('vnClientAddresses', component); diff --git a/client/client/src/basic-data/index.html b/client/client/src/basic-data/basic-data.html similarity index 100% rename from client/client/src/basic-data/index.html rename to client/client/src/basic-data/basic-data.html diff --git a/client/client/src/basic-data/index.js b/client/client/src/basic-data/basic-data.js similarity index 78% rename from client/client/src/basic-data/index.js rename to client/client/src/basic-data/basic-data.js index 2e3dececc..de05dd81a 100644 --- a/client/client/src/basic-data/index.js +++ b/client/client/src/basic-data/basic-data.js @@ -1,7 +1,7 @@ import {module} from '../module'; export const component = { - template: require('./index.html'), + template: require('./basic-data.html'), bindings: { client: '<' } diff --git a/client/client/src/billing-data/index.html b/client/client/src/billing-data/billing-data.html similarity index 77% rename from client/client/src/billing-data/index.html rename to client/client/src/billing-data/billing-data.html index a001ba49e..74180d36e 100644 --- a/client/client/src/billing-data/index.html +++ b/client/client/src/billing-data/billing-data.html @@ -5,7 +5,7 @@ form="form" save="put"> -
+ Información de facturación @@ -40,4 +40,18 @@ - \ No newline at end of file + + + + + Changed terms + Notify customer? + + + + + + + \ No newline at end of file diff --git a/client/client/src/billing-data/billing-data.js b/client/client/src/billing-data/billing-data.js new file mode 100644 index 000000000..1824a6091 --- /dev/null +++ b/client/client/src/billing-data/billing-data.js @@ -0,0 +1,63 @@ +import {module} from '../module'; + +export const NAME = 'vnClientBillingData'; + +class billingData { + constructor($scope, $http, $timeout, vnAppLogger, $translate) { + this.$ = $scope; + this.http = $http; + this.timeout = $timeout; + this.logger = vnAppLogger; + this.translate = $translate; + this.payId = null; + this.dueDay = null; + this.copyData(); + } + + $onChanges(changes) { + this.copyData(); + } + + copyData() { + if (this.client) { + this.payId = this.client.payMethod ? this.client.payMethod.id : null; + this.dueDay = this.client.dueDay ? this.client.dueDay : null; + } + } + + checkChanges() { + let payId = this.client.payMethodFk || null; + let dueDay = this.client.dueDay || null; + + if (this.payId !== payId || this.dueDay !== dueDay) { + this.$.sendMail.show(); + return false; + } + + return true; + } + returnDialog(response) { + if (response === 'ACCEPT') { + this.sendMail().then( + () => this.logger.showMessage(this.translate.instant('Notification sent!')), + () => this.logger.showMessage(this.translate.instant('Notification error')) + ); + } + this.timeout(() => this.$.watcher.submit()); + } + + sendMail() { + return this.http.post(`/mailer/manuscript/paymentUpdate`, {user: this.client.id}); + } +} +billingData.$inject = ['$scope', '$http', '$timeout', 'vnAppLogger', '$translate']; + +export const COMPONENT = { + template: require('./billing-data.html'), + controller: billingData, + controllerAs: 'bill', + bindings: { + client: '<' + } +}; +module.component(NAME, COMPONENT); diff --git a/client/client/src/billing-data/index.js b/client/client/src/billing-data/index.js deleted file mode 100644 index 7c6c6ffeb..000000000 --- a/client/client/src/billing-data/index.js +++ /dev/null @@ -1,11 +0,0 @@ -import {module} from '../module'; - -export const NAME = 'vnClientBillingData'; -export const COMPONENT = { - template: require('./index.html'), - controllerAs: 'bill', - bindings: { - client: '<' - } -}; -module.component(NAME, COMPONENT); diff --git a/client/client/src/billing-data/locale/es.json b/client/client/src/billing-data/locale/es.json new file mode 100644 index 000000000..f0b6a1213 --- /dev/null +++ b/client/client/src/billing-data/locale/es.json @@ -0,0 +1,8 @@ +{ + "Changed terms": "Has modificado las condiciones de pago", + "Notify customer?" : "¿Deseas notificar al cliente de dichos cambios?", + "No": "No", + "Yes, notify": "Sí, notificar", + "Notification sent!": "¡Notificación enviada!", + "Notification error": "Error al enviar notificación" +} \ No newline at end of file diff --git a/client/client/src/card/index.html b/client/client/src/card/card.html similarity index 100% rename from client/client/src/card/index.html rename to client/client/src/card/card.html diff --git a/client/client/src/card/index.js b/client/client/src/card/card.js similarity index 87% rename from client/client/src/card/index.js rename to client/client/src/card/card.js index 107aa9815..43d19facf 100644 --- a/client/client/src/card/index.js +++ b/client/client/src/card/card.js @@ -11,7 +11,7 @@ export default class vnClientCard { module.component(NAME, { - template: require('./index.html'), + template: require('./card.html'), controllerAs: 'card', controller: vnClientCard }); diff --git a/client/client/src/client.js b/client/client/src/client.js index 4bc822059..1ae857fa4 100644 --- a/client/client/src/client.js +++ b/client/client/src/client.js @@ -1,27 +1,27 @@ export * from './module'; export {NAME as CLIENT_CARD, - COMPONENT as CLIENT_CARD_COMPONENT} from './card/index'; + COMPONENT as CLIENT_CARD_COMPONENT} from './card/card'; export {NAME as CLIENTS, COMPONENT as CLIENTS_COMPONENT} from './index/index'; export {NAME as CLIENT_FISCAL_DATA_INDEX, - COMPONENT as CLIENT_FISCAL_DATA_INDEX_COMPONENT} from './fiscal-data/index'; + COMPONENT as CLIENT_FISCAL_DATA_INDEX_COMPONENT} from './fiscal-data/fiscal-data'; export {NAME as CLIENT_BILLING_DATA_INDEX, - COMPONENT as CLIENT_BILLINGL_DATA_INDEX_COMPONENT} from './billing-data/index'; + COMPONENT as CLIENT_BILLINGL_DATA_INDEX_COMPONENT} from './billing-data/billing-data'; export {NAME as CLIENT_DESCRIPTOR, - COMPONENT as CLIENT_DESCRIPTOR_COMPONENT} from './descriptor/index'; + COMPONENT as CLIENT_DESCRIPTOR_COMPONENT} from './descriptor/descriptor'; export {NAME as CLIENT_NOTES, - COMPONENT as CLIENT_NOTES_COMPONENT} from './notes/index'; + COMPONENT as CLIENT_NOTES_COMPONENT} from './notes/notes'; export {NAME as CLIENT_SEARCH_PANEL, - COMPONENT as CLIENT_SEARCH_PANEL_COMPONENT} from './search-panel/index'; + COMPONENT as CLIENT_SEARCH_PANEL_COMPONENT} from './search-panel/search-panel'; export {NAME as CLIENT_CREATE, - COMPONENT as CLIENT_CREATE_COMPONENT} from './create/index'; + COMPONENT as CLIENT_CREATE_COMPONENT} from './create/create'; export {NAME as CLIENT_ADDRESS_EDIT_INDEX, - COMPONENT as CLIENT_ADDRESS_EDIT_INDEX_COMPONENT} from './address-edit/index'; + COMPONENT as CLIENT_ADDRESS_EDIT_INDEX_COMPONENT} from './address-edit/address-edit'; export {NAME as NEW_NOTE_INDEX, - COMPONENT as NEW_NOTE_INDEX_COMPONENT} from './new-note/index'; + COMPONENT as NEW_NOTE_INDEX_COMPONENT} from './new-note/new-note'; -import './addresses/index'; -import './address-create/index'; -import './basic-data/index'; -import './web-access/index'; +import './addresses/addresses'; +import './address-create/address-create'; +import './basic-data/basic-data'; +import './web-access/web-access'; diff --git a/client/client/src/create/index.html b/client/client/src/create/create.html similarity index 100% rename from client/client/src/create/index.html rename to client/client/src/create/create.html diff --git a/client/client/src/create/index.js b/client/client/src/create/create.js similarity index 92% rename from client/client/src/create/index.js rename to client/client/src/create/create.js index f42583d25..bdf825481 100644 --- a/client/client/src/create/index.js +++ b/client/client/src/create/create.js @@ -17,7 +17,7 @@ class Controller { Controller.$inject = ['$scope', '$state']; export const component = { - template: require('./index.html'), + template: require('./create.html'), controller: Controller }; module.component('vnClientCreate', component); diff --git a/client/client/src/descriptor/index.html b/client/client/src/descriptor/descriptor.html similarity index 100% rename from client/client/src/descriptor/index.html rename to client/client/src/descriptor/descriptor.html diff --git a/client/client/src/descriptor/index.js b/client/client/src/descriptor/descriptor.js similarity index 92% rename from client/client/src/descriptor/index.js rename to client/client/src/descriptor/descriptor.js index 8c2da7404..a9c5722ec 100644 --- a/client/client/src/descriptor/index.js +++ b/client/client/src/descriptor/descriptor.js @@ -3,7 +3,7 @@ import './style.css'; export const NAME = 'vnDescriptor'; export const COMPONENT = { - template: require('./index.html'), + template: require('./descriptor.html'), controllerAs: 'descriptor', bindings: { client: '<', diff --git a/client/client/src/fiscal-data/index.html b/client/client/src/fiscal-data/fiscal-data.html similarity index 100% rename from client/client/src/fiscal-data/index.html rename to client/client/src/fiscal-data/fiscal-data.html diff --git a/client/client/src/fiscal-data/index.js b/client/client/src/fiscal-data/fiscal-data.js similarity index 82% rename from client/client/src/fiscal-data/index.js rename to client/client/src/fiscal-data/fiscal-data.js index d6ece6020..db96d82a5 100644 --- a/client/client/src/fiscal-data/index.js +++ b/client/client/src/fiscal-data/fiscal-data.js @@ -2,7 +2,7 @@ import {module} from '../module'; export const NAME = 'vnClientFiscalData'; export const COMPONENT = { - template: require('./index.html'), + template: require('./fiscal-data.html'), controllerAs: 'fiscal', bindings: { client: '<' diff --git a/client/client/src/index/index.html b/client/client/src/index/index.html index 2ead0c2b4..96338af36 100644 --- a/client/client/src/index/index.html +++ b/client/client/src/index/index.html @@ -3,19 +3,19 @@
- - + - +
diff --git a/client/client/src/index/index.js b/client/client/src/index/index.js index e69d35481..1f7060077 100644 --- a/client/client/src/index/index.js +++ b/client/client/src/index/index.js @@ -2,6 +2,16 @@ import {module} from '../module'; import './style.css'; import './item-client'; -module.component('vnClientIndex', { - template: require('./index.html') -}); +class Controller { + search(index) { + index.filter.search = this.model.search; + index.accept(); + } +} + +export const NAME = 'vnClientIndex'; +export const COMPONENT = { + template: require('./index.html'), + controller: Controller +}; +module.component(NAME, COMPONENT); diff --git a/client/client/src/new-note/index.html b/client/client/src/new-note/new-note.html similarity index 100% rename from client/client/src/new-note/index.html rename to client/client/src/new-note/new-note.html diff --git a/client/client/src/new-note/index.js b/client/client/src/new-note/new-note.js similarity index 94% rename from client/client/src/new-note/index.js rename to client/client/src/new-note/new-note.js index d69fa470e..8138990b5 100644 --- a/client/client/src/new-note/index.js +++ b/client/client/src/new-note/new-note.js @@ -1,4 +1,4 @@ -import template from './index.html'; +import template from './new-note.html'; import {module} from '../module'; class Controller { diff --git a/client/client/src/notes/index.html b/client/client/src/notes/notes.html similarity index 100% rename from client/client/src/notes/index.html rename to client/client/src/notes/notes.html diff --git a/client/client/src/notes/index.js b/client/client/src/notes/notes.js similarity index 96% rename from client/client/src/notes/index.js rename to client/client/src/notes/notes.js index d7fc78bf1..d5482bcb1 100644 --- a/client/client/src/notes/index.js +++ b/client/client/src/notes/notes.js @@ -1,5 +1,5 @@ import './style.css'; -import template from './index.html'; +import template from './notes.html'; import {module} from '../module'; export const NAME = 'vnClientNotes'; diff --git a/client/client/src/search-panel/index.html b/client/client/src/search-panel/search-panel.html similarity index 100% rename from client/client/src/search-panel/index.html rename to client/client/src/search-panel/search-panel.html diff --git a/client/client/src/search-panel/index.js b/client/client/src/search-panel/search-panel.js similarity index 95% rename from client/client/src/search-panel/index.js rename to client/client/src/search-panel/search-panel.js index bf8af3c03..c809bc615 100644 --- a/client/client/src/search-panel/index.js +++ b/client/client/src/search-panel/search-panel.js @@ -2,7 +2,7 @@ import {module} from '../module'; export const NAME = 'vnClientSearchPanel'; export const COMPONENT = { - template: require('./index.html'), + template: require('./search-panel.html'), controller: function($scope, $window) { this.filter = {id: null, fi: null, name: null, socialName: null, city: null, postcode: null, email: null, phone: null}; this.formVisibility = true; diff --git a/client/client/src/web-access/index.js b/client/client/src/web-access/index.js deleted file mode 100644 index d7f444af4..000000000 --- a/client/client/src/web-access/index.js +++ /dev/null @@ -1,48 +0,0 @@ -import {module} from '../module'; - -class Controller { - constructor($scope, $http, vnAppLogger) { - this.$scope = $scope; - this.$http = $http; - this.vnAppLogger = vnAppLogger; - } - $onChanges() { - if(this.client) - this.account = this.client.account; - } - onPassOpen() { - this.newPassword = ''; - this.repeatPassword = ''; - this.$scope.$apply(); - } - onPassChange(response) { - if(response == 'ACCEPT') - try { - if(!this.newPassword) - throw new Error(`Passwords can't be empty`); - if(this.newPassword != this.repeatPassword) - throw new Error(`Passwords don't match`); - - let account = { - password: this.newPassword - }; - - this.$http.put(`/client/api/Accounts/${this.client.id}`, account); - } - catch(e) { - this.vnAppLogger.showError(e.message); - return false; - } - - return true; - } -} -Controller.$inject = ['$scope', '$http', 'vnAppLogger']; - -module.component('vnClientWebAccess', { - template: require('./index.html'), - bindings: { - client: '<' - }, - controller: Controller -}); diff --git a/client/client/src/web-access/index.html b/client/client/src/web-access/web-access.html similarity index 100% rename from client/client/src/web-access/index.html rename to client/client/src/web-access/web-access.html diff --git a/client/client/src/web-access/web-access.js b/client/client/src/web-access/web-access.js new file mode 100644 index 000000000..413d80059 --- /dev/null +++ b/client/client/src/web-access/web-access.js @@ -0,0 +1,46 @@ +import {module} from '../module'; + +class Controller { + constructor($scope, $http, vnAppLogger) { + this.$scope = $scope; + this.$http = $http; + this.vnAppLogger = vnAppLogger; + } + $onChanges() { + if (this.client) + this.account = this.client.account; + } + onPassOpen() { + this.newPassword = ''; + this.repeatPassword = ''; + this.$scope.$apply(); + } + onPassChange(response) { + if (response == 'ACCEPT') + try { + if (!this.newPassword) + throw new Error(`Passwords can't be empty`); + if (this.newPassword != this.repeatPassword) + throw new Error(`Passwords don't match`); + let account = { + password: this.newPassword + }; + + this.$http.put(`/client/api/Accounts/${this.client.id}`, account); + } catch (e) { + this.vnAppLogger.showError(e.message); + return false; + } + + return true; + } +} +Controller.$inject = ['$scope', '$http', 'vnAppLogger']; + +module.component('vnClientWebAccess', { + template: require('./web-access.html'), + bindings: { + client: '<' + }, + controller: Controller +}); diff --git a/client/core/src/autocomplete/index.html b/client/core/src/autocomplete/autocomplete.html similarity index 100% rename from client/core/src/autocomplete/index.html rename to client/core/src/autocomplete/autocomplete.html diff --git a/client/core/src/autocomplete/index.js b/client/core/src/autocomplete/autocomplete.js similarity index 99% rename from client/core/src/autocomplete/index.js rename to client/core/src/autocomplete/autocomplete.js index 2cd088c9b..c46fcebf7 100644 --- a/client/core/src/autocomplete/index.js +++ b/client/core/src/autocomplete/autocomplete.js @@ -400,7 +400,7 @@ export default class Autocomplete extends Component { Autocomplete.$inject = ['$element', '$scope', '$http', 'vnPopover', '$transclude']; module.component('vnAutocomplete', { - template: require('./index.html'), + template: require('./autocomplete.html'), bindings: { url: '@', showField: '@?', diff --git a/client/core/src/components.js b/client/core/src/components.js index 5c631ab04..2c8a09630 100644 --- a/client/core/src/components.js +++ b/client/core/src/components.js @@ -1,18 +1,19 @@ import './mdl-override.css'; import './styles/fonts/mdi-override.css'; -import './textfield/index'; -import './watcher/index'; -import './paging/index'; -import './icon/index'; -import './autocomplete/index'; -import './popover/index'; -import './dialog/index'; -import './confirm/index'; -import './title/index'; -import './subtitle/index'; -import './spinner/index'; -import './snackbar/index'; +import './textfield/textfield'; +import './watcher/watcher'; +import './paging/paging'; +import './icon/icon'; +import './autocomplete/autocomplete'; +import './popover/popover'; +import './dialog/dialog'; + +import './confirm/confirm'; +import './title/title'; +import './subtitle/subtitle'; +import './spinner/spinner'; +import './snackbar/snackbar'; export {NAME as BUTTON, directive as ButtonDirective} from './button/button'; export {NAME as BUTTON_MDL, factory as buttonMdl} from './button/button.mdl'; diff --git a/client/core/src/confirm/index.html b/client/core/src/confirm/confirm.html similarity index 100% rename from client/core/src/confirm/index.html rename to client/core/src/confirm/confirm.html diff --git a/client/core/src/confirm/index.js b/client/core/src/confirm/confirm.js similarity index 78% rename from client/core/src/confirm/index.js rename to client/core/src/confirm/confirm.js index 0d7c56cc0..f629fe788 100644 --- a/client/core/src/confirm/index.js +++ b/client/core/src/confirm/confirm.js @@ -1,12 +1,12 @@ import {module} from '../module'; -import Dialog from '../dialog/index'; +import Dialog from '../dialog/dialog'; import './style.css'; export default class Confirm extends Dialog {} Dialog.$inject = ['$element']; module.component('vnConfirm', { - template: require('./index.html'), + template: require('./confirm.html'), bindings: { onResponse: '&', question: '@', diff --git a/client/core/src/dialog/index.html b/client/core/src/dialog/dialog.html similarity index 100% rename from client/core/src/dialog/index.html rename to client/core/src/dialog/dialog.html diff --git a/client/core/src/dialog/index.js b/client/core/src/dialog/dialog.js similarity index 98% rename from client/core/src/dialog/index.js rename to client/core/src/dialog/dialog.js index e45f66b93..e2be65799 100644 --- a/client/core/src/dialog/index.js +++ b/client/core/src/dialog/dialog.js @@ -98,7 +98,7 @@ export default class Dialog extends Component { Dialog.$inject = ['$element']; module.component('vnDialog', { - template: require('./index.html'), + template: require('./dialog.html'), transclude: { tplBody: 'tplBody', tplButtons: 'tplButtons' diff --git a/client/core/src/directives/dialog.js b/client/core/src/directives/dialog.js index b4baac7f3..d4ac65b45 100644 --- a/client/core/src/directives/dialog.js +++ b/client/core/src/directives/dialog.js @@ -1,5 +1,5 @@ import {module} from '../module'; -import Dialog from '../dialog/index'; +import Dialog from '../dialog/dialog'; import {kebabToCamel} from '../lib/string'; /** diff --git a/client/core/src/icon/index.js b/client/core/src/icon/icon.js similarity index 95% rename from client/core/src/icon/index.js rename to client/core/src/icon/icon.js index 7e36fab97..31e9ca565 100644 --- a/client/core/src/icon/index.js +++ b/client/core/src/icon/icon.js @@ -1,5 +1,5 @@ import {module} from '../module'; -import './index.mdl'; +import './icon.mdl'; import './style.css'; import * as resolveFactory from '../lib/resolveDefaultComponents'; diff --git a/client/core/src/icon/index.mdl.html b/client/core/src/icon/icon.mdl.html similarity index 100% rename from client/core/src/icon/index.mdl.html rename to client/core/src/icon/icon.mdl.html diff --git a/client/core/src/icon/index.mdl.js b/client/core/src/icon/icon.mdl.js similarity index 83% rename from client/core/src/icon/index.mdl.js rename to client/core/src/icon/icon.mdl.js index 3084fdd12..ce3f82856 100644 --- a/client/core/src/icon/index.mdl.js +++ b/client/core/src/icon/icon.mdl.js @@ -1,5 +1,5 @@ import {module} from '../module'; -import template from './index.mdl.html'; +import template from './icon.mdl.html'; export const NAME = 'vnIconMdlFactory'; export function factory() { diff --git a/client/core/src/label/label.mdl.html b/client/core/src/label/label.mdl.html index 9f95f13b3..2f33b3a1a 100644 --- a/client/core/src/label/label.mdl.html +++ b/client/core/src/label/label.mdl.html @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/client/core/src/paging/index.html b/client/core/src/paging/paging.html similarity index 100% rename from client/core/src/paging/index.html rename to client/core/src/paging/paging.html diff --git a/client/core/src/paging/index.js b/client/core/src/paging/paging.js similarity index 96% rename from client/core/src/paging/index.js rename to client/core/src/paging/paging.js index fd17b994e..8e0b86aa1 100644 --- a/client/core/src/paging/index.js +++ b/client/core/src/paging/paging.js @@ -36,7 +36,7 @@ Paging.$inject = ['$http', '$scope']; export const NAME = 'vnPaging'; export const COMPONENT = { - template: require('./index.html'), + template: require('./paging.html'), bindings: { index: '<', total: '<' diff --git a/client/core/src/popover/index.js b/client/core/src/popover/popover.js similarity index 100% rename from client/core/src/popover/index.js rename to client/core/src/popover/popover.js diff --git a/client/core/src/snackbar/index.html b/client/core/src/snackbar/snackbar.html similarity index 100% rename from client/core/src/snackbar/index.html rename to client/core/src/snackbar/snackbar.html diff --git a/client/core/src/snackbar/index.js b/client/core/src/snackbar/snackbar.js similarity index 93% rename from client/core/src/snackbar/index.js rename to client/core/src/snackbar/snackbar.js index ce76c1ba3..20a7e9374 100644 --- a/client/core/src/snackbar/index.js +++ b/client/core/src/snackbar/snackbar.js @@ -20,6 +20,6 @@ export default class Controller { Controller.$inject = ['$element']; module.component('vnSnackbar', { - template: require('./index.html'), + template: require('./snackbar.html'), controller: Controller }); diff --git a/client/core/src/spinner/index.html b/client/core/src/spinner/spinner.html similarity index 100% rename from client/core/src/spinner/index.html rename to client/core/src/spinner/spinner.html diff --git a/client/core/src/spinner/index.js b/client/core/src/spinner/spinner.js similarity index 96% rename from client/core/src/spinner/index.js rename to client/core/src/spinner/spinner.js index daf694e1d..ae6a69ede 100644 --- a/client/core/src/spinner/index.js +++ b/client/core/src/spinner/spinner.js @@ -49,7 +49,7 @@ export default class Spinner extends Component { Spinner.$inject = ['$element', '$scope']; export const component = { - template: require('./index.html'), + template: require('./spinner.html'), bindings: { enable: '=' }, diff --git a/client/core/src/subtitle/index.html b/client/core/src/subtitle/subtitle.html similarity index 100% rename from client/core/src/subtitle/index.html rename to client/core/src/subtitle/subtitle.html diff --git a/client/core/src/subtitle/index.js b/client/core/src/subtitle/subtitle.js similarity index 68% rename from client/core/src/subtitle/index.js rename to client/core/src/subtitle/subtitle.js index 941e8eb54..c98c25994 100644 --- a/client/core/src/subtitle/index.js +++ b/client/core/src/subtitle/subtitle.js @@ -1,6 +1,6 @@ import {module} from '../module'; module.component('vnSubtitle', { - template: require('./index.html'), + template: require('./subtitle.html'), transclude: true }); diff --git a/client/core/src/textfield/index.js b/client/core/src/textfield/textfield.js similarity index 98% rename from client/core/src/textfield/index.js rename to client/core/src/textfield/textfield.js index af4d7c4ab..e278c13a5 100644 --- a/client/core/src/textfield/index.js +++ b/client/core/src/textfield/textfield.js @@ -3,7 +3,7 @@ import Component from '../lib/component'; import * as resolveFactory from '../lib/resolveDefaultComponents'; import * as normalizerFactory from '../lib/inputAttrsNormalizer'; import './style.scss'; -import './index.mdl'; +import './textfield.mdl'; export default class Textfield extends Component { constructor($element, $scope, $attrs) { diff --git a/client/core/src/textfield/index.mdl.html b/client/core/src/textfield/textfield.mdl.html similarity index 100% rename from client/core/src/textfield/index.mdl.html rename to client/core/src/textfield/textfield.mdl.html diff --git a/client/core/src/textfield/index.mdl.js b/client/core/src/textfield/textfield.mdl.js similarity index 85% rename from client/core/src/textfield/index.mdl.js rename to client/core/src/textfield/textfield.mdl.js index 64e156885..e97d38d28 100644 --- a/client/core/src/textfield/index.mdl.js +++ b/client/core/src/textfield/textfield.mdl.js @@ -4,7 +4,7 @@ export const NAME = 'vnTextfieldMdlFactory'; export function factory() { return { - template: require('./index.mdl.html'), + template: require('./textfield.mdl.html'), default: { label: 'text', className: 'mdl-textfield--floating-label', diff --git a/client/core/src/title/index.html b/client/core/src/title/title.html similarity index 100% rename from client/core/src/title/index.html rename to client/core/src/title/title.html diff --git a/client/core/src/title/index.js b/client/core/src/title/title.js similarity index 69% rename from client/core/src/title/index.js rename to client/core/src/title/title.js index 3fb71f567..3420738e1 100644 --- a/client/core/src/title/index.js +++ b/client/core/src/title/title.js @@ -1,6 +1,6 @@ import {module} from '../module'; module.component('vnTitle', { - template: require('./index.html'), + template: require('./title.html'), transclude: true }); diff --git a/client/core/src/watcher/index.html b/client/core/src/watcher/watcher.html similarity index 100% rename from client/core/src/watcher/index.html rename to client/core/src/watcher/watcher.html diff --git a/client/core/src/watcher/index.js b/client/core/src/watcher/watcher.js similarity index 99% rename from client/core/src/watcher/index.js rename to client/core/src/watcher/watcher.js index d421405df..aec3bc0a8 100644 --- a/client/core/src/watcher/index.js +++ b/client/core/src/watcher/watcher.js @@ -149,7 +149,7 @@ export default class Watcher extends Component { Watcher.$inject = ['$element', '$scope', '$state', '$transitions', '$http', 'vnAppLogger', '$translate']; module.component('vnWatcher', { - template: require('./index.html'), + template: require('./watcher.html'), bindings: { url: '@?', idField: '@?', diff --git a/client/salix/src/aclService.js b/client/salix/src/aclService.js index aeb8b0129..63e75278c 100644 --- a/client/salix/src/aclService.js +++ b/client/salix/src/aclService.js @@ -1,10 +1,14 @@ import ngModule from './module'; -function aclService() { - this.roles = window.Salix.acl.roles; +aclService.$inject = ['aclConstant']; +function aclService(aclConstant) { + this.roles = aclConstant.roles || undefined; + this.routeHasPermission = function(route) { let hasPermission; - if (!route.acl) + if (!this.roles) + hasPermission = false; + else if (!route.acl) hasPermission = true; else if (!this.roles || !Object.keys(this.roles).length) hasPermission = false; diff --git a/client/salix/src/app.js b/client/salix/src/app.js index 8ec2c5df7..92caaf50c 100644 --- a/client/salix/src/app.js +++ b/client/salix/src/app.js @@ -6,3 +6,4 @@ import './config'; import './run'; import './components'; import './styles/index'; +import './modulesFactory'; diff --git a/client/salix/src/bootstrap.js b/client/salix/src/bootstrap.js index b0a57a215..dd7a61388 100644 --- a/client/salix/src/bootstrap.js +++ b/client/salix/src/bootstrap.js @@ -1,5 +1,5 @@ import {ng} from 'vendor'; -import './module'; +import appName from './module'; export const bootstrap = () => { const selector = 'selector'; @@ -13,5 +13,5 @@ export const bootstrap = () => { if (!_element) { throw new Error('Element is not defined'); } - ng.bootstrap(_element, ['salix']); + ng.bootstrap(_element, [appName]); }; diff --git a/client/salix/src/components/app/app.js b/client/salix/src/components/app/app.js index c20c448ee..18742e9f4 100644 --- a/client/salix/src/components/app/app.js +++ b/client/salix/src/components/app/app.js @@ -1,4 +1,4 @@ -import ngModule from '../../module'; +import ngModule, {appName} from '../../module'; import './style.scss'; export const NAME = 'vnApp'; @@ -76,4 +76,6 @@ function interceptorConfig($httpProvider) { } ngModule.config(interceptorConfig); +var acl = window[appName] ? window[appName].acl : {}; +ngModule.constant('aclConstant', acl); diff --git a/client/salix/src/components/home/home.html b/client/salix/src/components/home/home.html index 9d08cb286..b92bedb4d 100644 --- a/client/salix/src/components/home/home.html +++ b/client/salix/src/components/home/home.html @@ -1,3 +1,17 @@ - -
Push on applications menu
-
\ No newline at end of file + + +
+
+ +
+ + +

+
+ + + +
+
+ +
\ No newline at end of file diff --git a/client/salix/src/components/home/home.js b/client/salix/src/components/home/home.js index bbb9a6163..66002ae9f 100644 --- a/client/salix/src/components/home/home.js +++ b/client/salix/src/components/home/home.js @@ -4,11 +4,12 @@ import './style.scss'; export const NAME = 'vnHome'; export default class vnHome { - constructor() { - this.modules = []; + constructor(modulesFactory, $state) { + this.modules = modulesFactory.getModules(); + this.state = $state; } } -vnHome.$inject = []; +vnHome.$inject = ['modulesFactory', '$state']; export const COMPONENT = { template: require('./home.html'), diff --git a/client/salix/src/components/home/style.scss b/client/salix/src/components/home/style.scss index 1ddc08763..76c6cd402 100644 --- a/client/salix/src/components/home/style.scss +++ b/client/salix/src/components/home/style.scss @@ -1,7 +1,41 @@ vn-home { - & > .default { - text-align: center; - font-size: 1.3em; - padding: 2em; + padding: 2em; + vn-horizontal{ + margin-bottom: 15px; + } + h6{ + color: #3C393B; + text-align: center; + } + a:link{ + text-decoration: none; + } + .vn-module{ + display: flex; + flex: none; + padding: 2em; + border-radius: 4px; + box-sizing: border-box; + transition: opacity 0.7s ease; + h4{ + text-transform: capitalize; } + vn-one{ + text-align: center; + } + + i{ + font-size: 50px !important; + margin: 0 auto; + } + &:hover{ + opacity: 0.7; + } + + &.Clients{ + background-color: #ffa410; + color: #ffffff; + } + + } } \ No newline at end of file diff --git a/client/salix/src/components/main-menu/main-menu.html b/client/salix/src/components/main-menu/main-menu.html index 75100c1b2..da5047c63 100644 --- a/client/salix/src/components/main-menu/main-menu.html +++ b/client/salix/src/components/main-menu/main-menu.html @@ -6,14 +6,16 @@ diff --git a/client/salix/src/components/main-menu/main-menu.js b/client/salix/src/components/main-menu/main-menu.js index 4340c85e9..f2bc6e5d1 100644 --- a/client/salix/src/components/main-menu/main-menu.js +++ b/client/salix/src/components/main-menu/main-menu.js @@ -2,9 +2,10 @@ import ngModule from '../../module'; import './style.scss'; export default class Controller { - constructor($translate, $window) { + constructor($translate, $window, modulesFactory) { this.$translate = $translate; this.$window = $window; + this.modules = modulesFactory.getModules(); } onLogoutClick() { this.$window.location = 'salix/logout'; @@ -15,7 +16,7 @@ export default class Controller { console.log(`Locale changed: ${lang}`); } } -Controller.$inject = ['$translate', '$window']; +Controller.$inject = ['$translate', '$window', 'modulesFactory']; ngModule.component('vnMainMenu', { template: require('./main-menu.html'), diff --git a/client/salix/src/components/searchbar/searchbar.html b/client/salix/src/components/searchbar/searchbar.html index 50ccac05d..0ca47a768 100644 --- a/client/salix/src/components/searchbar/searchbar.html +++ b/client/salix/src/components/searchbar/searchbar.html @@ -1,6 +1,6 @@
- + { - let filter = removeEmpty(filterCb(params)); - this.find(filter, function(err, instances) { - if(!err) - cb(null, instances); - }) - }; + this[methodName] = (params, cb) => { + let filter = removeEmpty(filterCb(params)); + var response = {} + + function returnValues(){ + if(response.instances !== undefined && response.count !== undefined) + cb(null, response); + } + + function error(){ + cb(null, response); + } + + this.find(filter, function(err, instances) { + if(!err){ + response.instances = instances; + returnValues(); + } + else{ + error(); + } + + }) + + this.count(filter.where, function(err, totalCount){ + if(!err){ + response.count = totalCount; + returnValues(); + } + else{ + error(); + } + + }) + }; }; diff --git a/services/client/common/models/PayMethod.json b/services/client/common/models/PayMethod.json index c55589137..4e16d2b93 100644 --- a/services/client/common/models/PayMethod.json +++ b/services/client/common/models/PayMethod.json @@ -27,6 +27,12 @@ "accessType": "*", "principalType": "ROLE", "principalId": "$everyone", + "permission": "DENY" + }, + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "root", "permission": "ALLOW" } ] diff --git a/services/client/common/models/Province.json b/services/client/common/models/Province.json index b285bd419..b6dd16b2e 100644 --- a/services/client/common/models/Province.json +++ b/services/client/common/models/Province.json @@ -32,10 +32,22 @@ }, "acls": [ { - "accessType": "*", + "accessType": "READ", "principalType": "ROLE", "principalId": "$everyone", "permission": "ALLOW" + }, + { + "accessType": "WRITE", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "DENY" + }, + { + "accessType": "*", + "principalType": "ROLE", + "principalId": "root", + "permission": "ALLOW" } ] } \ No newline at end of file diff --git a/services/client/common/scopes/client/before-save.js b/services/client/common/scopes/client/before-save.js new file mode 100644 index 000000000..9a0c82cdd --- /dev/null +++ b/services/client/common/scopes/client/before-save.js @@ -0,0 +1,18 @@ +module.exports = function(Client){ + Client.observe('before save', function(ctx, next) { + if (ctx.instance) { + if (!ctx.instance.dueDay) + ctx.instance.dueDay = 5; + next(); + } else { + Client.findById(ctx.where.id, function(err, instance) { + if (instance + && instance.payMethodFk != ctx.data.payMethodFk + && instance.dueDay == ctx.data.dueDay) + ctx.data.dueDay = 5; + next(); + }); + } + }); + +} \ No newline at end of file diff --git a/services/client/common/scopes/client/card.json b/services/client/common/scopes/client/card.json index 84ca960d6..332a0409b 100644 --- a/services/client/common/scopes/client/card.json +++ b/services/client/common/scopes/client/card.json @@ -1,43 +1,57 @@ [ { - "relation": "salesPerson", - "scope":{ - "fields": { - "id": true, "name": true - } + "relation": "salesPerson", + "scope": { + "fields": [ + "id", + "name" + ] } }, { - "relation": "contactChannel", - "scope":{ - "fields": { - "id": true, "name": true - } + "relation": "contactChannel", + "scope": { + "fields": [ + "id", + "name" + ] } }, { - "relation": "province", - "scope":{ - "fields": { - "id": true, "name": true - } + "relation": "province", + "scope": { + "fields": [ + "id", + "name" + ] } }, { - "relation": "country", - "scope":{ - "fields": { - "id": true, "name": true - } + "relation": "country", + "scope": { + "fields": [ + "id", + "name" + ] } }, { - "relation": "payMethod", - "scope":{ - "fields": { - "id": true, "name": true - } + "relation": "payMethod", + "scope": { + "fields": [ + "id", + "name" + ] + } + }, + { + "relation": "account", + "scope": { + "fields": [ + "id", + "name", + "active" + ] } } -] - +] \ No newline at end of file diff --git a/services/client/common/scopes/client/filter.js b/services/client/common/scopes/client/filter.js new file mode 100644 index 000000000..d60f4c21c --- /dev/null +++ b/services/client/common/scopes/client/filter.js @@ -0,0 +1,39 @@ +module.exports = function(Client){ + Client.installMethod('filter', filterClients); + function filterClients(p) { + if(p.search && p.search !== "") + return searchWhere(p); + return andWhere(p); + } + + function searchWhere(p){ + return { + where: { + or:[ + {id: p.search,}, + {name: {regexp: p.search}} + ] + + }, + skip: (p.page - 1) * p.size, + limit: p.size + } + } + + function andWhere(p){ + return { + where: { + id: p.id, + name: {regexp: p.name}, + cif: p.cif, + socialName: {regexp: p.socialName}, + city: {regexp: p.city}, + postcode: p.postcode, + email: {regexp: p.email}, + phone: p.phone + }, + skip: (p.page - 1) * p.size, + limit: p.size + } + } +} \ No newline at end of file diff --git a/services/mailer/.gitignore b/services/mailer/.gitignore new file mode 100644 index 000000000..36420af85 --- /dev/null +++ b/services/mailer/.gitignore @@ -0,0 +1,2 @@ +node_modules +config.json \ No newline at end of file diff --git a/services/mailer/Application/Route/manuscript.js b/services/mailer/Application/Route/manuscript.js new file mode 100644 index 000000000..a229fd499 --- /dev/null +++ b/services/mailer/Application/Route/manuscript.js @@ -0,0 +1,30 @@ +var express = require('express'); +var router = new express.Router(); +var mail = require('../mail.js'); +var database = require('../database.js'); +var template = require('../template.js'); + +// Escrito de cambios en méto de pago del cliente +router.post('/paymentUpdate', function(request, response) { + database.pool.query('SELECT Cliente, `e-mail` AS email FROM Clientes WHERE Id_Cliente = ?', [request.body.user], function(error, rs) { + var params = { + clientName: rs[0].Cliente + }; + + template.getTemplate('paymentUpdate', params, function(body) { + var data = { + recipient: rs[0].email, + subject: 'Cambios en las condiciones de pago', + body: body + }; + + if (mail.send(data)) { + response.json({status: "OK"}); + } else { + response.json({status: "ERROR"}); + } + }); + }); +}); + +module.exports = router; diff --git a/services/mailer/Application/Route/notification.js b/services/mailer/Application/Route/notification.js new file mode 100644 index 000000000..5ec515dd1 --- /dev/null +++ b/services/mailer/Application/Route/notification.js @@ -0,0 +1,8 @@ +var express = require('express'); +var router = new express.Router(); + +router.get('/test', function(request, response) { + response.send("test"); +}); + +module.exports = router; diff --git a/services/mailer/Application/Template/paymentUpdate.html b/services/mailer/Application/Template/paymentUpdate.html new file mode 100644 index 000000000..203db8047 --- /dev/null +++ b/services/mailer/Application/Template/paymentUpdate.html @@ -0,0 +1,35 @@ +
+
+ +
+ Verdnatura Levante SL, B97367486 + Avda. Espioca 100, 46460 Silla (Valencia) +
+
+
+
+

CAMBIOS EN CONDICIONES DE PAGO

+
+ +

+ Estimado cliente {{clientName}} +

+ +

+ Se han cambiado las condiciones de pago, estas son las nuevas: + +

+
+
+

Este mensaje es privado y confidencial, y debe ser utilizado exclusivamente por la persona destinataria del mismo. + Si usted ha recibido este mensaje por error, le rogamos lo comunique al remitente y borre dicho mensaje y cualquier + documento adjunto que pudiera contener. Verdnatura Levante SL no renuncia a la confidencialidad ni a ningún privilegio + por causa de transmisión errónea o mal funcionamiento. Igualmente no se hace responsable de los cambios, alteraciones, + errores u omisiones que pudieran hacerse al mensaje una vez enviado.

+ +

En cumplimiento de lo dispuesto en la Ley Orgánica 15/1999, de Protección de Datos de Carácter Personal, le comunicamos + que los datos personales que facilite se incluirán en ficheros automatizados de VERDNATURA LEVANTE S.L., pudiendo en todo momento + ejercitar los derechos de acceso, rectificación, cancelación y oposición, comunicándolo por escrito al domicilio social de la entidad. + La finalidad del fichero es la gestión administrativa, contabilidad, y facturación.

+
+
\ No newline at end of file diff --git a/services/mailer/Application/Util/system.js b/services/mailer/Application/Util/system.js new file mode 100644 index 000000000..08092ad5c --- /dev/null +++ b/services/mailer/Application/Util/system.js @@ -0,0 +1,11 @@ +module.exports = { + + /** + * Obtiene las variables de entorno + * @param {String} env - Nombre de la variable de entorno + * @return {String} Valor de la variable de entorno + */ + getEnv: function(env) { + return process.env[env]; + } +}; diff --git a/services/mailer/Application/Util/terminal.js b/services/mailer/Application/Util/terminal.js new file mode 100644 index 000000000..d897671e7 --- /dev/null +++ b/services/mailer/Application/Util/terminal.js @@ -0,0 +1,13 @@ +var Settings = require('../Settings.js'); + +module.exports = { + + /** + * Imprimir cabecera + */ + printHeader: function() { + console.log('##########################################################'); + console.log('## ' + Settings.name + ' ##'); + console.log('##########################################################'); + } +}; diff --git a/services/mailer/Application/database.js b/services/mailer/Application/database.js new file mode 100644 index 000000000..979867a33 --- /dev/null +++ b/services/mailer/Application/database.js @@ -0,0 +1,26 @@ +var mysql = require('mysql'); +var settings = require('./Settings.js'); +var logger = require('./Logger.js'); + +module.exports = { + + /** + * Variable de instancia del pool + */ + pool: null, + + /** + * Iniciar pool de conexión con la base de datos + */ + init: function() { + this.pool = mysql.createPool(settings.mysql); + + this.pool.getConnection(function(error, connection) { + if (error) { + logger.print(__LOG_ERROR, 'No se ha podido establecer la conexión con la base de datos. ' + error.code); + } else { + logger.print(__LOG_INFO, 'Conexión con la base de datos establecida'); + } + }); + } +}; diff --git a/services/mailer/Application/language.js b/services/mailer/Application/language.js new file mode 100644 index 000000000..e69de29bb diff --git a/services/mailer/Application/logger.js b/services/mailer/Application/logger.js new file mode 100644 index 000000000..c7442c33f --- /dev/null +++ b/services/mailer/Application/logger.js @@ -0,0 +1,28 @@ + +// Tipos de advertencias +global.__LOG_INFO = 1; +global.__LOG_WARNING = 2; +global.__LOG_ERROR = 3; + +module.exports = { + + /** + * Imprimir advertencia directamente en consola + * @param {Integer} type - Constante tipo de advertencia + */ + print: function(type, message) + { + if (type == __LOG_INFO) + { + console.log('[INFORMACIÓN] -> ' + message); + } + else if(type == __LOG_WARNING) + { + console.log('[ADVERTENCIA] -> ' + message); + } + else if(type == __LOG_ERROR) + { + console.log('[ERROR] -> ' + message); + } + } +} \ No newline at end of file diff --git a/services/mailer/Application/mail.js b/services/mailer/Application/mail.js new file mode 100644 index 000000000..3390425fe --- /dev/null +++ b/services/mailer/Application/mail.js @@ -0,0 +1,48 @@ +var nodemailer = require('nodemailer'); +var settings = require('./Settings.js'); +var logger = require('./Logger.js'); + +// Módulo para el envío de emails +module.exports = { + + transporter: null, + + /** + * Si todavía no está inicializada la configuración, + * carga el fichero de configuración. + */ + init: function() { + this.transporter = nodemailer.createTransport(settings.smtp); + + this.transporter.verify(function(error, success) { + if (error) { + logger.print(__LOG_ERROR, error); + } else { + logger.print(__LOG_INFO, 'Conexión SMTP establecida'); + } + }); + }, + +/** + * Envia un email con los datos recibidos desde un vector. + * @param {Object} data - Datos para el envío del email + */ + send: function(data) { + let mailOptions = { + from: '"' + settings.senderName + '" <' + settings.senderMail + '>', + to: data.recipient, + subject: data.subject, + html: data.body + }; + + this.transporter.sendMail(mailOptions, (error, info) => { + if (error) { + logger.print(__LOG_ERROR, error); + } else if (Settings.debug) { + logger.print(__LOG_INFO, 'Se ha enviado el email ' + info.messageId + ' [' + info.response + ']'); + + return true; + } + }); + }, +} \ No newline at end of file diff --git a/services/mailer/Application/router.js b/services/mailer/Application/router.js new file mode 100644 index 000000000..c18f908a9 --- /dev/null +++ b/services/mailer/Application/router.js @@ -0,0 +1,16 @@ +var express = require('express'); +var router = new express.Router(); +var settings = require('./settings.js'); + +// Página por defecto +router.get('/', function(request, response) { + response.send(settings.name + ' v' + settings.version); +}); + +// Rutas de los escritos. +router.use('/manuscript', require('./Route/Manuscript.js')); + +// Rutas de las notificaciones. +router.use('/notification', require('./Route/Notification.js')); + +module.exports = router; diff --git a/services/mailer/Application/settings.js b/services/mailer/Application/settings.js new file mode 100644 index 000000000..f2a22d5d3 --- /dev/null +++ b/services/mailer/Application/settings.js @@ -0,0 +1,2 @@ +// Módulo de configuración +module.exports = require('./config.json'); diff --git a/services/mailer/Application/template.js b/services/mailer/Application/template.js new file mode 100644 index 000000000..3424c0dd2 --- /dev/null +++ b/services/mailer/Application/template.js @@ -0,0 +1,48 @@ +var fs = require('fs'); +var mustache = require('mustache'); +var database = require('./database.js'); +var logger = require('./logger.js'); + +var Template = { + + /** + * Obtiene la plantilla + * @param {String} name - Nombre de la plantilla + * @param {Object} params - Datos a reemplazar. + * @param {Object} callback - Callback + */ + getTemplate: function(name, params, callback) { + database.pool.query('SELECT name, attachmentPath FROM vn.mailTemplates WHERE name = ?', [name], function(error, rs) + { + if (rs.length == 0) { + logger.print(__LOG_ERROR, 'La plantilla ' + name + ' no existe'); + return; + } + + var path = './Application/Template/' + rs[0].name + '.html'; + + if (!fs.existsSync(path)) { + logger.print(__LOG_ERROR, 'No se ha podido cargar la plantilla ' + name + '.html'); + } else { + Template.render(path, params, function(body) { + callback(body); + }); + } + }); + }, + + /** + * Renderiza las plantillas + * @param {String} path - Ruta de la plantilla + * @param {Object} params - Listado de parámetros a remplazar + * @param {Object} callback - Callback + */ + render: function(path, params, callback) { + fs.readFile(path, 'utf8', function(error, body) { + mustache.parse(body); + callback(mustache.render(body, params)); + }); + } +}; + +module.exports = Template; diff --git a/services/mailer/package.json b/services/mailer/package.json new file mode 100644 index 000000000..87aced84e --- /dev/null +++ b/services/mailer/package.json @@ -0,0 +1,13 @@ +{ + "name": "MailServer", + "version": "0.0.1", + "description": "Servidor de envío de correos", + "main": "server.js", + "dependencies": { + "body-parser": "^1.17.2", + "express": "^4.15.3", + "mustache": "^2.3.0", + "mysql": "^2.13.0", + "nodemailer": "^4.0.1" + } +} diff --git a/services/mailer/server.js b/services/mailer/server.js new file mode 100644 index 000000000..448c9b922 --- /dev/null +++ b/services/mailer/server.js @@ -0,0 +1,37 @@ +/** + * Módulos necesarios + */ +var express = require('express'); +var app = module.exports = express(); +var bodyParser = require('body-parser'); + +var settings = require('./Application/settings.js'); +var mail = require('./Application/mail.js'); +var logger = require('./Application/logger.js'); +var database = require('./Application/database.js'); +var terminal = require('./Application/Util/terminal.js'); + +// Middleware +app.use(bodyParser.json()); +app.use(bodyParser.urlencoded({extended: true})); + +// Cargar rutas +app.use('/', require('./Application/router.js')); + + +app.start = function() { + return app.listen(settings.port, function() { + terminal.printHeader(); + mail.init(); + database.init(); + logger.print(__LOG_INFO, 'Servidor de correo iniciado en el puerto ' + settings.port); + if (settings.debug) { + logger.print(__LOG_WARNING, 'El modo debug está activado'); + } + }); +}; + +if (require.main === module) { + app.start(); +} + diff --git a/services/salix/server/boot/routes.js b/services/salix/server/boot/routes.js index 10ce5dd4b..cbd83d2c1 100644 --- a/services/salix/server/boot/routes.js +++ b/services/salix/server/boot/routes.js @@ -113,7 +113,7 @@ module.exports = function (app) { function sendACL(res, acl){ let aclStr = JSON.stringify(acl); res.header('Content-Type', 'application/javascript; charset=UTF-8'); - res.send(`(function(window){window.Salix = window.Salix || {}; window.Salix.acl = window.Salix.acl || {}; window.Salix.acl = ${aclStr}; })(window)`); + res.send(`(function(window){window.salix = window.salix || {}; window.salix.acl = window.salix.acl || {}; window.salix.acl = ${aclStr}; })(window)`); } };