Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
Merge pull request #57 from thaliproject/story_0_dadougla
Browse files Browse the repository at this point in the history
Story 0 dadougla
  • Loading branch information
mpodwysocki committed Oct 21, 2015
2 parents 4784b5a + d485db4 commit 3f40d98
Showing 6 changed files with 50 additions and 30 deletions.
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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
21 changes: 15 additions & 6 deletions www/jxcore/app.js
Original file line number Diff line number Diff line change
@@ -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 );
}
16 changes: 8 additions & 8 deletions www/jxcore/bower.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
20 changes: 13 additions & 7 deletions www/jxcore/cardroutes.js
Original file line number Diff line number Diff line change
@@ -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;
module.exports = routes;
8 changes: 5 additions & 3 deletions www/jxcore/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}


11 changes: 7 additions & 4 deletions www/jxcore/public/elements/page-login/page-login.html
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
<dom-module id="page-login">

<template>
<form is="iron-form" id="form-login" method="post" action="/api/login" class="inset" hidden>
<form is="iron-form" id="form-login" method="POST" action="/api/login" class="inset" hidden>
<paper-input name="username" label="Username" bind-value="{{username::input}}" error-message="{{error_username}}" required></paper-input>
<div class="alignCenter">
<paper-button class="accent" raised on-click="submitForm">Save</paper-button>
@@ -93,14 +93,17 @@ <h1>loading&hellip;</h1>
console.log("Form was submitted");
},
_formResponse: function(e) {
console.log("Server Response: ", e.detail);
console.log("Server Response");
// check server response
if(e.detail && e.detail.user) {
console.log("save username: " + e.detail.user);
console.log("Save username: " + e.detail.user);
myApp.username = e.detail.user; //this.username;
getURL("home");
} else {
alert("Error, unable to save user session. Please try again.");
var user = this.username.trim();
console.log("Error, unable to verify response data. Using user name: " + user);
myApp.username = user;
getURL("home");
}
},
_formError: function(e) {

0 comments on commit 3f40d98

Please sign in to comment.