Commits

Juan Carlos Picado Herrera committed 670d1ce

ENCUESTAME-109 Migrated notification status json call to cometD

  • Participants
  • Parent commits 3d6640c

Comments (0)

Files changed (8)

File encuestame-mvc/src/main/java/org/encuestame/comet/services/NotificationCometService.java

      * @param remote
      * @param message
      */
-    @Listener("/service/notification")
+    @Listener("/service/notification/status")
     public void processNotification(final ServerSession remote, final ServerMessage.Mutable message) {
         final Map<String, Object> input = message.getDataAsMap();
         log.debug("Notification Input "+input);
-        String name = (String) input.get("name");
         final Map<String, Object> output = new HashMap<String, Object>();
         final UserAccount userAccount = getByUsername(getUserPrincipalUsername());
         if (userAccount != null) {
             final Long totalNewNot = getNotificationDao().retrieveTotalNotReadedNotificationStatus(userAccount.getAccount());
             log.debug("totalNewNot "+totalNewNot);
             output.put("totalNot", totalNot);
-            output.put("totalNot", totalNewNot);
+            output.put("totalNewNot", totalNewNot);
         } else {
-            log.error("Error username ");
+            log.error("Error username");
         }
-        output.put("greeting", "Hello, " + name);
-        remote.deliver(serverSession, "/not", output, null);
+        remote.deliver(serverSession, "/notificationStatus", output, null);
     }
 
     /**

File encuestame-war/pom.xml

                     <webAppConfig>
                         <contextPath>/encuestame</contextPath>
                     </webAppConfig>
-                    <scanIntervalSeconds>10</scanIntervalSeconds><!--
+                    <scanIntervalSeconds>5</scanIntervalSeconds><!--
                         <requestLog implementation="org.mortbay.jetty.NCSARequestLog">
                             <filename>target/encuestame.log</filename>
                             <retainDays>90</retainDays>

File encuestame-war/src/main/webapp/WEB-INF/jsp/includes/web/menu.jsp

         <li class="item"><a href="<%=request.getContextPath()%>/survey">Surveys</a></li>
     </ul>
     <div style="float: right;">
-        <div dojoType="encuestame.org.core.commons.notifications.Notification" delay="40000"></div>
+        <div dojoType="encuestame.org.core.commons.notifications.Notification"></div>
     </div>
     <br style="clear: left" />
     </div>

File encuestame-war/src/main/webapp/WEB-INF/layouts/standard/page.jsp

          dojo.require("encuestame.org.core.commons.error.ErrorSessionHandler");
          dojo.require("encuestame.org.core.commons.error.ErrorConexionHandler");
          dojo.require("encuestame.org.core.commons.error.ErrorHandler");
+         //cometd libs
+         dojo.require("dojox.cometd");
+         dojo.require("dojo.io.script");
+         dojo.require("dojox.cometd");
+         //dojo.require("dojox.cometd.callbackPollTransport");
     </script>
+<script type="text/javascript">
+    var config = {
+        contextPath: '<%=request.getContextPath()%>'
+    };
+    var cometd = dojox.cometd;
+</script>
+<script src="<%=request.getContextPath()%>/resource/js/cometd.js"></script>
 </head>
 <body class="claro">
 <div id="contextWidget" dojoType="encuestame.org.core.contextWidget" contextPath="<%=request.getContextPath()%>"></div>

File encuestame-war/src/main/webapp/WEB-INF/views/dashboard/web/dashboard.jsp

 <%@ page session="false" %>
 <%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
-
 <script type="text/javascript">
   dojo.require("encuestame.org.core.commons.dashboard.chart.DashboardPie");
   dojo.require("encuestame.org.core.commons.dashboard.chart.DashboardColumn2D");
   dojo.require("encuestame.org.core.commons.dashboard.chart.DashboardLine");
   dojo.require("encuestame.org.core.commons.dashboard.Dashboard");
-  dojo.require("dojox.cometd");
-  dojo.require("dojo.io.script");
-  dojo.require("dojox.cometd");
-  dojo.require("dojox.cometd.callbackPollTransport");
-</script>
-<script type="text/javascript">
-dojo.addOnLoad(function()
-{
-
-    //More Info: http://cometd.org/node/49
-    var cometd = dojox.cometd;
-    console.debug("comentD",cometd);
-    var config = {
-            contextPath: '/encuestame'
-        };
-
-    function _connectionEstablished()
-    {
-        dojo.byId('body').innerHTML += '<div>CometD Connection Established</div>';
-    }
-
-    function _connectionBroken()
-    {
-        dojo.byId('body').innerHTML += '<div>CometD Connection Broken</div>';
-    }
-
-    function _connectionClosed()
-    {
-        dojo.byId('body').innerHTML += '<div>CometD Connection Closed</div>';
-    }
-
-    // Function that manages the connection status with the Bayeux server
-    var _connected = false;
-    function _metaConnect(message)
-    {
-        if (cometd.isDisconnected())
-        {
-            _connected = false;
-            _connectionClosed();
-            return;
-        }
-
-        var wasConnected = _connected;
-        _connected = message.successful === true;
-        if (!wasConnected && _connected)
-        {
-            _connectionEstablished();
-        }
-        else if (wasConnected && !_connected)
-        {
-            _connectionBroken();
-        }
-    }
-
-    // Function invoked when first contacting the server and
-    // when the server has lost the state of this client
-    function _metaHandshake(handshake)
-    {
-        if (handshake.successful === true)
-        {
-            cometd.batch(function(){
-                cometd.subscribe('/hello', function(message){
-                    dojo.byId('body').innerHTML += '<div>Server Says: ' + message.data.greeting + '</div>';
-                });
-                // Publish on a service channel since the message is for the server only
-                cometd.publish('/service/hello', { name: 'World' });
-
-                cometd.subscribe('/not', function(message){
-                    console.debug("NOTF", message);
-                });
-                // Publish on a service channel since the message is for the server only
-                cometd.publish('/service/notification', { name: 'World2' });
-            });
-        }
-    }
-
-    // Disconnect when the page unloads
-    dojo.addOnUnload(function()
-    {
-        cometd.disconnect(true);
-    });
-
-    var cometURL = location.protocol + "//" + location.host + config.contextPath + "/cometd";
-    cometd.configure({
-        url: cometURL,
-        logLevel: 'debug'
-    });
-
-    cometd.addListener('/meta/handshake', _metaHandshake);
-    cometd.addListener('/meta/connect', _metaConnect);
-
-    cometd.handshake();
-});
-
 </script>
 <div>
   <div id="body"></div>

File encuestame-war/src/main/webapp/resource/css/livePanel.css

     cursor: pointer;
 }
 
+div.notificationWrapper div.new{
+    color: red !important;
+}
+
 div.counter:hover{
-}
+}

File encuestame-war/src/main/webapp/resource/js/encuestame/org/core/commons/notifications/Notification.js

 
         widgetsInTemplate: true,
 
-        delay: 1000,
+        delay: 20000,
 
         limit: 8,
 
 
         timer: null,
 
+        _updateNotifications : false,
+
         openNot : false,
 
         postCreate: function() {
-            this.loadStatus();
-            this.loadTimer();
+            dojo.addOnLoad(dojo.hitch(this, function(){
+                this.loadStatus();
+                this.loadTimer();
+            }));
+            dojo.subscribe("/encuestame/notifications/update/status", this, "_updateStatus");
         },
 
-        /**
+        /*
          * Load Timer.
          */
         loadTimer : function(){
         },
 
         /*
+         * Update label status.
+         * @param totalNew
+         * @param lastNew
+         */
+        _updateStatus : function(totalNew, lastNew){
+            var total = parseInt(totalNew);
+            var totalNew = parseInt(lastNew);
+            if (totalNew > this.lastNew) {
+               //highligth new notifications.
+                this._displayNewHighlight();
+            } else if (totalNew == this.lastNew) {
+                this._displayNewHighlight();
+            } else {
+                this._hideNewHighlight();
+            }
+            this.lastNew = totalNew;
+            this.totalNot = total;
+            this._count.innerHTML = total;
+        },
+
+        /*
+         *
+         */
+        _displayNewHighlight : function(){
+            dojo.addClass(this._count, "new");
+        },
+
+        _hideNewHighlight : function(){
+            dojo.removeClass(this._count, "new");
+        },
+
+        /*
          * load notifications
          */
         loadStatus : function() {
-            var load = dojo.hitch(this, function(data){
-                var total = data.success.t;
-                var totalNew = data.success.n;
-                this.lastNew = totalNew;
-                this._count.innerHTML = data.success.t;
-            });
-            var error =  dojo.hitch(this, function(error) {
-                this.timer.stop();
-            });
-            encuestame.service.xhrGet(encuestame.service.list.getStatusNotifications, {}, load, error);
+//            var load = dojo.hitch(this, function(data){
+//                var total = data.success.t;
+//                var totalNew = data.success.n;
+//                this.lastNew = totalNew;
+//                this._count.innerHTML = data.success.t;
+//            });
+//            var error =  dojo.hitch(this, function(error) {
+//                this.timer.stop();
+//            });
+            // Publish on a service channel since the message is for
+            // the server only
+            cometd.publish('/service/notification/status', {});
+            //encuestame.service.xhrGet(encuestame.service.list.getStatusNotifications, {}, load, error);
         },
 
         // load notifications
                 var url = '/encuestame/api/remove-notification.json';
             }
 
-        });
+        });

File encuestame-war/src/main/webapp/resource/js/encuestame/org/core/commons/notifications/template/notification.inc

             <a href="#" dojoAttachEvent="onclick:_viewAll">View All</a>
         </div>
     </div>
-    <div dojoAttachPoint="_count" class="counter" dojoAttachEvent="onclick:open"></div>
+    <div dojoAttachPoint="_count" class="counter" dojoAttachEvent="onclick:open">0</div>
     <div dojoType="dojox.widget.Dialog" id="allNot" dimensions="[1030,310]">
          <div dojoType="dijit.layout.ContentPane" title="Add User Directly" selected="true">
             Dialog with All notifications
          </div>
     </div>
-</div>
+</div>