diff --git a/readme.md b/readme.md index 0e14d02..4068a74 100644 --- a/readme.md +++ b/readme.md @@ -107,8 +107,8 @@ On Windows one needs to use [Git Bash](https://git-scm.com/download/win) or equi ## Running in development environment on localhost You will also need to copy the Thali_CordovaPlugin 'mockmobile.js' script if you want run in development mode. This allows native methods to be called on the desktop when UX testing the web app. ``` -git clone https://github.com/thaliproject/Thali_CordovaPlugin.git -cp -v Thali_CordovaPlugin/test/www/jxcore/bv_tests/mockmobile.js postcardapp/www/jxcore/node_modules/thali/ +cd www/jxcore +cp -v ../../thaliDontCheckIn/Thali_CordovaPlugin-master/test/www/jxcore/bv_tests/mockmobile.js node_modules/thali/ ``` # Fun issues you are probably going to run into diff --git a/www/jxcore/app.js b/www/jxcore/app.js index 811bbb6..0a79535 100644 --- a/www/jxcore/app.js +++ b/www/jxcore/app.js @@ -15,8 +15,17 @@ var dbPath = path.join(os.tmpdir(), 'dbPath'); var env = process.env.NODE_ENV || 'production'; // default to production if ('development' === env) { - console.log('localhost "' + app.get('env') + '" environment'); - var Mobile = require('thali/mockmobile.js'); + console.log('localhost "' + app.get('env') + '" environment. ' + dbPath); + //var mockMobile = require('thali/mockmobile.js'); // uncomment for localhost testing +} else if (process.platform === 'ios' || process.platform === 'android') { + Mobile.getDocumentsPath(function(err, location) { + if (err) { + console.error("Error", err); + } else { + dbPath = path.join(location, 'dbPath'); + console.log("Mobile Documents dbPath location: ", dbPath); + } + }); } var LevelDownPouchDB = process.platform === 'android' || process.platform === 'ios' ? @@ -54,7 +63,7 @@ var server = app.listen(5000, function () { console.log('Express server started. (port: 5000)'); var manager = new ThaliReplicationManager(db); - manager.start(5000, 'thali'); + manager.start(String(Math.floor(Math.random() * 100)), 5000, 'thali'); // manager.start(5000, 'thali'); }); @@ -64,7 +73,7 @@ db.changes({ live: true }).on('change', cardChanged); var io = require('socket.io')(server); -function cardChanged(e){ - console.log('card #' + e.id + ' changed'); - io.emit('cardChanged', e ); +function cardChanged(e) { + console.log('card #' + e.id + ' changed'); + io.emit('cardChanged', e ); } diff --git a/www/jxcore/bower.json b/www/jxcore/bower.json index 7a57ff2..f2815d7 100644 --- a/www/jxcore/bower.json +++ b/www/jxcore/bower.json @@ -10,13 +10,13 @@ "tests" ], "dependencies": { - "iron-elements": "PolymerElements/iron-elements#~1.0.3", - "jquery": "~2.1.4", - "moment": "~2.10.6", - "neon-animation": "PolymerElements/neon-animation#~1.0.6", - "node-uuid": "~1.4.3", - "page.js": "~1.6.3", - "paper-elements": "PolymerElements/paper-elements#~1.0.4", - "underscore": "~1.8.3" + "iron-elements": "PolymerElements/iron-elements#1.0.4", + "jquery": "2.1.4", + "moment": "2.10.6", + "neon-animation": "PolymerElements/neon-animation#1.0.7", + "node-uuid": "1.4.3", + "page.js": "1.6.3", + "paper-elements": "PolymerElements/paper-elements#1.0.5", + "underscore": "1.8.3" } } diff --git a/www/jxcore/cardroutes.js b/www/jxcore/cardroutes.js index c276873..722eb84 100644 --- a/www/jxcore/cardroutes.js +++ b/www/jxcore/cardroutes.js @@ -5,13 +5,19 @@ function routes (db) { // Save / update user record cardRouter.route('/login').post(function(req, res) { - var username = req.body.username.trim(); res.setHeader('Content-Type', 'application/json'); + // form validation + if (typeof req.body.username === 'undefined') { + res.send(JSON.stringify({ error: 'Username is undefined' })); + return; + } // user input validation - if (username.length <= 0) { + var username = req.body.username.trim(); + if (username.trim().length <= 0) { res.send(JSON.stringify({ error: 'Username is required' })); return; } + console.log("hello", username); // send reponse db.get('me') .then(function(doc){ @@ -90,8 +96,8 @@ function routes (db) { if (err && err.status === 404) { db.put({ - _id: req.params.cardId, - author: req.body.author, + _id: req.params.cardId, + author: req.body.author, content: req.body.content, dateCreated: new Date().getTime() }) @@ -131,10 +137,10 @@ function routes (db) { res.status(err.status || 500).send(err.message || err); }); } - }) + }); }); return cardRouter; -}; +} -module.exports = routes; \ No newline at end of file +module.exports = routes; diff --git a/www/jxcore/package.json b/www/jxcore/package.json index 271466b..69054a2 100644 --- a/www/jxcore/package.json +++ b/www/jxcore/package.json @@ -8,15 +8,17 @@ "ejs-locals": "^1.0.2", "express": "^4.13.0", "express-pouchdb": "^0.14.2", - "leveldown": "^1.3.0", + "leveldown": "1.4.1", "leveldown-mobile": "^1.0.7", - "pouchdb": "^3.6.0", + "pouchdb": "5.0.0", "socket.io": "^1.3.6", "thali": "^1.0.22" }, "author": "", "license": "MIT", "scripts": { - "start": "NODE_ENV=development nodemon ./app.js" + "start": "NODE_ENV=development jx ./app.js" } } + + \ No newline at end of file diff --git a/www/jxcore/public/elements/page-login/page-login.html b/www/jxcore/public/elements/page-login/page-login.html index df58a16..3410f6f 100644 --- a/www/jxcore/public/elements/page-login/page-login.html +++ b/www/jxcore/public/elements/page-login/page-login.html @@ -4,7 +4,7 @@