Merge pull request '2967-zone_deliverydays_keep_search_on_url' (#687) from 2967-zone_deliverydays_keep_search_on_url into dev
gitea/salix/pipeline/head This commit looks good Details

Reviewed-on: #687
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2021-07-02 07:16:24 +00:00
commit a29b1fbd8d
5 changed files with 129 additions and 61 deletions

View File

@ -22,17 +22,20 @@
"abstract": true,
"component": "vn-order",
"description": "Orders"
}, {
},
{
"url": "/index?q",
"state": "order.index",
"component": "vn-order-index",
"description": "Orders"
}, {
},
{
"url": "/:id",
"state": "order.card",
"abstract": true,
"component": "vn-order-card"
}, {
},
{
"url": "/summary",
"state": "order.card.summary",
"component": "vn-order-summary",
@ -40,7 +43,8 @@
"params": {
"order": "$ctrl.order"
}
}, {
},
{
"url": "/catalog?q&categoryId&typeId&tagGroups",
"state": "order.card.catalog",
"component": "vn-order-catalog",
@ -48,7 +52,8 @@
"params": {
"order": "$ctrl.order"
}
}, {
},
{
"url": "/volume",
"state": "order.card.volume",
"component": "vn-order-volume",
@ -56,7 +61,8 @@
"params": {
"order": "$ctrl.order"
}
}, {
},
{
"url": "/line",
"state": "order.card.line",
"component": "vn-order-line",
@ -64,12 +70,14 @@
"params": {
"order": "$ctrl.order"
}
}, {
},
{
"url": "/create?clientFk",
"state": "order.create",
"component": "vn-order-create",
"description": "New order"
}, {
},
{
"url": "/basic-data",
"state": "order.card.basicData",
"component": "vn-order-basic-data",

View File

@ -5,24 +5,28 @@
</vn-zone-calendar>
</div>
<vn-side-menu side="right">
<form ng-submit="$ctrl.onSubmit()" class="vn-pa-md">
<form ng-submit="$ctrl.fetchData()" class="vn-pa-md">
<vn-radio
label="Pick up"
val="pickUp"
ng-model="$ctrl.deliveryMethodFk">
ng-model="$ctrl.deliveryMethodFk"
on-change="$ctrl.agencyModeFk = null"
tabindex="-1">
</vn-radio>
<vn-radio
label="Delivery"
val="delivery"
ng-model="$ctrl.deliveryMethodFk"
class="vn-mb-sm">
on-change="$ctrl.agencyModeFk = null"
class="vn-mb-sm"
tabindex="-1">
</vn-radio>
<vn-autocomplete
vn-one
ng-if="$ctrl.deliveryMethodFk === 'delivery'"
vn-focus
label="Postcode"
ng-model="params.geoFk"
ng-model="$ctrl.geoFk"
url="Postcodes/location"
fields="['code','townFk']"
order="code, townFk"
@ -39,7 +43,7 @@
</vn-autocomplete>
<vn-autocomplete
label="{{$ctrl.deliveryMethodFk == 'delivery' ? 'Agency' : 'Warehouse'}}"
ng-model="params.agencyModeFk"
ng-model="$ctrl.agencyModeFk"
url="AgencyModes/isActive"
where="$ctrl.agencyFilter"
vn-id="agencymode">

View File

@ -4,20 +4,44 @@ import './style.scss';
class Controller extends Section {
$onInit() {
this.$.params = {};
this.setParams();
}
$postLink() {
this.deliveryMethodFk = 'delivery';
}
onSubmit() {
setParams() {
const hasParams = this.$params.deliveryMethodFk || this.$params.geoFk || this.$params.agencyModeFk;
if (hasParams) {
if (this.$params.deliveryMethodFk)
this.deliveryMethodFk = this.$params.deliveryMethodFk;
if (this.$params.geoFk)
this.geoFk = this.$params.geoFk;
if (this.$params.agencyModeFk)
this.agencyModeFk = this.$params.agencyModeFk;
this.fetchData();
}
}
fetchData() {
const params = {
deliveryMethodFk: this.deliveryMethodFk,
geoFk: this.geoFk,
agencyModeFk: this.agencyModeFk
};
this.$.data = null;
this.$http.get(`Zones/getEvents`, {params: this.$.params})
this.$http.get(`Zones/getEvents`, {params})
.then(res => {
let data = res.data;
this.$.data = data;
if (!data.events.length)
this.vnApp.showMessage(this.$t('No service for the specified zone'));
this.$state.go(this.$state.current.name, params);
});
}
@ -27,16 +51,16 @@ class Controller extends Section {
set deliveryMethodFk(value) {
this._deliveryMethodFk = value;
this.$.params.agencyModeFk = null;
let filter;
if (value === 'pickUp') {
if (value === 'pickUp')
filter = {where: {code: 'PICKUP'}};
this.$.agencymode.focus();
} else
else
filter = {where: {code: {inq: ['DELIVERY', 'AGENCY']}}};
this.$http.get(`DeliveryMethods`, {filter}).then(res => {
let deliveryMethods = res.data.map(deliveryMethod => deliveryMethod.id);
const deliveryMethods = res.data.map(deliveryMethod => deliveryMethod.id);
this.agencyFilter = {deliveryMethodFk: {inq: deliveryMethods}};
});
}

View File

@ -19,46 +19,67 @@ describe('Zone Component vnZoneDeliveryDays', () => {
}));
describe('deliveryMethodFk() setter', () => {
it(`should set the deliveryMethodFk property and check just agencymode focus`, () => {
controller.$.agencymode = {focus: jasmine.createSpy('focus')};
it('should set the deliveryMethodFk property as pickup and then perform a query that sets the filter', () => {
$httpBackend.expect('GET', 'DeliveryMethods').respond([{id: 999}]);
controller.deliveryMethodFk = 'pickUp';
expect(controller.$.agencymode.focus).toHaveBeenCalledWith();
});
it(`should set the deliveryMethodFk property, call method http and sets the agencyfilter`, () => {
$httpBackend.when('GET', 'DeliveryMethods').respond([{id: 'id'}]);
controller.deliveryMethodFk = 'no pickUp';
$httpBackend.flush();
expect(controller.agencyFilter).toEqual({deliveryMethodFk: {inq: ['id']}});
expect(controller.agencyFilter).toEqual({deliveryMethodFk: {inq: [999]}});
});
});
describe('onSubmit()', () => {
describe('setParams()', () => {
it('should do nothing when no params are received', () => {
controller.setParams();
expect(controller.deliveryMethodFk).toBeUndefined();
expect(controller.geoFk).toBeUndefined();
expect(controller.agencyModeFk).toBeUndefined();
});
it('should set the controller properties when the params are provided', () => {
controller.$params = {
deliveryMethodFk: 3,
geoFk: 2,
agencyModeFk: 1
};
controller.setParams();
expect(controller.deliveryMethodFk).toEqual(controller.$params.deliveryMethodFk);
expect(controller.geoFk).toEqual(controller.$params.geoFk);
expect(controller.agencyModeFk).toEqual(controller.$params.agencyModeFk);
});
});
describe('fetchData()', () => {
it('should make an HTTP GET query and then call the showMessage() method', () => {
jest.spyOn(controller.vnApp, 'showMessage');
jest.spyOn(controller.$state, 'go');
controller.agencyModeFk = 1;
controller.deliveryMethodFk = 2;
controller.geoFk = 3;
controller.$state.current.name = 'myState';
const expectedData = {events: []};
$httpBackend.when('GET', 'Zones/getEvents').respond({events: []});
controller.onSubmit();
const url = 'Zones/getEvents?agencyModeFk=1&deliveryMethodFk=2&geoFk=3';
$httpBackend.when('GET', 'DeliveryMethods').respond([]);
$httpBackend.expect('GET', url).respond({events: []});
controller.fetchData();
$httpBackend.flush();
expect(controller.$.data).toBeDefined();
expect(controller.$.data).toEqual(expectedData);
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No service for the specified zone');
});
it('should make an HTTP GET query and then set the data property', () => {
const expectedData = {events: [{zoneFk: 1}]};
$httpBackend.when('GET', 'Zones/getEvents').respond({events: [{zoneFk: 1}]});
controller.onSubmit();
$httpBackend.flush();
expect(controller.$.data).toBeDefined();
expect(controller.$.data).toEqual(expectedData);
expect(controller.$state.go).toHaveBeenCalledWith(
controller.$state.current.name,
{
agencyModeFk: 1,
deliveryMethodFk: 2,
geoFk: 3
}
);
});
});

View File

@ -28,33 +28,39 @@
"abstract": true,
"component": "vn-zone",
"description": "Zones"
}, {
},
{
"url": "/index?q",
"state": "zone.index",
"component": "vn-zone-index",
"description": "Zones"
}, {
"url": "/delivery-days?q",
},
{
"url": "/delivery-days?q&deliveryMethodFk&geoFk&agencyModeFk",
"state": "zone.deliveryDays",
"component": "vn-zone-delivery-days",
"description": "Delivery days"
}, {
},
{
"url": "/upcoming-deliveries",
"state": "zone.upcomingDeliveries",
"component": "vn-upcoming-deliveries",
"description": "Upcoming deliveries"
}, {
},
{
"url": "/create",
"state": "zone.create",
"component": "vn-zone-create",
"description": "New zone"
}, {
},
{
"url": "/:id",
"state": "zone.card",
"component": "vn-zone-card",
"abstract": true,
"description": "Detail"
}, {
},
{
"url": "/summary",
"state": "zone.card.summary",
"component": "vn-zone-summary",
@ -62,7 +68,8 @@
"params": {
"zone": "$ctrl.zone"
}
}, {
},
{
"url": "/basic-data",
"state": "zone.card.basicData",
"component": "vn-zone-basic-data",
@ -70,17 +77,20 @@
"params": {
"zone": "$ctrl.zone"
}
}, {
},
{
"url": "/warehouses",
"state": "zone.card.warehouses",
"component": "vn-zone-warehouses",
"description": "Warehouses"
}, {
},
{
"url": "/events",
"state": "zone.card.events",
"component": "vn-zone-events",
"description": "Calendar"
}, {
},
{
"url": "/location?q",
"state": "zone.card.location",
"component": "vn-zone-location",
@ -88,7 +98,8 @@
"params": {
"zone": "$ctrl.zone"
}
}, {
},
{
"url" : "/log",
"state": "zone.card.log",
"component": "vn-zone-log",