Commit 2b4e6d8ee9383206784385866f627814c6f4f200

Authored by Pablo Marco del Pont
0 parents
Exists in master

Primera versión estable.

... ... @@ -0,0 +1,6 @@
  1 +/node_modules
  2 +/dist
  3 +/tmp
  4 +package-lock\.json
  5 +
  6 +src/etc/develop\.js
... ... @@ -0,0 +1,64 @@
  1 +{
  2 + /*
  3 + * ENVIRONMENTS
  4 + * =================
  5 + */
  6 +
  7 + // Define globals exposed by modern browsers.
  8 + "browser": true,
  9 +
  10 + // Define globals exposed by jQuery.
  11 + "jquery": true,
  12 +
  13 + // Define globals exposed by Node.js.
  14 + "node": true,
  15 +
  16 + // Allow ES6.
  17 + "esversion": 6,
  18 +
  19 + /*
  20 + * ENFORCING OPTIONS
  21 + * =================
  22 + */
  23 +
  24 + // Force all variable names to use either camelCase style or UPPER_CASE
  25 + // with underscores.
  26 + "camelcase": true,
  27 +
  28 + // Prohibit use of == and != in favor of === and !==.
  29 + "eqeqeq": true,
  30 +
  31 + // Enforce tab width of 2 spaces.
  32 + "indent": 4,
  33 +
  34 + // Prohibit use of a variable before it is defined.
  35 + "latedef": false,
  36 +
  37 + // Enforce line length to 100 characters
  38 + "maxlen": 100,
  39 +
  40 + // Require capitalized names for constructor functions.
  41 + "newcap": true,
  42 +
  43 + // Enforce use of single quotation marks for strings.
  44 + "quotmark": "single",
  45 +
  46 + // Enforce placing 'use strict' at the top function scope
  47 + "strict": false,
  48 +
  49 + // Prohibit use of explicitly undeclared variables.
  50 + "undef": true,
  51 +
  52 + // Warn when variables are defined but never used.
  53 + "unused": true,
  54 +
  55 + // Para que funcione en angular
  56 + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"],
  57 + /*
  58 + * RELAXING OPTIONS
  59 + * =================
  60 + */
  61 +
  62 + // Suppress warnings about == null comparisons.
  63 + "eqnull": true
  64 +}
... ... @@ -0,0 +1,2 @@
  1 +Busqueda de Nota de Remito
  2 +==========================
... ... @@ -0,0 +1,91 @@
  1 +const templateCache = require('gulp-angular-templatecache');
  2 +const concat = require('gulp-concat');
  3 +const htmlmin = require('gulp-htmlmin');
  4 +const rename = require('gulp-rename');
  5 +const uglify = require('gulp-uglify');
  6 +const gulp = require('gulp');
  7 +const pump = require('pump');
  8 +const jshint = require('gulp-jshint');
  9 +const replace = require('gulp-replace');
  10 +const connect = require('gulp-connect');
  11 +const clean = require('gulp-clean');
  12 +
  13 +var paths = {
  14 + srcJS: 'src/js/*.js',
  15 + srcViews: 'src/views/*.html',
  16 + tmp: 'tmp',
  17 + dist: 'dist/'
  18 +};
  19 +
  20 +gulp.task('clean', function() {
  21 + return gulp.src(['tmp', 'dist'], {read: false})
  22 + .pipe(clean());
  23 +});
  24 +
  25 +gulp.task('templates', ['clean'], function() {
  26 + return pump(
  27 + [
  28 + gulp.src(paths.srcViews),
  29 + htmlmin(),
  30 + templateCache('views.js', {
  31 + module: 'focaModalRemito',
  32 + root: ''
  33 + }),
  34 + gulp.dest(paths.tmp)
  35 + ]
  36 + );
  37 +});
  38 +
  39 +gulp.task('uglify', ['templates'], function() {
  40 + return pump(
  41 + [
  42 + gulp.src([
  43 + paths.srcJS,
  44 + 'tmp/views.js'
  45 + ]),
  46 + concat('foca-modal-remito.js'),
  47 + replace('src/views/', ''),
  48 + replace("['ui.bootstrap', 'focaDirectivas', 'angular-ladda']", '[]'),
  49 + gulp.dest(paths.tmp),
  50 + rename('foca-modal-remito.min.js'),
  51 + uglify(),
  52 + gulp.dest(paths.dist)
  53 + ]
  54 + );
  55 +});
  56 +
  57 +gulp.task('pre-commit', function() {
  58 + return pump(
  59 + [
  60 + gulp.src(paths.srcJS),
  61 + jshint('.jshintrc'),
  62 + jshint.reporter('default'),
  63 + jshint.reporter('fail')
  64 + ]
  65 + );
  66 +
  67 + gulp.start('uglify');
  68 +});
  69 +
  70 +gulp.task('webserver', function() {
  71 + pump [
  72 + connect.server({port: 3000})
  73 + ]
  74 +});
  75 +
  76 +gulp.task('clean-post-install', function(){
  77 + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
  78 + 'index.html'], {read: false})
  79 + .pipe(clean());
  80 +});
  81 +
  82 +gulp.task('default', ['webserver']);
  83 +
  84 +gulp.task('watch', function() {
  85 + gulp.watch([paths.srcJS, paths.srcViews], ['copy'])
  86 +});
  87 +
  88 +gulp.task('copy', ['uglify'], function(){
  89 + gulp.src('dist/*.js')
  90 + .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-modal-remito/dist'));
  91 +});
... ... @@ -0,0 +1,72 @@
  1 +<html ng-app="focaModalRemito">
  2 + <head>
  3 + <meta charset="UTF-8"/>
  4 + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  5 +
  6 + <!--CSS-->
  7 + <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"/>
  8 + <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
  9 + <link href="node_modules/ladda/dist/ladda-themeless.min.css" rel="stylesheet">
  10 +
  11 + <!--VENDOR JS-->
  12 + <script src="node_modules/jquery/dist/jquery.min.js"></script>
  13 + <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
  14 + <script src="node_modules/angular/angular.min.js"></script>
  15 + <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script>
  16 + <script src="node_modules/foca-directivas/dist/foca-directivas.min.js"></script>
  17 + <script src="node_modules/ladda/dist/spin.min.js"></script>
  18 + <script src="node_modules/ladda/dist/ladda.min.js"></script>
  19 + <script src="node_modules/angular-ladda/dist/angular-ladda.min.js"></script>
  20 +
  21 + <!-- BUILD -->
  22 + <script src="src/js/app.js"></script>
  23 + <script src="src/js/controller.js"></script>
  24 + <script src="src/js/service.js"></script>
  25 +
  26 + <!-- /BUILD -->
  27 +
  28 + <!-- CONFIG PARA DEVELOP -->
  29 + <script src="src/etc/develop.js"></script>
  30 + <script type="text/javascript">
  31 + angular.module('focaModalRemito')
  32 + .controller('controller', [
  33 + '$scope',
  34 + '$uibModal',
  35 + '$timeout',
  36 + function($scope, $uibModal, $timeout) {
  37 + openModal();
  38 +
  39 + function openModal() {
  40 + var modalInstance = $uibModal.open(
  41 + {
  42 + ariaLabelledBy: 'Busqueda de Remito',
  43 + templateUrl: 'src/views/foca-modal-remito.html',
  44 + controller: 'focaModalRemitoController',
  45 + size: 'lg',
  46 + resolve: {
  47 + parametroRemito: {
  48 + idLista: -1,
  49 + cotizacion: 1,
  50 + simbolo:'$'
  51 + }
  52 + }
  53 + }
  54 + );
  55 +
  56 + modalInstance.result.then(
  57 + function (selectedItem) {
  58 + console.info(selectedItem);
  59 + $timeout(openModal, 500);
  60 + }, function () {
  61 + console.info('modal-component dismissed at: ' + new Date());
  62 + $timeout(openModal, 500);
  63 + }
  64 + );
  65 + }
  66 + }
  67 + ]);
  68 + </script>
  69 + </head>
  70 + <body ng-controller="controller">
  71 + </body>
  72 +</html>
... ... @@ -0,0 +1,62 @@
  1 +{
  2 + "name": "foca-modal-remito",
  3 + "version": "0.0.1",
  4 + "description": "Modal para seleccion de remitos",
  5 + "scripts": {
  6 + "test": "echo \"Error: no test specified\" && exit 1",
  7 + "gulp-pre-commit": "gulp pre-commit",
  8 + "compile": "gulp uglify",
  9 + "postinstall": "npm run compile && gulp clean-post-install",
  10 + "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"
  11 + },
  12 + "pre-commit": [
  13 + "gulp-pre-commit"
  14 + ],
  15 + "repository": {
  16 + "type": "git",
  17 + "url": "https://debo.suite.repo/modulos-npm/foca-modal-remito"
  18 + },
  19 + "author": "Nicolás Guarnieri",
  20 + "license": "ISC",
  21 + "peerDependencies": {
  22 + "angular": "^1.7.4",
  23 + "bootstrap": "^4.1.3",
  24 + "font-awesome": "^4.7.0",
  25 + "ui-bootstrap4": "^3.0.4",
  26 + "gulp": "^3.9.1",
  27 + "gulp-angular-templatecache": "^2.2.1",
  28 + "gulp-concat": "^2.6.1",
  29 + "gulp-connect": "^5.6.1",
  30 + "gulp-htmlmin": "^5.0.1",
  31 + "gulp-rename": "^1.4.0",
  32 + "gulp-replace": "^1.0.0",
  33 + "gulp-uglify": "^3.0.1",
  34 + "jquery": "^3.3.1",
  35 + "pump": "^3.0.0",
  36 + "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas"
  37 + },
  38 + "devDependencies": {
  39 + "angular": "^1.7.5",
  40 + "angular-ladda": "^0.4.3",
  41 + "bootstrap": "^4.1.3",
  42 + "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas",
  43 + "font-awesome": "^4.7.0",
  44 + "gulp": "^3.9.1",
  45 + "gulp-angular-templatecache": "^2.2.3",
  46 + "gulp-clean": "^0.4.0",
  47 + "gulp-concat": "^2.6.1",
  48 + "gulp-connect": "^5.6.1",
  49 + "gulp-htmlmin": "^5.0.1",
  50 + "gulp-jshint": "^2.1.0",
  51 + "gulp-rename": "^1.4.0",
  52 + "gulp-replace": "^1.0.0",
  53 + "gulp-uglify": "^3.0.1",
  54 + "jasmine-core": "^3.3.0",
  55 + "jquery": "^3.3.1",
  56 + "jshint": "^2.9.6",
  57 + "ladda": "1.0.6",
  58 + "pre-commit": "^1.2.2",
  59 + "pump": "^3.0.0",
  60 + "ui-bootstrap4": "^3.0.5"
  61 + }
  62 +}
src/etc/develop.js.ejemplo
... ... @@ -0,0 +1,4 @@
  1 +angular.module('focaModalRemito')
  2 + .constant("API_ENDPOINT", {
  3 + 'URL': '//127.0.0.1:9000'
  4 + });
... ... @@ -0,0 +1 @@
  1 +angular.module('focaModalRemito', ['ui.bootstrap', 'focaDirectivas', 'angular-ladda']);
src/js/controller.js
... ... @@ -0,0 +1,175 @@
  1 +angular.module('focaModalRemito')
  2 + .controller('focaModalRemitoController',
  3 + [
  4 + '$filter',
  5 + '$scope',
  6 + '$uibModalInstance',
  7 + 'parametroRemito',
  8 + 'focaModalRemitoService',
  9 + function($filter, $scope, $uibModalInstance, parametroRemito,
  10 + focaModalRemitoService
  11 + ) {
  12 +
  13 + $scope.simbolo = parametroRemito.simbolo;
  14 + $scope.filters = '';
  15 + $scope.remitos = [];
  16 + $scope.primerBusqueda = false;
  17 + $scope.searchLoading = false;
  18 + // pagination
  19 + $scope.numPerPage = 10;
  20 + $scope.currentPage = 1;
  21 + $scope.filteredRemitos = [];
  22 + $scope.currentPageRemitos = [];
  23 + $scope.selectedRemito = -1;
  24 +
  25 + //METODOS
  26 + $scope.busquedaPress = function(key) {
  27 + if (key === 13) {
  28 + $scope.searchLoading = true;
  29 + if(parametroRemito.idLista > 0) {
  30 + focaModalRemitoService
  31 + .getRemitosByIdLista(parametroRemito.idLista, $scope.filters)
  32 + .then(llenarDatos);
  33 + } else if(parametroRemito.idLista === -1) {
  34 + focaModalRemitoService.getRemitos()
  35 + .then(llenarDatos);
  36 + }
  37 + }
  38 + };
  39 + function llenarDatos(res) {
  40 + for(var i = 0; i < res.data.length; i++) {
  41 + res.data[i].precio = res.data[i].precio / parametroRemito.cotizacion;
  42 + }
  43 + $scope.searchLoading = false;
  44 + $scope.primerBusqueda = true;
  45 + $scope.remitos = res.data;
  46 + $scope.search();
  47 + primera();
  48 + }
  49 + $scope.search = function() {
  50 + if($scope.remitos.length > 0) {
  51 + $scope.filteredRemitos = $filter('filter')(
  52 + $scope.remitos,
  53 + {$: $scope.filters}
  54 + );
  55 +
  56 + $scope.lastPage = Math.ceil(
  57 + $scope.filteredRemitos.length / $scope.numPerPage
  58 + );
  59 +
  60 + $scope.resetPage();
  61 + }
  62 + };
  63 +
  64 + $scope.resetPage = function() {
  65 + $scope.currentPage = 1;
  66 + $scope.selectPage(1);
  67 + };
  68 +
  69 + $scope.selectPage = function(page) {
  70 + var start = (page - 1) * $scope.numPerPage;
  71 + var end = start + $scope.numPerPage;
  72 + $scope.paginas = [];
  73 + $scope.paginas = calcularPages(page);
  74 + $scope.currentPageRemitos = $scope.filteredRemitos.slice(start, end);
  75 + $scope.currentPage = page;
  76 + };
  77 +
  78 + $scope.select = function(remito) {
  79 + $uibModalInstance.close(remito);
  80 + };
  81 +
  82 + $scope.cancel = function() {
  83 + $uibModalInstance.dismiss('cancel');
  84 + };
  85 +
  86 + $scope.busquedaDown = function(key) {
  87 + if (key === 40) {
  88 + primera(key);
  89 + }
  90 + };
  91 +
  92 + $scope.itemRemito = function(key) {
  93 + if (key === 38) {
  94 + anterior(key);
  95 + }
  96 +
  97 + if (key === 40) {
  98 + siguiente(key);
  99 + }
  100 +
  101 + if (key === 37) {
  102 + retrocederPagina();
  103 + }
  104 +
  105 + if (key === 39) {
  106 + avanzarPagina();
  107 + }
  108 + };
  109 +
  110 + function calcularPages(paginaActual) {
  111 + var paginas = [];
  112 + paginas.push(paginaActual);
  113 +
  114 + if (paginaActual - 1 > 1) {
  115 +
  116 + paginas.unshift(paginaActual - 1);
  117 + if (paginaActual - 2 > 1) {
  118 + paginas.unshift(paginaActual - 2);
  119 + }
  120 + }
  121 +
  122 + if (paginaActual + 1 < $scope.lastPage) {
  123 + paginas.push(paginaActual + 1);
  124 + if (paginaActual + 2 < $scope.lastPage) {
  125 + paginas.push(paginaActual + 2);
  126 + }
  127 + }
  128 +
  129 + if (paginaActual !== 1) {
  130 + paginas.unshift(1);
  131 + }
  132 +
  133 + if (paginaActual !== $scope.lastPage) {
  134 + paginas.push($scope.lastPage);
  135 + }
  136 +
  137 + return paginas;
  138 + }
  139 +
  140 + function primera() {
  141 + $scope.selectedRemito = 0;
  142 + }
  143 +
  144 + function anterior() {
  145 + if ($scope.selectedRemito === 0 && $scope.currentPage > 1) {
  146 + retrocederPagina();
  147 + } else {
  148 + $scope.selectedRemito--;
  149 + }
  150 + }
  151 +
  152 + function siguiente() {
  153 + if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1 ) {
  154 + $scope.selectedRemito++;
  155 + } else {
  156 + avanzarPagina();
  157 + }
  158 + }
  159 +
  160 + function retrocederPagina() {
  161 + if ($scope.currentPage > 1) {
  162 + $scope.selectPage($scope.currentPage - 1);
  163 + $scope.selectedRemito = $scope.numPerPage - 1;
  164 + }
  165 + }
  166 +
  167 + function avanzarPagina() {
  168 + if ($scope.currentPage < $scope.lastPage) {
  169 + $scope.selectPage($scope.currentPage + 1);
  170 + $scope.selectedRemito = 0;
  171 + }
  172 + }
  173 + }
  174 + ]
  175 + );
... ... @@ -0,0 +1,16 @@
  1 +angular.module('focaModalRemito')
  2 + .service('focaModalRemitoService', [
  3 + '$http',
  4 + 'API_ENDPOINT',
  5 + function($http, API_ENDPOINT) {
  6 + return {
  7 + getRemitos: function() {
  8 + return $http.get(API_ENDPOINT.URL + '/articulos');
  9 + },
  10 + getRemitosByIdLista: function(id, filters) {
  11 + return $http.post(API_ENDPOINT.URL + '/articulos/lista',
  12 + {filters: filters, id: id});
  13 + }
  14 + };
  15 + }
  16 + ]);
src/views/foca-modal-remito.html
... ... @@ -0,0 +1,100 @@
  1 +<div class="modal-header py-1">
  2 + <h5 class="modal-title">Busqueda de Remito</h5>
  3 +</div>
  4 +<div class="modal-body" id="modal-body">
  5 + <div class="input-group">
  6 + <input
  7 + ladda="searchLoading"
  8 + type="text"
  9 + class="form-control"
  10 + placeholder="Busqueda"
  11 + ng-model="filters"
  12 + ng-change="search()"
  13 + ng-keydown="busquedaDown($event.keyCode)"
  14 + ng-keypress="busquedaPress($event.keyCode)"
  15 + foca-focus="selectedRemito == -1"
  16 + ng-focus="selectedRemito = -1"
  17 + >
  18 + <div class="input-group-append">
  19 + <button
  20 + ladda="searchLoading"
  21 + class="btn btn-outline-secondary"
  22 + type="button"
  23 + ng-click="busquedaPress(13)"
  24 + >
  25 + <i class="fa fa-search" aria-hidden="true"></i>
  26 + </button>
  27 + </div>
  28 + </div>
  29 + <table ng-show="primerBusqueda" class="table table-striped table-sm">
  30 + <thead>
  31 + <tr>
  32 + <th>Sec.</th>
  33 + <th>Cod.</th>
  34 + <th>Descripción</th>
  35 + <th>P. Base</th>
  36 + <th></th>
  37 + </tr>
  38 + </thead>
  39 + <tbody>
  40 + <tr ng-show="currentPageRemitos.length == 0 && primerBusqueda">
  41 + <td colspan="5">
  42 + No se encontraron resultados.
  43 + </td>
  44 + </tr>
  45 + <tr class="selectable"
  46 + ng-repeat="(key,remito) in currentPageRemitos"
  47 + ng-click="select(remito)">
  48 + <td ng-bind="remito.sector"></td>
  49 + <td ng-bind="remito.codigo"></td>
  50 + <td ng-bind="remito.descripcion"></td>
  51 + <td ng-bind="remito.precio | currency: simbolo : 4"></td>
  52 + <td>
  53 + <button
  54 + type="button"
  55 + class="btn btn-xs p-1 float-right"
  56 + ng-class="{
  57 + 'btn-secondary': selectedRemito != key,
  58 + 'btn-primary': selectedRemito == key
  59 + }"
  60 + foca-focus="selectedRemito == {{key}}"
  61 + ng-keydown="itemRemito($event.keyCode)"
  62 + >
  63 + <i class="fa fa-arrow-right" aria-hidden="true"></i>
  64 + </button>
  65 + </td>
  66 + </tr>
  67 + </tbody>
  68 + </table>
  69 + <nav ng-show="currentPageRemitos.length > 0 && primerBusqueda">
  70 + <ul class="pagination pagination-sm justify-content mb-0">
  71 + <li class="page-item" ng-class="{'disabled': currentPage == 1}">
  72 + <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)">
  73 + <span aria-hidden="true">&laquo;</span>
  74 + <span class="sr-only">Anterior</span>
  75 + </a>
  76 + </li>
  77 + <li
  78 + class="page-item"
  79 + ng-repeat="pagina in paginas"
  80 + ng-class="{'active': pagina == currentPage}"
  81 + >
  82 + <a
  83 + class="page-link"
  84 + href="#"
  85 + ng-click="selectPage(pagina)"
  86 + ng-bind="pagina"
  87 + ></a>
  88 + </li>
  89 + <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
  90 + <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)">
  91 + <span aria-hidden="true">&raquo;</span>
  92 + <span class="sr-only">Siguiente</span>
  93 + </a>
  94 + </li>
  95 + </ul>
  96 + </nav>
  97 +</div>
  98 +<div class="modal-footer py-1">
  99 + <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button>
  100 +</div>