From b12d0388c971d947a247d5cf0c3c7d3f7dbe3cae Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Wed, 18 Sep 2019 09:41:25 +0200 Subject: [PATCH 1/2] #1074 Undo changes button for forms --- front/core/components/autocomplete/autocomplete.js | 6 +++--- front/core/components/watcher/watcher.js | 11 ++++++++++- front/core/components/watcher/watcher.spec.js | 10 ++++++++++ modules/agency/front/basic-data/index.html | 5 ++--- modules/claim/front/basic-data/index.html | 1 + modules/client/front/basic-data/index.html | 5 ++--- modules/client/front/basic-data/locale/es.yml | 3 ++- modules/client/front/billing-data/index.html | 1 + modules/client/front/fiscal-data/index.html | 4 ++-- modules/client/front/web-access/index.html | 1 + modules/item/front/basic-data/index.html | 1 + modules/item/front/botanical/index.html | 1 + modules/item/front/tax/index.html | 7 +++++++ modules/order/front/basic-data/index.html | 1 + modules/route/front/basic-data/index.html | 1 + modules/worker/front/basic-data/index.html | 1 + modules/worker/front/pbx/index.html | 1 + 17 files changed, 47 insertions(+), 13 deletions(-) diff --git a/front/core/components/autocomplete/autocomplete.js b/front/core/components/autocomplete/autocomplete.js index 91a88704af..469bb9e930 100755 --- a/front/core/components/autocomplete/autocomplete.js +++ b/front/core/components/autocomplete/autocomplete.js @@ -7,10 +7,10 @@ import './style.scss'; /** * Input with option selector. * - * @property {String} valueField The data field name that should be shown - * @property {String} showFiled The data field name that should be used as value + * @property {String} showFiled The data field name that should be shown + * @property {String} valueField The data field name that should be used as value * @property {Array} data Static data for the autocomplete - * @property {Object} intialData A initial data to avoid the server request used to get the selection + * @property {Object} intialData An initial data to avoid the server request used to get the selection * @property {Boolean} multiple Wether to allow multiple selection * @property {Object} selection Current object selected * diff --git a/front/core/components/watcher/watcher.js b/front/core/components/watcher/watcher.js index 84383f477e..a085ee45fc 100644 --- a/front/core/components/watcher/watcher.js +++ b/front/core/components/watcher/watcher.js @@ -39,7 +39,7 @@ export default class Watcher extends Component { throw new Error('URL parameter ommitted'); } - $onChanges(changes) { + $onChanges() { if (this.data) this.updateOriginalData(); } @@ -222,6 +222,15 @@ export default class Watcher extends Component { this.setPristine(); } + loadOriginalData() { + Object.keys(this.data).forEach(key => { + delete this.data[key]; + }); + + this.data = Object.assign(this.data, this.orgData); + this.setPristine(); + } + copyInNewObject(data) { let newCopy = {}; if (data && typeof data === 'object') { diff --git a/front/core/components/watcher/watcher.spec.js b/front/core/components/watcher/watcher.spec.js index 5bdbf56c80..32de7dda79 100644 --- a/front/core/components/watcher/watcher.spec.js +++ b/front/core/components/watcher/watcher.spec.js @@ -249,4 +249,14 @@ describe('Component vnWatcher', () => { }); }); }); + + describe(`loadOriginalData()`, () => { + it(`should iterate over the current data object, delete all properties then assign the ones from original data`, () => { + controller.data = {name: 'Bruce'}; + controller.orgData = {name: 'Batman'}; + controller.loadOriginalData(); + + expect(controller.data).toEqual(controller.orgData); + }); + }); }); diff --git a/modules/agency/front/basic-data/index.html b/modules/agency/front/basic-data/index.html index 5cff23eb16..7f4ed91ef8 100644 --- a/modules/agency/front/basic-data/index.html +++ b/modules/agency/front/basic-data/index.html @@ -75,8 +75,7 @@ - - + + diff --git a/modules/claim/front/basic-data/index.html b/modules/claim/front/basic-data/index.html index 9ff12acf7a..b626f57c74 100644 --- a/modules/claim/front/basic-data/index.html +++ b/modules/claim/front/basic-data/index.html @@ -59,5 +59,6 @@ + diff --git a/modules/client/front/basic-data/index.html b/modules/client/front/basic-data/index.html index 6fb455a763..f994d19054 100644 --- a/modules/client/front/basic-data/index.html +++ b/modules/client/front/basic-data/index.html @@ -43,7 +43,6 @@ - @@ -64,6 +62,7 @@ + diff --git a/modules/client/front/basic-data/locale/es.yml b/modules/client/front/basic-data/locale/es.yml index 7d7722e431..139d86d7dd 100644 --- a/modules/client/front/basic-data/locale/es.yml +++ b/modules/client/front/basic-data/locale/es.yml @@ -11,4 +11,5 @@ You can save multiple emails: >- Puede guardar varios correos electrónicos encadenándolos mediante comas sin espacios, ejemplo: user@dominio.com, user2@dominio.com siendo el primer correo electrónico el principal -Contact: Contacto \ No newline at end of file +Contact: Contacto +Undo changes: Deshacer cambios \ No newline at end of file diff --git a/modules/client/front/billing-data/index.html b/modules/client/front/billing-data/index.html index a7bcb71bd5..d923123b74 100644 --- a/modules/client/front/billing-data/index.html +++ b/modules/client/front/billing-data/index.html @@ -85,6 +85,7 @@ + diff --git a/modules/client/front/fiscal-data/index.html b/modules/client/front/fiscal-data/index.html index ceae68fb7f..acd2d69472 100644 --- a/modules/client/front/fiscal-data/index.html +++ b/modules/client/front/fiscal-data/index.html @@ -120,8 +120,8 @@ - - + + + + diff --git a/modules/item/front/botanical/index.html b/modules/item/front/botanical/index.html index 4742f70679..c1b6c32e4c 100644 --- a/modules/item/front/botanical/index.html +++ b/modules/item/front/botanical/index.html @@ -42,5 +42,6 @@ + \ No newline at end of file diff --git a/modules/item/front/tax/index.html b/modules/item/front/tax/index.html index 60b1114b53..9265c34ffe 100644 --- a/modules/item/front/tax/index.html +++ b/modules/item/front/tax/index.html @@ -4,6 +4,12 @@ data="classes" auto-load="true"> + +
@@ -23,5 +29,6 @@ +
\ No newline at end of file diff --git a/modules/order/front/basic-data/index.html b/modules/order/front/basic-data/index.html index 672ae92fa3..7a76d937fd 100644 --- a/modules/order/front/basic-data/index.html +++ b/modules/order/front/basic-data/index.html @@ -67,5 +67,6 @@ + diff --git a/modules/route/front/basic-data/index.html b/modules/route/front/basic-data/index.html index fb14d40986..da58ead63f 100644 --- a/modules/route/front/basic-data/index.html +++ b/modules/route/front/basic-data/index.html @@ -72,5 +72,6 @@ + diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index b12689c1d0..5c2f4d6cde 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -32,5 +32,6 @@ + diff --git a/modules/worker/front/pbx/index.html b/modules/worker/front/pbx/index.html index c0b34a73b6..1bb1bb265f 100644 --- a/modules/worker/front/pbx/index.html +++ b/modules/worker/front/pbx/index.html @@ -15,5 +15,6 @@ + From 031dbcb63a188cbb508f99391382af639b7b74e8 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Wed, 18 Sep 2019 10:35:46 +0200 Subject: [PATCH 2/2] Unlocked from autocomplete city and postcode fields #1703 --- e2e/helpers/selectors.js | 12 +++++------ .../02-client-module/01_create_client.spec.js | 7 +++++-- .../03_edit_fiscal_data.spec.js | 12 +++++++---- .../02-client-module/05_add_address.spec.js | 10 +++++++--- loopback/locale/en.json | 3 ++- loopback/locale/es.json | 5 ++++- modules/client/back/models/address.js | 15 ++++++++++++++ modules/client/back/models/client.js | 15 ++++++++++++++ .../client/front/address/create/index.html | 16 +++++++++++---- modules/client/front/address/edit/index.html | 16 +++++++++++---- modules/client/front/create/index.html | 20 +++++++++++++------ modules/client/front/fiscal-data/index.html | 12 +++++++++-- 12 files changed, 110 insertions(+), 33 deletions(-) diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index d4eb4562bd..d9d6cbc93e 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -33,8 +33,8 @@ export default { taxNumber: `${components.vnTextfield}[name="fi"]`, socialName: `${components.vnTextfield}[name="socialName"]`, street: `${components.vnTextfield}[name="street"]`, - postcode: `vn-autocomplete[field="$ctrl.client.postcode"]`, - city: `vn-autocomplete[field="$ctrl.client.city"]`, + postcode: `${components.vnTextfield}[name="postcode"]`, + city: `${components.vnTextfield}[name="city"]`, province: `vn-autocomplete[field="$ctrl.client.provinceFk"]`, country: `vn-autocomplete[field="$ctrl.client.countryFk"]`, userName: `${components.vnTextfield}[name="userName"]`, @@ -65,8 +65,8 @@ export default { equalizationTaxCheckbox: 'vn-check[label="Is equalizated"] md-checkbox', acceptPropagationButton: 'vn-client-fiscal-data > vn-confirm button[response=ACCEPT]', addressInput: `${components.vnTextfield}[name="street"]`, - postcodeAutocomplete: `vn-autocomplete[field="$ctrl.client.postcode"]`, - cityAutocomplete: `vn-autocomplete[field="$ctrl.client.city"]`, + postcodeInput: `${components.vnTextfield}[name="postcode"]`, + cityInput: `${components.vnTextfield}[name="city"]`, provinceAutocomplete: 'vn-autocomplete[field="$ctrl.client.provinceFk"]', countryAutocomplete: 'vn-autocomplete[field="$ctrl.client.countryFk"]', activeCheckbox: 'vn-check[label="Active"] md-checkbox', @@ -100,8 +100,8 @@ export default { defaultCheckboxInput: 'vn-check[label="Default"] md-checkbox', consigneeInput: `${components.vnTextfield}[name="nickname"]`, streetAddressInput: `${components.vnTextfield}[name="street"]`, - postcodeAutocomplete: `vn-autocomplete[field="$ctrl.address.postalCode"]`, - cityAutocomplete: `vn-autocomplete[field="$ctrl.address.city"]`, + postcodeInput: `${components.vnTextfield}[name="postalCode"]`, + cityInput: `${components.vnTextfield}[name="city"]`, provinceAutocomplete: 'vn-autocomplete[field="$ctrl.address.provinceFk"]', agencyAutocomplete: 'vn-autocomplete[field="$ctrl.address.agencyModeFk"]', phoneInput: `${components.vnTextfield}[name="phone"]`, diff --git a/e2e/paths/02-client-module/01_create_client.spec.js b/e2e/paths/02-client-module/01_create_client.spec.js index b9ea5e1129..b67a89e68f 100644 --- a/e2e/paths/02-client-module/01_create_client.spec.js +++ b/e2e/paths/02-client-module/01_create_client.spec.js @@ -53,7 +53,10 @@ describe('Client create path', () => { .write(selectors.createClientView.name, 'Carol Danvers') .write(selectors.createClientView.socialName, 'AVG tax') .write(selectors.createClientView.street, 'Many places') - .autocompleteSearch(selectors.createClientView.postcode, '46000') + .autocompleteSearch(selectors.createClientView.country, 'España') + .autocompleteSearch(selectors.createClientView.province, 'Province one') + .write(selectors.createClientView.city, 'Valencia') + .write(selectors.createClientView.postcode, '46000') .clearInput(selectors.createClientView.email) .write(selectors.createClientView.email, 'incorrect email format') .waitToClick(selectors.createClientView.createButton) @@ -64,7 +67,7 @@ describe('Client create path', () => { it(`should check for autocompleted city, province and country`, async() => { const clientCity = await nightmare - .waitToGetProperty(`${selectors.createClientView.city} input`, 'value'); + .waitToGetProperty(`${selectors.createClientView.city}`, 'value'); const clientProvince = await nightmare .waitToGetProperty(`${selectors.createClientView.province} input`, 'value'); diff --git a/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js b/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js index b304a03eeb..ae3020d2ad 100644 --- a/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js +++ b/e2e/paths/02-client-module/03_edit_fiscal_data.spec.js @@ -67,8 +67,12 @@ describe('Client Edit fiscalData path', () => { .write(selectors.clientFiscalData.fiscalIdInput, 'INVALID!') .clearInput(selectors.clientFiscalData.addressInput) .write(selectors.clientFiscalData.addressInput, 'Somewhere edited') - .autocompleteSearch(selectors.clientFiscalData.cityAutocomplete, 'Valencia') - .autocompleteSearch(selectors.clientFiscalData.postcodeAutocomplete, '46000') + .autocompleteSearch(selectors.clientFiscalData.countryAutocomplete, 'España') + .autocompleteSearch(selectors.clientFiscalData.provinceAutocomplete, 'Province one') + .clearInput(selectors.clientFiscalData.cityInput) + .write(selectors.clientFiscalData.cityInput, 'Valencia') + .clearInput(selectors.clientFiscalData.postcodeInput) + .write(selectors.clientFiscalData.postcodeInput, '46000') .waitToClick(selectors.clientFiscalData.activeCheckbox) .waitToClick(selectors.clientFiscalData.frozenCheckbox) .waitToClick(selectors.clientFiscalData.hasToInvoiceCheckbox) @@ -194,14 +198,14 @@ describe('Client Edit fiscalData path', () => { it('should confirm the postcode have been edited', async() => { const result = await nightmare - .waitToGetProperty(`${selectors.clientFiscalData.postcodeAutocomplete} input`, 'value'); + .waitToGetProperty(`${selectors.clientFiscalData.postcodeInput}`, 'value'); expect(result).toContain('46000'); }); it('should confirm the city have been autocompleted', async() => { const result = await nightmare - .waitToGetProperty(`${selectors.clientFiscalData.cityAutocomplete} input`, 'value'); + .waitToGetProperty(`${selectors.clientFiscalData.cityInput}`, 'value'); expect(result).toEqual('Valencia'); }); diff --git a/e2e/paths/02-client-module/05_add_address.spec.js b/e2e/paths/02-client-module/05_add_address.spec.js index 08227fc0f2..f4e68634a5 100644 --- a/e2e/paths/02-client-module/05_add_address.spec.js +++ b/e2e/paths/02-client-module/05_add_address.spec.js @@ -24,7 +24,11 @@ describe('Client Add address path', () => { const result = await nightmare .waitToClick(selectors.clientAddresses.defaultCheckboxInput) .clearInput(selectors.clientAddresses.streetAddressInput) - .autocompleteSearch(selectors.clientAddresses.postcodeAutocomplete, '46000') + .autocompleteSearch(selectors.clientAddresses.provinceAutocomplete, 'Province one') + .clearInput(selectors.clientAddresses.cityInput) + .write(selectors.clientAddresses.cityInput, 'Valencia') + .clearInput(selectors.clientAddresses.postcodeInput) + .write(selectors.clientAddresses.postcodeInput, '46000') .autocompleteSearch(selectors.clientAddresses.agencyAutocomplete, 'Entanglement') .write(selectors.clientAddresses.phoneInput, '999887744') .write(selectors.clientAddresses.mobileInput, '999887744') @@ -36,14 +40,14 @@ describe('Client Add address path', () => { it('should confirm the postcode have been edited', async() => { const result = await nightmare - .waitToGetProperty(`${selectors.clientAddresses.postcodeAutocomplete} input`, 'value'); + .waitToGetProperty(`${selectors.clientAddresses.postcodeInput}`, 'value'); expect(result).toContain('46000'); }); it('should confirm the city have been autocompleted', async() => { const result = await nightmare - .waitToGetProperty(`${selectors.clientAddresses.cityAutocomplete} input`, 'value'); + .waitToGetProperty(`${selectors.clientAddresses.cityInput}`, 'value'); expect(result).toEqual('Valencia'); }); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 7aea68f028..4c29d0a70d 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -54,5 +54,6 @@ "Weekday cannot be blank": "Weekday cannot be blank", "This ticket can not be modified": "This ticket can not be modified", "You can't delete a confirmed order": "You can't delete a confirmed order", - "Value has an invalid format": "Value has an invalid format" + "Value has an invalid format": "Value has an invalid format", + "The postcode doesn't exists. Ensure you put the correct format": "The postcode doesn't exists. Ensure you put the correct format" } \ No newline at end of file diff --git a/loopback/locale/es.json b/loopback/locale/es.json index fd09e8b1f9..43b3c8177f 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -104,5 +104,8 @@ "You can't delete a confirmed order": "No puedes borrar un pedido confirmado", "Can't create stowaway for this ticket": "No se puede crear un polizon para este ticket", "Value has an invalid format": "El valor tiene un formato incorrecto", - "Invalid quantity": "Cantidad invalida" + "Invalid quantity": "Cantidad invalida", + "This postal code is not valid": "This postal code is not valid", + "is invalid": "is invalid", + "The postcode doesn't exists. Ensure you put the correct format": "El código postal no existe. Asegúrate de ponerlo con el formato correcto" } \ No newline at end of file diff --git a/modules/client/back/models/address.js b/modules/client/back/models/address.js index d0cfd09004..afdacdee5e 100644 --- a/modules/client/back/models/address.js +++ b/modules/client/back/models/address.js @@ -42,6 +42,21 @@ module.exports = Self => { next(); }); + Self.validateAsync('postalCode', hasValidPostcode, { + message: `The postcode doesn't exists. Ensure you put the correct format` + }); + + async function hasValidPostcode(err, done) { + if (!this.postalCode) + return done(); + + const models = Self.app.models; + const postcode = await models.Postcode.findById(this.postalCode); + + if (!postcode) err(); + done(); + } + // Helpers Self.observe('before save', async function(ctx) { diff --git a/modules/client/back/models/client.js b/modules/client/back/models/client.js index 24659b3664..a5536c76e0 100644 --- a/modules/client/back/models/client.js +++ b/modules/client/back/models/client.js @@ -160,6 +160,21 @@ module.exports = Self => { return regexp.test(value); } + Self.validateAsync('postCode', hasValidPostcode, { + message: `The postcode doesn't exists. Ensure you put the correct format` + }); + + async function hasValidPostcode(err, done) { + if (!this.postcode) + return done(); + + const models = Self.app.models; + const postcode = await models.Postcode.findById(this.postcode); + + if (!postcode) err(); + done(); + } + Self.observe('before save', async function(ctx) { let changes = ctx.data || ctx.instance; let orgData = ctx.currentInstance; diff --git a/modules/client/front/address/create/index.html b/modules/client/front/address/create/index.html index 432d4ebbe9..0240aceb5f 100644 --- a/modules/client/front/address/create/index.html +++ b/modules/client/front/address/create/index.html @@ -31,7 +31,11 @@ value-field="id" label="Province"> - + + + + + - + + + + + - + + + + + + - + + + +