-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added message system - new message form, message lists and message vi…
…ew, and proper inbox count in navbar. Closes #9.
- Loading branch information
1 parent
9532c77
commit a90ae30
Showing
7 changed files
with
189 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
var express = require('express'); | ||
var router = express.Router(); | ||
var request = require('superagent'); | ||
require('superagent-bluebird-promise'); | ||
|
||
router.get('/messageForm', function(req, res) { | ||
res.render('editor/messageForm', {session: req.session, error: req.query.error}); | ||
}); | ||
|
||
function renderMessageList(view, req, res) { | ||
var ws = req.app.get('webservice'); | ||
request.get(ws + '/message/' + view) | ||
.set('Authorization', 'Bearer ' + req.session.oauth.access_token).promise() | ||
.then(function(listResponse) { | ||
return listResponse.body; | ||
}) | ||
.then(function(list) { | ||
res.render('editor/messageList', { | ||
session: req.session, | ||
view: view, | ||
messages: list | ||
}); | ||
}); | ||
} | ||
|
||
router.get('/inbox', function(req, res) { | ||
renderMessageList('inbox', req, res); | ||
}); | ||
|
||
router.get('/archive', function(req, res) { | ||
renderMessageList('archive', req, res); | ||
}); | ||
|
||
router.get('/sent', function(req, res) { | ||
renderMessageList('sent', req, res); | ||
}); | ||
|
||
router.get('/message/:id', function(req, res) { | ||
var ws = req.app.get('webservice'); | ||
request.get(ws + '/message/' + req.params.id) | ||
.set('Authorization', 'Bearer ' + req.session.oauth.access_token).promise() | ||
.then(function(messageResponse) { | ||
return messageResponse.body; | ||
}) | ||
.then(function(message) { | ||
res.render('editor/message', { | ||
session: req.session, | ||
message: message | ||
}); | ||
}) | ||
}); | ||
|
||
|
||
router.post('/message/handler', function(req, res) { | ||
// This function should post a new user to the /user endpoint of the ws. | ||
var ws = req.app.get('webservice'); | ||
|
||
// Parse recipient ids | ||
recipientIds = req.body.recipients.split(',').map(function(substr) { | ||
return parseInt(substr); | ||
}); | ||
|
||
request.post(ws + '/message/sent') | ||
.set('Authorization', 'Bearer ' + req.session.oauth.access_token) | ||
.send({ | ||
'recipient_ids': recipientIds, | ||
'subject': req.body.subject, | ||
'content': req.body.content, | ||
}).promise() | ||
.then(function() { | ||
res.redirect(303, '/'); | ||
}); | ||
}); | ||
|
||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extends ../layout | ||
|
||
block body | ||
include ../navbar | ||
|
||
.container | ||
h1='Message #' + message.message_id | ||
|
||
.row | ||
.col-md-8.col-md-offset-2 | ||
.panel.panel-default | ||
.panel-body | ||
dl.dl-horizontal | ||
dt Sender: | ||
dd=message.sender.name | ||
dt Subject: | ||
dd=message.subject | ||
dt Content: | ||
dd=message.content | ||
|
||
include ../footer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
extends ../layout | ||
|
||
block body | ||
include ../navbar | ||
|
||
.container | ||
h1 New Message | ||
p.lead. | ||
Use the form below to send a message to other BookBrainz users. These | ||
messages may be viewed by moderators, so please do not include any | ||
private information. | ||
.row | ||
.col-md-8.col-md-offset-2 | ||
form.whole-page-form.form-horizontal(action="/message/handler", method="post") | ||
.form-group | ||
label.col-md-2.control-label Recipients | ||
.col-md-8 | ||
input.form-control(type="text", name="recipients" placeholder="Recipient ID[, Recipient ID...]") | ||
.form-group | ||
label.col-md-2.control-label Subject | ||
.col-md-8 | ||
input.form-control(type="text", name="subject", placeholder="Subject") | ||
.form-group | ||
label.col-md-2.control-label Message | ||
.col-md-8 | ||
textarea.form-control(name="content", rows="6") | ||
.form-group | ||
.col-md-4.col-md-offset-4 | ||
button.btn.btn-success.btn-block(type="submit") Submit | ||
|
||
include ../footer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
extends ../layout | ||
|
||
block body | ||
include ../navbar | ||
|
||
.container | ||
h1 My Messages | ||
|
||
a.pull-right(href="/messageForm") | ||
span.fa.fa-plus | ||
| New Message | ||
|
||
ul.nav.nav-pills | ||
li(class=(view === 'inbox' ? 'active' : undefined)) | ||
a(href="/inbox") | ||
| Inbox | ||
span.badge=session.inboxCount | ||
li(class=(view === 'archive' ? 'active' : undefined)) | ||
a(href="/archive") Archive | ||
li(class=(view === 'sent' ? 'active' : undefined)) | ||
a(href="/sent") Sent | ||
|
||
table.table.table-hover | ||
thead | ||
tr | ||
th Sender | ||
th Subject | ||
tbody | ||
for message in messages.objects | ||
tr | ||
td=message.sender.name | ||
td | ||
a(href='/message/'+message.message_id)=message.subject | ||
|
||
include ../footer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters