Merge branch 'dev' of ssh://git.verdnatura.es:/var/lib/git/salix into dev

This commit is contained in:
Juan Ferrer Toribio 2017-05-17 12:14:17 +02:00
commit 5db994e263
10 changed files with 184 additions and 96 deletions

View File

@ -22,6 +22,7 @@
<vn-horizontal>
<vn-textfield vn-one label="Email" field="$ctrl.client.email"></vn-textfield>
<vn-autocomplete vn-one
initial-value="$ctrl.client.salesPerson"
field="$ctrl.client.salesPersonFk"
url="/client/api/Employees"
show-field="name"
@ -29,6 +30,7 @@
label="Comercial">
</vn-autocomplete>
<vn-autocomplete vn-one
initial-value="$ctrl.client.contactChannel"
field="$ctrl.client.contactChannelFk"
url="/client/api/ContactChannels"
show-field="name"

View File

@ -7,7 +7,7 @@ export const COMPONENT = {
controllerAs: 'card',
controller: function($http, $stateParams) {
this.client = null;
$http.get(`/client/api/Clients/${$stateParams.id}?filter[include][account]`).then(
$http.get(`/client/api/Clients/${$stateParams.id}/card`).then(
json => this.client = json.data
);

View File

@ -20,6 +20,7 @@
<vn-horizontal>
<vn-textfield vn-one label="Código postal" field="fiscal.client.postcode"></vn-textfield>
<vn-autocomplete vn-one
initial-value="fiscal.client.province"
field="fiscal.client.provinceFk"
url="/client/api/Provinces"
show-field="name"
@ -27,6 +28,7 @@
label="Provincia">
</vn-autocomplete>
<vn-autocomplete vn-one
initial-value="fiscal.client.country"
field="fiscal.client.countryFk"
url="/client/api/Countries"
show-field="name"
@ -42,6 +44,7 @@
<vn-horizontal>
<vn-textfield vn-two label="IBAN" field="fiscal.client.iban"></vn-textfield>
<vn-autocomplete vn-two
initial-value="fiscal.client.payMethod"
field="fiscal.client.payMethodFk"
url="/client/api/PayMethods"
show-field="name"

View File

@ -27,7 +27,6 @@ export default class Autocomplete extends Component {
this.vnPopover = vnPopover;
componentHandler.upgradeElement($element[0].firstChild);
this.requestItem();
}
set field(value) {
this.locked = true;
@ -37,6 +36,14 @@ export default class Autocomplete extends Component {
get field() {
return this.value;
}
set initialValue(value) {
if (value) {
if (!this.data)
this.data = [];
this.data.push(value);
}
}
mdlUpdate() {
let mdlField = this.element.firstChild.MaterialTextfield;
if (mdlField)
@ -191,9 +198,6 @@ export default class Autocomplete extends Component {
this.hasFocus = true;
this.input.select();
if (this.data)
this.showPopover();
else
this.loadData();
}
onBlur() {
@ -340,6 +344,7 @@ export default class Autocomplete extends Component {
this.item = item;
this.mdlUpdate();
}
}
Autocomplete.$inject = ['$element', '$scope', '$http', 'vnPopover'];
@ -349,6 +354,7 @@ module.component('vnAutocomplete', {
url: '@',
showField: '@',
valueField: '@',
initialValue: '<',
field: '=',
label: '@'
},

View File

@ -1,7 +1,10 @@
module.exports = function(Client) {
// Validations
require("../scopes/client/card.js")(Client);
require("../scopes/client/activate.js")(Client);
require("../scopes/client/addresses.js")(Client);
// Validations
Client.validatesUniquenessOf('name', {message: 'El nombre debe ser único'});
Client.validatesUniquenessOf('fi', {message: 'El NIF/CIF debe ser único'});
Client.validatesPresenceOf('socialName', {message: 'Debe especificarse la razón social'});
@ -42,36 +45,6 @@ module.exports = function(Client) {
}
});
// Methods
Client.remoteMethod('activate', {
description: 'Activate or deactive client',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'Model id',
http: {source: 'path'}
},
returns: {
arg: 'active',
type: 'boolean'
},
http: {
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});
cb(null, !client.active);
}
});
};
// Basic filter
@ -93,53 +66,4 @@ module.exports = function(Client) {
};
}
// 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: {
clientFk: id,
},
skip: (p.page - 1) * p.size,
limit: p.size
};
Client.app.models.Address.find(filter, function(err, instances) {
if(!err) {
cb(null, instances);
}
})
};
};

View File

@ -149,12 +149,5 @@
"permission": "ALLOW"
}
],
"methods": {},
"scopes": {
"test": {
"where": {
"name": "Verdnatura"
}
}
}
"methods": {}
}

View File

@ -0,0 +1,29 @@
module.exports = function(Client){
Client.remoteMethod('activate', {
description: 'Activate or deactive client',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'Model id',
http: {source: 'path'}
},
returns: {
arg: 'active',
type: 'boolean'
},
http: {
verb: 'put',
path: '/:id/activate'
}
});
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);
}
});
};
};

View File

@ -0,0 +1,49 @@
module.exports = function(Client){
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: {
clientFk: id,
},
skip: (p.page - 1) * p.size,
limit: p.size
};
Client.app.models.Address.find(filter, function(err, instances) {
if(!err) {
cb(null, instances);
}
})
};
}

View File

@ -0,0 +1,39 @@
module.exports = function(Client) {
// Validations
var card = require('./card.json');
Client.remoteMethod('card', {
description: 'Get client for card call',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'Model id',
http: {source: 'path'}
},
returns: {
arg: 'data',
type: 'Client',
root: true
},
http: {
verb: 'get',
path: '/:id/card'
}
});
Client.card = function(id, cb) {
let filter = {
where: {
id: id
},
include: card
};
Client.find(filter, function(err, instances) {
if(!err) {
cb(null, instances[0]);
}
})
};
};

View File

@ -0,0 +1,43 @@
[
{
"relation": "salesPerson",
"scope":{
"fields": {
"id": true, "name": true
}
}
},
{
"relation": "contactChannel",
"scope":{
"fields": {
"id": true, "name": true
}
}
},
{
"relation": "province",
"scope":{
"fields": {
"id": true, "name": true
}
}
},
{
"relation": "country",
"scope":{
"fields": {
"id": true, "name": true
}
}
},
{
"relation": "payMethod",
"scope":{
"fields": {
"id": true, "name": true
}
}
}
]