refactor ticket.basicData steps
gitea/salix/2041-ticket_datos_basico This commit looks good Details

This commit is contained in:
Bernat Exposito Domenech 2020-02-07 13:38:32 +01:00
parent 9918a5afbc
commit dd368a8c3f
14 changed files with 112 additions and 209 deletions

View File

@ -0,0 +1,5 @@
ALTER TABLE `vn`.`ticketUpdateAction`
ADD COLUMN `code` VARCHAR(45) NOT NULL AFTER `description`;
UPDATE `vn`.`ticketUpdateAction` SET `code`='changePrice' WHERE `id`='1';
UPDATE `vn`.`ticketUpdateAction` SET `code`='turnInMana' WHERE `id`='3';

View File

@ -471,7 +471,7 @@ export default {
nextStepButton: 'vn-step-control .buttons > section:last-child vn-button', nextStepButton: 'vn-step-control .buttons > section:last-child vn-button',
finalizeButton: 'vn-step-control .buttons > section:last-child button[type=submit]', finalizeButton: 'vn-step-control .buttons > section:last-child button[type=submit]',
stepTwoTotalPriceDif: 'vn-ticket-basic-data-step-two vn-tfoot > vn-tr > :nth-child(6)', stepTwoTotalPriceDif: 'vn-ticket-basic-data-step-two vn-tfoot > vn-tr > :nth-child(6)',
chargesReason: 'vn-autocomplete[ng-model="$ctrl.ticket.option"]', chargesReason: 'div:nth-child(3) > vn-radio > div',
}, },
ticketComponents: { ticketComponents: {
base: 'vn-ticket-components [name="base-sum"]' base: 'vn-ticket-components [name="base-sum"]'

View File

@ -80,15 +80,15 @@ describe('Ticket Edit basic data path', () => {
expect(result).toContain('-€248.00'); expect(result).toContain('-€248.00');
}); });
it(`should then click next to move on to step three`, async() => { // it(`should then click next to move on to step three`, async() => {
await page.waitToClick(selectors.ticketBasicData.nextStepButton); // await page.waitToClick(selectors.ticketBasicData.nextStepButton);
let url = await page.expectURL('data/step-three'); // let url = await page.expectURL('data/step-three');
expect(url).toBe(true); // expect(url).toBe(true);
}); // });
it(`should select a new reason for the changes made then click on finalize`, async() => { it(`should select a new reason for the changes made then click on finalize`, async() => {
await page.autocompleteSearch(selectors.ticketBasicData.chargesReason, 'Cambiar los precios en el ticket'); await page.waitToClick(selectors.ticketBasicData.chargesReason);
await page.waitToClick(selectors.ticketBasicData.finalizeButton); await page.waitToClick(selectors.ticketBasicData.finalizeButton);
let url = await page.expectURL('summary'); let url = await page.expectURL('summary');

View File

@ -1,28 +1,31 @@
{ {
"name": "TicketUpdateAction", "name": "TicketUpdateAction",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "ticketUpdateAction" "table": "ticketUpdateAction"
} }
}, },
"properties": { "properties": {
"id": { "id": {
"id": true, "id": true,
"type": "Number", "type": "Number",
"description": "Identifier" "description": "Identifier"
}, },
"description": { "description": {
"type": "String", "type": "String",
"required": true "required": true
} },
}, "code": {
"acls": [ "type": "String"
{ }
"accessType": "READ", },
"principalType": "ROLE", "acls": [
"principalId": "$everyone", {
"permission": "ALLOW" "accessType": "READ",
} "principalType": "ROLE",
] "principalId": "$everyone",
"permission": "ALLOW"
}
]
} }

View File

@ -3,9 +3,8 @@
step-count="10" step-count="10"
steps="[ steps="[
{name: 'Basic data', state: 'ticket.card.basicData.stepOne'}, {name: 'Basic data', state: 'ticket.card.basicData.stepOne'},
{name: 'Price difference', state: 'ticket.card.basicData.stepTwo'}, {name: 'Price difference', state: 'ticket.card.basicData.stepTwo'}]"
{name: 'Charge', state: 'ticket.card.basicData.stepThree'}]" on-step-change="$ctrl.onStepChange()"
on-step-change="$ctrl.onStepChange(state)"
on-step-end="$ctrl.onSubmit()"> on-step-end="$ctrl.onSubmit()">
</vn-step-control> </vn-step-control>
</vn-button-bar> </vn-button-bar>

View File

@ -16,8 +16,8 @@ class Controller {
this.child = child; this.child = child;
} }
onStepChange(state) { onStepChange() {
return this.child.onStepChange(state); return this.child.onStepChange();
} }
onSubmit() { onSubmit() {

View File

@ -1,14 +0,0 @@
<form name="form">
<vn-card class="vn-w-md vn-pa-lg">
<vn-horizontal>
<vn-autocomplete vn-one
url="TicketUpdateActions"
label="Charge difference to"
show-field="description"
value-field="id"
ng-model="$ctrl.ticket.option"
initial-data="$ctrl.ticket.option">
</vn-autocomplete>
</vn-horizontal>
</vn-card>
</form>

View File

@ -1,73 +0,0 @@
import ngModule from '../../module';
class Controller {
constructor($http, $scope, $state, $translate, vnApp) {
this.$http = $http;
this.$scope = $scope;
this.$state = $state;
this.$translate = $translate;
this.vnApp = vnApp;
}
$onInit() {
this.data.registerChild(this);
}
get ticket() {
return this._ticket;
}
set ticket(value) {
this._ticket = value;
if (value) this.ticket.option = 1;
}
onStepChange(state) {
return true;
}
onSubmit() {
if (!this.ticket.option) {
return this.vnApp.showError(
this.$translate.instant('Choose an option')
);
}
let query = `tickets/${this.ticket.id}/componentUpdate`;
let params = {
clientId: this.ticket.clientFk,
agencyModeId: this.ticket.agencyModeFk,
addressId: this.ticket.addressFk,
zoneId: this.ticket.zoneFk,
warehouseId: this.ticket.warehouseFk,
companyId: this.ticket.companyFk,
shipped: this.ticket.shipped,
landed: this.ticket.landed,
isDeleted: this.ticket.isDeleted,
option: this.ticket.option
};
this.$http.post(query, params).then(res => {
this.vnApp.showMessage(
this.$translate.instant(`The ticket has been unrouted`)
);
this.card.reload();
this.$state.go('ticket.card.summary', {id: this.$state.params.id});
});
}
}
Controller.$inject = ['$http', '$scope', '$state', '$translate', 'vnApp'];
ngModule.component('vnTicketBasicDataStepThree', {
template: require('./index.html'),
controller: Controller,
bindings: {
ticket: '<'
},
require: {
card: '^vnTicketCard',
data: '^vnTicketBasicData'
}
});

View File

@ -1,67 +0,0 @@
import './index.js';
describe('ticket', () => {
describe('Component vnTicketBasicDataStepThree', () => {
let now = Date.now();
let $state;
let controller;
let $httpBackend;
let vnApp;
beforeEach(ngModule('ticket'));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _vnApp_) => {
$state = _$state_;
spyOn($state, 'go');
vnApp = _vnApp_;
spyOn(vnApp, 'showError');
$httpBackend = _$httpBackend_;
controller = $componentController('vnTicketBasicDataStepThree', {$state});
}));
describe('onSubmit()', () => {
it(`should return an error if the item doesn't have option property in the controller`, () => {
controller._ticket = {id: 1};
controller.onSubmit();
expect(vnApp.showError).toHaveBeenCalledWith('Choose an option');
});
it('should perform a post query correctly then call two functions()', () => {
spyOn(controller.vnApp, 'showMessage');
controller.card = {reload: () => {}};
spyOn(controller.card, 'reload');
controller.ticket = {
id: 1,
agencyModeFk: 1,
addressFk: 121,
zoneFk: 3,
warehouseFk: 1,
shipped: now,
landed: now,
option: 1
};
let data = {
agencyModeId: 1,
addressId: 121,
zoneId: 3,
warehouseId: 1,
shipped: now,
landed: now,
option: 1
};
$httpBackend.whenPOST(`tickets/1/componentUpdate`, data).respond('ok');
$httpBackend.expectPOST(`tickets/1/componentUpdate`, data);
controller.onSubmit();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The ticket has been unrouted');
expect(controller.card.reload).toHaveBeenCalledWith();
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', jasmine.any(Object));
});
});
});
});

View File

@ -1,4 +0,0 @@
Charge: Cargo
Choose an option: Selecciona una opción
Charge difference to: Diferencia a cargo de
The ticket has been unrouted: El ticket ha sido desenrutado

View File

@ -1,3 +1,23 @@
<vn-crud-model
url="TicketUpdateActions"
data="ticketUpdateActions"
auto-load="true">
</vn-crud-model>
<vn-card class="vn-w-lg vn-pa-md vn-mb-md">
<h6
class="text-secondary"
style="font-weight: normal;"
translate>
Charge difference to
</h6>
<div ng-repeat="action in ticketUpdateActions">
<vn-radio
ng-model=$ctrl.ticket.option
label="{{action.description}}"
val={{action.id}}>
</vn-radio>
</div>
</vn-card>
<vn-card class="vn-w-lg"> <vn-card class="vn-w-lg">
<vn-table> <vn-table>
<vn-thead> <vn-thead>

View File

@ -1,8 +1,11 @@
import ngModule from '../../module'; import ngModule from '../../module';
class Controller { class Controller {
constructor($http) { constructor($http, $state, $translate, vnApp) {
this.$http = $http; this.$http = $http;
this.$state = $state;
this.$translate = $translate;
this.vnApp = vnApp;
} }
$onInit() { $onInit() {
@ -21,9 +24,18 @@ class Controller {
this.getTotalPrice(); this.getTotalPrice();
this.getTotalNewPrice(); this.getTotalNewPrice();
this.getTotalDifferenceOfPrice(); this.getTotalDifferenceOfPrice();
this.loadDefaultTicketAction();
} }
onStepChange(state) { loadDefaultTicketAction() {
let filter = {where: {code: 'changePrice'}};
this.$http.get(`TicketUpdateActions`, {filter}).then(response => {
return this.ticket.option = response.data[0].id;
});
}
onStepChange() {
return true; return true;
} }
@ -53,9 +65,39 @@ class Controller {
}); });
this.totalPriceDifference = totalPriceDifference; this.totalPriceDifference = totalPriceDifference;
} }
onSubmit() {
if (!this.ticket.option) {
return this.vnApp.showError(
this.$translate.instant('Choose an option')
);
}
let query = `tickets/${this.ticket.id}/componentUpdate`;
let params = {
clientId: this.ticket.clientFk,
agencyModeId: this.ticket.agencyModeFk,
addressId: this.ticket.addressFk,
zoneId: this.ticket.zoneFk,
warehouseId: this.ticket.warehouseFk,
companyId: this.ticket.companyFk,
shipped: this.ticket.shipped,
landed: this.ticket.landed,
isDeleted: this.ticket.isDeleted,
option: parseInt(this.ticket.option)
};
this.$http.post(query, params).then(res => {
this.vnApp.showMessage(
this.$translate.instant(`The ticket has been unrouted`)
);
this.card.reload();
this.$state.go('ticket.card.summary', {id: this.$state.params.id});
});
}
} }
Controller.$inject = ['$http']; Controller.$inject = ['$http', '$state', '$translate', 'vnApp'];
ngModule.component('vnTicketBasicDataStepTwo', { ngModule.component('vnTicketBasicDataStepTwo', {
template: require('./index.html'), template: require('./index.html'),
@ -64,6 +106,7 @@ ngModule.component('vnTicketBasicDataStepTwo', {
ticket: '<' ticket: '<'
}, },
require: { require: {
card: '^vnTicketCard',
data: '^vnTicketBasicData' data: '^vnTicketBasicData'
} }
}); });

View File

@ -13,7 +13,6 @@ import './summary';
import './basic-data'; import './basic-data';
import './basic-data/step-one'; import './basic-data/step-one';
import './basic-data/step-two'; import './basic-data/step-two';
import './basic-data/step-three';
import './note'; import './note';
import './expedition'; import './expedition';
import './volume'; import './volume';

View File

@ -79,14 +79,6 @@
"params": { "params": {
"ticket": "$ctrl.data" "ticket": "$ctrl.data"
} }
}, {
"url" : "/step-three",
"state": "ticket.card.basicData.stepThree",
"component": "vn-ticket-basic-data-step-three",
"description": "Charge",
"params": {
"ticket": "$ctrl.data"
}
}, { }, {
"url" : "/sale", "url" : "/sale",
"state": "ticket.card.sale", "state": "ticket.card.sale",