refactor(ticket-popup): extends from dialog
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
b11a6a7c5c
commit
9c4d58fc1a
|
@ -70,11 +70,11 @@
|
|||
route="$ctrl.routeSelected">
|
||||
</vn-route-summary>
|
||||
</vn-popup>
|
||||
<vn-popup vn-id="ticketPopup">
|
||||
<vn-route-ticket-popup
|
||||
route="$ctrl.routeSelected">
|
||||
</vn-route-ticket-popup>
|
||||
</vn-popup>
|
||||
|
||||
<vn-route-ticket-popup
|
||||
vn-id="ticketPopup"
|
||||
route="$ctrl.routeSelected">
|
||||
</vn-route-ticket-popup>
|
||||
|
||||
<vn-worker-descriptor-popover
|
||||
vn-id="workerDescriptor">
|
||||
|
|
|
@ -1,84 +1,79 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="Routes/{{$ctrl.route.id}}/getSuggestedTickets"
|
||||
data="$ctrl.possibleTickets"
|
||||
auto-load="true">
|
||||
</vn-crud-model>
|
||||
<vn-card
|
||||
vn-id="possibleTicketsDialog"
|
||||
class="dialog">
|
||||
<tpl-title>
|
||||
<vn-horizontal>
|
||||
<span translate>Tickets to add</span>
|
||||
<div class="button-right">
|
||||
<vn-button label="Add" ng-click="$ctrl.setTicketsRoute()"></vn-button>
|
||||
</div>
|
||||
</vn-horizontal>
|
||||
</tpl-title>
|
||||
<tpl-body>
|
||||
<vn-data-viewer data="$ctrl.possibleTickets">
|
||||
<vn-table auto-load="true">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th shrink>
|
||||
<vn-multi-check
|
||||
model="model">
|
||||
</vn-multi-check>
|
||||
</vn-th>
|
||||
<vn-th number>Ticket</vn-th>
|
||||
<vn-th>Client</vn-th>
|
||||
<vn-th shrink>Province</vn-th>
|
||||
<vn-th shrink>
|
||||
<span translate>
|
||||
Population
|
||||
</span>
|
||||
</vn-th>
|
||||
<vn-th expand>PC</vn-th>
|
||||
<vn-th>Address</vn-th>
|
||||
<vn-th shrink>Warehouse</vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="ticket in $ctrl.possibleTickets">
|
||||
<vn-td shrink>
|
||||
<vn-check
|
||||
ng-model="ticket.checked">
|
||||
</vn-check>
|
||||
</vn-td>
|
||||
<vn-td number>
|
||||
<span class="link" ng-click="ticketDescriptor.show($event, ticket.id)">
|
||||
{{::ticket.id}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td expand>
|
||||
<span class="link" ng-click="clientDescriptor.show($event, ticket.clientFk)">
|
||||
{{::ticket.nickname}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td shrink>{{::ticket.address.province.name}}</vn-td>
|
||||
<vn-td shrink>{{::ticket.address.city}}</vn-td>
|
||||
<vn-td number shrink>{{::ticket.address.postalCode}}</vn-td>
|
||||
<vn-td expand title="{{::ticket.address.street}}">{{::ticket.address.street}}</vn-td>
|
||||
<vn-td expand>
|
||||
{{::ticket.zone.name}}
|
||||
<vn-icon-button
|
||||
icon="link_off"
|
||||
class="pointer"
|
||||
translate-attr="{title: 'Unlink zone: {{::ticket.zone.name}} from agency: {{::ticket.agencyMode.name}}'}"
|
||||
ng-click="unlinkZoneConfirmation.show(ticket)">
|
||||
</vn-icon-button>
|
||||
</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
</vn-table>
|
||||
</vn-data-viewer>
|
||||
</tpl-body>
|
||||
</vn-card>
|
||||
|
||||
<!-- Unlink zone confirmation dialog -->
|
||||
<vn-confirm
|
||||
vn-id="unlinkZoneConfirmation"
|
||||
on-accept="$ctrl.unlinkZone($data)"
|
||||
question="{{$ctrl.confirmationMessage}}"
|
||||
message="Unlink selected zone?">
|
||||
</vn-confirm>
|
||||
<tpl-title>
|
||||
<vn-horizontal>
|
||||
<span translate>Tickets to add</span>
|
||||
<div class="button-right">
|
||||
<vn-button label="Add" ng-click="$ctrl.setTicketsRoute()"></vn-button>
|
||||
</div>
|
||||
</vn-horizontal>
|
||||
</tpl-title>
|
||||
<tpl-body id="manifold-form">
|
||||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="Routes/{{$ctrl.route.id}}/getSuggestedTickets"
|
||||
data="$ctrl.possibleTickets"
|
||||
auto-load="true">
|
||||
</vn-crud-model>
|
||||
<vn-data-viewer data="$ctrl.possibleTickets" class="manifold-panel">
|
||||
<vn-table auto-load="true">
|
||||
<vn-thead>
|
||||
<vn-tr>
|
||||
<vn-th shrink>
|
||||
<vn-multi-check
|
||||
model="model">
|
||||
</vn-multi-check>
|
||||
</vn-th>
|
||||
<vn-th number>Ticket</vn-th>
|
||||
<vn-th>Client</vn-th>
|
||||
<vn-th shrink>Province</vn-th>
|
||||
<vn-th shrink>
|
||||
<span translate>
|
||||
Population
|
||||
</span>
|
||||
</vn-th>
|
||||
<vn-th expand>PC</vn-th>
|
||||
<vn-th>Address</vn-th>
|
||||
<vn-th shrink>Warehouse</vn-th>
|
||||
</vn-tr>
|
||||
</vn-thead>
|
||||
<vn-tbody>
|
||||
<vn-tr ng-repeat="ticket in $ctrl.possibleTickets">
|
||||
<vn-td shrink>
|
||||
<vn-check
|
||||
ng-model="ticket.checked">
|
||||
</vn-check>
|
||||
</vn-td>
|
||||
<vn-td number>
|
||||
<span class="link" ng-click="ticketDescriptor.show($event, ticket.id)">
|
||||
{{::ticket.id}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td expand>
|
||||
<span class="link" ng-click="clientDescriptor.show($event, ticket.clientFk)">
|
||||
{{::ticket.nickname}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td shrink>{{::ticket.address.province.name}}</vn-td>
|
||||
<vn-td shrink>{{::ticket.address.city}}</vn-td>
|
||||
<vn-td number shrink>{{::ticket.address.postalCode}}</vn-td>
|
||||
<vn-td expand title="{{::ticket.address.street}}">{{::ticket.address.street}}</vn-td>
|
||||
<vn-td expand>
|
||||
{{::ticket.zone.name}}
|
||||
<vn-icon-button
|
||||
icon="link_off"
|
||||
class="pointer"
|
||||
translate-attr="{title: 'Unlink zone: {{::ticket.zone.name}} from agency: {{::ticket.agencyMode.name}}'}"
|
||||
ng-click="unlinkZoneConfirmation.show(ticket)">
|
||||
</vn-icon-button>
|
||||
</vn-td>
|
||||
</vn-tr>
|
||||
</vn-tbody>
|
||||
</vn-table>
|
||||
</vn-data-viewer>
|
||||
<vn-confirm
|
||||
vn-id="unlinkZoneConfirmation"
|
||||
on-accept="$ctrl.unlinkZone($data)"
|
||||
question="{{$ctrl.confirmationMessage}}"
|
||||
message="Unlink selected zone?">
|
||||
</vn-confirm>
|
||||
</tpl-body>
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import ngModule from '../module';
|
||||
import Component from 'core/lib/component';
|
||||
import Dialog from 'core/components/dialog';
|
||||
import './style.scss';
|
||||
|
||||
export default class Controller extends Component {
|
||||
constructor($element, $scope) {
|
||||
super($element, $scope);
|
||||
class Controller extends Dialog {
|
||||
constructor($element, $, $transclude) {
|
||||
super($element, $, $transclude);
|
||||
}
|
||||
|
||||
getSelectedTickets(tickets) {
|
||||
|
@ -29,7 +29,7 @@ export default class Controller extends Component {
|
|||
}
|
||||
|
||||
setTicketsRoute() {
|
||||
let tickets = this.getSelectedTickets(this.possibleTickets);
|
||||
const tickets = this.getSelectedTickets(this.possibleTickets);
|
||||
if (tickets.length === 0) return;
|
||||
|
||||
const updates = [];
|
||||
|
@ -49,6 +49,7 @@ export default class Controller extends Component {
|
|||
.then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.updateVolume();
|
||||
this.hide();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -62,12 +63,14 @@ export default class Controller extends Component {
|
|||
this.$http.post(query, params).then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.$.model.refresh();
|
||||
this.hide();
|
||||
});
|
||||
}
|
||||
}
|
||||
Controller.$inject = ['$element', '$scope', '$transclude'];
|
||||
|
||||
ngModule.vnComponent('vnRouteTicketPopup', {
|
||||
template: require('./index.html'),
|
||||
slotTemplate: require('./index.html'),
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
route: '<',
|
||||
|
|
|
@ -12,7 +12,12 @@ describe('Route', () => {
|
|||
$httpBackend = _$httpBackend_;
|
||||
$scope = $rootScope.$new();
|
||||
const $element = angular.element('<vn-route-ticket-popup></vn-route-ticket-popup>');
|
||||
controller = $componentController('vnRouteTicketPopup', {$element, $scope});
|
||||
const $transclude = {
|
||||
$$boundTransclude: {
|
||||
$$slots: []
|
||||
}
|
||||
};
|
||||
controller = $componentController('vnRouteTicketPopup', {$element, $scope, $transclude});
|
||||
controller.route = {id: 1};
|
||||
controller.$.model = {
|
||||
refresh: () => {},
|
||||
|
@ -25,6 +30,7 @@ describe('Route', () => {
|
|||
it('should call the route unlink endpoint with the agency and zone ids', () => {
|
||||
controller.$.model = {refresh: jest.fn()};
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
jest.spyOn(controller, 'hide');
|
||||
|
||||
controller.route = {
|
||||
agencyModeFk: 1
|
||||
|
@ -43,6 +49,7 @@ describe('Route', () => {
|
|||
$httpBackend.flush();
|
||||
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
expect(controller.hide).toHaveBeenCalled();
|
||||
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
@ -50,11 +57,8 @@ describe('Route', () => {
|
|||
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];
|
||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||
jest.spyOn(controller, 'hide');
|
||||
|
||||
controller.route = {id: 111};
|
||||
|
||||
|
@ -65,19 +69,14 @@ describe('Route', () => {
|
|||
{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();
|
||||
$httpBackend.whenPOST(`Routes/${controller.route.id}/updateVolume`).respond(200);
|
||||
$httpBackend.expectPOST('Tickets/crud').respond();
|
||||
controller.setTicketsRoute();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$.model.data).toEqual(expectedResult);
|
||||
// expect(controller.$.possibleTicketsDialog.hide).toHaveBeenCalledWith();
|
||||
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
||||
expect(controller.hide).toHaveBeenCalled();
|
||||
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -116,12 +116,11 @@
|
|||
on-accept="$ctrl.removeTicketFromRoute($index)">
|
||||
</vn-confirm>
|
||||
|
||||
<vn-popup vn-id="ticketPopup">
|
||||
<vn-route-ticket-popup
|
||||
route="$ctrl.$params"
|
||||
parent-reload="$ctrl.$.model.refresh()">
|
||||
</vn-route-ticket-popup>
|
||||
</vn-popup>
|
||||
<vn-route-ticket-popup
|
||||
vn-id="ticketPopup"
|
||||
route="$ctrl.$params"
|
||||
parent-reload="$ctrl.$.model.refresh()">
|
||||
</vn-route-ticket-popup>
|
||||
|
||||
<vn-float-button
|
||||
icon="add"
|
||||
|
|
Loading…
Reference in New Issue