diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bf9275c --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/dist +/tmp +package-lock\.json + +src/etc/develop\.js diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..d8cbb07 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,64 @@ +{ + /* + * ENVIRONMENTS + * ================= + */ + + // Define globals exposed by modern browsers. + "browser": true, + + // Define globals exposed by jQuery. + "jquery": true, + + // Define globals exposed by Node.js. + "node": true, + + // Allow ES6. + "esversion": 6, + + /* + * ENFORCING OPTIONS + * ================= + */ + + // Force all variable names to use either camelCase style or UPPER_CASE + // with underscores. + "camelcase": true, + + // Prohibit use of == and != in favor of === and !==. + "eqeqeq": true, + + // Enforce tab width of 2 spaces. + "indent": 4, + + // Prohibit use of a variable before it is defined. + "latedef": false, + + // Enforce line length to 100 characters + "maxlen": 100, + + // Require capitalized names for constructor functions. + "newcap": true, + + // Enforce use of single quotation marks for strings. + "quotmark": "single", + + // Enforce placing 'use strict' at the top function scope + "strict": false, + + // Prohibit use of explicitly undeclared variables. + "undef": true, + + // Warn when variables are defined but never used. + "unused": true, + + // Para que funcione en angular + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], + /* + * RELAXING OPTIONS + * ================= + */ + + // Suppress warnings about == null comparisons. + "eqnull": true +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..5abec8d --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +Busqueda de Nota de Remito +========================== diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..932b79a --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,91 @@ +const templateCache = require('gulp-angular-templatecache'); +const concat = require('gulp-concat'); +const htmlmin = require('gulp-htmlmin'); +const rename = require('gulp-rename'); +const uglify = require('gulp-uglify'); +const gulp = require('gulp'); +const pump = require('pump'); +const jshint = require('gulp-jshint'); +const replace = require('gulp-replace'); +const connect = require('gulp-connect'); +const clean = require('gulp-clean'); + +var paths = { + srcJS: 'src/js/*.js', + srcViews: 'src/views/*.html', + tmp: 'tmp', + dist: 'dist/' +}; + +gulp.task('clean', function() { + return gulp.src(['tmp', 'dist'], {read: false}) + .pipe(clean()); +}); + +gulp.task('templates', ['clean'], function() { + return pump( + [ + gulp.src(paths.srcViews), + htmlmin(), + templateCache('views.js', { + module: 'focaModalRemito', + root: '' + }), + gulp.dest(paths.tmp) + ] + ); +}); + +gulp.task('uglify', ['templates'], function() { + return pump( + [ + gulp.src([ + paths.srcJS, + 'tmp/views.js' + ]), + concat('foca-modal-remito.js'), + replace('src/views/', ''), + replace("['ui.bootstrap', 'focaDirectivas', 'angular-ladda']", '[]'), + gulp.dest(paths.tmp), + rename('foca-modal-remito.min.js'), + uglify(), + gulp.dest(paths.dist) + ] + ); +}); + +gulp.task('pre-commit', function() { + return pump( + [ + gulp.src(paths.srcJS), + jshint('.jshintrc'), + jshint.reporter('default'), + jshint.reporter('fail') + ] + ); + + gulp.start('uglify'); +}); + +gulp.task('webserver', function() { + pump [ + connect.server({port: 3000}) + ] +}); + +gulp.task('clean-post-install', function(){ + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', + 'index.html'], {read: false}) + .pipe(clean()); +}); + +gulp.task('default', ['webserver']); + +gulp.task('watch', function() { + gulp.watch([paths.srcJS, paths.srcViews], ['copy']) +}); + +gulp.task('copy', ['uglify'], function(){ + gulp.src('dist/*.js') + .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-modal-remito/dist')); +}); diff --git a/index.html b/index.html new file mode 100644 index 0000000..cb3fffb --- /dev/null +++ b/index.html @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..aad1c5e --- /dev/null +++ b/package.json @@ -0,0 +1,62 @@ +{ + "name": "foca-modal-remito", + "version": "0.0.1", + "description": "Modal para seleccion de remitos", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "gulp-pre-commit": "gulp pre-commit", + "compile": "gulp uglify", + "postinstall": "npm run compile && gulp clean-post-install", + "install-dev": "npm install -D angular angular-ladda ladda@1.0.6 bootstrap font-awesome gulp gulp-angular-templatecache gulp-concat gulp-connect gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify gulp-clean jasmine-core jquery jshint pre-commit pump ui-bootstrap4 && npm i -D git+https://debo.suite.repo/modulos-npm/foca-directivas" + }, + "pre-commit": [ + "gulp-pre-commit" + ], + "repository": { + "type": "git", + "url": "https://debo.suite.repo/modulos-npm/foca-modal-remito" + }, + "author": "Nicolás Guarnieri", + "license": "ISC", + "peerDependencies": { + "angular": "^1.7.4", + "bootstrap": "^4.1.3", + "font-awesome": "^4.7.0", + "ui-bootstrap4": "^3.0.4", + "gulp": "^3.9.1", + "gulp-angular-templatecache": "^2.2.1", + "gulp-concat": "^2.6.1", + "gulp-connect": "^5.6.1", + "gulp-htmlmin": "^5.0.1", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-uglify": "^3.0.1", + "jquery": "^3.3.1", + "pump": "^3.0.0", + "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas" + }, + "devDependencies": { + "angular": "^1.7.5", + "angular-ladda": "^0.4.3", + "bootstrap": "^4.1.3", + "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas", + "font-awesome": "^4.7.0", + "gulp": "^3.9.1", + "gulp-angular-templatecache": "^2.2.3", + "gulp-clean": "^0.4.0", + "gulp-concat": "^2.6.1", + "gulp-connect": "^5.6.1", + "gulp-htmlmin": "^5.0.1", + "gulp-jshint": "^2.1.0", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-uglify": "^3.0.1", + "jasmine-core": "^3.3.0", + "jquery": "^3.3.1", + "jshint": "^2.9.6", + "ladda": "1.0.6", + "pre-commit": "^1.2.2", + "pump": "^3.0.0", + "ui-bootstrap4": "^3.0.5" + } +} diff --git a/src/etc/develop.js.ejemplo b/src/etc/develop.js.ejemplo new file mode 100644 index 0000000..2c35ddf --- /dev/null +++ b/src/etc/develop.js.ejemplo @@ -0,0 +1,4 @@ +angular.module('focaModalRemito') + .constant("API_ENDPOINT", { + 'URL': '//127.0.0.1:9000' + }); diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..fe351fb --- /dev/null +++ b/src/js/app.js @@ -0,0 +1 @@ +angular.module('focaModalRemito', ['ui.bootstrap', 'focaDirectivas', 'angular-ladda']); diff --git a/src/js/controller.js b/src/js/controller.js new file mode 100644 index 0000000..f293f2d --- /dev/null +++ b/src/js/controller.js @@ -0,0 +1,175 @@ +angular.module('focaModalRemito') + .controller('focaModalRemitoController', + [ + '$filter', + '$scope', + '$uibModalInstance', + 'parametroRemito', + 'focaModalRemitoService', + function($filter, $scope, $uibModalInstance, parametroRemito, + focaModalRemitoService + ) { + + $scope.simbolo = parametroRemito.simbolo; + $scope.filters = ''; + $scope.remitos = []; + $scope.primerBusqueda = false; + $scope.searchLoading = false; + // pagination + $scope.numPerPage = 10; + $scope.currentPage = 1; + $scope.filteredRemitos = []; + $scope.currentPageRemitos = []; + $scope.selectedRemito = -1; + + //METODOS + $scope.busquedaPress = function(key) { + if (key === 13) { + $scope.searchLoading = true; + if(parametroRemito.idLista > 0) { + focaModalRemitoService + .getRemitosByIdLista(parametroRemito.idLista, $scope.filters) + .then(llenarDatos); + } else if(parametroRemito.idLista === -1) { + focaModalRemitoService.getRemitos() + .then(llenarDatos); + } + } + }; + function llenarDatos(res) { + for(var i = 0; i < res.data.length; i++) { + res.data[i].precio = res.data[i].precio / parametroRemito.cotizacion; + } + $scope.searchLoading = false; + $scope.primerBusqueda = true; + $scope.remitos = res.data; + $scope.search(); + primera(); + } + $scope.search = function() { + if($scope.remitos.length > 0) { + $scope.filteredRemitos = $filter('filter')( + $scope.remitos, + {$: $scope.filters} + ); + + $scope.lastPage = Math.ceil( + $scope.filteredRemitos.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.currentPageRemitos = $scope.filteredRemitos.slice(start, end); + $scope.currentPage = page; + }; + + $scope.select = function(remito) { + $uibModalInstance.close(remito); + }; + + $scope.cancel = function() { + $uibModalInstance.dismiss('cancel'); + }; + + $scope.busquedaDown = function(key) { + if (key === 40) { + primera(key); + } + }; + + $scope.itemRemito = 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.selectedRemito = 0; + } + + function anterior() { + if ($scope.selectedRemito === 0 && $scope.currentPage > 1) { + retrocederPagina(); + } else { + $scope.selectedRemito--; + } + } + + function siguiente() { + if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1 ) { + $scope.selectedRemito++; + } else { + avanzarPagina(); + } + } + + function retrocederPagina() { + if ($scope.currentPage > 1) { + $scope.selectPage($scope.currentPage - 1); + $scope.selectedRemito = $scope.numPerPage - 1; + } + } + + function avanzarPagina() { + if ($scope.currentPage < $scope.lastPage) { + $scope.selectPage($scope.currentPage + 1); + $scope.selectedRemito = 0; + } + } + } + ] + ); diff --git a/src/js/service.js b/src/js/service.js new file mode 100644 index 0000000..9059593 --- /dev/null +++ b/src/js/service.js @@ -0,0 +1,16 @@ +angular.module('focaModalRemito') + .service('focaModalRemitoService', [ + '$http', + 'API_ENDPOINT', + function($http, API_ENDPOINT) { + return { + getRemitos: function() { + return $http.get(API_ENDPOINT.URL + '/articulos'); + }, + getRemitosByIdLista: function(id, filters) { + return $http.post(API_ENDPOINT.URL + '/articulos/lista', + {filters: filters, id: id}); + } + }; + } + ]); diff --git a/src/views/foca-modal-remito.html b/src/views/foca-modal-remito.html new file mode 100644 index 0000000..3d4b235 --- /dev/null +++ b/src/views/foca-modal-remito.html @@ -0,0 +1,100 @@ + + +