From 0f360db06e5e7b89c3571d4e870b329162ac80d1 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Tue, 21 Feb 2017 16:21:55 +0100 Subject: [PATCH] mgCrud v2 --- client/client/src/address-create/index.html | 14 ++--- client/client/src/address-edit/index.html | 16 ++--- client/client/src/addresses/index.html | 2 +- client/client/src/basic-data/index.html | 7 ++- client/client/src/create/index.html | 49 ++++++++------- client/client/src/fiscal-data/index.html | 15 +++-- client/client/src/new-note/index.html | 16 ++--- client/client/src/web-access/index.html | 16 ++--- client/core/src/lib/crud.js | 1 + .../src/components/main-menu/main-menu.html | 25 ++++---- db.json | 10 ++-- services/client/common/models/Client.js | 60 +++++++++++++++---- services/client/common/util.js | 14 ++--- webpack.config.js | 12 ++-- 14 files changed, 148 insertions(+), 109 deletions(-) diff --git a/client/client/src/address-create/index.html b/client/client/src/address-create/index.html index 7acb4bcb1..215e407f4 100644 --- a/client/client/src/address-create/index.html +++ b/client/client/src/address-create/index.html @@ -1,3 +1,10 @@ + +
@@ -37,10 +44,3 @@ - - diff --git a/client/client/src/address-edit/index.html b/client/client/src/address-edit/index.html index a258bc547..ee0ae491a 100644 --- a/client/client/src/address-edit/index.html +++ b/client/client/src/address-edit/index.html @@ -1,3 +1,11 @@ + +
@@ -38,11 +46,3 @@ - - diff --git a/client/client/src/addresses/index.html b/client/client/src/addresses/index.html index 1b083788a..58266db6f 100644 --- a/client/client/src/addresses/index.html +++ b/client/client/src/addresses/index.html @@ -1,4 +1,4 @@ - + diff --git a/client/client/src/basic-data/index.html b/client/client/src/basic-data/index.html index a94f5c245..c5c35c8fb 100644 --- a/client/client/src/basic-data/index.html +++ b/client/client/src/basic-data/index.html @@ -1,5 +1,10 @@ - + +
diff --git a/client/client/src/create/index.html b/client/client/src/create/index.html index c8b5d3d10..c0779fb9b 100644 --- a/client/client/src/create/index.html +++ b/client/client/src/create/index.html @@ -1,29 +1,28 @@ -
- - - - - Crear Cliente - - - - - - - - - - - - - - - -
+ + form="form" + save="post"> +
+
+ + + Crear Cliente + + + + + + + + + + + + + + +
+
diff --git a/client/client/src/fiscal-data/index.html b/client/client/src/fiscal-data/index.html index acc895fd2..867ac8f54 100644 --- a/client/client/src/fiscal-data/index.html +++ b/client/client/src/fiscal-data/index.html @@ -1,3 +1,10 @@ + + +
@@ -65,11 +72,3 @@ - - diff --git a/client/client/src/new-note/index.html b/client/client/src/new-note/index.html index 8441f9e44..2e05ec244 100644 --- a/client/client/src/new-note/index.html +++ b/client/client/src/new-note/index.html @@ -1,3 +1,10 @@ + +
@@ -8,11 +15,4 @@ - - - \ No newline at end of file + \ No newline at end of file diff --git a/client/client/src/web-access/index.html b/client/client/src/web-access/index.html index dacf64c5b..50cf431cd 100644 --- a/client/client/src/web-access/index.html +++ b/client/client/src/web-access/index.html @@ -1,3 +1,11 @@ + +
@@ -11,14 +19,6 @@ - - - diff --git a/db.json b/db.json index 8a7e0a5c6..c15712c4f 100644 --- a/db.json +++ b/db.json @@ -2,10 +2,10 @@ "ids": { "User": 2, "AccessToken": 2, - "Client": 22, + "Client": 23, "PaymentMethod": 4, "SalesPerson": 11, - "Address": 86, + "Address": 87, "Country": 10, "Province": 44, "Agency": 4, @@ -25,7 +25,8 @@ "15": "{\"name\":\"Florsiteria Pepa\",\"fi\":\"12341234rasf\",\"socialName\":\"asdfasd\",\"dueDay\":5,\"id\":15,\"payMethod\":\"2\",\"salesPerson\":\"1\",\"modify\":\"BasicData\",\"iban\":\"sdfgsdfgsdfg\",\"email\":\"pepa@flores.es\",\"phone\":\"963242101\",\"city\":\"Alfarp\",\"postcode\":\"46985\"}", "16": "{\"name\":\"Floristeria Antonieta\",\"fi\":\"2345234523d\",\"socialName\":\"23452345assdfgsdfgt\",\"active\":true,\"dueDay\":5,\"id\":16,\"modify\":\"FiscalData\",\"email\":\"antonieta@gmail.com\",\"phone\":\"654654654\",\"mobile\":\"654456456\",\"fax\":\"456456456\",\"street\":\"asdfasdf\",\"salesPerson\":8,\"city\":\"Albalat de la Ribera\",\"postcode\":\"46532\"}", "19": "{\"name\":\"Planticas Eustaquio\",\"fi\":\"789456123B\",\"socialName\":\"Eustaquio Martinez\",\"active\":true,\"dueDay\":5,\"id\":19,\"email\":\"peustaquio@hotmail.es\",\"city\":\"Polinya\",\"postcode\":\"46231\",\"phone\":\"963215486\"}", - "21": "{\"name\":\"Ramos Antonieta\",\"fi\":\"B89564289\",\"socialName\":\"Antonia SL\",\"active\":true,\"dueDay\":5,\"id\":21,\"email\":\"ramos@rantonieta.es\",\"salesPerson\":8,\"phone\":\"986574232\"}" + "21": "{\"name\":\"Ramos Antonieta\",\"fi\":\"B89564289\",\"socialName\":\"Antonia SL\",\"active\":true,\"dueDay\":5,\"id\":21,\"email\":\"ramos@rantonieta.es\",\"salesPerson\":8,\"phone\":\"986574232\"}", + "22": "{\"name\":\"Plantas Raimundo\",\"fi\":\"2536418B\",\"socialName\":\"Plantas Raimundo SL\",\"dueDay\":5,\"id\":22,\"email\":\"jose@plantasraimundo.com\",\"phone\":\"963254289\",\"mobile\":\"641967586\",\"salesPerson\":3,\"city\":\"Sueca\",\"postcode\":\"46985\"}" }, "PaymentMethod": { "1": "{\"name\":\"Tarjeta\",\"id\":1}", @@ -58,7 +59,8 @@ "82": "{\"street\":\"Polígono\",\"consignee\":\"Verdnatura Levante SL\",\"city\":\"Picasent\",\"enabled\":true,\"client\":12,\"id\":82,\"province\":1,\"agency\":2,\"phone\":\"963242100\",\"mobile\":\"698357618\"}", "83": "{\"street\":\"San Nicolau de Bari, 6\",\"consignee\":\"Casa\",\"city\":\"Algemesi\",\"postcode\":\"46680\",\"enabled\":true,\"phone\":\"962480949\",\"client\":12,\"province\":1,\"agency\":1,\"id\":83,\"mobile\":\"658965745\"}", "84": "{\"street\":\"Poligono\",\"consignee\":\"Madrid\",\"city\":\"Madrid\",\"enabled\":true,\"client\":12,\"id\":84,\"postcode\":\"46001\",\"province\":2,\"agency\":2,\"phone\":\"912356489\",\"mobile\":\"654236589\"}", - "85": "{\"street\":\"Avenida la Parra, 43\",\"consignee\":\"Ramos Antonienta\",\"city\":\"Llombai\",\"enabled\":true,\"client\":21,\"province\":1,\"id\":85,\"phone\":\"965874583\",\"mobile\":\"675418958\",\"postcode\":\"46985\",\"agency\":2,\"default\":true}" + "85": "{\"street\":\"Avenida la Parra, 43\",\"consignee\":\"Ramos Antonienta\",\"city\":\"Llombai\",\"enabled\":true,\"client\":21,\"province\":1,\"id\":85,\"phone\":\"965874583\",\"mobile\":\"675418958\",\"postcode\":\"46985\",\"agency\":2,\"default\":true}", + "86": "{\"street\":\"Poligono industrial\",\"consignee\":\"Verdnatura\",\"city\":\"Barcelona\",\"enabled\":true,\"client\":12,\"province\":7,\"agency\":2,\"id\":86}" }, "Country": { "1": "{\"id\":1,\"name\":\"Spain\"}", diff --git a/services/client/common/models/Client.js b/services/client/common/models/Client.js index e445ba3f9..9dd08b422 100644 --- a/services/client/common/models/Client.js +++ b/services/client/common/models/Client.js @@ -51,22 +51,21 @@ module.exports = function(Client) { arg: 'id', type: 'number', required: true, - http: function(ctx) { - var id = ctx && ctx.req && ctx.req.params.id - return id; - } + description: 'Model id', + http: {source: 'path'} }, returns: { arg: 'active', type: 'boolean' }, http: { - path: '/:id/activate', - verb: 'put' + verb: 'put', + path: '/:id/activate' } }); Client.activate = function(id, cb) { + console.log(id); Client.findById(id, function(err, client) { if(!err) { Client.update({id: client.id}, {active: !client.active}); @@ -95,14 +94,53 @@ module.exports = function(Client) { }; } - installMethod(Client, 'filter', filterAddresses); - function filterAddresses(p){ - return { + // Client addresses + + Client.remoteMethod('addressesList', { + description: 'List items using a filter', + accessType: 'READ', + accepts: [ + { + arg: 'id', + type: 'string', + required: true, + description: 'Model id', + http: {source: 'path'} + }, + { + arg: 'filter', + type: 'object', + required: true, + description: 'Filter defining where', + http: function(ctx) { + return ctx.req.query; + } + } + ], + returns: { + arg: 'data', + type: ['Address'], + root: true + }, + http: { + path: `/:id/addressesList`, + verb: 'get' + } + }); + + Client.addressesList = function(id, p, cb) { + let filter = { where: { - client: p.client, + client: id, }, skip: (p.page - 1) * p.size, limit: p.size }; - } + + Client.app.models.Address.find(filter, function(err, instances) { + if(!err) { + cb(null, instances); + } + }) + }; }; \ No newline at end of file diff --git a/services/client/common/util.js b/services/client/common/util.js index d4c55df8f..aab36597c 100644 --- a/services/client/common/util.js +++ b/services/client/common/util.js @@ -1,8 +1,8 @@ module.exports = installMethod; -function installMethod(Model, methodName, filterCb) { - Model.remoteMethod(methodName, { +function installMethod(model, methodName, filterCb) { + model.remoteMethod(methodName, { description: 'List items using a filter', accessType: 'READ', accepts: [ @@ -18,18 +18,18 @@ function installMethod(Model, methodName, filterCb) { ], returns: { arg: 'data', - type: [Model.modelName], + type: [model.modelName], root: true }, http: { - path: `/${methodName}`, - verb: 'get' + verb: 'get', + path: `/${methodName}` } }); - Model.filter = function(params, cb) { + model.filter = function(params, cb) { let filter = removeEmpty(filterCb(params)); - Model.find(filter, function(err, instances) { + model.find(filter, function(err, instances) { if(!err) { cb(null, instances); } diff --git a/webpack.config.js b/webpack.config.js index 7898717ce..ffc971b4f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -61,12 +61,12 @@ var config = { }; if (!devMode) { - config.plugins.push ( - new webpack.optimize.UglifyJsPlugin({ - minimize: true, - compress: { warnings: false } - }) - ); + config.plugins.push ( + new webpack.optimize.UglifyJsPlugin({ + minimize: true, + compress: { warnings: false } + }) + ); } module.exports = config;