Commit e5e74aaba46ef4129a5fe9d8ed84f1fa863436c1
0 parents
Exists in
master
Primera versión estable.
Showing
11 changed files
with
505 additions
and
0 deletions
Show diff stats
.gitignore
File was created | 1 | /node_modules | |
2 | /dist | ||
3 | /tmp | ||
4 | package-lock\.json | ||
5 | src/etc/develop\.js | ||
6 |
.jshintrc
File was created | 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 | } | ||
65 |
README.md
File was created | 1 | # foca-modal-moneda | |
2 | |||
3 | Modal con lista de monedas |
gulpfile.js
File was created | 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('templates', function() { | ||
21 | return pump( | ||
22 | [ | ||
23 | gulp.src(paths.srcViews), | ||
24 | htmlmin(), | ||
25 | templateCache('views.js', { | ||
26 | module: 'focaModalMoneda', | ||
27 | root: '' | ||
28 | }), | ||
29 | gulp.dest(paths.tmp) | ||
30 | ] | ||
31 | ); | ||
32 | }); | ||
33 | |||
34 | gulp.task('uglify', ['templates'], function() { | ||
35 | return pump( | ||
36 | [ | ||
37 | gulp.src([ | ||
38 | paths.srcJS, | ||
39 | 'tmp/views.js' | ||
40 | ]), | ||
41 | concat('foca-modal-moneda.js'), | ||
42 | replace('src/views/', ''), | ||
43 | replace("['ui.bootstrap', 'focaDirectivas']", '[]'), | ||
44 | gulp.dest(paths.tmp), | ||
45 | rename('foca-modal-moneda.min.js'), | ||
46 | uglify(), | ||
47 | gulp.dest(paths.dist) | ||
48 | ] | ||
49 | ); | ||
50 | }); | ||
51 | |||
52 | gulp.task('pre-commit', function() { | ||
53 | return pump( | ||
54 | [ | ||
55 | gulp.src(paths.srcJS), | ||
56 | jshint('.jshintrc'), | ||
57 | jshint.reporter('default'), | ||
58 | jshint.reporter('fail') | ||
59 | ] | ||
60 | ); | ||
61 | }); | ||
62 | |||
63 | gulp.task('webserver', function() { | ||
64 | pump [ | ||
65 | connect.server({port: 3000}) | ||
66 | ] | ||
67 | }); | ||
68 | |||
69 | gulp.task('clean-post-install', function(){ | ||
70 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | ||
71 | 'index.html'], {read: false}) | ||
72 | .pipe(clean()); | ||
73 | }); | ||
74 | |||
75 | gulp.task('default', ['webserver']); | ||
76 |
index.html
File was created | 1 | <html ng-app="focaModalMoneda"> | |
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 | |||
10 | <!--VENDOR JS--> | ||
11 | <script src="node_modules/jquery/dist/jquery.min.js"></script> | ||
12 | <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> | ||
13 | <script src="node_modules/angular/angular.min.js"></script> | ||
14 | <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script> | ||
15 | <script src="node_modules/foca-directivas/dist/foca-directivas.min.js"></script> | ||
16 | |||
17 | <!-- BUILD --> | ||
18 | <script src="src/js/app.js"></script> | ||
19 | <script src="src/js/controller.js"></script> | ||
20 | <script src="src/js/service.js"></script> | ||
21 | |||
22 | <!-- /BUILD --> | ||
23 | |||
24 | <!-- CONFIG PARA DEVELOP --> | ||
25 | <script src="src/etc/develop.js"></script> | ||
26 | <script type="text/javascript"> | ||
27 | angular.module('focaModalMoneda') | ||
28 | .controller('controller', [ | ||
29 | '$scope', | ||
30 | '$uibModal', | ||
31 | '$timeout', | ||
32 | function($scope, $uibModal, $timeout) { | ||
33 | openModal(); | ||
34 | |||
35 | function openModal() { | ||
36 | var modalInstance = $uibModal.open( | ||
37 | { | ||
38 | ariaLabelledBy: 'Busqueda de Precio Condicion', | ||
39 | templateUrl: 'src/views/modal-moneda.html', | ||
40 | controller: 'focaModalMonedaController', | ||
41 | size: 'lg' | ||
42 | } | ||
43 | ); | ||
44 | |||
45 | modalInstance.result.then( | ||
46 | function (selectedItem) { | ||
47 | console.info(selectedItem); | ||
48 | $timeout(openModal, 500); | ||
49 | }, function () { | ||
50 | console.info('modal-component dismissed at: ' + new Date()); | ||
51 | $timeout(openModal, 500); | ||
52 | } | ||
53 | ); | ||
54 | } | ||
55 | } | ||
56 | ]); | ||
57 | </script> | ||
58 | </head> | ||
59 | <body ng-controller="controller"> | ||
60 | </body> | ||
61 | </html> | ||
62 |
package.json
File was created | 1 | { | |
2 | "name": "foca-modal-moneda", | ||
3 | "version": "0.0.1", | ||
4 | "description": "Modal de búsqueda de monedas", | ||
5 | "main": "index.js", | ||
6 | "scripts": { | ||
7 | "test": "echo \"Error: no test specified\" && exit 1", | ||
8 | "gulp-pre-commit": "gulp pre-commit", | ||
9 | "compile": "gulp uglify", | ||
10 | "postinstall": "npm run compile && gulp clean-post-install", | ||
11 | "install-dev": "npm install -D angular font-awesome pump jquery bootstrap ui-bootstrap4 jshint gulp gulp-uglify gulp-concat gulp-htmlmin gulp-rename gulp-uglify gulp-jshint gulp-replace gulp-connect gulp-clean gulp-angular-templatecache git+https://debo.suite.repo/modulos-npm/foca-directivas.git" | ||
12 | }, | ||
13 | "pre-commit": [ | ||
14 | "gulp-pre-commit" | ||
15 | ], | ||
16 | "repository": { | ||
17 | "type": "git", | ||
18 | "url": "https://debo.suite.repo/modulos-npm/foca-modal-moneda.git" | ||
19 | }, | ||
20 | "author": "Foca Software", | ||
21 | "license": "ISC", | ||
22 | "devDependencies": { | ||
23 | "angular": "^1.7.5", | ||
24 | "bootstrap": "^4.1.3", | ||
25 | "foca-directivas": "git+https://debo.suite.repo/modulos-npm/foca-directivas.git", | ||
26 | "font-awesome": "^4.7.0", | ||
27 | "gulp": "^3.9.1", | ||
28 | "gulp-angular-templatecache": "^2.2.2", | ||
29 | "gulp-clean": "^0.4.0", | ||
30 | "gulp-concat": "^2.6.1", | ||
31 | "gulp-connect": "^5.6.1", | ||
32 | "gulp-htmlmin": "^5.0.1", | ||
33 | "gulp-jshint": "^2.1.0", | ||
34 | "gulp-rename": "^1.4.0", | ||
35 | "gulp-replace": "^1.0.0", | ||
36 | "gulp-uglify": "^3.0.1", | ||
37 | "jquery": "^3.3.1", | ||
38 | "jshint": "^2.9.6", | ||
39 | "pump": "^3.0.0", | ||
40 | "ui-bootstrap4": "^3.0.5" | ||
41 | } | ||
42 | } | ||
43 |
src/etc/develop.js.ejemplo
File was created | 1 | angular.module('focaModalMoneda') | |
2 | .constant("API_ENDPOINT", { | ||
3 | 'URL': '//127.0.0.1:9000' | ||
4 | }); | ||
5 |
src/js/app.js
File was created | 1 | angular.module('focaModalMoneda', ['ui.bootstrap', 'focaDirectivas']); | |
2 |
src/js/controller.js
File was created | 1 | angular.module('focaModalMoneda') | |
2 | .controller('focaModalMonedaController', | ||
3 | [ | ||
4 | '$filter', | ||
5 | '$scope', | ||
6 | '$uibModalInstance', | ||
7 | 'focaModalMonedaService', | ||
8 | function($filter, $scope, $uibModalInstance, focaModalMonedaService) { | ||
9 | focaModalMonedaService.getMonedas().then( | ||
10 | function(res) { | ||
11 | $scope.moneda = res.data; | ||
12 | $scope.search(); | ||
13 | } | ||
14 | ); | ||
15 | |||
16 | // pagination | ||
17 | $scope.numPerPage = 10; | ||
18 | $scope.currentPage = 1; | ||
19 | $scope.filteredMoneda = []; | ||
20 | $scope.currentPageMoneda = []; | ||
21 | $scope.selectedMoneda = -1; | ||
22 | |||
23 | //METODOS | ||
24 | $scope.search = function() { | ||
25 | $scope.filteredMoneda = $filter('filter')( | ||
26 | $scope.moneda, | ||
27 | {$: $scope.filters} | ||
28 | ); | ||
29 | |||
30 | $scope.lastPage = Math.ceil( | ||
31 | $scope.filteredMoneda.length / $scope.numPerPage | ||
32 | ); | ||
33 | |||
34 | $scope.resetPage(); | ||
35 | }; | ||
36 | |||
37 | $scope.resetPage = function() { | ||
38 | $scope.currentPage = 1; | ||
39 | $scope.selectPage(1); | ||
40 | }; | ||
41 | |||
42 | $scope.selectPage = function(page) { | ||
43 | var start = (page - 1) * $scope.numPerPage; | ||
44 | var end = start + $scope.numPerPage; | ||
45 | $scope.paginas = []; | ||
46 | $scope.paginas = calcularPages(page); | ||
47 | $scope.currentPageMoneda = | ||
48 | $scope.filteredMoneda.slice(start, end); | ||
49 | $scope.currentPage = page; | ||
50 | }; | ||
51 | |||
52 | $scope.select = function(moneda) { | ||
53 | $uibModalInstance.close(moneda); | ||
54 | }; | ||
55 | |||
56 | $scope.cancel = function() { | ||
57 | $uibModalInstance.dismiss('cancel'); | ||
58 | }; | ||
59 | |||
60 | $scope.busquedaDown = function(key) { | ||
61 | if (key === 40) { | ||
62 | primera(key); | ||
63 | } | ||
64 | }; | ||
65 | |||
66 | $scope.busquedaPress = function(key) { | ||
67 | if (key === 13) { | ||
68 | primera(key); | ||
69 | } | ||
70 | }; | ||
71 | |||
72 | $scope.itemProducto = function(key) { | ||
73 | if (key === 38) { | ||
74 | anterior(key); | ||
75 | } | ||
76 | |||
77 | if (key === 40) { | ||
78 | siguiente(key); | ||
79 | } | ||
80 | |||
81 | if (key === 37) { | ||
82 | retrocederPagina(); | ||
83 | } | ||
84 | |||
85 | if (key === 39) { | ||
86 | avanzarPagina(); | ||
87 | } | ||
88 | }; | ||
89 | |||
90 | function calcularPages(paginaActual) { | ||
91 | var paginas = []; | ||
92 | paginas.push(paginaActual); | ||
93 | |||
94 | if (paginaActual - 1 > 1) { | ||
95 | |||
96 | paginas.unshift(paginaActual - 1); | ||
97 | if (paginaActual - 2 > 1) { | ||
98 | paginas.unshift(paginaActual - 2); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | if (paginaActual + 1 < $scope.lastPage) { | ||
103 | paginas.push(paginaActual + 1); | ||
104 | if (paginaActual + 2 < $scope.lastPage) { | ||
105 | paginas.push(paginaActual + 2); | ||
106 | } | ||
107 | } | ||
108 | |||
109 | if (paginaActual !== 1) { | ||
110 | paginas.unshift(1); | ||
111 | } | ||
112 | |||
113 | if (paginaActual !== $scope.lastPage) { | ||
114 | paginas.push($scope.lastPage); | ||
115 | } | ||
116 | |||
117 | return paginas; | ||
118 | } | ||
119 | |||
120 | function primera() { | ||
121 | $scope.selectedMoneda = 0; | ||
122 | } | ||
123 | |||
124 | function anterior() { | ||
125 | if ($scope.selectedMoneda === 0 && $scope.currentPage > 1) { | ||
126 | retrocederPagina(); | ||
127 | } else { | ||
128 | $scope.selectedMoneda--; | ||
129 | } | ||
130 | } | ||
131 | |||
132 | function siguiente() { | ||
133 | if ($scope.selectedMoneda < | ||
134 | $scope.currentPageMoneda.length - 1 ) { | ||
135 | $scope.selectedMoneda++; | ||
136 | } else { | ||
137 | avanzarPagina(); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | function retrocederPagina() { | ||
142 | if ($scope.currentPage > 1) { | ||
143 | $scope.selectPage($scope.currentPage - 1); | ||
144 | $scope.selectedMoneda = $scope.numPerPage - 1; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | function avanzarPagina() { | ||
149 | if ($scope.currentPage < $scope.lastPage) { | ||
150 | $scope.selectPage($scope.currentPage + 1); | ||
151 | $scope.selectedMoneda = 0; | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | ] | ||
156 | ); | ||
157 |
src/js/service.js
File was created | 1 | angular.module('focaModalMoneda') | |
2 | .service('focaModalMonedaService', [ | ||
3 | '$http', | ||
4 | 'API_ENDPOINT', | ||
5 | function($http, API_ENDPOINT) { | ||
6 | return { | ||
7 | getMonedas: function() { | ||
8 | return $http.get(API_ENDPOINT.URL + '/moneda'); | ||
9 | } | ||
10 | }; | ||
11 | } | ||
12 | ]); | ||
13 |
src/views/modal-moneda.html
File was created | 1 | <div class="modal-header"> | |
2 | <h3 class="modal-title">Busqueda de Moneda</h3> | ||
3 | </div> | ||
4 | <div class="modal-body" id="modal-body"> | ||
5 | <div class="input-group mb-3"> | ||
6 | <input | ||
7 | type="text" | ||
8 | class="form-control" | ||
9 | placeholder="Busqueda" | ||
10 | ng-model="filters" | ||
11 | ng-change="search()" | ||
12 | ng-keydown="busquedaDown($event.keyCode)" | ||
13 | ng-keypress="busquedaPress($event.keyCode)" | ||
14 | foca-focus="selectedMoneda == -1" | ||
15 | ng-focus="selectedMoneda = -1" | ||
16 | > | ||
17 | <table class="table table-striped table-sm"> | ||
18 | <thead> | ||
19 | <tr> | ||
20 | <th>Nombre</th> | ||
21 | <th>Simbolo</th> | ||
22 | <th></th> | ||
23 | </tr> | ||
24 | </thead> | ||
25 | <tbody> | ||
26 | <tr | ||
27 | class="selectable" | ||
28 | ng-repeat="(key,moneda) in currentPageMoneda" | ||
29 | ng-click="select(moneda)" | ||
30 | > | ||
31 | <td ng-bind="moneda.DETALLE"></td> | ||
32 | <td ng-bind="moneda.SIMBOLO"></td> | ||
33 | <td> | ||
34 | <button | ||
35 | type="button" | ||
36 | class="btn p-2 float-right" | ||
37 | ng-class="{ | ||
38 | 'btn-secondary': selectedMoneda != key, | ||
39 | 'btn-primary': selectedMoneda == key | ||
40 | }" | ||
41 | foca-focus="selectedMoneda == {{key}}" | ||
42 | ng-keydown="itemProducto($event.keyCode)" | ||
43 | > | ||
44 | <i class="fa fa-arrow-right" aria-hidden="true"></i> | ||
45 | </button> | ||
46 | </td> | ||
47 | </tr> | ||
48 | </tbody> | ||
49 | </table> | ||
50 | <nav> | ||
51 | <ul class="pagination justify-content-end"> | ||
52 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | ||
53 | <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> | ||
54 | <span aria-hidden="true">«</span> | ||
55 | <span class="sr-only">Anterior</span> | ||
56 | </a> | ||
57 | </li> | ||
58 | <li | ||
59 | class="page-item" | ||
60 | ng-repeat="pagina in paginas" | ||
61 | ng-class="{'active': pagina == currentPage}" | ||
62 | > | ||
63 | <a | ||
64 | class="page-link" | ||
65 | href="#" | ||
66 | ng-click="selectPage(pagina)" | ||
67 | ng-bind="pagina" | ||
68 | ></a> | ||
69 | </li> | ||
70 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | ||
71 | <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)"> | ||
72 | <span aria-hidden="true">»</span> | ||
73 | <span class="sr-only">Siguiente</span> | ||
74 | </a> | ||
75 | </li> | ||
76 | </ul> | ||
77 | </nav> | ||
78 | </div> | ||
79 | </div> | ||
80 | <div class="modal-footer"> | ||
81 | <button class="btn btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | ||
82 | </div> | ||
83 |