diff --git a/client/client/src/address-edit/address-edit.html b/client/client/src/address-edit/address-edit.html index a6e2b9499..a5830d715 100644 --- a/client/client/src/address-edit/address-edit.html +++ b/client/client/src/address-edit/address-edit.html @@ -61,29 +61,36 @@ {{$parent.$parent.item.description}} - + - - + + + + diff --git a/client/client/src/address-edit/address-edit.js b/client/client/src/address-edit/address-edit.js index ef20f68f1..4d73dc215 100644 --- a/client/client/src/address-edit/address-edit.js +++ b/client/client/src/address-edit/address-edit.js @@ -17,18 +17,6 @@ export default class Controller { this.observationsRemoved = []; } - _setIconAdd() { - if (this.observations.length) { - this.observations.map(element => { - element.showAddIcon = false; - return true; - }); - this.observations[this.observations.length - 1].showAddIcon = true; - } else { - this.addObservation(); - } - } - _setDirtyForm() { if (this.$scope.form) { this.$scope.form.$setDirty(); @@ -41,15 +29,13 @@ export default class Controller { } addObservation() { - this.observations.push({observationTypeFk: null, addressFk: this.address.id, description: null, showAddIcon: true}); - this._setIconAdd(); + this.observations.push({observationTypeFk: null, addressFk: this.address.id, description: null}); } removeObservation(index) { let item = this.observations[index]; if (item) { this.observations.splice(index, 1); - this._setIconAdd(); if (item.id) { this.observationsRemoved.push(item.id); this._setDirtyForm(); @@ -65,7 +51,10 @@ export default class Controller { } submit() { - this._unsetDirtyForm(); + if (this.$scope.form.$invalid) { + return false; + } + let canWatcherSubmit = this.$scope.watcher.dataChanged(); let canObservationsSubmit; let repeatedTypes = false; @@ -118,6 +107,7 @@ export default class Controller { this.$translate.instant('No changes to save') ); } + this._unsetDirtyForm(); } $onInit() { diff --git a/client/client/src/address-edit/address-edit.spec.js b/client/client/src/address-edit/address-edit.spec.js index 727772d7e..23499bd33 100644 --- a/client/client/src/address-edit/address-edit.spec.js +++ b/client/client/src/address-edit/address-edit.spec.js @@ -23,56 +23,6 @@ describe('Client', () => { expect(controller.address.id).toEqual(1); }); - describe('_setIconAdd()', () => { - it('should set the propertie sowAddIcon from all observations to false less last one that be true', () => { - controller.observations = [ - {id: 1, description: 'Spiderman rocks', showAddIcon: true}, - {id: 2, description: 'Batman sucks', showAddIcon: true}, - {id: 3, description: 'Ironman rules', showAddIcon: false} - ]; - - controller._setIconAdd(); - - expect(controller.observations[0].showAddIcon).toBeFalsy(); - expect(controller.observations[1].showAddIcon).toBeFalsy(); - expect(controller.observations[2].showAddIcon).toBeTruthy(); - }); - }); - - describe('addObservation()', () => { - it('should add one empty observation into controller observations collection and call _setIconAdd()', () => { - controller.observations = []; - spyOn(controller, '_setIconAdd').and.callThrough(); - controller.addObservation(); - - expect(controller._setIconAdd).toHaveBeenCalledWith(); - expect(controller.observations.length).toEqual(1); - expect(controller.observations[0].id).toBe(undefined); - expect(controller.observations[0].showAddIcon).toBeTruthy(); - }); - }); - - describe('removeObservation(index)', () => { - it('should remove an observation that occupies the position in the index given and call _setIconAdd()', () => { - let index = 2; - controller.observations = [ - {id: 1, description: 'Spiderman rocks', showAddIcon: false}, - {id: 2, description: 'Batman sucks', showAddIcon: false}, - {id: 3, description: 'Ironman rules', showAddIcon: true} - ]; - - spyOn(controller, '_setIconAdd').and.callThrough(); - - controller.removeObservation(index); - - expect(controller._setIconAdd).toHaveBeenCalledWith(); - expect(controller.observations.length).toEqual(2); - expect(controller.observations[0].showAddIcon).toBeFalsy(); - expect(controller.observations[1].showAddIcon).toBeTruthy(); - expect(controller.observations[index]).toBe(undefined); - }); - }); - describe('_observationsEquals', () => { it('should return true if two observations are equals independent of control attributes', () => { let ob1 = {id: 1, observationTypeFk: 1, description: 'Spiderman rocks', showAddIcon: true}; diff --git a/client/client/src/address-edit/locale/es.yml b/client/client/src/address-edit/locale/es.yml index 78f236039..aa9c23ef0 100644 --- a/client/client/src/address-edit/locale/es.yml +++ b/client/client/src/address-edit/locale/es.yml @@ -2,4 +2,6 @@ Enabled: Activo Is equalizated: Recargo de equivalencia Observation type: Tipo de observación Description: Descripción -The observation type must be unique: El tipo de observación ha de ser único \ No newline at end of file +The observation type must be unique: El tipo de observación ha de ser único +Add note: Añadir nota +Remove note: Quitar nota \ No newline at end of file diff --git a/services/db/04-fixtures.sql b/services/db/04-fixtures.sql index 8e26f3250..c63c9f616 100644 --- a/services/db/04-fixtures.sql +++ b/services/db/04-fixtures.sql @@ -24,6 +24,16 @@ INSERT INTO `account`.`user`(`id`,`name`,`password`,`role`,`active`,`email`) (109, 'BruceBanner', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'BruceBanner@verdnatura.es'), (110, 'JessicaJones', 'ac754a330530832ba1bf7687f577da91', 2, 1, 'JessicaJones@verdnatura.es'); + + + INSERT INTO `vn`.`worker`(`workerCode`, `id`, `firstName`, `name`, `userFk`) + VALUES + ('LGN', 106, 'David Charles', 'Haller', 106), + ('ANT', 107, 'Hank', 'Pym', 107), + ('DCX', 108, 'Charles', 'Xavier', 108), + ('HLK', 109, 'Bruce', 'Banner', 109), + ('JJJ', 110, 'Jessica', 'Jones', 110); + INSERT INTO `vn`.`country`(`id`, `country`, `isUeeMember`, `code`, `currencyFk`) VALUES (1, 'España', 0, 'ES', 1), @@ -125,11 +135,11 @@ INSERT INTO `vn`.`client`(`id`,`name`,`fi`,`socialName`,`contact`,`street`,`city (103, 'Clark Kent', '06815934E', 'Super-Man', 'lois lane', '344 Clinton Street', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'ClarkKent@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1), (104, 'Tony Stark', '06089160W', 'Iron-Man', 'Pepper Potts', '10880 Malibu Point', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'TonyStark@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1), (105, 'Max Eisenhardt', '39182496H', 'Magneto', 'Rogue', 'Unknown Whereabouts', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'MaxEisenhardt@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 18, 0, 1), - (106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'DavidCharlesHaller@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1), + (106, 'DavidCharlesHaller', '53136686Q', 'Legion', 'Charles Xavier', 'Evil hideout', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'DavidCharlesHaller@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 0,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1), (107, 'Hank Pym', '09854837G', 'Ant-Man', 'Hawk', 'Anthill', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'HankPym@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1), (108, 'Charles Xavier', '22641921P', 'Professor X', 'Beast', '3800 Victory Pkwy, Cincinnati, OH 45207, USA', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'CharlesXavier@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1), (109, 'Bruce Banner', '16104829E', 'Hulk', 'Black widow', 'Somewhere in New York', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'BruceBanner@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 0, 1, NULL, 0, 0, 19, 0, 1), - (110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 1, 1, NULL, 0, 0, 19, 0, 1); + (110, 'Jessica Jones', '58282869H', 'Jessica Jones', 'Luke Cage', 'NYCC 2015 Poster', 'Silla', 46460, 1111111111, 222222222, 333333333, 1, 'JessicaJones@verdnatura.es', NULL, 0, 1234567890, 0, 1, 1, 300, 1, 1,NULL, 10, 5,CURDATE(), 1, 5, 1, 1, 1,'0000-00-00', 1, NULL, 1, 1, 0, 1, NULL, 0, 0, 19, 0, 1); INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `provinceFk`, `phone`, `mobile`, `isActive`, `isDefaultAddress`, `clientFk`, `agencyModeFk`, `longitude`, `latitude`, `isEqualizated`) VALUES diff --git a/services/loopback/common/methods/client/filter.js b/services/loopback/common/methods/client/filter.js index 2c79e0556..bb1288630 100644 --- a/services/loopback/common/methods/client/filter.js +++ b/services/loopback/common/methods/client/filter.js @@ -40,16 +40,17 @@ module.exports = function(Client) { delete params.phone; } - let keys = Object.keys(params); - if (keys.length) { - keys.forEach( - key => { + let properties = Object.keys(params); + if (properties.length) { + properties.forEach( + property => { + let propertyToBeEqual = (property === 'postcode' || property === 'fi' || property === 'id'); if (filters.where.and) { let filter = {}; - filter[key] = (key === 'postcode' || key === 'fi' || key === 'id') ? params[key] : {regexp: params[key]}; + filter[property] = propertyToBeEqual ? params[property] : {regexp: params[property]}; filters.where.and.push(filter); } else { - filters.where[key] = (key === 'postcode' || key === 'fi' || key === 'id') ? params[key] : {regexp: params[key]}; + filters.where[property] = propertyToBeEqual ? params[property] : {regexp: params[property]}; } } ); diff --git a/services/loopback/common/methods/client/specs/listWorkers.spec.js b/services/loopback/common/methods/client/specs/listWorkers.spec.js index 7c3ed2acd..170975d6f 100644 --- a/services/loopback/common/methods/client/specs/listWorkers.spec.js +++ b/services/loopback/common/methods/client/specs/listWorkers.spec.js @@ -7,7 +7,7 @@ describe('Client listWorkers', () => { .then(result => { let amountOfEmployees = Object.keys(result).length; - expect(amountOfEmployees).toEqual(29); + expect(amountOfEmployees).toEqual(32); done(); }) .catch(catchErrors(done));