Merge pull request 'fixes #5070 route-tickets city is now a link to buscaman' (!1282) from 5070-route-tickets-link-maps into dev

Reviewed-on: #1282
Reviewed-by: Juan Ferrer <juan@verdnatura.es>
Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
Joan Sanchez 2023-03-02 06:33:03 +00:00
commit 8834d4d0a4
6 changed files with 65 additions and 17 deletions

View File

@ -93,7 +93,14 @@
<vn-tr ng-repeat="ticket in $ctrl.summary.tickets">
<vn-td shrink>{{ticket.priority | dashIfEmpty}}</vn-td>
<vn-td expand title="{{ticket.address.street}}">{{ticket.street}}</vn-td>
<vn-td expand>{{ticket.city}}</vn-td>
<vn-td
expand
ng-click="$ctrl.goToBuscaman(ticket)"
class="link"
vn-tooltip="Open buscaman"
tooltip-position="up">
{{::ticket.city}}
</vn-td>
<vn-td shrink>{{ticket.postalCode}}</vn-td>
<vn-td>
<span

View File

@ -31,6 +31,21 @@ class Controller extends Summary {
this.sumPackages();
});
}
goToBuscaman(ticket) {
if (!this.route.vehicleFk)
throw new UserError(`The route doesn't have a vehicle`);
let query = `Routes/${this.route.vehicleFk}/getDeliveryPoint`;
this.$http.get(query).then(response => {
if (!response.data)
throw new UserError(`The route's vehicle doesn't have a delivery point`);
const address = response.data + '+to:' + ticket.postalCode + ' ' + ticket.city + ' ' + ticket.street;
const url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
window.open(url + encodeURI(address), '_blank');
});
}
}
ngModule.vnComponent('vnRouteSummary', {

View File

@ -37,5 +37,29 @@ describe('Route', () => {
expect(controller.packagesTotal).toEqual(4);
});
});
describe('goToBuscaman()', () => {
it('should open buscaman with the given arguments', () => {
jest.spyOn(window, 'open').mockReturnThis();
const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460%20Av%20Espioca%20100+to:n19%20London%20my%20street';
controller.route = {vehicleFk: 1};
const url = `Routes/${controller.route.vehicleFk}/getDeliveryPoint`;
$httpBackend.when('GET', `Routes/1/summary`).respond();
$httpBackend.expectGET(url).respond('46460 Av Espioca 100');
const ticket = {
id: 1,
checked: true,
street: 'my street',
postalCode: 'n19',
city: 'London'
};
controller.goToBuscaman(ticket);
$httpBackend.flush();
expect(window.open).toHaveBeenCalledWith(expectedUrl, '_blank');
});
});
});
});

View File

@ -93,7 +93,14 @@
</vn-input-number>
</vn-td>
<vn-td expand title="{{::ticket.street}}">{{::ticket.street}}</vn-td>
<vn-td expand>{{::ticket.city}}</vn-td>
<vn-td
expand
ng-click="$ctrl.goToBuscaman(ticket)"
class="link"
vn-tooltip="Open buscaman"
tooltip-position="up">
{{::ticket.city}}
</vn-td>
<vn-td shrink>{{::ticket.postalCode}}</vn-td>
<vn-td expand>
<span

View File

@ -74,29 +74,24 @@ class Controller extends Section {
return selectedItems;
}
goToBuscaman() {
goToBuscaman(ticket) {
if (!this.route.vehicleFk)
throw new UserError(`The route doesn't have a vehicle`);
let query = `Routes/${this.route.vehicleFk}/getDeliveryPoint`;
this.$http.get(query).then(response => {
if (!response.data)
this.$http.get(`Routes/${this.route.vehicleFk}/getDeliveryPoint`).then(res => {
if (!res.data)
throw new UserError(`The route's vehicle doesn't have a delivery point`);
return response.data;
}).then(address => {
let addresses;
if (address) addresses = address;
let lines = this.getSelectedItems(this.tickets);
let url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
let addresses = res.data;
const lines = ticket ? [ticket] : this.getSelectedItems(this.tickets);
lines.forEach((line, index) => {
const previusLine = lines[index - 1] ? lines[index - 1].street : null;
if (previusLine != line.street)
const previousLine = lines[index - 1] ? lines[index - 1].street : null;
if (previousLine != line.street)
addresses = addresses + '+to:' + line.postalCode + ' ' + line.city + ' ' + line.street;
});
window.open(url + addresses, '_blank');
const url = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=';
window.open(url + encodeURI(addresses), '_blank');
});
}

View File

@ -136,7 +136,7 @@ describe('Route', () => {
describe('goToBuscaman()', () => {
it('should open buscaman with the given arguments', () => {
jest.spyOn(window, 'open').mockReturnThis();
const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460 Av Espioca 100+to:n19 London my street';
const expectedUrl = 'http://gps.buscalia.com/usuario/localizar.aspx?bmi=true&addr=46460%20Av%20Espioca%20100+to:n19%20London%20my%20street';
controller.route = {vehicleFk: 1};
const url = `Routes/${controller.route.vehicleFk}/getDeliveryPoint`;
$httpBackend.expectGET(url).respond('46460 Av Espioca 100');