You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@esme.apache.org by es...@apache.org on 2011/04/14 15:55:42 UTC

svn commit: r1092245 - in /esme/trunk/server/src/main: scala/org/apache/esme/comet/ scala/org/apache/esme/lib/ webapp/info_view/ webapp/scripts/ webapp/style/ webapp/templates-hidden/

Author: esjewett
Date: Thu Apr 14 13:55:42 2011
New Revision: 1092245

URL: http://svn.apache.org/viewvc?rev=1092245&view=rev
Log:
[ESME-328] Convert search to use comet timeline, make search box a little cleaner, fix error in stream timline caused by leftover code, clean up code that is now unused in display...js files and delete message_core.html

Added:
    esme/trunk/server/src/main/scala/org/apache/esme/comet/SearchTimeline.scala
Removed:
    esme/trunk/server/src/main/webapp/templates-hidden/message_core.html
Modified:
    esme/trunk/server/src/main/scala/org/apache/esme/lib/SearchMgr.scala
    esme/trunk/server/src/main/webapp/info_view/public.html
    esme/trunk/server/src/main/webapp/info_view/search.html
    esme/trunk/server/src/main/webapp/info_view/streams.html
    esme/trunk/server/src/main/webapp/scripts/display_messages_top.js
    esme/trunk/server/src/main/webapp/scripts/display_single_message.js
    esme/trunk/server/src/main/webapp/style/style.css
    esme/trunk/server/src/main/webapp/templates-hidden/base.html

Added: esme/trunk/server/src/main/scala/org/apache/esme/comet/SearchTimeline.scala
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/scala/org/apache/esme/comet/SearchTimeline.scala?rev=1092245&view=auto
==============================================================================
--- esme/trunk/server/src/main/scala/org/apache/esme/comet/SearchTimeline.scala (added)
+++ esme/trunk/server/src/main/scala/org/apache/esme/comet/SearchTimeline.scala Thu Apr 14 13:55:42 2011
@@ -0,0 +1,47 @@
+/**
+ * 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.common._  
+import net.liftweb.http._         
+import net.liftweb.util.Helpers.TimeSpan 
+
+import org.apache.esme._
+import actor.{Distributor,UserActor}
+import model._                
+import net.liftweb.http.js.jquery.JqJsCmds.{PrependHtml}  
+
+class SearchTimeline extends Timeline {   
+
+  val jsId = "search_timeline_messages"    
+  
+  override def localSetup() {
+    super.localSetup()
+                                                            
+    for( user <- User.currentUser;
+         n <- name ) {                
+      messages = Message.search(n, user.following, 50).map( m => 
+        (m.id.is, NoReason, false))
+    }
+  }         
+  
+  override def lifespan = Full(TimeSpan(100000))
+  
+}
\ No newline at end of file

Modified: esme/trunk/server/src/main/scala/org/apache/esme/lib/SearchMgr.scala
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/scala/org/apache/esme/lib/SearchMgr.scala?rev=1092245&r1=1092244&r2=1092245&view=diff
==============================================================================
--- esme/trunk/server/src/main/scala/org/apache/esme/lib/SearchMgr.scala (original)
+++ esme/trunk/server/src/main/scala/org/apache/esme/lib/SearchMgr.scala Thu Apr 14 13:55:42 2011
@@ -50,29 +50,24 @@ object SearchMgr {
 
   val menuItems =
   Menu(Loc("search", List("info_view", "search"), S.?("base_menu_search"), ifIsLoggedIn,
-           Loc.Snippet("displaySearch", displaySearch),
+           Loc.Snippet("display_search", displaySearch),
            Loc.Snippet("searchTerm", searchTerm))) ::
-  Nil
-
+  Nil                                        
+  
   def searchTerm(in: NodeSeq): NodeSeq = {
     Text(S.param("term").getOrElse("no words specified"))
   }
   
-  def displaySearch(in: NodeSeq): NodeSeq = {
+  def displaySearch(in: NodeSeq): NodeSeq = {   
+  
+// TODO: Switch to a random string for the name of the comet timeline. At least until we
+// get streaming search timelines working for real.
 
-    val jsId = "search_timeline_messages";
-    
-    {Script(
-      (for (term <- S.param("term");
-           user <- User.currentUser)
-      yield {
+    def cometTimeline:NodeSeq = { for(term <- S.param("term")) yield {
+      <lift:comet type="SearchTimeline" name={term} />
+    }}.openOr(Text(""))
 
-        val msgs = Message.search(term, user.following, 50)    
-        OnLoad(JsCrVar(jsId, JsArray(
-            msgs.map(m => JsObj(("message", m.asJs)) ) :_*)) &
-        JsFunc("displayMessages", JsVar(jsId), jsId).cmd)
-      }).getOrElse(Noop)
-    )}
+    bind("search", in, "cometTimeline" -> cometTimeline )  
 
   }
 

Modified: esme/trunk/server/src/main/webapp/info_view/public.html
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/webapp/info_view/public.html?rev=1092245&r1=1092244&r2=1092245&view=diff
==============================================================================
--- esme/trunk/server/src/main/webapp/info_view/public.html (original)
+++ esme/trunk/server/src/main/webapp/info_view/public.html Thu Apr 14 13:55:42 2011
@@ -25,8 +25,7 @@
   <div class="container-aux"> 
     <div id="public_timeline_messages">  
   		<!--updates-box -->
-  		<lift:comet type="PublicTimeline"/>
-  		<lift:embed what="templates-hidden/message_core"/>   
+  		<lift:comet type="PublicTimeline"/>                  
   	</div>    
   </div>
 </lift:surround>
\ No newline at end of file

Modified: esme/trunk/server/src/main/webapp/info_view/search.html
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/webapp/info_view/search.html?rev=1092245&r1=1092244&r2=1092245&view=diff
==============================================================================
--- esme/trunk/server/src/main/webapp/info_view/search.html (original)
+++ esme/trunk/server/src/main/webapp/info_view/search.html Thu Apr 14 13:55:42 2011
@@ -25,10 +25,9 @@
       <lift:embed what="templates-hidden/message_update_box"/>    
     </div> 
     <div class="container-aux">
-      <lift:displaySearch/> 
-      <div id="search_timeline_messages">
-        <lift:embed what="templates-hidden/message_core"/>        
-      </div>
+      <lift:display_search> 
+         <search:cometTimeline />
+      </lift:display_search>
     </div> 
   </div>     
 </lift:surround>

Modified: esme/trunk/server/src/main/webapp/info_view/streams.html
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/webapp/info_view/streams.html?rev=1092245&r1=1092244&r2=1092245&view=diff
==============================================================================
--- esme/trunk/server/src/main/webapp/info_view/streams.html (original)
+++ esme/trunk/server/src/main/webapp/info_view/streams.html Thu Apr 14 13:55:42 2011
@@ -50,8 +50,7 @@
           <script src="/scripts/display_messages_top.js" type="text/javascript"/>  
           <script src="/scripts/pretty.js" type="text/javascript"/> 
         </head>                         
-        <stream:cometTimeline />    
-        <lift:embed what="templates-hidden/message_core"/>
+        <stream:cometTimeline />                            
       </div>  
     </div>                                                   
   </lift:stream_display> 

Modified: esme/trunk/server/src/main/webapp/scripts/display_messages_top.js
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/webapp/scripts/display_messages_top.js?rev=1092245&r1=1092244&r2=1092245&view=diff
==============================================================================
--- esme/trunk/server/src/main/webapp/scripts/display_messages_top.js (original)
+++ esme/trunk/server/src/main/webapp/scripts/display_messages_top.js Thu Apr 14 13:55:42 2011
@@ -17,57 +17,7 @@
  under the License.                                           * 
 */
 
-// <![CDATA[
-/*
- * displayMessages called by lift:comet, type="Timeline" and type="PublicTimeline"
- */
-
-function msgDateCompare(msg1, msg2)
-{
-  return parseInt(msg1.message.when) - parseInt(msg2.message.when);
-}
-
-// Replaces all instances of the given substring.
-String.prototype.replaceAll = function( 
-	strTarget, // The substring you want to replace
-	strSubString // The string you want to replace in.
-	){
-	var strText = this;
-	var intIndexOfMatch = strText.indexOf( strTarget );
-	 
-	// Keep looping while an instance of the target string
-	// still exists in the string.
-	while (intIndexOfMatch != -1){
-		// Relace out the current instance.
-		strText = strText.replace( strTarget, strSubString )
-		 
-		// Get the index of any next matching substring.
-		intIndexOfMatch = strText.indexOf( strTarget );
-	}
-	 
-	// Return the updated string with ALL the target strings
-	// replaced out with the new substring.
-	return( strText );
-} 
-
-
-function strip(html)
-{
-   var tmp = document.createElement("DIV");
-   tmp.innerHTML = html;
-   return tmp.textContent||tmp.innerText;
-}
-
-function searchMe()
-{
-   if(document.forms["validateForm"].term.value.trim.length > 0)
-   	document.forms["validateForm"].submit();
-}    
-
-var resendFunction = function(id){
-  resend_msg(id);
-  clearResend("resend_" + id );
-}      
+// <![CDATA[ 
 
 var currentConvNumber = 0;
 
@@ -117,159 +67,5 @@ function clearReplyTo(){
   document.getElementById('reply-to-div').style.display = "none";
   jQuery('#vPool').val(0);
   jQuery('#message_request').html('What are you working on?');
-}           
-
-function clearResend(id){
-    document.getElementById(id).style.display = "none"
 }                            
-
-function clearMessages(elementId) {
-  jQuery('.updates-box').not("#message").remove(); 
-}
-
-function parseXml(xml) {
-    if (jQuery.browser.msie) {
-    	  var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
-          xmlDoc.loadXML(xml);
-           xml = xmlDoc;    
-      }       
-  return xml;
-}
-
-
-function displayMessages(msgArray, elementId, root)
-{
-	
-
-	
- // 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 = null;
-      
-      // Dealing with an IE bug when parsing XML with jQuery
-      
-      if (jQuery.browser.msie) {
-      	var msgBodyXML = parseXml(cometMsg.text);
-        var msgBodyBase = jQuery(msgBodyXML).find('body');
-        msgBody = msgBodyBase[0].xml.replaceAll ("<body>", "").replaceAll ("</body>", ""); 
-      }
-      else
-      	msgBody = jQuery(cometMsg.text).find('body').html();
-      	
-      var msgDateObj = new Date(parseInt(cometMsg.when));
-      
-      if (!msgBody)
-      	msgBody = cometMsg.text;
-      
-      var msgDateStr = prettyDate(msgDateObj);
-      
-
-      
-      var msgPool = '';
-      if (cometMsg.pool) msgPool = 'in pool \'' + cometMsg.pool.name + "\'"; 
-      var msgPoolId = 0;
-      if (cometMsg.pool) msgPoolId = cometMsg.pool.id; 
-      var msgSource = cometMsg.source;
-      var msgConversation = cometMsg.conversation;
-      var msgReason = ""
-      for (r in cometReason) {
-      	msgSource = ""
-        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);
-      
-      newMsg.find('.author').attr('href', root + "/user/" + msgAuthor.nickname );
-     
-     
-           // Dealing with users with no avatars
-      if (!msgAuthor.imageUrl) {
-        msgAuthor.imageUrl= root + "/images/avatar.jpg"
-      }
-     
-     	
-     if (!msgPool)
-      	msgPool="public"
-      	
-      var avatar = newMsg.find('#avatar')
-      .attr('src', msgAuthor.imageUrl)
-      .attr('alt',msgAuthor.firstName + ' ' + msgAuthor.lastName);
-      
-      newMsg.find('.msgbody').html(msgBody);
-      if (msgReason)
-         newMsg.find('.supp_data').text(msgPool + " " + msgDateStr  + " " +  msgReason );
-      else {
-      	 newMsg.find('.supp_data').text(msgPool + " " + msgDateStr  + " via "  +   msgSource);
-      }
-      var id = cometMsg.id;
-
-      var resendButton = newMsg.find('.resend');    
-      
-      if (cometResent) {
-        resendButton.css("display", "none");
-      } else {
-        resendButton
-            .attr('id', 'resend_' + id)     
-            .attr('href', "javascript:resendFunction(" + id + ");")       
-      }
-
-      var tempStr = strip(msgBody).replaceAll ("'", "ZZZ$%$");
-      
-      var myReplyMsg = tempStr.replaceAll ("ZZZ$%$", "\\'");   
-      
-          
-      newMsg.find('.reply').attr('href',
-        "javascript:setReplyTo(" + id + ", '"+ myReplyMsg + "'," + msgPoolId + ", '" + msgAuthor.nickname + "')");
-      var conversation = newMsg.find('.conversation');
-      if (msgConversation != 0) {
-        conversation.attr('href', 
-          root + '/conversation/' + msgConversation);
-      } else {
-        conversation.css("display", "none");
-      }
-
-      // Insert the updated copy of the message into the page
-      newMsg.prependTo(msgInsertPt).show();
-      jQuery('#msgsep').clone().show();
-    }
-  }
-}
 // ]]
\ No newline at end of file

Modified: esme/trunk/server/src/main/webapp/scripts/display_single_message.js
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/webapp/scripts/display_single_message.js?rev=1092245&r1=1092244&r2=1092245&view=diff
==============================================================================
--- esme/trunk/server/src/main/webapp/scripts/display_single_message.js (original)
+++ esme/trunk/server/src/main/webapp/scripts/display_single_message.js Thu Apr 14 13:55:42 2011
@@ -18,43 +18,6 @@
 */
 
 // <![CDATA[
-/*
- * displayMessages called by lift:comet, type="Timeline" and type="PublicTimeline"
- */
- 
-  // Replaces all instances of the given substring.
-String.prototype.replaceAll = function( 
-	strTarget, // The substring you want to replace
-	strSubString // The string you want to replace in.
-	){
-	var strText = this;
-	var intIndexOfMatch = strText.indexOf( strTarget );
-	 
-	// Keep looping while an instance of the target string
-	// still exists in the string.
-	while (intIndexOfMatch != -1){
-		// Relace out the current instance.
-		strText = strText.replace( strTarget, strSubString )
-		 
-		// Get the index of any next matching substring.
-		intIndexOfMatch = strText.indexOf( strTarget );
-	}
-	 
-	// Return the updated string with ALL the target strings
-	// replaced out with the new substring.
-	return( strText );
-} 
-
-function parseXml(xml) {
-    if (jQuery.browser.msie) {
-    	  var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
-          xmlDoc.loadXML(xml);
-           xml = xmlDoc;    
-      }       
-  return xml;
-}
- 
-
 function login()
 {
   var myAction;
@@ -66,134 +29,5 @@ function login()
     
      
   document.forms[0].submit();	
-}
-
-function msgDateCompare(msg1, msg2)
-{
-  return parseInt(msg1.message.when) - parseInt(msg2.message.when);
-}
-
-function displayMessages(msgArray, elementId, root)
-{
-  // 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]').remove();
-  }
-
-  // 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 msgText = cometMsg.text
-      // Dealing with an IE bug when parsing XML with jQuery
-      
-      if (jQuery.browser.msie) {
-      	var msgBodyXML = parseXml(cometMsg.text);
-        var msgBodyBase = jQuery(msgBodyXML).find('body');
-        msgBody = msgBodyBase[0].xml.replaceAll ("<body>", "").replaceAll ("</body>", ""); 
-      }
-      else
-      	msgBody = jQuery(cometMsg.text).find('body').html();
-      
-      if (!msgBody)
-      	msgBody = cometMsg.text;
-      
-      if (!msgBody)
-      	msgBody = cometMsg.text;
-                             
-      var msgDateObj = new Date(parseInt(cometMsg.when));
-      
-      var msgDateStr = prettyDate(msgDateObj);
-      
-      var msgPool = '';
-      if (cometMsg.pool) msgPool = 'in pool ' + cometMsg.pool.name;     
-      var msgPoolId = 0;
-      if (cometMsg.pool) msgPoolId = cometMsg.pool.id;
-      var msgSource = cometMsg.source;
-      var msgConversation = cometMsg.conversation;
-      var msgReason = ""
-      for (r in cometReason) {
-      	  msgSource = ""
-          if (r == "resent_from")
-             msgReason = "resent by " + cometReason[r].nickname;
-          else
-            msgReason = "caused by " + r;
-        break
-      }
-      
-
-      // 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= root + "/images/avatar.jpg"
-      	
-     if (!msgPool)
-      	msgPool="public"
-      	
-      var avatar = newMsg.find('#avatar')
-      .attr('src', msgAuthor.imageurl)
-      .attr('alt',msgAuthor.firstname + ' ' + msgAuthor.lastname);
-
-
-      newMsg.find('#msgbody').html(msgBody);
-      if (msgReason)
-         newMsg.find('#supp_data').text(msgPool + " " + msgDateStr  + " " +  msgReason );
-      else {
-      	 newMsg.find('#supp_data').text(msgPool + " " + msgDateStr  + " via "  +   msgSource);
-      }
-      var id = cometMsg.id;
-      var resendButton = newMsg.find('#resend');
-      if (cometResent) {
-        resendButton.css("display", "none");
-      } else {
-        resendButton
-            .attr('id', 'resend_' + id)
-            .click(function() { resend_msg(id);
-                                clearResend("resend_" + id );
-                                return false;})
-          /*
-          attr('onclick', 'javascript:resend_msg(' + id + ');' +
-                                     'clearResend("resend_' + id + '")');
-          */
-      }
-      newMsg.find('#reply').attr('href',
-        "javascript:setReplyTo(" + id + ", '"+ msgBody + "', " + msgPoolId + ")");
-      var conversation = newMsg.find('#conversation');
-      if (msgConversation != 0) {
-        conversation.attr('href',
-          root + '/conversation/' + msgConversation);
-      } else {
-        conversation.css("display", "none");
-      }
-
-      // 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();
-    }
-  }
-}
+}                      
 // ]]>
\ No newline at end of file

Modified: esme/trunk/server/src/main/webapp/style/style.css
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/webapp/style/style.css?rev=1092245&r1=1092244&r2=1092245&view=diff
==============================================================================
--- esme/trunk/server/src/main/webapp/style/style.css (original)
+++ esme/trunk/server/src/main/webapp/style/style.css Thu Apr 14 13:55:42 2011
@@ -284,16 +284,18 @@ textarea.inputBox2 {  
 	height:28px; 
 	width:181px; 
 	margin:15px 0 20px 0; 
-	}
+	}        
+/* TODO: Need some cross-browser compatibility work to make this pretty in all
+         browsers. */
 .searchBox .inputBox { 
-	padding:5px 0 0 8px;
+	padding:7px 0 0 11px;
 	float:left;	
-	width:140px; 
+	width:140px;
 	border:0;
-	}
+	}             
 .searchButton {	
 	float:left;	
-	
+	padding-top:2px;
 	}
 
 /*RIGHT box

Modified: esme/trunk/server/src/main/webapp/templates-hidden/base.html
URL: http://svn.apache.org/viewvc/esme/trunk/server/src/main/webapp/templates-hidden/base.html?rev=1092245&r1=1092244&r2=1092245&view=diff
==============================================================================
--- esme/trunk/server/src/main/webapp/templates-hidden/base.html (original)
+++ esme/trunk/server/src/main/webapp/templates-hidden/base.html Thu Apr 14 13:55:42 2011
@@ -81,7 +81,7 @@
                         </div>
                         <lift:MenuSnippet.menu />
                         <!--search form-->
-                        <form action="/info_view/search" method="post" id = "validateForm">
+                        <form action="/info_view/search" method="get" id = "validateForm">
                             <div id="search">
                                 <div class="searchBox">
                                     <input type="text" class="inputBox required alphanumeric nowhitespace" name="term" value=""/>