Commit 3527909b24d6f2f3a24e51738f5d29af4e7a96aa
1 parent
c91d8307b3
Exists in
master
primera versión
Showing
5 changed files
with
259 additions
and
0 deletions
Show diff stats
.gitignore
.jshintrc
| ... | ... | @@ -0,0 +1,64 @@ |
| 1 | +{ | |
| 2 | + /* | |
| 3 | + * ENVIRONMENTS | |
| 4 | + * ================= | |
| 5 | + */ | |
| 6 | + | |
| 7 | + // Define globals exposed by modern browsers. | |
| 8 | + "browser": true, | |
| 9 | + | |
| 10 | + // Define globals exposed by jQuery. | |
| 11 | + "jquery": true, | |
| 12 | + | |
| 13 | + // Define globals exposed by Node.js. | |
| 14 | + "node": true, | |
| 15 | + | |
| 16 | + // Allow ES6. | |
| 17 | + "esversion": 6, | |
| 18 | + | |
| 19 | + /* | |
| 20 | + * ENFORCING OPTIONS | |
| 21 | + * ================= | |
| 22 | + */ | |
| 23 | + | |
| 24 | + // Force all variable names to use either camelCase style or UPPER_CASE | |
| 25 | + // with underscores. | |
| 26 | + "camelcase": true, | |
| 27 | + | |
| 28 | + // Prohibit use of == and != in favor of === and !==. | |
| 29 | + "eqeqeq": true, | |
| 30 | + | |
| 31 | + // Enforce tab width of 2 spaces. | |
| 32 | + "indent": 4, | |
| 33 | + | |
| 34 | + // Prohibit use of a variable before it is defined. | |
| 35 | + "latedef": true, | |
| 36 | + | |
| 37 | + // Enforce line length to 100 characters | |
| 38 | + "maxlen": 100, | |
| 39 | + | |
| 40 | + // Require capitalized names for constructor functions. | |
| 41 | + "newcap": true, | |
| 42 | + | |
| 43 | + // Enforce use of single quotation marks for strings. | |
| 44 | + "quotmark": "single", | |
| 45 | + | |
| 46 | + // Enforce placing 'use strict' at the top function scope | |
| 47 | + "strict": false, | |
| 48 | + | |
| 49 | + // Prohibit use of explicitly undeclared variables. | |
| 50 | + "undef": true, | |
| 51 | + | |
| 52 | + // Warn when variables are defined but never used. | |
| 53 | + "unused": true, | |
| 54 | + | |
| 55 | + // Para que funcione en angular | |
| 56 | + "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], | |
| 57 | + /* | |
| 58 | + * RELAXING OPTIONS | |
| 59 | + * ================= | |
| 60 | + */ | |
| 61 | + | |
| 62 | + // Suppress warnings about == null comparisons. | |
| 63 | + "eqnull": true | |
| 64 | +} |
gulpfile.js
| ... | ... | @@ -0,0 +1,83 @@ |
| 1 | +const clean = require('gulp-clean'); | |
| 2 | +const concat = require('gulp-concat'); | |
| 3 | +const connect = require('gulp-connect'); | |
| 4 | +const gulp = require('gulp'); | |
| 5 | +const htmlmin = require('gulp-htmlmin'); | |
| 6 | +const jshint = require('gulp-jshint'); | |
| 7 | +const pump = require('pump'); | |
| 8 | +const rename = require('gulp-rename'); | |
| 9 | +const replace = require('gulp-replace'); | |
| 10 | +const templateCache = require('gulp-angular-templatecache'); | |
| 11 | +const uglify = require('gulp-uglify'); | |
| 12 | + | |
| 13 | +var paths = { | |
| 14 | + srcJS: 'src/js/*.js', | |
| 15 | + srcViews: 'src/views/*.html', | |
| 16 | + tmp: 'tmp', | |
| 17 | + dist: 'dist/' | |
| 18 | +}; | |
| 19 | + | |
| 20 | +gulp.task('templates', ['clean'], function() { | |
| 21 | + return pump( | |
| 22 | + [ | |
| 23 | + gulp.src(paths.srcViews), | |
| 24 | + htmlmin(), | |
| 25 | + templateCache('views.js', { | |
| 26 | + module: 'focaSqlite', | |
| 27 | + root: '' | |
| 28 | + }), | |
| 29 | + gulp.dest(paths.tmp) | |
| 30 | + ] | |
| 31 | + ); | |
| 32 | +}); | |
| 33 | + | |
| 34 | +gulp.task('uglify', ['templates'], function() { | |
| 35 | + return pump( | |
| 36 | + [ | |
| 37 | + gulp.src([ | |
| 38 | + paths.srcJS, | |
| 39 | + 'tmp/views.js' | |
| 40 | + ]), | |
| 41 | + concat('foca-focaSqlite.js'), | |
| 42 | + replace('src/views/', ''), | |
| 43 | + gulp.dest(paths.tmp), | |
| 44 | + rename('foca-focaSqlite.min.js'), | |
| 45 | + uglify(), | |
| 46 | + gulp.dest(paths.dist) | |
| 47 | + ] | |
| 48 | + ); | |
| 49 | +}); | |
| 50 | + | |
| 51 | +gulp.task('clean', function() { | |
| 52 | + return gulp.src(['tmp', 'dist'], {read: false}) | |
| 53 | + .pipe(clean()); | |
| 54 | +}); | |
| 55 | + | |
| 56 | +gulp.task('pre-commit', function() { | |
| 57 | + pump( | |
| 58 | + [ | |
| 59 | + gulp.src(paths.srcJS), | |
| 60 | + jshint('.jshintrc'), | |
| 61 | + jshint.reporter('default'), | |
| 62 | + jshint.reporter('fail') | |
| 63 | + ] | |
| 64 | + ); | |
| 65 | +}); | |
| 66 | + | |
| 67 | +gulp.task('clean-post-install', function() { | |
| 68 | + return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | |
| 69 | + 'index.html'], {read: false}) | |
| 70 | + .pipe(clean()); | |
| 71 | +}); | |
| 72 | + | |
| 73 | +gulp.task('webserver', function() { | |
| 74 | + pump [ | |
| 75 | + connect.server({port: 3000}) | |
| 76 | + ] | |
| 77 | +}); | |
| 78 | + | |
| 79 | +gulp.task('default', ['webserver']); | |
| 80 | + | |
| 81 | +gulp.task('watch', function() { | |
| 82 | + return gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); | |
| 83 | +}); |
package.json
| ... | ... | @@ -0,0 +1,57 @@ |
| 1 | +{ | |
| 2 | + "name": "foca-sqlite", | |
| 3 | + "version": "0.0.1", | |
| 4 | + "description": "servicios para guardar en sqlite", | |
| 5 | + "main": "dist/foca-sqlite.js", | |
| 6 | + "scripts": { | |
| 7 | + "test": "echo \"Error: no test specified\" && exit 1", | |
| 8 | + "gulp-pre-commit": "gulp pre-commit", | |
| 9 | + "postinstall": "gulp uglify && gulp clean-post-install", | |
| 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" | |
| 11 | + }, | |
| 12 | + "pre-commit": [ | |
| 13 | + "gulp-pre-commit" | |
| 14 | + ], | |
| 15 | + "repository": { | |
| 16 | + "type": "git", | |
| 17 | + "url": "http://git.focasoftware.com/npm/foca-sqlite.git" | |
| 18 | + }, | |
| 19 | + "author": "Foca Software", | |
| 20 | + "license": "ISC", | |
| 21 | + "peerDependencies": { | |
| 22 | + "angular": "^1.7.x", | |
| 23 | + "bootstrap": "^4.1.x", | |
| 24 | + "jquery": "^3.3.x", | |
| 25 | + "font-awesome": "^4.7.x", | |
| 26 | + "gulp": "^3.9.x", | |
| 27 | + "gulp-concat": "2.6.x", | |
| 28 | + "gulp-jshint": "^2.1.x", | |
| 29 | + "gulp-rename": "^1.4.x", | |
| 30 | + "gulp-replace": "^1.0.x", | |
| 31 | + "gulp-uglify-es": "^1.0.x", | |
| 32 | + "jshint": "^2.9.x", | |
| 33 | + "pump": "^3.0.x" | |
| 34 | + }, | |
| 35 | + "devDependencies": { | |
| 36 | + "angular": "^1.7.6", | |
| 37 | + "angular-cookies": "^1.7.6", | |
| 38 | + "angular-route": "^1.7.6", | |
| 39 | + "bootstrap": "^4.2.1", | |
| 40 | + "font-awesome": "^4.7.0", | |
| 41 | + "gulp": "^3.9.1", | |
| 42 | + "gulp-angular-templatecache": "^2.2.6", | |
| 43 | + "gulp-clean": "^0.4.0", | |
| 44 | + "gulp-connect": "^5.7.0", | |
| 45 | + "gulp-htmlmin": "^5.0.1", | |
| 46 | + "gulp-jshint": "^2.1.0", | |
| 47 | + "gulp-rename": "^1.4.0", | |
| 48 | + "gulp-replace": "^1.0.0", | |
| 49 | + "gulp-sequence": "^1.0.0", | |
| 50 | + "gulp-uglify": "^3.0.1", | |
| 51 | + "jasmine-core": "^3.3.0", | |
| 52 | + "jquery": "^3.3.1", | |
| 53 | + "jshint": "^2.9.7", | |
| 54 | + "pre-commit": "^1.2.2", | |
| 55 | + "pump": "^3.0.0" | |
| 56 | + } | |
| 57 | +} |
src/js/app.js
| ... | ... | @@ -0,0 +1,50 @@ |
| 1 | +angular.module('focaSqlite', []) | |
| 2 | + .factory('focaSqliteService', [ | |
| 3 | + function() { | |
| 4 | + function error(error) { | |
| 5 | + console.log(error); | |
| 1 |
|
|
| 6 | + } | |
| 7 | + return { | |
| 8 | + openDataBase: function() { | |
| 9 | + var db = null; | |
| 10 | + db = window.sqlitePlugin.openDatabase({ | |
| 11 | + name: 'foca.distribuidor', | |
| 12 | + location: 'default', | |
| 13 | + }); | |
| 14 | + this.db = db; | |
| 15 | + var queryCreate = "CREATE TABLE IF NOT EXISTS querys " + | |
| 16 | + "(route text," + | |
| 17 | + "type text," + | |
| 18 | + "body text," + | |
| 19 | + "response text," + | |
| 20 | + "PRIMARY KEY(route, body, type))"; | |
| 21 | + this.db.transaction(function(tx) { | |
| 22 | + tx.executeSql(queryCreate); | |
| 23 | + }, function(error) { | |
| 24 | + console.log(error); | |
| 1 |
|
|
| 25 | + }); | |
| 26 | + }, | |
| 27 | + updateQuery: function(route, body, type, response, success) { | |
| 28 | + var query = 'INSERT OR REPLACE INTO querys (route, type, body, response)' + | |
| 29 | + "VALUES('" + route + "'" + | |
| 30 | + ", '" + type + "'" + | |
| 31 | + ", '" + body + "'" + | |
| 32 | + ", '" + response + "')"; | |
| 33 | + this.db.transaction(function(tx) { | |
| 34 | + tx.executeSql(query); | |
| 35 | + }, function(error) { | |
| 36 | + console.log(error); | |
| 1 |
|
|
| 37 | + }, success) | |
| 38 | + }, | |
| 39 | + getQuery: function(route, body, type, success) { | |
| 40 | + var query= "SELECT * FROM querys " + | |
| 41 | + "WHERE route = '" + route + "'" + | |
| 42 | + " and body = '" + body + "'" + | |
| 43 | + " and type = '" + type + "'"; | |
| 44 | + this.db.executeSql(query, [], function(data) { | |
| 45 | + success(data.rows.item(0).response); | |
| 46 | + }, error); | |
| 47 | + } | |
| 48 | + } | |
| 49 | + } | |
| 50 | + ]); | |