Skip to content

Commit

Permalink
Added status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
robrighter committed Apr 15, 2010
1 parent e278ed6 commit 685af7e
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 35 deletions.
36 changes: 35 additions & 1 deletion dynamic/css/site.sass
Expand Up @@ -274,4 +274,38 @@ em
#recent .item .name a
color: #009827
font-weight: bold
text-decoration: none
text-decoration: none

#progressbox
background: white
padding: 5px
border-radius: 5px
height: 54px
margin-bottom: 30px
margin-left: 8px
margin-right: 8px


#progressoutline
width: 735px
height: 20px
margin-left: auto
margin-right: auto
margin-top: 10px
margin-bottom: 0px
background-color: #cccccc
border: 2px solid #90D55C
overflow: hidden

#progressbar
width: 0%
height: 20px
margin: 0
border-right: 1px solid #fff
background-color: #90D55C

#progressstatus
color: #666666
margin: 0
text-align: center
font-size: 12px
5 changes: 5 additions & 0 deletions dynamic/index.haml
Expand Up @@ -37,6 +37,11 @@
%span= 'Followers'
%div{:class=>'tabline kill'}= ' '

#progressbox
#progressoutline
#progressbar
#progressstatus
%span= 'Calculating Social Graph...'

#userlist
%div{:class=>'user template'}
Expand Down
33 changes: 33 additions & 0 deletions prod-buildout/css/site.css
Expand Up @@ -272,3 +272,36 @@ em {
color: #009827;
font-weight: bold;
text-decoration: none; }

#progressbox {
background: white;
padding: 5px;
border-radius: 5px;
height: 54px;
margin-bottom: 30px;
margin-left: 8px;
margin-right: 8px; }

#progressoutline {
width: 735px;
height: 20px;
margin-left: auto;
margin-right: auto;
margin-top: 10px;
margin-bottom: 0px;
background-color: #cccccc;
border: 2px solid #90D55C;
overflow: hidden; }

#progressbar {
width: 0%;
height: 20px;
margin: 0;
border-right: 1px solid #fff;
background-color: #90D55C; }

#progressstatus {
color: #666666;
margin: 0;
text-align: center;
font-size: 12px; }
8 changes: 8 additions & 0 deletions prod-buildout/index.html
Expand Up @@ -59,6 +59,14 @@
<div class='tabline kill'></div>
</div>
</div>
<div id='progressbox'>
<div id='progressoutline'>
<div id='progressbar'></div>
</div>
<div id='progressstatus'>
<span>Calculating Social Graph...</span>
</div>
</div>
<div id='userlist'>
<div class='user template'>
<img src='http://a1.twimg.com/profile_images/79569518/eagle_bigger.jpg' />
Expand Down
8 changes: 8 additions & 0 deletions prod-buildout/js/friendpage.js
Expand Up @@ -2,6 +2,14 @@ $(document).ready(function() {
tw = new tweetWrap(theuser, function(){
populateList(tw.toogoodforme);
setProfile(tw.personalprofile);
$('#progressbox').slideUp('slow');
},
function(progress, status){
setStatusBar(progress, status);
console.log("Progress: " + progress + " Status: " + status);
},
function(error){
alert(error);
});

$('.profile .following').bind('click', function() {
Expand Down
5 changes: 5 additions & 0 deletions prod-buildout/js/site.js
Expand Up @@ -41,4 +41,9 @@ var replaceList = function(list){
clearList();
populateList(list);
$('.profile').find('img').attr('src' ,tw.personalprofile.profile_image_url);
}

var setStatusBar = function(percent, message){
$('#progressbar').css('width', (percent+'%'));
$('#progressstatus span').html( (message || '') );
}
57 changes: 40 additions & 17 deletions prod-buildout/js/tweetwrap.js
@@ -1,5 +1,5 @@

var tweetWrap = function (screenname, initcallback){
var tweetWrap = function (screenname, initcallback, notifyprogress, abandon){
//TRY THIS http://api.twitter.com/1/statuses/friends.json to get around the rate limit

var initializationcallback = initcallback;
Expand All @@ -10,18 +10,24 @@ var tweetWrap = function (screenname, initcallback){
this.toogoodforme = [];
this.personalprofile = {};
this.userscreenname = screenname;
this.notifyprogresscallback = notifyprogress;
this.abandoncallback = abandon;

var progress = 0;

var that = this;

var getFollowers = function (cursor){
$.ajax({
'url': ('http://api.twitter.com/1/statuses/followers.json?callback=?&screen_name='+ that.userscreenname +'&cursor='+cursor),
success: function(result) {
console.log(result);
console.log("Followers recieved: "+ result.users.length +" users and a cursor of: " + result.next_cursor);
if(result.error){
that.abandoncallback(result.error);
}
progress += pageProgressPercentage(parseInt(that.personalprofile.followers_count));
that.followers = that.followers.concat(result.users);
that.notifyprogresscallback(progress,"Followers recieved: "+ that.followers.length);
if(result.next_cursor == 0){
console.log("Found all of the followers. A total of " + that.followers.length);
getFollowing(-1); //ok we got everyone, lets move on to grab all of the followING
}
else{
Expand All @@ -36,11 +42,15 @@ var tweetWrap = function (screenname, initcallback){
$.ajax({
'url': ('http://api.twitter.com/1/statuses/friends.json?callback=?&screen_name='+ that.userscreenname + '&cursor=' + cursor),
success: function(result) {
if(result.error){
that.abandoncallback(result.error);
}
console.log(result);
console.log("Following recieved: "+ result.users.length +" users and a cursor of: " + result.next_cursor);
progress += pageProgressPercentage(parseInt(that.personalprofile.friends_count));
that.following = that.following.concat(result.users);
that.notifyprogresscallback(progress,"Following recieved: "+ that.following.length);
if(result.next_cursor == 0){
console.log("Found all of the following. A total of " + that.following.length);
computeRemainingArrays();
}
else{
Expand All @@ -52,15 +62,15 @@ var tweetWrap = function (screenname, initcallback){
}

var computeRemainingArrays = function(){
console.log("Followers: "+that.followers.length + " Following:"+that.following.length);
var followersnames = _.map(that.followers, function(item){
return item.screen_name;
});
var followingnames = _.map(that.following, function(item){
return item.screen_name;
});
var recipricationnames = _.intersect(followersnames, followingnames);
console.log("Reciprications:" + recipricationnames.length);

that.notifyprogresscallback(78,"Reciprications:" + recipricationnames.length);
//Now that we have the reciprication list, we can process the remaining arrays
_.each(that.followers, function(user){
if(_.detect(recipricationnames, function(name){return (user.screen_name === name);}) ){
Expand All @@ -76,25 +86,30 @@ var tweetWrap = function (screenname, initcallback){
that.toogoodforme.push(user);
}
});

getUserDetailByScreenName(that.userscreenname,function(data){
that.personalprofile = data;
console.log('Recieved the UserProfile:');
console.log(that.personalprofile);
// Ok initialization is done, go ahead and call the callback
initializationcallback();
});
that.notifyprogresscallback(100,"All Done!");
initializationcallback();

}


var pageProgressPercentage = function(totalnumbertopage){
var basepercent = 33;
var percentperpage = (100/totalnumbertopage);
if(percentperpage > 1){
percentperpage = 1;
}

console.log('CHECK IT=> ' + (percentperpage*basepercent));
return percentperpage*basepercent;
}


var getFollowersByUserId = function (userid, callback){
$.getJSON('http://api.twitter.com/1/followers/ids.json?callback=?&user_id='+userid, callback);
}

var getUserDetailByScreenName = function (screenname, callback){
console.log('http://api.twitter.com/1/users/show.json?callback=?&screen_name='+screenname);
console.log('You are here: http://api.twitter.com/1/users/show.json?callback=?&screen_name='+screenname);
$.getJSON('http://api.twitter.com/1/users/show.json?callback=?&screen_name='+screenname,callback);
}

Expand All @@ -103,7 +118,15 @@ var tweetWrap = function (screenname, initcallback){
}

var init = function(){
getFollowers(-1);
getUserDetailByScreenName(that.userscreenname,function(data){
if(data.error){
that.abandoncallback(data.error);
}
that.personalprofile = data;
console.log('Recieved the UserProfile:');
console.log(that.personalprofile);
getFollowers(-1);
});
};

init();
Expand Down
8 changes: 8 additions & 0 deletions static/js/friendpage.js
Expand Up @@ -2,6 +2,14 @@ $(document).ready(function() {
tw = new tweetWrap(theuser, function(){
populateList(tw.toogoodforme);
setProfile(tw.personalprofile);
$('#progressbox').slideUp('slow');
},
function(progress, status){
setStatusBar(progress, status);
console.log("Progress: " + progress + " Status: " + status);
},
function(error){
alert(error);
});

$('.profile .following').bind('click', function() {
Expand Down
5 changes: 5 additions & 0 deletions static/js/site.js
Expand Up @@ -41,4 +41,9 @@ var replaceList = function(list){
clearList();
populateList(list);
$('.profile').find('img').attr('src' ,tw.personalprofile.profile_image_url);
}

var setStatusBar = function(percent, message){
$('#progressbar').css('width', (percent+'%'));
$('#progressstatus span').html( (message || '') );
}

0 comments on commit 685af7e

Please sign in to comment.