From 09a731c8122b65f132817318498159e81215c2da Mon Sep 17 00:00:00 2001 From: Bernat Date: Mon, 30 Apr 2018 08:46:41 +0200 Subject: [PATCH 1/5] refactor docker for mac users CR: Joan --- gulpfile.js | 2 +- services/db/Dockerfile | 3 +-- services/db/install/boot.sh | 8 ++++++++ services/db/install/install.sh | 6 +++--- 4 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 services/db/install/boot.sh diff --git a/gulpfile.js b/gulpfile.js index 413d86f6e..9c82e608e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -472,7 +472,7 @@ gulp.task('docker-run', async () => { await execP('docker run -d --name dblocal -p 3306:3306 dblocal'); await runSequenceP('docker-wait'); } catch (err) { - await runSequenceP('docker-image'); + await runSequenceP('docker-build'); } }); diff --git a/services/db/Dockerfile b/services/db/Dockerfile index 47891748b..a738c8aef 100644 --- a/services/db/Dockerfile +++ b/services/db/Dockerfile @@ -4,8 +4,7 @@ WORKDIR /docker-entrypoint-initdb.d COPY install/ ./ RUN chmod -R 777 . RUN ./install.sh -USER mysql -CMD ["mysqld"] +CMD ./boot.sh #HEALTHCHECK --interval=5s --timeout=10s --retries=200 \ # CMD mysqladmin ping -h 127.0.0.1 -u root || exit 1 EXPOSE 3306 \ No newline at end of file diff --git a/services/db/install/boot.sh b/services/db/install/boot.sh new file mode 100644 index 000000000..47dd15e13 --- /dev/null +++ b/services/db/install/boot.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +find /var/lib/mysql -type f -exec touch {} \; && service mysql start + +# Disable SQL strict mode +mysql -u root -proot -e "SET GLOBAL sql_mode='NO_ENGINE_SUBSTITUTION';" + +sleep infinity \ No newline at end of file diff --git a/services/db/install/install.sh b/services/db/install/install.sh index 211d57948..f38f6cd9f 100644 --- a/services/db/install/install.sh +++ b/services/db/install/install.sh @@ -1,7 +1,7 @@ #!/bin/bash # Start MySQL service -service mysql start +find /var/lib/mysql -type f -exec touch {} \; && service mysql start # Disable SQL strict mode mysql -u root -proot -e "SET GLOBAL sql_mode='NO_ENGINE_SUBSTITUTION';" @@ -15,7 +15,7 @@ done # Import changes for file in changes/*/*.sql; do echo "Imported $file" >> log.txt - mysql -u root -proot < $file + mysql -u root -proot < $file done # Import fixtures @@ -23,6 +23,6 @@ echo "Imported fixtures.sql" >> log.txt mysql -u root -proot < dump/fixtures.sql >> log.txt # Remove installation -#rm -rf /docker-entrypoint-initdb.d +rm -rf changes dump install.sh From 50011bff8e225ba83e79647d717525d70c67d6df Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Mon, 30 Apr 2018 12:30:56 +0200 Subject: [PATCH 2/5] getWatchers function --- client/core/src/lib/get-watchers.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 client/core/src/lib/get-watchers.js diff --git a/client/core/src/lib/get-watchers.js b/client/core/src/lib/get-watchers.js new file mode 100644 index 000000000..f84506eb1 --- /dev/null +++ b/client/core/src/lib/get-watchers.js @@ -0,0 +1,22 @@ +function getWatchers(root) { + root = angular.element(root || document.documentElement); + + function getElemWatchers(element) { + let isolateWatchers = getWatchersFromScope(element.data().$isolateScope); + let scopeWatchers = getWatchersFromScope(element.data().$scope); + let watchers = scopeWatchers.concat(isolateWatchers); + angular.forEach(element.children(), childElement => { + watchers = watchers.concat(getElemWatchers(angular.element(childElement))); + }); + return watchers; + } + + function getWatchersFromScope(scope) { + if (scope) + return scope.$$watchers || []; + return []; + } + + return getElemWatchers(root).length; +} +export default getWatchers; From c31d1ed88840d94369db0166aa79df859dee9090 Mon Sep 17 00:00:00 2001 From: Bernat Date: Mon, 30 Apr 2018 12:48:29 +0200 Subject: [PATCH 3/5] update fixtures and dumpedfixtures with table vn.state --- client/ticket/src/sale/sale.html | 2 +- client/ticket/src/sale/sale.js | 9 ++++++--- e2e/paths/ticket-module/03_list_sale.spec.js | 8 ++++---- gulpfile.js | 2 +- services/db/install/dump/fixtures.sql | 13 +++++++++---- services/db/install/install.sh | 13 ++++++------- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/client/ticket/src/sale/sale.html b/client/ticket/src/sale/sale.html index 94b6d06da..7b57f603a 100644 --- a/client/ticket/src/sale/sale.html +++ b/client/ticket/src/sale/sale.html @@ -1,4 +1,4 @@ - + diff --git a/client/ticket/src/sale/sale.js b/client/ticket/src/sale/sale.js index 71c8fb7ba..e9f7b4fb6 100644 --- a/client/ticket/src/sale/sale.js +++ b/client/ticket/src/sale/sale.js @@ -1,9 +1,12 @@ import ngModule from '../module'; +import FilterTicketList from '../filter-ticket-list'; -class Controller { - constructor($scope, $timeout) { +class Controller extends FilterTicketList { + constructor($scope, $timeout, $stateParams) { + super($scope, $timeout, $stateParams); this.$ = $scope; this.$timeout = $timeout; + this.onOrder('itemFk', 'ASC'); } showDescriptor(event, itemFk) { @@ -16,7 +19,7 @@ class Controller { } } -Controller.$inject = ['$scope', '$timeout']; +Controller.$inject = ['$scope', '$timeout', '$state']; ngModule.component('vnTicketSale', { template: require('./sale.html'), diff --git a/e2e/paths/ticket-module/03_list_sale.spec.js b/e2e/paths/ticket-module/03_list_sale.spec.js index aa151a783..983b45d67 100644 --- a/e2e/paths/ticket-module/03_list_sale.spec.js +++ b/e2e/paths/ticket-module/03_list_sale.spec.js @@ -52,10 +52,10 @@ describe('Ticket', () => { .getInnerText(selectors.ticketSales.firstSaleText) .then(value => { expect(value).toContain('Color Yellow'); - expect(value).toContain('2'); + expect(value).toContain('5'); expect(value).toContain('€1.50'); expect(value).toContain('0 %'); - expect(value).toContain('€3.00'); + expect(value).toContain('€7.50'); }); }); @@ -65,10 +65,10 @@ describe('Ticket', () => { .getInnerText(selectors.ticketSales.secondSaleText) .then(value => { expect(value).toContain('Color Yellow'); - expect(value).toContain('5'); + expect(value).toContain('2'); expect(value).toContain('€1.50'); expect(value).toContain('0 %'); - expect(value).toContain('€7.50'); + expect(value).toContain('€3.00'); }); }); }); diff --git a/gulpfile.js b/gulpfile.js index 9c82e608e..5d86d5972 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -435,7 +435,7 @@ gulp.task('docker-build', async () => { } catch (e) {} log('Building image...'); - await execP('docker build -t dblocal:latest ./services/db'); + log(await execP('docker build -t dblocal:latest ./services/db > ./services/db/docker.log')); }); /** diff --git a/services/db/install/dump/fixtures.sql b/services/db/install/dump/fixtures.sql index d8857ef27..49cd56143 100644 --- a/services/db/install/dump/fixtures.sql +++ b/services/db/install/dump/fixtures.sql @@ -115,6 +115,14 @@ INSERT INTO `vn`.`province`(`id`, `name`, `countryFk`, `warehouseFk`, `zoneFk`) (4, 'Province four', 1, NULL, 2), (5, 'Province five', 1, NULL, 1); +INSERT INTO `vn`.`agencyHour`(`id`, `agencyFk`, `weekDay`, `warehouseFk`, `provinceFk`, `maxHour`) + VALUES + ( 1, 2, 0, 1, 1, 13), + ( 2, 2, 1, 1, 1, 14), + ( 3, 2, 2, 1, 1, 15), + ( 4, 2, 3, 1, 1, 16), + ( 5, 2, 4, 1, 1, 17); + INSERT INTO `vn`.`clientType`(`id`, `code`, `type`) VALUES (1, 'normal', 'Normal'), @@ -578,7 +586,4 @@ INSERT INTO `cache`.`cache_calc`(`id`, `cache_id`, `cacheName`, `params`, `last_ INSERT INTO `bs`.`workerMana`(`workerFk`, `amount`) VALUES ( 1, -500), - ( 3, 0), - ( 5, 250), - ( 6, 1000), - ( 9, 1500); \ No newline at end of file + \ No newline at end of file diff --git a/services/db/install/install.sh b/services/db/install/install.sh index f38f6cd9f..b99c6e387 100644 --- a/services/db/install/install.sh +++ b/services/db/install/install.sh @@ -8,21 +8,20 @@ mysql -u root -proot -e "SET GLOBAL sql_mode='NO_ENGINE_SUBSTITUTION';" # Dump structure for file in dump/*-*.sql; do - echo "Imported $file" >> log.txt + echo "Imported $file" mysql -u root -proot < $file done # Import changes for file in changes/*/*.sql; do - echo "Imported $file" >> log.txt + echo "Imported $file" mysql -u root -proot < $file done # Import fixtures -echo "Imported fixtures.sql" >> log.txt -mysql -u root -proot < dump/fixtures.sql >> log.txt +echo "Imported fixtures.sql" +mysql -u root -proot < dump/fixtures.sql + # Remove installation -rm -rf changes dump install.sh - - +rm -rf changes dump install.sh \ No newline at end of file From a7e5f1a623d04b2946d0f9c324b191b311153912 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Mon, 30 Apr 2018 13:57:10 +0200 Subject: [PATCH 4/5] new component for infinite scroll vnAutoPaging --- .../client/src/greuge-list/greuge-list.html | 13 +- .../components/auto-paging/auto-paging.html | 7 ++ .../src/components/auto-paging/auto-paging.js | 118 ++++++++++++++++++ .../auto-paging/auto-paging.spec.js | 61 +++++++++ client/core/src/components/index.js | 1 + client/core/src/lib/filter-list.js | 5 +- client/core/src/lib/index.js | 1 + client/core/src/locale/en.yml | 3 +- client/core/src/locale/es.yml | 3 +- client/item/src/list/list.html | 5 +- client/item/src/list/list.js | 5 +- .../ticket/src/volume/ticket-volume.spec.js | 8 +- .../client/common/methods/greuge/filter.js | 6 +- .../loopback/common/methods/item/filter.js | 2 +- 14 files changed, 220 insertions(+), 18 deletions(-) create mode 100644 client/core/src/components/auto-paging/auto-paging.html create mode 100644 client/core/src/components/auto-paging/auto-paging.js create mode 100644 client/core/src/components/auto-paging/auto-paging.spec.js diff --git a/client/client/src/greuge-list/greuge-list.html b/client/client/src/greuge-list/greuge-list.html index 5122006e8..ea91180a3 100644 --- a/client/client/src/greuge-list/greuge-list.html +++ b/client/client/src/greuge-list/greuge-list.html @@ -14,11 +14,11 @@ - {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} - {{::greuge.description}} - {{::greuge.amount | number:2}} € - {{::greuge.greugeType.name}} + ng-repeat="greuge in $ctrl.instances track by $index"> + {{greuge.shipped | date:'dd/MM/yyyy HH:mm' }} + {{greuge.description}} + {{greuge.amount | number:2}} € + {{greuge.greugeType.name}} No results @@ -28,7 +28,8 @@ {{edit.model.sumAmount | number:2}} € - + + diff --git a/client/core/src/components/auto-paging/auto-paging.html b/client/core/src/components/auto-paging/auto-paging.html new file mode 100644 index 000000000..eee5ec1f4 --- /dev/null +++ b/client/core/src/components/auto-paging/auto-paging.html @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/client/core/src/components/auto-paging/auto-paging.js b/client/core/src/components/auto-paging/auto-paging.js new file mode 100644 index 000000000..5b8c85ce9 --- /dev/null +++ b/client/core/src/components/auto-paging/auto-paging.js @@ -0,0 +1,118 @@ +import ngModule from '../../module'; +import getWatchers from '../../lib/get-watchers'; + +class AutoPaging { + constructor($http, $window, $element, $timeout, vnApp, $translate) { + this.$http = $http; + this.$window = $window; + this.$element = $element; + this.$timeout = $timeout; + this.vnApp = vnApp; + this.$translate = $translate; + + this.numPerPage = null; + this.maxItems = 0; + this.watchScroll = false; + this.waitingNewPage = false; + + this.handlerScroll = this.onScroll.bind(this); + } + + get numPages() { + return this.numPerPage ? Math.ceil(this.maxItems / this.numPerPage) : 0; + } + + loadNewPage() { + this.index.filter.page++; + this.waitingNewPage = true; + + this.index.accept().then(res => { + this.$timeout(() => { + res.instances.forEach(item => { + this.items.push(item); + }); + this.checkWatchers(); + }); + if (this.index.filter.page == this.numPages) { + this.cancelScroll(); + } + this.waitingNewPage = false; + }); + } + + checkPosition() { + let element = this.$element[0].querySelector('vn-spinner'); + let position = element.getBoundingClientRect(); + if (this.currentPage < this.numPages && position.y < document.body.offsetHeight + 150 && !this.waitingNewPage) { + this.loadNewPage(); + } + } + + onScroll() { + this.checkPosition(); + } + + startScroll() { + this.watchScroll = true; + this.checkPosition(); + angular.element(this.$window).bind("wheel", this.handlerScroll); + } + + cancelScroll() { + this.watchScroll = false; + angular.element(this.$window).unbind("wheel", this.handlerScroll); + } + + checkScroll() { + if (this.numPages > this.currentPage && !this.watchScroll) { + this.startScroll(); + } else if (this.numPages <= this.currentPage && this.watchScroll) { + this.cancelScroll(); + } + } + + checkWatchers() { + let watchers = getWatchers(); + if (watchers > 3000 && this.watchScroll) { + this.cancelScroll(); + this.vnApp.showMessage( + this.$translate.instant('Auto-scroll interrupted, please adjust the search') + ); + } + } + + $onChanges(changes) { + if (!this.index) return; + + this.numPerPage = this.index.filter.size; + this.currentPage = this.index.filter.page; + this.currentInstances = this.items; + if (changes.total) + this.maxItems = changes.total.currentValue; + + this.checkScroll(); + } + + $postLink() { + this.checkScroll(); + } + + $doCheck() { + if (this.index && this.index.filter && this.index.filter.page && this.index.filter.page != this.currentPage) { + this.currentPage = this.index.filter.page; + this.checkScroll(); + } + } +} + +AutoPaging.$inject = ['$http', '$window', '$element', '$timeout', 'vnApp', '$translate']; + +ngModule.component('vnAutoPaging', { + template: require('./auto-paging.html'), + bindings: { + index: '<', + total: '<', + items: '<' + }, + controller: AutoPaging +}); diff --git a/client/core/src/components/auto-paging/auto-paging.spec.js b/client/core/src/components/auto-paging/auto-paging.spec.js new file mode 100644 index 000000000..e5070ffbb --- /dev/null +++ b/client/core/src/components/auto-paging/auto-paging.spec.js @@ -0,0 +1,61 @@ +import './auto-paging.js'; +import template from './auto-paging.html'; + +describe('Component vnAutoPaging', () => { + let $http; + let $window; + let $element; + let $timeout; + let controller; + + beforeEach(() => { + angular.mock.module('client'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_, _$window_, _$timeout_) => { + $http = _$httpBackend_; + $window = _$window_; + $timeout = _$timeout_; + $element = angular.element(`
${template}
`); + + controller = _$componentController_('vnAutoPaging', {$http, $window, $element, $timeout}); + })); + + describe('onChanges: actions when index object changes', () => { + beforeEach(() => { + controller.index = { + filter: { + size: 5, + page: 1 + } + }; + controller.items = [1, 2, 3, 4, 5]; + }); + + it('call startScroll() if there are pages to load', () => { + let changes = { + total: { + currentValue: 20 + } + }; + spyOn(controller, 'startScroll'); + + controller.$onChanges(changes); + + expect(controller.startScroll).toHaveBeenCalled(); + }); + + it('call stopScroll() if there are not pages to load', () => { + let changes = { + total: { + currentValue: 5 + } + }; + controller.watchScroll = true; + spyOn(controller, 'cancelScroll'); + controller.$onChanges(changes); + + expect(controller.cancelScroll).toHaveBeenCalled(); + }); + }); +}); diff --git a/client/core/src/components/index.js b/client/core/src/components/index.js index 2da08fd15..44a41911c 100644 --- a/client/core/src/components/index.js +++ b/client/core/src/components/index.js @@ -31,3 +31,4 @@ import './switch/switch'; import './float-button/float-button'; import './step-control/step-control'; import './label-value/label-value'; +import './auto-paging/auto-paging'; diff --git a/client/core/src/lib/filter-list.js b/client/core/src/lib/filter-list.js index 1c63414d7..d3f5d2963 100644 --- a/client/core/src/lib/filter-list.js +++ b/client/core/src/lib/filter-list.js @@ -9,6 +9,7 @@ export default class FilterList { this.waitingMgCrud = 0; this.modelId = $state.params.id; + this.instances = []; } onOrder(field, order) { this.filter(`${field} ${order}`); @@ -27,7 +28,9 @@ export default class FilterList { this.$.index.filter.order = order; } - this.$.index.accept(); + this.$.index.accept().then(res => { + this.instances = res.instances; + }); } else if (!this.modelId || !this.modelName) { throw new Error('Error: model not found'); } else if (this.waitingMgCrud > 3) { diff --git a/client/core/src/lib/index.js b/client/core/src/lib/index.js index 9df4b6911..77904844c 100644 --- a/client/core/src/lib/index.js +++ b/client/core/src/lib/index.js @@ -12,3 +12,4 @@ import './copy'; import './equals'; import './modified'; import './key-codes'; +import './get-watchers'; diff --git a/client/core/src/locale/en.yml b/client/core/src/locale/en.yml index 1c72342dd..3a06f2bd0 100644 --- a/client/core/src/locale/en.yml +++ b/client/core/src/locale/en.yml @@ -10,4 +10,5 @@ No more results: No more results Hide: Hide Next: Next Finalize: Finalize -Previous: Back \ No newline at end of file +Previous: Back +Auto-scroll interrupted, please adjust the search: Auto-scroll interrupted, please adjust the search \ No newline at end of file diff --git a/client/core/src/locale/es.yml b/client/core/src/locale/es.yml index 0f6d87d9f..4e826330b 100644 --- a/client/core/src/locale/es.yml +++ b/client/core/src/locale/es.yml @@ -10,4 +10,5 @@ No more results: No hay más resultados Hide: Ocultar Next: Siguiente Finalize: Finalizar -Previous: Anterior \ No newline at end of file +Previous: Anterior +Auto-scroll interrupted, please adjust the search: Auto-scroll interrumpido, por favor ajusta la búsqueda \ No newline at end of file diff --git a/client/item/src/list/list.html b/client/item/src/list/list.html index 50a35b930..a981f3716 100644 --- a/client/item/src/list/list.html +++ b/client/item/src/list/list.html @@ -15,11 +15,12 @@ - + + diff --git a/client/item/src/list/list.js b/client/item/src/list/list.js index 43d2a95e4..2f6a8819f 100644 --- a/client/item/src/list/list.js +++ b/client/item/src/list/list.js @@ -9,9 +9,12 @@ class ItemList { this.$scope = $scope; this.model = {}; this.itemSelected = null; + this.items = []; } search(index) { - index.accept(); + index.accept().then(res => { + this.items = res.instances; + }); } cloneItem(item) { this.itemSelected = item; diff --git a/client/ticket/src/volume/ticket-volume.spec.js b/client/ticket/src/volume/ticket-volume.spec.js index 7679167e1..bd367ee6c 100644 --- a/client/ticket/src/volume/ticket-volume.spec.js +++ b/client/ticket/src/volume/ticket-volume.spec.js @@ -16,8 +16,12 @@ describe('ticket', () => { $componentController = _$componentController_; $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); - $scope.index = {model: {instances: [{id: 1}, {id: 2}]}, accept: () => {}}; - $state = _$state_; + $scope.index = {model: {instances: [{id: 1}, {id: 2}]}, accept: () => { + return { + then: () => {} + }; + }}; + $state = _$state_; $state.params.id = 101; controller = $componentController('vnTicketVolume', {$scope: $scope}, {$httpBackend: $httpBackend}, {$state: $state}); })); diff --git a/services/client/common/methods/greuge/filter.js b/services/client/common/methods/greuge/filter.js index dba4e8ef6..0f3a71cef 100644 --- a/services/client/common/methods/greuge/filter.js +++ b/services/client/common/methods/greuge/filter.js @@ -6,9 +6,9 @@ module.exports = Self => { where: { clientFk: params.clientFk }, - skip: (params.page - 1) * params.size, - limit: params.size, - order: params.order || 'shipped DESC', + skip: (params.page - 1) * parseInt(params.size), + limit: parseInt(params.size), + order: `${params.order}, id ASC` || 'shipped DESC', include: { relation: "greugeType", scope: { diff --git a/services/loopback/common/methods/item/filter.js b/services/loopback/common/methods/item/filter.js index 72720ef45..f6170d6f4 100644 --- a/services/loopback/common/methods/item/filter.js +++ b/services/loopback/common/methods/item/filter.js @@ -6,7 +6,7 @@ module.exports = Self => { where: {}, skip: (params.page - 1) * params.size, limit: params.size, - order: params.order || 'name, relevancy DESC', + order: params.order || 'name ASC', // name, relevancy DESC include: { relation: 'itemType', scope: { From 33f7b2d45a8f18ca6aaa64c7e74d1664eda74a48 Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Mon, 30 Apr 2018 14:00:09 +0200 Subject: [PATCH 5/5] renamed action --- client/core/src/components/auto-paging/auto-paging.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/core/src/components/auto-paging/auto-paging.js b/client/core/src/components/auto-paging/auto-paging.js index 5b8c85ce9..892df0f1a 100644 --- a/client/core/src/components/auto-paging/auto-paging.js +++ b/client/core/src/components/auto-paging/auto-paging.js @@ -43,7 +43,8 @@ class AutoPaging { checkPosition() { let element = this.$element[0].querySelector('vn-spinner'); let position = element.getBoundingClientRect(); - if (this.currentPage < this.numPages && position.y < document.body.offsetHeight + 150 && !this.waitingNewPage) { + let isVisible = position.y < document.body.offsetHeight + 150; + if (this.currentPage < this.numPages && isVisible && !this.waitingNewPage) { this.loadNewPage(); } }