Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
Update to fix prettyDate display in the drawMessages() func. There was
Browse files Browse the repository at this point in the history
lots of date arithmetic, none of it documented, which seemd to go round
the block and end up where it started. Converting a number to a Date()
object, then converting that to a string, then replacing dashes in that
string with slashes, converting the result back to another Date()
object. It was all very obtuse. On my browser it resulted in all
messages being formatted as "just now" which is obviously wrong. I
simplified and it seems to work better now.
  • Loading branch information
DinoChiesa committed Sep 19, 2012
1 parent f25d647 commit 1616c68
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 27 deletions.
41 changes: 41 additions & 0 deletions index.php
@@ -0,0 +1,41 @@
<?php
//
// CORS allows HTML5 apps running in modern browsers
// to make valid cross-origin requests.
//
// For more on CORS, see
// http://en.wikipedia.org/wiki/Cross-origin_resource_sharing
//
// This PHP module sets the appropriate headers in the webserver
// response, to tell browsers that it's ok to connect to
// api.usergrid.com directly from script.
//
// Another way to add this header is to do so via Webserver
// configuration. You can use one or the other, but you do not need
// both.
//
// NB: This file will work only on webservers that have PHP enabled.
//

// Specify domains from which requests are allowed
header('Access-Control-Allow-Origin: https://api.usergrid.com');

// Specify which request methods are allowed
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');

// Additional headers which may be sent along with the CORS request
// The X-Requested-With header allows jQuery requests to go through
header('Access-Control-Allow-Headers: X-Requested-With');

// Set the age to 1 day to improve speed/caching.
header('Access-Control-Max-Age: 86400');

// Exit early so the page isn't fully loaded for options requests
if (strtolower($_SERVER['REQUEST_METHOD']) == 'options') {
exit();
}

// delegate to the view
include './index.html';

?>
47 changes: 20 additions & 27 deletions js/app.js
Expand Up @@ -162,7 +162,7 @@ $(document).ready(function () {
function pageUpdateAccount(){ function pageUpdateAccount(){
//turn the reload timer off so we don't get interrupted during the update //turn the reload timer off so we don't get interrupted during the update
window.clearInterval( feedReloadTimer ); window.clearInterval( feedReloadTimer );

$("#update-name").val(appUser.get('name')); $("#update-name").val(appUser.get('name'));
$("#update-email").val(appUser.get('email')); $("#update-email").val(appUser.get('email'));
$("#update-username").val(appUser.get('username')); $("#update-username").val(appUser.get('username'));
Expand Down Expand Up @@ -274,7 +274,7 @@ $(document).ready(function () {
$('#user-message-update-account').html('<strong>There was an error updating your account</strong>'); $('#user-message-update-account').html('<strong>There was an error updating your account</strong>');
} }
); );
} }
} }


/** /**
Expand Down Expand Up @@ -326,7 +326,7 @@ $(document).ready(function () {
$("#next-btn-container").hide(); $("#next-btn-container").hide();
} }
}, },
function(){ function(){
$("#messages-list").html("There was an error getting the messages!"); $("#messages-list").html("There was an error getting the messages!");
} }
); );
Expand Down Expand Up @@ -358,14 +358,14 @@ $(document).ready(function () {
} }
//make sure we are on the messages page //make sure we are on the messages page
window.location = "#page-messages-list"; window.location = "#page-messages-list";

fullFeedView = true; fullFeedView = true;
$('#btn-show-full-feed').addClass('ui-btn-up-c'); $('#btn-show-full-feed').addClass('ui-btn-up-c');
$('#btn-show-my-feed').removeClass('ui-btn-up-c'); $('#btn-show-my-feed').removeClass('ui-btn-up-c');


fullActivityFeed.get( fullActivityFeed.get(
function(){ function(){
drawMessages(fullActivityFeed); drawMessages(fullActivityFeed);
if (fullActivityFeed.hasPreviousPage()) { if (fullActivityFeed.hasPreviousPage()) {
$("#previous-btn-container").show(); $("#previous-btn-container").show();
} else { } else {
Expand Down Expand Up @@ -400,16 +400,15 @@ $(document).ready(function () {
var usersToBind = []; var usersToBind = [];
feed.resetEntityPointer(); feed.resetEntityPointer();
while(feed.hasNextEntity()) { while(feed.hasNextEntity()) {
var message = feed.getNextEntity(); var message = feed.getNextEntity(),
var created = message.get('created'); created = message.get('created'),
var content = message.get('content'); content = message.get('content'),
var actor = message.get('actor'); email = '',
var name = actor.displayName; imageUrl = '',
if (!name) { name = 'Anonymous'; } actor = message.get('actor'),
var username = actor.displayName; name = actor.displayName || 'Anonymous',

username = actor.displayName;
var email = '';
var imageUrl = '';
if ('email' in actor) { if ('email' in actor) {
email = actor.email; email = actor.email;
imageUrl = 'http://www.gravatar.com/avatar/' + MD5(email.toLowerCase()) + '?s=' + 50; imageUrl = 'http://www.gravatar.com/avatar/' + MD5(email.toLowerCase()) + '?s=' + 50;
Expand All @@ -423,12 +422,7 @@ $(document).ready(function () {
imageUrl = 'http://www.gravatar.com/avatar/' + MD5('rod@apigee.com') + '?s=' + 50; imageUrl = 'http://www.gravatar.com/avatar/' + MD5('rod@apigee.com') + '?s=' + 50;
} }


var initialDate = new Date(created); formattedTime = prettyDate(created);
var offset = initialDate.getTimezoneOffset() * 60000;
var utcDate = created - offset;
var date = new Date(utcDate);
var isotime = date.toISOString();
formattedTime = prettyDate(isotime);


html += '<div style="border-bottom: 1px solid #444; padding: 5px; min-height: 60px;"><img src="' + imageUrl + '" style="border none; height: 50px; width: 50px; float: left;padding-right: 10px"> '; html += '<div style="border-bottom: 1px solid #444; padding: 5px; min-height: 60px;"><img src="' + imageUrl + '" style="border none; height: 50px; width: 50px; float: left;padding-right: 10px"> ';
html += '<span style="float: right">'+formattedTime+'</span>'; html += '<span style="float: right">'+formattedTime+'</span>';
Expand Down Expand Up @@ -543,7 +537,7 @@ $(document).ready(function () {
//reset the feed object so when we view it again, we will get the latest feed //reset the feed object so when we view it again, we will get the latest feed
userFeed.clearQuery(); userFeed.clearQuery();
showMyFeed(); showMyFeed();
} }
window.location = "#page-messages-list"; window.location = "#page-messages-list";
}, },
function () { function () {
Expand All @@ -565,10 +559,9 @@ $(document).ready(function () {


// Takes an ISO time and returns a string representing how // Takes an ISO time and returns a string representing how
// long ago the date represents. // long ago the date represents.
function prettyDate(time){ function prettyDate(createdDateValue) {
var date = new Date((time || "").replace(/-/g,"/").replace(/[TZ]/g," ")); var diff = (((new Date()).getTime() - createdDateValue) / 1000),
var diff = (((new Date()).getTime() - date.getTime()) / 1000); day_diff = Math.floor(diff / 86400);
var day_diff = Math.floor(diff / 86400);


if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 ) if ( isNaN(day_diff) || day_diff < 0 || day_diff >= 31 )
return 'just now'; return 'just now';
Expand Down Expand Up @@ -613,4 +606,4 @@ $(document).ready(function () {


}); });


//abudda abudda abudda that's all folks! //abudda abudda abudda that's all folks!

0 comments on commit 1616c68

Please sign in to comment.