clientObservation contra modelo correcto

This commit is contained in:
Javi Gallego 2017-01-17 15:03:32 +01:00
parent b469b52ba1
commit 826b340c20
5 changed files with 65 additions and 19 deletions

View File

@ -1,16 +1,16 @@
<form name="form" ng-submit="form.$valid && notes.submit()" pad-medium>
<form name="form" ng-submit="form.$valid && observation.submit()" pad-medium>
<vn-card>
<vn-vertical pad-large>
<vn-title>Notas</vn-title>
<vn-textarea label="Notas" model="notes.newNote" focus padd-medium-top></vn-textarea>
<vn-textarea label="Notas" model="observation.newNote" focus padd-medium-top></vn-textarea>
</vn-vertical>
</vn-card>
<div margin-small-top>
<vn-submit label="Guardar"></vn-submit>
</div>
<vn-card margin-small-top>
<div ng-repeat="n in notes.notes">
<p><b>{{n.date}}</b></p>
<div ng-repeat="n in observation.observations">
<p><b>{{n.creationDate}} {{n.salesPerson}}</b></p>
<p>>{{n.text}}</p>
</div>
<div style="margin:0" pad-large>{{notes.client.notes}}</div>

View File

@ -4,23 +4,57 @@ import {module} from '../../module';
export const NAME = 'vnClientNotes';
export const COMPONENT = {
template: template,
controllerAs: 'notes',
controllerAs: 'observation',
bindings: {
client: '<'
},
controller: function($http) {
this.notes = [];
this.submit = function() {
this.notes.push({
text: this.newNote,
salesPerson: 'user'
});
controller: function($http, copyObject, equalsObject, $transitions, $element) {
var self = this;
var deregister = $transitions.onStart({ }, callback);
$http.put('/client/api/ClientObservation', this.client).then(() => {
this.newNote = "";
});
this.submit = function() {
if (this.newNote) {
this.client.modify = "ClientObservation";
let observation = {
client: this.client.id,
text: this.newNote,
salesPerson: 'user'
};
this.observations.unshift(observation);
$http.put('/client/api/ClientObservations', observation).then(() => {
this.newNote = "";
});
}
};
this.$onChanges = function(changes) {
if (this.client) {
this.getObservation(this.client.id);
}
};
this.$onDestroy = function() {
deregister();
};
function callback(transition) {
if (!equalsObject(self.observation, self.observationOld)) {
self.state = transition.to().name;
var dialog = $element[0].querySelector('dialog');
dialog.showModal();
return false;
}
}
this.getObservation = function(clientId) {
let json = JSON.stringify({where: {client: this.client.id}});
$http.get(`/client/api/clientObservations?filter=${json}`).then(
json => {
this.observations = json.data;
}
);
};
}
};
COMPONENT.controller.$inject = ['$http'];
COMPONENT.controller.$inject = ['$http', 'copyObject', 'equalsObject', '$transitions', '$element'];
module.component(NAME, COMPONENT);

12
db.json
View File

@ -9,7 +9,8 @@
"Country": 3,
"Province": 3,
"Agency": 4,
"Account": 14
"Account": 14,
"ClientObservation": 1248
},
"models": {
"User": {
@ -54,6 +55,15 @@
"Account": {
"12": "{\"id\":12,\"name\":\"prueba12\",\"active\":false,\"user\":\"juanete\"}",
"13": "{\"id\":13,\"name\":\"manu\",\"active\":false,\"user\":\"joselito\"}"
},
"ClientObservation": {
"12": "{\"id\":12,\"text\":\"prueba12\"}",
"41": "{\"id\":41,\"text\":\"text41\",\"creationDate\":\"2017-01-17T00:00:00.000Z\",\"client\":12,\"sdfopi\":24}",
"1243": "{\"id\":1243,\"text\":\"string\",\"creationDate\":\"2017-01-17T00:00:00.000Z\",\"relations\":{\"clientId\":12},\"client\":1289034237891}",
"1244": "{\"text\":\"asdf\",\"client\":12,\"salesPerson\":\"user\",\"id\":1244}",
"1245": "{\"text\":\"asdf\",\"client\":12,\"salesPerson\":\"user\",\"id\":1245}",
"1246": "{\"text\":\"asdf\",\"client\":12,\"salesPerson\":\"user\",\"id\":1246}",
"1247": "{\"text\":\"zzzz\",\"client\":12,\"salesPerson\":\"user\",\"id\":1247}"
}
}
}

View File

@ -24,9 +24,9 @@
"foreignKey": "salePersonId"
},
"client": {
"type": "belongsTo",
"model": "Client",
"foreignKey": "clientId"
"type": "belongsTo",
"foreignKey": "id"
}
}
}

View File

@ -51,3 +51,5 @@
2017/01/13 15:37:25 [notice] 5088#9876: signal process started
2017/01/16 07:49:58 [notice] 9028#8132: signal process started
2017/01/16 08:26:22 [notice] 1256#3772: signal process started
2017/01/17 13:27:35 [notice] 7104#204: signal process started
2017/01/17 13:38:00 [notice] 1592#8484: signal process started