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

View File

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

View File

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

View File

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

View File

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