From 8937dda11435b8baff14fea69ee20ba894585ea4 Mon Sep 17 00:00:00 2001 From: Jose Pinto Date: Tue, 22 Jan 2019 15:54:18 -0300 Subject: [PATCH] Primera version --- .gitignore | 5 +++ .jshintrc | 64 +++++++++++++++++++++++++++++++++ gulpfile.js | 81 ++++++++++++++++++++++++++++++++++++++++++ index.html | 38 ++++++++++++++++++++ package.json | 61 +++++++++++++++++++++++++++++++ src/etc/develop.js.ejemplo | 4 +++ src/js/app.js | 5 +++ src/js/controller.js | 45 +++++++++++++++++++++++ src/js/osm-directive.js | 43 ++++++++++++++++++++++ src/js/service.js | 12 +++++++ src/views/modal-localizar.html | 46 ++++++++++++++++++++++++ 11 files changed, 404 insertions(+) create mode 100644 .gitignore create mode 100644 .jshintrc create mode 100644 gulpfile.js create mode 100644 index.html create mode 100644 package.json create mode 100644 src/etc/develop.js.ejemplo create mode 100644 src/js/app.js create mode 100644 src/js/controller.js create mode 100644 src/js/osm-directive.js create mode 100644 src/js/service.js create mode 100644 src/views/modal-localizar.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44f11df --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/node_modules +/dist +/tmp +package-lock\.json +src/etc/develop\.js 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..ac4432a --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,81 @@ +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), + htmlmin(), + templateCache('views.js', { + module: 'focaModalLocalizar', + root: '' + }), + gulp.dest(paths.tmp) + ] + ); +}); + +gulp.task('uglify', ['templates'], function() { + return pump( + [ + gulp.src([ + paths.srcJS, + 'tmp/views.js' + ]), + concat('foca-modal-localizar.js'), + replace('src/views/', ''), + replace("['ui.bootstrap', 'focaDirectivas']", '[]'), + gulp.dest(paths.tmp), + rename('foca-modal-localizar.min.js'), + uglify(), + gulp.dest(paths.dist) + ] + ); +}); + +gulp.task('pre-commit', function() { + return pump( + [ + gulp.src(paths.srcJS), + jshint('.jshintrc'), + jshint.reporter('default'), + jshint.reporter('fail') + ] + ); + + gulp.start('uglify'); +}); + +gulp.task('webserver', function() { + pump [ + connect.server({port: 3000}) + ] +}); + +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('default', ['webserver']); + +gulp.task('watch', function() { + gulp.watch([paths.srcJS, paths.srcViews], ['uglify']) +}); diff --git a/index.html b/index.html new file mode 100644 index 0000000..8238d91 --- /dev/null +++ b/index.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/package.json b/package.json new file mode 100644 index 0000000..cb71eb5 --- /dev/null +++ b/package.json @@ -0,0 +1,61 @@ +{ + "name": "foca-modal-localizar", + "version": "0.0.1", + "description": "Modal para localizar domicilio", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "gulp-pre-commit": "gulp pre-commit", + "compile": "gulp uglify", + "postinstall": "npm run compile && gulp clean-post-install", + "install-dev": "npm install -D angular bootstrap font-awesome gulp gulp-angular-templatecache gulp-concat gulp-connect gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify gulp-clean jasmine-core jquery jshint pre-commit pump ui-bootstrap4 && npm i -D git+http://git.focasoftware.com/npm/foca-directivas.git" + }, + "pre-commit": [ + "gulp-pre-commit" + ], + "repository": { + "type": "git", + "url": "https://debo.suite.repo/modulos-npm/foca-modal-localizar.git" + }, + "author": "Foca Software", + "license": "ISC", + "peerDependencies": { + "angular": "^1.7.4", + "bootstrap": "^4.1.3", + "font-awesome": "^4.7.0", + "ui-bootstrap4": "^3.0.4", + "gulp": "^3.9.1", + "gulp-angular-templatecache": "^2.2.1", + "gulp-concat": "^2.6.1", + "gulp-connect": "^5.6.1", + "gulp-htmlmin": "^5.0.1", + "gulp-rename": "^1.4.0", + "gulp-replace": "^1.0.0", + "gulp-uglify": "^3.0.1", + "jquery": "^3.3.1", + "pump": "^3.0.0", + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git" + }, + "devDependencies": { + "angular": "^1.7.5", + "bootstrap": "^4.1.3", + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", + "font-awesome": "^4.7.0", + "gulp": "^3.9.1", + "gulp-angular-templatecache": "^2.2.3", + "gulp-clean": "^0.4.0", + "gulp-concat": "^2.6.1", + "gulp-connect": "^5.6.1", + "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", + "jasmine-core": "^3.3.0", + "jquery": "^3.3.1", + "jshint": "^2.9.6", + "leaflet": "^1.3.4", + "pre-commit": "^1.2.2", + "pump": "^3.0.0", + "ui-bootstrap4": "^3.0.5" + } +} diff --git a/src/etc/develop.js.ejemplo b/src/etc/develop.js.ejemplo new file mode 100644 index 0000000..0bfc3c9 --- /dev/null +++ b/src/etc/develop.js.ejemplo @@ -0,0 +1,4 @@ +angular.module('focaModalLocalizar') + .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..2a9aba7 --- /dev/null +++ b/src/js/app.js @@ -0,0 +1,5 @@ +angular.module('focaModalLocalizar', [ + 'ui.bootstrap', + 'focaDirectivas', + 'focaModal' +]); diff --git a/src/js/controller.js b/src/js/controller.js new file mode 100644 index 0000000..58a91aa --- /dev/null +++ b/src/js/controller.js @@ -0,0 +1,45 @@ +angular.module('focaModalLocalizar') + .controller('focaModalLocalizarController', + [ + '$scope', + '$uibModalInstance', + 'focaModalLocalizarService', + 'direccion', + function($scope, $uibModalInstance, + focaModalLocalizarService, direccion) { + + $scope.latitud = -32.89214159952345; + $scope.longitud = -68.84572999101856; + + if(direccion) { + focaModalLocalizarService + .getLatLng({ + street: direccion.numero + ' ' + direccion.calle, + country: 'Argentina', + city: direccion.provincia, + county: direccion.localidad, + format: 'json' + }) + .then(function(res) { + $scope.latitud = res.data[0].lat; + $scope.longitud = res.data[0].lon; + $scope.$broadcast('moveMap', { + latitud: $scope.latitud, + longitud: $scope.longitud + }); + }); + } + + $scope.cancel = function() { + $uibModalInstance.dismiss(); + }; + + $scope.aceptar = function() { + $uibModalInstance.close({ + latitud: $scope.latitud, + longitud: $scope.longitud + }); + }; + } + ] + ); diff --git a/src/js/osm-directive.js b/src/js/osm-directive.js new file mode 100644 index 0000000..3f02ad5 --- /dev/null +++ b/src/js/osm-directive.js @@ -0,0 +1,43 @@ +angular.module('focaModalLocalizar').directive('osmDireccion', function() { + return { + restrict: 'E', + link: function(scope, el, attrs) { + var contenedor = document.createElement('div'); + contenedor.className = 'w-100 h-50 mt-3'; + el.append(contenedor); + scope.map = L.map(contenedor).setView([-32.89214159952345, -68.84572999101856], attrs.zoom); + L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(scope.map); + }, + controller: ['$scope', '$timeout', function($scope, $timeout) { + //resuelve bug mapa gris en modales + $timeout(function() { + $scope.map.invalidateSize(); + }, 100); + + $scope.markers = []; + $scope.$watchGroup(['latitud', 'longitud'], function() { + for(var i in $scope.markers) { + $scope.map.removeLayer($scope.markers[i]); + } + $scope.markers.push( + L.marker([$scope.latitud, $scope.longitud], {draggable: true}) + .addTo($scope.map) + .on('dragend', function() { + $scope.latitud = this.getLatLng().lat; + $scope.longitud = this.getLatLng().lng; + $scope.$apply(); + }) + ); + }); + + $scope.$on('moveMap', function(evt, data) { + $scope.map.panTo(new L.LatLng(data.latitud, data.longitud)); + }); + }], + scope: { + latitud: '=', + longitud: '=', + zoom: '=' + } + }; +}); diff --git a/src/js/service.js b/src/js/service.js new file mode 100644 index 0000000..d180d53 --- /dev/null +++ b/src/js/service.js @@ -0,0 +1,12 @@ +angular.module('focaModalLocalizar') + .service('focaModalLocalizarService', [ + '$http', + 'API_ENDPOINT', + function($http, API_ENDPOINT) { + return { + getLatLng: function(direccion) { + return $http.get('https://nominatim.openstreetmap.org/search', {params: direccion}); + } + }; + } + ]); diff --git a/src/views/modal-localizar.html b/src/views/modal-localizar.html new file mode 100644 index 0000000..5e7be74 --- /dev/null +++ b/src/views/modal-localizar.html @@ -0,0 +1,46 @@ + + + -- 1.9.1