This commit is contained in:
parent
c02d576bb9
commit
82ab9e5ac5
|
@ -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];
|
||||
};
|
||||
};
|
||||
|
|
@ -5,6 +5,7 @@ let isMultiple = require('vn-loopback/util/hook').isMultiple;
|
|||
module.exports = Self => {
|
||||
// Methods
|
||||
require('../methods/address/createDefaultAddress')(Self);
|
||||
require('../methods/address/filter')(Self);
|
||||
|
||||
Self.validateAsync('isEqualizated', cannotHaveET, {
|
||||
message: 'Cannot check Equalization Tax in this NIF/CIF'
|
||||
|
|
|
@ -1,72 +1,74 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="/client/api/Addresses"
|
||||
filter="::$ctrl.filter"
|
||||
url="/client/api/Addresses/filter"
|
||||
limit="10"
|
||||
link="{clientFk: $ctrl.$stateParams.id}"
|
||||
data="$ctrl.addresses"
|
||||
auto-load="true">
|
||||
auto-load="false">
|
||||
</vn-crud-model>
|
||||
<div compact>
|
||||
<vn-card pad-large>
|
||||
<vn-horizontal
|
||||
ng-repeat="address in $ctrl.addresses"
|
||||
class="pad-medium-top"
|
||||
style="align-items: center;">
|
||||
<vn-one
|
||||
border-radius
|
||||
class="pad-small border-solid"
|
||||
ng-class="{
|
||||
'item-hightlight': $ctrl.isDefaultAddress(address),
|
||||
'item-disabled': !address.isActive && !$ctrl.isDefaultAddress(address)
|
||||
}">
|
||||
<vn-horizontal style="align-items: center;">
|
||||
<vn-none pad-medium-h>
|
||||
<vn-icon-button
|
||||
icon="star"
|
||||
ng-if="$ctrl.isDefaultAddress(address)">
|
||||
</vn-icon-button>
|
||||
<vn-icon-button
|
||||
ng-if="!address.isActive"
|
||||
icon="star_border"
|
||||
vn-tooltip="Active first to set as default">
|
||||
</vn-icon-button>
|
||||
<vn-icon-button
|
||||
ng-if="address.isActive && !$ctrl.isDefaultAddress(address)"
|
||||
icon="star_border"
|
||||
vn-tooltip="Set as default"
|
||||
ng-click="$ctrl.setDefault(address)">
|
||||
</vn-icon-button>
|
||||
</vn-none>
|
||||
<vn-one border-solid-right>
|
||||
<vn-horizontal>
|
||||
<vn-one>
|
||||
<div><b>{{::address.nickname}}</b></div>
|
||||
<div name="street">{{::address.street}}</div>
|
||||
<div>{{::address.city}}, {{::address.province}}</div>
|
||||
<div>{{::address.phone}}, {{::address.mobile}}</div>
|
||||
</vn-one>
|
||||
<vn-one>
|
||||
<vn-check
|
||||
vn-one label="Is equalizated"
|
||||
field="address.isEqualizated"
|
||||
disabled="true">
|
||||
</vn-check>
|
||||
</vn-one>
|
||||
</vn-horizontal>
|
||||
</vn-one>
|
||||
<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-table model="model">
|
||||
<vn-card pad-large>
|
||||
<vn-horizontal
|
||||
ng-repeat="address in $ctrl.addresses"
|
||||
class="pad-medium-top"
|
||||
style="align-items: center;">
|
||||
<vn-one
|
||||
border-radius
|
||||
class="pad-small border-solid"
|
||||
ng-class="{
|
||||
'item-hightlight': $ctrl.isDefaultAddress(address),
|
||||
'item-disabled': !address.isActive && !$ctrl.isDefaultAddress(address)
|
||||
}">
|
||||
<vn-horizontal style="align-items: center;">
|
||||
<vn-none pad-medium-h>
|
||||
<vn-icon-button
|
||||
icon="star"
|
||||
ng-if="$ctrl.isDefaultAddress(address)">
|
||||
</vn-icon-button>
|
||||
<vn-icon-button
|
||||
ng-if="!address.isActive"
|
||||
icon="star_border"
|
||||
vn-tooltip="Active first to set as default">
|
||||
</vn-icon-button>
|
||||
<vn-icon-button
|
||||
ng-if="address.isActive && !$ctrl.isDefaultAddress(address)"
|
||||
icon="star_border"
|
||||
vn-tooltip="Set as default"
|
||||
ng-click="$ctrl.setDefault(address)">
|
||||
</vn-icon-button>
|
||||
</vn-none>
|
||||
<vn-one border-solid-right>
|
||||
<vn-horizontal>
|
||||
<vn-one>
|
||||
<div><b>{{::address.nickname}}</b></div>
|
||||
<div name="street">{{::address.street}}</div>
|
||||
<div>{{::address.city}}, {{::address.province}}</div>
|
||||
<div>{{::address.phone}}, {{::address.mobile}}</div>
|
||||
</vn-one>
|
||||
<vn-one>
|
||||
<vn-check
|
||||
vn-one label="Is equalizated"
|
||||
field="address.isEqualizated"
|
||||
disabled="true">
|
||||
</vn-check>
|
||||
</vn-one>
|
||||
</vn-horizontal>
|
||||
</vn-one>
|
||||
</vn-vertical>
|
||||
<a pad-medium-h vn-tooltip="Edit address"
|
||||
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-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-vertical>
|
||||
<a pad-medium-h vn-tooltip="Edit address"
|
||||
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-float-button
|
||||
vn-bind="+"
|
||||
|
@ -76,4 +78,5 @@
|
|||
icon="add"
|
||||
label="Add">
|
||||
</vn-float-button>
|
||||
<vn-pagination model="model"></vn-pagination>
|
||||
</div>
|
||||
|
|
|
@ -5,30 +5,6 @@ class Controller {
|
|||
this.$http = $http;
|
||||
this.$scope = $scope;
|
||||
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) {
|
||||
|
@ -43,8 +19,8 @@ class Controller {
|
|||
}
|
||||
|
||||
isDefaultAddress(address) {
|
||||
if (!this.client) return;
|
||||
return this.client.defaultAddressFk === address.id;
|
||||
if (this.client)
|
||||
return this.client.defaultAddressFk === address.id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +28,7 @@ class Controller {
|
|||
*/
|
||||
sortAddresses() {
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue