Merge branch 'dev' into test

This commit is contained in:
Daniel Herrero 2017-11-16 15:09:57 +01:00
commit 5cb54eb8e1
25 changed files with 280 additions and 129 deletions

2
Jenkinsfile vendored
View File

@ -43,7 +43,7 @@ node
stage ("Stopping/Removing Docker")
{
sh "docker-compose down --rmi all"
sh "docker-compose down --rmi 'all'"
}
stage ("Generar dockers")

View File

@ -48,7 +48,6 @@ export default class Controller {
onLoginErr(json) {
this.loading = false;
this.password = '';
this.focusUser();
let message;
@ -64,6 +63,7 @@ export default class Controller {
}
this.showMessage(message);
this.focusUser();
}
focusUser() {
this.$.userField.select();

View File

@ -7,7 +7,6 @@
index="index"
on-search="$ctrl.search(index)"
advanced="true"
search="$ctrl.model.search"
popover="vn-client-search-panel">
</vn-searchbar>
</vn-horizontal>

View File

@ -7,7 +7,6 @@ export default class Controller {
this.model = {};
}
search(index) {
index.filter.search = this.model.search;
index.accept();
}
}

View File

@ -1,28 +1,16 @@
import ngModule from '../module';
export default class Controller {
constructor(sessionStorage) {
this.sessionStorage = sessionStorage;
constructor() {
// onSubmit() is defined by @vnSearchbar
this.onSubmit = () => {};
}
onSearch() {
this.setStorageValue();
this.onSubmit(this.filter);
}
$onChanges() {
var value = this.sessionStorage.get('filter');
if (value !== undefined)
this.filter = value;
}
setStorageValue() {
this.sessionStorage.set('filter', this.filter);
}
}
Controller.$inject = ['sessionStorage'];
Controller.$inject = [];
ngModule.component('vnClientSearchPanel', {
template: require('./search-panel.html'),

View File

@ -7,6 +7,10 @@ import {module} from '../module';
* @property {Snackbar} snackbar The main object to show messages.
*/
export default class App {
constructor($rootScope) {
this.loaderStatus = 0;
this.$rootScope = $rootScope;
}
show(message) {
if (this.snackbar) this.snackbar.show({message: message});
}
@ -16,5 +20,17 @@ export default class App {
showError(message) {
this.show(`Error: ${message}`);
}
pushLoader() {
this.loaderStatus++;
if (this.loaderStatus === 1)
this.$rootScope.loading = true;
}
popLoader() {
this.loaderStatus--;
if (this.loaderStatus === 0)
this.$rootScope.loading = false;
}
}
App.$inject = ['$rootScope'];
module.service('vnApp', App);

View File

@ -0,0 +1,13 @@
import Component from './component';
/**
* Component that host an input.
*/
export default class Input extends Component {
select() {
this.input.select();
}
focus() {
this.input.focus();
}
}

View File

@ -1,11 +1,10 @@
import {module} from '../module';
interceptor.$inject = ['$q', '$rootScope', '$window', 'vnApp', '$translate', '$cookies'];
function interceptor($q, $rootScope, $window, vnApp, $translate, $cookies) {
$rootScope.loading = false;
interceptor.$inject = ['$q', '$window', 'vnApp', '$translate', '$cookies'];
function interceptor($q, $window, vnApp, $translate, $cookies) {
return {
request: function(config) {
$rootScope.loading = true;
vnApp.pushLoader();
let token = $cookies.get('vnToken');
if (token)
@ -23,11 +22,11 @@ function interceptor($q, $rootScope, $window, vnApp, $translate, $cookies) {
case 'PATCH':
vnApp.showMessage($translate.instant('Data saved!'));
}
$rootScope.loading = false;
vnApp.popLoader();
return response;
},
responseError: function(rejection) {
$rootScope.loading = false;
vnApp.popLoader();
let data = rejection.data;
let error;

View File

@ -4,8 +4,7 @@
ng-focus="$ctrl.hasFocus = true"
ng-blur="$ctrl.hasFocus = false"
ng-mouseenter="$ctrl.hasMouseIn = true"
ng-mouseleave="$ctrl.hasMouseIn = false"
>
ng-mouseleave="$ctrl.hasMouseIn = false">
<input
class="mdl-textfield__input"
type="{{$ctrl.type}}"
@ -13,11 +12,19 @@
ng-model="$ctrl.value"
vn-validation="{{$ctrl.rule}}"
ng-disabled="$ctrl.disabled"
ng-readonly="$ctrl.readonly"
/>
ng-readonly="$ctrl.readonly"/>
<div class="mdl-chip__action">
<i class="material-icons" ng-if="$ctrl.hasInfo" vn-tooltip="{{$ctrl.info}}" tooltip-position="up">info_outline</i>
<i class="material-icons pointer" ng-show="$ctrl.hasValue&&($ctrl.hasFocus||$ctrl.hasMouseIn)" ng-click="$ctrl.clear()">clear</i>
<i class="material-icons"
ng-if="$ctrl.hasInfo"
vn-tooltip="{{$ctrl.info}}"
tooltip-position="up">
info_outline
</i>
<i class="material-icons pointer"
ng-show="$ctrl.hasValue && ($ctrl.hasFocus || $ctrl.hasMouseIn)"
ng-click="$ctrl.clear()">
clear
</i>
</div>
<label class="mdl-textfield__label" translate>{{$ctrl.label}}</label>
</div>

View File

@ -1,9 +1,8 @@
import {module} from '../module';
import Component from '../lib/component';
import * as normalizerFactory from '../lib/inputAttrsNormalizer';
import Input from '../lib/input';
import './style.scss';
export default class TextfieldController extends Component {
export default class Textfield extends Input {
constructor($element, $scope, $attrs, $timeout, normalizer) {
super($element);
@ -15,45 +14,39 @@ export default class TextfieldController extends Component {
this.$timeout = $timeout;
this._value = null;
this.type = this.$attrs.type || 'text';
this.type = $attrs.type || 'text';
this.showActions = false;
this.input = $element[0].querySelector('input');
this.focus = false;
this.hasInfo = Boolean(this.$attrs.info);
this.info = this.$attrs.info || null;
this.hasInfo = Boolean($attrs.info);
this.info = $attrs.info || null;
this.hasFocus = false;
this.hasMouseIn = false;
componentHandler.upgradeElement($element[0].firstChild);
}
get value() {
return this._value;
}
set value(value) {
this._value = (value === undefined || value === '') ? null : value;
this.input.value = this._value;
this.hasValue = Boolean(this._value);
this.mdlUpdate();
}
mdlUpdate() {
let mdlField = this.$element[0].firstChild.MaterialTextfield;
if (mdlField)
mdlField.updateClasses_();
}
clear() {
this.value = null;
this.input.focus();
}
}
TextfieldController.$inject = ['$element', '$scope', '$attrs', '$timeout', normalizerFactory.NAME];
Textfield.$inject = ['$element', '$scope', '$attrs', '$timeout', 'vnInputAttrsNormalizer'];
module.component('vnTextfield', {
template: require('./textfield.html'),
controller: TextfieldController,
controller: Textfield,
bindings: {
value: '=model',
label: '@?',

View File

@ -1,10 +1,10 @@
<form ng-submit="$ctrl.onSubmit()">
<vn-horizontal>
<vn-textfield vn-one label="Search" model="$ctrl.search"></vn-textfield>
<vn-textfield vn-one label="Search" model="$ctrl.stringSearch"></vn-textfield>
<vn-icon
pad-medium-top
ng-if="$ctrl.advanced"
ng-click="$ctrl.onClick($event)"
ng-click="$ctrl.onpenFilters($event)"
icon="keyboard_arrow_down"
style="cursor: pointer;">
</vn-icon>

View File

@ -1,21 +1,66 @@
import ngModule from '../../module';
export default class Controller {
constructor($element, $scope, $document, $compile, vnPopover, sessionStorage, $timeout) {
constructor($element, $scope, $document, $compile, vnPopover, $timeout) {
this.element = $element[0];
this.$scope = $scope;
this.$document = $document;
this.$compile = $compile;
this.vnPopover = vnPopover;
this.sessionStorage = sessionStorage;
this.$timeout = $timeout;
this.stringSearch = '';
}
clearFilter() {
this.index.filter = {};
this.sessionStorage.remove('filter');
this.index.filter = {
page: 1,
size: 20
};
}
onClick(event) {
this.search = null;
// string search to json filter
getFiltersFromSearch() {
let toFind = this.stringSearch;
let find;
if (this.stringSearch) {
// find pattern key:value or key:(extra value) and returns array
find = toFind.match(/((([\w_]+):([\w_]+))|([\w_]+):\(([\w_ ]+)\))/gi);
// remove pattern key:value or key:(extra value) from string
this.index.filter.search = (toFind.replace(/((([\w_]+):([\w_]+))|([\w_]+):\(([\w_ ]+)\))/gi, '')).trim();
if (find)
for (let i = 0; i < find.length; i++) {
let aux = find[i].split(':');
let property = aux[0];
let value = aux[1].replace(/\(|\)/g, '');
this.index.filter[property] = value.trim();
}
}
}
// json filter to string search
createFilterSearch(filter) {
let search = [];
let keys = Object.keys(filter);
if (keys.length) {
keys.forEach(k => {
if (k !== 'page' && k !== 'size' && k !== 'search') {
let value = filter[k];
if (typeof value === 'string' && value.indexOf(' ') !== -1) {
search.push(`${k}:(${value})`);
} else if (typeof value !== 'object') {
search.push(`${k}:${value}`);
}
}
});
}
if (this.index.filter.search) {
search.push(this.index.filter.search);
}
delete this.index.filter.search;
this.stringSearch = (search.length) ? search.join(' ') : '';
}
onpenFilters(event) {
if (this.stringSearch) {
this.getFiltersFromSearch();
}
this.child = this.vnPopover.showComponent(this.popover, this.$scope, this.element);
@ -27,12 +72,21 @@ export default class Controller {
event.preventDefault();
}
onChildSubmit(filter) {
// this.vnPopover.hide();
Object.assign(this.index.filter, filter);
this.onSubmit();
this.createFilterSearch(filter);
this.index.filter = {
page: 1,
size: 20
};
this.$timeout(() => {
this.onSubmit();
});
}
onSubmit() {
if (this.stringSearch) {
this.getFiltersFromSearch();
}
if (this.onSearch)
this.onSearch();
@ -47,13 +101,12 @@ export default class Controller {
this.clearFilter();
}
}
Controller.$inject = ['$element', '$scope', '$document', '$compile', 'vnPopover', 'sessionStorage', '$timeout'];
Controller.$inject = ['$element', '$scope', '$document', '$compile', 'vnPopover', '$timeout'];
ngModule.component('vnSearchbar', {
template: require('./searchbar.html'),
bindings: {
index: '<',
search: '=',
onSearch: '&',
advanced: '=',
popover: '@',

View File

@ -3,7 +3,4 @@ var vnLoopback = require('../../loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
app.set('applications', require('./application.json'));
vnLoopback.boot(app, __dirname);
if (require.main === module) {
app.start();
}
vnLoopback.boot(app, __dirname, module);

View File

@ -31,15 +31,15 @@ module.exports = function(Client) {
Client.activate = function(id, ctx, cb) {
Client.findById(id, function(err, client) {
if(!err) {
if (!err) {
Client.update({id: client.id}, {active: !client.active});
let filter = {where: {clientFk: client.id}, fields: ['started', 'ended']};
app.models.CreditClassification.findOne(filter, function(error, data) {
if (error)
return;
let currentDate = new Date();
if (data && client.active && (data.ended >= currentDate || data.ended == null)) {

View File

@ -2,26 +2,6 @@ module.exports = function(Client) {
Client.installMethod('filter', filterClients);
function filterClients(params) {
if (params.search)
return searchWhere(params);
return andWhere(params);
}
function searchWhere(params) {
return {
where: {
or: [
{id: params.search},
{name: {regexp: params.search}}
]
},
skip: (params.page - 1) * params.size,
limit: params.size
};
}
function andWhere(params) {
let filters = {
where: {},
skip: (params.page - 1) * params.size,
@ -31,18 +11,51 @@ module.exports = function(Client) {
delete params.page;
delete params.size;
if (params.search) {
hasAnd = true;
filters.where.and = [
{
or: [
{id: params.search},
{name: {regexp: params.search}}
]
}
];
delete params.search;
}
if (params.phone) {
filters.where.or = [
let phones = [
{phone: params.phone},
{mobile: params.phone}
];
if (filters.where.and) {
filters.where.and.push(
{
or: phones
}
);
} else {
filters.where.or = phones;
}
delete params.phone;
}
Object.keys(params).forEach(
key => {
filters.where[key] = (key === 'postcode' || key === 'fi') ? params[key] : {regexp: params[key]};
}
);
let keys = Object.keys(params);
if (keys.length) {
keys.forEach(
key => {
if (filters.where.and) {
let filter = {};
filter[key] = (key === 'postcode' || key === 'fi' || key === 'id') ? params[key] : {regexp: params[key]};
filters.where.and.push(filter);
} else {
filters.where[key] = (key === 'postcode' || key === 'fi' || key === 'id') ? params[key] : {regexp: params[key]};
}
}
);
}
return filters;
}
};

View File

@ -11,7 +11,7 @@ module.exports = function(Self) {
let app = require('../../server/server');
let Employee = app.models.Employee;
Employee.findOne({where: {userFk: userId}}, function (err, user){
if (user){
if (user) {
ctx.instance.employeeFk = user.id;
next();
}

View File

@ -40,7 +40,7 @@ module.exports = function(Self) {
message: 'Correo electrónico inválido',
allowNull: true,
allowBlank: true,
with: /^[\w|\.|\-]+@\w[\w|\.|\-]*\w(,[\w|\.|\-]+@\w[\w|\.|\-]*\w)*$/
with: /^[\w|.|-]+@\w[\w|.|-]*\w(,[\w|.|-]+@\w[\w|.|-]*\w)*$/
});
Self.validatesLengthOf('postcode', {
allowNull: true,
@ -53,6 +53,11 @@ module.exports = function(Self) {
message: 'El iban no tiene el formato correcto'
});
let validateDni = require('../validations/validateDni');
Self.validateBinded('fi', validateDni, {
message: 'DNI Incorrecto'
});
Self.validate('payMethod', hasSalesMan, {
message: 'No se puede cambiar la forma de pago si no hay comercial asignado'
});

View File

@ -0,0 +1,94 @@
module.exports = fi => {
let dni = fi;
let getLetterDni = dni => {
const regExpDni = 'TRWAGMYFPDXBNJZSQVHLCKE';
const letterDni = dni.toUpperCase().substring(0, 1);
let positionLetter = parseInt(dni) % 23;
let getLetter = regExpDni.substring(positionLetter + 1, positionLetter);
switch (letterDni) {
case 'X': case 'Y': case 'Z':
positionLetter = parseInt(dni.replace(letterDni, letterDni.charCodeAt(0) - 88)) % 23;
getLetter = regExpDni.substring(positionLetter + 1, positionLetter);
console.log(letterDni.charCodeAt(0));
}
return getLetter;
};
let getDniSpain = (dniNumeric, dniLetter) => {
let returnValue = false;
switch (dni.length) {
case 9:
if (dniLetter === getLetterDni(dni))
returnValue = true;
}
return returnValue;
};
let getDniForeign = (dniNumeric, dniLetter) => {
let returnValue = false;
switch (dni.length) {
case 9:
if (dniLetter === getLetterDni(dni))
returnValue = true;
}
return returnValue;
};
let getDniBusiness = () => {
if (dni.length == 9)
return true;
return false;
};
let getDniFrance = dniLetterCountry => {
let returnValue = false;
switch (dni.length) {
case 13:
if (dniLetter === 'R')
returnValue = true;
}
return returnValue;
};
let getDniItaly = dniLetterCountry => {
let returnValue = false;
switch (dni.length) {
case 13:
if (dniLetter === 'T')
returnValue = true;
}
return returnValue;
};
let getDni = () => {
const dniNumeric = dni.substring(0, 8);
const dniLetter = dni.substring(8, 9);
const dniLetterCountry = dni.substring(0, 1);
const dniLetterAscii = parseInt(dniLetterCountry.charCodeAt(0));
let dniValue = false;
switch (true) {
case (dniLetterAscii >= 88 && dniLetterAscii <= 90): // X-Z
dniValue = getDniForeign(dniNumeric, dniLetter);
break;
case (dniLetterAscii === 66): // B
dniValue = getDniBusiness();
break;
case (dniLetterAscii === 70): // F
dniValue = getDniFrance(dniLetterCountry);
break;
case (dniLetterAscii === 73): // I
dniValue = getDniItaly(dniLetterCountry);
break;
case (dniLetterAscii >= 48 && dniLetterAscii <= 57): // 0- 9
console.log('dni spain');
dniValue = getDniSpain(dniNumeric, dniLetter);
break;
default:
console.log('default');
dniValue = true;
}
return dniValue;
};
return getDni();
};

View File

@ -13,7 +13,6 @@
"url": "https://git.verdnatura.es/salix"
},
"dependencies": {
"loopback-context": "^3.3.0",
"request": "^2.83.0"
}
}

View File

@ -2,7 +2,4 @@
var vnLoopback = require('../../loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname);
if (require.main === module) {
app.start();
}
vnLoopback.boot(app, __dirname, module);

View File

@ -1,13 +1,5 @@
var cors = require('cors');
var whitelist = ['http://localhost:8080'];
var corsOptions = {
origin: function(origin, callback) {
var originIsWhitelisted = whitelist.indexOf(origin) !== -1;
callback(originIsWhitelisted ? null : 'Bad Request', originIsWhitelisted);
}
};
module.exports = function() {
return cors({origin: true});
};

View File

@ -10,7 +10,7 @@ module.exports = {
boot: vnBoot
};
function vnBoot(app, rootDir, cb) {
function vnBoot(app, rootDir, rootModule) {
// Internationalization
let i18nDir = rootDir + '/i18n';
@ -22,7 +22,7 @@ function vnBoot(app, rootDir, cb) {
});
app.get('/prueba', function(req, res) {
i18n.setLocale(req.get('Accept-Language').substring(0,2));
i18n.setLocale(req.get('Accept-Language').substring(0, 2));
res.send(i18n.__('Hello'));
});
}
@ -63,31 +63,28 @@ function vnBoot(app, rootDir, cb) {
modelSources: [
"loopback/common/models",
"loopback/server/models",
__dirname + "/../common/models",
__dirname + "/models",
path.join(__dirname, "../common/models"),
path.join(__dirname, "models"),
rootDir + "/../common/models",
rootDir + "/models"
],
mixinDirs: [
"loopback/common/mixins",
"loopback/server/mixins",
__dirname + "/../common/mixins",
__dirname + "/mixins",
path.join(__dirname, "../common/mixins"),
path.join(__dirname, "mixins"),
rootDir + "/../common/mixins",
rootDir + "/mixins"
],
bootDirs: [
__dirname + "/boot",
path.join(__dirname, "boot"),
rootDir + "/boot"
]
};
boot(app, bootOptions, function(err) {
if (err) throw err;
if (require.main === module) {
if (require.main === rootModule)
app.start();
}
if (cb)
cb(app);
});
}

View File

@ -1,7 +1,4 @@
var vnLoopback = require('../../loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname);
if (require.main === module) {
app.start();
}
vnLoopback.boot(app, __dirname, module);

View File

@ -2,7 +2,4 @@
var vnLoopback = require('../../loopback/server/server.js');
var app = module.exports = vnLoopback.loopback();
vnLoopback.boot(app, __dirname);
if (require.main === module) {
app.start();
}
vnLoopback.boot(app, __dirname, module);

View File

@ -10,8 +10,4 @@ app.set('url auth', '/auth');
app.use(cookieParser());
vnLoopback.boot(app, __dirname);
if (require.main === module) {
app.start();
}
vnLoopback.boot(app, __dirname, module);