This commit is contained in:
Vicente Falco 2017-05-17 13:18:20 +02:00
commit 39f5f55714
12 changed files with 199 additions and 111 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"
@ -41,6 +43,7 @@
<vn-title>Información de facturación</vn-title>
<vn-horizontal>
<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,10 +198,7 @@ export default class Autocomplete extends Component {
this.hasFocus = true;
this.input.select();
if (this.data)
this.showPopover();
else
this.loadData();
this.loadData();
}
onBlur() {
this.hasFocus = false;
@ -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

@ -40,7 +40,7 @@ gulp.task('clean', function() {
var splitingFiles = './spliting/*';
gulp.task('spliting', function() {
gulp.task('spliting', function(cb) {
var importTpl = fs.readFileSync('./spliting/import.tpl.js', 'utf8');
var requireTpl = fs.readFileSync('./spliting/require.tpl.js', 'utf8');
@ -55,27 +55,28 @@ gulp.task('spliting', function() {
fs.appendFileSync(splitFile, importTpl);
var i = deps.length;
while (i--) {
while (i--)
fs.appendFileSync(splitFile,
requireTpl.replace(/\$module/g, deps[i]));
}
}
cb();
});
// Webpack
gulp.task('webpack', ['spliting'], function(callback) {
gulp.task('webpack', ['spliting'], function(cb) {
var configCopy = Object.create(webpackConfig);
var compiler = webpack(configCopy);
compiler.run(function(err, stats) {
if (err) throw new gutil.PluginError('webpack', err);
gutil.log('[webpack]', stats.toString({colors: true}));
callback();
cb();
});
});
gulp.task('webpack-dev-server', ['spliting'], function(callback) {
gulp.task('webpack-dev-server', ['spliting'], function() {
var configCopy = Object.create(webpackConfig);
for (var entry in configCopy.entry) {
@ -124,23 +125,22 @@ gulp.task('locales', function() {
// Routes
var routeFiles = `./${srcDir}/**/routes.js`;
var routeFiles = `./${srcDir}/**/routes.json`;
gulp.task('routes', function() {
var fileTpl = '\n"<%=dirname%>": <%=contents%>';
var globalTpl = 'var routes = {<%=contents%>\n}';
var regex = new RegExp('^(.*)/routes\.js$');
function cb(file) {
var relative = file.relative.replace(/\\/g, '/');
var dirname = relative.match(regex)[1];
return {dirname: dirname};
var dirname = relative.match(/^(.*)\/routes\.json$/)[1];
return {
dirname: dirname,
json: file.contents
};
}
return gulp.src(routeFiles)
.pipe(wrap(fileTpl, cb))
.pipe(wrap('\n"<%=dirname%>": <%=json%>', cb))
.pipe(concat('routes.js', {newLine: ','}))
.pipe(wrap(globalTpl))
.pipe(wrap('var routes = {<%=contents%>\n};'))
.pipe(gulp.dest(buildDir));
});

View File

@ -1,7 +1,10 @@
module.exports = function(Client) {
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
}
}
}
]