diff --git a/modules/route/front/main/index.html b/modules/route/front/main/index.html index 16243be03..7be7153af 100644 --- a/modules/route/front/main/index.html +++ b/modules/route/front/main/index.html @@ -9,7 +9,8 @@ vn-focus panel="vn-route-search-panel" info="Search routes by id" - filter="$ctrl.filterParams" + fetch-params="$ctrl.fetchParams($params)" + suggested-filter="$ctrl.filterParams" model="model"> diff --git a/modules/route/front/main/index.js b/modules/route/front/main/index.js index a6d5bedd1..0f30707e9 100644 --- a/modules/route/front/main/index.js +++ b/modules/route/front/main/index.js @@ -2,16 +2,30 @@ import ngModule from '../module'; import ModuleMain from 'salix/components/module-main'; export default class Route extends ModuleMain { - $postLink() { - let to = new Date(); - to.setDate(to.getDate() + 1); - to.setHours(0, 0, 0, 0); + constructor() { + super(); - let from = new Date(); - from.setHours(0, 0, 0, 0); + this.filterParams = { + scopeDays: 1 + }; + } - this.filterParams = {from, to, warehouseFk: this.vnConfig.warehouseFk}; - this.$.model.applyFilter(null, this.filterParams); + fetchParams($params) { + if (!Object.entries($params).length) + $params.scopeDays = 1; + + if (typeof $params.scopeDays === 'number') { + const from = new Date(); + from.setHours(0, 0, 0, 0); + + const to = new Date(from.getTime()); + to.setDate(to.getDate() + $params.scopeDays); + to.setHours(23, 59, 59, 999); + + Object.assign($params, {from, to}); + } + + return $params; } } diff --git a/modules/route/front/search-panel/index.html b/modules/route/front/search-panel/index.html index 2c7dd93b2..dc41e95fd 100644 --- a/modules/route/front/search-panel/index.html +++ b/modules/route/front/search-panel/index.html @@ -1,6 +1,6 @@
-
- + + - + - - - - - - - +
+ + + + + + O + + + + + +
+ - + - + diff --git a/modules/route/front/search-panel/index.js b/modules/route/front/search-panel/index.js index d2de05709..b5abbd94a 100644 --- a/modules/route/front/search-panel/index.js +++ b/modules/route/front/search-panel/index.js @@ -1,7 +1,43 @@ import ngModule from '../module'; import SearchPanel from 'core/components/searchbar/search-panel'; +class Controller extends SearchPanel { + constructor($, $element) { + super($, $element); + this.filter = this.$.filter; + } + + get from() { + return this._from; + } + + set from(value) { + this._from = value; + this.filter.scopeDays = null; + } + + get to() { + return this._to; + } + + set to(value) { + this._to = value; + this.filter.scopeDays = null; + } + + get scopeDays() { + return this._scopeDays; + } + + set scopeDays(value) { + this._scopeDays = value; + + this.filter.from = null; + this.filter.to = null; + } +} + ngModule.vnComponent('vnRouteSearchPanel', { template: require('./index.html'), - controller: SearchPanel + controller: Controller }); diff --git a/modules/route/front/search-panel/index.spec.js b/modules/route/front/search-panel/index.spec.js new file mode 100644 index 000000000..cb75e3ff5 --- /dev/null +++ b/modules/route/front/search-panel/index.spec.js @@ -0,0 +1,48 @@ +import './index'; + +describe('Route Component vnRouteSearchPanel', () => { + let controller; + + beforeEach(ngModule('route')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + controller = $componentController('vnRouteSearchPanel', {$element: null}); + controller.$t = () => {}; + controller.filter = {}; + })); + + describe('from() setter', () => { + it('should clear the scope days when setting the from property', () => { + controller.filter.scopeDays = 1; + + controller.from = new Date(); + + expect(controller.filter.scopeDays).toBeNull(); + expect(controller.from).toBeDefined(); + }); + }); + + describe('to() setter', () => { + it('should clear the scope days when setting the to property', () => { + controller.filter.scopeDays = 1; + + controller.to = new Date(); + + expect(controller.filter.scopeDays).toBeNull(); + expect(controller.to).toBeDefined(); + }); + }); + + describe('scopeDays() setter', () => { + it('should clear the date range when setting the scopeDays property', () => { + controller.filter.from = new Date(); + controller.filter.to = new Date(); + + controller.scopeDays = 1; + + expect(controller.filter.from).toBeNull(); + expect(controller.filter.to).toBeNull(); + expect(controller.scopeDays).toBeDefined(); + }); + }); +});