Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
98b26a3c27
|
@ -77,7 +77,7 @@
|
|||
margin-medium-left
|
||||
orange
|
||||
icon="add_circle"
|
||||
ng-if = "observation.showAddIcon"
|
||||
ng-if = "observation.showAddIcon && observationsTypes.model.length > $ctrl.observations.length"
|
||||
ng-click="$ctrl.addObservation()"
|
||||
></vn-icon>
|
||||
</vn-one>
|
||||
|
|
|
@ -13,7 +13,7 @@ export default class Controller {
|
|||
id: parseInt($state.params.addressId)
|
||||
};
|
||||
this.observations = [];
|
||||
this.observationsDictionary = {};
|
||||
this.observationsOld = {};
|
||||
this.observationsRemoved = [];
|
||||
}
|
||||
|
||||
|
@ -60,11 +60,16 @@ export default class Controller {
|
|||
return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, objectObservations);
|
||||
}
|
||||
|
||||
_observationsEquals(ob1, ob2) {
|
||||
return ob1.observationTypeFk === ob2.observationTypeFk && ob1.description === ob2.description;
|
||||
}
|
||||
|
||||
submit() {
|
||||
this._unsetDirtyForm();
|
||||
let submitWatcher = this.$scope.watcher.dataChanged();
|
||||
let submitObservations;
|
||||
let repeatedTypes = false;
|
||||
let types = [];
|
||||
let observationsObj = {
|
||||
delete: this.observationsRemoved,
|
||||
create: [],
|
||||
|
@ -73,31 +78,27 @@ export default class Controller {
|
|||
|
||||
for (let i = 0; i < this.observations.length; i++) {
|
||||
let observation = this.observations[i];
|
||||
// only one observation is allowed for each of its types
|
||||
if (this.observationsDictionary[observation.observationTypeFk] !== undefined && // IF the dictionary contains the type
|
||||
(
|
||||
// AND (is a new Observation OR is old but with distinct Id) --> repeated
|
||||
!observation.id || (observation.id && this.observationsDictionary[observation.observationTypeFk].id !== observation.id)
|
||||
)
|
||||
) {
|
||||
let isNewObservation = observation.id === undefined;
|
||||
|
||||
if (types.indexOf(observation.observationTypeFk) !== -1) {
|
||||
repeatedTypes = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!observation.id && observation.observationTypeFk && observation.description) {
|
||||
types.push(observation.observationTypeFk);
|
||||
|
||||
if (isNewObservation && observation.observationTypeFk && observation.description) {
|
||||
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);
|
||||
}
|
||||
|
||||
this.observationsDictionary[observation.observationTypeFk] = observation;
|
||||
}
|
||||
|
||||
submitObservations = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
|
||||
|
||||
if (repeatedTypes) {
|
||||
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) {
|
||||
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.observations = res.data;
|
||||
res.data.forEach(item => {
|
||||
this.observationsDictionary[item.observationTypeFk] = Object.assign({}, item);
|
||||
this.observationsOld[item.id] = Object.assign({}, item);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,2 +1,5 @@
|
|||
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
|
|
@ -181,7 +181,7 @@ gulp.task('nginx-stop', ['nginx-conf'], async () => {
|
|||
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(command, err => {
|
||||
if (err) return reject(err);
|
||||
if (err && err.code != 1) return reject(err);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue