diff --git a/.jshintrc b/.jshintrc index dd429f7..d8cbb07 100644 --- a/.jshintrc +++ b/.jshintrc @@ -32,7 +32,7 @@ "indent": 4, // Prohibit use of a variable before it is defined. - "latedef": true, + "latedef": false, // Enforce line length to 100 characters "maxlen": 100, diff --git a/gulpfile.js b/gulpfile.js index 4d5f193..f08d1ed 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -17,7 +17,7 @@ var paths = { }; gulp.task('templates', function() { - pump( + return pump( [ gulp.src(paths.srcViews), replace('views/', ''), @@ -31,8 +31,8 @@ gulp.task('templates', function() { ); }); -gulp.task('uglify', function() { - pump( +gulp.task('uglify', ['templates'], function() { + return pump( [ gulp.src([ paths.srcJS, @@ -48,7 +48,7 @@ gulp.task('uglify', function() { }); gulp.task('pre-commit', function() { - pump( + return pump( [ gulp.src(paths.srcJS), jshint('.jshintrc'), @@ -58,7 +58,6 @@ gulp.task('pre-commit', function() { ); gulp.start('uglify'); - gulp.start('templates'); }); gulp.task('webserver', function() { diff --git a/index.html b/index.html index e396921..d16af4a 100644 --- a/index.html +++ b/index.html @@ -13,7 +13,7 @@ - + @@ -25,17 +25,35 @@ + +
diff --git a/package.json b/package.json index 4887be1..b955da4 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,21 @@ { "name": "foca-modal-vendedores", "version": "0.0.1", - "description": "Modal búsqueda de vendedores", + "description": "Modal para seleccionar vendedores", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "compile": "gulp templates && gulp uglify", + "gulp-pre-commit": "gulp pre-commit", + "compile": "gulp uglify", "postinstall": "npm run compile && rm -R src && rm index.html && rm .jshintrc && rm gulpfile.js", - "install-dev": "npm install angular bootstrap jquery font-awesome gulp gulp-concat gulp-jshint gulp-rename gulp-replace gulp-uglify-es jshint pump gulp-connect jasmine-core pre-commit" + "install-dev": "npm install -D angular bootstrap font-awesome gulp gulp-angular-templatecache gulp-concat gulp-connect gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify jasmine-core jquery jshint pre-commit pump ui-bootstrap4 && npm i -D git+https://192.168.0.11/modulos-npm/foca-directivas" }, + "pre-commit": [ + "gulp-pre-commit" + ], "repository": { "type": "git", - "url": "https://192.168.0.11/modulos-npm/foca-modal-vendedores.git" + "url": "https://192.168.0.11/modulos-npm/foca-modal-vendedores" }, "author": "Foca Software", "license": "ISC", @@ -29,11 +33,13 @@ "gulp-replace": "^1.0.0", "gulp-uglify": "^3.0.1", "jquery": "^3.3.1", - "pump": "^3.0.0" + "pump": "^3.0.0", + "foca-directivas": "git+https://192.168.0.11/modulos-npm/foca-directivas" }, "devDependencies": { - "angular": "^1.7.4", + "angular": "^1.7.5", "bootstrap": "^4.1.3", + "foca-directivas": "git+https://192.168.0.11/modulos-npm/foca-directivas", "font-awesome": "^4.7.0", "gulp": "^3.9.1", "gulp-angular-templatecache": "^2.2.1", @@ -49,6 +55,6 @@ "jshint": "^2.9.6", "pre-commit": "^1.2.2", "pump": "^3.0.0", - "ui-bootstrap4": "^3.0.4" + "ui-bootstrap4": "^3.0.5" } } diff --git a/src/etc/develop.js.ejemplo b/src/etc/develop.js.ejemplo index 506b1e5..519b7a7 100644 --- a/src/etc/develop.js.ejemplo +++ b/src/etc/develop.js.ejemplo @@ -1,4 +1,4 @@ -angular.module('focaBusquedaProductos') +angular.module('focaModalVendedores') .constant("API_ENDPOINT", { 'URL': '//127.0.0.1:9000' }); diff --git a/src/js/controller.js b/src/js/controller.js index 94beece..901f9ac 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,141 +1,150 @@ angular.module('focaModalVendedores') - .controller('modalVendedoresCtrl', [ - '$filter', - '$scope', - '$uibModalInstance', - 'focaVendedoresService', - function ($filter, $scope, $uibModalInstance, focaVendedoresService) { - var json = { - nombre: '' - } - focaVendedoresService.getVendedores(json).then( - function (res) { - $scope.vendedores = res.data; - $scope.search(); - }); - - // pagination - $scope.numPerPage = 10; - $scope.currentPage = 1; - $scope.filteredVendedores = []; - $scope.currentPageVendedores = []; - $scope.selectVendedores = -1; - - $scope.search = function () { - $scope.filteredVendedores = $filter('filter')($scope.vendedores, { $: $scope.filters }); - $scope.resetPage(); - } - - $scope.resetPage = function () { - $scope.currentPage = 1; - $scope.selectPage(1); - } - - $scope.selectPage = function (page) { - var start = (page - 1) * $scope.numPerPage; - var end = start + $scope.numPerPage; - $scope.currentPageVendedores = $scope.filteredVendedores.slice(start, end); - } - - $scope.select = function (vendedor) { - $uibModalInstance.close(vendedor); - } - - $scope.cancel = function () { - $uibModalInstance.dismiss('cancel'); - } - $scope.busquedaDown = function (key) { - if (key === 40) { - primera(key); - } - }; - - $scope.busquedaPress = function (key) { - if (key === 13) { - primera(key); - } - }; - - $scope.itemProducto = function (key) { - if (key === 38) { - anterior(key); - } - - if (key === 40) { - siguiente(key); - } - - if (key === 37) { - retrocederPagina(); - } - - if (key === 39) { - avanzarPagina(); - } - }; - - function calcularPages(paginaActual) { - var paginas = []; - paginas.push(paginaActual); - - if (paginaActual - 1 > 1) { - - paginas.unshift(paginaActual - 1); - if (paginaActual - 2 > 1) { - paginas.unshift(paginaActual - 2); - } - } - - if (paginaActual + 1 < $scope.lastPage) { - paginas.push(paginaActual + 1); - if (paginaActual + 2 < $scope.lastPage) { - paginas.push(paginaActual + 2); - } - } - - if (paginaActual !== 1) { - paginas.unshift(1); - } - - if (paginaActual !== $scope.lastPage) { - paginas.push($scope.lastPage); - } - - return paginas; - } - - function primera() { - $scope.selectedProducto = 0; - } - - function anterior() { - if ($scope.selectedProducto === 0 && $scope.currentPage > 1) { - retrocederPagina(); - } else { - $scope.selectedProducto--; - } - } - - function siguiente() { - if ($scope.selectedProducto < $scope.currentPageProductos.length - 1) { - $scope.selectedProducto++; - } else { - avanzarPagina(); - } - } - - function retrocederPagina() { - if ($scope.currentPage > 1) { - $scope.selectPage($scope.currentPage - 1); - $scope.selectedProducto = $scope.numPerPage - 1; - } - } - - function avanzarPagina() { - if ($scope.currentPage < $scope.lastPage) { - $scope.selectPage($scope.currentPage + 1); - $scope.selectedProducto = 0; - } - } - }] - ) + .controller('modalVendedoresCtrl', [ + '$filter', + '$scope', + '$uibModalInstance', + 'focaVendedoresService', + function($filter, $scope, $uibModalInstance, focaVendedoresService) { + focaVendedoresService.getVendedores().then( + function(res) { + $scope.vendedores = res.data; + $scope.search(); + } + ); + + // pagination + $scope.numPerPage = 10; + $scope.currentPage = 1; + $scope.filteredVendedores = []; + $scope.currentPageVendedores = []; + $scope.selectedVendedor = -1; + + $scope.search = function() { + $scope.filteredVendedores = $filter('filter')( + $scope.vendedores, { $: $scope.filters } + ); + + $scope.lastPage = Math.ceil( + $scope.filteredVendedores.length / $scope.numPerPage + ); + + $scope.resetPage(); + }; + + $scope.resetPage = function() { + $scope.currentPage = 1; + $scope.selectPage(1); + }; + + $scope.selectPage = function(page) { + var start = (page - 1) * $scope.numPerPage; + var end = start + $scope.numPerPage; + $scope.paginas = []; + $scope.paginas = calcularPages(page); + $scope.currentPageVendedores = $scope.filteredVendedores.slice(start, end); + $scope.currentPage = page; + }; + + $scope.select = function(vendedor) { + $uibModalInstance.close(vendedor); + }; + + $scope.cancel = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.busquedaDown = function(key) { + if (key === 40) { + primera(key); + } + }; + + $scope.busquedaPress = function(key) { + if (key === 13) { + primera(key); + } + }; + + $scope.itemVendedor = function(key) { + if (key === 38) { + anterior(key); + } + + if (key === 40) { + siguiente(key); + } + + if (key === 37) { + retrocederPagina(); + } + + if (key === 39) { + avanzarPagina(); + } + }; + + function calcularPages(paginaActual) { + var paginas = []; + paginas.push(paginaActual); + + if (paginaActual - 1 > 1) { + + paginas.unshift(paginaActual - 1); + if (paginaActual - 2 > 1) { + paginas.unshift(paginaActual - 2); + } + } + + if (paginaActual + 1 < $scope.lastPage) { + paginas.push(paginaActual + 1); + if (paginaActual + 2 < $scope.lastPage) { + paginas.push(paginaActual + 2); + } + } + + if (paginaActual !== 1) { + paginas.unshift(1); + } + + if (paginaActual !== $scope.lastPage) { + paginas.push($scope.lastPage); + } + + return paginas; + } + + function primera() { + $scope.selectedVendedor = 0; + } + + function anterior() { + if ($scope.selectedVendedor === 0 && $scope.currentPage > 1) { + retrocederPagina(); + } else { + $scope.selectedVendedor--; + } + } + + function siguiente() { + if ($scope.selectedVendedor < $scope.currentPageVendedores.length - 1) { + $scope.selectedVendedor++; + } else { + avanzarPagina(); + } + } + + function retrocederPagina() { + if ($scope.currentPage > 1) { + $scope.selectPage($scope.currentPage - 1); + $scope.selectedVendedor = $scope.numPerPage - 1; + } + } + + function avanzarPagina() { + if ($scope.currentPage < $scope.lastPage) { + $scope.selectPage($scope.currentPage + 1); + $scope.selectedVendedor = 0; + } + } + }] + ); diff --git a/src/js/service.js b/src/js/service.js index 8326cd4..790f1ad 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -1,9 +1,9 @@ angular.module('focaModalVendedores') - .service('focaVendedoresService', ['$http', function($http) { - var configRoute ='http://localhost:9900'; + .service('focaVendedoresService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { return { - getVendedores: function(json) { - return $http.post(configRoute + '/vendedores', json); + getVendedores: function() { + // TODO ACOMODAR PARA TURNOS AHORA 1 HARDCODEO + return $http.get(API_ENDPOINT.URL + '/vendedores/1'); } - } - }]) + }; + }]); diff --git a/src/views/modal-vendedores.html b/src/views/modal-vendedores.html index 49106b4..2e9609b 100644 --- a/src/views/modal-vendedores.html +++ b/src/views/modal-vendedores.html @@ -3,30 +3,40 @@