Crafting the SAPO Campus platform, a thousand pixels at a time.
Search
Latest posts

High Performance Javascript - dealing with JSON

No Widget is an Island

Designing Email - Part II

Designing Email - Part I

The amazing "widget" object

The Facebook Witch Project

SAPO Campus keynote from OSL Unesco demonstration session

SAPO Campus session at the UNESCO OSL Seminar

SAPO Campus - Eden Seventh Open Classroom Conference

SAPO Campus leaflet for the UA freshmen

Archive

Janeiro 2011

Novembro 2010

Fevereiro 2010

Dezembro 2009

Novembro 2009

Outubro 2009

Setembro 2009

Julho 2009

Maio 2009

Abril 2009

Março 2009

Fevereiro 2009

Dezembro 2008

Novembro 2008

Outubro 2008

Setembro 2008

Segunda-feira, 27 de Julho de 2009
Development Peek: The Notification Server
For the past week or so, I've been directing part of my development efforts into building a Notification Server for the SAPO Campus PLE. The concept was inspired by the bottom bar prevalent in most Facebook pages:



The need for a notification system arose from a pretty obvious concern: sometimes the connection to the server would drop, and every action which needed to access the server (using AJAX) would silently fail. This means any work the user did since the server gave out was effectively lost, without any kind of feedback.

The design of an error reporting system quickly evolved into an abstract notification system, which could be used not only to provide error feedback but also general messages of interest to the user.

Thus, the basic design of such a system lies on two different components: a Server Manager and an Interface Manager.

 


The Server Manager


The Server Manager listens for notifications and pushes Notification Objects into a priority queue. Each Notification Object is, at heart, a jQuery Event object, and implements a series of custom properties (defined in the object prototype, and thus easily overridden):

Internally, the Notification Object is expanded to contain other properties (priority, timeToLive and wasBorn) which are used to control the object's place in the queue, and whether it is fresh enough to be shown when its time comes (This prevents the kind of scenario when a significant number of notifications are queued up, and the ones being shown to the user are no longer relevant).

A periodical function determines if there are unread notifications available and whether it's alright to show them (a delay is in place to allow the user to actually read the notification). If both conditions are true, the notification is pushed through to the Interface Manager and the Notification Object is removed from the Priority Queue.

 


The Interface Manager


The Interface Manager receives new notifications from the Server Manager and shows them in the interface. There aren't a lot of complex things going on in here, but here are the highlights anyway:

Note that the callback function actually lives in a closure, so any local variables you use while defining the callback function are kept just as they were when the function was passed on to the Notification Server. If you wish to evaluate variables as they are when the callback runs, you need to use public or privileged variables/functions.

Here's how the interface currently looks like (not designer approved yet, mind you!):


 


Ok, so how do I use the Notification Server?


If you're developing on top of the SAPO Campus PLE Platform and need to display awesome messages to your users, tapping into the power of the Notification Server is easy as can be:

var notification = new Notification();
notification.kind = 'error';
notification.message = 'Han shot first!'
$().trigger(notification);

What's going on here is pretty straightforward: you're creating a new Notification Object, and all you need to do is alter the properties specific to your situation. In this case, all we really need to change from the default values is the kind and message properties. After creating the object, shoot it into space using jQuery's trigger() method, passing the object as a parameter.

Notifications are automatically sent whenever an AJAX request is made, and also when the requests are either successful or error out.
tags:

Published by bruno-abrantes às 16:39

3

De Designing Email – Part II | sapocampus a 7 de Setembro de 2010 às 12:44
[...] also try to make Roundcube play nice with our Notification Server so that, when using the PLE, the user doesn’t need to keep checking the email page. The email [...]


De mlucas@ua.pt a 27 de Julho de 2009 às 17:03
well done ;)


De Carlos a 27 de Julho de 2009 às 19:44
very nice... and it works :)


Post a comment

About us
Janeiro 2011
Dom
Seg
Ter
Qua
Qui
Sex
Sab

1

2
3
4
5
6
7
8

9
10
11
12
13
14
15

16
17
18
19
20
21
22

23
24
25
26
27
28
29

30
31


tags

todas as tags

subscrever feeds

RSSPosts

RSSComentários

RSSComentários do post