From c8424f98f4a38a0379a37430db4dd6c1e8556bd3 Mon Sep 17 00:00:00 2001 From: nelo Date: Wed, 31 May 2017 10:58:48 +0200 Subject: [PATCH] =?UTF-8?q?paginaci=C3=B3n=20en=20clientes=20arreglado=20p?= =?UTF-8?q?roblema=20de=20b=C3=BAsqueda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/client/src/index/index.html | 10 ++--- client/client/src/index/index.js | 16 +++++-- .../src/components/searchbar/searchbar.html | 2 +- .../src/components/searchbar/searchbar.js | 4 +- services/client/common/models/Client.js | 39 +---------------- services/client/common/models/MyModel.js | 42 +++++++++++++++---- .../common/scopes/client/before-save.js | 18 ++++++++ .../client/common/scopes/client/filter.js | 39 +++++++++++++++++ 8 files changed, 116 insertions(+), 54 deletions(-) create mode 100644 services/client/common/scopes/client/before-save.js create mode 100644 services/client/common/scopes/client/filter.js diff --git a/client/client/src/index/index.html b/client/client/src/index/index.html index 2ead0c2b4..96338af36 100644 --- a/client/client/src/index/index.html +++ b/client/client/src/index/index.html @@ -3,19 +3,19 @@
- - + - +
diff --git a/client/client/src/index/index.js b/client/client/src/index/index.js index e69d35481..1f7060077 100644 --- a/client/client/src/index/index.js +++ b/client/client/src/index/index.js @@ -2,6 +2,16 @@ import {module} from '../module'; import './style.css'; import './item-client'; -module.component('vnClientIndex', { - template: require('./index.html') -}); +class Controller { + search(index) { + index.filter.search = this.model.search; + index.accept(); + } +} + +export const NAME = 'vnClientIndex'; +export const COMPONENT = { + template: require('./index.html'), + controller: Controller +}; +module.component(NAME, COMPONENT); diff --git a/client/salix/src/components/searchbar/searchbar.html b/client/salix/src/components/searchbar/searchbar.html index 50ccac05d..0ca47a768 100644 --- a/client/salix/src/components/searchbar/searchbar.html +++ b/client/salix/src/components/searchbar/searchbar.html @@ -1,6 +1,6 @@
- + { - let filter = removeEmpty(filterCb(params)); - this.find(filter, function(err, instances) { - if(!err) - cb(null, instances); - }) - }; + this[methodName] = (params, cb) => { + let filter = removeEmpty(filterCb(params)); + var response = {} + + function returnValues(){ + if(response.instances !== undefined && response.count !== undefined) + cb(null, response); + } + + function error(){ + cb(null, response); + } + + this.find(filter, function(err, instances) { + if(!err){ + response.instances = instances; + returnValues(); + } + else{ + error(); + } + + }) + + this.count(filter.where, function(err, totalCount){ + if(!err){ + response.count = totalCount; + returnValues(); + } + else{ + error(); + } + + }) + }; }; diff --git a/services/client/common/scopes/client/before-save.js b/services/client/common/scopes/client/before-save.js new file mode 100644 index 000000000..9a0c82cdd --- /dev/null +++ b/services/client/common/scopes/client/before-save.js @@ -0,0 +1,18 @@ +module.exports = function(Client){ + Client.observe('before save', function(ctx, next) { + if (ctx.instance) { + if (!ctx.instance.dueDay) + ctx.instance.dueDay = 5; + next(); + } else { + Client.findById(ctx.where.id, function(err, instance) { + if (instance + && instance.payMethodFk != ctx.data.payMethodFk + && instance.dueDay == ctx.data.dueDay) + ctx.data.dueDay = 5; + next(); + }); + } + }); + +} \ No newline at end of file diff --git a/services/client/common/scopes/client/filter.js b/services/client/common/scopes/client/filter.js new file mode 100644 index 000000000..d60f4c21c --- /dev/null +++ b/services/client/common/scopes/client/filter.js @@ -0,0 +1,39 @@ +module.exports = function(Client){ + Client.installMethod('filter', filterClients); + function filterClients(p) { + if(p.search && p.search !== "") + return searchWhere(p); + return andWhere(p); + } + + function searchWhere(p){ + return { + where: { + or:[ + {id: p.search,}, + {name: {regexp: p.search}} + ] + + }, + skip: (p.page - 1) * p.size, + limit: p.size + } + } + + function andWhere(p){ + return { + where: { + id: p.id, + name: {regexp: p.name}, + cif: p.cif, + socialName: {regexp: p.socialName}, + city: {regexp: p.city}, + postcode: p.postcode, + email: {regexp: p.email}, + phone: p.phone + }, + skip: (p.page - 1) * p.size, + limit: p.size + } + } +} \ No newline at end of file