Tarea #1534 Paginar consignatarios
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-06-18 09:34:32 +02:00
parent c02d576bb9
commit 82ab9e5ac5
4 changed files with 122 additions and 89 deletions

View File

@ -0,0 +1,53 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('filter', {
description: 'Find all instances of the model matched by filter from the data source.',
accessType: 'READ',
accepts: [
{
arg: 'filter',
type: 'Object',
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
http: {source: 'query'}
}
],
returns: {
type: ['Object'],
root: true
},
http: {
path: `/filter`,
verb: 'GET'
}
});
Self.filter = async filter => {
let conn = Self.dataSource.connector;
let stmts = [];
let stmt;
filter.order = [
'c.defaultAddressFk DESC',
'a.isActive DESC',
'a.nickname ASC'
];
stmt = new ParameterizedSQL(
`SELECT a.*
FROM vn.address a
LEFT JOIN vn.client c ON c.defaultAddressFk = a.id`
);
stmt.merge(conn.makeSuffix(filter));
let itemsIndex = stmts.push(stmt) - 1;
let sql = ParameterizedSQL.join(stmts, ';');
let result = await conn.executeStmt(sql);
return itemsIndex === 0 ? result : result[itemsIndex];
};
};

View File

@ -5,6 +5,7 @@ let isMultiple = require('vn-loopback/util/hook').isMultiple;
module.exports = Self => { module.exports = Self => {
// Methods // Methods
require('../methods/address/createDefaultAddress')(Self); require('../methods/address/createDefaultAddress')(Self);
require('../methods/address/filter')(Self);
Self.validateAsync('isEqualizated', cannotHaveET, { Self.validateAsync('isEqualizated', cannotHaveET, {
message: 'Cannot check Equalization Tax in this NIF/CIF' message: 'Cannot check Equalization Tax in this NIF/CIF'

View File

@ -1,72 +1,74 @@
<vn-crud-model <vn-crud-model
vn-id="model" vn-id="model"
url="/client/api/Addresses" url="/client/api/Addresses/filter"
filter="::$ctrl.filter" limit="10"
link="{clientFk: $ctrl.$stateParams.id}" link="{clientFk: $ctrl.$stateParams.id}"
data="$ctrl.addresses" data="$ctrl.addresses"
auto-load="true"> auto-load="false">
</vn-crud-model> </vn-crud-model>
<div compact> <div compact>
<vn-card pad-large> <vn-table model="model">
<vn-horizontal <vn-card pad-large>
ng-repeat="address in $ctrl.addresses" <vn-horizontal
class="pad-medium-top" ng-repeat="address in $ctrl.addresses"
style="align-items: center;"> class="pad-medium-top"
<vn-one style="align-items: center;">
border-radius <vn-one
class="pad-small border-solid" border-radius
ng-class="{ class="pad-small border-solid"
'item-hightlight': $ctrl.isDefaultAddress(address), ng-class="{
'item-disabled': !address.isActive && !$ctrl.isDefaultAddress(address) 'item-hightlight': $ctrl.isDefaultAddress(address),
}"> 'item-disabled': !address.isActive && !$ctrl.isDefaultAddress(address)
<vn-horizontal style="align-items: center;"> }">
<vn-none pad-medium-h> <vn-horizontal style="align-items: center;">
<vn-icon-button <vn-none pad-medium-h>
icon="star" <vn-icon-button
ng-if="$ctrl.isDefaultAddress(address)"> icon="star"
</vn-icon-button> ng-if="$ctrl.isDefaultAddress(address)">
<vn-icon-button </vn-icon-button>
ng-if="!address.isActive" <vn-icon-button
icon="star_border" ng-if="!address.isActive"
vn-tooltip="Active first to set as default"> icon="star_border"
</vn-icon-button> vn-tooltip="Active first to set as default">
<vn-icon-button </vn-icon-button>
ng-if="address.isActive && !$ctrl.isDefaultAddress(address)" <vn-icon-button
icon="star_border" ng-if="address.isActive && !$ctrl.isDefaultAddress(address)"
vn-tooltip="Set as default" icon="star_border"
ng-click="$ctrl.setDefault(address)"> vn-tooltip="Set as default"
</vn-icon-button> ng-click="$ctrl.setDefault(address)">
</vn-none> </vn-icon-button>
<vn-one border-solid-right> </vn-none>
<vn-horizontal> <vn-one border-solid-right>
<vn-one> <vn-horizontal>
<div><b>{{::address.nickname}}</b></div> <vn-one>
<div name="street">{{::address.street}}</div> <div><b>{{::address.nickname}}</b></div>
<div>{{::address.city}}, {{::address.province}}</div> <div name="street">{{::address.street}}</div>
<div>{{::address.phone}}, {{::address.mobile}}</div> <div>{{::address.city}}, {{::address.province}}</div>
</vn-one> <div>{{::address.phone}}, {{::address.mobile}}</div>
<vn-one> </vn-one>
<vn-check <vn-one>
vn-one label="Is equalizated" <vn-check
field="address.isEqualizated" vn-one label="Is equalizated"
disabled="true"> field="address.isEqualizated"
</vn-check> disabled="true">
</vn-one> </vn-check>
</vn-horizontal> </vn-one>
</vn-one> </vn-horizontal>
<vn-vertical vn-one pad-medium-h>
<vn-one ng-repeat="observation in address.observations track by $index" ng-class="{'pad-small-top': $index}">
<b margin-medium-right>{{::observation.observationType.description}}:</b>
<span>{{::observation.description}}</span>
</vn-one> </vn-one>
</vn-vertical> <vn-vertical vn-one pad-medium-h>
<a pad-medium-h vn-tooltip="Edit address" <vn-one ng-repeat="observation in address.observations track by $index" ng-class="{'pad-small-top': $index}">
vn-auto ui-sref="client.card.address.edit({addressId: {{::address.id}}})"> <b margin-medium-right>{{::observation.observationType.description}}:</b>
<vn-icon-button icon="edit"></vn-icon-button> <span>{{::observation.description}}</span>
</a> </vn-one>
</vn-horizontal> </vn-vertical>
</vn-one> <a pad-medium-h vn-tooltip="Edit address"
</vn-horizontal> vn-auto ui-sref="client.card.address.edit({addressId: {{::address.id}}})">
<vn-icon-button icon="edit"></vn-icon-button>
</a>
</vn-horizontal>
</vn-one>
</vn-horizontal>
</vn-table>
</vn-card> </vn-card>
<vn-float-button <vn-float-button
vn-bind="+" vn-bind="+"
@ -76,4 +78,5 @@
icon="add" icon="add"
label="Add"> label="Add">
</vn-float-button> </vn-float-button>
<vn-pagination model="model"></vn-pagination>
</div> </div>

View File

@ -5,30 +5,6 @@ class Controller {
this.$http = $http; this.$http = $http;
this.$scope = $scope; this.$scope = $scope;
this.$stateParams = $stateParams; this.$stateParams = $stateParams;
this.filter = {
include: {
observations: 'observationType'
},
order: ['isActive DESC', 'nickname ASC']
};
}
get client() {
return this._client;
}
set client(value) {
this._client = value;
this.sortAddresses();
}
get addresses() {
return this._addresses;
}
set addresses(value) {
this._addresses = value;
this.sortAddresses();
} }
setDefault(address) { setDefault(address) {
@ -43,8 +19,8 @@ class Controller {
} }
isDefaultAddress(address) { isDefaultAddress(address) {
if (!this.client) return; if (this.client)
return this.client.defaultAddressFk === address.id; return this.client.defaultAddressFk === address.id;
} }
/** /**
@ -52,7 +28,7 @@ class Controller {
*/ */
sortAddresses() { sortAddresses() {
if (!this.client || !this.addresses) return; if (!this.client || !this.addresses) return;
this.$scope.model.data = this.addresses.sort((a, b) => { this.addresses = this.addresses.sort((a, b) => {
return this.isDefaultAddress(b) - this.isDefaultAddress(a); return this.isDefaultAddress(b) - this.isDefaultAddress(a);
}); });
} }