2509 - Added forms to create new locations + e2e #412
|
@ -0,0 +1,3 @@
|
||||||
|
UPDATE `salix`.`ACL` SET `principalId` = 'deliveryBoss' WHERE (`id` = '194');
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Town', '*', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss');
|
||||||
|
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('Province', '*', 'WRITE', 'ALLOW', 'ROLE', 'deliveryBoss');
|
|
@ -42,13 +42,24 @@ export default {
|
||||||
taxNumber: 'vn-client-create vn-textfield[ng-model="$ctrl.client.fi"]',
|
taxNumber: 'vn-client-create vn-textfield[ng-model="$ctrl.client.fi"]',
|
||||||
socialName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.socialName"]',
|
socialName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.socialName"]',
|
||||||
street: 'vn-client-create vn-textfield[ng-model="$ctrl.client.street"]',
|
street: 'vn-client-create vn-textfield[ng-model="$ctrl.client.street"]',
|
||||||
|
addPostCode: 'vn-client-create vn-datalist[ng-model="$ctrl.client.postcode"] vn-icon-button[icon="add_circle"]',
|
||||||
|
addProvince: 'vn-autocomplete[ng-model="$ctrl.location.provinceFk"] vn-icon-button[icon="add_circle"]',
|
||||||
|
addCity: 'vn-autocomplete[ng-model="$ctrl.location.townFk"] vn-icon-button[icon="add_circle"]',
|
||||||
|
newProvinceName: 'vn-textfield[ng-model="$ctrl.province.name"]',
|
||||||
|
newCityName: 'vn-textfield[ng-model="$ctrl.city.name"]',
|
||||||
|
newCityProvince: 'vn-autocomplete[ng-model="$ctrl.city.provinceFk"]',
|
||||||
|
newPostcode: 'vn-textfield[ng-model="$ctrl.location.code"]',
|
||||||
postcode: 'vn-client-create vn-datalist[ng-model="$ctrl.client.postcode"]',
|
postcode: 'vn-client-create vn-datalist[ng-model="$ctrl.client.postcode"]',
|
||||||
city: 'vn-client-create vn-datalist[ng-model="$ctrl.client.city"]',
|
city: 'vn-client-create vn-datalist[ng-model="$ctrl.client.city"]',
|
||||||
province: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.provinceFk"]',
|
province: 'vn-autocomplete[ng-model="$ctrl.client.provinceFk"]',
|
||||||
country: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.countryFk"]',
|
country: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.countryFk"]',
|
||||||
|
dialogCountry: 'vn-autocomplete[ng-model="$ctrl.province.countryFk"]',
|
||||||
userName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.userName"]',
|
userName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.userName"]',
|
||||||
email: 'vn-client-create vn-textfield[ng-model="$ctrl.client.email"]',
|
email: 'vn-client-create vn-textfield[ng-model="$ctrl.client.email"]',
|
||||||
salesPerson: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.salesPersonFk"]',
|
salesPerson: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.salesPersonFk"]',
|
||||||
|
saveNewProvicenButton: '#saveProvince',
|
||||||
|
saveNewCityButton: '#saveCity',
|
||||||
|
saveNewPoscode: '#savePostcode',
|
||||||
createButton: 'vn-client-create button[type=submit]'
|
createButton: 'vn-client-create button[type=submit]'
|
||||||
},
|
},
|
||||||
clientDescriptor: {
|
clientDescriptor: {
|
||||||
|
|
|
@ -8,7 +8,7 @@ describe('Client create path', () => {
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
browser = await getBrowser();
|
browser = await getBrowser();
|
||||||
page = browser.page;
|
page = browser.page;
|
||||||
await page.loginAndModule('employee', 'client');
|
await page.loginAndModule(' deliveryBoss', 'client');
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async() => {
|
afterAll(async() => {
|
||||||
|
@ -45,14 +45,40 @@ describe('Client create path', () => {
|
||||||
expect(message.text).toBe('Some fields are invalid');
|
expect(message.text).toBe('Some fields are invalid');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it(`should create a new province`, async() => {
|
||||||
|
await page.waitToClick(selectors.createClientView.addPostCode);
|
||||||
|
await page.waitToClick(selectors.createClientView.addProvince);
|
||||||
|
await page.write(selectors.createClientView.newProvinceName, 'Massachusetts');
|
||||||
|
await page.autocompleteSearch(selectors.createClientView.dialogCountry, 'España');
|
||||||
|
await page.waitToClick(selectors.createClientView.saveNewProvicenButton);
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
expect(message.text).toBe('The province has been created');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should create a new city`, async() => {
|
||||||
|
await page.waitToClick(selectors.createClientView.addCity);
|
||||||
|
await page.write(selectors.createClientView.newCityName, 'Boston');
|
||||||
|
await page.autocompleteSearch(selectors.createClientView.newCityProvince, 'Massachusetts');
|
||||||
|
await page.waitToClick(selectors.createClientView.saveNewCityButton);
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
expect(message.text).toBe('The city has been created');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should create a new post code`, async() => {
|
||||||
|
await page.write(selectors.createClientView.newPostcode, '61616');
|
||||||
|
await page.waitToClick(selectors.createClientView.saveNewPoscode);
|
||||||
|
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
expect(message.text).toBe('The postcode has been created. You can save the data now');
|
||||||
|
});
|
||||||
|
|
||||||
it(`should attempt to create a new user with all it's data but wrong email`, async() => {
|
it(`should attempt to create a new user with all it's data but wrong email`, async() => {
|
||||||
await page.write(selectors.createClientView.name, 'Carol Danvers');
|
await page.write(selectors.createClientView.name, 'Carol Danvers');
|
||||||
await page.write(selectors.createClientView.socialName, 'AVG tax');
|
await page.write(selectors.createClientView.socialName, 'AVG tax');
|
||||||
await page.write(selectors.createClientView.street, 'Many places');
|
await page.write(selectors.createClientView.street, 'Many places');
|
||||||
await page.autocompleteSearch(selectors.createClientView.country, 'España');
|
|
||||||
await page.autocompleteSearch(selectors.createClientView.province, 'Province one');
|
|
||||||
await page.write(selectors.createClientView.city, 'Valencia');
|
|
||||||
await page.write(selectors.createClientView.postcode, '46000');
|
|
||||||
await page.clearInput(selectors.createClientView.email);
|
await page.clearInput(selectors.createClientView.email);
|
||||||
await page.write(selectors.createClientView.email, 'incorrect email format');
|
await page.write(selectors.createClientView.email, 'incorrect email format');
|
||||||
await page.waitToClick(selectors.createClientView.createButton);
|
await page.waitToClick(selectors.createClientView.createButton);
|
||||||
|
@ -82,14 +108,14 @@ describe('Client create path', () => {
|
||||||
const clientCountry = await page
|
const clientCountry = await page
|
||||||
.waitToGetProperty(selectors.createClientView.country, 'value');
|
.waitToGetProperty(selectors.createClientView.country, 'value');
|
||||||
|
|
||||||
expect(clientCity).toEqual('Valencia');
|
expect(clientCity).toEqual('Boston');
|
||||||
expect(clientProvince).toContain('Province one');
|
expect(clientProvince).toContain('Massachusetts');
|
||||||
expect(clientCountry).toEqual('España');
|
expect(clientCountry).toEqual('España');
|
||||||
});
|
});
|
||||||
|
|
||||||
it(`should create a new user with all correct data`, async() => {
|
it(`should create a new user with all correct data`, async() => {
|
||||||
await page.clearInput(selectors.createClientView.postcode);
|
await page.clearInput(selectors.createClientView.postcode);
|
||||||
await page.write(selectors.createClientView.postcode, '46000');
|
await page.write(selectors.createClientView.postcode, '61616');
|
||||||
await page.waitToClick(selectors.createClientView.createButton);
|
await page.waitToClick(selectors.createClientView.createButton);
|
||||||
const message = await page.waitForSnackbar();
|
const message = await page.waitForSnackbar();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,9 @@ describe('Entry create path', () => {
|
||||||
await page.autocompleteSearch(selectors.entryIndex.newEntryCompany, 'ORN');
|
await page.autocompleteSearch(selectors.entryIndex.newEntryCompany, 'ORN');
|
||||||
|
|
||||||
await page.waitToClick(selectors.entryIndex.saveNewEntry);
|
await page.waitToClick(selectors.entryIndex.saveNewEntry);
|
||||||
await page.waitFor(500);
|
await page.waitForNavigation({
|
||||||
|
waitUntil: 'load',
|
||||||
|
});
|
||||||
await page.waitForState('entry.card.basicData');
|
await page.waitForState('entry.card.basicData');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -153,9 +153,9 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- New postcode dialog -->
|
<!-- New postcode dialog -->
|
||||||
<vn-client-postcode vn-id="postcode"
|
<vn-geo-postcode vn-id="postcode"
|
||||||
on-response="$ctrl.onResponse($response)">
|
on-response="$ctrl.onResponse($response)">
|
||||||
</vn-client-postcode>
|
</vn-geo-postcode>
|
||||||
|
|
||||||
<!-- Create custom agent dialog -->
|
<!-- Create custom agent dialog -->
|
||||||
<vn-dialog class="edit"
|
<vn-dialog class="edit"
|
||||||
|
|
|
@ -74,6 +74,8 @@ export default class Controller extends Section {
|
||||||
|
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
this.address.postalCode = response.code;
|
this.address.postalCode = response.code;
|
||||||
|
this.address.city = response.city;
|
||||||
|
this.address.provinceFk = response.provinceFk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,9 +191,9 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!-- New postcode dialog -->
|
<!-- New postcode dialog -->
|
||||||
<vn-client-postcode vn-id="postcode"
|
<vn-geo-postcode vn-id="postcode"
|
||||||
on-response="$ctrl.onResponse($response)">
|
on-response="$ctrl.onResponse($response)">
|
||||||
</vn-client-postcode>
|
</vn-geo-postcode>
|
||||||
|
|
||||||
<!-- Create custom agent dialog -->
|
<!-- Create custom agent dialog -->
|
||||||
<vn-dialog class="edit"
|
<vn-dialog class="edit"
|
||||||
|
|
|
@ -78,6 +78,8 @@ export default class Controller extends Section {
|
||||||
|
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
this.address.postalCode = response.code;
|
this.address.postalCode = response.code;
|
||||||
|
this.address.city = response.city;
|
||||||
|
this.address.provinceFk = response.provinceFk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,6 @@
|
||||||
insert-mode="true"
|
insert-mode="true"
|
||||||
form="form">
|
form="form">
|
||||||
</vn-watcher>
|
</vn-watcher>
|
||||||
<vn-crud-model
|
|
||||||
auto-load="true"
|
|
||||||
url="Towns/location"
|
|
||||||
data="townLocations"
|
|
||||||
order="name">
|
|
||||||
</vn-crud-model>
|
|
||||||
<form name="form" vn-http-submit="$ctrl.onSubmit()" class="vn-w-md">
|
<form name="form" vn-http-submit="$ctrl.onSubmit()" class="vn-w-md">
|
||||||
<vn-card class="vn-pa-lg">
|
<vn-card class="vn-pa-lg">
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
|
@ -82,7 +76,7 @@
|
||||||
label="City"
|
label="City"
|
||||||
ng-model="$ctrl.client.city"
|
ng-model="$ctrl.client.city"
|
||||||
selection="$ctrl.town"
|
selection="$ctrl.town"
|
||||||
data="townsLocation"
|
url="Towns/location"
|
||||||
fields="['id', 'name', 'provinceFk']"
|
fields="['id', 'name', 'provinceFk']"
|
||||||
value-field="name">
|
value-field="name">
|
||||||
<tpl-item>
|
<tpl-item>
|
||||||
|
@ -136,7 +130,7 @@
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</form>
|
</form>
|
||||||
<!-- New postcode dialog -->
|
<!-- New postcode dialog -->
|
||||||
<vn-client-postcode
|
<vn-geo-postcode
|
||||||
vn-id="postcode"
|
vn-id="postcode"
|
||||||
on-response="$ctrl.onResponse($response)">
|
on-response="$ctrl.onResponse($response)">
|
||||||
</vn-client-postcode>
|
</vn-geo-postcode>
|
|
@ -81,6 +81,9 @@ export default class Controller extends Section {
|
||||||
|
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
this.client.postcode = response.code;
|
this.client.postcode = response.code;
|
||||||
|
this.client.city = response.city;
|
||||||
|
this.client.provinceFk = response.provinceFk;
|
||||||
|
this.client.countryFk = response.countryFk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@
|
||||||
on-accept="$ctrl.onAcceptDuplication()">
|
on-accept="$ctrl.onAcceptDuplication()">
|
||||||
</vn-confirm>
|
</vn-confirm>
|
||||||
<!-- New postcode dialog -->
|
<!-- New postcode dialog -->
|
||||||
<vn-client-postcode
|
<vn-geo-postcode
|
||||||
vn-id="postcode"
|
vn-id="postcode"
|
||||||
on-response="$ctrl.onResponse($response)">
|
on-response="$ctrl.onResponse($response)">
|
||||||
</vn-client-postcode>
|
</vn-geo-postcode>
|
|
@ -159,6 +159,9 @@ export default class Controller extends Section {
|
||||||
|
|
||||||
onResponse(response) {
|
onResponse(response) {
|
||||||
this.client.postcode = response.code;
|
this.client.postcode = response.code;
|
||||||
|
this.client.city = response.city;
|
||||||
|
this.client.provinceFk = response.provinceFk;
|
||||||
|
this.client.countryFk = response.countryFk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@ import './web-payment';
|
||||||
import './log';
|
import './log';
|
||||||
import './sms';
|
import './sms';
|
||||||
import './postcode';
|
import './postcode';
|
||||||
|
import './postcode/province';
|
||||||
|
import './postcode/city';
|
||||||
import './dms/index';
|
import './dms/index';
|
||||||
import './dms/create';
|
import './dms/create';
|
||||||
import './dms/edit';
|
import './dms/edit';
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<vn-dialog class="edit"
|
||||||
|
vn-id="cityDialog"
|
||||||
|
on-open="$ctrl.onOpen()"
|
||||||
|
on-accept="$ctrl.onAccept()"
|
||||||
|
message="New city">
|
||||||
|
<tpl-body>
|
||||||
|
<p translate>Please, ensure you put the correct data!</p>
|
||||||
|
<vn-horizontal>
|
||||||
|
<vn-textfield vn-one
|
||||||
|
vn-focus
|
||||||
|
ng-model="$ctrl.city.name"
|
||||||
|
label="Name">
|
||||||
|
</vn-textfield>
|
||||||
|
<vn-autocomplete vn-one
|
||||||
|
ng-model="$ctrl.city.provinceFk"
|
||||||
|
url="Provinces"
|
||||||
|
show-field="name"
|
||||||
|
value-field="id"
|
||||||
|
label="Province">
|
||||||
|
</vn-autocomplete>
|
||||||
|
</vn-horizontal>
|
||||||
|
</tpl-body>
|
||||||
|
<tpl-buttons>
|
||||||
|
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||||
|
<button id="saveCity" response="accept" translate>Save</button>
|
||||||
|
</tpl-buttons>
|
||||||
|
</vn-dialog>
|
|
@ -0,0 +1,37 @@
|
||||||
|
import ngModule from '../../module';
|
||||||
|
import Component from 'core/lib/component';
|
||||||
|
|
||||||
|
class Controller extends Component { // Comprobar funcionamiento añadir ciudad
|
||||||
|
open($event) {
|
||||||
|
if ($event.defaultPrevented) return;
|
||||||
|
|
||||||
|
this.$.cityDialog.show();
|
||||||
|
$event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
onAccept() {
|
||||||
|
try {
|
||||||
|
if (!this.city.name)
|
||||||
|
throw new Error(`The city name can't be empty`);
|
||||||
|
if (!this.city.provinceFk)
|
||||||
|
throw new Error(`The province can't be empty`);
|
||||||
|
|
||||||
|
this.$http.patch(`towns`, this.city).then(res => {
|
||||||
|
this.vnApp.showMessage(this.$t('The city has been created'));
|
||||||
|
this.emit('response', {$response: res.data});
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.vnApp.showError(this.$t(e.message));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngModule.vnComponent('vnGeoCity', {
|
||||||
|
template: require('./index.html'),
|
||||||
|
controller: Controller,
|
||||||
|
bindings: {
|
||||||
|
data: '<',
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,34 @@
|
||||||
|
import './index';
|
||||||
|
|
||||||
|
describe('Client', () => {
|
||||||
|
describe('Component vnGeoCity', () => {
|
||||||
|
let controller;
|
||||||
|
let $httpBackend;
|
||||||
|
let $scope;
|
||||||
|
|
||||||
|
beforeEach(ngModule('client'));
|
||||||
|
|
||||||
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
|
$scope = $rootScope.$new();
|
||||||
|
const $element = angular.element('<vn-dialog></vn-dialog>');
|
||||||
|
controller = $componentController('vnGeoCity', {$element, $scope});
|
||||||
|
controller.client = {id: 101};
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('onAccept()', () => {
|
||||||
|
it('should perform a POST query and show a success snackbar', () => {
|
||||||
|
let params = {name: 'Gotham City', provinceFk: 1};
|
||||||
|
controller.city = {name: 'Gotham City', provinceFk: 1};
|
||||||
|
|
||||||
|
jest.spyOn(controller.vnApp, 'showMessage');
|
||||||
|
$httpBackend.expect('PATCH', `towns`, params).respond(200, params);
|
||||||
|
|
||||||
|
controller.onAccept();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The city has been created');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -11,7 +11,7 @@
|
||||||
vn-focus
|
vn-focus
|
||||||
vn-id="postcode"
|
vn-id="postcode"
|
||||||
label="Postcode"
|
label="Postcode"
|
||||||
ng-model="$ctrl.data.code"
|
ng-model="$ctrl.location.code"
|
||||||
required="true">
|
required="true">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-autocomplete vn-one
|
<vn-autocomplete vn-one
|
||||||
|
@ -19,23 +19,39 @@
|
||||||
url="Towns/location"
|
url="Towns/location"
|
||||||
show-field="name"
|
show-field="name"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
ng-model="$ctrl.data.townFk"
|
ng-model="$ctrl.location.townFk"
|
||||||
selection="$ctrl.townSelection"
|
selection="$ctrl.townSelection"
|
||||||
required="true">
|
required="true">
|
||||||
|
<append>
|
||||||
|
<vn-icon-button
|
||||||
|
icon="add_circle"
|
||||||
|
vn-tooltip="New city"
|
||||||
|
ng-click="city.open($event)"
|
||||||
|
vn-acl="deliveryBoss"
|
||||||
|
vn-acl-action="remove">
|
||||||
|
</vn-icon-button>
|
||||||
|
</append>
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-autocomplete vn-one
|
<vn-autocomplete vn-one
|
||||||
disabled="true"
|
ng-model="$ctrl.location.provinceFk"
|
||||||
ng-model="$ctrl.data.provinceFk"
|
|
||||||
url="Provinces"
|
url="Provinces"
|
||||||
show-field="name"
|
show-field="name"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
label="Province">
|
label="Province">
|
||||||
|
<append>
|
||||||
|
<vn-icon-button
|
||||||
|
icon="add_circle"
|
||||||
|
vn-tooltip="New province"
|
||||||
|
ng-click="province.open($event)"
|
||||||
|
vn-acl="deliveryBoss"
|
||||||
|
vn-acl-action="remove">
|
||||||
|
</vn-icon-button>
|
||||||
|
</append>
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
<vn-autocomplete vn-one
|
<vn-autocomplete vn-one
|
||||||
disabled="true"
|
ng-model="$ctrl.location.countryFk"
|
||||||
ng-model="$ctrl.data.countryFk"
|
|
||||||
url="Countries"
|
url="Countries"
|
||||||
show-field="country"
|
show-field="country"
|
||||||
value-field="id"
|
value-field="id"
|
||||||
|
@ -45,6 +61,16 @@
|
||||||
</tpl-body>
|
</tpl-body>
|
||||||
<tpl-buttons>
|
<tpl-buttons>
|
||||||
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||||
<button response="accept" translate>Save</button>
|
<button id= "savePostcode" response="accept" translate>Save</button>
|
||||||
</tpl-buttons>
|
</tpl-buttons>
|
||||||
</vn-dialog>
|
</vn-dialog>
|
||||||
|
<!-- New province dialog -->
|
||||||
|
<vn-geo-province
|
||||||
|
vn-id="province"
|
||||||
|
on-response="$ctrl.onProvinceResponse($response)">
|
||||||
|
</vn-geo-province>
|
||||||
|
<!-- New city dialog -->
|
||||||
|
<vn-geo-city
|
||||||
|
vn-id="city"
|
||||||
|
on-response="$ctrl.onCityResponse($response)">
|
||||||
|
</vn-geo-city>
|
|
@ -15,8 +15,9 @@ class Controller extends Component {
|
||||||
const province = selection.province;
|
const province = selection.province;
|
||||||
const country = province.country;
|
const country = province.country;
|
||||||
|
|
||||||
this.data.provinceFk = province.id;
|
this.location.city = selection.name;
|
||||||
this.data.countryFk = country.id;
|
this.location.provinceFk = province.id;
|
||||||
|
this.location.countryFk = country.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
|
@ -24,19 +25,35 @@ class Controller extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
onOpen() {
|
onOpen() {
|
||||||
|
this.location = {};
|
||||||
this.$.postcode.focus();
|
this.$.postcode.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onProvinceResponse(response) {
|
||||||
|
this.location.provinceFk = response.id;
|
||||||
|
this.location.countryFk = response.countryFk;
|
||||||
|
}
|
||||||
|
|
||||||
|
onCityResponse(response) {
|
||||||
|
this.location.townFk = response.id;
|
||||||
|
this.location.provinceFk = response.provinceFk;
|
||||||
|
this.location.countryFk = response.countryFk;
|
||||||
|
}
|
||||||
|
|
||||||
onAccept() {
|
onAccept() {
|
||||||
try {
|
try {
|
||||||
if (!this.data.code)
|
if (!this.location.code)
|
||||||
throw new Error(`The postcode can't be empty`);
|
throw new Error(`The postcode can't be empty`);
|
||||||
if (!this.data.townFk)
|
if (!this.location.townFk)
|
||||||
throw new Error(`The town can't be empty`);
|
throw new Error(`The town can't be empty`);
|
||||||
|
if (!this.location.provinceFk)
|
||||||
|
throw new Error(`The province can't be empty`);
|
||||||
|
if (!this.location.provinceFk)
|
||||||
|
throw new Error(`The country can't be empty`);
|
||||||
|
|
||||||
this.$http.patch(`postcodes`, this.data).then(res => {
|
this.$http.patch(`postcodes`, this.location).then(() => {
|
||||||
this.vnApp.showMessage(this.$t('The postcode has been saved'));
|
this.vnApp.showMessage(this.$t('The postcode has been created. You can save the data now'));
|
||||||
this.emit('response', {$response: res.data});
|
this.emit('response', {$response: this.location});
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.vnApp.showError(this.$t(e.message));
|
this.vnApp.showError(this.$t(e.message));
|
||||||
|
@ -46,7 +63,7 @@ class Controller extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnClientPostcode', {
|
ngModule.vnComponent('vnGeoPostcode', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
bindings: {
|
bindings: {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import './index';
|
import './index';
|
||||||
|
|
||||||
describe('Client', () => {
|
describe('Client', () => {
|
||||||
describe('Component vnClientPostcode', () => {
|
describe('Component vnGeoPostcode', () => {
|
||||||
let controller;
|
let controller;
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
let $scope;
|
let $scope;
|
||||||
|
@ -12,14 +12,14 @@ describe('Client', () => {
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
const $element = angular.element('<vn-dialog></vn-dialog>');
|
const $element = angular.element('<vn-dialog></vn-dialog>');
|
||||||
controller = $componentController('vnClientPostcode', {$element, $scope});
|
controller = $componentController('vnGeoPostcode', {$element, $scope});
|
||||||
controller.client = {id: 101};
|
controller.client = {id: 101};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('onAccept()', () => {
|
describe('onAccept()', () => {
|
||||||
it('should perform a POST query and show a success snackbar', () => {
|
it('should perform a POST query and show a success snackbar', () => {
|
||||||
let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
|
let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
|
||||||
controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
|
controller.location = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
|
||||||
|
|
||||||
jest.spyOn(controller.vnApp, 'showMessage');
|
jest.spyOn(controller.vnApp, 'showMessage');
|
||||||
$httpBackend.expect('PATCH', `postcodes`, params).respond(200, params);
|
$httpBackend.expect('PATCH', `postcodes`, params).respond(200, params);
|
||||||
|
@ -27,7 +27,7 @@ describe('Client', () => {
|
||||||
controller.onAccept();
|
controller.onAccept();
|
||||||
$httpBackend.flush();
|
$httpBackend.flush();
|
||||||
|
|
||||||
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved');
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been created. You can save the data now');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
New postcode: Nuevo código postal
|
New postcode: Nuevo código postal
|
||||||
|
New city: Nueva ciudad
|
||||||
|
New province: Nueva provincia
|
||||||
Please, ensure you put the correct data!: ¡Por favor, asegúrate de poner los datos correctos!
|
Please, ensure you put the correct data!: ¡Por favor, asegúrate de poner los datos correctos!
|
||||||
The postcode can't be empty: El código postal no puede quedar vacío
|
The postcode can't be empty: El código postal no puede quedar vacío
|
||||||
The town can't be empty: La población no puede quedar vacía
|
The town can't be empty: La población no puede quedar vacía
|
||||||
The postcode has been saved: El código postal ha sido guardado
|
The province can't be empty: La provincia no puede quedar vacía
|
||||||
|
The country can't be empty: El país no puede quedar vacío
|
||||||
|
The postcode has been created. You can save the data now: Se ha creado el código postal. Ahora puedes guardar los datos
|
||||||
|
The city has been created: Se ha creado la ciudad
|
||||||
|
The province has been created: Se ha creado la provincia
|
|
@ -0,0 +1,27 @@
|
||||||
|
<vn-dialog class="edit"
|
||||||
|
vn-id="provinceDialog"
|
||||||
|
on-open="$ctrl.onOpen()"
|
||||||
|
on-accept="$ctrl.onAccept()"
|
||||||
|
message="New province">
|
||||||
|
<tpl-body>
|
||||||
|
<p translate>Please, ensure you put the correct data!</p>
|
||||||
|
<vn-horizontal>
|
||||||
|
<vn-textfield vn-one
|
||||||
|
vn-focus
|
||||||
|
ng-model="$ctrl.province.name"
|
||||||
|
label="Name">
|
||||||
|
</vn-textfield>
|
||||||
|
<vn-autocomplete vn-one
|
||||||
|
ng-model="$ctrl.province.countryFk"
|
||||||
|
url="Countries"
|
||||||
|
show-field="country"
|
||||||
|
value-field="id"
|
||||||
|
label="Country">
|
||||||
|
</vn-autocomplete>
|
||||||
|
</vn-horizontal>
|
||||||
|
</tpl-body>
|
||||||
|
<tpl-buttons>
|
||||||
|
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
|
||||||
|
<button id="saveProvince" response="accept" translate>Save</button>
|
||||||
|
</tpl-buttons>
|
||||||
|
</vn-dialog>
|
|
@ -0,0 +1,37 @@
|
||||||
|
import ngModule from '../../module';
|
||||||
|
import Component from 'core/lib/component';
|
||||||
|
|
||||||
|
class Controller extends Component {
|
||||||
|
open($event) {
|
||||||
|
if ($event.defaultPrevented) return;
|
||||||
|
|
||||||
|
this.$.provinceDialog.show();
|
||||||
|
$event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
onAccept() {
|
||||||
|
try {
|
||||||
|
if (!this.province.name)
|
||||||
|
throw new Error(`The province name can't be empty`);
|
||||||
|
if (!this.province.countryFk)
|
||||||
|
throw new Error(`The country can't be empty`);
|
||||||
|
|
||||||
|
this.$http.patch(`provinces`, this.province).then(res => {
|
||||||
|
this.vnApp.showMessage(this.$t('The province has been created'));
|
||||||
|
this.emit('response', {$response: res.data});
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
this.vnApp.showError(this.$t(e.message));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngModule.vnComponent('vnGeoProvince', {
|
||||||
|
template: require('./index.html'),
|
||||||
|
controller: Controller,
|
||||||
|
bindings: {
|
||||||
|
data: '<',
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,34 @@
|
||||||
|
import './index';
|
||||||
|
|
||||||
|
describe('Client', () => {
|
||||||
|
describe('Component vnGeoProvince', () => {
|
||||||
|
let controller;
|
||||||
|
let $httpBackend;
|
||||||
|
let $scope;
|
||||||
|
|
||||||
|
beforeEach(ngModule('client'));
|
||||||
|
|
||||||
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
||||||
|
$httpBackend = _$httpBackend_;
|
||||||
|
$scope = $rootScope.$new();
|
||||||
|
const $element = angular.element('<vn-dialog></vn-dialog>');
|
||||||
|
controller = $componentController('vnGeoProvince', {$element, $scope});
|
||||||
|
controller.client = {id: 101};
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('onAccept()', () => {
|
||||||
|
it('should perform a POST query and show a success snackbar', () => {
|
||||||
|
let params = {name: 'New Jersey', countryFk: 1};
|
||||||
|
controller.province = {name: 'New Jersey', countryFk: 1};
|
||||||
|
|
||||||
|
jest.spyOn(controller.vnApp, 'showMessage');
|
||||||
|
$httpBackend.expect('PATCH', `provinces`, params).respond(200, params);
|
||||||
|
|
||||||
|
controller.onAccept();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The province has been created');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
@import "variables";
|
@import "variables";
|
||||||
|
|
||||||
vn-client-postcode {
|
vn-geo-postcode {
|
||||||
vn-dialog {
|
vn-dialog {
|
||||||
p {
|
p {
|
||||||
color: $color-alert
|
color: $color-alert
|
||||||
|
|
Loading…
Reference in New Issue