From 726bb73ca025d9783c44e0c51846ff8d5b4bde12 Mon Sep 17 00:00:00 2001 From: nelo Date: Wed, 17 May 2017 14:58:23 +0200 Subject: [PATCH 1/6] Todos heredan de MyModel --- client/client/src/index/index.html | 4 +-- client/core/src/paging/index.js | 7 +++-- services/client/common/models/Address.json | 2 +- .../client/common/models/AgencyService.json | 2 +- .../common/models/ClientObservation.json | 2 +- .../client/common/models/ContactChannel.json | 2 +- services/client/common/models/Country.json | 2 +- services/client/common/models/Employee.json | 2 +- services/client/common/models/MyModel.js | 30 ++++++++++++++++++- services/client/common/models/PayMethod.json | 2 +- services/client/common/models/Province.json | 2 +- 11 files changed, 44 insertions(+), 13 deletions(-) diff --git a/client/client/src/index/index.html b/client/client/src/index/index.html index 2ead0c2b4..ce695e038 100644 --- a/client/client/src/index/index.html +++ b/client/client/src/index/index.html @@ -13,9 +13,9 @@ - + - + diff --git a/client/core/src/paging/index.js b/client/core/src/paging/index.js index 3df147c2c..fd17b994e 100644 --- a/client/core/src/paging/index.js +++ b/client/core/src/paging/index.js @@ -13,9 +13,11 @@ export default class Paging { this.numItems = 0; $scope.$watch('$ctrl.index.model.length', () => this.onModelUpdated()); } - $onChanges() { + $onChanges(changes) { if (!this.index) return; this.numPerPage = this.index.filter.size; + if(changes.total) + this.numItems = changes.total.currentValue; } onModelUpdated() { let index = this.index; @@ -36,7 +38,8 @@ export const NAME = 'vnPaging'; export const COMPONENT = { template: require('./index.html'), bindings: { - index: '<' + index: '<', + total: '<' }, controller: Paging }; diff --git a/services/client/common/models/Address.json b/services/client/common/models/Address.json index f779be6d8..73bf81c7a 100644 --- a/services/client/common/models/Address.json +++ b/services/client/common/models/Address.json @@ -1,6 +1,6 @@ { "name": "Address", - "base": "PersistedModel", + "base": "MyModel", "validateUpsert": true, "properties": { "id": { diff --git a/services/client/common/models/AgencyService.json b/services/client/common/models/AgencyService.json index 57c2b51ac..98f742f64 100644 --- a/services/client/common/models/AgencyService.json +++ b/services/client/common/models/AgencyService.json @@ -1,6 +1,6 @@ { "name": "AgencyService", - "base": "PersistedModel", + "base": "MyModel", "validateUpsert": true, "properties": { "id": { diff --git a/services/client/common/models/ClientObservation.json b/services/client/common/models/ClientObservation.json index 59f86dcc9..ed4a46d8d 100644 --- a/services/client/common/models/ClientObservation.json +++ b/services/client/common/models/ClientObservation.json @@ -1,7 +1,7 @@ { "name": "ClientObservation", "description": "Notas de los clientes.", - "base": "PersistedModel", + "base": "MyModel", "validateUpsert": true, "properties": { "id": { diff --git a/services/client/common/models/ContactChannel.json b/services/client/common/models/ContactChannel.json index bfacd0926..980de5ccc 100644 --- a/services/client/common/models/ContactChannel.json +++ b/services/client/common/models/ContactChannel.json @@ -1,6 +1,6 @@ { "name": "ContactChannel", - "base": "PersistedModel", + "base": "MyModel", "validateUpsert": true, "properties": { "id": { diff --git a/services/client/common/models/Country.json b/services/client/common/models/Country.json index d695b24bd..09b96d858 100644 --- a/services/client/common/models/Country.json +++ b/services/client/common/models/Country.json @@ -1,6 +1,6 @@ { "name": "Country", - "base": "PersistedModel", + "base": "MyModel", "validateUpsert": true, "properties": { "id": { diff --git a/services/client/common/models/Employee.json b/services/client/common/models/Employee.json index 3218933d8..58ebf605a 100644 --- a/services/client/common/models/Employee.json +++ b/services/client/common/models/Employee.json @@ -1,6 +1,6 @@ { "name": "Employee", - "base": "PersistedModel", + "base": "MyModel", "validateUpsert": true, "properties": { "id": { diff --git a/services/client/common/models/MyModel.js b/services/client/common/models/MyModel.js index 6bf440d1a..d21be2697 100644 --- a/services/client/common/models/MyModel.js +++ b/services/client/common/models/MyModel.js @@ -25,6 +25,12 @@ module.exports = function(self) { for(let method in disableMethods) { //this.disableRemoteMethod(method, disableMethods[method]); } + + var find = self.find; + self.find = function(filter,cb){ + cb(null,'This is a overridden method') + } + console.log(self.find); } self.installMethod = function(methodName, filterCb) { @@ -55,9 +61,30 @@ module.exports = function(self) { this.filter = (params, cb) => { let filter = removeEmpty(filterCb(params)); + data = {}; + function check () { + if (data.count && data.instances) + cb(null, data); + } + function error(){ + cb(null, data); + } + this.count(filter, function (err, count) { + if(!err) { + data.count = count; + check(); + } + else{ + error(); + } + }) this.find(filter, function(err, instances) { if(!err) { - cb(null, instances); + data.instances = instances; + check(); + } + else{ + error(); } }) }; @@ -94,3 +121,4 @@ function removeEmpty(o) { function isEmpty(value) { return value === undefined || value === ""; } + diff --git a/services/client/common/models/PayMethod.json b/services/client/common/models/PayMethod.json index 2ead866a0..c55589137 100644 --- a/services/client/common/models/PayMethod.json +++ b/services/client/common/models/PayMethod.json @@ -1,6 +1,6 @@ { "name": "PayMethod", - "base": "PersistedModel", + "base": "MyModel", "validateUpsert": true, "properties": { "id": { diff --git a/services/client/common/models/Province.json b/services/client/common/models/Province.json index 777f34310..b285bd419 100644 --- a/services/client/common/models/Province.json +++ b/services/client/common/models/Province.json @@ -1,6 +1,6 @@ { "name": "Province", - "base": "PersistedModel", + "base": "MyModel", "validateUpsert": true, "properties": { "id": { From b4d167bbb7ff9f9c476688ea6790e4f15477770b Mon Sep 17 00:00:00 2001 From: nelo Date: Thu, 18 May 2017 11:54:39 +0200 Subject: [PATCH 2/6] header.js --- client/client/src/index/index.html | 4 +-- services/client/common/models/MyModel.js | 38 ++++++------------------ services/client/server/boot/header.js | 19 ++++++++++++ 3 files changed, 30 insertions(+), 31 deletions(-) create mode 100644 services/client/server/boot/header.js diff --git a/client/client/src/index/index.html b/client/client/src/index/index.html index ce695e038..2ead0c2b4 100644 --- a/client/client/src/index/index.html +++ b/client/client/src/index/index.html @@ -13,9 +13,9 @@ - + - + diff --git a/services/client/common/models/MyModel.js b/services/client/common/models/MyModel.js index d21be2697..15757314d 100644 --- a/services/client/common/models/MyModel.js +++ b/services/client/common/models/MyModel.js @@ -26,11 +26,13 @@ module.exports = function(self) { //this.disableRemoteMethod(method, disableMethods[method]); } - var find = self.find; - self.find = function(filter,cb){ - cb(null,'This is a overridden method') - } - console.log(self.find); + self.on('find', function() { + self.printModelName(); + }); + + self.list = function(filter, cb){ + self.find(filter, cb); + } } self.installMethod = function(methodName, filterCb) { @@ -61,31 +63,9 @@ module.exports = function(self) { this.filter = (params, cb) => { let filter = removeEmpty(filterCb(params)); - data = {}; - function check () { - if (data.count && data.instances) - cb(null, data); - } - function error(){ - cb(null, data); - } - this.count(filter, function (err, count) { - if(!err) { - data.count = count; - check(); - } - else{ - error(); - } - }) this.find(filter, function(err, instances) { - if(!err) { - data.instances = instances; - check(); - } - else{ - error(); - } + if(!err) + cb(null, instances); }) }; }; diff --git a/services/client/server/boot/header.js b/services/client/server/boot/header.js new file mode 100644 index 000000000..91b465219 --- /dev/null +++ b/services/client/server/boot/header.js @@ -0,0 +1,19 @@ +module.exports = function(app) { + + /*function modifyResponse(ctx, model, next) { + var result = ctx.result; + var status = ctx.res.statusCode; + if(Array.isArray(result)){ + /*app.models.Client.count(null, function (err, count) { + if(!err) { + ctx.res.set('Count-elements', count); + } + }) + ctx.res.set('Count-elements', 3); + ctx.res.status(status).next(); + } + } + + app.models.Client.afterRemote('**', modifyResponse);*/ + +}; \ No newline at end of file From 5e965f485fc3152a798ea573698395ee67e3dbe7 Mon Sep 17 00:00:00 2001 From: nelo Date: Thu, 18 May 2017 11:55:46 +0200 Subject: [PATCH 3/6] eliminado el filter de MyModel --- services/client/common/models/MyModel.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/services/client/common/models/MyModel.js b/services/client/common/models/MyModel.js index 15757314d..f4178f47c 100644 --- a/services/client/common/models/MyModel.js +++ b/services/client/common/models/MyModel.js @@ -60,14 +60,6 @@ module.exports = function(self) { path: `/${methodName}` } }); - - this.filter = (params, cb) => { - let filter = removeEmpty(filterCb(params)); - this.find(filter, function(err, instances) { - if(!err) - cb(null, instances); - }) - }; }; } From 51c145158b58e32da37fb7a5392e5b5e147c9fbe Mon Sep 17 00:00:00 2001 From: Vicente Falco Date: Thu, 18 May 2017 13:27:45 +0200 Subject: [PATCH 4/6] Error Guardar consignatario --- client/client/src/address-create/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/client/src/address-create/index.js b/client/client/src/address-create/index.js index 25c8e9e95..be2b337dd 100644 --- a/client/client/src/address-create/index.js +++ b/client/client/src/address-create/index.js @@ -5,7 +5,7 @@ class Controller { this.$scope = $scope; this.$state = $state; this.address = { - client: parseInt($state.params.id), + clientFk: parseInt($state.params.id), enabled: true }; } From 7691449e52285cd00e4b5a9e5e21e5ffdc9947e2 Mon Sep 17 00:00:00 2001 From: nelo Date: Thu, 18 May 2017 13:40:42 +0200 Subject: [PATCH 5/6] restablecido filtre --- services/client/common/models/MyModel.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/services/client/common/models/MyModel.js b/services/client/common/models/MyModel.js index f4178f47c..50a4d2587 100644 --- a/services/client/common/models/MyModel.js +++ b/services/client/common/models/MyModel.js @@ -26,13 +26,6 @@ module.exports = function(self) { //this.disableRemoteMethod(method, disableMethods[method]); } - self.on('find', function() { - self.printModelName(); - }); - - self.list = function(filter, cb){ - self.find(filter, cb); - } } self.installMethod = function(methodName, filterCb) { @@ -61,6 +54,15 @@ module.exports = function(self) { } }); }; + + this.filter = (params, cb) => { + let filter = removeEmpty(filterCb(params)); + this.find(filter, function(err, instances) { + if(!err) + cb(null, instances); + }) + }; + } function removeEmpty(o) { From a031f31a0591577daa4d6be9c904363f7baf35bb Mon Sep 17 00:00:00 2001 From: nelo Date: Thu, 18 May 2017 13:59:02 +0200 Subject: [PATCH 6/6] restablecido filtre --- services/client/common/models/MyModel.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/client/common/models/MyModel.js b/services/client/common/models/MyModel.js index 50a4d2587..533496821 100644 --- a/services/client/common/models/MyModel.js +++ b/services/client/common/models/MyModel.js @@ -53,9 +53,8 @@ module.exports = function(self) { path: `/${methodName}` } }); - }; - this.filter = (params, cb) => { + this.filter = (params, cb) => { let filter = removeEmpty(filterCb(params)); this.find(filter, function(err, instances) { if(!err) @@ -63,6 +62,8 @@ module.exports = function(self) { }) }; + }; + } function removeEmpty(o) {