Merge pull request '2820 Added scope days on item request section + test' (#556) from 2820-add_item_scopeDays into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #556
Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
Carlos Jimenez Ruiz 2021-02-25 11:28:29 +00:00
commit 0c4c2b0df4
5 changed files with 124 additions and 11 deletions

View File

@ -1,6 +1,6 @@
<div class="search-panel"> <div class="search-panel">
<form class="vn-pa-lg" ng-submit="$ctrl.onSearch()"> <form id="manifold-form" ng-submit="$ctrl.onSearch()">
<vn-horizontal> <vn-horizontal class="vn-px-lg vn-pt-lg">
<vn-textfield <vn-textfield
vn-one vn-one
label="General search" label="General search"
@ -8,7 +8,7 @@
vn-focus> vn-focus>
</vn-textfield> </vn-textfield>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal class="vn-px-lg">
<vn-textfield <vn-textfield
vn-one vn-one
label="Ticket id" label="Ticket id"
@ -25,7 +25,7 @@
<tpl-item>{{nickname}}</tpl-item> <tpl-item>{{nickname}}</tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal class="vn-px-lg">
<vn-textfield <vn-textfield
vn-one vn-one
label="Client id" label="Client id"
@ -38,19 +38,37 @@
url="Warehouses"> url="Warehouses">
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <section class="vn-px-md">
<vn-horizontal class="manifold-panel vn-pa-md">
<vn-date-picker <vn-date-picker
vn-one vn-one
label="From" label="From"
ng-model="filter.from"> ng-model="filter.from"
on-change="$ctrl.from = value">
</vn-date-picker> </vn-date-picker>
<vn-date-picker <vn-date-picker
vn-one vn-one
label="To" label="To"
ng-model="filter.to"> ng-model="filter.to"
on-change="$ctrl.to = value">
</vn-date-picker> </vn-date-picker>
<vn-none class="or vn-px-md" translate>Or</vn-none>
<vn-input-number
vn-one
min="0"
step="1"
label="Days onward"
ng-model="filter.scopeDays"
on-change="$ctrl.scopeDays = value"
display-controls="true">
</vn-input-number>
<vn-icon color-marginal
icon="info"
vn-tooltip="Cannot choose a range of dates and days onward at the same time">
</vn-icon>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> </section>
<vn-horizontal class="vn-px-lg">
<vn-check vn-one <vn-check vn-one
triple-state="true" triple-state="true"
label="For me" label="For me"
@ -65,7 +83,7 @@
<tpl-item>{{name}}</tpl-item> <tpl-item>{{name}}</tpl-item>
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal class="vn-mt-lg"> <vn-horizontal class="vn-px-lg vn-pb-lg vn-mt-lg">
<vn-submit label="Search"></vn-submit> <vn-submit label="Search"></vn-submit>
</vn-horizontal> </vn-horizontal>
</form> </form>

View File

@ -11,6 +11,35 @@ class Controller extends SearchPanel {
{code: 'denied', name: this.$t('Denied')} {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', { ngModule.vnComponent('vnRequestSearchPanel', {

View File

@ -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();
});
});
});

View File

@ -10,9 +10,10 @@
<vn-portal slot="topbar"> <vn-portal slot="topbar">
<vn-searchbar <vn-searchbar
panel="vn-request-search-panel" panel="vn-request-search-panel"
suggested-filter="$ctrl.filterParams"
info="Search request by id or alias" info="Search request by id or alias"
suggested-filter="$ctrl.filterParams"
filter="$ctrl.filterParams" filter="$ctrl.filterParams"
fetch-params="$ctrl.fetchParams($params)"
model="model" model="model"
auto-state="false"> auto-state="false">
</vn-searchbar> </vn-searchbar>

View File

@ -15,7 +15,6 @@ export default class Controller extends Section {
nextWeek.setDate(nextWeek.getDate() + 7); nextWeek.setDate(nextWeek.getDate() + 7);
this.filterParams = { this.filterParams = {
mine: true,
from: today, from: today,
to: nextWeek, to: nextWeek,
state: 'pending' state: 'pending'
@ -23,6 +22,24 @@ export default class Controller extends Section {
} }
} }
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) { getState(isOk) {
if (isOk === null) if (isOk === null)
return 'Pending'; return 'Pending';