diff --git a/src/main/scala/view/helpers.scala b/src/main/scala/view/helpers.scala index 4e8267b..8dc2adf 100644 --- a/src/main/scala/view/helpers.scala +++ b/src/main/scala/view/helpers.scala @@ -35,12 +35,16 @@ Html(Markdown.toHtml(value, repository, enableWikiLink, enableRefsLink)) /** - * Returns <img> which displays the avatar icon. - * Looks up Gravatar if avatar icon has not been configured in user settings. + * Returns <img> which displays the avatar icon for the given user name. + * This method looks up Gravatar if avatar icon has not been configured in user settings. */ def avatar(userName: String, size: Int, tooltip: Boolean = false)(implicit context: app.Context): Html = getAvatarImageHtml(userName, size, "", tooltip) + /** + * Returns <img> which displays the avatar icon for the given mail address. + * This method looks up Gravatar if avatar icon has not been configured in user settings. + */ def avatar(commit: util.JGitUtil.CommitInfo, size: Int)(implicit context: app.Context): Html = getAvatarImageHtml(commit.committer, size, commit.mailAddress) @@ -64,6 +68,9 @@ } } + /** + * Convert link notations in the activity message. + */ def activityMessage(message: String)(implicit context: app.Context): Html = Html(message .replaceAll("\\[issue:([^\\s]+?)/([^\\s]+?)#((\\d+))\\]" , s"""$$1/$$2#$$3""") @@ -71,7 +78,7 @@ .replaceAll("\\[repo:([^\\s]+?)/([^\\s]+?)\\]" , s"""$$1/$$2""") .replaceAll("\\[branch:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]", (m: Match) => s"""${m.group(3)}""") .replaceAll("\\[tag:([^\\s]+?)/([^\\s]+?)#([^\\s]+?)\\]" , (m: Match) => s"""${m.group(3)}""") - .replaceAll("\\[user:([^\\s]+?)\\]" , s"""$$1""") // TODO disable link if user is removed? + .replaceAll("\\[user:([^\\s]+?)\\]" , (m: Match) => user(m.group(1)).body) ) /** @@ -100,14 +107,32 @@ def assets(implicit context: app.Context): String = s"${context.path}/assets" /** - * Generates the link to the account page. + * Generates the text link to the account page. + * If user does not exist or disabled, this method returns user name as text without link. */ - def user(userName: String, mailAddress: String, styleClass: String = "")(implicit context: app.Context): Html = { - getAccountByMailAddress(mailAddress).map { account => - Html(s"""${userName}""") - } getOrElse Html(userName) - } + def user(userName: String, mailAddress: String = "", styleClass: String = "")(implicit context: app.Context): Html = + userWithContent(userName, mailAddress, styleClass)(Html(userName)) + /** + * Generates the avatar link to the account page. + * If user does not exist or disabled, this method returns avatar image without link. + */ + def avatarLink(userName: String, size: Int, mailAddress: String = "", tooltip: Boolean = false)(implicit context: app.Context): Html = + userWithContent(userName, mailAddress)(avatar(userName, size, tooltip)) + + private def userWithContent(userName: String, mailAddress: String = "", styleClass: String = "")(content: Html)(implicit context: app.Context): Html = + (if(mailAddress.isEmpty){ + getAccountByUserName(userName) + } else { + getAccountByMailAddress(mailAddress) + }).map { account => + Html(s"""${content}""") + } getOrElse content + + + /** + * Test whether the given Date is past date. + */ def isPast(date: Date): Boolean = System.currentTimeMillis > date.getTime /** diff --git a/src/main/twirl/issues/commentlist.scala.html b/src/main/twirl/issues/commentlist.scala.html index 4071dcf..3460585 100644 --- a/src/main/twirl/issues/commentlist.scala.html +++ b/src/main/twirl/issues/commentlist.scala.html @@ -11,7 +11,7 @@
- @comment.commentedUserName commented + @user(comment.commentedUserName, styleClass="username strong") commented @datetime(comment.registeredDate) @if(comment.action != "commit" && comment.action != "merge" && (hasWritePermission || loginAccount.map(_.userName == comment.commentedUserName).getOrElse(false))){ @@ -36,7 +36,7 @@
Merged @avatar(comment.commentedUserName, 20) - @comment.commentedUserName merged commit @pullreq.map(_.commitIdTo.substring(0, 7)) + @user(comment.commentedUserName, styleClass="username strong") merged commit @pullreq.map(_.commitIdTo.substring(0, 7)) @if(pullreq.get.requestUserName == repository.owner){ @pullreq.map(_.requestBranch) to @pullreq.map(_.branch) } else { @@ -50,9 +50,9 @@ Closed @avatar(comment.commentedUserName, 20) @if(issue.isPullRequest){ - @comment.commentedUserName closed the pull request @datetime(comment.registeredDate) + @user(comment.commentedUserName, styleClass="username strong") closed the pull request @datetime(comment.registeredDate) } else { - @comment.commentedUserName closed the issue @datetime(comment.registeredDate) + @user(comment.commentedUserName, styleClass="username strong") closed the issue @datetime(comment.registeredDate) }
} @@ -60,7 +60,7 @@
Reopened @avatar(comment.commentedUserName, 20) - @comment.commentedUserName reopened the issue @datetime(comment.registeredDate) + @user(comment.commentedUserName, styleClass="username strong") reopened the issue @datetime(comment.registeredDate)
} } diff --git a/src/main/twirl/issues/issuedetail.scala.html b/src/main/twirl/issues/issuedetail.scala.html index 884655d..7a61819 100644 --- a/src/main/twirl/issues/issuedetail.scala.html +++ b/src/main/twirl/issues/issuedetail.scala.html @@ -14,14 +14,14 @@ Edit }
- @issue.openedUserName opened this issue @datetime(issue.registeredDate) + @user(issue.openedUserName, styleClass="username strong") opened this issue @datetime(issue.registeredDate)

@issue.title

@issue.assignedUserName.map { userName => - @avatar(userName, 20) @userName is assigned + @avatar(userName, 20) @user(userName, styleClass="username strong") is assigned }.getOrElse("No one is assigned") @if(hasWritePermission){ @@ -84,7 +84,7 @@
@defining((issue.openedUserName :: comments.map(_.commentedUserName)).distinct){ participants => @participants.size @plural(participants.size, "participant") - @participants.map { participant => @avatar(participant, 20, tooltip = true) } + @participants.map { participant => @avatarLink(participant, 20, tooltip = true) } }