Skip to content

Commit

Permalink
added datetime to comment list in user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatov committed Jul 13, 2011
1 parent 3f29017 commit b08b58c
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/main/scala/scala/tools/colladoc/snippet/ProfileOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import lib.DependencyFactory._
import page.Profile
import xml.{NodeSeq, Text}
import net.liftweb.util.BindHelpers._
import net.liftweb.util.DefaultDateTimeConverter._
import net.liftweb.http.{SHtml, S, RequestVar}
import net.liftweb.mapper.By
import net.liftweb.widgets.gravatar.Gravatar
Expand Down Expand Up @@ -120,21 +121,26 @@ class ProfileOps {

val fullname = user.userName.is

val cmts = Comment.findAll(By(Comment.user, user), By(Comment.valid, true))
val cmts: List[Comment] = Comment.findAll(By(Comment.user, user), By(Comment.valid, true))
val comments =
if (cmts.length == 0)
<span>No comments from this user.</span>
<h3>No comments by user.</h3>
else
<ul>
{ cmts.map(c =>
{
val abs = "/" + c.qualifiedName.is.replace(".", "/").replace("#", "$") + ".html"
<li>
<a href={abs}>{c.qualifiedName.is}</a>: {c.comment.is}
</li>
})
}
</ul>
<xml:group>
<h3>Comments by user</h3>
<ul>
{ cmts.sortBy(c => c.qualifiedName.is).map(c =>
{
val abs = "/" + c.qualifiedName.is.replace(".", "/").replace("#", "$") + ".html"
<li>
<a href={abs}>{c.qualifiedName.is}</a>:
<span class="comment">{c.comment.is}</span>
<span class="datetime" title={Comment.atomDateFormatter(c.dateTime)}>{formatDate(c.dateTime)}</span>
</li>
})
}
</ul>
</xml:group>

bind("profile", profile.body,
"form" -> userForm(user),
Expand Down
9 changes: 9 additions & 0 deletions src/main/webapp/coprofile.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@
font-size: 8pt;
padding-top: 0.2em;
}

.profile h2, h3, h4, h5, h6 {
font-weight: bold;
}

.datetime {
color: #666;
font-size: 80%;
}
1 change: 1 addition & 0 deletions src/main/webapp/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<title><lift:profileOps.title /></title>
<lift:with-resource-id>
<script src="/lib/tools.tooltip.js" type="text/javascript" />
<script src="/scripts/jquery.prettydate.js" type="text/javascript"/>
<script src="/scripts/cotemplate.js" type="text/javascript"/>
<script src="/scripts/coprofile.js" type="text/javascript"/>
<link href="/lib/template.css" media="screen" type="text/css" rel="stylesheet" />
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/scripts/coprofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@
$(document).ready(function() {
$("#profile_tabs").tabs();
$(".profile_form").validate();
$(".datetime").prettyDate();
});
100 changes: 100 additions & 0 deletions src/main/webapp/scripts/jquery.prettydate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* jQuery pretty date plug-in 1.0.0
*
* http://bassistance.de/jquery-plugins/jquery-plugin-prettydate/
*
* Based on John Resig's prettyDate http://ejohn.org/blog/javascript-pretty-date
*
* Copyright (c) 2009 Jörn Zaefferer
*
* $Id: jquery.validate.js 6096 2009-01-12 14:12:04Z joern.zaefferer $
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function() {
$.prettyDate = {

template: function(source, params) {
if (arguments.length == 1)
return function() {
var args = $.makeArray(arguments);
args.unshift(source);
return $.prettyDate.template.apply(this, args);
};
if (arguments.length > 2 && params.constructor != Array) {
params = $.makeArray(arguments).slice(1);
}
if (params.constructor != Array) {
params = [ params ];
}
$.each(params, function(i, n) {
source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
});
return source;
},

now: function() {
return new Date();
},

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

if (isNaN(day_diff) || day_diff < 0 || day_diff >= 2) // We use only today and yesterday
return;

var messages = $.prettyDate.messages;
return day_diff == 0 && (
diff < 60 && messages.now ||
diff < 120 && messages.minute ||
diff < 3600 && messages.minutes(Math.floor(diff / 60)) ||
diff < 7200 && messages.hour ||
diff < 86400 && messages.hours(Math.floor(diff / 3600))) ||
day_diff == 1 && messages.yesterday ||
day_diff < 7 && messages.days(day_diff) ||
day_diff < 31 && messages.weeks(Math.ceil(day_diff / 7));
}

};

$.prettyDate.messages = {
now: "just now",
minute: "1 minute ago",
minutes: $.prettyDate.template("{0} minutes ago"),
hour: "1 hour ago",
hours: $.prettyDate.template("{0} hours ago"),
yesterday: "Yesterday",
days: $.prettyDate.template("{0} days ago"),
weeks: $.prettyDate.template("{0} weeks ago")
};

$.fn.prettyDate = function(options) {
options = $.extend({
value: function() {
return $(this).attr("title");
},
interval: 10000
}, options);
var elements = this;

function format() {
elements.each(function() {
var date = $.prettyDate.format(options.value.apply(this));
if (date && $(this).text() != date)
$(this).text(date);
});
}

format();
if (options.interval)
setInterval(format, options.interval);
return this;
};

})();

0 comments on commit b08b58c

Please sign in to comment.