Skip to content

Commit

Permalink
added message model
Browse files Browse the repository at this point in the history
  • Loading branch information
marksupalla committed Sep 5, 2014
2 parents b1a87d5 + 1f2d620 commit 167a9bc
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 3 deletions.
4 changes: 4 additions & 0 deletions app/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,7 @@ exports.message = function(req, res){
res.render('users/message', {msg:msg});
});
};
exports.alias = function(req, res){
res.render('users/alias');
};

47 changes: 47 additions & 0 deletions app/models/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

var async = require('async'),
Mongo = require('mongodb');

function Message(senderId, receiverId, message){
this.senderId = senderId;
this.receiverId = receiverId;
this.message = message;
this.date = new Date();
this.isRead = false;
}

Object.defineProperty(Message, 'collection', {
get: function(){return global.mongodb.collection('messages');}
});

Message.read = function(id, cb){
var _id = Mongo.ObjectID(id);
Message.collection.findAndModify({_id:_id}, [], {$set:{isRead:true}}, function(err, msg){
iterator(msg, cb);
});
};

Message.send = function(senderId, receiverId, message, cb){
var m = new Message(senderId, receiverId, message);
Message.collection.save(m, cb);
};

Message.unread = function(receiverId, cb){
Message.collection.find({receiverId:receiverId, isRead:false}).count(cb);
};

Message.messages = function(receiverId, cb){
Message.collection.find({receiverId:receiverId}).sort({date:-1}).toArray(function(err, msgs){
async.map(msgs, iterator, cb);
});
};

module.exports = Message;

function iterator(msg, cb){
require('./user').findById(msg.senderId, function(err, sender){
msg.sender = sender;
cb(null, msg);
});
}
2 changes: 2 additions & 0 deletions app/routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ module.exports = function(app, express){
app.post('/message/:userId', users.send);
app.get('/messages', users.messages);
app.get('/messages/:msgId', users.message);
app.get('/users/alias', users.alias);

console.log('Express: Routes Loaded');
};

1 change: 1 addition & 0 deletions app/static/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions app/static/css/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,15 @@ body {

}

#messagesTable{
height: 190px;
overflow: scroll;
}
#winksTable{
height: 190px;
overflow: scroll;
}
#proposalsTable{
height: 190px;
overflow: scroll;
}
66 changes: 66 additions & 0 deletions app/views/users/alias.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
extends ../shared/template
block content
.panel.panel-default
.panel-body
.row
.col-xs-4
h2 user.alias
.col-xs-4
ul.list-inline
li
h5 user.age
li
h5 user.gender
li
h5 user.location
.col-xs-2
a.thumbnail#alias(href='#')
img(src='/img/node.png')
.col-xs-2.col-xs-offset-1
span.glyphicon.glyphicon-heart
.col-xs-4

button.btn.btn-default.btn-(data-toggle='modal', data-target='#newMessage') Message
include newMessage
button.btn.btn-default.btn-(data-toggle='modal', data-target='#gift') Gift
#gift.modal.fade(tabindex='-1', role='dialog', aria-labelledby='giftlLabel', aria-hidden='true')
.modal-dialog
.modal-content
.modal-header
button.close(type='button', data-dismiss='modal', aria-hidden='true') ×
h4.modal-title Send a Gift
textarea.modal-body
.modal-footer
button.btn.btn-default(type='button', data-dismiss='modal') Close
button.btn.btn-primary(type='button') Send
button.btn.btn-default.btn-(data-toggle='modal', data-target='wink') Wink
span.glyphicon.glyphicon-eye-open

.row
.col-xs-12
.panel.panel-default
.panel-heading
h3.panel-title About # {client.alias}panel,f
.panel-body
h6 This is the About Me Section of the Profile Page
.row
.col-xs-12
#carousel-example-generic.carousel.slide(data-ride='carousel')
ol.carousel-indicators
li.active(data-target='#carousel-example-generic', data-slide-to='0')
li.active(data-target='#carousel-example-generic', data-slide-to='1')
li.active(data-target='#carousel-example-generic', data-slide-to='2')
.carousel-inner
.item.active
img(src='/img/node.png')
.item
img(src='/img/node.png')
a.left.carousel-control(href='#carousel-example-generic', role='button', data-slide='prev')
span.glyphicon.glyphicon-chevron-left
a.right.carousel-control(href='#carousel-example-generic', role='button', data-slide='prev')
span.glyphicon.glyphicon-chevron-right




block scripts
51 changes: 51 additions & 0 deletions app/views/users/inbox.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
extends ../shared/template
block content
.row
.col-xs-12
.panel.panel-primary
.panel-heading
h3.panel-title Messages
.panel-body
.table-responsive
table.table.table-hover.table-bordered#messagesTable
thead
th From
th Date
th Message
tbody
each msg in msgs
tr(style='background-color:#{msg.isRead ? "#ECECEC" : "#8C8A8D"}')
td: a(href='/users/#{msg.sender.email}')= msg.sender.name
td= msg.date.toDateString()
td: a(href='/messages/#{msg._id}')= (msg.message.slice(0, 20) + ' .....')
.col-xs-12
.row
.col-xs-6
.panel.panel-primary
.panel-heading
h3.panel-title Proposals
.panel-body
.table-responsive
table.table.table-hover.table-bordered#proposalsTable
thead
th From
th Date
th Activity
th Message
tbody
each msg in msgs
tr(style='background-color:#{msg.isRead ? "#ECECEC" : "#8C8A8D"}')
td: a(href='/users/#{msg.sender.email}')= msg.sender.name
td= msg.date.toDateString()
td: a(href='/messages/#{msg._id}')= (msg.message.slice(0, 20) + ' .....')
.col-xs-6
.panel.panel-primary
.panel-heading
h3.panel-title Proposals
.panel-body
.table-responsive
table.table.table-hover.table-bordered#proposalsTable
thead
th From

block scripts
16 changes: 16 additions & 0 deletions app/views/users/message.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends ../shared/template
block content
.row
.col-xs-12
h3 Message from sender.name
.panel.panel-success
.panel-body
p Date
h4 msg.message
.col-xs-12
.row
.col-xs-4
button.btn.btn-primary: Reply


block scripts
53 changes: 53 additions & 0 deletions app/views/users/messages.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
extends ../shared/template
block content
.row
.col-xs-12
.panel.panel-success
.panel-heading
h3.panel-title Messages
.panel-body
.table-responsive
table.table.table-hover.table-bordered#messagesTable
thead
th From
th Date
th Message
tbody
tr
td
td
td
.col-xs-12
.row
.col-xs-9
.panel.panel-info
.panel-heading
h3.panel-title Date Proposals
.panel-body
.table-responsive
table.table.table-hover.table-bordered#proposalsTable
thead
th From
th Date
th Activity
th Message
tbody
tr
td
td
td
td
.col-xs-3
.panel.panel-danger
.panel-heading
h3.panel-title Winks
.panel-body
.table-responsive
table.table.table-hover.table-bordered#winksTable
thead
th From
tbody
tr
td

block scripts
2 changes: 1 addition & 1 deletion app/views/users/new.jade
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends ../shared/template
block content
h2 Register
.row
.col-xs-6
.col-xs-4.col-xs-offset-4
form(role='form', method='post', action='/register')
.form-group
label(for='email') Email
Expand Down
10 changes: 10 additions & 0 deletions app/views/users/newMessage.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#newMessage.modal.fade(tabindex='-1', role='dialog', aria-labelledby='messageLabel', aria-hidden='true')
.modal-dialog
.modal-content
.modal-header
button.close(type='button', data-dismiss='modal', aria-hidden='true') ×
h4.modal-title Send a Message
textarea.modal-body
.modal-footer
button.btn.btn-default(type='button', data-dismiss='modal') Close
button.btn.btn-primary(type='button') Send
27 changes: 25 additions & 2 deletions app/views/users/profile.jade
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
extends ../shared/template
block content
h2 Profile
.panel.panel-default
.panel-body
a(href='profile/edit') Edit Profile
.row
.col-xs-2
a.thumbnail#profile(href='/profile/photos')
img(src='/img/node.png')
.col-xs-6
a(href='/profile/about')
h2 user.alias
ul.list-inline
li
h5 user.age
li
h5 user.gender
li
h5 user.location
.col-xs-2

.panel.panel-info
.panel-heading
h3#about.panel-title About Me
.panel-body
h6 This is the About Me Section of the Profile Page





block scripts
Empty file.

0 comments on commit 167a9bc

Please sign in to comment.