diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d914d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/node_modules +/dist +/tmp +package-lock\.json +src/etc/develop.js +yarn.lock \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..d8cbb07 --- /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": false, + + // 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..b642f0c --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,89 @@ +const templateCache = require('gulp-angular-templatecache'); +const concat = require('gulp-concat'); +const htmlmin = require('gulp-htmlmin'); +const rename = require('gulp-rename'); +const uglify = require('gulp-uglify'); +const gulp = require('gulp'); +const pump = require('pump'); +const jshint = require('gulp-jshint'); +const replace = require('gulp-replace'); +const connect = require('gulp-connect'); +const clean = require('gulp-clean'); + +var paths = { + srcJS: 'src/js/*.js', + srcViews: 'src/views/*.html', + tmp: 'tmp', + dist: 'dist/' +}; + +gulp.task('templates', function() { + return pump( + [ + gulp.src(paths.srcViews), + replace('views/', ''), + htmlmin(), + templateCache('views.js', { + module: 'focaAgendarVisita', + root: '' + }), + gulp.dest(paths.tmp) + ] + ); +}); + +gulp.task('uglify', ['templates'], function() { + return pump( + [ + gulp.src([ + paths.srcJS, + 'tmp/views.js' + ]), + concat('foca-agendar-visita.js'), + replace("['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']", '[]'), + replace("src/views/", ''), + gulp.dest(paths.tmp), + rename('foca-agendar-visita.min.js'), + uglify(), + gulp.dest(paths.dist) + ] + ); +}); + +gulp.task('clean', function() { + return gulp.src(['tmp', 'dist'], {read: false}) + .pipe(clean()); +}); + +gulp.task('pre-commit', function() { + pump( + [ + gulp.src(paths.srcJS), + jshint('.jshintrc'), + jshint.reporter('default'), + jshint.reporter('fail') + ] + ); + + gulp.start('uglify'); +}); + +gulp.task('clean-post-install', function() { + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', + 'index.html'], {read: false}) + .pipe(clean()); +}); + +gulp.task('compile', ['templates', 'uglify']); + +gulp.task('watch', function() { + gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); +}); + +gulp.task('webserver', function() { + pump [ + connect.server({port: 3000}) + ] +}); + +gulp.task('default', ['webserver']); diff --git a/package.json b/package.json new file mode 100644 index 0000000..a4369e7 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "foca-activar-hoja-ruta", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "compile": "gulp uglify", + "gulp-pre-commit": "gulp pre-commit", + "postinstall": "npm run compile && gulp clean-post-install", + "install-dev": "npm install -D jasmine-core pre-commit angular angular-ladda ladda@1.0.6 angular-route bootstrap ui-bootstrap4 font-awesome gulp gulp-angular-templatecache gulp-connect gulp-clean gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-sequence gulp-uglify-es gulp-uglify jquery jshint pump git+ssh://git@debonline.dyndns.org:npm/foca-directivas.git git+ssh://git@debonline.dyndns.org:npm/foca-modal-remito.git" + }, + "pre-commit": [ + "gulp-pre-commit" + ], + "author": "", + "license": "ISC", + "devDependencies": { + "gulp": "^3.9.1", + "gulp-angular-templatecache": "^2.2.6", + "gulp-clean": "^0.4.0", + "gulp-connect": "^5.7.0", + "gulp-htmlmin": "^5.0.1", + "gulp-jshint": "^2.1.0", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-uglify": "^3.0.1", + "jshint": "^2.9.7", + "pre-commit": "^1.2.2", + "pump": "^3.0.0" + } +} diff --git a/src/etc/develop.js.ejemplo b/src/etc/develop.js.ejemplo new file mode 100644 index 0000000..daf2b80 --- /dev/null +++ b/src/etc/develop.js.ejemplo @@ -0,0 +1,4 @@ +angular.module('focaAgendarVisita') + .constant("API_ENDPOINT", { + 'URL': '//127.0.0.1:9000' + }); diff --git a/src/js/app.js b/src/js/app.js new file mode 100644 index 0000000..c5bca8b --- /dev/null +++ b/src/js/app.js @@ -0,0 +1 @@ +angular.module('focaAgendarVisita', ['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']); diff --git a/src/js/controller.js b/src/js/controller.js new file mode 100644 index 0000000..aceb968 --- /dev/null +++ b/src/js/controller.js @@ -0,0 +1,102 @@ +angular.module('focaAgendarVisita') + .controller('focaAgendarVisitaController', [ + '$scope', 'focaAgendarVisitaService', '$location', '$timeout', + '$uibModal', 'focaBotoneraLateralService', '$filter', 'focaLoginService', + 'focaModalService', 'focaSeguimientoService', + function($scope, focaAgendarVisitaService, $location, $timeout, + $uibModal, focaBotoneraLateralService, $filter, focaLoginService, + focaModalService, focaSeguimientoService) { + $scope.focused = 0; + $scope.rol = 1; + $scope.visita = {}; + $scope.now = new Date(); + $scope.botonera = [ + { + label: 'Agendar', + image: 'precios-condiciones.png' + } + ]; + $timeout(function() { + focaBotoneraLateralService.showSalir(true); + focaBotoneraLateralService.showPausar(true); + focaBotoneraLateralService.showGuardar(true, $scope.guardar); + }); + + $scope.seleccionarCliente = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Cliente', + templateUrl: 'foca-busqueda-cliente-modal.html', + controller: 'focaBusquedaClienteModalController', + resolve: { + vendedor: function() { return null; } + }, + size: 'lg' + } + ); + modalInstance.result.then( + function(cliente) { + $scope.visita.cliente = cliente; + } + ); + }; + $scope.seleccionarVisitante = function() { + var parametrosModal = { + query: '/vendedor-cobrador', + columnas: [ + { + propiedad: 'NUM', + nombre: 'Codigo', + filtro: { + nombre: 'rellenarDigitos', + parametro: 3 + } + }, + { + propiedad: 'NOM', + nombre: 'Nombre' + } + ], + titulo:'Búsqueda de vendedores y cobradores', + size: 'md' + }; + focaModalService.modal(parametrosModal).then(function(vendedorCobrador) { + $scope.visita.visitante = vendedorCobrador; + }); + }; + + $scope.next = function(key) { + if (key === 13) $scope.focused ++; + }; + + $scope.guardar = function() { + var rol; + if($scope.visita.visitante.rol === 1){ + rol = 'Nota de pedido'; + } else if($scope.visita.visitante.rol === 2){ + rol = 'Cobranza'; + } else { + rol = ($scope.rol === 1) ? 'Nota de pedido' : 'Cobranza'; + } + + focaAgendarVisitaService + .guardarVisita({ + idVisitante: $scope.visita.visitante.NUM, + tipoVisitante: ($scope.visita.visitante.rol !== 3) ? + $scope.visita.visitante.rol : $scope.rol, + idCliente: $scope.visita.cliente.cod + }) + .then(function(data) { + focaSeguimientoService.guardarPosicion( + rol, + data.data.id, + $scope.visita.observacion, + true + ); + }) + .then(function() { + $location.path('/'); + }); + }; + } + ]); diff --git a/src/js/route.js b/src/js/route.js new file mode 100644 index 0000000..2824ba5 --- /dev/null +++ b/src/js/route.js @@ -0,0 +1,10 @@ +angular.module('focaAgendarVisita') + .config([ + '$routeProvider', + function($routeProvider) { + $routeProvider.when('/visita/agendar', { + controller: 'focaAgendarVisitaController', + templateUrl: 'src/views/agendar-visita.html' + }); + } + ]); diff --git a/src/js/service.js b/src/js/service.js new file mode 100644 index 0000000..0390fa0 --- /dev/null +++ b/src/js/service.js @@ -0,0 +1,8 @@ +angular.module('focaAgendarVisita') + .factory('focaAgendarVisitaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { + return { + guardarVisita: function(visita) { + return $http.post(API_ENDPOINT.URL + '/visita', {visita: visita}); + } + }; + }]); diff --git a/src/views/agendar-visita.html b/src/views/agendar-visita.html new file mode 100644 index 0000000..43692b7 --- /dev/null +++ b/src/views/agendar-visita.html @@ -0,0 +1,85 @@ +
+ +
+
+
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ +
+