incubator-esme-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhir...@apache.org
Subject svn commit: r920963 - in /incubator/esme/branches/ui-2010-03-05/src/main: scala/org/apache/esme/comet/SinglePublicTimeline.scala webapp/index.html webapp/scripts/display_single_message.js webapp/templates-hidden/base.html
Date Tue, 09 Mar 2010 16:26:42 GMT
Author: rhirsch
Date: Tue Mar  9 16:26:42 2010
New Revision: 920963

URL: http://svn.apache.org/viewvc?rev=920963&view=rev
Log:
[ESME-100] Finish web UI

Added:
    incubator/esme/branches/ui-2010-03-05/src/main/scala/org/apache/esme/comet/SinglePublicTimeline.scala
    incubator/esme/branches/ui-2010-03-05/src/main/webapp/scripts/display_single_message.js
Modified:
    incubator/esme/branches/ui-2010-03-05/src/main/webapp/index.html
    incubator/esme/branches/ui-2010-03-05/src/main/webapp/templates-hidden/base.html

Added: incubator/esme/branches/ui-2010-03-05/src/main/scala/org/apache/esme/comet/SinglePublicTimeline.scala
URL: http://svn.apache.org/viewvc/incubator/esme/branches/ui-2010-03-05/src/main/scala/org/apache/esme/comet/SinglePublicTimeline.scala?rev=920963&view=auto
==============================================================================
--- incubator/esme/branches/ui-2010-03-05/src/main/scala/org/apache/esme/comet/SinglePublicTimeline.scala
(added)
+++ incubator/esme/branches/ui-2010-03-05/src/main/scala/org/apache/esme/comet/SinglePublicTimeline.scala
Tue Mar  9 16:26:42 2010
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.esme.comet
+
+import net.liftweb.http._
+import net.liftweb.mapper._
+import net.liftweb.util._
+import net.liftweb.common._
+import net.liftweb.util.Helpers._
+import scala.xml._
+import js._
+import JsCmds._
+import JE._
+
+import org.apache.esme._
+import org.apache.esme.actor._
+import model._
+import lib._
+
+import java.text._
+
+class SinglePublicTimeline extends CometActor {
+  private var messages: List[Long] = Nil
+  private var lastRender = millis
+  private var scheduled = false
+
+  override def localSetup() {
+    super.localSetup()
+    Distributor ! Distributor.PublicTimelineListeners(this) 
+    messages = Message.findAll(By(Message.pool, Empty),
+        OrderBy(Message.id, Descending), 
+                               MaxRows(1)).map(_.id.is)
+  }
+  
+  override def localShutdown() {
+    super.localShutdown()
+    Distributor ! Distributor.PublicTimelineUnlisteners(this)
+  }
+  
+  def render = {
+    lastRender = millis
+    scheduled = false
+    val msgMap = Message.findMessages(messages)
+    val toDisplay = messages.flatMap(msgMap.get)
+    val jsId = "timeline_messages";
+
+    OnLoad(JsCrVar(jsId, JsArray(
+        toDisplay.map(m => JsObj(("message", m.asJs)) ) :_*)) &
+    JsFunc("displayMessages", JsVar(jsId), jsId).cmd)
+  }
+
+  override def lowPriority = {
+    case ForceRender =>
+      reRender(false)
+
+    case Distributor.NewMessage(msg) =>
+      if (!msg.pool.defined_?)
+        messages = (msg.id.is :: messages).take(40)
+
+      if ((millis - lastRender) < 30000L) {
+        if (!scheduled) {
+          scheduled = true    
+          ActorPing.schedule(this, ForceRender, 30000L)
+        }
+      }
+      else reRender(false)
+  }
+}
+
+case object ForceRender

Modified: incubator/esme/branches/ui-2010-03-05/src/main/webapp/index.html
URL: http://svn.apache.org/viewvc/incubator/esme/branches/ui-2010-03-05/src/main/webapp/index.html?rev=920963&r1=920962&r2=920963&view=diff
==============================================================================
--- incubator/esme/branches/ui-2010-03-05/src/main/webapp/index.html (original)
+++ incubator/esme/branches/ui-2010-03-05/src/main/webapp/index.html Tue Mar  9 16:26:42 2010
@@ -10,11 +10,48 @@
 		       <h1><span><lift:loc>custom_opening_main_title</lift:loc></span></h1>
 		       <p><lift:loc>custom_opening_main_body</lift:loc> </p>
 		</div><!--container-2nd-level-->
+	 <link rel="stylesheet" href="../style/style.css" type="text/css" media="screen" />
 	</div><!--container-2nd-level-bg-->
 	<!--END BLUE HEADER-->	
-	
-	<script src="/scripts/display_messages_start.js" type="text/javascript"/>
+      <script id="jquery" src="/classpath/jquery.js" type="text/javascript"/><script
id="json" src="/classpath/json.js" type="text/javascript"/><script src="/scripts/display_single_message.js"
type="text/javascript"/>
+
 	 <lift:comet type="SinglePublicTimeline"/>
+	 
+	                    <!--updates-box -->
+                    <lift:comet type="SinglePublicTimeline"/> 
+                    <div class="separator">
+                    </div>
+                    <table>
+                      <tbody id="timeline_messages">
+                       <tr id="message">
+                      <div id="timeline_messages">
+                       <div class="updates-box">
+                        <div class="avatar">
+                            <img id="avatar" src="/images/avatar.jpg" alt="Anonymous"
width="50px"/>
+                        </div>
+                        <div class="update2">
+                            <div class="info2" >
+                                <a href="" id="author">-</a>
+                            </div>
+                            <div id="body">-</div>
+                            <div class="time">
+                                <table><tr><td><div id="pool"> -</div></td><td>
  </td><td> <div id="when"> -</div></td><td><div id="reason">
-</div></td><td> <div id="source"> -</div></td></tr></table>
+                            </div>
+                            <div id="tags" class="tags">
+                                <p id="tag">
+                                  <a href="tag/tag1">-</a>
+                                </p>
+                                <p id="tag">
+                                  <a href="tag/tag2">-</a>
+                                </p>
+                            </div>
+                        </div>
+                      </div>
+                      </div>
+                      </tr>
+                       </tbody>
+                     </table>
+                    <!--updates-box
 
 	<div class="gray-box">
 		<h1>Now on ESME</h1>
@@ -23,7 +60,7 @@
 			<div class="tag"><a href="">mac</a>, <a href="">design</a>,
<a href="">graphics</a>, <a href="">photoshop</a>, <a href="">cs3</a></div>

 			<div class="info"><a href="">Nickname</a> 3 hours ago</div>
 		</div>
-	</div><!--gray-box
+	</div>
 	
 	<div class="tags-box">
 		<a href="" class="style5">software</a> 

Added: incubator/esme/branches/ui-2010-03-05/src/main/webapp/scripts/display_single_message.js
URL: http://svn.apache.org/viewvc/incubator/esme/branches/ui-2010-03-05/src/main/webapp/scripts/display_single_message.js?rev=920963&view=auto
==============================================================================
--- incubator/esme/branches/ui-2010-03-05/src/main/webapp/scripts/display_single_message.js
(added)
+++ incubator/esme/branches/ui-2010-03-05/src/main/webapp/scripts/display_single_message.js
Tue Mar  9 16:26:42 2010
@@ -0,0 +1,118 @@
+// <![CDATA[
+/*
+ * displayMessages called by lift:comet, type="Timeline" and type="PublicTimeline"
+ */
+
+function msgDateCompare(msg1, msg2)
+{
+  return parseInt(msg1.message.when) - parseInt(msg2.message.when);
+}
+
+function displayMessages(msgArray, elementId)
+{
+  // Select the first element in table id="timeline_messages"
+  //  with id="message" as the message template
+  if (msgTemplate == null) {
+    //                                    var msgTemplate = jQuery('span.'+spanId+' message:first');
+    var msgTemplate = jQuery('#'+elementId+' #message:first');
+    var tagTemplate = msgTemplate.find('#tag:first');
+    var msgInsertPt = jQuery('#'+elementId);
+
+    // Now we have the template, make the existing instances invisible
+    jQuery('#'+elementId+' *[id=message]').hide();
+  }
+
+  // Sort the messages into date order
+  msgArray.sort(msgDateCompare);
+
+  for (var msgIndex in msgArray)
+  {
+    // Marshall the data from the Comet-supplied message
+    var cometMsg = msgArray[msgIndex].message;
+    var cometReason = msgArray[msgIndex].reason;
+    var cometResent = msgArray[msgIndex].resent;
+    var msgId = "message_"+cometMsg.id;
+
+    // Only do this if the message is not already in the table
+    if (jQuery('#'+elementId+' #'+msgId).size() == 0)
+    {
+      var msgAuthor = cometMsg.author;
+      var msgBody = jQuery(cometMsg.text).find('body').html();
+      var msgDateObj = new Date(parseInt(cometMsg.when));
+      var msgDateStr = 'on ' + msgDateObj.toLocaleDateString() +
+        ' ' + msgDateObj.toLocaleTimeString();
+      var msgPool = '';
+      if (cometMsg.pool) msgPool = 'in pool ' + cometMsg.pool.name;
+      var msgSource = cometMsg.source;
+      var msgConversation = cometMsg.conversation;
+      var msgReason = ""
+      for (r in cometReason) {
+        if (r == "resent_from")
+          msgReason = "resent by " + cometReason[r].nickname;
+        else
+          msgReason = "caused by " + r;
+        break
+      }
+      var msgTags = jQuery(cometMsg.text).find('tags > tag').get();
+      for (var tagIndex=0; tagIndex < msgTags.length; tagIndex++) {
+        // Replace each tag element with the plain tag text
+        msgTags[tagIndex] = jQuery(msgTags[tagIndex]).attr('name');
+      }
+
+      // Put the marshalled data into a copy of the template
+      var newMsg = msgTemplate.clone(true).attr('id',msgId);
+
+      newMsg.find('#author').text(msgAuthor.nickname);
+     
+      // Dealing with users with no avatars
+      if (!msgAuthor.imageurl)
+      	msgAuthor.imageurl="/images/avatar.jpg"
+      	
+     if (!msgPool)
+      	msgPool="public"
+      	
+      var avatar = newMsg.find('#avatar')
+      .attr('src', msgAuthor.imageurl)
+      .attr('alt',msgAuthor.firstname + ' ' + msgAuthor.lastname);
+
+      newMsg.find('#body').html(msgBody);
+      newMsg.find('#pool').text(msgPool);
+      newMsg.find('#source').text(msgSource);
+      newMsg.find('#reason').text(msgReason);
+      newMsg.find('#when').text(msgDateStr);
+      var id = cometMsg.id;
+      var resendButton = newMsg.find('#resend');
+      if (cometResent) {
+        resendButton.css("display", "none");
+      } else {
+        resendButton.attr('id', 'resend_' + id).
+          attr('onclick', 'javascript:resend_msg(' + id + ');' +
+                                     'clearResend("resend_' + id + '")');
+      }
+      newMsg.find('#reply').attr('href',
+        "javascript:setReplyTo(" + id + ", '"+ msgBody + "')");
+      var conversation = newMsg.find('#conversation');
+      if (msgConversation != 0) {
+        conversation.attr('href',
+          '/conversation/' + msgConversation);
+      } else {
+        conversation.css("display", "none");
+      }
+      for (var tagIndex=0; tagIndex < msgTags.length; tagIndex++) {
+        var newTag = tagTemplate.clone(true).attr('id',msgTags[tagIndex]);
+        newTag.find('a')
+        .attr('href','tag/'+msgTags[tagIndex])
+        .text(msgTags[tagIndex]);
+        newTag.insertBefore(newMsg.find('#tag:first'));
+      }
+
+      // Remove any old tags from the template
+      newMsg.find('*[id=tag]').remove();
+
+      // Insert the updated copy of the message into the page
+      newMsg.prependTo(msgInsertPt).show();
+    }
+  }
+}
+// ]]>
+

Modified: incubator/esme/branches/ui-2010-03-05/src/main/webapp/templates-hidden/base.html
URL: http://svn.apache.org/viewvc/incubator/esme/branches/ui-2010-03-05/src/main/webapp/templates-hidden/base.html?rev=920963&r1=920962&r2=920963&view=diff
==============================================================================
--- incubator/esme/branches/ui-2010-03-05/src/main/webapp/templates-hidden/base.html (original)
+++ incubator/esme/branches/ui-2010-03-05/src/main/webapp/templates-hidden/base.html Tue Mar
 9 16:26:42 2010
@@ -159,5 +159,6 @@
                 <lift:loc>ui_default_footer</lift:loc>
           <br />
          </div> 
+         </div> 
     </body>
 </html>



Mime
View raw message