Commit bd630535022d20b18b35ff639829c38c7fb5230a
0 parents
Exists in
master
Primera versión estable.
Showing
11 changed files
with
564 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-chofer | |
2 | |||
3 | Modal con lista de choferes |
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: 'focaModalChofer', | ||
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-chofer.js'), | ||
42 | replace('src/views/', ''), | ||
43 | replace("['ui.bootstrap', 'focaDirectivas']", '[]'), | ||
44 | gulp.dest(paths.tmp), | ||
45 | rename('foca-modal-chofer.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 | |||
77 | gulp.task('watch', function() { | ||
78 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']) | ||
79 | }); | ||
80 | |||
81 | gulp.task('copy', ['uglify'], function() { | ||
82 | gulp.src('dist/*.js') | ||
83 | .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-modal-chofer/dist')); | ||
84 | }); | ||
85 | |||
86 | gulp.task('watchAndCopy', function() { | ||
87 | return gulp.watch([paths.srcJS, paths.srcViews], ['copy']); | ||
88 | }); | ||
89 |
index.html
File was created | 1 | <html ng-app="focaModalChofer"> | |
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('focaModalChofer') | ||
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-chofer.html', | ||
40 | controller: 'focaModalChoferController', | ||
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-chofer", | ||
3 | "version": "0.0.1", | ||
4 | "description": "Modal de búsqueda de choferes", | ||
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 bootstrap font-awesome gulp gulp-angular-templatecache gulp-clean gulp-concat gulp-connect gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify jasmine-core jquery jshint ladda@1.0.6 pre-commit pump ui-bootstrap4 && npm i -D git+https://debo.suite.repo/modulos-npm/foca-directivas.git" | ||
11 | }, | ||
12 | "pre-commit": [ | ||
13 | "gulp-pre-commit" | ||
14 | ], | ||
15 | "repository": { | ||
16 | "type": "git", | ||
17 | "url": "https://debo.suite.repo/modulos-npm/foca-modal-chofer.git" | ||
18 | }, | ||
19 | "author": "Foca Software", | ||
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.git", | ||
43 | "font-awesome": "^4.7.0", | ||
44 | "gulp": "^3.9.1", | ||
45 | "gulp-angular-templatecache": "^2.2.5", | ||
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 | } | ||
63 |
src/etc/develop.js.ejemplo
File was created | 1 | angular.module('focaModalChofer') | |
2 | .constant("API_ENDPOINT", { | ||
3 | 'URL': '//127.0.0.1:9000' | ||
4 | }); | ||
5 |
src/js/app.js
File was created | 1 | angular.module('focaModalChofer', ['ui.bootstrap', 'focaDirectivas']); | |
2 |
src/js/controller.js
File was created | 1 | angular.module('focaModalChofer') | |
2 | .controller('focaModalChoferController', | ||
3 | [ | ||
4 | '$filter', | ||
5 | '$scope', | ||
6 | '$uibModalInstance', | ||
7 | 'focaModalChoferService', | ||
8 | function($filter, $scope, $uibModalInstance, | ||
9 | focaModalChoferService | ||
10 | ) { | ||
11 | |||
12 | $scope.filters = ''; | ||
13 | $scope.choferes = []; | ||
14 | $scope.primerBusqueda = false; | ||
15 | $scope.searchLoading = false; | ||
16 | // pagination | ||
17 | $scope.numPerPage = 10; | ||
18 | $scope.currentPage = 1; | ||
19 | $scope.filteredChoferes = []; | ||
20 | $scope.currentPageChoferes = []; | ||
21 | $scope.selectedChofer = -1; | ||
22 | |||
23 | //METODOS | ||
24 | $scope.busquedaPress = function(key) { | ||
25 | if (key === 13) { | ||
26 | $scope.searchLoading = true; | ||
27 | focaModalChoferService.getChoferes().then(llenarDatos); | ||
28 | } | ||
29 | }; | ||
30 | function llenarDatos(res) { | ||
31 | $scope.searchLoading = false; | ||
32 | $scope.primerBusqueda = true; | ||
33 | $scope.choferes = res.data; | ||
34 | $scope.search(); | ||
35 | primera(); | ||
36 | } | ||
37 | $scope.search = function() { | ||
38 | if($scope.choferes.length > 0) { | ||
39 | $scope.filteredChoferes = $filter('filter')( | ||
40 | $scope.choferes, | ||
41 | {$: $scope.filters} | ||
42 | ); | ||
43 | |||
44 | $scope.lastPage = Math.ceil( | ||
45 | $scope.filteredChoferes.length / $scope.numPerPage | ||
46 | ); | ||
47 | |||
48 | $scope.resetPage(); | ||
49 | } | ||
50 | }; | ||
51 | |||
52 | $scope.resetPage = function() { | ||
53 | $scope.currentPage = 1; | ||
54 | $scope.selectPage(1); | ||
55 | }; | ||
56 | |||
57 | $scope.selectPage = function(page) { | ||
58 | var start = (page - 1) * $scope.numPerPage; | ||
59 | var end = start + $scope.numPerPage; | ||
60 | $scope.paginas = []; | ||
61 | $scope.paginas = calcularPages(page); | ||
62 | $scope.currentPageChoferes = | ||
63 | $scope.filteredChoferes.slice(start, end); | ||
64 | $scope.currentPage = page; | ||
65 | }; | ||
66 | |||
67 | $scope.select = function(chofer) { | ||
68 | $uibModalInstance.close(chofer); | ||
69 | }; | ||
70 | |||
71 | $scope.cancel = function() { | ||
72 | $uibModalInstance.dismiss('cancel'); | ||
73 | }; | ||
74 | |||
75 | $scope.busquedaDown = function(key) { | ||
76 | if (key === 40) { | ||
77 | primera(key); | ||
78 | } | ||
79 | }; | ||
80 | |||
81 | $scope.itemChofer = function(key) { | ||
82 | if (key === 38) { | ||
83 | anterior(key); | ||
84 | } | ||
85 | |||
86 | if (key === 40) { | ||
87 | siguiente(key); | ||
88 | } | ||
89 | |||
90 | if (key === 37) { | ||
91 | retrocederPagina(); | ||
92 | } | ||
93 | |||
94 | if (key === 39) { | ||
95 | avanzarPagina(); | ||
96 | } | ||
97 | }; | ||
98 | |||
99 | function calcularPages(paginaActual) { | ||
100 | var paginas = []; | ||
101 | paginas.push(paginaActual); | ||
102 | |||
103 | if (paginaActual - 1 > 1) { | ||
104 | |||
105 | paginas.unshift(paginaActual - 1); | ||
106 | if (paginaActual - 2 > 1) { | ||
107 | paginas.unshift(paginaActual - 2); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | if (paginaActual + 1 < $scope.lastPage) { | ||
112 | paginas.push(paginaActual + 1); | ||
113 | if (paginaActual + 2 < $scope.lastPage) { | ||
114 | paginas.push(paginaActual + 2); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | if (paginaActual !== 1) { | ||
119 | paginas.unshift(1); | ||
120 | } | ||
121 | |||
122 | if (paginaActual !== $scope.lastPage) { | ||
123 | paginas.push($scope.lastPage); | ||
124 | } | ||
125 | |||
126 | return paginas; | ||
127 | } | ||
128 | |||
129 | function primera() { | ||
130 | $scope.selectedChofer = 0; | ||
131 | } | ||
132 | |||
133 | function anterior() { | ||
134 | if ($scope.selectedChofer === 0 && $scope.currentPage > 1) { | ||
135 | retrocederPagina(); | ||
136 | } else { | ||
137 | $scope.selectedChofer--; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | function siguiente() { | ||
142 | if ( | ||
143 | $scope.selectedChofer < $scope.currentPageChoferes.length - 1 | ||
144 | ) { | ||
145 | $scope.selectedChofer++; | ||
146 | } else { | ||
147 | avanzarPagina(); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | function retrocederPagina() { | ||
152 | if ($scope.currentPage > 1) { | ||
153 | $scope.selectPage($scope.currentPage - 1); | ||
154 | $scope.selectedChofer = $scope.numPerPage - 1; | ||
155 | } | ||
156 | } | ||
157 | |||
158 | function avanzarPagina() { | ||
159 | if ($scope.currentPage < $scope.lastPage) { | ||
160 | $scope.selectPage($scope.currentPage + 1); | ||
161 | $scope.selectedChofer = 0; | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | ] | ||
166 | ); | ||
167 |
src/js/service.js
File was created | 1 | angular.module('focaModalChofer') | |
2 | .service('focaModalChoferService', [ | ||
3 | '$http', | ||
4 | 'API_ENDPOINT', | ||
5 | function($http, API_ENDPOINT) { | ||
6 | return { | ||
7 | getChoferes: function() { | ||
8 | return $http.get(API_ENDPOINT.URL + '/chofer'); | ||
9 | } | ||
10 | }; | ||
11 | } | ||
12 | ]); | ||
13 |
src/views/modal-chofer.html
File was created | 1 | <div class="modal-header py-1"> | |
2 | <h5 class="modal-title">Busqueda de Chofer</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="selectedChofer == -1" | ||
16 | ng-focus="selectedChofer = -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>Nombre</th> | ||
33 | <th>DNI</th> | ||
34 | <th>Teléfono</th> | ||
35 | <th></th> | ||
36 | </tr> | ||
37 | </thead> | ||
38 | <tbody> | ||
39 | <tr ng-show="currentPageChoferes.length == 0 && primerBusqueda"> | ||
40 | <td colspan="5"> | ||
41 | No se encontraron resultados. | ||
42 | </td> | ||
43 | </tr> | ||
44 | <tr class="selectable" | ||
45 | ng-repeat="(key,chofer) in currentPageChoferes" | ||
46 | ng-click="select(chofer)"> | ||
47 | <td ng-bind="chofer.nombre"></td> | ||
48 | <td ng-bind="chofer.dni"></td> | ||
49 | <td ng-bind="chofer.telefono"></td> | ||
50 | <td> | ||
51 | <button | ||
52 | type="button" | ||
53 | class="btn btn-xs p-1 float-right" | ||
54 | ng-class="{ | ||
55 | 'btn-secondary': selectedChofer != key, | ||
56 | 'btn-primary': selectedChofer == key | ||
57 | }" | ||
58 | foca-focus="selectedChofer == {{key}}" | ||
59 | ng-keydown="itemChofer($event.keyCode)" | ||
60 | > | ||
61 | <i class="fa fa-arrow-right" aria-hidden="true"></i> | ||
62 | </button> | ||
63 | </td> | ||
64 | </tr> | ||
65 | </tbody> | ||
66 | </table> | ||
67 | <nav ng-show="currentPageChoferes.length > 0 && primerBusqueda"> | ||
68 | <ul class="pagination pagination-sm justify-content mb-0"> | ||
69 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | ||
70 | <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> | ||
71 | <span aria-hidden="true">«</span> | ||
72 | <span class="sr-only">Anterior</span> | ||
73 | </a> | ||
74 | </li> | ||
75 | <li | ||
76 | class="page-item" | ||
77 | ng-repeat="pagina in paginas" | ||
78 | ng-class="{'active': pagina == currentPage}" | ||
79 | > | ||
80 | <a | ||
81 | class="page-link" | ||
82 | href="#" | ||
83 | ng-click="selectPage(pagina)" | ||
84 | ng-bind="pagina" | ||
85 | ></a> | ||
86 | </li> | ||
87 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | ||
88 | <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)"> | ||
89 | <span aria-hidden="true">»</span> | ||
90 | <span class="sr-only">Siguiente</span> | ||
91 | </a> | ||
92 | </li> | ||
93 | </ul> | ||
94 | </nav> | ||
95 | </div> | ||
96 | <div class="modal-footer py-1"> | ||
97 | <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | ||
98 | </div> | ||
99 |