Merge branch 'dev' of ssh://git.verdnatura.es:/var/lib/git/salix into dev
This commit is contained in:
commit
72d5e3e0a3
|
@ -3,19 +3,19 @@
|
||||||
<div style="max-width: 40em; margin: 0 auto;">
|
<div style="max-width: 40em; margin: 0 auto;">
|
||||||
<vn-card>
|
<vn-card>
|
||||||
<vn-horizontal pad-medium>
|
<vn-horizontal pad-medium>
|
||||||
<vn-searchbar
|
<vn-searchbar vn-auto
|
||||||
vn-auto
|
|
||||||
index="index"
|
index="index"
|
||||||
on-search="index.accept()"
|
on-search="$ctrl.search(index)"
|
||||||
advanced="true"
|
advanced="true"
|
||||||
|
search="$ctrl.model.search"
|
||||||
popover="vn-client-search-panel">
|
popover="vn-client-search-panel">
|
||||||
</vn-searchbar>
|
</vn-searchbar>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-card margin-medium-top>
|
<vn-card margin-medium-top>
|
||||||
<vn-item-client ng-repeat="client in index.model" title="View client" client="client"></vn-item-client>
|
<vn-item-client ng-repeat="client in index.model.instances" title="View client" client="client"></vn-item-client>
|
||||||
</vn-card>
|
</vn-card>
|
||||||
<vn-paging index="index"></vn-paging>
|
<vn-paging index="index" total="index.model.count"></vn-paging>
|
||||||
</div>
|
</div>
|
||||||
<a ui-sref="create" fixed-bottom-right>
|
<a ui-sref="create" fixed-bottom-right>
|
||||||
<vn-float-button icon="person_add"></vn-float-button>
|
<vn-float-button icon="person_add"></vn-float-button>
|
||||||
|
|
|
@ -2,6 +2,16 @@ import {module} from '../module';
|
||||||
import './style.css';
|
import './style.css';
|
||||||
import './item-client';
|
import './item-client';
|
||||||
|
|
||||||
module.component('vnClientIndex', {
|
class Controller {
|
||||||
template: require('./index.html')
|
search(index) {
|
||||||
});
|
index.filter.search = this.model.search;
|
||||||
|
index.accept();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const NAME = 'vnClientIndex';
|
||||||
|
export const COMPONENT = {
|
||||||
|
template: require('./index.html'),
|
||||||
|
controller: Controller
|
||||||
|
};
|
||||||
|
module.component(NAME, COMPONENT);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<form ng-submit="$ctrl.onSubmit()">
|
<form ng-submit="$ctrl.onSubmit()">
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield vn-one label="Search" model="$ctrl.model.search"></vn-textfield>
|
<vn-textfield vn-one label="Search" model="$ctrl.search"></vn-textfield>
|
||||||
<vn-icon
|
<vn-icon
|
||||||
ng-if="$ctrl.advanced"
|
ng-if="$ctrl.advanced"
|
||||||
ng-click="$ctrl.onClick($event)"
|
ng-click="$ctrl.onClick($event)"
|
||||||
|
|
|
@ -22,9 +22,10 @@ export default class Controller {
|
||||||
}
|
}
|
||||||
onChildSubmit(filter) {
|
onChildSubmit(filter) {
|
||||||
this.vnPopover.hide();
|
this.vnPopover.hide();
|
||||||
this.index.filter = filter;
|
Object.assign(this.index.filter, filter);
|
||||||
this.onSubmit();
|
this.onSubmit();
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
if (this.onSearch)
|
if (this.onSearch)
|
||||||
this.onSearch();
|
this.onSearch();
|
||||||
|
@ -39,6 +40,7 @@ ngModule.component('vnSearchbar', {
|
||||||
template: require('./searchbar.html'),
|
template: require('./searchbar.html'),
|
||||||
bindings: {
|
bindings: {
|
||||||
index: '<',
|
index: '<',
|
||||||
|
search: '=',
|
||||||
onSearch: '&',
|
onSearch: '&',
|
||||||
advanced: '=',
|
advanced: '=',
|
||||||
popover: '@'
|
popover: '@'
|
||||||
|
|
|
@ -5,6 +5,8 @@ module.exports = function(Client) {
|
||||||
require('../scopes/client/card.js')(Client);
|
require('../scopes/client/card.js')(Client);
|
||||||
require('../scopes/client/activate.js')(Client);
|
require('../scopes/client/activate.js')(Client);
|
||||||
require('../scopes/client/addresses.js')(Client);
|
require('../scopes/client/addresses.js')(Client);
|
||||||
|
require('../scopes/client/filter.js')(Client);
|
||||||
|
require('../scopes/client/before-save.js')(Client);
|
||||||
|
|
||||||
// Validations
|
// Validations
|
||||||
|
|
||||||
|
@ -58,41 +60,4 @@ module.exports = function(Client) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hooks
|
|
||||||
|
|
||||||
Client.observe('before save', function(ctx, next) {
|
|
||||||
if (ctx.instance) {
|
|
||||||
if (!ctx.instance.dueDay)
|
|
||||||
ctx.instance.dueDay = 5;
|
|
||||||
next();
|
|
||||||
} else {
|
|
||||||
Client.findById(ctx.where.id, function(err, instance) {
|
|
||||||
if (instance
|
|
||||||
&& instance.payMethodFk != ctx.data.payMethodFk
|
|
||||||
&& instance.dueDay == ctx.data.dueDay)
|
|
||||||
ctx.data.dueDay = 5;
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Basic filter
|
|
||||||
|
|
||||||
Client.installMethod('filter', filterClients);
|
|
||||||
function filterClients(p) {
|
|
||||||
return {
|
|
||||||
where: {
|
|
||||||
id: p.id,
|
|
||||||
name: {regexp: p.name},
|
|
||||||
cif: p.cif,
|
|
||||||
socialName: {regexp: p.socialName},
|
|
||||||
city: {regexp: p.city},
|
|
||||||
postcode: p.postcode,
|
|
||||||
email: {regexp: p.email},
|
|
||||||
phone: p.phone
|
|
||||||
},
|
|
||||||
skip: (p.page - 1) * p.size,
|
|
||||||
limit: p.size
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
};
|
|
@ -54,11 +54,39 @@ module.exports = function(self) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.filter = (params, cb) => {
|
this[methodName] = (params, cb) => {
|
||||||
let filter = removeEmpty(filterCb(params));
|
let filter = removeEmpty(filterCb(params));
|
||||||
|
var response = {}
|
||||||
|
|
||||||
|
function returnValues(){
|
||||||
|
if(response.instances !== undefined && response.count !== undefined)
|
||||||
|
cb(null, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
function error(){
|
||||||
|
cb(null, response);
|
||||||
|
}
|
||||||
|
|
||||||
this.find(filter, function(err, instances) {
|
this.find(filter, function(err, instances) {
|
||||||
if(!err)
|
if(!err){
|
||||||
cb(null, instances);
|
response.instances = instances;
|
||||||
|
returnValues();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
error();
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
this.count(filter.where, function(err, totalCount){
|
||||||
|
if(!err){
|
||||||
|
response.count = totalCount;
|
||||||
|
returnValues();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
error();
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
module.exports = function(Client){
|
||||||
|
Client.observe('before save', function(ctx, next) {
|
||||||
|
if (ctx.instance) {
|
||||||
|
if (!ctx.instance.dueDay)
|
||||||
|
ctx.instance.dueDay = 5;
|
||||||
|
next();
|
||||||
|
} else {
|
||||||
|
Client.findById(ctx.where.id, function(err, instance) {
|
||||||
|
if (instance
|
||||||
|
&& instance.payMethodFk != ctx.data.payMethodFk
|
||||||
|
&& instance.dueDay == ctx.data.dueDay)
|
||||||
|
ctx.data.dueDay = 5;
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
module.exports = function(Client){
|
||||||
|
Client.installMethod('filter', filterClients);
|
||||||
|
function filterClients(p) {
|
||||||
|
if(p.search && p.search !== "")
|
||||||
|
return searchWhere(p);
|
||||||
|
return andWhere(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
function searchWhere(p){
|
||||||
|
return {
|
||||||
|
where: {
|
||||||
|
or:[
|
||||||
|
{id: p.search,},
|
||||||
|
{name: {regexp: p.search}}
|
||||||
|
]
|
||||||
|
|
||||||
|
},
|
||||||
|
skip: (p.page - 1) * p.size,
|
||||||
|
limit: p.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function andWhere(p){
|
||||||
|
return {
|
||||||
|
where: {
|
||||||
|
id: p.id,
|
||||||
|
name: {regexp: p.name},
|
||||||
|
cif: p.cif,
|
||||||
|
socialName: {regexp: p.socialName},
|
||||||
|
city: {regexp: p.city},
|
||||||
|
postcode: p.postcode,
|
||||||
|
email: {regexp: p.email},
|
||||||
|
phone: p.phone
|
||||||
|
},
|
||||||
|
skip: (p.page - 1) * p.size,
|
||||||
|
limit: p.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue