Merge pull request #17 from abhshkdz/heroku-integration

Heroku integration
This commit is contained in:
DC*
2014-08-26 19:29:50 -03:00
14 changed files with 116 additions and 60 deletions
+3
View File
@@ -16,3 +16,6 @@ results
npm-debug.log npm-debug.log
node_modules node_modules
*.sqlite
*.env
+1
View File
@@ -0,0 +1 @@
web: node server.js
+14 -2
View File
@@ -6,11 +6,23 @@ An open-source [Workflowy](http://workflowy.com) clone.
##Installation ##Installation
* Edit `config/development.json` to your needs * Edit `config/development.json` and `config/database.json` to your needs
* `npm install` * `npm install`
* Run migrations and initialize the database: `sequelize-cli -m --config config/database.json` and `node db/seed/initial_tasks.js`
* `node server.js` * `node server.js`
##Heroku deploy
You can use our one-click heroku deploy:
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
Or proceed manually as follow:
* heroku create --stack cedar
* heroku addons:add heroku-postgresql:dev
* heroku config:set NODE_ENV=production
* git push heroku heroku-integration:master
##Controls ##Controls
* <kbd>UP</kbd> & <kbd>DOWN</kbd>: navigate through tasks * <kbd>UP</kbd> & <kbd>DOWN</kbd>: navigate through tasks
+13
View File
@@ -0,0 +1,13 @@
{
"name": "HackFlowy",
"description": "Workflowy clone, built using Backbone.js & Socket.io",
"keywords": ["express", "backbone", "socket.io"],
"website": "https://github.com/abhshkdz/HackFlowy",
"repository": "https://github.com/abhshkdz/HackFlowy",
"env": {
"NODE_ENV": "production"
},
"addons": [
"heroku-postgresql"
]
}
+1 -5
View File
@@ -8,10 +8,6 @@
"storage": "db/test.sqlite" "storage": "db/test.sqlite"
}, },
"production": { "production": {
"username": "postgres", "use_env_variable": "DATABASE_URL"
"password": "",
"database": "hackflowy",
"host" : "localhost",
"dialect" : "postgres"
} }
} }
+2 -9
View File
@@ -1,13 +1,6 @@
{ {
"port": 3000, "port": 80,
"database": { "database": {
"username": "postgres", "use_env_variable": "DATABASE_URL"
"password": "",
"database": "hackflowy",
"options" : {
"dialect": "postgres",
"host" : "localhost",
"port" : "5432"
}
} }
} }
+12 -10
View File
@@ -1,14 +1,16 @@
var config = require('config'), var config = require('config'),
orm = require('../../orm').configure(config.get('database')), orm = require('../../orm').configure(config.get('database')),
Tasks = require('../../db/models/task').instance(orm); Tasks = require('../../db/models/task').instance(orm);
Tasks.bulkCreate([ Tasks.destroy().success(function() {
{content: 'Welcome to HackFlowy!', isCompleted: false}, Tasks.bulkCreate([
{content: 'An open-source WorkFlowy clone', isCompleted: false}, {content: 'Welcome to HackFlowy!', isCompleted: false},
{content: 'Built using Backbone + Socket.IO', isCompleted: false}, {content: 'An open-source WorkFlowy clone', isCompleted: false},
{content: 'I pulled this together in a few hours to learn Backbone', isCompleted: false}, {content: 'Built using Backbone + Socket.IO', isCompleted: false},
{content: 'Feel free to try it out and hack on it', isCompleted: false}, {content: 'I pulled this together in a few hours to learn Backbone', isCompleted: false},
{content: 'Good Luck!', isCompleted: false} {content: 'Feel free to try it out and hack on it', isCompleted: false},
]); {content: 'Good Luck!', isCompleted: false}
]);
});
orm.sync(); orm.sync();
+19
View File
@@ -1,7 +1,26 @@
var Sequelize = require('sequelize'); var Sequelize = require('sequelize');
/* http://sequelizejs.com/articles/heroku */
var parseUrl = function(url) {
var match = url.match(/([\w]+):\/\/([^:]+):([^@]+)@([^:]+):(\d+)\/(.+)/);
db = {
database : match[6],
username : match[2],
password : match[3],
options : {
port : match[5],
host : match[4],
dialect : match[1],
}
}
return db;
}
module.exports = { module.exports = {
configure: function(db) { configure: function(db) {
db.url = db.use_env_variable ? process.env[db.use_env_variable] : null;
db = db.url ? parseUrl(db.url) : db;
return new Sequelize(db.database, db.username, db.password, db.options); return new Sequelize(db.database, db.username, db.password, db.options);
} }
} }
+17 -2
View File
@@ -5,10 +5,25 @@
"dependencies": { "dependencies": {
"express": "~3.1.0", "express": "~3.1.0",
"path": "~0.4.9", "path": "~0.4.9",
"mysql": "~2.0.0", "pg": "~3.4.1",
"sqlite3": "~2.1.0",
"sequelize": "~1.7.9", "sequelize": "~1.7.9",
"socket.io": "~1.0.6", "socket.io": "~1.0.6",
"config": "~1.0.2" "config": "~1.0.2"
},
"devDependencies": {
"sqlite3": "~2.1.0"
},
"engines": {
"node": "0.10.x"
},
"scripts": {
"start": "node server.js",
"db:migrate": "./node_modules/sequelize/bin/sequelize -m --config config/database.json",
"db:seed": "node db/seed/initial_tasks.js",
"postinstall": "npm run db:migrate && npm run db:seed"
},
"repository": {
"type": "git",
"url": "git://github.com/abhshkdz/HackFlowy.git"
} }
} }
+5 -5
View File
@@ -9,20 +9,20 @@ Backbone
var TaskModel = Backbone.Model.extend({ var TaskModel = Backbone.Model.extend({
defaults: { defaults: {
parent_id: '', parent: 0,
content: '', content: '',
is_completed:'n' isCompleted: 0
}, },
toggelCompletedStatus:function(isCompleted){ toggelCompletedStatus:function(isCompleted){
var prev_isCompleted = isCompleted, var prev_isCompleted = isCompleted,
self = this; self = this;
this.save({'is_completed':isCompleted}, this.save({'isCompleted':isCompleted},
{ {
success:function(){}, success:function(){},
error:function(){ error:function(){
//REVERT BACK ON ERROR //REVERT BACK ON ERROR
self.set({'is_completed':prev_isCompleted}); self.set({'isCompleted':prev_isCompleted});
} }
}) })
} }
@@ -31,4 +31,4 @@ Backbone
return TaskModel; return TaskModel;
}); });
+2 -2
View File
@@ -37,8 +37,8 @@ TaskView
model: task model: task
}); });
var a = taskView.render(); var a = taskView.render();
if (a.model.get('parent_id')!=0) if (a.model.get('parent')!=0)
a.$el.insertAfter($('*[data-id="'+a.model.get('parent_id')+'"]').parents('li:first')); a.$el.insertAfter($('*[data-id="'+a.model.get('parent')+'"]').parents('li:first'));
else else
this.$el.append(a.el); this.$el.append(a.el);
} }
+19 -19
View File
@@ -38,7 +38,7 @@ taskTemplate
var task = this; var task = this;
this.socket.on('task', function(data){ this.socket.on('task', function(data){
if (task.model.id == data.id) { if (task.model.id == data.id) {
task.model.set({'content':data.content, 'is_completed':data.is_completed}); task.model.set({'content':data.content, 'isCompleted':data.isCompleted});
} }
}); });
}, },
@@ -47,9 +47,9 @@ taskTemplate
var tmpl = _.template(this.template); var tmpl = _.template(this.template);
var task = this; var task = this;
this.$el.html(tmpl({model:this.model.toJSON()})); this.$el.html(tmpl({model:this.model.toJSON()}));
if (this.model.get('parent_id')!=0) { if (this.model.get('parentId')!=0) {
this.$el.addClass('shift1'); this.$el.addClass('shift1');
var className = $('*[data-id="'+this.model.get('parent_id')+'"]').parents('li:first').attr('class'); var className = $('*[data-id="'+this.model.get('parentId')+'"]').parents('li:first').attr('class');
if (className!=undefined && className!=0 && className.substring(0,5) == 'shift') { if (className!=undefined && className!=0 && className.substring(0,5) == 'shift') {
this.$el.removeClass(); this.$el.removeClass();
this.$el.addClass('shift' + (parseInt(className.charAt(5))+1)); this.$el.addClass('shift' + (parseInt(className.charAt(5))+1));
@@ -74,31 +74,31 @@ taskTemplate
if (e.shiftKey && e.keyCode == 9) { if (e.shiftKey && e.keyCode == 9) {
var model = this.$el.next('li').find('input').data('id'); var model = this.$el.next('li').find('input').data('id');
model = Tasks.get(model); model = Tasks.get(model);
var old_parent = model.get('parent_id'); var old_parent = model.get('parentId');
old_parent = Tasks.get(old_parent); old_parent = Tasks.get(old_parent);
var new_parent = old_parent.get('parent_id'); var new_parent = old_parent.get('parentId');
if (new_parent == null) new_parent = 0; if (new_parent == null) new_parent = 0;
model.set('parent_id',new_parent); model.set('parentId',new_parent);
model.save({content: model.get('content'), parent_id: model.get('parent_id')}); model.save({content: model.get('content'), parentId: model.get('parentId')});
} }
else if (e.keyCode == 9) { else if (e.keyCode == 9) {
var parent = this.$el.prev('li').prev('li').find('input').data('id'); var parent = this.$el.prev('li').prev('li').find('input').data('id');
var current = this.$el.prev('li').find('input').data('id'); var current = this.$el.prev('li').find('input').data('id');
var model = Tasks.get(current); var model = Tasks.get(current);
model.set('parent_id',parent); model.set('parentId',parent);
model.save({content: model.get('content'), parent_id: model.get('parent_id')}); model.save({content: model.get('content'), parentId: model.get('parentId')});
} }
this.socket.emit('task', { this.socket.emit('task', {
id: this.model.id, id: this.model.id,
parent_id: this.model.parent_id, parentId: this.model.parentId,
content: this.$input.val().trim(), content: this.$input.val().trim(),
is_completed:this.model.toJSON().is_completed isCompleted:this.model.toJSON().isCompleted
}); });
}, },
update: function(e) { update: function(e) {
if ( e.which === constants.ENTER_KEY ) { if ( e.which === constants.ENTER_KEY ) {
Tasks.add({content:'', parent_id: this.model.get('parent_id')}); Tasks.add({content:'', parentId: this.model.get('parentId')});
this.$input.blur(); this.$input.blur();
this.$el.next('li').find('input').focus(); this.$el.next('li').find('input').focus();
} }
@@ -110,7 +110,7 @@ taskTemplate
this.model.destroy(); this.model.destroy();
} }
else { else {
this.model.save({content: value, parent_id: this.model.attributes.parent_id}); this.model.save({content: value, parentId: this.model.attributes.parentId});
} }
this.$el.removeClass('editing'); this.$el.removeClass('editing');
}, },
@@ -124,22 +124,22 @@ taskTemplate
}, },
markComplete:function(){ markComplete:function(){
this.model.toggelCompletedStatus('Y'); this.model.toggelCompletedStatus(true);
this.socket.emit('task', { this.socket.emit('task', {
id: this.model.id, id: this.model.id,
parent_id: this.model.parent_id, parentId: this.model.parentId,
content:this.model.toJSON().content, content:this.model.toJSON().content,
is_completed: this.model.toJSON().is_completed isCompleted: this.model.toJSON().isCompleted
}); });
}, },
unmarkComlete:function(){ unmarkComlete:function(){
this.model.toggelCompletedStatus('N'); this.model.toggelCompletedStatus(false);
this.socket.emit('task', { this.socket.emit('task', {
id: this.model.id, id: this.model.id,
parent_id: this.model.parent_id, parentId: this.model.parentId,
content:this.model.toJSON().content, content:this.model.toJSON().content,
is_completed: this.model.toJSON().is_completed isCompleted: this.model.toJSON().isCompleted
}); });
}, },
+2 -2
View File
@@ -4,7 +4,7 @@
<div class="options"> <div class="options">
<div class="options-left"> <div class="options-left">
<div class="mouse-tip"></div> <div class="mouse-tip"></div>
<% if(model.is_completed=='Y'){%> <% if(model.isCompleted){%>
<a class="uncomplete">Uncomplete<hr></a> <a class="uncomplete">Uncomplete<hr></a>
<%}else {%> <%}else {%>
<a class="complete">Complete<hr></a> <a class="complete">Complete<hr></a>
@@ -16,7 +16,7 @@
</div> </div>
</div> </div>
<% if(model.is_completed=='Y'){%> <% if(model.isCompleted){%>
<input value="<%= model.content %>" data-id="<%= model.id %>" class="edit task-completed"> <input value="<%= model.content %>" data-id="<%= model.id %>" class="edit task-completed">
<%}else {%> <%}else {%>
<input value="<%= model.content %>" data-id="<%= model.id %>" class="edit"> <input value="<%= model.content %>" data-id="<%= model.id %>" class="edit">
+6 -4
View File
@@ -16,8 +16,9 @@ app.configure(function() {
app.use(express.errorHandler({dumpExceptions: true, showStack: true})); app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
}); });
server.listen(config.get('port'), function() { var port = process.env.PORT || config.get('port');
console.log( 'Express server listening on port %d in %s mode', config.get('port'), app.settings.env ); server.listen(port, function() {
console.log( 'Express server listening on port %d in %s mode', port, app.settings.env );
}); });
app.get('/tasks', function(req,res){ app.get('/tasks', function(req,res){
@@ -29,7 +30,7 @@ app.get('/tasks', function(req,res){
app.post('/tasks', function(req,res){ app.post('/tasks', function(req,res){
Tasks.create({ Tasks.create({
content: req.body.content, content: req.body.content,
parent: req.body.parent_id, parent: parseInt(req.body.parent) || 0,
isCompleted: false isCompleted: false
}).success(function(task){ }).success(function(task){
res.send(task); res.send(task);
@@ -40,7 +41,8 @@ app.put('/tasks/:id', function(req,res){
console.log(req.body.isCompleted); console.log(req.body.isCompleted);
Tasks.find(req.params.id).success(function(task){ Tasks.find(req.params.id).success(function(task){
task.content = req.body.content; task.content = req.body.content;
task.isCompleted = req.body.isCompleted; task.parent = parseInt(req.body.parent) || 0,
task.isCompleted = req.body.isCompleted == 1;
task.save().success(function(task){ task.save().success(function(task){
res.send(task); res.send(task);
}) })