Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
Juan Ferrer Toribio 2018-02-07 13:24:51 +01:00
commit 98b26a3c27
4 changed files with 21 additions and 17 deletions

View File

@ -77,7 +77,7 @@
margin-medium-left margin-medium-left
orange orange
icon="add_circle" icon="add_circle"
ng-if = "observation.showAddIcon" ng-if = "observation.showAddIcon && observationsTypes.model.length > $ctrl.observations.length"
ng-click="$ctrl.addObservation()" ng-click="$ctrl.addObservation()"
></vn-icon> ></vn-icon>
</vn-one> </vn-one>

View File

@ -13,7 +13,7 @@ export default class Controller {
id: parseInt($state.params.addressId) id: parseInt($state.params.addressId)
}; };
this.observations = []; this.observations = [];
this.observationsDictionary = {}; this.observationsOld = {};
this.observationsRemoved = []; this.observationsRemoved = [];
} }
@ -60,11 +60,16 @@ export default class Controller {
return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, objectObservations); return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, objectObservations);
} }
_observationsEquals(ob1, ob2) {
return ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description;
}
submit() { submit() {
this._unsetDirtyForm(); this._unsetDirtyForm();
let submitWatcher = this.$scope.watcher.dataChanged(); let submitWatcher = this.$scope.watcher.dataChanged();
let submitObservations; let submitObservations;
let repeatedTypes = false; let repeatedTypes = false;
let types = [];
let observationsObj = { let observationsObj = {
delete: this.observationsRemoved, delete: this.observationsRemoved,
create: [], create: [],
@ -73,31 +78,27 @@ export default class Controller {
for (let i = 0; i < this.observations.length; i++) { for (let i = 0; i < this.observations.length; i++) {
let observation = this.observations[i]; let observation = this.observations[i];
// only one observation is allowed for each of its types let isNewObservation = observation.id === undefined;
if (this.observationsDictionary[observation.observationTypeFk] !== undefined && // IF the dictionary contains the type
( if (types.indexOf(observation.observationTypeFk) !== -1) {
// AND (is a new Observation OR is old but with distinct Id) --> repeated
!observation.id || (observation.id && this.observationsDictionary[observation.observationTypeFk].id !== observation.id)
)
) {
repeatedTypes = true; repeatedTypes = true;
break; break;
} }
if (!observation.id && observation.observationTypeFk && observation.description) { types.push(observation.observationTypeFk);
if (isNewObservation && observation.observationTypeFk && observation.description) {
observationsObj.create.push(observation); observationsObj.create.push(observation);
} else if (observation.id && this.observationsDictionary[observation.observationTypeFk].description !== observation.description) { } else if (!isNewObservation && !this._observationsEquals(this.observationsOld[observation.id], observation)) {
observationsObj.update.push(observation); observationsObj.update.push(observation);
} }
this.observationsDictionary[observation.observationTypeFk] = observation;
} }
submitObservations = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0; submitObservations = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
if (repeatedTypes) { if (repeatedTypes) {
this.vnApp.showMessage( this.vnApp.showMessage(
this.$translate.instant('you can not repeat the types of observations') this.$translate.instant('The observation type must be unique')
); );
} else if (submitWatcher && !submitObservations) { } else if (submitWatcher && !submitObservations) {
this.$scope.watcher.submit().then(() => { this.$scope.watcher.submit().then(() => {
@ -126,7 +127,7 @@ export default class Controller {
this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => { this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => {
this.observations = res.data; this.observations = res.data;
res.data.forEach(item => { res.data.forEach(item => {
this.observationsDictionary[item.observationTypeFk] = Object.assign({}, item); this.observationsOld[item.id] = Object.assign({}, item);
}); });
}); });
} }

View File

@ -1,2 +1,5 @@
Enabled: Activo Enabled: Activo
Is equalizated: Recargo de equivalencia 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

View File

@ -181,7 +181,7 @@ gulp.task('nginx-stop', ['nginx-conf'], async () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
exec(command, err => { exec(command, err => {
if (err) return reject(err); if (err && err.code != 1) return reject(err);
resolve(); resolve();
}); });
}); });