filter by selection + unit tests for travel index
This commit is contained in:
parent
5fb4442221
commit
8373c6f5d1
|
@ -31,8 +31,8 @@ describe('Component vnTicketIndex', () => {
|
||||||
|
|
||||||
describe('compareDate()', () => {
|
describe('compareDate()', () => {
|
||||||
it('should return warning when the date is the present', () => {
|
it('should return warning when the date is the present', () => {
|
||||||
let curDate = new Date();
|
let today = new Date();
|
||||||
let result = controller.compareDate(curDate);
|
let result = controller.compareDate(today);
|
||||||
|
|
||||||
expect(result).toEqual('warning');
|
expect(result).toEqual('warning');
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<vn-table model="model">
|
<vn-table model="model">
|
||||||
<vn-thead>
|
<vn-thead>
|
||||||
<vn-tr>
|
<vn-tr>
|
||||||
<vn-th field="id" number>Id</vn-th>
|
<vn-th field="id" number filter-enabled="false">Id</vn-th>
|
||||||
<vn-th field="ref">Reference</vn-th>
|
<vn-th field="ref">Reference</vn-th>
|
||||||
<vn-th field="agencyFk">Agency</vn-th>
|
<vn-th field="agencyFk">Agency</vn-th>
|
||||||
<vn-th field="warehouseOutFk">Warehouse Out</vn-th>
|
<vn-th field="warehouseOutFk">Warehouse Out</vn-th>
|
||||||
|
@ -26,13 +26,21 @@
|
||||||
class="clickable vn-tr search-result"
|
class="clickable vn-tr search-result"
|
||||||
ui-sref="travel.card.summary({id: {{::travel.id}}})">
|
ui-sref="travel.card.summary({id: {{::travel.id}}})">
|
||||||
<vn-td number>{{::travel.id}}</vn-td>
|
<vn-td number>{{::travel.id}}</vn-td>
|
||||||
<vn-td expand>{{::travel.ref}}</vn-td>
|
<vn-td>{{::travel.ref}}</vn-td>
|
||||||
<vn-td expand>{{::travel.agencyModeName}}</vn-td>
|
<vn-td>{{::travel.agencyModeName}}</vn-td>
|
||||||
<vn-td expand>{{::travel.warehouseOutName}}</vn-td>
|
<vn-td>{{::travel.warehouseOutName}}</vn-td>
|
||||||
<vn-td center expand>{{::travel.shipped | date:'dd/MM/yyyy'}}</vn-td>
|
<vn-td center expand>
|
||||||
<vn-td><vn-check ng-model="travel.isDelivered" disabled="true"></vn-check></vn-td>
|
<span class="chip {{$ctrl.compareDate(travel.shipped)}}">
|
||||||
|
{{::travel.shipped | date:'dd/MM/yyyy'}}
|
||||||
|
</span>
|
||||||
|
</vn-td>
|
||||||
|
<vn-td center><vn-check ng-model="travel.isDelivered" disabled="true"></vn-check></vn-td>
|
||||||
<vn-td expand>{{::travel.warehouseInName}}</vn-td>
|
<vn-td expand>{{::travel.warehouseInName}}</vn-td>
|
||||||
<vn-td center expand>{{::travel.landed | date:'dd/MM/yyyy'}}</vn-td>
|
<vn-td center expand>
|
||||||
|
<span class="chip {{$ctrl.compareDate(travel.landed)}}">
|
||||||
|
{{::travel.landed | date:'dd/MM/yyyy'}}
|
||||||
|
</span>
|
||||||
|
</vn-td>
|
||||||
<vn-td center><vn-check ng-model="travel.isReceived" disabled="true"></vn-check></vn-td>
|
<vn-td center><vn-check ng-model="travel.isReceived" disabled="true"></vn-check></vn-td>
|
||||||
<vn-td shrink>
|
<vn-td shrink>
|
||||||
<vn-horizontal class="buttons">
|
<vn-horizontal class="buttons">
|
||||||
|
@ -71,3 +79,27 @@
|
||||||
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>
|
||||||
|
</slot-menu>
|
||||||
|
</vn-contextmenu>
|
|
@ -18,6 +18,49 @@ export default class Controller extends Section {
|
||||||
});
|
});
|
||||||
this.$state.go('travel.create', {q: params});
|
this.$state.go('travel.create', {q: params});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compareDate(date) {
|
||||||
|
let today = new Date();
|
||||||
|
today.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
date = new Date(date);
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
|
const timeDifference = today - date;
|
||||||
|
if (timeDifference == 0) return 'warning';
|
||||||
|
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 'agencyFk':
|
||||||
|
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', {
|
||||||
|
|
|
@ -47,4 +47,32 @@ describe('Travel Component vnTravelIndex', () => {
|
||||||
expect(controller.$state.go).toHaveBeenCalledWith('travel.create', {q: queryParams});
|
expect(controller.$state.go).toHaveBeenCalledWith('travel.create', {q: queryParams});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('compareDate()', () => {
|
||||||
|
it('should return warning if the date passed to compareDate() is todays', () => {
|
||||||
|
const today = new Date();
|
||||||
|
|
||||||
|
const result = controller.compareDate(today);
|
||||||
|
|
||||||
|
expect(result).toEqual('warning');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return success if the date passed to compareDate() is in the future', () => {
|
||||||
|
const tomorrow = new Date();
|
||||||
|
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||||
|
|
||||||
|
const result = controller.compareDate(tomorrow);
|
||||||
|
|
||||||
|
expect(result).toEqual('success');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return undefined if the date passed to compareDate() is in the past', () => {
|
||||||
|
const yesterday = new Date();
|
||||||
|
yesterday.setDate(yesterday.getDate() - 1);
|
||||||
|
|
||||||
|
const result = controller.compareDate(yesterday);
|
||||||
|
|
||||||
|
expect(result).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue