diff --git a/@salix/app/src/styles/display.css b/@salix/app/src/styles/display.css index 29100e06c..442c0e6db 100644 --- a/@salix/app/src/styles/display.css +++ b/@salix/app/src/styles/display.css @@ -1,3 +1,52 @@ .display-block{ display: block; } + +/*angular-paging*/ +.well { + min-height: 20px; + padding: 19px; + margin-bottom: 20px; + background-color: #f5f5f5; + border: 1px solid #e3e3e3; + border-radius: 4px; + -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .05); + box-shadow: inset 0 1px 1px rgba(0, 0, 0, .05); +} +.pagination { + display: inline-block; + padding-left: 0; + margin: 20px 0; + border-radius: 4px; +} +.pagination > li { + display: inline; +} +.pagination > li > a, +.pagination > li > span { + position: relative; + float: left; + padding: 6px 12px; + margin-left: -1px; + line-height: 1.42857143; + color: #337ab7; + text-decoration: none; + background-color: #fff; + border: 1px solid #ddd; +} +.pagination > li:first-child > a, +.pagination > li:first-child > span { + margin-left: 0; + border-top-left-radius: 4px; + border-bottom-left-radius: 4px; +} +.form-group { + margin-bottom: 15px; +} + +.pagination>li.active>a { + background: #4f94ce; + color: #fff; +} +ul.pagination li a:hover:not(.active) {background-color: #ddd;} +/* fin angular-paging*/ diff --git a/@salix/crud/src/client/addresses-data-create/index.js b/@salix/crud/src/client/addresses-data-create/index.js index b426bddb4..b9520dcf4 100644 --- a/@salix/crud/src/client/addresses-data-create/index.js +++ b/@salix/crud/src/client/addresses-data-create/index.js @@ -7,6 +7,8 @@ export const COMPONENT = { controllerAs: 'addressData', controller: function($http, $state) { + var self = this; + this.clientId = $state.params.id; this.address = {}; $http.get('/client/api/Agencies').then( json => this.agencies = json.data @@ -16,6 +18,7 @@ export const COMPONENT = { ); this.submit = function(){ + this.address.client = self.clientId; $http.post('/client/api/Addresses', this.address).then( json => $state.go('clientCard.addresses') ); diff --git a/@salix/crud/src/client/addresses/index.html b/@salix/crud/src/client/addresses/index.html index 4160250d3..5331e7bb9 100644 --- a/@salix/crud/src/client/addresses/index.html +++ b/@salix/crud/src/client/addresses/index.html @@ -18,8 +18,22 @@ + + + + + + + - + diff --git a/@salix/crud/src/client/addresses/index.js b/@salix/crud/src/client/addresses/index.js index 0da0cc3ac..fe1d24796 100644 --- a/@salix/crud/src/client/addresses/index.js +++ b/@salix/crud/src/client/addresses/index.js @@ -5,22 +5,64 @@ export const NAME = 'vnClientAddresses'; export const COMPONENT = { template: template, controllerAs: 'address', - bindings: { - adresses: '<', + bindings: { client: '<' }, - controller: function($http) + controller: function($http, $state) { + var self = this; + let numPerPage = 2; + let numRecords = 0; + + this.$onChanges = function(changes) { + if (this.client) { + self.client = this.client; + this.getAddresses(); + } + }; + this.getAddresses = () => { + var json = JSON.stringify({client: self.client.id}); + $http.get(`/client/api/Addresses/count?where=${json}`).then( + json => { + numRecords = json.data.count; + self.getNumPages(); + self.figureOutToDisplay(); + } + ); + }; $http.get('/client/api/Addresses').then( json => this.addresses = json.data ); - this.submit = function(){ - $http.post('/client/api/Clients', this.model).then( - json => $state.go('clientCard.basicData',{id: json.data.id}) + + this.getNumPages = () => { + var nPages = numRecords / numPerPage; + if (nPages > 0) + self.numPages = (nPages % 2) ? Math.ceil(nPages) : Math.ceil(nPages) + 1; + }; + + this.figureOutToDisplay = () => { + var begin = ((self.currentPage - 1) * numPerPage); + self.getAddress(begin); + }; + + this.getAddress = function(end) { + var json = JSON.stringify({where: {client: self.client.id}, limit: numPerPage, skip: end}); + $http.get(`/client/api/Addresses?filter=${json}`).then( + json => { + self.addresses = json.data; + self.filteredTodos = self.addresses; + } ); }; + + this.pageChanged = () => { + self.figureOutToDisplay(); + }; + this.newAddress = () => { + $state.go("clientCard.addressDataCreate", {id: self.client.id}); + }; } }; -COMPONENT.controller.$inject = ['$http']; +COMPONENT.controller.$inject = ['$http', '$state']; module.component(NAME, COMPONENT); diff --git a/@salix/crud/src/client/routes.js b/@salix/crud/src/client/routes.js index 23dd0d3f1..fa5a6f07d 100644 --- a/@salix/crud/src/client/routes.js +++ b/@salix/crud/src/client/routes.js @@ -31,6 +31,9 @@ url: "/addresses", state: "clientCard.addresses", component: "vn-client-addresses", + params: { + client: "card.client" + }, description: "Consignatarios", icon: "local_shipping" }, { diff --git a/@salix/package.json b/@salix/package.json index e9520bc8d..bee8f861f 100644 --- a/@salix/package.json +++ b/@salix/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "angular": "^1.5.8", + "angular-paging": "^2.2.2", "angular-translate": "^2.13.1", "angular-ui-router": "^1.0.0-beta.3", "express": "^4.14.0", diff --git a/@salix/vendor/src/angular-paging.js b/@salix/vendor/src/angular-paging.js new file mode 100644 index 000000000..52c3085aa --- /dev/null +++ b/@salix/vendor/src/angular-paging.js @@ -0,0 +1,5 @@ +import * as _ngPaging from 'angular-paging'; + +export const ngPaging = { + name: 'bw.paging' +}; diff --git a/@salix/vendor/src/vendor.js b/@salix/vendor/src/vendor.js index 740587725..a6667d6d6 100644 --- a/@salix/vendor/src/vendor.js +++ b/@salix/vendor/src/vendor.js @@ -2,4 +2,5 @@ export * from './angular-vendor'; export * from './oclazyload-vendor'; export * from './uirouter-vendor'; export * from './angular-translate-vendor'; -export * from './materialdesignlite-vendor'; \ No newline at end of file +export * from './materialdesignlite-vendor'; +export * from './angular-paging'; \ No newline at end of file diff --git a/services/client/common/models/Address.json b/services/client/common/models/Address.json index 69ab68a20..9a60529e5 100644 --- a/services/client/common/models/Address.json +++ b/services/client/common/models/Address.json @@ -49,6 +49,11 @@ "type": "belongsTo", "model": "Province", "foreignKey": "provinceId" + }, + "client": { + "type": "belongsTo", + "model":"Client", + "foreignKey": "clientId" } } }