diff --git a/modules/route/front/index.js b/modules/route/front/index.js
index 7c2a17483..10ccb0634 100644
--- a/modules/route/front/index.js
+++ b/modules/route/front/index.js
@@ -11,3 +11,4 @@ import './create';
import './basic-data';
import './log';
import './tickets';
+import './ticket-popup';
diff --git a/modules/route/front/index/index.html b/modules/route/front/index/index.html
index 5a503b149..b4f45e7b4 100644
--- a/modules/route/front/index/index.html
+++ b/modules/route/front/index/index.html
@@ -48,6 +48,11 @@
{{::route.m3 | dashIfEmpty}}
{{::route.description | dashIfEmpty}}
+
+
+
+
+
+
+
+
+
+
diff --git a/modules/route/front/index/index.js b/modules/route/front/index/index.js
index b94acb55a..69c4ee99a 100644
--- a/modules/route/front/index/index.js
+++ b/modules/route/front/index/index.js
@@ -13,6 +13,11 @@ export default class Controller extends Section {
this.$.summary.show();
}
+ showTicketPopup(route) {
+ this.routeSelected = route;
+ this.$.ticketPopup.show();
+ }
+
get checked() {
const rows = this.$.model.data || [];
const checkedRows = [];
diff --git a/modules/route/front/ticket-popup/index.html b/modules/route/front/ticket-popup/index.html
new file mode 100644
index 000000000..2f2971efc
--- /dev/null
+++ b/modules/route/front/ticket-popup/index.html
@@ -0,0 +1,84 @@
+
+
+
+
+
+ Tickets to add
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Ticket
+ Client
+ Province
+
+
+ Population
+
+
+ PC
+ Address
+ Warehouse
+
+
+
+
+
+
+
+
+
+
+ {{::ticket.id}}
+
+
+
+
+ {{::ticket.nickname}}
+
+
+ {{::ticket.address.province.name}}
+ {{::ticket.address.city}}
+ {{::ticket.address.postalCode}}
+ {{::ticket.address.street}}
+
+ {{::ticket.zone.name}}
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/modules/route/front/ticket-popup/index.js b/modules/route/front/ticket-popup/index.js
new file mode 100644
index 000000000..f2a9d1b55
--- /dev/null
+++ b/modules/route/front/ticket-popup/index.js
@@ -0,0 +1,77 @@
+import ngModule from '../module';
+import Component from 'core/lib/component';
+import './style.scss';
+
+export default class Controller extends Component {
+ constructor($element, $scope) {
+ super($element, $scope);
+ }
+
+ getSelectedTickets(tickets) {
+ const selectedTickets = [];
+
+ if (tickets) {
+ for (let i = 0; i < tickets.length; i++) {
+ if (tickets[i].checked)
+ selectedTickets.push(tickets[i]);
+ }
+ }
+ return selectedTickets;
+ }
+
+ updateVolume() {
+ let url = `Routes/${this.route.id}/updateVolume`;
+ this.$http.post(url).then(() => {
+ this.$.model.refresh();
+ if (this.parentReload)
+ this.parentReload();
+ });
+ }
+
+ setTicketsRoute() {
+ let tickets = this.getSelectedTickets(this.possibleTickets);
+ if (tickets.length === 0) return;
+
+ const updates = [];
+
+ for (let ticket of tickets) {
+ delete ticket.checked;
+ const update = {
+ where: {id: ticket.id},
+ data: {routeFk: this.route.id}
+ };
+
+ updates.push(update);
+ }
+
+ const data = {creates: [], updates: updates, deletes: []};
+ return this.$http.post(`Tickets/crud`, data)
+ .then(() => {
+ this.vnApp.showSuccess(this.$t('Data saved!'));
+ this.updateVolume();
+ });
+ }
+
+ unlinkZone(ticket) {
+ const params = {
+ agencyModeId: this.route.agencyModeFk,
+ zoneId: ticket.zoneFk,
+ };
+
+ const query = `Routes/unlink`;
+ this.$http.post(query, params).then(() => {
+ this.vnApp.showSuccess(this.$t('Data saved!'));
+ this.$.model.refresh();
+ });
+ }
+}
+
+ngModule.vnComponent('vnRouteTicketPopup', {
+ template: require('./index.html'),
+ controller: Controller,
+ bindings: {
+ route: '<',
+ model: '',
+ parentReload: '&'
+ }
+});
diff --git a/modules/route/front/ticket-popup/index.spec.js b/modules/route/front/ticket-popup/index.spec.js
new file mode 100644
index 000000000..0ab9393e3
--- /dev/null
+++ b/modules/route/front/ticket-popup/index.spec.js
@@ -0,0 +1,83 @@
+/* eslint max-len: ["error", { "code": 150 }]*/
+import './index';
+
+describe('Route', () => {
+ let controller;
+ let $httpBackend;
+ let $scope;
+
+ beforeEach(ngModule('route'));
+
+ beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
+ $httpBackend = _$httpBackend_;
+ $scope = $rootScope.$new();
+ const $element = angular.element('');
+ controller = $componentController('vnRouteTicketPopup', {$element, $scope});
+ controller.route = {id: 1};
+ controller.$.model = {
+ refresh: () => {},
+ remove: () => {}
+ };
+ controller.card = {reload: () => {}};
+ }));
+
+ describe('unlink()', () => {
+ it('should call the route unlink endpoint with the agency and zone ids', () => {
+ controller.$.model = {refresh: jest.fn()};
+ jest.spyOn(controller.vnApp, 'showSuccess');
+
+ controller.route = {
+ agencyModeFk: 1
+ };
+
+ const ticket = {
+ zoneFk: 2,
+ };
+ const params = {
+ agencyModeId: controller.route.agencyModeFk,
+ zoneId: ticket.zoneFk,
+ };
+
+ $httpBackend.expectPOST(`Routes/unlink`, params).respond('ok');
+ controller.unlinkZone(ticket);
+ $httpBackend.flush();
+
+ expect(controller.vnApp.showSuccess).toHaveBeenCalled();
+ expect(controller.$.model.refresh).toHaveBeenCalledWith();
+ });
+ });
+
+ describe('setTicketsRoute()', () => {
+ it('should perform a POST query to add tickets to the route', () => {
+ controller.$.model = {refresh: jest.fn()};
+
+ controller.route = {id: 1101};
+ controller.$.model.data = [{id: 1, checked: false}];
+
+ const existingTicket = controller.$.model.data[0];
+
+ controller.route = {id: 111};
+
+ controller.possibleTickets = [
+ {id: 2, checked: false},
+ {id: 3, checked: true},
+ {id: 4, checked: false},
+ {id: 5, checked: true},
+ ];
+
+ let expectedResult = [
+ existingTicket,
+ {id: 3},
+ {id: 5}
+ ];
+
+ $httpBackend.expectPOST(`Routes/${controller.route.id}/updateVolume`).respond(200);
+ $httpBackend.whenPOST('Tickets/crud').respond();
+ controller.setTicketsRoute();
+ $httpBackend.flush();
+
+ expect(controller.$.model.data).toEqual(expectedResult);
+ // expect(controller.$.possibleTicketsDialog.hide).toHaveBeenCalledWith();
+ });
+ });
+});
diff --git a/modules/route/front/ticket-popup/style.scss b/modules/route/front/ticket-popup/style.scss
new file mode 100644
index 000000000..77fa48f20
--- /dev/null
+++ b/modules/route/front/ticket-popup/style.scss
@@ -0,0 +1,5 @@
+@import "variables";
+
+.dialog{
+ padding: $float-spacing
+}
\ No newline at end of file
diff --git a/modules/route/front/tickets/index.html b/modules/route/front/tickets/index.html
index 970c7574b..83960d47d 100644
--- a/modules/route/front/tickets/index.html
+++ b/modules/route/front/tickets/index.html
@@ -115,83 +115,17 @@
question="Delete ticket from route?"
on-accept="$ctrl.removeTicketFromRoute($index)">
-
-
-
-
-
- Tickets to add
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Ticket
- Client
- Province
-
-
- Population
-
-
- PC
- Address
- Zone
-
-
-
-
-
-
-
-
-
-
- {{::ticket.id}}
-
-
-
-
- {{::ticket.nickname}}
-
-
- {{::ticket.address.province.name}}
- {{::ticket.address.city}}
- {{::ticket.address.postalCode}}
- {{::ticket.address.street}}
-
- {{::ticket.zone.name}}
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/modules/route/front/tickets/index.js b/modules/route/front/tickets/index.js
index e74cbcd40..b14b28ed6 100644
--- a/modules/route/front/tickets/index.js
+++ b/modules/route/front/tickets/index.js
@@ -4,14 +4,6 @@ import './style.scss';
import UserError from 'core/lib/user-error';
class Controller extends Section {
- get route() {
- return this._route;
- }
-
- set route(value) {
- this._route = value;
- }
-
get isChecked() {
if (this.tickets) {
for (let instance of this.tickets)
@@ -37,19 +29,6 @@ class Controller extends Section {
});
}
- unlinkZone(ticket) {
- const params = {
- agencyModeId: this.route.agencyModeFk,
- zoneId: ticket.zoneFk,
- };
-
- const query = `Routes/unlink`;
- this.$http.post(query, params).then(() => {
- this.vnApp.showSuccess(this.$t('Data saved!'));
- this.$.possibleTicketsModel.refresh();
- });
- }
-
getSelectedItems(items) {
const selectedItems = [];
@@ -117,38 +96,6 @@ class Controller extends Section {
});
}
- openPossibleTicketsDialog() {
- this.$.possibleTicketsModel.refresh();
- this.$.possibleTicketsDialog.show();
- }
-
- setTicketsRoute() {
- let tickets = this.getSelectedItems(this.possibleTickets);
- if (tickets.length === 0) return;
-
- const updates = [];
-
- for (let ticket of tickets) {
- delete ticket.checked;
- const update = {
- where: {id: ticket.id},
- data: {routeFk: this.route.id}
- };
-
- updates.push(update);
- }
-
- const data = {creates: [], updates: updates, deletes: []};
-
- return this.$http.post(`Tickets/crud`, data)
- .then(() => {
- this.$.model.data = this.$.model.data.concat(tickets);
- this.vnApp.showSuccess(this.$t('Data saved!'));
- this.updateVolume();
- this.$.possibleTicketsDialog.hide();
- });
- }
-
onDrop($event) {
const ticketId = $event.dataTransfer.getData('Text');
diff --git a/modules/route/front/tickets/index.spec.js b/modules/route/front/tickets/index.spec.js
index 092445e6f..82647d903 100644
--- a/modules/route/front/tickets/index.spec.js
+++ b/modules/route/front/tickets/index.spec.js
@@ -74,32 +74,6 @@ describe('Route', () => {
});
});
- describe('unlink()', () => {
- it('should call the route unlink endpoint with the agency and zone ids', () => {
- controller.$.possibleTicketsModel = {refresh: jest.fn()};
- jest.spyOn(controller.vnApp, 'showSuccess');
-
- controller.route = {
- agencyModeFk: 1
- };
-
- const ticket = {
- zoneFk: 2,
- };
- const params = {
- agencyModeId: controller.route.agencyModeFk,
- zoneId: ticket.zoneFk,
- };
-
- $httpBackend.expectPOST(`Routes/unlink`, params).respond('ok');
- controller.unlinkZone(ticket);
- $httpBackend.flush();
-
- expect(controller.vnApp.showSuccess).toHaveBeenCalled();
- expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith();
- });
- });
-
describe('getSelectedItems()', () => {
it('should return the selected items', () => {
let items = [
@@ -208,55 +182,6 @@ describe('Route', () => {
});
});
- describe('openPossibleTicketsDialog()', () => {
- it('should call both refresh and show methods in posible tickets model and dialog', () => {
- controller.$.possibleTicketsModel = {refresh: () => {}};
- jest.spyOn(controller.$.possibleTicketsModel, 'refresh');
- controller.$.possibleTicketsDialog = {show: () => {}};
- jest.spyOn(controller.$.possibleTicketsDialog, 'show');
-
- controller.openPossibleTicketsDialog();
-
- expect(controller.$.possibleTicketsModel.refresh).toHaveBeenCalledWith();
- expect(controller.$.possibleTicketsDialog.show).toHaveBeenCalledWith();
- });
- });
-
- describe('setTicketsRoute()', () => {
- it('should perform a POST query to add tickets to the route', () => {
- controller.$.possibleTicketsDialog = {hide: () => {}};
- jest.spyOn(controller.$.possibleTicketsDialog, 'hide');
-
- controller.$params = {id: 1101};
- controller.$.model.data = [{id: 1, checked: false}];
-
- const existingTicket = controller.$.model.data[0];
-
- controller.route = {id: 111};
-
- controller.possibleTickets = [
- {id: 2, checked: false},
- {id: 3, checked: true},
- {id: 4, checked: false},
- {id: 5, checked: true},
- ];
-
- let expectedResult = [
- existingTicket,
- {id: 3},
- {id: 5}
- ];
-
- $httpBackend.whenPOST(`Routes/${controller.$params.id}/updateVolume`).respond(200);
- $httpBackend.expectPOST('Tickets/crud').respond();
- controller.setTicketsRoute();
- $httpBackend.flush();
-
- expect(controller.$.model.data).toEqual(expectedResult);
- expect(controller.$.possibleTicketsDialog.hide).toHaveBeenCalledWith();
- });
- });
-
describe('onDrop()', () => {
it('should call the insert method when dragging a ticket number', () => {
jest.spyOn(controller, 'insert');