Merge branch '2034-postcode_autocomplete' of verdnatura/salix into dev
gitea/salix/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Joan Sanchez 2020-03-04 12:15:41 +00:00 committed by Gitea
commit 516b112354
24 changed files with 670 additions and 335 deletions

View File

@ -1,46 +1,53 @@
{
"name": "Province",
"description": "Provinces of every country",
"base": "VnModel",
"options": {
"mysql": {
"table": "province"
}
},
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
"name": "Province",
"description": "Provinces of every country",
"base": "VnModel",
"options": {
"mysql": {
"table": "province"
}
},
"name": {
"type": "string",
"required": true
}
},
"relations": {
"country": {
"type": "belongsTo",
"model": "Country",
"foreignKey": "countryFk"
"properties": {
"id": {
"type": "Number",
"id": true,
"description": "Identifier"
},
"name": {
"type": "string",
"required": true
}
},
"warehouse": {
"type": "belongsTo",
"model": "Warehouse",
"foreignKey": "warehouseFk"
"relations": {
"country": {
"type": "belongsTo",
"model": "Country",
"foreignKey": "countryFk"
},
"warehouse": {
"type": "belongsTo",
"model": "Warehouse",
"foreignKey": "warehouseFk"
},
"zone": {
"type": "belongsTo",
"model": "Zone",
"foreignKey": "zoneFk"
}
},
"zone": {
"type": "belongsTo",
"model": "Zone",
"foreignKey": "zoneFk"
}
},
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
"scopes": {
"location": {
"include": {
"relation": "country"
}
}
},
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
}
]
}

View File

@ -197,14 +197,16 @@ INSERT INTO `vn`.`town`(`id`, `name`, `provinceFk`)
(1, 'Valencia', 1),
(2, 'Silla', 1),
(3, 'Algemesi', 1),
(4, 'Alzira', 1);
(4, 'Alzira', 1),
(5, 'Quito', 5);
INSERT INTO `vn`.`postCode`(`code`, `townFk`, `geoFk`)
VALUES
('46000', 1, 6),
('46460', 2, 6),
('46680', 3, 6),
('46600', 4, 7);
('46600', 4, 7),
('EC170150', 5, 8);
INSERT INTO `vn`.`clientType`(`id`, `code`, `type`)
VALUES

View File

@ -44,8 +44,8 @@ export default {
taxNumber: 'vn-client-create vn-textfield[ng-model="$ctrl.client.fi"]',
socialName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.socialName"]',
street: 'vn-client-create vn-textfield[ng-model="$ctrl.client.street"]',
postcode: 'vn-client-create vn-textfield[ng-model="$ctrl.client.postcode"]',
city: 'vn-client-create vn-textfield[ng-model="$ctrl.client.city"]',
postcode: 'vn-client-create vn-datalist[ng-model="$ctrl.client.postcode"]',
city: 'vn-client-create vn-datalist[ng-model="$ctrl.client.city"]',
province: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.provinceFk"]',
country: 'vn-client-create vn-autocomplete[ng-model="$ctrl.client.countryFk"]',
userName: 'vn-client-create vn-textfield[ng-model="$ctrl.client.userName"]',
@ -76,8 +76,8 @@ export default {
equalizationTaxCheckbox: 'vn-client-fiscal-data vn-check[ng-model="$ctrl.client.isEqualizated"]',
acceptPropagationButton: '.vn-confirm.shown button[response=accept]',
address: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.street"]',
postcode: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.postcode"]',
city: 'vn-client-fiscal-data vn-textfield[ng-model="$ctrl.client.city"]',
postcode: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.postcode"]',
city: 'vn-client-fiscal-data vn-datalist[ng-model="$ctrl.client.city"]',
province: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.provinceFk"]',
country: 'vn-client-fiscal-data vn-autocomplete[ng-model="$ctrl.client.countryFk"]',
activeCheckbox: 'vn-client-fiscal-data vn-check[label="Active"]',
@ -114,8 +114,8 @@ export default {
defaultCheckbox: 'vn-check[label="Default"]',
consignee: 'vn-textfield[ng-model="$ctrl.address.nickname"]',
streetAddress: 'vn-textfield[ng-model="$ctrl.address.street"]',
postcode: 'vn-textfield[ng-model="$ctrl.address.postalCode"]',
city: 'vn-textfield[ng-model="$ctrl.address.city"]',
postcode: 'vn-datalist[ng-model="$ctrl.address.postalCode"]',
city: 'vn-datalist[ng-model="$ctrl.address.city"]',
province: 'vn-autocomplete[ng-model="$ctrl.address.provinceId"]',
agency: 'vn-autocomplete[ng-model="$ctrl.address.agencyModeId"]',
phone: 'vn-textfield[ng-model="$ctrl.address.phone"]',

View File

@ -87,7 +87,7 @@ describe('Client create path', async() => {
.waitToGetProperty(selectors.createClientView.country, 'value');
expect(clientCity).toEqual('Valencia');
expect(clientProvince).toEqual('Province one');
expect(clientProvince).toContain('Province one');
expect(clientCountry).toEqual('España');
});

View File

@ -198,11 +198,10 @@ describe('Client Edit fiscalData path', () => {
expect(result).toEqual('Valencia');
});
it(`should confirm the province have been autocompleted`, async() => {
const result = await page.waitToGetProperty(selectors.clientFiscalData.province, 'value');
expect(result).toEqual('Province one');
expect(result).toContain('Province one');
});
it('should confirm the country have been autocompleted', async() => {

View File

@ -25,9 +25,7 @@ describe('Client Add address path', () => {
it('should receive an error after clicking save button as consignee, street and town fields are empty', async() => {
await page.waitToClick(selectors.clientAddresses.defaultCheckbox);
await page.autocompleteSearch(selectors.clientAddresses.province, 'Province five');
await page.write(selectors.clientAddresses.city, 'Valencia');
await page.write(selectors.clientAddresses.postcode, '46000');
await page.write(selectors.clientAddresses.postcode, 'EC170150');
await page.autocompleteSearch(selectors.clientAddresses.agency, 'Entanglement');
await page.write(selectors.clientAddresses.phone, '999887744');
await page.write(selectors.clientAddresses.mobileInput, '999887744');
@ -37,6 +35,16 @@ describe('Client Add address path', () => {
expect(result).toEqual('Some fields are invalid');
});
it('should confirm that the city and province are propertly filled', async() => {
const city = await page
.waitToGetProperty(selectors.clientAddresses.city, 'value');
const province = await page
.waitToGetProperty(selectors.clientAddresses.province, 'value');
expect(city).toEqual('Quito');
expect(province).toContain('Province five');
});
it(`should receive an error after clicking save button as consignee, incoterms and customsAgent are empty`, async() => {
await page.write(selectors.clientAddresses.consignee, 'Bruce Bunner');

View File

@ -27,7 +27,7 @@ export default class Datalist extends Textfield {
value = value == '' || value == null ? null : value;
oldValue = oldValue == '' || oldValue == null ? null : oldValue;
this.refreshSelection();
if (oldValue === undefined) this.refreshSelection();
if (!value || value === oldValue && this.modelData != null) return;
@ -52,7 +52,14 @@ export default class Datalist extends Textfield {
validSelection(selection) {
return this.modelData && this.modelData.find(item => {
return item[this.valueField] == selection;
let dataValue = item[this.valueField];
if (typeof(dataValue) === 'string')
dataValue = dataValue.toLowerCase();
if (typeof(selection) === 'string')
selection = selection.toLowerCase();
return dataValue == selection;
});
}

View File

@ -64,5 +64,6 @@
"Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member",
"Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member",
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}"
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}",
"Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment"
}

View File

@ -39,61 +39,53 @@
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
vn-id="province"
ng-model="$ctrl.address.provinceId"
url="Provinces"
show-field="name"
value-field="id"
label="Province">
</vn-autocomplete>
<vn-textfield
vn-one
label="City"
ng-model="$ctrl.address.city"
rule>
</vn-textfield>
<!-- <vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}"
show-field="name"
value-field="name"
ng-model="$ctrl.address.city">
</vn-autocomplete>
<vn-autocomplete vn-one
url="Postcodes/location"
fields="['code', 'townFk']"
ng-model="$ctrl.address.postalCode"
selection="$ctrl.postcodeSelection"
search-function="{code: $search}"
where="{townFk: town.selection.id}"
order="code, townFk"
show-field="code"
value-field="code"
label="Postcode">
<tpl-item>
{{code}}, {{town.name}} - {{town.province.name}}
({{town.province.country.country}})
</tpl-item>
</vn-autocomplete> -->
<vn-textfield
vn-one
<vn-datalist vn-one
label="Postcode"
ng-model="$ctrl.address.postalCode"
selection="$ctrl.postcode"
url="Postcodes/location"
fields="['code','townFk']"
order="code, townFk"
value-field="code"
show-field="code"
rule>
</vn-textfield>
<!--
<vn-icon-button
vn-auto
class="vn-my-md"
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()">
</vn-icon-button>
-->
<tpl-item>
{{code}} - {{town.name}} ({{town.province.name}},
{{town.province.country.country}})
</tpl-item>
<append>
<vn-icon-button
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()"
vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-datalist>
<vn-datalist vn-id="town" vn-one
label="City"
ng-model="$ctrl.address.city"
selection="$ctrl.town"
url="Towns/location"
fields="['id', 'name', 'provinceFk']"
show-field="name"
value-field="name">
<tpl-item>
{{name}}, {{province.name}}
({{province.country.country}})
</tpl-item>
</vn-datalist>
<vn-autocomplete vn-id="province" vn-one
label="Province"
ng-model="$ctrl.address.provinceId"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
show-field="name"
value-field="id"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete

View File

@ -11,26 +11,6 @@ export default class Controller extends Component {
};
}
get postcodeSelection() {
return this._postcodeSelection;
}
set postcodeSelection(selection) {
this._postcodeSelection = selection;
if (!selection) return;
const town = selection.town;
const province = town.province;
this.address.city = town.name;
this.address.provinceFk = province.id;
}
onResponse(response) {
this.address.postalCode = response.code;
}
onSubmit() {
this.$.watcher.submit().then(res => {
if (this.address.isDefaultAddress)
@ -51,6 +31,46 @@ export default class Controller extends Component {
return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
.then(res => this.address.customsAgentFk = res.data.id);
}
get town() {
return this._town;
}
// Town auto complete
set town(selection) {
this._town = selection;
if (!selection) return;
const province = selection.province;
const postcodes = selection.postcodes;
this.address.provinceId = province.id;
if (postcodes.length === 1)
this.address.postalCode = postcodes[0].code;
}
get postcode() {
return this._postcode;
}
// Postcode auto complete
set postcode(selection) {
this._postcode = selection;
if (!selection) return;
const town = selection.town;
const province = town.province;
this.address.city = town.name;
this.address.provinceId = province.id;
}
onResponse(response) {
this.address.postalCode = response.code;
}
}
Controller.$inject = ['$element', '$scope'];

View File

@ -53,9 +53,48 @@ describe('Client', () => {
});
});
describe('postcodeSelection() setter', () => {
it(`should set the town, province and contry properties`, () => {
controller.postcodeSelection = {
describe('town() setter', () => {
it(`should set provinceId property`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
expect(controller.address.provinceId).toEqual(1);
});
it(`should set provinceId property and fill the postalCode if there's just one`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
expect(controller.address.provinceId).toEqual(1);
expect(controller.address.postalCode).toEqual('46001');
});
});
describe('postcode() setter', () => {
it(`should set the town and province properties`, () => {
controller.postcode = {
townFk: 1,
code: 46001,
town: {
@ -73,7 +112,7 @@ describe('Client', () => {
};
expect(controller.address.city).toEqual('New York');
expect(controller.address.provinceFk).toEqual(1);
expect(controller.address.provinceId).toEqual(1);
});
});

View File

@ -56,58 +56,53 @@
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
vn-id="province"
ng-model="$ctrl.address.provinceFk"
url="Provinces"
show-field="name"
value-field="id"
label="Province">
</vn-autocomplete>
<vn-textfield
vn-one
label="City"
ng-model="$ctrl.address.city"
rule>
</vn-textfield>
<!--
<vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}"
show-field="name"
value-field="name"
ng-model="$ctrl.address.city">
</vn-autocomplete>
<vn-autocomplete vn-one
url="Postcodes/location"
fields="['code', 'townFk']"
ng-model="$ctrl.address.postalCode"
where="{townFk: town.selection.id}"
search-function="{code: $search}"
order="code, townFk"
show-field="code"
value-field="code"
label="Postcode">
</vn-autocomplete>
-->
<vn-textfield
vn-one
<vn-datalist vn-one
label="Postcode"
ng-model="$ctrl.address.postalCode"
selection="$ctrl.postcode"
url="Postcodes/location"
fields="['code','townFk']"
order="code, townFk"
value-field="code"
show-field="code"
rule>
</vn-textfield>
<!-- <vn-icon-button
vn-auto
class="vn-my-md"
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()">
</vn-icon-button>
-->
<tpl-item>
{{code}} - {{town.name}} ({{town.province.name}},
{{town.province.country.country}})
</tpl-item>
<append>
<vn-icon-button
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()"
vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-datalist>
<vn-datalist vn-id="town" vn-one
label="City"
ng-model="$ctrl.address.city"
selection="$ctrl.town"
url="Towns/location"
fields="['id', 'name', 'provinceFk']"
show-field="name"
value-field="name">
<tpl-item>
{{name}}, {{province.name}}
({{province.country.country}})
</tpl-item>
</vn-datalist>
<vn-autocomplete vn-id="province" vn-one
label="Province"
ng-model="$ctrl.address.provinceFk"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
show-field="name"
value-field="id"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-one

View File

@ -15,10 +15,6 @@ export default class Controller extends Component {
this.$state.go('client.card.address.index');
}
onResponse(response) {
this.address.postalCode = response.code;
}
onSubmit() {
this.$.watcher.submit()
.then(() => this.$.model.save(true))
@ -39,6 +35,48 @@ export default class Controller extends Component {
return this.$http.post(`CustomsAgents`, this.newCustomsAgent)
.then(res => this.address.customsAgentFk = res.data.id);
}
get town() {
return this._town;
}
// Town auto complete
set town(selection) {
const oldValue = this._town;
this._town = selection;
if (!oldValue) return;
const province = selection.province;
const postcodes = selection.postcodes;
this.address.provinceFk = province.id;
if (postcodes.length === 1)
this.address.postalCode = postcodes[0].code;
}
get postcode() {
return this._postcode;
}
// Postcode auto complete
set postcode(selection) {
const oldValue = this._postcode;
this._postcode = selection;
if (!oldValue) return;
const town = selection.town;
const province = town.province;
this.address.city = town.name;
this.address.provinceFk = province.id;
}
onResponse(response) {
this.address.postalCode = response.code;
}
}
ngModule.component('vnClientAddressEdit', {

View File

@ -49,76 +49,63 @@
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-id="country"
vn-one
<vn-datalist vn-one
label="Postcode"
ng-model="$ctrl.client.postcode"
selection="$ctrl.postcode"
url="Postcodes/location"
fields="['code','townFk']"
order="code, townFk"
value-field="code"
show-field="code"
rule>
<tpl-item>
{{code}} - {{town.name}} ({{town.province.name}},
{{town.province.country.country}})
</tpl-item>
<append>
<vn-icon-button
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()"
vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-datalist>
<vn-datalist vn-id="town" vn-one
label="City"
ng-model="$ctrl.client.city"
selection="$ctrl.town"
url="Towns/location"
fields="['id', 'name', 'provinceFk']"
show-field="name"
value-field="name">
<tpl-item>
{{name}}, {{province.name}}
({{province.country.country}})
</tpl-item>
</vn-datalist>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-id="province" vn-one
label="Province"
ng-model="$ctrl.client.provinceFk"
selection="$ctrl.province"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
show-field="name"
value-field="id"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
<vn-autocomplete vn-id="country" vn-one
ng-model="$ctrl.client.countryFk"
url="Countries"
show-field="country"
value-field="id"
label="Country">
</vn-autocomplete>
<vn-autocomplete
vn-id="province"
vn-one
url="Provinces"
ng-model="$ctrl.client.provinceFk"
where="{countryFk: country.selection.id}"
show-field="name"
value-field="id"
label="Province">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
label="City"
ng-model="$ctrl.client.city"
rule>
</vn-textfield>
<!--
<vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}"
show-field="name"
value-field="name"
ng-model="$ctrl.client.city">
</vn-autocomplete>
<vn-icon-button
vn-auto
class="vn-my-md"
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()">
</vn-icon-button>
-->
<vn-textfield
vn-one
label="Postcode"
ng-model="$ctrl.client.postcode"
rule>
</vn-textfield>
<!--
<vn-autocomplete
vn-one
url="Postcodes/location"
fields="['code', 'townFk']"
ng-model="$ctrl.client.postcode"
selection="$ctrl.postcodeSelection"
search-function="{code: $search}"
where="{townFk: town.selection.id}"
order="code, townFk"
show-field="code"
value-field="code"
label="Postcode">
<tpl-item>
{{code}}, {{town.name}} - {{town.province.name}}
({{town.province.country.country}})
</tpl-item>
</vn-autocomplete>
-->
</vn-horizontal>
<vn-horizontal>
<vn-textfield

View File

@ -12,12 +12,55 @@ export default class Controller {
};
}
get postcodeSelection() {
return this._postcodeSelection;
onSubmit() {
return this.$.watcher.submit().then(
json => this.$state.go('client.card.basicData', {id: json.data.id})
);
}
set postcodeSelection(selection) {
this._postcodeSelection = selection;
get province() {
return this._province;
}
// Province auto complete
set province(selection) {
this._province = selection;
if (!selection) return;
const country = selection.country;
this.client.countryFk = country.id;
}
get town() {
return this._town;
}
// Town auto complete
set town(selection) {
this._town = selection;
if (!selection) return;
const province = selection.province;
const country = province.country;
const postcodes = selection.postcodes;
this.client.provinceFk = province.id;
this.client.countryFk = country.id;
if (postcodes.length === 1)
this.client.postcode = postcodes[0].code;
}
get postcode() {
return this._postcode;
}
// Postcode auto complete
set postcode(selection) {
this._postcode = selection;
if (!selection) return;
@ -33,13 +76,8 @@ export default class Controller {
onResponse(response) {
this.client.postcode = response.code;
}
onSubmit() {
return this.$.watcher.submit().then(
json => this.$state.go('client.card.basicData', {id: json.data.id})
);
}
}
Controller.$inject = ['$scope', '$state', '$http', '$translate', 'vnApp'];
ngModule.component('vnClientCreate', {

View File

@ -40,9 +40,63 @@ describe('Client', () => {
});
});
describe('postcodeSelection() setter', () => {
it(`should set the town, province and contry properties`, () => {
controller.postcodeSelection = {
describe('province() setter', () => {
it(`should set countryFk property`, () => {
controller.province = {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
};
expect(controller.client.countryFk).toEqual(2);
});
});
describe('town() setter', () => {
it(`should set provinceFk property`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
expect(controller.client.provinceFk).toEqual(1);
});
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
expect(controller.client.provinceFk).toEqual(1);
expect(controller.client.postcode).toEqual('46001');
});
});
describe('postcode() setter', () => {
it(`should set the town, provinceFk and contryFk properties`, () => {
controller.postcode = {
townFk: 1,
code: 46001,
town: {

View File

@ -33,9 +33,57 @@
</vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete
vn-one
vn-id="country"
<vn-datalist vn-one
label="Postcode"
ng-model="$ctrl.client.postcode"
selection="$ctrl.postcode"
url="Postcodes/location"
fields="['code','townFk']"
order="code, townFk"
value-field="code"
show-field="code"
rule>
<tpl-item>
{{code}} - {{town.name}} ({{town.province.name}},
{{town.province.country.country}})
</tpl-item>
<append>
<vn-icon-button
icon="add_circle"
vn-tooltip="New postcode"
ng-click="postcode.open()"
vn-acl="deliveryBoss"
vn-acl-action="remove">
</vn-icon-button>
</append>
</vn-datalist>
<vn-datalist vn-id="town" vn-one
label="City"
ng-model="$ctrl.client.city"
selection="$ctrl.town"
url="Towns/location"
fields="['id', 'name', 'provinceFk']"
show-field="name"
value-field="name">
<tpl-item>
{{name}}, {{province.name}}
({{province.country.country}})
</tpl-item>
</vn-datalist>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-id="province" vn-one
label="Province"
ng-model="$ctrl.client.provinceFk"
selection="$ctrl.province"
url="Provinces/location"
fields="['id', 'name', 'countryFk']"
show-field="name"
value-field="id"
rule>
<tpl-item>{{name}} ({{country.country}})</tpl-item>
</vn-autocomplete>
<vn-autocomplete vn-id="country" vn-one
ng-model="$ctrl.client.countryFk"
url="Countries"
show-field="country"
@ -43,51 +91,6 @@
label="Country"
rule>
</vn-autocomplete>
<vn-autocomplete
vn-one
vn-id="province"
ng-model="$ctrl.client.provinceFk"
url="Provinces"
where="{countryFk: country.selection.id}"
show-field="name"
value-field="id"
label="Province"
rule>
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-textfield
vn-one
label="City"
ng-model="$ctrl.client.city"
rule>
</vn-textfield>
<vn-textfield
vn-one
label="Postcode"
ng-model="$ctrl.client.postcode"
rule>
</vn-textfield>
<!-- <vn-autocomplete vn-id="town" vn-one
label="City"
url="Towns"
fields="['id', 'name']"
where="{provinceFk: province.selection.id}"
show-field="name"
value-field="name"
ng-model="$ctrl.client.city">
</vn-autocomplete>
<vn-autocomplete vn-id="postcode" vn-one
url="Postcodes/location"
fields="['code', 'townFk']"
ng-model="$ctrl.client.postcode"
search-function="{code: $search}"
where="{townFk: town.selection.id}"
order="code, townFk"
show-field="code"
value-field="code"
label="Postcode">
</vn-autocomplete> -->
</vn-horizontal>
<vn-horizontal>
<vn-check
@ -157,3 +160,8 @@
message="Found a client with this data"
on-accept="$ctrl.onAcceptDuplication()">
</vn-confirm>
<!-- New postcode dialog -->
<vn-client-postcode
vn-id="postcode"
on-response="$ctrl.onResponse($response)">
</vn-client-postcode>

View File

@ -90,6 +90,68 @@ export default class Controller extends Component {
this.$.$apply();
}
get province() {
return this._province;
}
// Province auto complete
set province(selection) {
const oldValue = this._province;
this._province = selection;
if (!oldValue) return;
const country = selection.country;
this.client.countryFk = country.id;
}
get town() {
return this._town;
}
// Town auto complete
set town(selection) {
const oldValue = this._town;
this._town = selection;
if (!oldValue) return;
const province = selection.province;
const country = province.country;
const postcodes = selection.postcodes;
this.client.provinceFk = province.id;
this.client.countryFk = country.id;
if (postcodes.length === 1)
this.client.postcode = postcodes[0].code;
}
get postcode() {
return this._postcode;
}
// Postcode auto complete
set postcode(selection) {
const oldValue = this._postcode;
this._postcode = selection;
if (!oldValue) return;
const town = selection.town;
const province = town.province;
const country = province.country;
this.client.city = town.name;
this.client.provinceFk = province.id;
this.client.countryFk = country.id;
}
onResponse(response) {
this.client.postcode = response.code;
}
}
ngModule.component('vnClientFiscalData', {

View File

@ -25,6 +25,10 @@ describe('Client', () => {
isEqualizated: false,
isTaxDataChecked: false
};
controller.province = {};
controller.town = {};
controller.postcode = {};
}));
describe('onSubmit()', () => {
@ -129,5 +133,84 @@ describe('Client', () => {
$httpBackend.flush();
});
});
describe('province() setter', () => {
it(`should set countryFk property`, () => {
controller.province = {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
};
expect(controller.client.countryFk).toEqual(2);
});
});
describe('town() setter', () => {
it(`should set provinceFk property`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: []
};
expect(controller.client.provinceFk).toEqual(1);
});
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
controller.town = {
provinceFk: 1,
code: 46001,
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
},
postcodes: [{code: '46001'}]
};
expect(controller.client.provinceFk).toEqual(1);
expect(controller.client.postcode).toEqual('46001');
});
});
describe('postcode() setter', () => {
it(`should set the town, provinceFk and contryFk properties`, () => {
controller.postcode = {
townFk: 1,
code: 46001,
town: {
id: 1,
name: 'New York',
province: {
id: 1,
name: 'New york',
country: {
id: 2,
name: 'USA'
}
}
}
};
expect(controller.client.city).toEqual('New York');
expect(controller.client.provinceFk).toEqual(1);
expect(controller.client.countryFk).toEqual(2);
});
});
});
});

View File

@ -1,7 +1,7 @@
<vn-dialog class="edit"
vn-id="postcodeDialog"
on-open="$ctrl.onOpen()"
on-response="$ctrl.onResponse($response)">
on-accept="$ctrl.onAccept()">
<tpl-body>
<h5 class="vn-py-sm" translate>New postcode</h5>
<p translate>Please, ensure you put the correct data!</p>

View File

@ -35,25 +35,20 @@ class Controller extends Component {
this.$.postcode.focus();
}
onResponse(response) {
if (response == 'accept') {
try {
if (!this.data.code)
throw new Error(`The postcode can't be empty`);
if (!this.data.townFk)
throw new Error(`The town can't be empty`);
onAccept() {
try {
if (!this.data.code)
throw new Error(`The postcode can't be empty`);
if (!this.data.townFk)
throw new Error(`The town can't be empty`);
this.$http.patch(`postcodes`, this.data).then(response => {
if (response.data) {
this.vnApp.showMessage(this.$translate.instant('The postcode has been saved'));
this.emit('response', {response: response.data});
}
});
} catch (e) {
this.vnApp.showError(this.$translate.instant(e.message));
return false;
}
this.$http.patch(`postcodes`, this.data).then(res => {
this.vnApp.showMessage(this.$translate.instant('The postcode has been saved'));
this.emit('response', {$response: res.data});
});
} catch (e) {
this.vnApp.showError(this.$translate.instant(e.message));
return false;
}
return true;
}

View File

@ -15,7 +15,7 @@ describe('Client', () => {
controller.client = {id: 101};
}));
describe('onResponse()', () => {
describe('onAccept()', () => {
it('should perform a POST query and show a success snackbar', () => {
let params = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
controller.data = {townFk: 1, provinceFk: 1, countryFk: 1, code: '46460'};
@ -24,7 +24,7 @@ describe('Client', () => {
$httpBackend.when('PATCH', `postcodes`, params).respond(200, params);
$httpBackend.expect('PATCH', `postcodes`, params).respond(params);
controller.onResponse('accept');
controller.onAccept();
$httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The postcode has been saved');

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('createThermograph', {
description: 'Upload and attach a document',
description: 'Creates a new travel thermograph',
accessType: 'WRITE',
accepts: [{
arg: 'id',

View File

@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('updateThermograph', {
description: 'updates a file properties or file',
description: 'Updates a travel thermograph',
accessType: 'WRITE',
accepts: [{
arg: 'id',