From 6f6d3d4623d5d2e3b03e4534dbd932d124675f40 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Fri, 13 Jan 2017 15:45:14 +0100 Subject: [PATCH] Filtro avanzado clientes --- @salix/app/src/components/app/app.js | 28 ++++++++- .../app/src/components/searchbar/searchbar.js | 9 +++ @salix/app/src/run.js | 4 +- @salix/core/src/focus.js | 12 ++-- @salix/core/src/popover/popover.js | 9 +-- .../crud/src/client/addresses-data/index.html | 62 +++++++++---------- @salix/crud/src/client/addresses/index.html | 10 ++- @salix/crud/src/client/basic-data/index.html | 4 +- @salix/crud/src/client/fiscal-data/index.html | 20 +++--- @salix/crud/src/client/index/index.html | 6 +- @salix/crud/src/client/index/index.js | 35 +++++++++-- .../src/client/search-panel/search-panel.html | 20 +++--- .../src/client/search-panel/search-panel.js | 7 ++- db.json | 2 +- 14 files changed, 146 insertions(+), 82 deletions(-) diff --git a/@salix/app/src/components/app/app.js b/@salix/app/src/components/app/app.js index 0967d792b..567cc0070 100644 --- a/@salix/app/src/components/app/app.js +++ b/@salix/app/src/components/app/app.js @@ -1,9 +1,33 @@ require('./style.css'); -import template from './app.html'; import {module} from '../../module'; export const NAME = 'vnApp'; export const COMPONENT = { - template: template + template: require('./app.html') }; module.component(NAME, COMPONENT); + +vnAppInterceptor.$inject = ['$q']; +function vnAppInterceptor($q) { + return { + request: function(config) { + return config; + }, + requestError: function(rejection) { + return $q.reject(rejection); + }, + response: function(response) { + return response; + }, + responseError: function(rejection) { + return $q.reject(rejection); + } + }; +} +module.factory('vnAppInterceptor', vnAppInterceptor); + +interceptorConfig.$inject = ['$httpProvider']; +function interceptorConfig($httpProvider) { + $httpProvider.interceptors.push('vnAppInterceptor'); +} +module.config(interceptorConfig); diff --git a/@salix/app/src/components/searchbar/searchbar.js b/@salix/app/src/components/searchbar/searchbar.js index e2a4a3afd..ee94fa5e1 100644 --- a/@salix/app/src/components/searchbar/searchbar.js +++ b/@salix/app/src/components/searchbar/searchbar.js @@ -20,6 +20,15 @@ function controller($element, $scope, $document, $compile, popover) { var child = $document[0].createElement(this.popover); $compile(child)($scope); popover.show($element, child); + + // XXX: ¿Existe una forma más adecuada de acceder al controlador de un componente? + var childCtrl = angular.element(child).isolateScope().$ctrl; + childCtrl.onSubmit = () => { + popover.hide(); + this.model.params = childCtrl.filter; + this.search(); + }; + event.preventDefault(); }; } diff --git a/@salix/app/src/run.js b/@salix/app/src/run.js index 4641c9785..997e30790 100644 --- a/@salix/app/src/run.js +++ b/@salix/app/src/run.js @@ -1,7 +1,7 @@ import {module} from './module'; -export const run = function($rootScope) { +run.$inject = ['$rootScope']; +export function run ($rootScope) { $rootScope.$on('$viewContentLoaded', () => {}) } -run.$inject = ['$rootScope']; module.run(run); diff --git a/@salix/core/src/focus.js b/@salix/core/src/focus.js index ddfce791c..644549697 100644 --- a/@salix/core/src/focus.js +++ b/@salix/core/src/focus.js @@ -4,12 +4,12 @@ export const NAME = 'vnFocus'; export function directive() { return { restrict: 'A', - link: function(scope, elements, attrs) { - let element = elements[0]; - element.focus(); - let len = element.value ? element.value.length : 0; - element.setSelectionRange(0, len); - // element.select(); + link: function($scope, $element, $attrs) { + var input = $element[0]; + input.focus(); + var len = input.value ? input.value.length : 0; + input.setSelectionRange(0, len); + // input.select(); } }; } diff --git a/@salix/core/src/popover/popover.js b/@salix/core/src/popover/popover.js index 0a6b37942..0779a04c7 100644 --- a/@salix/core/src/popover/popover.js +++ b/@salix/core/src/popover/popover.js @@ -46,8 +46,8 @@ function $get($document) { var style = popover.style; var spacing = 0; - var margin = 20; - var dblMargin = margin * 2; + var screenMargin = 20; + var dblMargin = screenMargin * 2; var width = popover.offsetWidth; var height = popover.offsetHeight; @@ -75,12 +75,13 @@ function $get($document) { top -= height + parentNode.offsetHeight + spacing * 2; if(left < 0) - left = margin; + left = screenMargin; if(top < 0) - top = margin; + top = screenMargin; style.top = (top) +'px'; style.left = (left) +'px'; + style.minWidth = (rect.width) +'px'; } $document[0].body.appendChild (popover); diff --git a/@salix/crud/src/client/addresses-data/index.html b/@salix/crud/src/client/addresses-data/index.html index 1a0d19cc9..062c2e832 100644 --- a/@salix/crud/src/client/addresses-data/index.html +++ b/@salix/crud/src/client/addresses-data/index.html @@ -1,34 +1,32 @@ -
- - - - Consignatario - - - - - - - - - - - - - - - - - - - - - - - - - + + + + Consignatario + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/@salix/crud/src/client/addresses/index.html b/@salix/crud/src/client/addresses/index.html index 6c172b366..28cd047cd 100644 --- a/@salix/crud/src/client/addresses/index.html +++ b/@salix/crud/src/client/addresses/index.html @@ -1,9 +1,8 @@ - - + + Consignatario - @@ -18,6 +17,11 @@ + + + + + diff --git a/@salix/crud/src/client/basic-data/index.html b/@salix/crud/src/client/basic-data/index.html index fc23f53b3..efba4afbc 100644 --- a/@salix/crud/src/client/basic-data/index.html +++ b/@salix/crud/src/client/basic-data/index.html @@ -18,8 +18,8 @@ - - + + diff --git a/@salix/crud/src/client/fiscal-data/index.html b/@salix/crud/src/client/fiscal-data/index.html index aa651fe9b..2b97bee5d 100644 --- a/@salix/crud/src/client/fiscal-data/index.html +++ b/@salix/crud/src/client/fiscal-data/index.html @@ -1,6 +1,6 @@
- + Datos fiscales y de facturación @@ -28,7 +28,7 @@ - + Información de facturación @@ -46,17 +46,19 @@ - + Documentación - - - + + + - - - + + + + + \ No newline at end of file diff --git a/@salix/crud/src/client/index/index.html b/@salix/crud/src/client/index/index.html index 10c21e943..bcd03dbf2 100644 --- a/@salix/crud/src/client/index/index.html +++ b/@salix/crud/src/client/index/index.html @@ -1,5 +1,5 @@
-
+
+ popover="vn-client-search-panel"> diff --git a/@salix/crud/src/client/index/index.js b/@salix/crud/src/client/index/index.js index aa0d6a5f3..c7ebe1774 100644 --- a/@salix/crud/src/client/index/index.js +++ b/@salix/crud/src/client/index/index.js @@ -9,12 +9,39 @@ export const COMPONENT = { controller: function($http) { this.clients = []; this.find = function() { + var where = null; + var filter = this.filter; var queryStr = '/client/api/Clients'; - var search = this.filter.search; - if(search) { - let json = JSON.stringify({where: {name: {ilike: search}}}); - var queryStr = `${queryStr}?filter=${json}`; + + var search = filter.search; + if(search) + where = {name: {ilike: search}}; + + var params = filter.params; + if(params) { + where = {}; + let partials = { + alias: true, + name: true, + socialName: true, + city: true, + email: true + } + for(let param in params) + if (params[param]) { + if(partials[param]) + where[param] = {ilike: params[param]}; + else + where[param] = params[param]; + } + filter.params = undefined; } + + if(where) { + let json = JSON.stringify({where: where}); + queryStr = `${queryStr}?filter=${json}`; + } + $http.get(queryStr).then( json => this.clients = json.data, json => console.error(json.data.error.message) diff --git a/@salix/crud/src/client/search-panel/search-panel.html b/@salix/crud/src/client/search-panel/search-panel.html index 79d79c98a..e7f5ca2bd 100644 --- a/@salix/crud/src/client/search-panel/search-panel.html +++ b/@salix/crud/src/client/search-panel/search-panel.html @@ -1,25 +1,25 @@
-
+ - - + + - + - + - - + + - - + + - +
diff --git a/@salix/crud/src/client/search-panel/search-panel.js b/@salix/crud/src/client/search-panel/search-panel.js index 5c5ea48a9..a044193ab 100644 --- a/@salix/crud/src/client/search-panel/search-panel.js +++ b/@salix/crud/src/client/search-panel/search-panel.js @@ -1,9 +1,10 @@ -import template from './search-panel.html'; import {module} from '../../module'; export const NAME = 'vnClientSearchPanel'; export const COMPONENT = { - controllerAs: 'search', - template: template + template: require('./search-panel.html'), + controller: function($scope) { + this.onSubmit = function() {} + } }; module.component(NAME, COMPONENT); diff --git a/db.json b/db.json index 178307e40..0ae352e30 100644 --- a/db.json +++ b/db.json @@ -18,7 +18,7 @@ "NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue": "{\"id\":\"NUf7o684TmteojFX9KmPOpaDLthjP5Def4wuy83Yjv31i43HHiWgV3FyBp6pX8Ue\",\"ttl\":1209600,\"created\":\"2016-11-21T11:06:11.113Z\",\"userId\":1}" }, "Client": { - "12": "{\"name\":\"Verdnatura\",\"id\":12,\"fi\":\"B97367486\",\"salesPerson\":\"2\",\"telefono\":\"963242100\",\"socialName\":\"Verdnatura Levante SL\",\"active\":true,\"user\":\"verdnatura\",\"fax\":\"963242100\",\"phone\":\"96324210\",\"email\":\"informatica@verdnatura.es\",\"surcharge\":true,\"cyc\":2345,\"credit\":1000,\"iban\":\"2352345234523452345\",\"street\":\"Avenida Espioca, 100\",\"city\":\"Silla\",\"postcode\":\"46680\",\"mobile\":\"654654654\",\"dueDay\":4,\"gestdoc\":23452343,\"province\":1,\"country\":\"1\"}", + "12": "{\"name\":\"Verdnatura\",\"id\":12,\"fi\":\"B97367486\",\"salesPerson\":\"2\",\"telefono\":\"963242100\",\"socialName\":\"Verdnatura Levante SL\",\"active\":true,\"user\":\"verdnatura\",\"fax\":\"963242100\",\"phone\":\"963242100\",\"email\":\"informatica@verdnatura.es\",\"surcharge\":true,\"cyc\":2345,\"credit\":1000,\"iban\":\"2352345234523452345\",\"street\":\"Avenida Espioca, 100\",\"city\":\"Silla\",\"postcode\":\"46013\",\"mobile\":\"654654654\",\"dueDay\":4,\"gestdoc\":23452343,\"province\":1,\"country\":\"1\",\"modify\":\"BasicData\"}", "14": "{\"name\":\"Cliente 1\",\"id\":14,\"street\":\"Aaaaaaaaaa\",\"fi\":\"1234567890A\",\"socialName\":\"Cliente 1\",\"fax\":\"963242100\",\"dischargeDate\":\"01/01/2017\",\"telefono\":\"963242100\",\"salesPerson\":\"2\",\"email\":\"informatica@verdnatura.es\",\"city\":\"asdf\",\"postcode\":\"asdf\",\"phone\":\"asdf\",\"mobile\":\"asdf\",\"credit\":2345,\"cyc\":123,\"iban\":\"asdf\",\"dueDay\":345,\"gestdoc\":2435,\"surcharge\":true}" }, "PaymentMethod": {