Commit e78f6a3735ff472d13b0717beb2967011633ca03
Exists in
master
Merge branch 'master' into 'master'
paginacion y navegacion por teclado See merge request modulos-npm/foca-modal-petroleras!2
Showing
9 changed files
Show diff stats
.jshintrc
1 | { | 1 | { |
2 | /* | 2 | /* |
3 | * ENVIRONMENTS | 3 | * ENVIRONMENTS |
4 | * ================= | 4 | * ================= |
5 | */ | 5 | */ |
6 | 6 | ||
7 | // Define globals exposed by modern browsers. | 7 | // Define globals exposed by modern browsers. |
8 | "browser": true, | 8 | "browser": true, |
9 | 9 | ||
10 | // Define globals exposed by jQuery. | 10 | // Define globals exposed by jQuery. |
11 | "jquery": true, | 11 | "jquery": true, |
12 | 12 | ||
13 | // Define globals exposed by Node.js. | 13 | // Define globals exposed by Node.js. |
14 | "node": true, | 14 | "node": true, |
15 | 15 | ||
16 | // Allow ES6. | 16 | // Allow ES6. |
17 | "esversion": 6, | 17 | "esversion": 6, |
18 | 18 | ||
19 | /* | 19 | /* |
20 | * ENFORCING OPTIONS | 20 | * ENFORCING OPTIONS |
21 | * ================= | 21 | * ================= |
22 | */ | 22 | */ |
23 | 23 | ||
24 | // Force all variable names to use either camelCase style or UPPER_CASE | 24 | // Force all variable names to use either camelCase style or UPPER_CASE |
25 | // with underscores. | 25 | // with underscores. |
26 | "camelcase": true, | 26 | "camelcase": true, |
27 | 27 | ||
28 | // Prohibit use of == and != in favor of === and !==. | 28 | // Prohibit use of == and != in favor of === and !==. |
29 | "eqeqeq": true, | 29 | "eqeqeq": true, |
30 | 30 | ||
31 | // Enforce tab width of 2 spaces. | 31 | // Enforce tab width of 2 spaces. |
32 | "indent": 4, | 32 | "indent": 4, |
33 | 33 | ||
34 | // Prohibit use of a variable before it is defined. | 34 | // Prohibit use of a variable before it is defined. |
35 | "latedef": true, | 35 | "latedef": false, |
36 | 36 | ||
37 | // Enforce line length to 100 characters | 37 | // Enforce line length to 100 characters |
38 | "maxlen": 100, | 38 | "maxlen": 100, |
39 | 39 | ||
40 | // Require capitalized names for constructor functions. | 40 | // Require capitalized names for constructor functions. |
41 | "newcap": true, | 41 | "newcap": true, |
42 | 42 | ||
43 | // Enforce use of single quotation marks for strings. | 43 | // Enforce use of single quotation marks for strings. |
44 | "quotmark": "single", | 44 | "quotmark": "single", |
45 | 45 | ||
46 | // Enforce placing 'use strict' at the top function scope | 46 | // Enforce placing 'use strict' at the top function scope |
47 | "strict": false, | 47 | "strict": false, |
48 | 48 | ||
49 | // Prohibit use of explicitly undeclared variables. | 49 | // Prohibit use of explicitly undeclared variables. |
50 | "undef": true, | 50 | "undef": true, |
51 | 51 | ||
52 | // Warn when variables are defined but never used. | 52 | // Warn when variables are defined but never used. |
53 | "unused": true, | 53 | "unused": true, |
54 | 54 | ||
55 | // Para que funcione en angular | 55 | // Para que funcione en angular |
56 | "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], | 56 | "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], |
57 | /* | 57 | /* |
58 | * RELAXING OPTIONS | 58 | * RELAXING OPTIONS |
59 | * ================= | 59 | * ================= |
60 | */ | 60 | */ |
61 | 61 | ||
62 | // Suppress warnings about == null comparisons. | 62 | // Suppress warnings about == null comparisons. |
63 | "eqnull": true | 63 | "eqnull": true |
64 | } | 64 | } |
65 | 65 |
gulpfile.js
1 | const templateCache = require('gulp-angular-templatecache'); | 1 | const templateCache = require('gulp-angular-templatecache'); |
2 | const concat = require('gulp-concat'); | 2 | const concat = require('gulp-concat'); |
3 | const htmlmin = require('gulp-htmlmin'); | 3 | const htmlmin = require('gulp-htmlmin'); |
4 | const rename = require('gulp-rename'); | 4 | const rename = require('gulp-rename'); |
5 | const uglify = require('gulp-uglify'); | 5 | const uglify = require('gulp-uglify'); |
6 | const gulp = require('gulp'); | 6 | const gulp = require('gulp'); |
7 | const pump = require('pump'); | 7 | const pump = require('pump'); |
8 | const jshint = require('gulp-jshint'); | 8 | const jshint = require('gulp-jshint'); |
9 | const replace = require('gulp-replace'); | 9 | const replace = require('gulp-replace'); |
10 | const connect = require('gulp-connect'); | 10 | const connect = require('gulp-connect'); |
11 | 11 | ||
12 | var paths = { | 12 | var paths = { |
13 | srcJS: 'src/js/*.js', | 13 | srcJS: 'src/js/*.js', |
14 | srcViews: 'src/views/*.html', | 14 | srcViews: 'src/views/*.html', |
15 | tmp: 'tmp', | 15 | tmp: 'tmp', |
16 | dist: 'dist/' | 16 | dist: 'dist/' |
17 | }; | 17 | }; |
18 | 18 | ||
19 | gulp.task('templates', function() { | 19 | gulp.task('templates', function() { |
20 | pump( | 20 | return pump( |
21 | [ | 21 | [ |
22 | gulp.src(paths.srcViews), | 22 | gulp.src(paths.srcViews), |
23 | replace('views/', ''), | 23 | replace('views/', ''), |
24 | htmlmin(), | 24 | htmlmin(), |
25 | templateCache('views.js', { | 25 | templateCache('views.js', { |
26 | module: 'focaBusquedaProductos', | 26 | module: 'focaModalPetroleras', |
27 | root: '' | 27 | root: '' |
28 | }), | 28 | }), |
29 | gulp.dest(paths.tmp) | 29 | gulp.dest(paths.tmp) |
30 | ] | 30 | ] |
31 | ); | 31 | ); |
32 | }); | 32 | }); |
33 | 33 | ||
34 | gulp.task('uglify', function() { | 34 | gulp.task('uglify', ['templates'], function() { |
35 | pump( | 35 | return pump( |
36 | [ | 36 | [ |
37 | gulp.src([ | 37 | gulp.src([ |
38 | paths.srcJS, | 38 | paths.srcJS, |
39 | 'tmp/views.js' | 39 | 'tmp/views.js' |
40 | ]), | 40 | ]), |
41 | concat('foca-busqueda-productos.js'), | 41 | concat('foca-modal-petroleras.js'), |
42 | gulp.dest(paths.tmp), | 42 | gulp.dest(paths.tmp), |
43 | rename('foca-busqueda-productos.min.js'), | 43 | rename('foca-modal-petroleras.min.js'), |
44 | uglify(), | 44 | uglify(), |
45 | gulp.dest(paths.dist) | 45 | gulp.dest(paths.dist) |
46 | ] | 46 | ] |
47 | ); | 47 | ); |
48 | }); | 48 | }); |
49 | 49 | ||
50 | gulp.task('pre-commit', function() { | 50 | gulp.task('pre-commit', function() { |
51 | pump( | 51 | return pump( |
52 | [ | 52 | [ |
53 | gulp.src(paths.srcJS), | 53 | gulp.src(paths.srcJS), |
54 | jshint('.jshintrc'), | 54 | jshint('.jshintrc'), |
55 | jshint.reporter('default'), | 55 | jshint.reporter('default'), |
56 | jshint.reporter('fail') | 56 | jshint.reporter('fail') |
57 | ] | 57 | ] |
58 | ); | 58 | ); |
59 | 59 | ||
60 | gulp.start('uglify'); | 60 | gulp.start('uglify'); |
61 | gulp.start('templates'); | ||
62 | }); | 61 | }); |
63 | 62 | ||
64 | gulp.task('webserver', function() { | 63 | gulp.task('webserver', function() { |
65 | pump [ | 64 | pump [ |
66 | connect.server({port: 3000}) | 65 | connect.server({port: 3000}) |
67 | ] | 66 | ] |
68 | }); | 67 | }); |
69 | 68 | ||
70 | gulp.task('default', ['webserver']); | 69 | gulp.task('default', ['webserver']); |
index.html
1 | <html ng-app="focaModalPetroleras"> | 1 | <html ng-app="focaModalPetroleras"> |
2 | 2 | ||
3 | <head> | 3 | <head> |
4 | <meta charset="UTF-8" /> | 4 | <meta charset="UTF-8" /> |
5 | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | 5 | <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> |
6 | 6 | ||
7 | <!--CSS--> | 7 | <!--CSS--> |
8 | <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" /> | 8 | <link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet" /> |
9 | <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet" /> | 9 | <link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet" /> |
10 | 10 | ||
11 | <!--VENDOR JS--> | 11 | <!--VENDOR JS--> |
12 | <script src="node_modules/jquery/dist/jquery.min.js"></script> | 12 | <script src="node_modules/jquery/dist/jquery.min.js"></script> |
13 | <script src="node_modules/bootstrap/dist/js/bootstrap.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> | 14 | <script src="node_modules/angular/angular.min.js"></script> |
15 | <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.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> | ||
16 | 17 | ||
17 | <!-- BUILD --> | 18 | <!-- BUILD --> |
18 | <script src="src/js/app.js"></script> | 19 | <script src="src/js/app.js"></script> |
19 | <script src="src/js/controller.js"></script> | 20 | <script src="src/js/controller.js"></script> |
20 | <script src="src/js/service.js"></script> | 21 | <script src="src/js/service.js"></script> |
21 | 22 | ||
22 | <!-- /BUILD --> | 23 | <!-- /BUILD --> |
23 | 24 | ||
24 | <!-- CONFIG PARA DEVELOP --> | 25 | <!-- CONFIG PARA DEVELOP --> |
26 | <script src="src/etc/develop.js"></script> | ||
27 | |||
25 | <script type="text/javascript"> | 28 | <script type="text/javascript"> |
26 | angular.module('focaModalPetroleras') | 29 | angular.module('focaModalPetroleras') |
27 | .controller('controller', ['$uibModal', function ($uibModal) { | 30 | .controller('controller', ['$uibModal', '$timeout', function ($uibModal, $timeout) { |
28 | var modalInstance = $uibModal.open( | 31 | openModal(); |
29 | { | 32 | |
30 | ariaLabelledBy: 'Busqueda de Petroleras', | 33 | function openModal() { |
31 | templateUrl: 'src/views/modal-petroleras.html', | 34 | var modalInstance = $uibModal.open( |
32 | controller: 'modalPetrolerasCtrl', | 35 | { |
33 | size: 'lg' | 36 | ariaLabelledBy: 'Busqueda de Petroleras', |
34 | } | 37 | templateUrl: 'src/views/modal-petroleras.html', |
35 | ); | 38 | controller: 'modalPetrolerasCtrl', |
39 | size: 'lg' | ||
40 | } | ||
41 | ); | ||
42 | |||
43 | modalInstance.result.then( | ||
44 | function (selectedItem) { | ||
45 | console.info(selectedItem); | ||
46 | $timeout(openModal, 500); | ||
47 | }, function () { | ||
48 | console.info('modal-component dismissed at: ' + new Date()); | ||
49 | $timeout(openModal, 500); | ||
50 | } | ||
51 | ); | ||
52 | } | ||
36 | }]); | 53 | }]); |
37 | </script> | 54 | </script> |
38 | </head> | 55 | </head> |
39 | 56 | ||
40 | <body ng-controller="controller"> | 57 | <body ng-controller="controller"> |
41 | <style> | 58 | <style> |
42 | .p-5 { | 59 | .p-5 { |
43 | padding: 5px !important; | 60 | padding: 5px !important; |
44 | } | 61 | } |
45 | </style> | 62 | </style> |
46 | </body> | 63 | </body> |
47 | 64 | ||
48 | </html> | 65 | </html> |
package.json
1 | { | 1 | { |
2 | "name": "foca-navegacion-doble", | 2 | "name": "foca-modal-petroleras", |
3 | "version": "0.0.1", | 3 | "version": "0.0.2", |
4 | "description": "Menu de navegacion de doble entrada", | 4 | "description": "Modal para seleccionar petroleras", |
5 | "main": "index.js", | ||
6 | "scripts": { | 5 | "scripts": { |
7 | "test": "echo \"Error: no test specified\" && exit 1", | 6 | "test": "echo \"Error: no test specified\" && exit 1", |
8 | "compile": "gulp templates && gulp uglify", | 7 | "gulp-pre-commit": "gulp pre-commit", |
9 | "pre-commit": [ | 8 | "compile": "gulp uglify", |
10 | "gulp-pre-commit" | ||
11 | ], | ||
12 | "postinstall": "npm run compile && rm -R src && rm index.html && rm .jshintrc && rm gulpfile.js", | 9 | "postinstall": "npm run compile && rm -R src && rm index.html && rm .jshintrc && rm gulpfile.js", |
13 | "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" | 10 | "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 gulp-uglify jasmine-core pre-commit gulp-angular-templatecache ui-bootstrap4 git+https://192.168.0.11/modulos-npm/foca-directivas" |
14 | }, | 11 | }, |
12 | "pre-commit": [ | ||
13 | "gulp-pre-commit" | ||
14 | ], | ||
15 | "repository": { | 15 | "repository": { |
16 | "type": "git", | 16 | "type": "git", |
17 | "url": "https://192.168.0.11/modulos-npm/foca-navegacion-doble" | 17 | "url": "https://192.168.0.11/modulos-npm/foca-modal-petroleras" |
18 | }, | 18 | }, |
19 | "author": "Nicolás Guarnieri", | 19 | "author": "Nicolás Guarnieri", |
20 | "license": "ISC", | 20 | "license": "ISC", |
21 | "peerDependencies": { | 21 | "peerDependencies": { |
22 | "angular": "^1.7.4", | 22 | "angular": "^1.7.4", |
23 | "bootstrap": "^4.1.3", | 23 | "bootstrap": "^4.1.3", |
24 | "font-awesome": "^4.7.0", | 24 | "font-awesome": "^4.7.0", |
25 | "ui-bootstrap4": "^3.0.4", | 25 | "ui-bootstrap4": "^3.0.4", |
26 | "gulp": "^3.9.1", | 26 | "gulp": "^3.9.1", |
27 | "gulp-angular-templatecache": "^2.2.1", | 27 | "gulp-angular-templatecache": "^2.2.1", |
28 | "gulp-concat": "^2.6.1", | 28 | "gulp-concat": "^2.6.1", |
29 | "gulp-connect": "^5.6.1", | 29 | "gulp-connect": "^5.6.1", |
30 | "gulp-htmlmin": "^5.0.1", | 30 | "gulp-htmlmin": "^5.0.1", |
31 | "gulp-rename": "^1.4.0", | 31 | "gulp-rename": "^1.4.0", |
32 | "gulp-replace": "^1.0.0", | 32 | "gulp-replace": "^1.0.0", |
33 | "gulp-uglify": "^3.0.1", | 33 | "gulp-uglify": "^3.0.1", |
34 | "jquery": "^3.3.1", | 34 | "jquery": "^3.3.1", |
35 | "pump": "^3.0.0" | 35 | "pump": "^3.0.0", |
36 | "foca-directivas": "git+https://192.168.0.11/modulos-npm/foca-directivas" | ||
36 | }, | 37 | }, |
37 | "devDependencies": { | 38 | "devDependencies": { |
38 | "angular": "^1.7.4", | 39 | "angular": "^1.7.5", |
39 | "bootstrap": "^4.1.3", | 40 | "bootstrap": "^4.1.3", |
41 | "foca-directivas": "git+https://192.168.0.11/modulos-npm/foca-directivas", | ||
40 | "font-awesome": "^4.7.0", | 42 | "font-awesome": "^4.7.0", |
41 | "gulp": "^3.9.1", | 43 | "gulp": "^3.9.1", |
42 | "gulp-angular-templatecache": "^2.2.1", | 44 | "gulp-angular-templatecache": "^2.2.1", |
43 | "gulp-concat": "^2.6.1", | 45 | "gulp-concat": "^2.6.1", |
44 | "gulp-connect": "^5.6.1", | 46 | "gulp-connect": "^5.6.1", |
45 | "gulp-htmlmin": "^5.0.1", | 47 | "gulp-htmlmin": "^5.0.1", |
46 | "gulp-jshint": "^2.1.0", | 48 | "gulp-jshint": "^2.1.0", |
47 | "gulp-rename": "^1.4.0", | 49 | "gulp-rename": "^1.4.0", |
48 | "gulp-replace": "^1.0.0", | 50 | "gulp-replace": "^1.0.0", |
49 | "gulp-uglify": "^3.0.1", | 51 | "gulp-uglify": "^3.0.1", |
50 | "jasmine-core": "^3.2.1", | 52 | "jasmine-core": "^3.2.1", |
51 | "jquery": "^3.3.1", | 53 | "jquery": "^3.3.1", |
52 | "jshint": "^2.9.6", | 54 | "jshint": "^2.9.6", |
53 | "pre-commit": "^1.2.2", | 55 | "pre-commit": "^1.2.2", |
54 | "pump": "^3.0.0", | 56 | "pump": "^3.0.0", |
55 | "ui-bootstrap4": "^3.0.4" | 57 | "ui-bootstrap4": "^3.0.5" |
src/etc/develop.js.ejemplo
1 | angular.module('focaBusquedaProductos') | 1 | angular.module('focaModalPetroleras') |
2 | .constant("API_ENDPOINT", { | 2 | .constant("API_ENDPOINT", { |
3 | 'URL': '//127.0.0.1:9000' | 3 | 'URL': '//127.0.0.1:9000' |
4 | }); | 4 | }); |
5 | 5 |
src/js/app.js
1 | angular.module('focaModalPetroleras', ['ui.bootstrap']); | 1 | angular.module('focaModalPetroleras', ['ui.bootstrap', 'focaDirectivas']); |
2 | 2 |
src/js/controller.js
1 | angular.module('focaModalPetroleras') | 1 | angular.module('focaModalPetroleras') |
2 | .controller('modalPetrolerasCtrl', [ | 2 | .controller('modalPetrolerasCtrl', [ |
3 | '$filter', | 3 | '$filter', |
4 | '$scope', | 4 | '$scope', |
5 | '$uibModalInstance', | 5 | '$uibModalInstance', |
6 | 'focaPetrolerasService', | 6 | 'focaPetrolerasService', |
7 | function ($filter, $scope, $uibModalInstance, focaPetrolerasService) { | 7 | function ($filter, $scope, $uibModalInstance, focaPetrolerasService) { |
8 | var json = { | 8 | var json = {razonCuitCod: ''}; |
9 | razonCuitCod: '' | 9 | |
10 | } | 10 | focaPetrolerasService.getPetroleras(json).then( |
11 | focaPetrolerasService.getPetroleras(json).then( | 11 | function (res) { |
12 | function (res) { | 12 | for (var i = res.data.length - 1; i >= 0; i--) { |
13 | $scope.vendedores = res.data; | 13 | if (res.data[i].COD === 0) { |
14 | $scope.search(); | 14 | delete res.data[i]; |
15 | }); | 15 | } |
16 | 16 | } | |
17 | // pagination | 17 | |
18 | $scope.numPerPage = 10; | 18 | $scope.petroleras = res.data; |
19 | $scope.currentPage = 1; | 19 | $scope.search(); |
20 | $scope.filteredPetroleras = []; | 20 | }); |
21 | $scope.currentPagePetroleras = []; | 21 | |
22 | $scope.selectPetroleras = 0; | 22 | // pagination |
23 | 23 | $scope.numPerPage = 10; | |
24 | $scope.search = function () { | 24 | $scope.currentPage = 1; |
25 | $scope.filteredPetroleras = $filter('filter')($scope.vendedores, { $: $scope.filters }); | 25 | $scope.filteredPetroleras = []; |
26 | $scope.resetPage(); | 26 | $scope.currentPagePetroleras = []; |
27 | } | 27 | $scope.selectedPetroleras = -1; |
28 | 28 | ||
29 | $scope.resetPage = function () { | 29 | $scope.search = function () { |
30 | $scope.currentPage = 1; | 30 | $scope.filteredPetroleras = $filter('filter')( |
31 | $scope.selectPage(1); | 31 | $scope.petroleras, {$: $scope.filters} |
32 | } | 32 | ); |
33 | 33 | ||
34 | $scope.selectPage = function (page) { | 34 | $scope.lastPage = Math.ceil( |
35 | var start = (page - 1) * $scope.numPerPage; | 35 | $scope.filteredPetroleras.length / $scope.numPerPage |
36 | var end = start + $scope.numPerPage; | 36 | ); |
37 | $scope.currentPagePetroleras = $scope.filteredPetroleras.slice(start, end); | 37 | |
38 | } | 38 | $scope.resetPage(); |
39 | 39 | }; | |
40 | $scope.select = function(vendedor) { | 40 | |
41 | $uibModalInstance.close(vendedor); | 41 | $scope.resetPage = function () { |
42 | } | 42 | $scope.currentPage = 1; |
43 | 43 | $scope.selectPage(1); | |
44 | $scope.cancel = function() { | 44 | }; |
45 | $uibModalInstance.dismiss('cancel'); | 45 | |
46 | } | 46 | $scope.selectPage = function (page) { |
47 | 47 | console.info(page); | |
48 | $scope.enter = function(key) { | 48 | var start = (page - 1) * $scope.numPerPage; |
49 | if (key === 13) { | 49 | var end = start + $scope.numPerPage; |
50 | console.table($scope.currentPagePetroleras); | 50 | $scope.paginas = []; |
51 | } | 51 | $scope.paginas = calcularPages(page); |
52 | } | 52 | $scope.currentPagePetroleras = $scope.filteredPetroleras.slice(start, end); |
53 | }] | 53 | $scope.currentPage = page; |
54 | ) | 54 | }; |
55 | |||
56 | $scope.select = function(petrolera) { | ||
57 | $uibModalInstance.close(petrolera); | ||
58 | }; | ||
59 | |||
60 | $scope.cancel = function() { | ||
61 | $uibModalInstance.dismiss('cancel'); | ||
62 | }; | ||
63 | |||
64 | $scope.busquedaDown = function(key) { | ||
65 | if (key === 40) { | ||
66 | primera(key); | ||
67 | } | ||
68 | }; | ||
69 | |||
70 | $scope.busquedaPress = function(key) { | ||
71 | if (key === 13) { | ||
72 | primera(key); | ||
73 | } | ||
74 | }; | ||
75 | |||
76 | $scope.itemPetrolera = function(key) { | ||
77 | if (key === 38) { | ||
78 | anterior(key); | ||
79 | } | ||
80 | |||
81 | if (key === 40) { | ||
82 | siguiente(key); | ||
83 | } | ||
84 | |||
85 | if (key === 37) { | ||
86 | retrocederPagina(); | ||
87 | } | ||
88 | |||
89 | if (key === 39) { | ||
90 | avanzarPagina(); | ||
91 | } | ||
92 | }; | ||
93 | |||
94 | function calcularPages(paginaActual) { | ||
95 | var paginas = []; | ||
96 | paginas.push(paginaActual); | ||
97 | |||
98 | if (paginaActual - 1 > 1) { | ||
99 | |||
100 | paginas.unshift(paginaActual - 1); | ||
101 | if (paginaActual - 2 > 1) { | ||
102 | paginas.unshift(paginaActual - 2); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | if (paginaActual + 1 < $scope.lastPage) { | ||
107 | paginas.push(paginaActual + 1); | ||
108 | if (paginaActual + 2 < $scope.lastPage) { | ||
109 | paginas.push(paginaActual + 2); | ||
110 | } | ||
111 | } | ||
112 | |||
113 | if (paginaActual !== 1) { | ||
114 | paginas.unshift(1); | ||
115 | } | ||
116 | |||
117 | if (paginaActual !== $scope.lastPage) { | ||
118 | paginas.push($scope.lastPage); | ||
119 | } | ||
120 | |||
121 | return paginas; | ||
122 | } | ||
123 | |||
124 | function primera() { | ||
125 | $scope.selectedPetroleras = 0; | ||
126 | } | ||
127 | |||
128 | function anterior() { | ||
129 | if ($scope.selectedPetroleras === 0 && $scope.currentPage > 1) { | ||
130 | retrocederPagina(); | ||
131 | } else { | ||
132 | $scope.selectedPetroleras--; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | function siguiente() { | ||
137 | if ($scope.selectedPetroleras < $scope.currentPagePetroleras.length - 1 ) { | ||
138 | $scope.selectedPetroleras++; | ||
139 | } else { | ||
140 | avanzarPagina(); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | function retrocederPagina() { | ||
145 | if ($scope.currentPage > 1) { | ||
146 | $scope.selectPage($scope.currentPage - 1); | ||
147 | $scope.selectedPetroleras = $scope.numPerPage - 1; | ||
148 | } | ||
149 | } | ||
150 | |||
151 | function avanzarPagina() { | ||
152 | if ($scope.currentPage < $scope.lastPage) { | ||
153 | $scope.selectPage($scope.currentPage + 1); | ||
154 | $scope.selectedPetroleras = 0; | ||
155 | } | ||
156 | } | ||
157 | }] | ||
158 | ); | ||
55 | 159 |
src/js/service.js
1 | angular.module('focaModalPetroleras') | 1 | angular.module('focaModalPetroleras') |
2 | .service('focaPetrolerasService', ['$http', function($http) { | 2 | .service('focaPetrolerasService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { |
3 | var configRoute ='http://localhost:9900'; | ||
4 | return { | 3 | return { |
5 | getPetroleras: function(json) { | 4 | getPetroleras: function(json) { |
6 | return $http.post(configRoute + '/petroleras', json); | 5 | return $http.post(API_ENDPOINT.URL + '/petroleras', json); |
7 | } | 6 | } |
8 | } | 7 | }; |
9 | }]) | 8 | }]); |
10 | 9 |
src/views/modal-petroleras.html
1 | <div class="modal-header"> | 1 | <div class="modal-header"> |
2 | <h3 class="modal-title">Búsqueda de Petrolera</h3> | 2 | <h3 class="modal-title">Búsqueda de Petrolera</h3> |
3 | </div> | 3 | </div> |
4 | <div class="modal-body" id="modal-body"> | 4 | <div class="modal-body" id="modal-body"> |
5 | <div class="input-group mb-3"> | 5 | <div class="input-group mb-3"> |
6 | <input | 6 | <input |
7 | type="text" | 7 | type="text" |
8 | class="form-control" | 8 | class="form-control" |
9 | placeholder="Busqueda" | 9 | placeholder="Busqueda" |
10 | ng-model="filters" | 10 | ng-model="filters" |
11 | ng-change="search()" | 11 | ng-change="search()" |
12 | ng-keypress="enter($event.keyCode)" | 12 | ng-keydown="busquedaDown($event.keyCode)" |
13 | ng-keypress="busquedaPress($event.keyCode)" | ||
14 | foca-focus="selectedPetroleras == -1" | ||
15 | ng-focus="selectedPetroleras = -1" | ||
13 | > | 16 | > |
14 | <table class="table table-striped table-sm"> | 17 | <table class="table table-striped table-sm"> |
15 | <thead> | 18 | <thead> |
16 | <tr> | 19 | <tr> |
17 | <th>Código</th> | 20 | <th>Código</th> |
18 | <th>Nombre</th> | 21 | <th>Nombre</th> |
19 | <th>CUIT</th> | 22 | <th>CUIT</th> |
20 | <th></th> | 23 | <th></th> |
21 | </tr> | 24 | </tr> |
22 | </thead> | 25 | </thead> |
23 | <tbody> | 26 | <tbody> |
24 | <tr ng-repeat="petrolera in filteredPetroleras"> | 27 | <tr ng-repeat="(key, petrolera) in currentPagePetroleras"> |
25 | <td ng-bind="petrolera.COD"></td> | 28 | <td ng-bind="petrolera.COD"></td> |
26 | <td ng-bind="petrolera.NOM"></td> | 29 | <td ng-bind="petrolera.NOM"></td> |
27 | <td ng-bind="petrolera.CUIT"></td> | 30 | <td ng-bind="petrolera.CUIT"></td> |
28 | <td> | 31 | <td> |
29 | <button type="button" class="btn btn-secondary p-5 float-right mr-1" ng-click="select(producto)"> | 32 | <button |
30 | <i class="fa fa-check" aria-hidden="true"></i> | 33 | type="button" |
34 | class="btn p-2 float-right" | ||
35 | ng-class="{ | ||
36 | 'btn-secondary': selectedPetroleras != key, | ||
37 | 'btn-primary': selectedPetroleras == key | ||
38 | }" | ||
39 | ng-click="select(petrolera)" | ||
40 | foca-focus="selectedPetroleras == {{key}}" | ||
41 | ng-keydown="itemPetrolera($event.keyCode)" | ||
42 | > | ||
43 | <i class="fa fa-arrow-right" aria-hidden="true"></i> | ||
31 | </button> | 44 | </button> |
32 | </td> | 45 | </td> |
33 | </tr> | 46 | </tr> |
34 | </tbody> | 47 | </tbody> |
35 | </table> | 48 | </table> |
49 | <nav> | ||
50 | <ul class="pagination justify-content-end"> | ||
51 | <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | ||
52 | <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> | ||
53 | <span aria-hidden="true">«</span> | ||
54 | <span class="sr-only">Anterior</span> | ||
55 | </a> | ||
56 | </li> | ||
57 | <li | ||
58 | class="page-item" | ||
59 | ng-repeat="pagina in paginas" | ||
60 | ng-class="{'active': pagina == currentPage}" | ||
61 | > | ||
62 | <a | ||
63 | class="page-link" | ||
64 | href="#" | ||
65 | ng-click="selectPage(pagina)" | ||
66 | ng-bind="pagina" | ||
67 | ></a> | ||
68 | </li> | ||
69 | <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | ||
70 | <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)"> | ||
71 | <span aria-hidden="true">»</span> | ||
72 | <span class="sr-only">Siguiente</span> | ||
73 | </a> | ||
74 | </li> | ||
75 | </ul> | ||
76 | </nav> | ||
36 | </div> | 77 | </div> |
37 | </div> | 78 | </div> |
38 | <div class="modal-footer"> | 79 | <div class="modal-footer"> |
39 | <button class="btn btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | 80 | <button class="btn btn-secondary" type="button" ng-click="cancel()">Cancelar</button> |
40 | </div> | 81 | </div> |
41 | 82 |