merge
This commit is contained in:
commit
9d6eeba1a3
|
@ -1,5 +1,3 @@
|
|||
import './dialog.js';
|
||||
|
||||
describe('Component vnDialog', () => {
|
||||
let $componentController;
|
||||
let $element;
|
||||
|
|
|
@ -11,7 +11,8 @@ export function directive() {
|
|||
restrict: 'A',
|
||||
link: function($scope, $element, $attrs) {
|
||||
$element.on('click', function(event) {
|
||||
let dialog = $scope[kebabToCamel($attrs.vnDialog)];
|
||||
let dialogKey = kebabToCamel($attrs.vnDialog);
|
||||
let dialog = $scope[dialogKey];
|
||||
if (dialog instanceof Dialog)
|
||||
dialog.show();
|
||||
event.preventDefault();
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
describe('Directive dialog', () => {
|
||||
let $scope;
|
||||
let $element;
|
||||
let element;
|
||||
let compile;
|
||||
let $componentController;
|
||||
let controller;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
compile = _element => {
|
||||
inject(($compile, $rootScope) => {
|
||||
$scope = $rootScope.$new();
|
||||
$scope.myDialog = controller;
|
||||
element = angular.element(_element);
|
||||
$compile(element)($scope);
|
||||
$scope.$digest();
|
||||
});
|
||||
};
|
||||
|
||||
beforeEach(angular.mock.inject(_$componentController_ => {
|
||||
$componentController = _$componentController_;
|
||||
$element = angular.element('<div></div>');
|
||||
controller = $componentController('vnDialog', {$element});
|
||||
}));
|
||||
|
||||
it('should call show() function if dialog is a instance of vnDialog', () => {
|
||||
let html = `<div vn-dialog="myDialog"></div>`;
|
||||
spyOn(controller, 'show');
|
||||
compile(html);
|
||||
element[0].click();
|
||||
|
||||
expect(controller.show).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,55 @@
|
|||
describe('Directive focus', () => {
|
||||
let $scope;
|
||||
let $element;
|
||||
let compile;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
compile = (_element, _childElement) => {
|
||||
inject(($compile, $rootScope) => {
|
||||
$scope = $rootScope.$new();
|
||||
$element = angular.element(_element);
|
||||
if (_childElement) {
|
||||
let childElement = angular.element(_childElement);
|
||||
$element[0] < childElement;
|
||||
$element[0].firstChild.focus = jasmine.createSpy(focus);
|
||||
}
|
||||
$element[0].focus = jasmine.createSpy('focus');
|
||||
$element[0].select = jasmine.createSpy('select');
|
||||
$compile($element)($scope);
|
||||
$scope.$digest();
|
||||
});
|
||||
};
|
||||
|
||||
it('should call the querySelector function upon the input to redefine it with the expected selector then call focus', () => {
|
||||
let html = `<div vn-focus><input></input></div>`;
|
||||
let childHtml = '<input></input>';
|
||||
compile(html, childHtml);
|
||||
|
||||
expect($element[0].firstChild.focus).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should print a warning message on console', () => {
|
||||
let html = `<potato vn-focus></potato>`;
|
||||
console.warn = jasmine.createSpy('warn');
|
||||
compile(html);
|
||||
|
||||
expect(console.warn).toHaveBeenCalledWith(`vnFocus: Can't find a focusable element`);
|
||||
});
|
||||
|
||||
it('should call focus function on the element', () => {
|
||||
let html = `<input vn-focus></input>`;
|
||||
compile(html);
|
||||
|
||||
expect($element[0].focus).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should call select function on the element', () => {
|
||||
let html = `<input vn-focus></input>`;
|
||||
compile(html);
|
||||
|
||||
expect($element[0].select).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,43 @@
|
|||
describe('Directive vnId', () => {
|
||||
let $scope;
|
||||
let $element;
|
||||
let compile;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
compile = _element => {
|
||||
inject(($compile, $rootScope) => {
|
||||
$scope = $rootScope.$new();
|
||||
$element = angular.element(_element);
|
||||
$compile($element)($scope);
|
||||
$scope.$digest();
|
||||
});
|
||||
};
|
||||
|
||||
it(`should throw an error when there's no id defined`, () => {
|
||||
let html = `<form vn-id=""></form>`;
|
||||
|
||||
expect(() => {
|
||||
compile(html);
|
||||
}).toThrow(new Error(`vnId: Attribute can't be null`));
|
||||
});
|
||||
|
||||
it(`should throw an error when these's no controller defined in $element[0]`, () => {
|
||||
let html = `<div vn-id="1"></div>`;
|
||||
|
||||
expect(() => {
|
||||
compile(html);
|
||||
}).toThrow(new Error(`vnId: Can't find controller for element '1'`));
|
||||
});
|
||||
|
||||
it(`should set the controller into the $scope as there are no errors being thrown`, () => {
|
||||
let html = `<form vn-id="1"></form>`;
|
||||
|
||||
expect($scope['1']).not.toBeDefined();
|
||||
compile(html);
|
||||
|
||||
expect($scope['1']).toBeDefined();
|
||||
});
|
||||
});
|
68
gulpfile.js
68
gulpfile.js
|
@ -15,7 +15,6 @@ var WebpackDevServer = require('webpack-dev-server');
|
|||
var exec = require('child_process').exec;
|
||||
|
||||
// Configuration
|
||||
|
||||
var srcDir = './client';
|
||||
var buildDir = './services/nginx/static';
|
||||
var langs = ['es', 'en'];
|
||||
|
@ -38,19 +37,16 @@ gulp.task('client', ['clean'], function() {
|
|||
return gulp.start('watch', 'routes', 'locales', 'webpack-dev-server');
|
||||
});
|
||||
|
||||
gulp.task('services', function() {
|
||||
require('./services/mailer/server.js').start();
|
||||
|
||||
var lbServices = [
|
||||
'auth',
|
||||
'salix',
|
||||
'client',
|
||||
'production',
|
||||
'route'
|
||||
];
|
||||
|
||||
for (var service of lbServices)
|
||||
require(`./services/${service}/server/server.js`).start();
|
||||
gulp.task('services', () => {
|
||||
process.env.NODE_ENV = gutil.env.env || 'development';
|
||||
const pathServices = './services/';
|
||||
const services = fs.readdirSync(pathServices);
|
||||
services.splice(services.indexOf('loopback'), 1);
|
||||
return services.forEach(service => {
|
||||
const serviceJs = pathServices.concat(service, '/server/server.js');
|
||||
if (fs.existsSync(serviceJs))
|
||||
require(serviceJs).start();
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('clean', function() {
|
||||
|
@ -101,7 +97,7 @@ gulp.task('webpack-dev-server', function() {
|
|||
contentBase: buildDir,
|
||||
quiet: false,
|
||||
noInfo: false,
|
||||
// hot: true,
|
||||
// hot: true,
|
||||
stats: {
|
||||
assets: true,
|
||||
colors: true,
|
||||
|
@ -140,37 +136,49 @@ var routeFiles = `${srcDir}/**/routes.json`;
|
|||
|
||||
gulp.task('routes', function() {
|
||||
return gulp.src(routeFiles)
|
||||
.pipe(concat('routes.js', {newLine: ','}))
|
||||
.pipe(wrap('var routes = [<%=contents%>\n];'))
|
||||
.pipe(gulp.dest(buildDir));
|
||||
.pipe(concat('routes.js', {newLine: ','}))
|
||||
.pipe(wrap('var routes = [<%=contents%>\n];'))
|
||||
.pipe(gulp.dest(buildDir));
|
||||
});
|
||||
|
||||
// Watch
|
||||
|
||||
gulp.task('watch', function() {
|
||||
gulp.watch(routeFiles, ['routes']);
|
||||
gulp.watch(localeFiles, ['locales']);
|
||||
});
|
||||
|
||||
gulp.task('test', () => {
|
||||
process.env.NODE_ENV = gutil.env.env || 'test';
|
||||
console.log(process.env.NODE_ENV);
|
||||
runSequence('deleteDockerDb', 'buildDockerDb', 'runDockerDb');
|
||||
// Test environment
|
||||
gulp.task('test', callback => {
|
||||
return require('./services_tests').start();
|
||||
});
|
||||
|
||||
gulp.task('runDockerDb', (callback) => {
|
||||
exec('docker run -d --name dblocal -p 3306:3306 dblocal:latest', (err, stdout, stderr) => {
|
||||
callback(err);
|
||||
// docker dblocal
|
||||
gulp.task('docker', callback => {
|
||||
runSequence('deleteDockerDb', 'deleteDockerImageDb', 'buildDockerDb', 'runDockerDb', callback);
|
||||
});
|
||||
|
||||
gulp.task('runDockerDb', callback => {
|
||||
exec('docker run -d --name dblocal -p 3306:3306 dblocal', (err, stdout, stderr) => {
|
||||
setTimeout(() => {
|
||||
callback(err);
|
||||
}, 15000);
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('buildDockerDb', (callback) => {
|
||||
gulp.task('buildDockerDb', callback => {
|
||||
exec('docker build -t dblocal:latest ./services/db', (err, stdout, stderr) => {
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
gulp.task('deleteDockerDb', (callback) => {
|
||||
exec('docker rm -f dblocal', (err, stdout, stderr) => {
|
||||
callback();
|
||||
|
||||
gulp.task('deleteDockerImageDb', callback => {
|
||||
exec('docker rmi dblocal:latest', (err, stdout, stderr) => {
|
||||
callback(err = null);
|
||||
});
|
||||
});
|
||||
|
||||
gulp.task('deleteDockerDb', callback => {
|
||||
exec('docker stop dblocal && docker wait dblocal && docker rm -f dblocal', (err, stdout, stderr) => {
|
||||
callback(err = null);
|
||||
});
|
||||
});
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -18,6 +18,7 @@
|
|||
"flatpickr": "^2.6.3",
|
||||
"material-design-lite": "^1.3.0",
|
||||
"mg-crud": "^1.1.2",
|
||||
"nodemon": "^1.12.1",
|
||||
"oclazyload": "^0.6.3",
|
||||
"validator": "^6.2.1"
|
||||
},
|
||||
|
@ -58,7 +59,6 @@
|
|||
"merge-stream": "^1.0.1",
|
||||
"nightmare": "^2.10.0",
|
||||
"node-sass": "^3.11.0",
|
||||
"nodemon": "^1.12.0",
|
||||
"raw-loader": "*",
|
||||
"run-sequence": "^2.2.0",
|
||||
"sass-loader": "^4.0.2",
|
||||
|
|
|
@ -3,7 +3,7 @@ let app = require('../../../../server/server');
|
|||
|
||||
describe('Client Create()', () => {
|
||||
let data = {
|
||||
name: 'Max Eisenhardt',
|
||||
name: 'MaxEisenhardt',
|
||||
userName: 'Magneto',
|
||||
email: 'magneto@marvel.com',
|
||||
fi: 'X-tax number',
|
||||
|
|
|
@ -51,15 +51,8 @@ module.exports = function(Self) {
|
|||
next();
|
||||
}
|
||||
|
||||
function getData(ctx) {
|
||||
if (ctx.data)
|
||||
return ctx.data;
|
||||
else
|
||||
return ctx.instance;
|
||||
}
|
||||
|
||||
function removeAllDefault(client, next) {
|
||||
Self.updateAll({clientFk: client.id, isDefaultAddress: true}, {isDefaultAddress: false}, next);
|
||||
Self.updateAll({clientFk: client.id, isDefaultAddress: {neq: 0}}, {isDefaultAddress: false}, next);
|
||||
}
|
||||
|
||||
function generateErrorDefaultAddress() {
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
module.exports = function(Self) {
|
||||
|
||||
let loopBackContext = require('loopback-context');
|
||||
|
||||
Self.validate('text', isEnabled, {message: 'Se debe rellenar el campo de texto'});
|
||||
function isEnabled(err) {
|
||||
if (!this.text) err();
|
||||
|
@ -9,15 +6,15 @@ module.exports = function(Self) {
|
|||
|
||||
Self.observe('before save', function(ctx, next) {
|
||||
ctx.instance.created = Date();
|
||||
let currentUser = loopBackContext.getCurrentContext();
|
||||
let userId = currentUser.get('currentUser');
|
||||
let app = require('../../server/server');
|
||||
let Employee = app.models.Employee;
|
||||
Employee.findOne({where: {userFk: userId}}, function (err, user){
|
||||
let token = ctx.options.accessToken;
|
||||
let userId = token && token.userId;
|
||||
let app = require('../../server/server');
|
||||
let Employee = app.models.Employee;
|
||||
Employee.findOne({where: {userFk: userId}}, function (err, user){
|
||||
if (user){
|
||||
ctx.instance.employeeFk = user.id;
|
||||
next();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
@ -156,9 +156,9 @@ INSERT INTO `salix`.`ClientCredit`(`id`, `clientFk`, `employeeFk`, `amount`, `cr
|
|||
|
||||
INSERT INTO `salix`.`ClientCreditLimit`(`id`, `maxAmount`, `roleFk`)
|
||||
VALUES
|
||||
(1, 10000, 20),
|
||||
(2, 600, 19),
|
||||
(3, 0, 13);
|
||||
(1, 10000, 3),
|
||||
(2, 600, 3),
|
||||
(3, 0, 3);
|
||||
|
||||
INSERT INTO `salix`.`ClientObservation`(`id`, `clientFk`, `employeeFk`, `text`, `created`)
|
||||
VALUES
|
||||
|
@ -243,3 +243,46 @@ INSERT INTO `salix`.`Vehicle`(`id`, `numberPlate`, `tradeMark`, `model`, `compan
|
|||
INSERT INTO `vn`.`config`(`id`, `mdbServer`, `fakeEmail`, `defaultersMaxAmount`)
|
||||
VALUES
|
||||
(1, 'beta-server', 'nightmare@verdnatura.es', '200');
|
||||
|
||||
INSERT INTO `salix`.`ACL`(`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
(1, 'Account', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(2, 'Account', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(3, 'Address', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(4, 'Address', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(5, 'AgencyService', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(6, 'AgencyService', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(7, 'Client', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(8, 'Client', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(9, 'ClientObservation', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(10, 'ClientObservation', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(11, 'ContactChannel', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(12, 'ContactChannel', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(13, 'Employee', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(14, 'PayMethod', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(15, 'PayMethod', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(16, 'FakeProduction', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(17, 'Warehouse', '* ', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(18, 'State', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(19, 'FakeProduction', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(20, 'TicketState', '*', 'WRITE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(22, 'TicketState', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(23, 'TicketState', '*', 'EXECUTE', 'ALLOW', 'ROLE', 'employee'),
|
||||
(24, 'Delivery', '*', 'READ', 'ALLOW', 'ROLE', 'employee'),
|
||||
(25, 'Zone', '*', 'READ', 'ALLOW', 'ROLE', 'employee');
|
||||
|
||||
INSERT INTO `account`.`roleRole` (`role`,`inheritsFrom`)
|
||||
VALUES
|
||||
(1, 1),
|
||||
(1, 2),
|
||||
(2, 2),
|
||||
(3, 1),
|
||||
(3, 2),
|
||||
(3, 3),
|
||||
(3, 4),
|
||||
(4, 1),
|
||||
(4, 2),
|
||||
(4, 4);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
"type": "boolean"
|
||||
},
|
||||
"email": {
|
||||
"type": "string",
|
||||
"required": true
|
||||
"type": "string"
|
||||
},
|
||||
"created": {
|
||||
"type": "date"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"host": "localhost",
|
||||
"port": 3306,
|
||||
"user": "rot",
|
||||
"user": "root",
|
||||
"password": "",
|
||||
"database": "vn"
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
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 database = require('./application/database.js');
|
||||
var auth = require('./application/auth.js');
|
||||
var settings = require('../application/settings.js');
|
||||
var mail = require('../application/mail.js');
|
||||
var database = require('../application/database.js');
|
||||
var auth = require('../application/auth.js');
|
||||
var path = require('path');
|
||||
|
||||
// Body parser middleware
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({extended: true}));
|
||||
|
||||
app.use('/static', express.static(path.join(__dirname, '/static')));
|
||||
app.use('/static', express.static(path.join(__dirname, '../static')));
|
||||
|
||||
// Auth middleware
|
||||
var requestToken = function(request, response, next) {
|
||||
|
@ -19,7 +19,7 @@ var requestToken = function(request, response, next) {
|
|||
};
|
||||
|
||||
// Load routes
|
||||
app.use('/', requestToken, require('./application/router.js'));
|
||||
app.use('/', requestToken, require('../application/router.js'));
|
||||
|
||||
app.start = function() {
|
||||
var listener = app.listen(settings.app().port, function() {
|
||||
|
@ -28,7 +28,7 @@ app.start = function() {
|
|||
database.init();
|
||||
database.testEmail();
|
||||
|
||||
let packageJson = require('./package.json');
|
||||
let packageJson = require('../package.json');
|
||||
console.log(`Web server ${packageJson.name} listening at: ${servicePath}`);
|
||||
|
||||
if (settings.app().debug) {
|
|
@ -36,4 +36,6 @@ jasmine.addReporter(new SpecReporter({
|
|||
}
|
||||
}));
|
||||
|
||||
jasmine.execute();
|
||||
exports.start = () => {
|
||||
jasmine.execute();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue