mg-crud añadida, filtro phone
This commit is contained in:
parent
f5d9f1d679
commit
51c58d9a9b
|
@ -1,7 +1,7 @@
|
||||||
<a ui-sref="clientCard.basicData({ id: {{itemClient.client.id}} })" pad-medium border-solid-bottom>
|
<a ui-sref="clientCard.basicData({ id: {{itemClient.client.id}} })" pad-medium border-solid-bottom>
|
||||||
<div class="vn-item-client-name">{{itemClient.client.name}}</div>
|
<div class="vn-item-client-name">{{itemClient.client.name}}</div>
|
||||||
<div>Id Cliente: <b>{{itemClient.client.id}}</b></div>
|
<div>Id Cliente: <b>{{itemClient.client.id}}</b></div>
|
||||||
<div>Teléfono: <b>{{itemClient.client.phone}}</b></div>
|
<div>Teléfono: <b>{{itemClient.client.phone | vnPhone}}</b></div>
|
||||||
<div>Población: <b>{{itemClient.client.city}}</b></div>
|
<div>Población: <b>{{itemClient.client.city}}</b></div>
|
||||||
<div>email: <b>{{itemClient.client.email}}</b></div>
|
<div>email: <b>{{itemClient.client.email}}</b></div>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect">
|
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect">
|
||||||
<input type="checkbox" name="*[name]*" class="*[className]*" name="*[name]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]* *[focus]*>
|
<input type="checkbox" name="*[name]*" class="*[className]*" name="*[name]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]*>
|
||||||
<span class="mdl-checkbox__label" translate>*[label]*</span>
|
<span class="mdl-checkbox__label" translate>*[label]*</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
export * from './config';
|
export * from './config';
|
||||||
export * from './module';
|
export * from './module';
|
||||||
export * from './directives/index';
|
export * from './directives/index';
|
||||||
|
export * from './filters/index';
|
||||||
export * from './lib/index';
|
export * from './lib/index';
|
||||||
export * from './components';
|
export * from './components';
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
import './phone';
|
|
@ -0,0 +1,18 @@
|
||||||
|
import {module} from '../module';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Formats a phone number putting a space every three digits.
|
||||||
|
*/
|
||||||
|
function phone() {
|
||||||
|
return function(input) {
|
||||||
|
input = input || '';
|
||||||
|
let out = '';
|
||||||
|
for(let i = 0; i < input.length; i++) {
|
||||||
|
out = out + input.charAt(i);
|
||||||
|
if((i+1) % 3 == 0)
|
||||||
|
out = out +' ';
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
module.filter('vnPhone', phone);
|
|
@ -1,4 +1,4 @@
|
||||||
<div class="mdl-textfield mdl-js-textfield *[className]*">
|
<div class="mdl-textfield mdl-js-textfield *[className]*">
|
||||||
<input class="mdl-textfield__input" type="password" name="*[name]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]* *[focus]*/>
|
<input class="mdl-textfield__input" type="password" name="*[name]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]*/>
|
||||||
<label class="mdl-textfield__label" translate>*[label]*</label>
|
<label class="mdl-textfield__label" translate>*[label]*</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<div class="mdl-textfield mdl-js-textfield">
|
<div class="mdl-textfield mdl-js-textfield">
|
||||||
<textarea class="mdl-textfield__input" type="text" rows= "*[rows]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]* *[focus]*></textarea>
|
<textarea class="mdl-textfield__input" type="text" rows= "*[rows]*" ng-model="*[model]*" rule="*[rule]*" *[enabled]*></textarea>
|
||||||
<label class="mdl-textfield__label" translate>*[label]*</label>
|
<label class="mdl-textfield__label" translate>*[label]*</label>
|
||||||
</div>
|
</div>
|
|
@ -5,7 +5,6 @@
|
||||||
name="*[name]*"
|
name="*[name]*"
|
||||||
ng-model="*[model]*"
|
ng-model="*[model]*"
|
||||||
vn-validation="*[rule]*"
|
vn-validation="*[rule]*"
|
||||||
*[enabled]*
|
*[enabled]*/>
|
||||||
*[focus]*/>
|
|
||||||
<label class="mdl-textfield__label" translate>*[label]*</label>
|
<label class="mdl-textfield__label" translate>*[label]*</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
import 'mg-crud';
|
||||||
|
|
||||||
|
export const mgCrud = {
|
||||||
|
name: 'mgCrud'
|
||||||
|
};
|
|
@ -4,4 +4,5 @@ export * from './ui-router';
|
||||||
export * from './angular-translate';
|
export * from './angular-translate';
|
||||||
export * from './material-design-lite';
|
export * from './material-design-lite';
|
||||||
export * from './angular-paging';
|
export * from './angular-paging';
|
||||||
export * from './validator';
|
export * from './validator';
|
||||||
|
//export * from './mg-crud';
|
10
db.json
10
db.json
|
@ -20,11 +20,11 @@
|
||||||
"NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue": "{\"id\":\"NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue\",\"ttl\":1209600,\"created\":\"2016-11-21T11:06:11.113Z\",\"userId\":1}"
|
"NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue": "{\"id\":\"NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue\",\"ttl\":1209600,\"created\":\"2016-11-21T11:06:11.113Z\",\"userId\":1}"
|
||||||
},
|
},
|
||||||
"Client": {
|
"Client": {
|
||||||
"12": "{\"name\":\"Verdnatura\",\"id\":12,\"fi\":\"B97367486\",\"salesPerson\":3,\"telefono\":\"963242100\",\"socialName\":\"Verdnatura Levante SL\",\"active\":true,\"user\":\"verdnatura\",\"fax\":\"963242100\",\"phone\":\"963242101\",\"email\":\"informatica@verdnatura.es\",\"surcharge\":true,\"cyc\":321,\"credit\":1000,\"iban\":\"456\",\"street\":\"Avenida Espioca, 100\",\"city\":\"Silla\",\"postcode\":\"12345678\",\"mobile\":\"654654654\",\"dueDay\":321,\"gestdoc\":23452343,\"province\":1,\"country\":1,\"modify\":\"BasicData\",\"navigate\":true,\"payMethod\":\"1\",\"coreVnh\":true,\"coreVnl\":true,\"invoiceByEmail\":true}",
|
"12": "{\"name\":\"Verdnatura\",\"id\":12,\"fi\":\"B97367486\",\"salesPerson\":8,\"telefono\":\"963242100\",\"socialName\":\"Verdnatura Levante SL\",\"active\":true,\"user\":\"verdnatura\",\"fax\":\"963242100\",\"phone\":\"963242101\",\"email\":\"informatica@verdnatura.es\",\"surcharge\":true,\"cyc\":321,\"credit\":1000,\"iban\":\"456\",\"street\":\"Avenida Espioca, 100\",\"city\":\"Silla\",\"postcode\":\"12345678\",\"mobile\":\"654654654\",\"dueDay\":321,\"gestdoc\":23452343,\"province\":1,\"country\":1,\"modify\":\"BasicData\",\"navigate\":true,\"payMethod\":\"1\",\"coreVnh\":true,\"coreVnl\":true,\"invoiceByEmail\":true}",
|
||||||
"14": "{\"name\":\"Leopoldo\",\"id\":14,\"street\":\"Casa\",\"fi\":\"1234567890A\",\"socialName\":\"Leopoldo\",\"fax\":\"963242100\",\"dischargeDate\":\"01/01/2017\",\"telefono\":\"963242100\",\"salesPerson\":\"2\",\"email\":\"informatica@verdnatura.es\",\"city\":\"asdf\",\"postcode\":\"123\",\"phone\":\"963215469\",\"mobile\":\"667985632\",\"credit\":2345,\"cyc\":56,\"iban\":\"asdf\",\"dueDay\":345,\"gestdoc\":2435,\"surcharge\":true,\"navigate\":true,\"province\":6,\"country\":2,\"payMethod\":1}",
|
"14": "{\"name\":\"Leopoldo\",\"id\":14,\"street\":\"Casa\",\"fi\":\"1234567890A\",\"socialName\":\"Leopoldo\",\"fax\":\"963242100\",\"dischargeDate\":\"01/01/2017\",\"telefono\":\"963242100\",\"salesPerson\":\"2\",\"email\":\"informatica@verdnatura.es\",\"city\":\"Benicull\",\"postcode\":\"123\",\"phone\":\"963215469\",\"mobile\":\"667985632\",\"credit\":2345,\"cyc\":56,\"iban\":\"asdf\",\"dueDay\":345,\"gestdoc\":2435,\"surcharge\":true,\"navigate\":true,\"province\":6,\"country\":2,\"payMethod\":1}",
|
||||||
"15": "{\"name\":\"Florsiteria Pepa\",\"fi\":\"12341234rasf\",\"socialName\":\"asdfasd\",\"dueDay\":5,\"id\":15,\"payMethod\":\"2\",\"salesPerson\":\"1\",\"modify\":\"BasicData\",\"iban\":\"sdfgsdfgsdfg\",\"email\":\"pepa@flores.es\"}",
|
"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}",
|
"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\"}"
|
"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\"}"
|
||||||
},
|
},
|
||||||
"PaymentMethod": {
|
"PaymentMethod": {
|
||||||
"1": "{\"name\":\"Tarjeta\",\"id\":1}",
|
"1": "{\"name\":\"Tarjeta\",\"id\":1}",
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
"angular-translate-loader-partial": "^2.13.1",
|
"angular-translate-loader-partial": "^2.13.1",
|
||||||
"angular-ui-router": "^1.0.0-beta.3",
|
"angular-ui-router": "^1.0.0-beta.3",
|
||||||
"material-design-lite": "^1.3.0",
|
"material-design-lite": "^1.3.0",
|
||||||
|
"mg-crud": "^1.0.1",
|
||||||
"oclazyload": "^0.6.3",
|
"oclazyload": "^0.6.3",
|
||||||
"validator": "^6.2.1"
|
"validator": "^6.2.1"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
module.exports = function(Client) {
|
module.exports = function(Client) {
|
||||||
//validations
|
// Validations
|
||||||
|
|
||||||
Client.validatesUniquenessOf('name', {message: 'El nombre debe ser unico'});
|
Client.validatesUniquenessOf('name', {message: 'El nombre debe ser unico'});
|
||||||
Client.validatesUniquenessOf('fi', {message: 'El nif/cif debe ser unico'});
|
Client.validatesUniquenessOf('fi', {message: 'El nif/cif debe ser unico'});
|
||||||
Client.validatesPresenceOf('socialName', {message: 'Debe especificarse la razón social'});
|
Client.validatesPresenceOf('socialName', {message: 'Debe especificarse la razón social'});
|
||||||
|
@ -9,7 +10,7 @@ module.exports = function(Client) {
|
||||||
|
|
||||||
Client.validate('payMethod', hasCC, {message: 'Introduzca el iban del cliente'});
|
Client.validate('payMethod', hasCC, {message: 'Introduzca el iban del cliente'});
|
||||||
function hasCC(err) {
|
function hasCC(err) {
|
||||||
if (this.payMethod == 2 && !this.iban) err();
|
if (this.payMethod == 2 && !this.iban) err();
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.validate('payMethod', hasSalesMan, {message: 'No se puede cambiar la forma de pago si no hay comercial asignado'});
|
Client.validate('payMethod', hasSalesMan, {message: 'No se puede cambiar la forma de pago si no hay comercial asignado'});
|
||||||
|
@ -17,35 +18,6 @@ module.exports = function(Client) {
|
||||||
if(this.payMethod && !this.salesPerson) err();
|
if(this.payMethod && !this.salesPerson) err();
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.remoteMethod('activate', {
|
|
||||||
description: 'Activate or deactive client',
|
|
||||||
accepts: {
|
|
||||||
arg: 'id',
|
|
||||||
type: 'number',
|
|
||||||
required: true,
|
|
||||||
http: function(ctx) {
|
|
||||||
var id = ctx && ctx.req && ctx.req.params.id
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
returns: {
|
|
||||||
arg: 'active',
|
|
||||||
type: 'boolean'
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
path: '/:id/activate', verb: 'put'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Client.activate = function(id, cb){
|
|
||||||
Client.findById(id, function(err, client) {
|
|
||||||
if(!err) {
|
|
||||||
Client.update({id: client.id}, {active: !client.active});
|
|
||||||
cb(null, !client.active);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
// Hooks
|
// Hooks
|
||||||
|
|
||||||
Client.observe('before save', function(ctx, next) {
|
Client.observe('before save', function(ctx, next) {
|
||||||
|
@ -68,4 +40,120 @@ module.exports = function(Client) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Methods
|
||||||
|
|
||||||
|
Client.remoteMethod('activate', {
|
||||||
|
description: 'Activate or deactive client',
|
||||||
|
accepts: {
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
required: true,
|
||||||
|
http: function(ctx) {
|
||||||
|
var id = ctx && ctx.req && ctx.req.params.id
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
returns: {
|
||||||
|
arg: 'active',
|
||||||
|
type: 'boolean'
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/:id/activate',
|
||||||
|
verb: 'put'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Client.activate = function(id, cb) {
|
||||||
|
Client.findById(id, function(err, client) {
|
||||||
|
if(!err) {
|
||||||
|
Client.update({id: client.id}, {active: !client.active});
|
||||||
|
cb(null, !client.active);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
// Filters
|
||||||
|
|
||||||
|
let Model = Client;
|
||||||
|
let fields = {
|
||||||
|
id: false,
|
||||||
|
fi: false,
|
||||||
|
name: true,
|
||||||
|
socialName: true,
|
||||||
|
city: true,
|
||||||
|
postcode: false,
|
||||||
|
email: true,
|
||||||
|
phone: false
|
||||||
|
};
|
||||||
|
|
||||||
|
Model.remoteMethod('filter', {
|
||||||
|
description: 'List items using a filter',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: {
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'object',
|
||||||
|
description: 'Filter defining where'
|
||||||
|
},
|
||||||
|
returns: {
|
||||||
|
arg: 'data',
|
||||||
|
type: 'Client',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: '/filter',
|
||||||
|
verb: 'get'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Model.filter = function(filter, cb) {
|
||||||
|
filter = removeEmpty(filter);
|
||||||
|
let where = {};
|
||||||
|
|
||||||
|
if(filter)
|
||||||
|
for (let field in fields)
|
||||||
|
if(filter[field]) {
|
||||||
|
if(fields[field])
|
||||||
|
where[field] = {ilike: filter[field]};
|
||||||
|
else
|
||||||
|
where[field] = filter[field];
|
||||||
|
}
|
||||||
|
|
||||||
|
Model.find({where: where}, function(err, instances) {
|
||||||
|
if(!err) {
|
||||||
|
cb(null, instances);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
function removeEmpty(o) {
|
||||||
|
if(Array.isArray(o)) {
|
||||||
|
let array = [];
|
||||||
|
for(let item of o) {
|
||||||
|
let i = removeEmpty(item);
|
||||||
|
if(!isEmpty(item))
|
||||||
|
array.push(item);
|
||||||
|
};
|
||||||
|
if(array.length > 0)
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
else if (typeof o === 'object') {
|
||||||
|
let object = {};
|
||||||
|
for(let key in o) {
|
||||||
|
let i = removeEmpty(o[key]);
|
||||||
|
if(!isEmpty(i))
|
||||||
|
object[key] = i;
|
||||||
|
}
|
||||||
|
if(Object.keys(object).length > 0)
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
else if (!isEmpty(o))
|
||||||
|
return o;
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEmpty(value) {
|
||||||
|
return value === undefined || value === "";
|
||||||
|
}
|
||||||
};
|
};
|
|
@ -93,9 +93,6 @@
|
||||||
"where": {"name": "Verdnatura"}
|
"where": {"name": "Verdnatura"}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"_scope": {
|
|
||||||
"where": {"name": "Verdnatura"}
|
|
||||||
},
|
|
||||||
"acls": [],
|
"acls": [],
|
||||||
"methods": {}
|
"methods": {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue