Merge branch 'dev' of http://git.verdnatura.es/salix into dev
This commit is contained in:
commit
d866e0c982
|
@ -13,7 +13,9 @@ export function directive($parse) {
|
||||||
link: function($scope, $element, $attrs) {
|
link: function($scope, $element, $attrs) {
|
||||||
if ($scope.$last && $attrs.onLast) {
|
if ($scope.$last && $attrs.onLast) {
|
||||||
let fn = $parse($attrs.onLast);
|
let fn = $parse($attrs.onLast);
|
||||||
|
setTimeout(() => {
|
||||||
fn($scope);
|
fn($scope);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,17 +25,6 @@ class Controller {
|
||||||
return this._item;
|
return this._item;
|
||||||
}
|
}
|
||||||
|
|
||||||
get alertLevelIndex() {
|
|
||||||
let lines = this.$scope.model.data;
|
|
||||||
for (let i = 0; i < lines.length; i++) {
|
|
||||||
let isFutureDate = new Date(lines[i].date) > new Date();
|
|
||||||
let isGenreOut = lines[i].alertLevel != 0;
|
|
||||||
|
|
||||||
if (!isFutureDate && !isGenreOut)
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onChange(value) {
|
onChange(value) {
|
||||||
if (!value) return;
|
if (!value) return;
|
||||||
|
|
||||||
|
@ -63,15 +52,47 @@ class Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get freeLineIndex() {
|
||||||
|
let lines = this.$scope.model.data;
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
let isFutureDate = new Date(lines[i].date) > new Date();
|
||||||
|
let isGenreOut = lines[i].alertLevel != 0;
|
||||||
|
|
||||||
|
if (!isFutureDate && !isGenreOut)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get onPreparationLineIndex() {
|
||||||
|
let lines = this.$scope.model.data;
|
||||||
|
|
||||||
|
for (let i = this.freeLineIndex; i > 0; i--) {
|
||||||
|
let line = lines[i];
|
||||||
|
|
||||||
|
if (line.alertLevel == 1 && line.isPicked || line.alertLevel > 1) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
scrollToActive() {
|
scrollToActive() {
|
||||||
let body = this.$window.document.body;
|
let body = this.$window.document.body;
|
||||||
let lineIndex = this.alertLevelIndex;
|
let lineIndex = this.onPreparationLineIndex;
|
||||||
let lines = body.querySelector('vn-tbody').children;
|
let lines = body.querySelector('vn-tbody').children;
|
||||||
|
|
||||||
if (!lineIndex || !lines.length) return;
|
if (!lineIndex || !lines.length) return;
|
||||||
|
|
||||||
lines[lineIndex].scrollIntoView();
|
let onPreparationLine = lines[lineIndex];
|
||||||
lines[lineIndex - 1].querySelector('.balance').classList.add('counter');
|
|
||||||
|
let balance = onPreparationLine.querySelector('.balance');
|
||||||
|
balance.classList.add('counter');
|
||||||
|
balance.title = 'Visible quantity';
|
||||||
|
|
||||||
|
let headerOffset = body.querySelector('header').getBoundingClientRect();
|
||||||
|
let headerHeight = headerOffset.height;
|
||||||
|
let offsetTop = onPreparationLine.offsetTop - headerHeight;
|
||||||
|
|
||||||
|
body.querySelector('ui-view').scrollTop = offsetTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import './index.js';
|
import './index.js';
|
||||||
|
|
||||||
describe('Item', () => {
|
fdescribe('Item', () => {
|
||||||
describe('Component vnItemDiary', () => {
|
describe('Component vnItemDiary', () => {
|
||||||
let $componentController;
|
let $componentController;
|
||||||
let $scope;
|
let $scope;
|
||||||
|
@ -38,19 +38,33 @@ describe('Item', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('alertLevelIndex()', () => {
|
describe('freeLineIndex()', () => {
|
||||||
it(`should call alertLevelIndex() 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`, () => {
|
||||||
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: new Date()}]
|
||||||
};
|
};
|
||||||
let result = controller.alertLevelIndex;
|
let result = controller.freeLineIndex;
|
||||||
|
|
||||||
expect(result).toEqual(2);
|
expect(result).toEqual(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('onPreparationLineIndex()', () => {
|
||||||
|
it(`should call onPreparationLineIndex() and return an index from line with alertLevel 1 and isPicked true`, () => {
|
||||||
|
controller.$scope.model = {data: [
|
||||||
|
{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 4', alertLevel: 1, isPicked: false, date: '2018-05-03'},
|
||||||
|
{name: 'My item 5', alertLevel: 0, isPicked: false, date: new Date()}]
|
||||||
|
};
|
||||||
|
let result = controller.onPreparationLineIndex;
|
||||||
|
|
||||||
|
expect(result).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('set item()', () => {
|
describe('set item()', () => {
|
||||||
it(`should call filterBuilder()`, () => {
|
it(`should call filterBuilder()`, () => {
|
||||||
spyOn(controller, 'filterBuilder');
|
spyOn(controller, 'filterBuilder');
|
||||||
|
|
Loading…
Reference in New Issue