Merge pull request '2692-add_advanced_search_engine2' (#519) from 2692-add_advanced_search_engine2 into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #519 Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
commit
1379b52d8a
|
@ -9,6 +9,7 @@
|
||||||
vn-focus
|
vn-focus
|
||||||
panel="vn-route-search-panel"
|
panel="vn-route-search-panel"
|
||||||
info="Search routes by id"
|
info="Search routes by id"
|
||||||
|
fetch-params="$ctrl.fetchParams($params)"
|
||||||
filter="$ctrl.filterParams"
|
filter="$ctrl.filterParams"
|
||||||
model="model">
|
model="model">
|
||||||
</vn-searchbar>
|
</vn-searchbar>
|
||||||
|
|
|
@ -3,16 +3,36 @@ import ModuleMain from 'salix/components/module-main';
|
||||||
|
|
||||||
export default class Route extends ModuleMain {
|
export default class Route extends ModuleMain {
|
||||||
$postLink() {
|
$postLink() {
|
||||||
let to = new Date();
|
const to = new Date();
|
||||||
to.setDate(to.getDate() + 1);
|
to.setDate(to.getDate() + 1);
|
||||||
to.setHours(0, 0, 0, 0);
|
to.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
let from = new Date();
|
const from = new Date();
|
||||||
|
from.setDate(from.getDate());
|
||||||
from.setHours(0, 0, 0, 0);
|
from.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
this.filterParams = {from, to, warehouseFk: this.vnConfig.warehouseFk};
|
this.filterParams = {from, to};
|
||||||
this.$.model.applyFilter(null, this.filterParams);
|
this.$.model.applyFilter(null, this.filterParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchParams($params) {
|
||||||
|
const hasEntries = Object.entries($params).length;
|
||||||
|
if (!hasEntries)
|
||||||
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnRoute', {
|
ngModule.vnComponent('vnRoute', {
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
import './index.js';
|
||||||
|
|
||||||
|
describe('Route Component vnRoute', () => {
|
||||||
|
let controller;
|
||||||
|
|
||||||
|
beforeEach(ngModule('route'));
|
||||||
|
|
||||||
|
beforeEach(inject($componentController => {
|
||||||
|
let $element = angular.element(`<div></div>`);
|
||||||
|
controller = $componentController('vnRoute', {$element});
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('fetchParams()', () => {
|
||||||
|
it('should return a range of dates with passed scope days', () => {
|
||||||
|
let params = controller.fetchParams({
|
||||||
|
scopeDays: 2
|
||||||
|
});
|
||||||
|
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);
|
||||||
|
|
||||||
|
const expectedParams = {
|
||||||
|
from,
|
||||||
|
scopeDays: params.scopeDays,
|
||||||
|
to
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(params).toEqual(expectedParams);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return default value for scope days', () => {
|
||||||
|
let params = controller.fetchParams({
|
||||||
|
scopeDays: 1
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(params.scopeDays).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a number value in scope days', () => {
|
||||||
|
let params = controller.fetchParams({
|
||||||
|
scopeDays: 2
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(params.scopeDays).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error when scope days is not equal a number', () => {
|
||||||
|
let params = controller.fetchParams({
|
||||||
|
scopeDays: 'ScopeDayNoNumber'
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(params.scopeDays).toBe('ScopeDayNoNumber');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="search-panel">
|
<div class="search-panel">
|
||||||
<form 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"
|
||||||
|
@ -9,7 +9,7 @@
|
||||||
vn-focus>
|
vn-focus>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal class="vn-px-lg">
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
ng-model="filter.workerFk"
|
ng-model="filter.workerFk"
|
||||||
|
@ -29,19 +29,37 @@
|
||||||
value-field="id">
|
value-field="id">
|
||||||
</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-autocomplete
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
label="Vehicle"
|
label="Vehicle"
|
||||||
|
@ -56,7 +74,7 @@
|
||||||
ng-model="filter.m3">
|
ng-model="filter.m3">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal class="vn-px-lg">
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-one
|
vn-one
|
||||||
label="Warehouse"
|
label="Warehouse"
|
||||||
|
@ -71,7 +89,7 @@
|
||||||
ng-model="filter.description">
|
ng-model="filter.description">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</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>
|
||||||
|
|
|
@ -1,7 +1,43 @@
|
||||||
import ngModule from '../module';
|
import ngModule from '../module';
|
||||||
import SearchPanel from 'core/components/searchbar/search-panel';
|
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', {
|
ngModule.vnComponent('vnRouteSearchPanel', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: SearchPanel
|
controller: Controller
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
import './index';
|
||||||
|
|
||||||
|
describe('Route Component vnRouteSearchPanel', () => {
|
||||||
|
let controller;
|
||||||
|
|
||||||
|
beforeEach(ngModule('route'));
|
||||||
|
|
||||||
|
beforeEach(inject($componentController => {
|
||||||
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -35,7 +35,7 @@
|
||||||
ng-model="filter.to"
|
ng-model="filter.to"
|
||||||
on-change="$ctrl.to = value">
|
on-change="$ctrl.to = value">
|
||||||
</vn-date-picker>
|
</vn-date-picker>
|
||||||
<vn-none class="or vn-px-md">O</vn-none>
|
<vn-none class="or vn-px-md" translate>Or</vn-none>
|
||||||
<vn-input-number
|
<vn-input-number
|
||||||
vn-one
|
vn-one
|
||||||
min="0"
|
min="0"
|
||||||
|
|
|
@ -18,3 +18,4 @@ DELIVERED: Servido
|
||||||
ON_PREPARATION: En preparacion
|
ON_PREPARATION: En preparacion
|
||||||
PACKED: Encajado
|
PACKED: Encajado
|
||||||
Cannot choose a range of dates and days onward at the same time: No se puede selecionar un rango de fechas y días en adelante a la vez
|
Cannot choose a range of dates and days onward at the same time: No se puede selecionar un rango de fechas y días en adelante a la vez
|
||||||
|
Or: O
|
Loading…
Reference in New Issue