Fixed scroll on itemDIary to line with alertLevel 1 #433

This commit is contained in:
Joan Sanchez 2018-07-30 12:12:41 +02:00
parent 0022e4e427
commit 182599f663
3 changed files with 56 additions and 19 deletions

View File

@ -13,7 +13,9 @@ export function directive($parse) {
link: function($scope, $element, $attrs) {
if ($scope.$last && $attrs.onLast) {
let fn = $parse($attrs.onLast);
fn($scope);
setTimeout(() => {
fn($scope);
});
}
}
};

View File

@ -25,17 +25,6 @@ class Controller {
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) {
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() {
let body = this.$window.document.body;
let lineIndex = this.alertLevelIndex;
let lineIndex = this.onPreparationLineIndex;
let lines = body.querySelector('vn-tbody').children;
if (!lineIndex || !lines.length) return;
lines[lineIndex].scrollIntoView();
lines[lineIndex - 1].querySelector('.balance').classList.add('counter');
let onPreparationLine = lines[lineIndex];
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;
}
/**

View File

@ -1,6 +1,6 @@
import './index.js';
describe('Item', () => {
fdescribe('Item', () => {
describe('Component vnItemDiary', () => {
let $componentController;
let $scope;
@ -38,19 +38,33 @@ describe('Item', () => {
});
});
describe('alertLevelIndex()', () => {
it(`should call alertLevelIndex() and return an index from line with alertLevel 0 and current date`, () => {
describe('freeLineIndex()', () => {
it(`should call freeLineIndex() and return an index from line with alertLevel 0 and current date`, () => {
controller.$scope.model = {data: [
{name: 'My item 1', alertLevel: 3, date: '2018-05-02'},
{name: 'My item 2', alertLevel: 1, date: '2018-05-03'},
{name: 'My item 3', alertLevel: 0, date: new Date()}]
};
let result = controller.alertLevelIndex;
let result = controller.freeLineIndex;
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()', () => {
it(`should call filterBuilder()`, () => {
spyOn(controller, 'filterBuilder');