diff --git a/modules/item/front/request-search-panel/index.html b/modules/item/front/request-search-panel/index.html index 10d5f9762..7d3a9f1a5 100644 --- a/modules/item/front/request-search-panel/index.html +++ b/modules/item/front/request-search-panel/index.html @@ -1,6 +1,6 @@
-
- + + - + {{nickname}} - + - +
+ + ng-model="filter.from" + on-change="$ctrl.from = value"> + ng-model="filter.to" + on-change="$ctrl.to = value"> + Or + + + + - +
+ {{name}} - + diff --git a/modules/item/front/request-search-panel/index.js b/modules/item/front/request-search-panel/index.js index 823346e30..556bdd874 100644 --- a/modules/item/front/request-search-panel/index.js +++ b/modules/item/front/request-search-panel/index.js @@ -11,6 +11,35 @@ class Controller extends SearchPanel { {code: 'denied', name: this.$t('Denied')} ]; } + + 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('vnRequestSearchPanel', { diff --git a/modules/item/front/request-search-panel/index.spec.js b/modules/item/front/request-search-panel/index.spec.js new file mode 100644 index 000000000..2fb339209 --- /dev/null +++ b/modules/item/front/request-search-panel/index.spec.js @@ -0,0 +1,48 @@ +import './index'; + +describe(' Component vnRequestSearchPanel', () => { + let controller; + + beforeEach(ngModule('item')); + + beforeEach(inject($componentController => { + controller = $componentController('vnRequestSearchPanel', {$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(); + }); + }); +}); diff --git a/modules/item/front/request/index.html b/modules/item/front/request/index.html index 9b129a017..932d7cc91 100644 --- a/modules/item/front/request/index.html +++ b/modules/item/front/request/index.html @@ -10,9 +10,9 @@ diff --git a/modules/item/front/request/index.js b/modules/item/front/request/index.js index 231d5eda7..3916d20ef 100644 --- a/modules/item/front/request/index.js +++ b/modules/item/front/request/index.js @@ -16,13 +16,31 @@ export default class Controller extends Section { this.filterParams = { mine: true, - from: today, - to: nextWeek, + to: today, + from: nextWeek, state: 'pending' }; } } + 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; + } + getState(isOk) { if (isOk === null) return 'Pending';