Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made the reaction work as well for invites

  • Loading branch information...
commit 5d4bc6b729345427103d839e086d95a6a6d8dcaa 1 parent 44d0326
@jettro authored
View
4 office-events/app/App.groovy
@@ -5,8 +5,10 @@
*
*
*/
-
+def log = container.logger
+def mongoConfig = ["db_name": "officeevents", "address": "vertx.persist"]
container.with {
+ deployModule('vertx.mongo-persistor-v1.1', mongoConfig)
deployModule('website')
deployModule('notifications')
deployModule('invitations')
View
45 office-events/mods/invitations/invitation.rb
@@ -4,7 +4,44 @@
logger = Vertx.logger
EventBus.register_handler("message.newinvitation") do |message|
- theMessage = message.body['message'] + " (max " + message.body['maxpersons'] + " personen)"
- logger.info theMessage
- EventBus.send("message.send.invitation",theMessage)
-end
+ message.reply({'message'=>'Thank you for the invitation'})
+ receivedMessage = message.body['message']
+ receivedMaxPersons = message.body['maxpersons']
+
+ EventBus.send("vertx.persist",
+ {
+ 'action' => 'save',
+ 'collection' => 'invites',
+ 'document' => {
+ 'message' => receivedMessage,
+ 'maxPersons' => receivedMaxPersons,
+ 'registeredPersons' => 0
+ }
+ }) do |replyMessage|
+ theMessage = {'id'=>replyMessage.body['_id'],'message'=>receivedMessage,'maxPersons'=>receivedMaxPersons}
+ EventBus.send("message.send.invitation",theMessage)
+ end
+end
+
+EventBus.register_handler("message.registerinvitation") do |message|
+ message.reply({'message'=>'You are now welcome to join me'})
+
+ EventBus.send("vertx.persist",
+ {
+ 'action' => 'update',
+ 'collection' => 'invites',
+ 'criteria' => {
+ '_id' => message.body['invitationid']
+ },
+ 'objNew' => {
+ '$inc' => {
+ 'registeredPersons' => 1
+ }
+ },
+ 'upsert' => true,
+ 'multi' => false
+ }) do |replyMessage|
+ logger.info "We stored the updated number of registered persons for " + message.body['invitationid']
+ end
+
+end
View
23 office-events/mods/notifications/notification.js
@@ -15,6 +15,29 @@ var handler = function (message) {
var address = "notification.received";
eb.registerHandler(address, handler);
+eb.registerHandler("NUEVENNIET.message.registerinvitation", function (message) {
+ logger.info(message.invitationid);
+ var json = {
+ "action":"update",
+ "collection":"invites",
+ "criteria":{
+ "_id":message.invitationid
+ },
+ "objNew":{
+ "$inc":{
+ "registeredPersons":1
+ }
+ },
+ "upsert":true,
+ "multi":false
+ };
+ logger.info(JSON.stringify(json));
+ eb.send("vertx.persist", json, function (message) {
+ var parse = JSON.stringify(message);
+ logger.info("Received a message from: " + parse);
+ });
+});
+
function vertxStop() {
eb.unregisterHandler(address, handler);
}
View
20 office-events/mods/website/BasicHttpServer.groovy
@@ -1,4 +1,3 @@
-import groovy.json.JsonSlurper
import org.vertx.groovy.core.eventbus.EventBus
import org.vertx.groovy.core.http.RouteMatcher
import org.vertx.groovy.core.http.impl.DefaultHttpServer
@@ -8,21 +7,26 @@ import org.vertx.groovy.core.http.impl.DefaultHttpServer
*/
def log = container.logger
EventBus eventBus = vertx.eventBus
-def slurper = new JsonSlurper()
eventBus.registerHandler("message.send.notification") {message ->
- sendMessageToEventBus(message.body, "notification", log, slurper, eventBus)
+ publishMessageToEventBus(message.body, "notification", log, eventBus)
}
eventBus.registerHandler("message.send.invitation") {message ->
- sendMessageToEventBus(message.body, "invitation", log, slurper, eventBus)
+ def theMessage = message.body
+ theMessage.put("type", "invitation")
+ log.info "Received a message to send to a client ${theMessage}"
+ eventBus.publish("message.forclients", theMessage)
}
-def sendMessageToEventBus(message, type, log, slurper, eventBus) {
+def publishMessageToEventBus(message, type, log, eventBus) {
log.info "Received a message to send to a client ${message} of type ${type}"
- def theMessage = "{\"message\":\"${message}\",\"type\":\"${type}\"}"
- def jsonMessage = slurper.parseText(theMessage)
- eventBus.publish("message.forclients", jsonMessage)
+
+ def theMessage = [:]
+ theMessage.put("message", message)
+ theMessage.put("type", type)
+
+ eventBus.publish("message.forclients", theMessage)
}
View
23 office-events/mods/website/static/index.html
@@ -18,14 +18,32 @@
};
function publish(address, message) {
if (eb) {
- eb.publish(address, message);
+ eb.send(address, message, function (reply) {
+ $('#replymessage').html("<div class=\"alert alert-info\">" + reply.message + "</div>");
+ $('#replymessage').fadeIn('fast');
+ $('#replymessage').fadeOut(5000);
+ });
}
}
+ function register(id) {
+ var message = {invitationid:id};
+ publish("message.registerinvitation", message);
+ }
+
function subscribe(address) {
if (eb) {
eb.registerHandler(address, function (msg, replyTo) {
- $('#messages').append("<div class=\"alert " + styles[msg.type] + "\">" + msg.message + "</div>");
+ if ('invitation' == msg.type) {
+ $('#messages').append("<div class=\"alert " + styles[msg.type] + "\">" + msg.message +
+ " (max " + msg.maxPersons + " persons)" +
+ "<div class=\"pull-right\">" +
+ "<button class=\"btn btn-mini\" type=\"button\" onclick=\"register('" + msg.id + "')\">Register</button>" +
+ "</div>" +
+ "</div>");
+ } else {
+ $('#messages').append("<div class=\"alert " + styles[msg.type] + "\">" + msg.message + "</div>");
+ }
});
}
}
@@ -83,6 +101,7 @@
</div>
</div>
<div class="span4">
+ <div id="replymessage"></div>
<div id="invitationForm">
<form onsubmit="return false;">
<legend>Create invitation</legend>
Please sign in to comment.
Something went wrong with that request. Please try again.