Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
gerard 2018-09-03 11:03:10 +02:00
commit b46bc7d296
6 changed files with 87 additions and 27 deletions

View File

@ -14,16 +14,24 @@ describe('Component vnTh', () => {
$componentController = _$componentController_; $componentController = _$componentController_;
$element = angular.element(`<div>${template}</div>`); $element = angular.element(`<div>${template}</div>`);
controller = $componentController('vnTh', {$element: $element}); controller = $componentController('vnTh', {$element: $element});
controller.table = {setOrder: () => {}}; controller.table = {
controller.column = { setOrder: () => {},
getAttribute: () => 'MyField', applyOrder: () => {}
classList: {
add: () => {},
remove: () => {}
}
}; };
controller.column.setAttribute('field', 'MyField');
})); }));
describe('onInit()', () => {
it(`should define controllers order as per defaultOrder then call setOrder()`, () => {
controller.defaultOrder = 'DESC';
spyOn(controller.table, 'setOrder');
controller.$onInit();
expect(controller.order).toEqual('DESC');
expect(controller.table.setOrder).toHaveBeenCalledWith('MyField', 'DESC');
});
});
describe('toggleOrder()', () => { describe('toggleOrder()', () => {
it(`should change the ordenation to DESC (descendant) if it was ASC (ascendant)`, () => { it(`should change the ordenation to DESC (descendant) if it was ASC (ascendant)`, () => {
controller.order = 'ASC'; controller.order = 'ASC';
@ -47,14 +55,56 @@ describe('Component vnTh', () => {
}); });
}); });
describe('onInit()', () => { describe('onToggleOrder()', () => {
it(`should define controllers order as per defaultOrder then call setOrder()`, () => { it(`should not call updateArrow() method if field property isn't defined`, () => {
controller.defaultOrder = 'DESC'; controller.column.setAttribute('field', '');
spyOn(controller.table, 'setOrder'); spyOn(controller, 'updateArrow');
controller.$onInit();
expect(controller.order).toEqual('DESC'); controller.onToggleOrder();
expect(controller.table.setOrder).toHaveBeenCalledWith('MyField', 'DESC');
expect(controller.updateArrow).not.toHaveBeenCalledWith();
});
it(`should call toggleOrder() method if field property and
table field property equals and then call updateArrow()`, () => {
controller.table.field = 'MyField';
spyOn(controller, 'toggleOrder');
spyOn(controller, 'updateArrow');
controller.onToggleOrder();
expect(controller.toggleOrder).toHaveBeenCalledWith();
expect(controller.updateArrow).toHaveBeenCalledWith();
});
it(`should call setOrder() method if field property and
table field property doesn't equals and then call updateArrow()`, () => {
controller.table.field = 'MyField2';
spyOn(controller.table, 'setOrder');
spyOn(controller, 'updateArrow');
controller.onToggleOrder();
expect(controller.table.setOrder).toHaveBeenCalledWith('MyField', 'ASC');
expect(controller.updateArrow).toHaveBeenCalledWith();
});
});
describe('updateArrow()', () => {
it(`should remove 'asc' class and add 'desc' class if order property is descendant`, () => {
controller.column.classList.add('asc');
controller.order = 'DESC';
controller.updateArrow();
expect(controller.column.classList[0]).toEqual('desc');
});
it(`should remove 'asc' class and add it again if order property is ascendant`, () => {
controller.column.classList.add('asc');
controller.order = 'ASC';
controller.updateArrow();
expect(controller.column.classList[0]).toEqual('asc');
}); });
}); });
}); });

View File

@ -2,11 +2,12 @@ import ngModule from '../module';
import './style.scss'; import './style.scss';
class Controller { class Controller {
constructor($scope, $http, $state, $window) { constructor($scope, $http, $state, $window, $translate) {
this.$scope = $scope; this.$scope = $scope;
this.$http = $http; this.$http = $http;
this.$state = $state; this.$state = $state;
this.$window = $window; this.$window = $window;
this.$translate = $translate;
} }
$postLink() { $postLink() {
@ -56,9 +57,8 @@ class Controller {
let lines = this.$scope.model.data; let lines = this.$scope.model.data;
for (let i = 0; i < lines.length; i++) { for (let i = 0; i < lines.length; i++) {
let isFutureDate = new Date(lines[i].date) > new Date(); let isFutureDate = new Date(lines[i].date) > new Date();
let isGenreOut = lines[i].alertLevel != 0;
if (!isFutureDate && !isGenreOut) if (isFutureDate)
return i; return i;
} }
} }
@ -68,10 +68,14 @@ class Controller {
for (let i = this.freeLineIndex; i > 0; i--) { for (let i = this.freeLineIndex; i > 0; i--) {
let line = lines[i]; let line = lines[i];
let currentDate = new Date();
currentDate.setHours(0, 0, 0);
if (line.alertLevel == 1 && line.isPicked || line.alertLevel > 1) { let isPastDate = new Date(lines[i].date) < currentDate;
let isPicked = line.alertLevel == 1 && line.isPicked;
if ((isPicked) || line.alertLevel > 1 || isPastDate)
return i; return i;
}
} }
} }
@ -86,7 +90,7 @@ class Controller {
let balance = onPreparationLine.querySelector('.balance'); let balance = onPreparationLine.querySelector('.balance');
balance.classList.add('counter'); balance.classList.add('counter');
balance.title = 'Visible quantity'; balance.title = this.$translate.instant('Visible quantity');
let headerOffset = body.querySelector('header').getBoundingClientRect(); let headerOffset = body.querySelector('header').getBoundingClientRect();
let headerHeight = headerOffset.height; let headerHeight = headerOffset.height;
@ -126,7 +130,7 @@ class Controller {
} }
} }
Controller.$inject = ['$scope', '$http', '$state', '$window']; Controller.$inject = ['$scope', '$http', '$state', '$window', '$translate'];
ngModule.component('vnItemDiary', { ngModule.component('vnItemDiary', {
template: require('./index.html'), template: require('./index.html'),

View File

@ -40,10 +40,13 @@ describe('Item', () => {
describe('freeLineIndex()', () => { describe('freeLineIndex()', () => {
it(`should call freeLineIndex() and return an index from line with alertLevel 0 and current date`, () => { it(`should call freeLineIndex() and return an index from line with alertLevel 0 and current date`, () => {
let currentDate = new Date();
currentDate.setDate(currentDate.getDate() + 1);
controller.$scope.model = {data: [ controller.$scope.model = {data: [
{name: 'My item 1', alertLevel: 3, date: '2018-05-02'}, {name: 'My item 1', alertLevel: 3, date: '2018-05-02'},
{name: 'My item 2', alertLevel: 1, date: '2018-05-03'}, {name: 'My item 2', alertLevel: 1, date: '2018-05-03'},
{name: 'My item 3', alertLevel: 0, date: new Date()}] {name: 'My item 3', alertLevel: 0, date: currentDate}]
}; };
let result = controller.freeLineIndex; let result = controller.freeLineIndex;
@ -53,15 +56,17 @@ describe('Item', () => {
describe('onPreparationLineIndex()', () => { describe('onPreparationLineIndex()', () => {
it(`should call onPreparationLineIndex() and return an index from line with alertLevel 1 and isPicked true`, () => { it(`should call onPreparationLineIndex() and return an index from line with alertLevel 1 and isPicked true`, () => {
let currentDate = new Date();
currentDate.setDate(currentDate.getDate() + 1);
controller.$scope.model = {data: [ controller.$scope.model = {data: [
{name: 'My item 1', alertLevel: 3, isPicked: true, date: '2018-05-02'}, {name: 'My item 1', alertLevel: 3, isPicked: true, date: '2018-05-02'},
{name: 'My item 3', alertLevel: 1, isPicked: true, date: '2018-05-03'}, {name: 'My item 3', alertLevel: 1, isPicked: true, date: '2018-05-03'},
{name: 'My item 4', alertLevel: 1, isPicked: false, date: '2018-05-03'}, {name: 'My item 4', alertLevel: 1, isPicked: false, date: '2018-05-03'},
{name: 'My item 5', alertLevel: 0, isPicked: false, date: new Date()}] {name: 'My item 5', alertLevel: 0, isPicked: false, date: currentDate}]
}; };
let result = controller.onPreparationLineIndex; let result = controller.onPreparationLineIndex;
expect(result).toEqual(1); expect(result).toEqual(2);
}); });
}); });

View File

@ -0,0 +1,3 @@
In: Entrada
Out: Salida
Visible quantity: Cantidad visible

View File

@ -25,8 +25,6 @@ Intrastat code: Código intrastat
Warehouse: Almacén Warehouse: Almacén
Code: Código Code: Código
State: Estado State: Estado
In: Entrada
Out: Salida
Species: Especie Species: Especie
Add tag: Añadir etiqueta Add tag: Añadir etiqueta
Remove tag: Quitar etiqueta Remove tag: Quitar etiqueta

View File

@ -89,7 +89,7 @@ module.exports = Self => {
tp.problem tp.problem
FROM tmp.filter f FROM tmp.filter f
LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.ticketFk`); LEFT JOIN tmp.ticketProblems tp ON tp.ticketFk = f.ticketFk`);
stmt.merge(Self.buildOrderBy(filter, 'f')); stmt.merge(Self.buildOrderBy(filter));
let ticketsIndex = stmts.push(stmt) - 1; let ticketsIndex = stmts.push(stmt) - 1;
stmts.push( stmts.push(