Commit 17564a92a36b588f6604cced7bbc5cd3010ecaa4
Exists in
master
Merge branch 'master' into 'master'
Master See merge request !3
Showing
5 changed files
Show diff stats
gulpfile.js
| 1 | const clean = require('gulp-clean'); | 1 | const clean = require('gulp-clean'); |
| 2 | const concat = require('gulp-concat'); | 2 | const concat = require('gulp-concat'); |
| 3 | const connect = require('gulp-connect'); | 3 | const connect = require('gulp-connect'); |
| 4 | const gulp = require('gulp'); | 4 | const gulp = require('gulp'); |
| 5 | const htmlmin = require('gulp-htmlmin'); | 5 | const htmlmin = require('gulp-htmlmin'); |
| 6 | const jshint = require('gulp-jshint'); | 6 | const jshint = require('gulp-jshint'); |
| 7 | const pump = require('pump'); | 7 | const pump = require('pump'); |
| 8 | const rename = require('gulp-rename'); | 8 | const rename = require('gulp-rename'); |
| 9 | const replace = require('gulp-replace'); | 9 | const replace = require('gulp-replace'); |
| 10 | const templateCache = require('gulp-angular-templatecache'); | 10 | const templateCache = require('gulp-angular-templatecache'); |
| 11 | const uglify = require('gulp-uglify-es').default; | 11 | const uglify = require('gulp-uglify'); |
| 12 | 12 | ||
| 13 | var paths = { | 13 | var paths = { |
| 14 | srcJS: 'src/js/*.js', | 14 | srcJS: 'src/js/*.js', |
| 15 | srcViews: 'src/views/*.html', | 15 | srcViews: 'src/views/*.html', |
| 16 | tmp: 'tmp', | 16 | tmp: 'tmp', |
| 17 | dist: 'dist/' | 17 | dist: 'dist/' |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | gulp.task('templates', ['clean'], function() { | 20 | gulp.task('templates', ['clean'], function() { |
| 21 | return pump( | 21 | return pump( |
| 22 | [ | 22 | [ |
| 23 | gulp.src(paths.srcViews), | 23 | gulp.src(paths.srcViews), |
| 24 | htmlmin(), | 24 | htmlmin(), |
| 25 | templateCache('views.js', { | 25 | templateCache('views.js', { |
| 26 | module: 'focaLogin', | 26 | module: 'focaLogin', |
| 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', ['templates'], function() { | 34 | gulp.task('uglify', ['templates'], function() { |
| 35 | return 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-login.js'), | 41 | concat('foca-login.js'), |
| 42 | replace("['ngRoute', 'ngCookies', 'focaDirectivas', 'angular-ladda']",'[]'), | 42 | replace("['ngRoute', 'ngCookies', 'focaDirectivas', 'angular-ladda']",'[]'), |
| 43 | replace('src/views/', ''), | 43 | replace('src/views/', ''), |
| 44 | gulp.dest(paths.tmp), | 44 | gulp.dest(paths.tmp), |
| 45 | rename('foca-login.min.js'), | 45 | rename('foca-login.min.js'), |
| 46 | uglify(), | 46 | uglify(), |
| 47 | gulp.dest(paths.dist) | 47 | gulp.dest(paths.dist) |
| 48 | ] | 48 | ] |
| 49 | ); | 49 | ); |
| 50 | }); | 50 | }); |
| 51 | 51 | ||
| 52 | gulp.task('clean', function() { | 52 | gulp.task('clean', function() { |
| 53 | return gulp.src(['tmp', 'dist'], {read: false}) | 53 | return gulp.src(['tmp', 'dist'], {read: false}) |
| 54 | .pipe(clean()); | 54 | .pipe(clean()); |
| 55 | }); | 55 | }); |
| 56 | 56 | ||
| 57 | gulp.task('pre-commit', function() { | 57 | gulp.task('pre-commit', function() { |
| 58 | pump( | 58 | pump( |
| 59 | [ | 59 | [ |
| 60 | gulp.src(paths.srcJS), | 60 | gulp.src(paths.srcJS), |
| 61 | jshint('.jshintrc'), | 61 | jshint('.jshintrc'), |
| 62 | jshint.reporter('default'), | 62 | jshint.reporter('default'), |
| 63 | jshint.reporter('fail') | 63 | jshint.reporter('fail') |
| 64 | ] | 64 | ] |
| 65 | ); | 65 | ); |
| 66 | }); | 66 | }); |
| 67 | 67 | ||
| 68 | gulp.task('clean-post-install', function() { | 68 | gulp.task('clean-post-install', function() { |
| 69 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | 69 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', |
| 70 | 'index.html'], {read: false}) | 70 | 'index.html'], {read: false}) |
| 71 | .pipe(clean()); | 71 | .pipe(clean()); |
| 72 | }); | 72 | }); |
| 73 | 73 | ||
| 74 | gulp.task('compile', ['templates', 'uglify']); | ||
| 75 | |||
| 76 | gulp.task('webserver', function() { | 74 | gulp.task('webserver', function() { |
| 77 | pump [ | 75 | pump [ |
| 78 | connect.server({port: 3000}) | 76 | connect.server({port: 3000}) |
| 79 | ] | 77 | ] |
| 80 | }); | 78 | }); |
| 81 | 79 | ||
| 82 | gulp.task('default', ['webserver']); | 80 | gulp.task('default', ['webserver']); |
| 83 | 81 | ||
| 84 | gulp.task('watch', function() { | 82 | gulp.task('watch', function() { |
| 85 | return gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); | 83 | return gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); |
| 86 | }); | 84 | }); |
| 87 | 85 |
package.json
| 1 | { | 1 | { |
| 2 | "name": "foca-login", | 2 | "name": "foca-login", |
| 3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
| 4 | "description": "Login", | 4 | "description": "Login", |
| 5 | "main": "dist/foca-login.js", | 5 | "main": "dist/foca-login.js", |
| 6 | "scripts": { | 6 | "scripts": { |
| 7 | "test": "echo \"Error: no test specified\" && exit 1", | 7 | "test": "echo \"Error: no test specified\" && exit 1", |
| 8 | "compile": "gulp compile", | ||
| 9 | "gulp-pre-commit": "gulp pre-commit", | 8 | "gulp-pre-commit": "gulp pre-commit", |
| 10 | "postinstall": "npm run compile && gulp clean-post-install", | 9 | "postinstall": "gulp uglify && gulp clean-post-install", |
| 11 | "install-dev": "npm install -D gulp gulp-connect jasmine-core pre-commit angular angular-route angular-cookies bootstrap font-awesome gulp-angular-templatecache gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-replace jquery jshint pump && npm i -D git+http://git.focasoftware.com/npm/foca-directivas.git" | 10 | "install-dev": "npm install -D gulp gulp-connect jasmine-core pre-commit angular angular-route angular-cookies bootstrap font-awesome gulp-angular-templatecache gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify gulp-replace jquery jshint pump && npm i -D git+https://debo.suite.repo/modulos-npm/foca-directivas" |
| 12 | }, | 11 | }, |
| 13 | "pre-commit": [ | 12 | "pre-commit": [ |
| 14 | "gulp-pre-commit" | 13 | "gulp-pre-commit" |
| 15 | ], | 14 | ], |
| 16 | "repository": { | 15 | "repository": { |
| 17 | "type": "git", | 16 | "type": "git", |
| 18 | "url": "https://debo.suite.repo/modulos-npm/foca-login.git" | 17 | "url": "https://debo.suite.repo/modulos-npm/foca-login.git" |
| 19 | }, | 18 | }, |
| 20 | "author": "Foca Software", | 19 | "author": "Foca Software", |
| 21 | "license": "ISC", | 20 | "license": "ISC", |
| 22 | "peerDependencies": { | 21 | "peerDependencies": { |
| 23 | "angular": "^1.7.x", | 22 | "angular": "^1.7.x", |
| 24 | "bootstrap": "^4.1.x", | 23 | "bootstrap": "^4.1.x", |
| 25 | "jquery": "^3.3.x", | 24 | "jquery": "^3.3.x", |
| 26 | "font-awesome": "^4.7.x", | 25 | "font-awesome": "^4.7.x", |
| 27 | "gulp": "^3.9.x", | 26 | "gulp": "^3.9.x", |
| 28 | "gulp-concat": "2.6.x", | 27 | "gulp-concat": "2.6.x", |
| 29 | "gulp-jshint": "^2.1.x", | 28 | "gulp-jshint": "^2.1.x", |
| 30 | "gulp-rename": "^1.4.x", | 29 | "gulp-rename": "^1.4.x", |
| 31 | "gulp-replace": "^1.0.x", | 30 | "gulp-replace": "^1.0.x", |
| 32 | "gulp-uglify-es": "^1.0.x", | 31 | "gulp-uglify-es": "^1.0.x", |
| 33 | "jshint": "^2.9.x", | 32 | "jshint": "^2.9.x", |
| 34 | "pump": "^3.0.x", | 33 | "pump": "^3.0.x", |
| 35 | "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git" | 34 | "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git" |
| 36 | }, | 35 | }, |
| 37 | "devDependencies": { | 36 | "devDependencies": { |
| 38 | "angular": "^1.7.5", | 37 | "angular": "^1.7.5", |
| 39 | "angular-cookies": "^1.7.5", | 38 | "angular-cookies": "^1.7.5", |
| 40 | "angular-route": "^1.7.5", | 39 | "angular-route": "^1.7.5", |
| 41 | "bootstrap": "^4.1.3", | 40 | "bootstrap": "^4.1.3", |
| 42 | "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", | 41 | "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", |
| 43 | "font-awesome": "^4.7.0", | 42 | "font-awesome": "^4.7.0", |
| 44 | "gulp": "^3.9.1", | 43 | "gulp": "^3.9.1", |
| 45 | "gulp-angular-templatecache": "^2.2.5", | 44 | "gulp-angular-templatecache": "^2.2.2", |
| 46 | "gulp-clean": "^0.4.0", | 45 | "gulp-clean": "^0.4.0", |
| 47 | "gulp-connect": "^5.7.0", | 46 | "gulp-connect": "^5.7.0", |
| 48 | "gulp-htmlmin": "^5.0.1", | 47 | "gulp-htmlmin": "^5.0.1", |
| 49 | "gulp-jshint": "^2.1.0", | 48 | "gulp-jshint": "^2.1.0", |
| 50 | "gulp-rename": "^1.4.0", | 49 | "gulp-rename": "^1.4.0", |
| 51 | "gulp-replace": "^1.0.0", | 50 | "gulp-replace": "^1.0.0", |
| 52 | "gulp-sequence": "^1.0.0", | 51 | "gulp-sequence": "^1.0.0", |
| 53 | "gulp-uglify-es": "^1.0.4", | 52 | "gulp-uglify": "^3.0.1", |
| 54 | "jasmine-core": "^3.3.0", | 53 | "jasmine-core": "^3.3.0", |
| 55 | "jquery": "^3.3.1", | 54 | "jquery": "^3.3.1", |
| 56 | "jshint": "^2.9.7", | 55 | "jshint": "^2.9.7", |
| 57 | "pre-commit": "^1.2.2", | 56 | "pre-commit": "^1.2.2", |
| 58 | "pump": "^3.0.0" | 57 | "pump": "^3.0.0" |
| 59 | } | 58 | } |
| 60 | } | 59 | } |
| 61 | 60 |
src/js/app.js
| 1 | angular.module('focaLogin', ['ngRoute', 'ngCookies', 'focaDirectivas', 'angular-ladda']) | 1 | angular.module('focaLogin', ['ngRoute', 'ngCookies', 'focaDirectivas', 'angular-ladda']) |
| 2 | .run(['$rootScope', '$cookies', '$location', function($rootScope, $cookies, $location) { | 2 | .run(['$rootScope', '$cookies', '$location', function($rootScope, $cookies, $location) { |
| 3 | $rootScope.$on('$locationChangeStart', function() { | 3 | $rootScope.$on('$locationChangeStart', function() { |
| 4 | var idUsuario = $cookies.get('idUsuario'); | 4 | if(!$cookies.get('token')) { |
| 5 | if(!idUsuario) { | ||
| 6 | if($location.path() !== '/login') { | 5 | if($location.path() !== '/login') { |
| 7 | $location.path('/login'); | 6 | $location.path('/login'); |
| 8 | } | 7 | } |
| 9 | } | 8 | } |
| 10 | }); | 9 | }); |
| 11 | }]); | 10 | }]); |
| 12 | 11 |
src/js/controller.js
| 1 | angular.module('focaLogin') | 1 | angular.module('focaLogin') |
| 2 | .controller('focaLoginController', [ | 2 | .controller('focaLoginController', [ |
| 3 | '$scope', 'focaLoginService', '$location', '$cookies', 'focaModalService', | 3 | '$scope', 'focaLoginService', '$location', '$cookies', 'focaModalService', |
| 4 | function($scope, focaLoginService, $location, $cookies, focaModalService) { | 4 | function($scope, focaLoginService, $location, $cookies, focaModalService) { |
| 5 | $scope.paso = 1; | 5 | $scope.paso = 1; |
| 6 | $scope.enviar = function() { | 6 | $scope.enviar = function() { |
| 7 | $scope.loginLoading = true; | 7 | focaLoginService.login($scope.usuario).then(function(datos) { |
| 8 | focaLoginService.login($scope.usuario) | 8 | $cookies.put('token', datos.data.token); |
| 9 | .then(function(datos) { | 9 | |
| 10 | $scope.loginLoading = false; | 10 | if (datos.data.chofer) { |
| 11 | $cookies.put('idUsuario', $scope.usuario.idUsuario); | 11 | $cookies.put('chofer', datos.data.chofer.id); |
| 12 | $cookies.put('token', datos.data.token); | 12 | } else if (datos.data.vendedorCobrador) { |
| 13 | $location.path('/'); | 13 | $cookies.put('vendedorCobrador', datos.data.vendedorCobrador.CodVen); |
| 14 | $scope.$emit('blur'); | 14 | } |
| 15 | }) | 15 | |
| 16 | .catch(function(error) { | 16 | $location.path('/'); |
| 17 | $scope.loginLoading = false; | 17 | $scope.$emit('blur'); |
| 18 | if(error.status === 401) { | 18 | }, function(error) { |
| 19 | focaModalService.alert('El usuario y/o la contraseña no coinciden'); | 19 | if (error.status === 401) { |
| 20 | return; | 20 | focaModalService.alert('El usuario o la contraseña han sido mal introducidos'); |
| 21 | } | 21 | } |
| 22 | if(error.status === -1) { | 22 | |
| 23 | focaModalService.alert('Sin servicio'); | 23 | if(error.status === -1) { |
| 24 | return; | 24 | focaModalService.alert('Sin servicio'); |
| 25 | } | 25 | return; |
| 26 | }); | 26 | } |
| 27 | }); | ||
| 27 | }; | 28 | }; |
| 28 | $scope.irPaso = function(numeroPaso) { | 29 | $scope.irPaso = function(numeroPaso) { |
| 29 | $scope.paso = numeroPaso; | 30 | $scope.paso = numeroPaso; |
| 30 | }; | 31 | }; |
| 31 | } | 32 | } |
| 32 | ]) | 33 | ]) |
| 33 | .controller('focaLogoutController', [ | 34 | .controller('focaLogoutController', [ |
| 34 | '$cookies', '$location', | 35 | '$cookies', '$location', |
| 35 | function($cookies, $location) { | 36 | function($cookies, $location) { |
| 36 | $cookies.remove('idUsuario'); | 37 | $cookies.remove('chofer'); |
| 38 | $cookies.remove('vendedorCobrador'); | ||
| 37 | $cookies.remove('token'); | 39 | $cookies.remove('token'); |
| 38 | //Cierra ventana | 40 | //Cierra ventana |
| 39 | window.open('', '_self', ''); //bug fix | 41 | window.open('', '_self', ''); //bug fix |
| 40 | window.close(); | 42 | window.close(); |
| 41 | $location.path('/login'); | 43 | $location.path('/login'); |
| 42 | } | 44 | } |
| 43 | ]); | 45 | ]); |
| 44 | 46 |
src/js/service.js
| 1 | angular.module('focaLogin') | 1 | angular.module('focaLogin') |
| 2 | .service('focaLoginService', [ | 2 | .service('focaLoginService', [ |
| 3 | '$http', 'API_ENDPOINT', | 3 | '$http', 'API_ENDPOINT', 'APP', |
| 4 | function($http, API_ENDPOINT) { | 4 | function($http, API_ENDPOINT, APP) { |
| 5 | return { | 5 | return { |
| 6 | login: function(usuario) { | 6 | login: function(usuario) { |
| 7 | return $http.post(API_ENDPOINT.URL + '/usuario/login', usuario); | 7 | if (APP) { |
| 8 | APP = '/' + APP; | ||
| 9 | } | ||
| 10 | |||
| 11 | return $http.post(API_ENDPOINT.URL + '/usuario/login' + APP , usuario); | ||
| 8 | } | 12 | } |
| 9 | }; | 13 | }; |
| 10 | } | 14 | } |
| 11 | ]); | 15 | ]); |
| 12 | 16 |