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

* 'dev' of https://git.verdnatura.es/salix:
  watcher: removed unnecessary injection
  removed unnecessary function in equals.js
  watcher renamed properties
  refactor watcher
This commit is contained in:
Carlos 2017-10-05 09:58:28 +02:00
commit 231bd9f813
5 changed files with 34 additions and 33 deletions

View File

@ -22,7 +22,7 @@
"state": "clientCard.basicData",
"component": "vn-client-basic-data",
"params": {
"client": "card.client"
"client": "$ctrl.client"
},
"menu": {
"description": "Datos básicos",
@ -33,7 +33,7 @@
"state": "clientCard.fiscalData",
"component": "vn-client-fiscal-data",
"params": {
"client": "card.client"
"client": "$ctrl.client"
},
"menu": {
"description": "Datos fiscales",
@ -44,7 +44,7 @@
"state": "clientCard.billingData",
"component": "vn-client-billing-data",
"params": {
"client": "card.client"
"client": "$ctrl.client"
},
"menu": {
"description": "Datos facturación",
@ -60,7 +60,7 @@
"state": "clientCard.addresses.list",
"component": "vn-client-addresses",
"params": {
"client": "card.client"
"client": "$ctrl.client"
},
"menu": {
"description": "Consignatarios",
@ -79,7 +79,7 @@
"state": "clientCard.webAccess",
"component": "vn-client-web-access",
"params": {
"client": "card.client"
"client": "$ctrl.client"
},
"menu": {
"description": "Acceso web",
@ -95,7 +95,7 @@
"state": "clientCard.notes.list",
"component": "vn-client-notes",
"params": {
"client": "card.client"
"client": "$ctrl.client"
},
"menu": {
"description": "Notas",

View File

@ -1,13 +1,13 @@
<vn-horizontal>
<mg-ajax
path="/client/api/Clients/{{edit.params.id}}/card"
actions="card.client = edit.model"
actions="$ctrl.client = edit.model"
options="mgEdit">
</mg-ajax>
<vn-empty style="min-width: 18em; padding-left: 1em; padding-bottom: 1em;">
<vn-descriptor
client="card.client"
active="card.client.active"
client="$ctrl.client"
active="$ctrl.client.active"
class="display-block" >
</vn-descriptor>
<vn-left-menu></vn-left-menu>

View File

@ -9,6 +9,5 @@ export default class Controller {
ngModule.component('vnClientCard', {
template: require('./card.html'),
controller: Controller,
controllerAs: 'card'
controller: Controller
});

View File

@ -1,6 +1,7 @@
import {module} from '../module';
const isEqual = angular.equals;
export default isEqual;
export const NAME = 'equalsObject';

View File

@ -1,7 +1,7 @@
import {module} from '../module';
import Component from '../lib/component';
import getModifiedData from '../lib/modified';
// import copyObject from '../lib/copy';
import copyObject from '../lib/copy';
import isEqual from '../lib/equals';
/**
@ -22,7 +22,7 @@ export default class Watcher extends Component {
this.state = null;
this.deregisterCallback = $transitions.onStart({},
transition => this.callback(transition));
this.copyData();
this.updateOriginalData();
}
$onInit() {
@ -35,7 +35,7 @@ export default class Watcher extends Component {
$onChanges(changes) {
if (this.data) {
this.copyData();
this.updateOriginalData();
}
}
@ -48,8 +48,8 @@ export default class Watcher extends Component {
// return new Promise((resolve, reject) => {
this.$http.get(`${this.url}/${id}`).then(
json => {
this.data = this.copyObject(json.data);
this.copyData();
this.data = copyObject(json.data);
this.updateOriginalData();
}
// json => reject(json)
);
@ -126,13 +126,8 @@ export default class Watcher extends Component {
}
writeData(json, resolve) {
Object.keys(this.data).forEach(
key => {
this.data[key] = json.data[key];
}
);
this.copyData();
Object.assign(this.data, json.data);
this.updateOriginalData();
resolve(json);
}
@ -150,21 +145,26 @@ export default class Watcher extends Component {
resolve();
}
copyData() {
this.orgData = this.copyObject(this.data);
updateOriginalData() {
this.orgData = this.copyInNewObject(this.data);
}
copyObject(data) {
let copy = {};
if (data) {
copyInNewObject(data) {
let newCopy = {};
if (data && typeof data === 'object') {
Object.keys(data).forEach(
val => {
if (data[val] !== "" && data[val] !== undefined && data[val] !== null)
copy[val] = data[val];
if (data[val] !== "" && data[val] !== undefined && data[val] !== null) {
if (typeof data[val] === 'object') {
newCopy[val] = this.copyInNewObject(data[val]);
} else {
newCopy[val] = data[val];
}
}
}
);
}
return copy;
return newCopy;
}
callback(transition) {
@ -179,14 +179,15 @@ export default class Watcher extends Component {
}
dataChanged() {
let newData = this.copyObject(this.data);
let newData = this.copyInNewObject(this.data);
return !isEqual(newData, this.orgData);
}
onConfirmResponse(response) {
if (response === 'ACCEPT') {
this.data = this.copyObject(this.orgData);
Object.assign(this.data, this.orgData);
this.$state.go(this.state);
} else {
this.state = null;
}