Skip to content

Commit

Permalink
load more tweets done on all pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
amaron committed Aug 11, 2012
1 parent a09168f commit 2292625
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 73 deletions.
19 changes: 16 additions & 3 deletions src/main/java/TwitMini/controller/HomePageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import TwitMini.model.TweetData;
import TwitMini.model.User;
import TwitMini.services.TweetService;
import TwitMini.services.UserService;
import TwitMini.services.ViewService;
Expand Down Expand Up @@ -46,18 +47,30 @@ public ModelAndView homeredirect(){

@RequestMapping(value="/search/moreSearchTweets.json", method=RequestMethod.GET)
@ResponseBody
public List<TweetData> moreSearchResults(@RequestParam String searchtext, @RequestParam int offset){
public List<TweetData> moreSearchResultsTweets(@RequestParam String searchtext, @RequestParam int offset){
return viewService.searchTweets(searchtext,offset,10);
}

@RequestMapping(value="/search/moreSearchUsers.json", method=RequestMethod.GET)
@ResponseBody
public List<User> moreSearchResultsUsers(@RequestParam String searchtext, @RequestParam int offset){
return viewService.searchUsers(searchtext, offset, 10);
}

@RequestMapping("/search")
public ModelAndView Search(@RequestParam final String searchtext, HttpSession Session){

logger.info("User " + (String)Session.getAttribute("userName") + " searched for "+ searchtext );

final List<TweetData> tweet_list= viewService.searchTweets(searchtext,0,10);
final List<User> user_list = viewService.searchUsers(searchtext,0,10);

return new ModelAndView("search"){{
addObject("searchtext",searchtext);
addObject("UserList", viewService.searchUsers(searchtext,0,1000));
addObject("TweetList", viewService.searchTweets(searchtext,0,10));
addObject("UserList", user_list);
addObject("TweetList", tweet_list );
addObject("UserListSize",user_list.size());
addObject("TweetListSize",tweet_list.size());
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/TwitMini/controller/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public LoginController(JdbcTemplate db, UserService userService, Logger logger)
public ModelAndView index(HttpSession Session) {
String userName = (String) Session.getAttribute("userName");
if(userName==null)
return new ModelAndView("index-Karthik"); // will change it to specific register page with only register
return new ModelAndView("index"); // will change it to specific register page with only register
else return new ModelAndView("redirect:/home");

}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/TwitMini/controller/ProfileViewController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package TwitMini.controller;

import TwitMini.model.TweetData;
import TwitMini.model.User;
import TwitMini.services.TweetService;
import TwitMini.services.UserService;
Expand All @@ -12,6 +13,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Hashtable;
import java.util.List;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -102,6 +104,23 @@ public ModelAndView mentions(@PathVariable final String handle)
};
}

@RequestMapping(value="{handle}/getMoreMentions.json", method=RequestMethod.GET)
@ResponseBody
public List<TweetData> moreMentions(@PathVariable final String handle, @RequestParam final int offset)
{

return viewService.listUserMentions(handle,offset,10);
}


@RequestMapping(value="{handle}/getMoreUserTweets.json", method=RequestMethod.GET)
@ResponseBody
public List<TweetData> moreUserTwees(@PathVariable final String handle, @RequestParam final int offset)
{

return viewService.listUserTweets(handle,offset,10);
}



@RequestMapping("{handle}/followers")
Expand Down
82 changes: 23 additions & 59 deletions src/main/webapp/WEB-INF/jsp/mentions.jsp
Original file line number Diff line number Diff line change
@@ -1,63 +1,5 @@
<!--<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<link rel="stylesheet" href="/static/css/bootstrap.css">
<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/ejs_production.js"></script>
<script type="text/javascript" src="/static/js/timeDifference.js"></script>
<script type="text/javascript" src="/static/js/appendItem.js"></script>
<script type="text/javascript" src="/static/js/getJSTimestamp.js"></script>
</head>
<body>
Hello, Y U No Signup?! <a href="/user/register">Signup!</a>
<a href="/user/login">login</a>
<h2>SpeakOUT!</h2>
<h1> ${List[0].username}'s Profile</h1>
<ul id="tweetList">
User ${List[0].username}'s Tweets
<c:forEach var='item' items='${List}'>
<script type="text/javascript">
appendItem({tweet_id:${item.tweet_id}, tweet:'${item.tweet}', username:'${item.username}', pushtime:'${item.pushtime}'})
</script>
</c:forEach>
</ul>
</body>
</html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
</head>
<body>
Hello <a href ="/user/${sessionScope.userName}">${sessionScope.userName}</a> <a href="/user/logout">Logout</a>
<h1><a href="/home">My Homepage</a></h1>
<h1> ${handle}'s Profile</h1>
<li id='numFollowers'><a href="/user/getfollowers/${handle}">followers: <span id="num_followers">${User.num_followers}</span></a></li>
<li><a href="/user/getfollowing/${handle}">following: ${User.num_following}</a></li>
User ${handle}'s Tweets ${User.num_tweets}
<ul id="tweetList">
<c:forEach var='item' items='${List}'>
<script type="text/javascript">
appendItem({tweet_id:${item.tweet_id}, tweet:'${item.tweet}', username:'${item.username}', pushtime:'${item.pushtime}'})
</script>
</c:forEach>
</ul>
</body>
</html>-->


<!DOCTYPE html>
Expand Down Expand Up @@ -188,6 +130,26 @@ User ${handle}'s Tweets ${User.num_tweets}
<script type="text/javascript" src='/static/js/follow.js'></script>
<script type="text/javascript" src='/static/js/addTweet.js'></script>
<script type="text/javascript">var num_followers=${User.num_followers};</script>
<script type="text/javascript">
var cur_offset_tweets=10;
var cur_handle='${User.username}';
function getMoreMentions(){
$.ajax({
type: 'GET',
url: '/user/'+cur_handle+'/getMoreMentions.json',
data: $.param({ offset: cur_offset_tweets, handle: cur_handle}),
success: function(data) {
if(data.length==0) $('#moreTweetsBtn').hide();
for(var k=0;k<data.length;k++){
//alert(JSON.stringify(data.List[k]));
appendItem(data[k]);
}
cur_offset_tweets+=data.length;
}
});
}
</script>
<link rel="shortcut icon" href="../assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
Expand Down Expand Up @@ -290,7 +252,9 @@ User ${handle}'s Tweets ${User.num_tweets}
</div>
</div>


<div class="span9">
<button class="btn btn-success" id="moreTweetsBtn" onclick="getMoreMentions();return false">load more...</button>
</div>


</div>
Expand Down
27 changes: 26 additions & 1 deletion src/main/webapp/WEB-INF/jsp/profileview.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@
<script type="text/javascript" src='/static/js/follow.js'></script>
<script type="text/javascript" src='/static/js/addTweet.js'></script>
<script type="text/javascript">var num_followers=${User.num_followers};</script>
<script type="text/javascript">
var cur_offset_tweets=10;
var cur_handle='${User.username}';
function getMoreMentions(){
$.ajax({
type: 'GET',
url: '/user/'+cur_handle+'/getMoreUserTweets.json',
data: $.param({ offset: cur_offset_tweets, handle: cur_handle}),
success: function(data) {
if(data.length==0) $('#moreTweetsBtn').hide();
for(var k=0;k<data.length;k++){
//alert(JSON.stringify(data.List[k]));
appendItem(data[k]);
}
cur_offset_tweets+=data.length;
}
});
}
</script>



<link rel="shortcut icon" href="../assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
Expand Down Expand Up @@ -291,7 +314,9 @@
</div>
</div>


<div class="span9">
<button class="btn btn-success" id="moreTweetsBtn" onclick="getMoreMentions();return false">load more...</button>
</div>


</div>
Expand Down
2 changes: 0 additions & 2 deletions src/main/webapp/WEB-INF/jsp/randomhome.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<meta name="author" content="">

<!-- Le styles -->
<link rel="stylesheet" href="static/css/easyNotification.css">

<script type="text/javascript" src="/static/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/js/easy.notification.js"></script>
<script type="text/javascript" src="/static/js/ejs_production.js"></script>
Expand Down
35 changes: 32 additions & 3 deletions src/main/webapp/WEB-INF/jsp/search.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,46 @@
<script type="text/javascript" src="/static/js/appendItem.js"></script>
<script type="text/javascript" src="/static/js/getJSTimestamp.js"></script>
<script type="text/javascript">
var cur_offset=10;
var cur_offset_tweets=${TweetListSize};
var cur_searchtext='${searchtext}';
function getMoreSearchTweets(){
$.ajax({
type: 'GET',
url: '/search/moreSearchTweets.json',
data: $.param({ offset: cur_offset, searchtext: cur_searchtext}),
data: $.param({ offset: cur_offset_tweets, searchtext: cur_searchtext}),
success: function(data) {
if(data.length==0) $('#moreTweetsBtn').hide();
for(var k=0;k<data.length;k++){
//alert(JSON.stringify(data.List[k]));
appendItem(data[k]);
}
cur_offset_tweets+=data.length;
}
});
cur_offset+=10;
}
var cur_offset_users=${UserListSize};
function getMoreSearchUsers(){
$.ajax({
type: 'GET',
url: '/search/moreSearchUsers.json',
data: $.param({ offset: cur_offset_users, searchtext: cur_searchtext}),
success: function(data) {
if(data.length==0) $('#moreUsersBtn').hide();
for(var k=0;k<data.length;k++){
//alert(JSON.stringify(data.List[k]));
var node=$("<li><blockquote><a href='/user/"+data[k].username+"'>"+data[k].username+"</a></blockquote></li>");
$('#userList').append(node);
}
cur_offset_users+=data.length;
}
});
}
Expand All @@ -49,6 +72,12 @@ Hello <a href="/user/${sessionScope.userName}"> ${sessionScope.userName} </a><a
</ul>


<form action="/search/moreSearchUsers.json" onsubmit="getMoreSearchUsers();return false">
<input type="submit" value="Load More Results" id="moreUsersBtn"/>
</form>

====================================================================================================================

<h2>TweetList</h2>
<ul id="tweetList">
<c:forEach var='item' items='${TweetList}'>
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/static/js/displayNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ var alnum=lwr+upr+numb;
function idFinder(tweet){
var idList=new Array();
var count =0;
for(i=0;i<tweet.length;i++){
for(var i=0;i<tweet.length;i++){
if(tweet[i]=='@' && alnum.indexOf(tweet[i-1])==-1){
var id="";
for(j=i+1;alnum.indexOf(tweet[j])!=-1;j++){
for(var j=i+1;alnum.indexOf(tweet[j])!=-1;j++){
id+=tweet[j];
}
id='@'+id;
Expand All @@ -24,7 +24,7 @@ function idFinder(tweet){

function htmlAdder(tweet,idList){

for(i=0;i<idList.length;i++){
for(var i=0;i<idList.length;i++){
var link="@\<a href='/user/placeholder'>placeholder</a> ";
var cleanID=idList[i].substring(1);
var userlink=link.replace(/placeholder/g,cleanID);
Expand All @@ -44,7 +44,7 @@ function displayNew(form){
$.post('/user/getNewTweet.json', $(form).serialize(),function(data) {

$('#updateBtn').hide();
for(i=0;i<data.val;i++){
for(var i=0;i<data.val;i++){
var temp=data.List[i];
//alert(temp);
var list= idFinder(temp.tweet);
Expand Down
Loading

0 comments on commit 2292625

Please sign in to comment.