This commit is contained in:
parent
8f2398bc8c
commit
0baccc4745
|
@ -105,32 +105,3 @@
|
||||||
question="Do you want to clone this travel?"
|
question="Do you want to clone this travel?"
|
||||||
message="All it's properties will be copied">
|
message="All it's properties will be copied">
|
||||||
</vn-confirm>
|
</vn-confirm>
|
||||||
<vn-contextmenu vn-id="contextmenu" targets="['vn-data-viewer']" model="model"
|
|
||||||
expr-builder="$ctrl.exprBuilder(param, value)">
|
|
||||||
<slot-menu>
|
|
||||||
<vn-item translate
|
|
||||||
ng-if="contextmenu.isFilterAllowed()"
|
|
||||||
ng-click="contextmenu.filterBySelection()">
|
|
||||||
Filter by selection
|
|
||||||
</vn-item>
|
|
||||||
<vn-item translate
|
|
||||||
ng-if="contextmenu.isFilterAllowed()"
|
|
||||||
ng-click="contextmenu.excludeSelection()">
|
|
||||||
Exclude selection
|
|
||||||
</vn-item>
|
|
||||||
<vn-item translate
|
|
||||||
ng-if="contextmenu.isFilterAllowed()"
|
|
||||||
ng-click="contextmenu.removeFilter()">
|
|
||||||
Remove filter
|
|
||||||
</vn-item>
|
|
||||||
<vn-item translate
|
|
||||||
ng-click="contextmenu.removeAllFilters()" >
|
|
||||||
Remove all filters
|
|
||||||
</vn-item>
|
|
||||||
<vn-item translate
|
|
||||||
ng-if="contextmenu.isActionAllowed()"
|
|
||||||
ng-click="contextmenu.copyValue()">
|
|
||||||
Copy value
|
|
||||||
</vn-item>
|
|
||||||
</slot-menu>
|
|
||||||
</vn-contextmenu>
|
|
||||||
|
|
|
@ -31,37 +31,6 @@ export default class Controller extends Section {
|
||||||
if (timeDifference == 0) return 'warning';
|
if (timeDifference == 0) return 'warning';
|
||||||
if (timeDifference < 0) return 'success';
|
if (timeDifference < 0) return 'success';
|
||||||
}
|
}
|
||||||
|
|
||||||
exprBuilder(param, value) {
|
|
||||||
switch (param) {
|
|
||||||
case 'search':
|
|
||||||
return /^\d+$/.test(value)
|
|
||||||
? {'t.id': value}
|
|
||||||
: {'t.ref': {like: `%${value}%`}};
|
|
||||||
case 'ref':
|
|
||||||
return {'t.ref': {like: `%${value}%`}};
|
|
||||||
case 'shipped':
|
|
||||||
return {'t.shipped': {between: this.dateRange(value)}};
|
|
||||||
case 'landed':
|
|
||||||
return {'t.landed': {between: this.dateRange(value)}};
|
|
||||||
case 'id':
|
|
||||||
case 'agencyModeFk':
|
|
||||||
case 'warehouseOutFk':
|
|
||||||
case 'warehouseInFk':
|
|
||||||
case 'totalEntries':
|
|
||||||
param = `t.${param}`;
|
|
||||||
return {[param]: value};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dateRange(value) {
|
|
||||||
const minHour = new Date(value);
|
|
||||||
minHour.setHours(0, 0, 0, 0);
|
|
||||||
const maxHour = new Date(value);
|
|
||||||
maxHour.setHours(23, 59, 59, 59);
|
|
||||||
|
|
||||||
return [minHour, maxHour];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnTravelIndex', {
|
ngModule.vnComponent('vnTravelIndex', {
|
||||||
|
|
|
@ -2,6 +2,9 @@ import ngModule from '../module';
|
||||||
import ModuleMain from 'salix/components/module-main';
|
import ModuleMain from 'salix/components/module-main';
|
||||||
|
|
||||||
export default class Travel extends ModuleMain {
|
export default class Travel extends ModuleMain {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnTravel', {
|
ngModule.vnComponent('vnTravel', {
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
import './index.js';
|
|
||||||
|
|
||||||
describe('Travel Component vnTravel', () => {
|
|
||||||
let controller;
|
|
||||||
|
|
||||||
beforeEach(ngModule('travel'));
|
|
||||||
|
|
||||||
beforeEach(inject($componentController => {
|
|
||||||
let $element = angular.element(`<div></div>`);
|
|
||||||
controller = $componentController('vnTravel', {$element});
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe('fetchParams()', () => {
|
|
||||||
it('should return a range of dates with passed scope days', () => {
|
|
||||||
let params = controller.fetchParams({
|
|
||||||
scopeDays: 2
|
|
||||||
});
|
|
||||||
const shippedFrom = Date.vnNew();
|
|
||||||
shippedFrom.setHours(0, 0, 0, 0);
|
|
||||||
const shippedTo = new Date(shippedFrom.getTime());
|
|
||||||
shippedTo.setDate(shippedTo.getDate() + params.scopeDays);
|
|
||||||
shippedTo.setHours(23, 59, 59, 999);
|
|
||||||
|
|
||||||
const expectedParams = {
|
|
||||||
shippedFrom,
|
|
||||||
scopeDays: params.scopeDays,
|
|
||||||
shippedTo
|
|
||||||
};
|
|
||||||
|
|
||||||
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 the given scope days', () => {
|
|
||||||
let params = controller.fetchParams({
|
|
||||||
scopeDays: 2
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(params.scopeDays).toEqual(2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -8,41 +8,31 @@ describe('Travel Component vnTravelSearchPanel', () => {
|
||||||
beforeEach(inject($componentController => {
|
beforeEach(inject($componentController => {
|
||||||
controller = $componentController('vnTravelSearchPanel', {$element: null});
|
controller = $componentController('vnTravelSearchPanel', {$element: null});
|
||||||
controller.$t = () => {};
|
controller.$t = () => {};
|
||||||
controller.filter = {};
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('shippedFrom() setter', () => {
|
describe('applyFilters()', () => {
|
||||||
it('should clear the scope days when setting the from property', () => {
|
it('should apply filters', async() => {
|
||||||
controller.filter.scopeDays = 1;
|
controller.filter = {foo: 'bar'};
|
||||||
|
controller.model = {
|
||||||
|
applyFilter: jest.fn().mockResolvedValue(),
|
||||||
|
_orgData: [{id: 1}]
|
||||||
|
};
|
||||||
|
controller.$state = {
|
||||||
|
current: {
|
||||||
|
name: 'foo'
|
||||||
|
},
|
||||||
|
go: jest.fn()
|
||||||
|
};
|
||||||
|
|
||||||
controller.shippedFrom = Date.vnNew();
|
await controller.applyFilters(true);
|
||||||
|
|
||||||
expect(controller.filter.scopeDays).toBeNull();
|
expect(controller.model.applyFilter).toHaveBeenCalledWith({}, controller.filter);
|
||||||
expect(controller.shippedFrom).toBeDefined();
|
expect(controller.$state.go).toHaveBeenCalledWith('travel.card.summary', {id: 1});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('shippedTo() setter', () => {
|
await controller.applyFilters(false);
|
||||||
it('should clear the scope days when setting the to property', () => {
|
|
||||||
controller.filter.scopeDays = 1;
|
|
||||||
|
|
||||||
controller.shippedTo = Date.vnNew();
|
expect(controller.$state.go).toHaveBeenCalledWith(controller.$state.current.name,
|
||||||
|
{q: JSON.stringify(controller.filter)}, {location: 'replace'});
|
||||||
expect(controller.filter.scopeDays).toBeNull();
|
|
||||||
expect(controller.shippedTo).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('scopeDays() setter', () => {
|
|
||||||
it('should clear the date range when setting the scopeDays property', () => {
|
|
||||||
controller.filter.shippedFrom = Date.vnNew();
|
|
||||||
controller.filter.shippedTo = Date.vnNew();
|
|
||||||
|
|
||||||
controller.scopeDays = 1;
|
|
||||||
|
|
||||||
expect(controller.filter.shippedFrom).toBeNull();
|
|
||||||
expect(controller.filter.shippedTo).toBeNull();
|
|
||||||
expect(controller.scopeDays).toBeDefined();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue