mgCrud v2

This commit is contained in:
Juan Ferrer Toribio 2017-02-21 16:21:55 +01:00
parent 034c3214fc
commit 0f360db06e
14 changed files with 148 additions and 109 deletions

View File

@ -1,3 +1,10 @@
<vn-watcher
vn-id="watcher"
url="/client/api/Addresses"
id-field="id"
data="addressData.address"
form="form">
</vn-watcher>
<form name="form" ng-submit="addressData.onSubmit()" pad-medium> <form name="form" ng-submit="addressData.onSubmit()" pad-medium>
<vn-card > <vn-card >
<vn-vertical pad-large> <vn-vertical pad-large>
@ -37,10 +44,3 @@
<vn-submit label="Guardar"></vn-submit> <vn-submit label="Guardar"></vn-submit>
</vn-button-bar> </vn-button-bar>
</form> </form>
<vn-watcher
vn-id="watcher"
url="/client/api/Addresses"
id-field="id"
data="addressData.address"
form="form">
</vn-watcher>

View File

@ -1,3 +1,11 @@
<vn-watcher
vn-id="watcher"
get="true"
url="/client/api/Addresses"
id-field="id"
data="addressData.address"
form="form">
</vn-watcher>
<form name="form" ng-submit="addressData.onSubmit()" pad-medium> <form name="form" ng-submit="addressData.onSubmit()" pad-medium>
<vn-card> <vn-card>
<vn-vertical pad-large> <vn-vertical pad-large>
@ -38,11 +46,3 @@
<vn-submit label="Guardar"></vn-submit> <vn-submit label="Guardar"></vn-submit>
</vn-button-bar> </vn-button-bar>
</form> </form>
<vn-watcher
vn-id="watcher"
get="true"
url="/client/api/Addresses"
id-field="id"
data="addressData.address"
form="form">
</vn-watcher>

View File

@ -1,4 +1,4 @@
<mg-ajax path="/client/api/Clients/{{index.params.id}}/Addresses" options="vnIndex"></mg-ajax> <mg-ajax path="/client/api/Clients/{{index.params.id}}/addressesList" options="vnIndex"></mg-ajax>
<vn-vertical pad-medium> <vn-vertical pad-medium>
<vn-card> <vn-card>
<vn-vertical pad-large> <vn-vertical pad-large>

View File

@ -1,5 +1,10 @@
<mg-ajax path="/client/api/Clients/{{put.params.id}}" options="vnPut"></mg-ajax> <mg-ajax path="/client/api/Clients/{{put.params.id}}" options="vnPut"></mg-ajax>
<vn-watcher vn-id="watcher" data="$ctrl.client" form="form" save="put"></vn-watcher> <vn-watcher
vn-id="watcher"
data="$ctrl.client"
form="form"
save="put">
</vn-watcher>
<form name="form" ng-submit="watcher.submit()" pad-medium> <form name="form" ng-submit="watcher.submit()" pad-medium>
<vn-card > <vn-card >
<vn-vertical pad-large> <vn-vertical pad-large>

View File

@ -1,6 +1,12 @@
<div margin-medium> <mg-ajax path="/client/api/Clients" options="vnPost"></mg-ajax>
<mg-ajax path="/client/api/Clients/{{put.params.id}}" options="vnPost"></mg-ajax> <vn-watcher
<form name="form" ng-submit="$ctrl.onSubmit()" style="max-width: 70em; margin: 0 auto;"> vn-id="watcher"
data="$ctrl.client"
form="form"
save="post">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" margin-medium>
<div style="max-width: 70em; margin: 0 auto;">
<vn-card> <vn-card>
<vn-vertical pad-large> <vn-vertical pad-large>
<vn-title>Crear Cliente</vn-title> <vn-title>Crear Cliente</vn-title>
@ -18,12 +24,5 @@
<vn-submit label="Crear y continuar"></vn-submit> <vn-submit label="Crear y continuar"></vn-submit>
<vn-button label="Crear" ng-click="$ctrl.onCreate()"></vn-button> <vn-button label="Crear" ng-click="$ctrl.onCreate()"></vn-button>
</vn-button-bar> </vn-button-bar>
</form>
</div> </div>
<vn-watcher </form>
vn-id="watcher"
url="/client/api/Clients"
id-field="id"
data="$ctrl.client"
form="form">
</vn-watcher>

View File

@ -1,3 +1,10 @@
<mg-ajax path="/client/api/Clients/{{put.params.id}}" options="vnPut"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="fiscal.client"
form="form"
save="put">
</vn-watcher>
<form name="form" ng-submit="watcher.submit()" pad-medium> <form name="form" ng-submit="watcher.submit()" pad-medium>
<vn-card margin-small-bottom> <vn-card margin-small-bottom>
<vn-vertical pad-large> <vn-vertical pad-large>
@ -65,11 +72,3 @@
<vn-submit label="Guardar"></vn-submit> <vn-submit label="Guardar"></vn-submit>
</vn-button-bar> </vn-button-bar>
</form> </form>
<vn-watcher
vn-id="watcher"
url="/client/api/Clients"
id-field="id"
form="form"
data="fiscal.client"
form="form">
</vn-watcher>

View File

@ -1,3 +1,10 @@
<vn-watcher
vn-id="watcher"
url="/client/api/ClientObservations"
id-field="id"
data="newNote.note"
form="form">
</vn-watcher>
<form name="form" ng-submit="newNote.onSubmit()" pad-medium> <form name="form" ng-submit="newNote.onSubmit()" pad-medium>
<vn-card> <vn-card>
<vn-vertical pad-large> <vn-vertical pad-large>
@ -9,10 +16,3 @@
<vn-submit label="Guardar"></vn-submit> <vn-submit label="Guardar"></vn-submit>
</vn-button-bar> </vn-button-bar>
</form> </form>
<vn-watcher
vn-id="watcher"
url="/client/api/ClientObservations"
id-field="id"
data="newNote.note"
form="form">
</vn-watcher>

View File

@ -1,3 +1,11 @@
<vn-watcher
vn-id="watcher"
url="/client/api/Accounts"
id-field="id"
data="$ctrl.client.account"
to="$ctrl.account"
form="form">
</vn-watcher>
<form name="form" ng-submit="watcher.submit()" pad-medium> <form name="form" ng-submit="watcher.submit()" pad-medium>
<vn-card> <vn-card>
<vn-vertical pad-large> <vn-vertical pad-large>
@ -11,14 +19,6 @@
<vn-button label="Cambiar contraseña" vn-dialog="change-pass"></vn-button> <vn-button label="Cambiar contraseña" vn-dialog="change-pass"></vn-button>
</vn-button-bar> </vn-button-bar>
</form> </form>
<vn-watcher
vn-id="watcher"
id-field="id"
url="/client/api/Accounts"
watch="$ctrl.client.account"
to="$ctrl.account"
form="form">
</vn-watcher>
<vn-dialog <vn-dialog
vn-id="change-pass" vn-id="change-pass"
on-open="$ctrl.onPassOpen()" on-open="$ctrl.onPassOpen()"

View File

@ -27,6 +27,7 @@ module.factory('vnPut', put);
post.$inject = ['mgCreate']; post.$inject = ['mgCreate'];
function post(mgCreate) { function post(mgCreate) {
return angular.extend(mgCreate, { return angular.extend(mgCreate, {
as: 'post',
success: 'vnSuccessFactoryCreate' success: 'vnSuccessFactoryCreate'
}); });
} }

View File

@ -4,11 +4,6 @@
<vn-icon icon="language" translate-attr="{title: 'Change language'}" ng-click="mainMenu.onChangeLanguage()"></vn-icon> <vn-icon icon="language" translate-attr="{title: 'Change language'}" ng-click="mainMenu.onChangeLanguage()"></vn-icon>
<vn-icon icon="exit_to_app" translate-attr="{title: 'Logout'}" ng-click="mainMenu.onLogoutClick()"></vn-icon> <vn-icon icon="exit_to_app" translate-attr="{title: 'Logout'}" ng-click="mainMenu.onLogoutClick()"></vn-icon>
<vn-icon icon="account_circle" translate-attr="{title: 'Profile'}" style="font-size: 35px;"></vn-icon> <vn-icon icon="account_circle" translate-attr="{title: 'Profile'}" style="font-size: 35px;"></vn-icon>
<!--
<vn-popover pad-medium for="apps">
<a ui-sref="clients"><vn-icon icon=""></vn-icon></a>
</vn-popover>
-->
<ul class="mdl-menu mdl-js-menu mdl-menu--bottom-right" pad-medium for="apps"> <ul class="mdl-menu mdl-js-menu mdl-menu--bottom-right" pad-medium for="apps">
<vn-horizontal> <vn-horizontal>
<vn-vertical> <vn-vertical>

10
db.json
View File

@ -2,10 +2,10 @@
"ids": { "ids": {
"User": 2, "User": 2,
"AccessToken": 2, "AccessToken": 2,
"Client": 22, "Client": 23,
"PaymentMethod": 4, "PaymentMethod": 4,
"SalesPerson": 11, "SalesPerson": 11,
"Address": 86, "Address": 87,
"Country": 10, "Country": 10,
"Province": 44, "Province": 44,
"Agency": 4, "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\"}", "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\"}", "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\"}", "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": { "PaymentMethod": {
"1": "{\"name\":\"Tarjeta\",\"id\":1}", "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\"}", "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\"}", "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\"}", "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": { "Country": {
"1": "{\"id\":1,\"name\":\"Spain\"}", "1": "{\"id\":1,\"name\":\"Spain\"}",

View File

@ -51,22 +51,21 @@ module.exports = function(Client) {
arg: 'id', arg: 'id',
type: 'number', type: 'number',
required: true, required: true,
http: function(ctx) { description: 'Model id',
var id = ctx && ctx.req && ctx.req.params.id http: {source: 'path'}
return id;
}
}, },
returns: { returns: {
arg: 'active', arg: 'active',
type: 'boolean' type: 'boolean'
}, },
http: { http: {
path: '/:id/activate', verb: 'put',
verb: 'put' path: '/:id/activate'
} }
}); });
Client.activate = function(id, cb) { Client.activate = function(id, cb) {
console.log(id);
Client.findById(id, function(err, client) { Client.findById(id, function(err, client) {
if(!err) { if(!err) {
Client.update({id: client.id}, {active: !client.active}); Client.update({id: client.id}, {active: !client.active});
@ -95,14 +94,53 @@ module.exports = function(Client) {
}; };
} }
installMethod(Client, 'filter', filterAddresses); // Client addresses
function filterAddresses(p){
return { 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: { where: {
client: p.client, client: id,
}, },
skip: (p.page - 1) * p.size, skip: (p.page - 1) * p.size,
limit: p.size limit: p.size
}; };
Client.app.models.Address.find(filter, function(err, instances) {
if(!err) {
cb(null, instances);
} }
})
};
}; };

View File

@ -1,8 +1,8 @@
module.exports = installMethod; module.exports = installMethod;
function installMethod(Model, methodName, filterCb) { function installMethod(model, methodName, filterCb) {
Model.remoteMethod(methodName, { model.remoteMethod(methodName, {
description: 'List items using a filter', description: 'List items using a filter',
accessType: 'READ', accessType: 'READ',
accepts: [ accepts: [
@ -18,18 +18,18 @@ function installMethod(Model, methodName, filterCb) {
], ],
returns: { returns: {
arg: 'data', arg: 'data',
type: [Model.modelName], type: [model.modelName],
root: true root: true
}, },
http: { http: {
path: `/${methodName}`, verb: 'get',
verb: 'get' path: `/${methodName}`
} }
}); });
Model.filter = function(params, cb) { model.filter = function(params, cb) {
let filter = removeEmpty(filterCb(params)); let filter = removeEmpty(filterCb(params));
Model.find(filter, function(err, instances) { model.find(filter, function(err, instances) {
if(!err) { if(!err) {
cb(null, instances); cb(null, instances);
} }