diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..851972e --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ + +node_modules/ +tmp/ + +package-lock\.json + +dist/ diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..dd429f7 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,64 @@ +{ + /* + * ENVIRONMENTS + * ================= + */ + + // Define globals exposed by modern browsers. + "browser": true, + + // Define globals exposed by jQuery. + "jquery": true, + + // Define globals exposed by Node.js. + "node": true, + + // Allow ES6. + "esversion": 6, + + /* + * ENFORCING OPTIONS + * ================= + */ + + // Force all variable names to use either camelCase style or UPPER_CASE + // with underscores. + "camelcase": true, + + // Prohibit use of == and != in favor of === and !==. + "eqeqeq": true, + + // Enforce tab width of 2 spaces. + "indent": 4, + + // Prohibit use of a variable before it is defined. + "latedef": true, + + // Enforce line length to 100 characters + "maxlen": 100, + + // Require capitalized names for constructor functions. + "newcap": true, + + // Enforce use of single quotation marks for strings. + "quotmark": "single", + + // Enforce placing 'use strict' at the top function scope + "strict": false, + + // Prohibit use of explicitly undeclared variables. + "undef": true, + + // Warn when variables are defined but never used. + "unused": true, + + // Para que funcione en angular + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], + /* + * RELAXING OPTIONS + * ================= + */ + + // Suppress warnings about == null comparisons. + "eqnull": true +} diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..afdc805 --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,44 @@ +const gulp = require('gulp'); +const concat = require('gulp-concat'); +const rename = require('gulp-rename'); +const uglify = require('gulp-uglify'); +const pump = require('pump'); +const jshint = require('gulp-jshint'); +const replace = require('gulp-replace'); + +var paths = { + srcHTML : 'src/views/*.html', + srcJS : 'src/js/*.js', + confJS : 'src/etc/develop.js', + dist : 'dist/', + temp : 'tmp/', + distHTML : 'dist/views/' +}; + +gulp.task('uglify', function() { + pump( + [ + gulp.src([paths.srcJS, paths.confJS]), + concat('foca-configuracion.js'), + replace('/src/', '/dist/'), + gulp.dest(paths.temp), + rename('foca-configuracion.min.js'), + uglify(), + gulp.dest(paths.dist) + ] + ); +}); + +gulp.task('pre-commit', function() { + pump( + [ + gulp.src(paths.srcJS), + jshint('.jshintrc'), + jshint.reporter('default'), + jshint.reporter('fail') + ] + ); + gulp.start('uglify'); +}); + +gulp.task('default', ['uglify']); diff --git a/package.json b/package.json new file mode 100644 index 0000000..8c2b2da --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "foca-configuracion", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://debo.suite.repo/modulos-npm/foca-configuracion.git" + }, + "author": "Nicolás Guarnieri", + "license": "ISC", + "dependencies": { + "angular": "^1.7.5", + "angular-cookies": "^1.7.5", + "angular-route": "^1.7.5", + "gulp": "^3.9.1", + "gulp-angular-templatecache": "^2.2.3", + "gulp-clean": "^0.4.0", + "gulp-concat": "^2.6.1", + "gulp-jshint": "^2.1.0", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-uglify": "^3.0.1", + "jquery": "^3.3.1", + "jshint": "^2.9.6", + "pre-commit": "^1.2.2", + "pump": "^3.0.0" + } +} diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..a28cbe4 --- /dev/null +++ b/src/js/app.js @@ -0,0 +1,8 @@ +angular.module('focaConfiguracion', []) + .run(['$cookies', 'focaConfiguracionService', function($cookies, focaConfiguracionService) { + if (!$cookies.get("terminalKey")) { + focaConfiguracionService.getHashTerminal().then(function(res) { + $cookies.put('terminalKey', res.data); + }); + } + }]); \ No newline at end of file diff --git a/src/js/config.js b/src/js/config.js new file mode 100644 index 0000000..2555ca0 --- /dev/null +++ b/src/js/config.js @@ -0,0 +1,4 @@ +angular.module('focaConfiguracion') + .config(['$httpProvider', function($httpProvider) { + $httpProvider.interceptors.push('RequestHeadersInterceptor'); + }]); \ No newline at end of file diff --git a/src/js/requestHeadersInterceptor.js b/src/js/requestHeadersInterceptor.js new file mode 100644 index 0000000..c304483 --- /dev/null +++ b/src/js/requestHeadersInterceptor.js @@ -0,0 +1,13 @@ +angular.module('focaConfiguracion') + .factory("RequestHeadersInterceptor", [ + '$cookies', function($cookies) { + var request = { + request: function(config) { + config.headers["X-Terminal-Key"] = $cookies.get("terminalKey"); + return config; + } + } + + return request; + } + ]); \ No newline at end of file diff --git a/src/js/service.js b/src/js/service.js new file mode 100644 index 0000000..6860da1 --- /dev/null +++ b/src/js/service.js @@ -0,0 +1,11 @@ +angular.module('focaConfiguracion') + .factory("focaConfiguracionService", [ + '$http', '$cookies', '$q', 'API_ENDPOINT', + function($http, $cookies, $q, API_ENDPOINT) { + return { + getHashTerminal: function() { + return $http.get(API_ENDPOINT.URL + '/config/terminal'); + } + } + } + ]); \ No newline at end of file